Small refactor (#232)

because `canSelectAll` is false there is no need for this check
This commit is contained in:
Erik Jan de Wit 2020-11-30 20:30:44 +01:00 committed by GitHub
parent 17b1fab80e
commit cf95b7184d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -59,37 +59,25 @@ export const GroupsList = ({
setFormattedData(formatData(list!));
}, [list]);
function onSelect(
_: React.FormEvent<HTMLInputElement>,
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 = ({
<Table
actions={actions}
variant={TableVariant.compact}
onSelect={onSelect}
onSelect={(_, isSelected, rowId) => onSelect(isSelected, rowId)}
canSelectAll={false}
aria-label={t("tableOfGroups")}
cells={tableHeader}