From 24fc2a5a701dd4bb6edf503efee992942ea5b667 Mon Sep 17 00:00:00 2001 From: Lisa Knox Date: Tue, 25 Apr 2023 12:48:21 -0400 Subject: [PATCH] 15768: state update on checkbox tick Arvados-DCO-1.1-Signed-off-by: Lisa Knox --- src/components/data-table/data-table.tsx | 42 ++++++++---------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/components/data-table/data-table.tsx b/src/components/data-table/data-table.tsx index 2bb48a3c9e..6a02d7e6b1 100644 --- a/src/components/data-table/data-table.tsx +++ b/src/components/data-table/data-table.tsx @@ -102,23 +102,17 @@ type DataTableProps = DataTableDataProps & WithStyles & DataTabl export const DataTable = withStyles(styles)( class Component extends React.Component> { - constructor(props) { - super(props); - this.state = { - checkedList: {}, - }; - this.initializeCheckedList = this.initializeCheckedList.bind(this); - this.handleResourceSelect = this.handleResourceSelect.bind(this); - } + state: DataTableState = { + checkedList: {}, + }; checkBoxColumn: DataColumn = { name: 'checkBoxColumn', selected: true, configurable: false, filters: createTree(), - render: (uuid) => { - return this.handleResourceSelect(uuid)}>; - }, + render: (uuid) => this.handleCheck(uuid)}>, }; + initializeCheckedList = (items: any[]): void => { const checkedList = this.state; for (const uuid in checkedList) { @@ -131,24 +125,20 @@ export const DataTable = withStyles(styles)( checkedList[uuid] = false; } }); - console.log(this.state); - }; - - handleResourceSelect = (uuid: string) => { - const checkedList = this.state; - if (!checkedList[uuid]) { - checkedList[uuid] = true; - } else { - checkedList[uuid] = false; - } - console.log(checkedList); }; - componentDidUpdate(prevProps: Readonly>, prevState: Readonly<{}>, snapshot?: any): void { + componentDidUpdate(prevProps: Readonly>): void { if (prevProps.items !== this.props.items) { this.initializeCheckedList(this.props.items); } } + + handleCheck = async (uuid: string) => { + const checkedList = this.state; + const newCheckedList = { ...checkedList }; + newCheckedList[uuid] = !checkedList[uuid]; + await this.setState(newCheckedList); + }; render() { const { items, classes, working, columns } = this.props; if (columns[0].name !== this.checkBoxColumn.name) columns.unshift(this.checkBoxColumn); @@ -158,15 +148,11 @@ export const DataTable = withStyles(styles)(
- {/* */} {this.mapVisibleColumns(this.renderHeadCell)} -- 2.30.2