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

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


The following commit(s) were added to refs/heads/main by this push:
     new edc44e1f1 fix(config-ui): incorrect scope id type (#5572)
edc44e1f1 is described below

commit edc44e1f100122aab6e74d5767dbb8f1e741fbc6
Author: 青湛 <[email protected]>
AuthorDate: Fri Jun 30 00:09:51 2023 +1200

    fix(config-ui): incorrect scope id type (#5572)
    
    * fix(config-ui): incorrect scope id type
    
    * fix(config-ui): the type for component table
    
    * refactor(config-ui): remove plugin utils getPluginId
---
 config-ui/src/components/table/components/content.tsx |  4 +++-
 .../src/components/table/hooks/use-row-selection.ts   |  4 ++--
 config-ui/src/components/table/types.ts               |  2 +-
 config-ui/src/pages/connection/detail/index.tsx       | 10 ++++------
 .../plugins/components/data-scope-select/index.tsx    |  2 +-
 .../plugins/components/scope-config-select/index.tsx  |  1 -
 config-ui/src/plugins/utils.ts                        | 19 -------------------
 7 files changed, 11 insertions(+), 31 deletions(-)

diff --git a/config-ui/src/components/table/components/content.tsx 
b/config-ui/src/components/table/components/content.tsx
index 9b288827d..a77a283cf 100644
--- a/config-ui/src/components/table/components/content.tsx
+++ b/config-ui/src/components/table/components/content.tsx
@@ -73,7 +73,9 @@ export const TableContent = <T extends Record<string, any>>({
               </S.TD>
             )}
             {columns.map(({ key, width, align = 'left', ellipsis, dataIndex, 
render }) => {
-              const value = Array.isArray(dataIndex)
+              const value = !dataIndex
+                ? null
+                : Array.isArray(dataIndex)
                 ? dataIndex.reduce((acc, cur) => {
                     acc[cur] = data[cur];
                     return acc;
diff --git a/config-ui/src/components/table/hooks/use-row-selection.ts 
b/config-ui/src/components/table/hooks/use-row-selection.ts
index 41fcd0fb1..5342811f8 100644
--- a/config-ui/src/components/table/hooks/use-row-selection.ts
+++ b/config-ui/src/components/table/hooks/use-row-selection.ts
@@ -33,13 +33,13 @@ export const useRowSelection = <T>({ dataSource, 
rowSelection }: UseRowSelection
   const [selectedKeys, setSelectedKeys] = useState<ID[]>([]);
 
   const {
-    rowKey = 'key',
+    rowKey = 'id',
     getRowKey = (data: T) => (data as any)[rowKey],
     type = 'checkbox',
     selectedRowKeys,
     onChange,
   } = {
-    rowKey: 'key',
+    rowKey: 'id',
     type: 'checkbox',
     ...rowSelection,
   };
diff --git a/config-ui/src/components/table/types.ts 
b/config-ui/src/components/table/types.ts
index 7f19de446..44d282912 100644
--- a/config-ui/src/components/table/types.ts
+++ b/config-ui/src/components/table/types.ts
@@ -18,7 +18,7 @@
 
 export type ColumnType<T> = Array<{
   title: string;
-  dataIndex: string | string[];
+  dataIndex?: string | string[];
   key: string;
   width?: number;
   align?: 'left' | 'center' | 'right';
diff --git a/config-ui/src/pages/connection/detail/index.tsx 
b/config-ui/src/pages/connection/detail/index.tsx
index 5fc2e3311..f0ef64f6d 100644
--- a/config-ui/src/pages/connection/detail/index.tsx
+++ b/config-ui/src/pages/connection/detail/index.tsx
@@ -28,7 +28,6 @@ import {
   ConnectionStatus,
   DataScopeSelectRemote,
   getPluginConfig,
-  getPluginId,
   getPluginScopeId,
   ScopeConfigForm,
   ScopeConfigSelect,
@@ -294,20 +293,19 @@ const ConnectionDetail = ({ plugin, connectionId }: 
Props) => {
             },
             {
               title: '',
-              dataIndex: getPluginId(plugin),
               key: 'id',
               width: 100,
-              render: (id) => (
+              render: (_, row) => (
                 <>
                   <IconButton
                     image={<img src={ClearImg} alt="clear" />}
                     tooltip="Clear historical data"
-                    onClick={() => handleShowClearDataScopeDialog(id)}
+                    onClick={() => 
handleShowClearDataScopeDialog(getPluginScopeId(plugin, row))}
                   />
                   <IconButton
                     icon="trash"
                     tooltip="Delete Data Scope"
-                    onClick={() => handleShowDeleteDataScopeDialog(id)}
+                    onClick={() => 
handleShowDeleteDataScopeDialog(getPluginScopeId(plugin, row))}
                   />
                 </>
               ),
@@ -320,7 +318,7 @@ const ConnectionDetail = ({ plugin, connectionId }: Props) 
=> {
             onCreate: handleShowCreateDataScopeDialog,
           }}
           rowSelection={{
-            rowKey: getPluginId(plugin),
+            getRowKey: (row) => getPluginScopeId(plugin, row),
             selectedRowKeys: scopeIds,
             onChange: (selectedRowKeys) => setScopeIds(selectedRowKeys),
           }}
diff --git a/config-ui/src/plugins/components/data-scope-select/index.tsx 
b/config-ui/src/plugins/components/data-scope-select/index.tsx
index 4a3b57daa..4542c7e2f 100644
--- a/config-ui/src/plugins/components/data-scope-select/index.tsx
+++ b/config-ui/src/plugins/components/data-scope-select/index.tsx
@@ -21,7 +21,7 @@ import { Button, Intent } from '@blueprintjs/core';
 
 import { PageLoading, FormItem, ExternalLink, Message, Buttons, Table } from 
'@/components';
 import { useRefreshData } from '@/hooks';
-import { getPluginId, getPluginScopeId } from '@/plugins';
+import { getPluginScopeId } from '@/plugins';
 
 import * as API from './api';
 import * as S from './styled';
diff --git a/config-ui/src/plugins/components/scope-config-select/index.tsx 
b/config-ui/src/plugins/components/scope-config-select/index.tsx
index 974d6d88c..50bf5650c 100644
--- a/config-ui/src/plugins/components/scope-config-select/index.tsx
+++ b/config-ui/src/plugins/components/scope-config-select/index.tsx
@@ -88,7 +88,6 @@ export const ScopeConfigSelect = ({ plugin, connectionId, 
scopeConfigId, onCance
         ]}
         dataSource={dataSource}
         rowSelection={{
-          rowKey: 'id',
           type: 'radio',
           selectedRowKeys: trId ? [trId] : [],
           onChange: (selectedRowKeys) => setTrId(selectedRowKeys[0]),
diff --git a/config-ui/src/plugins/utils.ts b/config-ui/src/plugins/utils.ts
index b6b5f2a0c..d851f41f0 100644
--- a/config-ui/src/plugins/utils.ts
+++ b/config-ui/src/plugins/utils.ts
@@ -21,25 +21,6 @@ import PluginIcon from '@/images/plugin-icon.svg';
 import { PluginConfig } from './config';
 import { PluginConfigType, PluginType } from './types';
 
-export const getPluginId = (plugin: string) => {
-  switch (plugin) {
-    case 'github':
-      return 'githubId';
-    case 'jira':
-      return 'boardId';
-    case 'gitlab':
-      return 'gitlabId';
-    case 'jenkins':
-      return 'jobFullName';
-    case 'bitbucket':
-      return 'bitbucketId';
-    case 'sonarqube':
-      return 'projectKey';
-    default:
-      return 'id';
-  }
-};
-
 export const getPluginScopeId = (plugin: string, scope: any) => {
   switch (plugin) {
     case 'github':

Reply via email to