Skip to content

Commit

Permalink
fix api dataset select all
Browse files Browse the repository at this point in the history
  • Loading branch information
newfish-cmyk committed Jan 16, 2025
1 parent 2d82db0 commit 271cc56
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,20 @@ const CustomAPIFileInput = () => {
[selectFiles]
);

const handleSelectAll = useCallback(() => {
const isAllSelected = fileList.length === selectFiles.length;
const isAllSelected = useMemo(() => {
const validSelectFiles = selectFiles.filter((file) =>
fileList.some((apiFile) => apiFile.id === file.id)
);
return fileList.length === validSelectFiles.length;
}, [fileList, selectFiles]);

const handleSelectAll = useCallback(() => {
if (isAllSelected) {
setSelectFiles([]);
} else {
setSelectFiles(fileList);
}
}, [fileList, selectFiles]);
}, [fileList, isAllSelected]);

return (
<MyBox isLoading={loading} position="relative" h="full">
Expand Down Expand Up @@ -199,7 +204,7 @@ const CustomAPIFileInput = () => {
<Checkbox
className="checkbox"
mr={2}
isChecked={fileList.length === selectFiles.length}
isChecked={isAllSelected}
onChange={handleSelectAll}
/>
{t('common:Select_all')}
Expand Down

0 comments on commit 271cc56

Please sign in to comment.