refactor(ui): simplify table selection and clarify mobile label rendering

Addresses PR feedback:
- Removes over-abstracted useTableSelection hook, inlines selection logic
- Replaces triple-condition with explicit hideMobileLabel bool flag
- Removes unsafe Record<string, never> casting

Fixes #3602
This commit is contained in:
harsh-aghara committed 2026-05-05 17:06:48 +05:30
1 parent 657a35e948
commit 387cb35494
4 files changed
+41 -98

No files matched your search

-74
View File
@@ -1,74 +0,0 @@
import { useMemo, useCallback } from "react";
interface SelectableItem {
id: string;
}
interface UseTableSelectionReturn {
isAllSelected: boolean;
isSomeSelected: boolean;
handleSelectAll: (checked: boolean) => void;
handleSelectRow: (itemId: string, checked: boolean) => void;
isRowSelected: (itemId: string) => boolean;
}
export const useTableSelection = (
items: SelectableItem[],
selectedIds: string[],
onSelectionChange?: (selected: string[]) => void
): UseTableSelectionReturn => {
const selectedSet = useMemo(() => new Set(selectedIds), [selectedIds]);
const isAllSelected = useMemo(
() =>
items.length > 0 &&
items.every((item) => selectedSet.has(item.id)) &&
selectedIds.length >= items.length,
[items, selectedSet, selectedIds.length]
);
const isSomeSelected = useMemo(
() => selectedIds.length > 0 && !isAllSelected,
[selectedIds.length, isAllSelected]
);
const handleSelectAll = useCallback(
(checked: boolean) => {
if (onSelectionChange) {
if (checked) {
const allIds = items.map((item) => item.id);
onSelectionChange(allIds);
} else {
onSelectionChange([]);
}
}
},
[items, onSelectionChange]
);
const handleSelectRow = useCallback(
(itemId: string, checked: boolean) => {
if (onSelectionChange) {
if (checked) {
onSelectionChange([...selectedIds, itemId]);
} else {
onSelectionChange(selectedIds.filter((id) => id !== itemId));
}
}
},
[selectedIds, onSelectionChange]
);
const isRowSelected = useCallback(
(itemId: string) => selectedSet.has(itemId),
[selectedSet]
);
return {
isAllSelected,
isSomeSelected,
handleSelectAll,
handleSelectRow,
isRowSelected,
};
};