From: Lisa Knox Date: Tue, 25 Apr 2023 14:40:05 +0000 (-0400) Subject: 15768: remote select/unselect works Arvados-DCO-1.1-Signed-off-by: Lisa Knox --- diff --git a/src/components/data-explorer/data-explorer.tsx b/src/components/data-explorer/data-explorer.tsx index ea95648e..685d6bc1 100644 --- a/src/components/data-explorer/data-explorer.tsx +++ b/src/components/data-explorer/data-explorer.tsx @@ -238,6 +238,7 @@ export const DataExplorer = withStyles(styles)( defaultViewMessages={defaultViewMessages} currentItemUuid={currentItemUuid} currentRoute={paperKey} + checkedList={{}} /> diff --git a/src/components/data-table/data-table.tsx b/src/components/data-table/data-table.tsx index e2ee6951..2bb48a3c 100644 --- a/src/components/data-table/data-table.tsx +++ b/src/components/data-table/data-table.tsx @@ -90,61 +90,83 @@ const styles: StyleRulesCallback = (theme: Theme) => ({ }, }); -//master list for all things checked and unchecked -const checkedList: Record = {}; - -const initializeCheckedList = (items: any[]): void => { - for (const uuid in checkedList) { - if (checkedList.hasOwnProperty(uuid)) { - delete checkedList[uuid]; - } - } - items.forEach((uuid) => { - if (!checkedList.hasOwnProperty[uuid]) { - checkedList[uuid] = false; - } - }); -}; - -const handleResourceSelect = (uuid: string) => { - if (!checkedList[uuid]) { - checkedList[uuid] = true; - } else { - checkedList[uuid] = false; - } - console.log(checkedList); -}; - const handleSelectAll = () => {}; const handleDeselectAll = () => {}; -const checkBoxColumn: DataColumn = { - name: '', - selected: true, - configurable: false, - filters: createTree(), - render: (item) => { - return handleResourceSelect(item)} />; - }, +type DataTableState = { + checkedList: Record; }; -type DataTableProps = DataTableDataProps & WithStyles; +type DataTableProps = DataTableDataProps & WithStyles & DataTableState; 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); + } + checkBoxColumn: DataColumn = { + name: 'checkBoxColumn', + selected: true, + configurable: false, + filters: createTree(), + render: (uuid) => { + return this.handleResourceSelect(uuid)}>; + }, + }; + initializeCheckedList = (items: any[]): void => { + const checkedList = this.state; + for (const uuid in checkedList) { + if (checkedList.hasOwnProperty(uuid)) { + delete checkedList[uuid]; + } + } + items.forEach((uuid) => { + if (!checkedList.hasOwnProperty[uuid]) { + 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 { if (prevProps.items !== this.props.items) { - console.log('hi'); - initializeCheckedList(this.props.items); + this.initializeCheckedList(this.props.items); } } render() { const { items, classes, working, columns } = this.props; - if (columns[0] !== checkBoxColumn) columns.unshift(checkBoxColumn); + if (columns[0].name !== this.checkBoxColumn.name) columns.unshift(this.checkBoxColumn); + const firstBox: HTMLInputElement | null = document.querySelector('input[type="checkbox"]'); return (
+ + {/* */} {this.mapVisibleColumns(this.renderHeadCell)}