forked from apache/incubator-devlake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: simplify scope config configuration (apache#7408)
- Loading branch information
Showing
16 changed files
with
263 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,4 +17,3 @@ | |
*/ | ||
|
||
export * from './connections'; | ||
export * from './tips'; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
config-ui/src/plugins/components/scope-config/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
import { useState } from 'react'; | ||
import { LinkOutlined, EditOutlined } from '@ant-design/icons'; | ||
import { Button, Modal } from 'antd'; | ||
import styled from 'styled-components'; | ||
|
||
import API from '@/api'; | ||
import { operator } from '@/utils'; | ||
|
||
import { PluginName } from '../plugin-name'; | ||
import { ScopeConfigSelect } from '../scope-config-select'; | ||
import { ScopeConfigForm } from '../scope-config-form'; | ||
|
||
const Wrapper = styled.div``; | ||
|
||
interface Props { | ||
plugin: string; | ||
connectionId: ID; | ||
scopeId: ID; | ||
id?: ID; | ||
name?: string; | ||
onSuccess?: () => void; | ||
} | ||
|
||
export const ScopeConfig = ({ plugin, connectionId, scopeId, id, name, onSuccess }: Props) => { | ||
const [type, setType] = useState<'associate' | 'update'>(); | ||
|
||
const handleHideDialog = () => setType(undefined); | ||
|
||
const handleAssociate = async (trId: ID) => { | ||
const [success] = await operator( | ||
() => API.scope.update(plugin, connectionId, scopeId, { scopeConfigId: trId !== 'None' ? +trId : null }), | ||
{ | ||
hideToast: true, | ||
}, | ||
); | ||
|
||
if (success) { | ||
handleHideDialog(); | ||
onSuccess?.(); | ||
} | ||
}; | ||
|
||
const handleUpdate = (trId: ID) => { | ||
handleHideDialog(); | ||
onSuccess?.(); | ||
}; | ||
|
||
return ( | ||
<Wrapper> | ||
<span>{id ? name : 'N/A'}</span> | ||
<Button | ||
size="small" | ||
type="link" | ||
icon={<LinkOutlined />} | ||
onClick={() => { | ||
setType('associate'); | ||
}} | ||
/> | ||
{id && ( | ||
<Button | ||
size="small" | ||
type="link" | ||
icon={<EditOutlined />} | ||
onClick={() => { | ||
// TO-DO: check if the scope config is associated with any scope | ||
setType('update'); | ||
}} | ||
/> | ||
)} | ||
{type === 'associate' && ( | ||
<Modal | ||
open | ||
width={960} | ||
centered | ||
footer={null} | ||
title={<PluginName plugin={plugin} name="Associate Scope Config" />} | ||
onCancel={handleHideDialog} | ||
> | ||
{plugin === 'tapd' ? ( | ||
<ScopeConfigForm | ||
plugin={plugin} | ||
connectionId={connectionId} | ||
scopeConfigId={id} | ||
scopeId={scopeId} | ||
onCancel={handleHideDialog} | ||
onSubmit={handleAssociate} | ||
/> | ||
) : ( | ||
<ScopeConfigSelect | ||
plugin={plugin} | ||
connectionId={connectionId} | ||
scopeConfigId={id} | ||
onCancel={handleHideDialog} | ||
onSubmit={handleAssociate} | ||
/> | ||
)} | ||
</Modal> | ||
)} | ||
{type === 'update' && ( | ||
<Modal open width={960} centered footer={null} title="Edit Scope Config" onCancel={handleHideDialog}> | ||
<ScopeConfigForm | ||
plugin={plugin} | ||
connectionId={connectionId} | ||
showWarning | ||
scopeConfigId={id} | ||
scopeId={scopeId} | ||
onCancel={handleHideDialog} | ||
onSubmit={handleUpdate} | ||
/> | ||
</Modal> | ||
)} | ||
</Wrapper> | ||
); | ||
}; |
Oops, something went wrong.