Skip to content

Commit

Permalink
fix: scope selection is not working (apache#5576)
Browse files Browse the repository at this point in the history
  • Loading branch information
klesh committed Jun 26, 2023
1 parent 90c2e1d commit 395d214
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions config-ui/src/components/table/hooks/use-row-selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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) {
Expand All @@ -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);
Expand All @@ -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,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit 395d214

Please sign in to comment.