Small refactor (#232)
because `canSelectAll` is false there is no need for this check
This commit is contained in:
parent
17b1fab80e
commit
cf95b7184d
1 changed files with 19 additions and 31 deletions
|
@ -59,37 +59,25 @@ export const GroupsList = ({
|
||||||
setFormattedData(formatData(list!));
|
setFormattedData(formatData(list!));
|
||||||
}, [list]);
|
}, [list]);
|
||||||
|
|
||||||
function onSelect(
|
function onSelect(isSelected: boolean, rowId: number) {
|
||||||
_: React.FormEvent<HTMLInputElement>,
|
const localRow = [...formattedData];
|
||||||
isSelected: boolean,
|
const localTableRow = [...tableRowSelectedArray];
|
||||||
rowId: number
|
if (localRow[rowId].selected !== isSelected) {
|
||||||
) {
|
localRow[rowId].selected = isSelected;
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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") }];
|
const tableHeader = [{ title: t("groupName") }, { title: t("members") }];
|
||||||
|
@ -122,7 +110,7 @@ export const GroupsList = ({
|
||||||
<Table
|
<Table
|
||||||
actions={actions}
|
actions={actions}
|
||||||
variant={TableVariant.compact}
|
variant={TableVariant.compact}
|
||||||
onSelect={onSelect}
|
onSelect={(_, isSelected, rowId) => onSelect(isSelected, rowId)}
|
||||||
canSelectAll={false}
|
canSelectAll={false}
|
||||||
aria-label={t("tableOfGroups")}
|
aria-label={t("tableOfGroups")}
|
||||||
cells={tableHeader}
|
cells={tableHeader}
|
||||||
|
|
Loading…
Reference in a new issue