Feat: Batch operations on documents in a dataset #3221 (#7352)

### What problem does this PR solve?

Feat: Batch operations on documents in a dataset #3221

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-04-27 17:00:41 +08:00
committed by GitHub
parent 43e507d554
commit 6a45d93005
12 changed files with 181 additions and 203 deletions

View File

@ -0,0 +1,29 @@
import { RowSelectionState } from '@tanstack/react-table';
import { isEmpty } from 'lodash';
import { useMemo, useState } from 'react';
export function useRowSelection() {
const [rowSelection, setRowSelection] = useState<RowSelectionState>({});
return {
rowSelection,
setRowSelection,
rowSelectionIsEmpty: isEmpty(rowSelection),
};
}
export type UseRowSelectionType = ReturnType<typeof useRowSelection>;
export function useSelectedIds<T extends Array<{ id: string }>>(
rowSelection: RowSelectionState,
list: T,
) {
const selectedIds = useMemo(() => {
const indexes = Object.keys(rowSelection);
return list
.filter((x, idx) => indexes.some((y) => Number(y) === idx))
.map((x) => x.id);
}, [list, rowSelection]);
return { selectedIds };
}