Skip to content

Instantly share code, notes, and snippets.

@manstis
Created October 15, 2020 13:34
Show Gist options
  • Save manstis/e44716944ccfa4301009b9d815acc4df to your computer and use it in GitHub Desktop.
Save manstis/e44716944ccfa4301009b9d815acc4df to your computer and use it in GitHub Desktop.
export const CharacteristicsTable = (props: CharacteristicsTableProps) => {
const { characteristics, onRowClick, onRowDelete, onAddCharacteristic } = props;
interface DeleteCharacteristicProps {
index: number;
}
const DeleteCharacteristic = useCallback(
(_props: DeleteCharacteristicProps) => {
return (
<Button
variant="link"
icon={<TrashIcon />}
onClick={e => {
e.stopPropagation();
onRowDelete(_props.index);
}}
>
&nbsp;
</Button>
);
},
[characteristics]
);
const rows: IRow[] = useMemo(() => {
return characteristics.map<IRow>((c, index) => {
return {
cells: [
c.name,
<>
<Label key={index}>{c.Attribute.length}</Label>
</>,
c.reasonCode,
c.baselineScore,
<>
<DeleteCharacteristic key={index} index={index} />
</>
]
};
});
}, [characteristics]);
const rowClickHandler = (
event: React.MouseEvent,
row: IRow,
rowProps: IExtraRowData,
computedData: IComputedData
) => {
onRowClick(rowProps.rowIndex as number);
};
return (
<React.Fragment>
<Table aria-label="Characteristics" cells={columns} rows={rows}>
<TableHeader />
<TableBody onRowClick={rowClickHandler} />
</Table>
{rows.length === 0 && <EmptyStateNoCharacteristics createCharacteristic={onAddCharacteristic} />}
</React.Fragment>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment