From cf95b7184d48208b3df29eea634894c6c0b16f56 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 30 Nov 2020 20:30:44 +0100 Subject: [PATCH] Small refactor (#232) because `canSelectAll` is false there is no need for this check --- src/groups/GroupsList.tsx | 50 +++++++++++++++------------------------ 1 file changed, 19 insertions(+), 31 deletions(-) diff --git a/src/groups/GroupsList.tsx b/src/groups/GroupsList.tsx index a2514c3379..0f0afbbd00 100644 --- a/src/groups/GroupsList.tsx +++ b/src/groups/GroupsList.tsx @@ -59,37 +59,25 @@ export const GroupsList = ({ setFormattedData(formatData(list!)); }, [list]); - function onSelect( - _: React.FormEvent, - isSelected: boolean, - rowId: number - ) { - let localRow; - if (rowId === undefined) { - localRow = formattedData.map((row: { [key: string]: any }) => { - row.selected = isSelected; - return row; - }); - } else { - localRow = [...formattedData]; - const localTableRow = [...tableRowSelectedArray]; - if (localRow[rowId].selected !== isSelected) { - localRow[rowId].selected = isSelected; - } - - if (localTableRow.includes(rowId)) { - const index = localTableRow.indexOf(rowId); - if (index === 0) { - localTableRow.shift(); - } else { - localTableRow.splice(index, 1); - } - setTableRowSelectedArray(localTableRow); - } else { - setTableRowSelectedArray([rowId, ...tableRowSelectedArray]); - } - setFormattedData(localRow); + function onSelect(isSelected: boolean, rowId: number) { + const localRow = [...formattedData]; + const localTableRow = [...tableRowSelectedArray]; + if (localRow[rowId].selected !== isSelected) { + localRow[rowId].selected = isSelected; } + + if (localTableRow.includes(rowId)) { + const index = localTableRow.indexOf(rowId); + if (index === 0) { + localTableRow.shift(); + } else { + localTableRow.splice(index, 1); + } + setTableRowSelectedArray(localTableRow); + } else { + setTableRowSelectedArray([rowId, ...tableRowSelectedArray]); + } + setFormattedData(localRow); } const tableHeader = [{ title: t("groupName") }, { title: t("members") }]; @@ -122,7 +110,7 @@ export const GroupsList = ({ onSelect(isSelected, rowId)} canSelectAll={false} aria-label={t("tableOfGroups")} cells={tableHeader}