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 2023/09/05 23:25:45 UTC

[incubator-devlake] 01/01: fix(config-ui): adjust the interface return blueprint value

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

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

commit e65940a5fc84764a5bac2de858865e4dcf64e0ad
Author: mintsweet <0x...@gmail.com>
AuthorDate: Wed Sep 6 11:25:30 2023 +1200

    fix(config-ui): adjust the interface return blueprint value
---
 .../src/pages/blueprint/connection-detail/api.ts   |  6 ++--
 .../pages/blueprint/connection-detail/index.tsx    | 37 ++++++++++------------
 .../components/update-policy-dialog/index.tsx      |  8 +----
 .../pages/blueprint/detail/configuration-panel.tsx | 15 ++++-----
 config-ui/src/pages/blueprint/home/index.tsx       |  6 ++--
 config-ui/src/pages/blueprint/types.ts             | 17 ++++------
 .../src/pages/project/detail/webhooks-panel.tsx    | 34 ++++++++------------
 config-ui/src/pages/project/home/index.tsx         |  6 ++--
 8 files changed, 54 insertions(+), 75 deletions(-)

diff --git a/config-ui/src/pages/blueprint/connection-detail/api.ts b/config-ui/src/pages/blueprint/connection-detail/api.ts
index 6dd6beb12..a09ac84d6 100644
--- a/config-ui/src/pages/blueprint/connection-detail/api.ts
+++ b/config-ui/src/pages/blueprint/connection-detail/api.ts
@@ -18,9 +18,11 @@
 
 import { request } from '@/utils';
 
-export const getProject = (pname: string) => request(`/projects/${pname}`);
+import { BlueprintType } from '../types';
 
-export const getBlueprint = (id: ID) => request(`/blueprints/${id}`);
+export const getProject = (pname: string): Promise<{ blueprint: BlueprintType }> => request(`/projects/${pname}`);
+
+export const getBlueprint = (id: ID): Promise<BlueprintType> => request(`/blueprints/${id}`);
 
 export const updateBlueprint = (id: ID, payload: any) =>
   request(`/blueprints/${id}`, { method: 'patch', data: payload });
diff --git a/config-ui/src/pages/blueprint/connection-detail/index.tsx b/config-ui/src/pages/blueprint/connection-detail/index.tsx
index 8147b718f..182145201 100644
--- a/config-ui/src/pages/blueprint/connection-detail/index.tsx
+++ b/config-ui/src/pages/blueprint/connection-detail/index.tsx
@@ -58,9 +58,10 @@ export const BlueprintConnectionDetailPage = () => {
       API.getDataScopes(plugin, connectionId),
     ]);
 
