You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by mi...@apache.org on 2024/05/08 05:51:49 UTC

(incubator-devlake) 01/01: feat: add duplicate operate for scope config

This is an automated email from the ASF dual-hosted git repository.

mintsweet pushed a commit to branch feat-7407
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git

commit 4204a387a726bdd82fb89ae930c5bcf2b4160fef
Author: mintsweet <0x...@gmail.com>
AuthorDate: Wed May 8 17:51:34 2024 +1200

    feat: add duplicate operate for scope config
---
 .../plugins/components/scope-config-form/index.tsx |  6 ++--
 .../src/plugins/components/scope-config/index.tsx  | 32 ++++++++++++++++++----
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/config-ui/src/plugins/components/scope-config-form/index.tsx b/config-ui/src/plugins/components/scope-config-form/index.tsx
index c6ba08d78..d3519d1b2 100644
--- a/config-ui/src/plugins/components/scope-config-form/index.tsx
+++ b/config-ui/src/plugins/components/scope-config-form/index.tsx
@@ -42,6 +42,7 @@ interface Props {
   connectionId: ID;
   defaultName?: string;
   showWarning?: boolean;
+  forceCreate?: boolean;
   scopeId?: ID;
   scopeConfigId?: ID;
   onCancel: () => void;
@@ -53,6 +54,7 @@ export const ScopeConfigForm = ({
   connectionId,
   defaultName,
   showWarning = false,
+  forceCreate = false,
   scopeId,
   scopeConfigId,
   onCancel,
@@ -81,7 +83,7 @@ export const ScopeConfigForm = ({
     (async () => {
       try {
         const res = await API.scopeConfig.get(plugin, connectionId, scopeConfigId);
-        setName(res.name);
+        setName(forceCreate ? `${res.name}-copy` : res.name);
         setEntities(res.entities ?? []);
         setTransformation(omit(res, ['id', 'connectionId', 'name', 'entities', 'createdAt', 'updatedAt']));
       } catch {}
@@ -99,7 +101,7 @@ export const ScopeConfigForm = ({
   const handleSubmit = async () => {
     const [success, res] = await operator(
       () =>
-        !scopeConfigId
+        !scopeConfigId || forceCreate
           ? API.scopeConfig.create(plugin, connectionId, { name, entities, ...transformation })
           : API.scopeConfig.update(plugin, connectionId, scopeConfigId, { name, entities, ...transformation }),
       {
diff --git a/config-ui/src/plugins/components/scope-config/index.tsx b/config-ui/src/plugins/components/scope-config/index.tsx
index 0bc83870d..3ef2afda9 100644
--- a/config-ui/src/plugins/components/scope-config/index.tsx
+++ b/config-ui/src/plugins/components/scope-config/index.tsx
@@ -42,8 +42,10 @@ interface Props {
 }
 
 export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name, onSuccess }: Props) => {
-  const [type, setType] = useState<'associate' | 'update' | 'relatedProjects'>();
-  const [relatedProjects, setRelatedProjects] = useState<Array<{ name: string; scopes: string[] }>>([]);
+  const [type, setType] = useState<'associate' | 'update' | 'relatedProjects' | 'duplicate'>();
+  const [relatedProjects, setRelatedProjects] = useState<
+    Array<{ name: string; scopes: Array<{ scopeId: ID; scopeName: string }> }>
+  >([]);
 
   const {
     token: { colorPrimary },
@@ -57,7 +59,10 @@ export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name
     const [success, res] = await operator(() => API.scopeConfig.check(plugin, id), { hideToast: true });
 
     if (success) {
-      const projects = res.projects.map((it: any) => ({ name: it.name, scopes: [] }));
+      const projects = res.projects.map((it: any) => ({
+        name: it.name,
+        scopes: it.scopes,
+      }));
 
       if (projects.length !== 1) {
         setRelatedProjects(projects);
@@ -141,6 +146,20 @@ export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name
           />
         </Modal>
       )}
+      {type === 'duplicate' && (
+        <Modal open width={960} centered footer={null} title="Edit Scope Config" onCancel={handleHideDialog}>
+          <ScopeConfigForm
+            plugin={plugin}
+            connectionId={connectionId}
+            showWarning
+            forceCreate
+            scopeConfigId={id}
+            scopeId={scopeId}
+            onCancel={handleHideDialog}
+            onSubmit={handleAssociate}
+          />
+        </Modal>
+      )}
       {type === 'relatedProjects' && (
         <Modal
           open
@@ -151,10 +170,10 @@ export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name
           onCancel={handleHideDialog}
         >
           <Message content="The change will apply to all following projects:" />
-          <ul style={{ marginTop: 15, marginLeft: 30 }}>
+          <ul style={{ margin: '15px 0 30px 30px' }}>
             {relatedProjects.map((it) => (
               <li style={{ color: colorPrimary }}>
-                {it.name}:{it.scopes.join(',')}
+                {it.name}: {it.scopes.map((sc) => sc.scopeName).join(',')}
               </li>
             ))}
           </ul>
@@ -164,6 +183,9 @@ export const ScopeConfig = ({ plugin, connectionId, scopeId, scopeName, id, name
               <Button type="primary" onClick={() => setType('update')}>
                 Continue
               </Button>
+              <Button type="primary" onClick={() => setType('duplicate')}>
+                Duplicate a scope config for {scopeName}
+              </Button>
             </Space>
           </Flex>
         </Modal>