mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### 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:
29
web/src/hooks/logic-hooks/use-row-selection.ts
Normal file
29
web/src/hooks/logic-hooks/use-row-selection.ts
Normal 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 };
|
||||
}
|
||||
Reference in New Issue
Block a user