-    const scopeIds = blueprint.settings.connections
-      .find((cs: any) => cs.plugin === plugin && cs.connectionId === +connectionId)
-      .scopes.map((sc: any) => sc.id);
+    const scopeIds =
+      blueprint.connections
+        .find((cs) => cs.pluginName === plugin && cs.connectionId === +connectionId)
+        ?.scopes?.map((sc: any) => sc.scopeId) ?? [];
 
     return {
       blueprint,
@@ -114,12 +115,9 @@ export const BlueprintConnectionDetailPage = () => {
     const [success] = await operator(() =>
       API.updateBlueprint(blueprint.id, {
         ...blueprint,
-        settings: {
-          ...blueprint.settings,
-          connections: blueprint.settings.connections.filter(
-            (cs: any) => !(cs.plugin === connection.plugin && cs.connectionId === connection.id),
-          ),
-        },
+        connections: blueprint.connections.filter(
+          (cs) => !(cs.pluginName === connection.plugin && cs.connectionId === connection.id),
+        ),
       }),
     );
 
@@ -136,18 +134,15 @@ export const BlueprintConnectionDetailPage = () => {
       () =>
         API.updateBlueprint(blueprint.id, {
           ...blueprint,
-          settings: {
-            ...blueprint.settings,
-            connections: blueprint.settings.connections.map((cs: any) => {
-              if (cs.plugin === connection.plugin && cs.connectionId === connection.id) {
-                return {
-                  ...cs,
-                  scopes: scope.map((sc: any) => ({ id: getPluginScopeId(connection.plugin, sc) })),
-                };
-              }
-              return cs;
-            }),
-          },
+          connections: blueprint.connections.map((cs) => {
+            if (cs.pluginName === connection.plugin && cs.connectionId === connection.id) {
+              return {
+                ...cs,
+                scopes: scope.map((sc: any) => ({ id: getPluginScopeId(connection.plugin, sc) })),
+              };
+            }
+            return cs;
+          }),
         }),
       {
         formatMessage: () => 'Update data scope successful.',
diff --git a/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx b/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
index d694ad3f5..f5c586634 100644
--- a/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
+++ b/config-ui/src/pages/blueprint/detail/components/update-policy-dialog/index.tsx
@@ -54,13 +54,7 @@ export const UpdatePolicyDialog = ({ blueprint, operating, onCancel, onSubmit, .
       isManual,
       cronConfig,
       skipOnFail,
-      settings:
-        blueprint.mode === ModeEnum.normal
-          ? {
-              ...blueprint.settings,
-              timeAfter,
-            }
-          : undefined,
+      timeAfter,
     });
   };
 
diff --git a/config-ui/src/pages/blueprint/detail/configuration-panel.tsx b/config-ui/src/pages/blueprint/detail/configuration-panel.tsx
index d56714110..9bd6b21aa 100644
--- a/config-ui/src/pages/blueprint/detail/configuration-panel.tsx
+++ b/config-ui/src/pages/blueprint/detail/configuration-panel.tsx
@@ -56,13 +56,12 @@ export const ConfigurationPanel = ({ from, blueprint, onRefresh, onChangeTab }:
 
   const connections = useMemo(
     () =>
-      blueprint.settings?.connections
-        .filter((cs) => cs.plugin !== 'webhook')
+      blueprint.connections
+        .filter((cs) => cs.pluginName !== 'webhook')
         .map((cs: any) => {
-          const unique = `${cs.plugin}-${cs.connectionId}`;
-          const plugin = getPluginConfig(cs.plugin);
+          const unique = `${cs.pluginName}-${cs.connectionId}`;
+          const plugin = getPluginConfig(cs.pluginName);
           const connection = onGet(unique);
-
           return {
             unique,
             icon: plugin.icon,
@@ -163,7 +162,7 @@ export const ConfigurationPanel = ({ from, blueprint, onRefresh, onChangeTab }:
           ]}
           dataSource={[
             {
-              timeRange: blueprint?.settings?.timeAfter,
+              timeRange: blueprint.timeAfter,
               frequency: blueprint.cronConfig,
               isManual: blueprint.isManual,
               skipFailed: blueprint.skipOnFail,
@@ -263,7 +262,7 @@ export const ConfigurationPanel = ({ from, blueprint, onRefresh, onChangeTab }:
           isManual={blueprint.isManual}
           cronConfig={blueprint.cronConfig}
           skipOnFail={blueprint.skipOnFail}
-          timeAfter={blueprint.settings?.timeAfter}
+          timeAfter={blueprint.timeAfter}
           operating={operating}
           onCancel={handleCancel}
           onSubmit={(payload) => handleUpdate(payload)}
@@ -275,7 +274,7 @@ export const ConfigurationPanel = ({ from, blueprint, onRefresh, onChangeTab }:
           onCancel={handleCancel}
           onSubmit={(connection) =>
             handleUpdate({
-              settings: { ...blueprint.settings, connections: [...blueprint.settings.connections, connection] },
+              connections: [...blueprint.connections, connection],
             })
           }
         />
diff --git a/config-ui/src/pages/blueprint/home/index.tsx b/config-ui/src/pages/blueprint/home/index.tsx
index 1541bb657..fb6ca4b63 100644
--- a/config-ui/src/pages/blueprint/home/index.tsx
+++ b/config-ui/src/pages/blueprint/home/index.tsx
@@ -52,9 +52,9 @@ export const BlueprintHomePage = () => {
     () => [
       (data?.blueprints ?? []).map((it) => {
         const connections =
-          it.settings?.connections
-            .filter((cs) => cs.plugin !== 'webhook')
-            .map((cs) => onGet(`${cs.plugin}-${cs.connectionId}`) || `${cs.plugin}-${cs.connectionId}`) ?? [];
+          it.connections
+            .filter((cs) => cs.pluginName !== 'webhook')
+            .map((cs) => onGet(`${cs.pluginName}-${cs.connectionId}`) || `${cs.pluginName}-${cs.connectionId}`) ?? [];
         return {
           ...it,
           connections: connections.map((cs) => cs.name),
diff --git a/config-ui/src/pages/blueprint/types.ts b/config-ui/src/pages/blueprint/types.ts
index 2c498e9c4..ff9660fd9 100644
--- a/config-ui/src/pages/blueprint/types.ts
+++ b/config-ui/src/pages/blueprint/types.ts
@@ -36,15 +36,12 @@ export type BlueprintType = {
   cronConfig: string;
   skipOnFail: boolean;
   plan: any;
-  settings: {
-    version: string;
-    timeAfter: null | string;
-    connections: Array<{
-      plugin: string;
-      connectionId: ID;
-      scopes?: Array<{
-        id: string;
-      }>;
+  timeAfter: null | string;
+  connections: Array<{
+    pluginName: string;
+    connectionId: ID;
+    scopes?: Array<{
+      scopeId: string;
     }>;
-  };
+  }>;
 };
diff --git a/config-ui/src/pages/project/detail/webhooks-panel.tsx b/config-ui/src/pages/project/detail/webhooks-panel.tsx
index 343926d9f..ceda24020 100644
--- a/config-ui/src/pages/project/detail/webhooks-panel.tsx
+++ b/config-ui/src/pages/project/detail/webhooks-panel.tsx
@@ -40,9 +40,7 @@ export const WebhooksPanel = ({ project, onRefresh }: Props) => {
   const webhookIds = useMemo(
     () =>
       project.blueprint
-        ? project.blueprint.settings.connections
-            .filter((cs: any) => cs.plugin === 'webhook')
-            .map((cs: any) => cs.connectionId)
+        ? project.blueprint.connections.filter((cs) => cs.pluginName === 'webhook').map((cs: any) => cs.connectionId)
         : [],
     [project],
   );
@@ -55,9 +53,9 @@ export const WebhooksPanel = ({ project, onRefresh }: Props) => {
     const payload = {
       ...project.blueprint,
       settings: {
-        ...project.blueprint.settings,
+        ...project.blueprint,
         connections: [
-          ...project.blueprint.settings.connections,
+          ...project.blueprint.connections,
           {
             plugin: 'webhook',
             connectionId: id,
@@ -78,16 +76,13 @@ export const WebhooksPanel = ({ project, onRefresh }: Props) => {
   const handleSelect = async (items: WebhookItemType[]) => {
     const payload = {
       ...project.blueprint,
-      settings: {
-        ...project.blueprint.settings,
-        connections: [
-          ...project.blueprint.settings.connections,
-          ...items.map((it) => ({
-            plugin: 'webhook',
-            connectionId: it.id,
-          })),
-        ],
-      },
+      connections: [
+        ...project.blueprint.connections,
+        ...items.map((it) => ({
+          pluginName: 'webhook',
+          connectionId: it.id,
+        })),
+      ],
     };
 
     const [success] = await operator(() => API.updateBlueprint(project.blueprint.id, payload), {
@@ -102,12 +97,9 @@ export const WebhooksPanel = ({ project, onRefresh }: Props) => {
   const handleDelete = async (id: ID) => {
     const payload = {
       ...project.blueprint,
-      settings: {
-        ...project.blueprint.settings,
-        connections: project.blueprint.settings.connections.filter(
-          (cs: any) => !(cs.plugin === 'webhook' && cs.connectionId === id),
-        ),
-      },
+      connections: project.blueprint.connections.filter(
+        (cs) => !(cs.pluginName === 'webhook' && cs.connectionId === id),
+      ),
     };
 
     const [success] = await operator(() => API.updateBlueprint(project.blueprint.id, payload), {
diff --git a/config-ui/src/pages/project/home/index.tsx b/config-ui/src/pages/project/home/index.tsx
index 79dca269c..9304dabc9 100644
--- a/config-ui/src/pages/project/home/index.tsx
+++ b/config-ui/src/pages/project/home/index.tsx
@@ -54,7 +54,7 @@ export const ProjectHomePage = () => {
       (data?.projects ?? []).map((it) => {
         return {
           name: it.name,
-          connections: it.blueprint?.settings.connections,
+          connections: it.blueprint?.connections,
           isManual: it.blueprint?.isManual,
           cronConfig: it.blueprint?.cronConfig,
           createdAt: it.createdAt,
@@ -141,12 +141,12 @@ export const ProjectHomePage = () => {
             title: 'Data Connections',
             dataIndex: 'connections',
             key: 'connections',
-            render: (val: BlueprintType['settings']['connections']) =>
+            render: (val: BlueprintType['connections']) =>
               !val || !val.length
                 ? 'N/A'
                 : val
                     .map((it) => {
-                      const cs = onGet(`${it.plugin}-${it.connectionId}`);
+                      const cs = onGet(`${it.pluginName}-${it.connectionId}`);
                       return cs?.name;
                     })
                     .join(', '),