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 395d21477 fix: scope selection is not working (#5576)
395d21477 is described below
commit 395d21477453024f112e614e84ceeca276b794c9
Author: Klesh Wong <[email protected]>
AuthorDate: Mon Jun 26 16:51:08 2023 +0800
fix: scope selection is not working (#5576)
---
config-ui/src/components/table/hooks/use-row-selection.ts | 10 ++++++----
config-ui/src/plugins/components/data-scope-select/index.tsx | 2 +-
2 files changed, 7 insertions(+), 5 deletions(-)
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 ab56bdd81..41fcd0fb1 100644
--- a/config-ui/src/components/table/hooks/use-row-selection.ts
+++ b/config-ui/src/components/table/hooks/use-row-selection.ts
@@ -21,7 +21,8 @@ import { useState, useEffect, useMemo } from 'react';
export interface UseRowSelectionProps<T> {
dataSource: T[];
rowSelection?: {
- rowKey: ID;
+ rowKey?: ID;
+ getRowKey?: (data: T) => ID;
type?: 'checkbox' | 'radio';
selectedRowKeys?: ID[];
onChange?: (selectedRowKeys: ID[]) => void;
@@ -33,6 +34,7 @@ export const useRowSelection = <T>({ dataSource, rowSelection
}: UseRowSelection
const {
rowKey = 'key',
+ getRowKey = (data: T) => (data as any)[rowKey],
type = 'checkbox',
selectedRowKeys,
onChange,
@@ -47,7 +49,7 @@ export const useRowSelection = <T>({ dataSource, rowSelection
}: UseRowSelection
}, [selectedRowKeys]);
const handleChecked = (data: T) => {
- const key = (data as any)[rowKey];
+ const key = getRowKey(data);
let result: ID[] = selectedKeys;
switch (true) {
@@ -69,7 +71,7 @@ export const useRowSelection = <T>({ dataSource, rowSelection
}: UseRowSelection
let result: string[] = [];
if (selectedKeys.length !== dataSource.length) {
- result = dataSource.map((data: any) => data[rowKey]);
+ result = dataSource.map(getRowKey);
}
onChange ? onChange(result) : setSelectedKeys(result);
@@ -82,7 +84,7 @@ export const useRowSelection = <T>({ dataSource, rowSelection
}: UseRowSelection
getCheckedAll: () => dataSource.length === selectedKeys.length,
onCheckedAll: handleCheckedAll,
getChecked: (data: T) => {
- return selectedKeys.includes((data as any)[rowKey]);
+ return selectedKeys.includes(getRowKey(data));
},
onChecked: handleChecked,
}),
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 fc26b5249..4a3b57daa 100644
--- a/config-ui/src/plugins/components/data-scope-select/index.tsx
+++ b/config-ui/src/plugins/components/data-scope-select/index.tsx
@@ -122,7 +122,7 @@ export const DataScopeSelect = ({
]}
dataSource={data}
rowSelection={{
- rowKey: getPluginId(plugin),
+ getRowKey: (data) => getPluginScopeId(plugin, data),
type: 'checkbox',
selectedRowKeys: scopeIds as string[],
onChange: (selectedRowKeys) => setScopeIds(selectedRowKeys),