X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6f3e2cd586172574f2b6ee0f03fc5c79e7ce3b32..8169b80dda901b6a628af000e2f2bd12b3489f50:/services/workbench2/src/components/data-table/data-table.tsx diff --git a/services/workbench2/src/components/data-table/data-table.tsx b/services/workbench2/src/components/data-table/data-table.tsx index 7b78799457..7629034f9d 100644 --- a/services/workbench2/src/components/data-table/data-table.tsx +++ b/services/workbench2/src/components/data-table/data-table.tsx @@ -29,6 +29,7 @@ import { SvgIconProps } from "@material-ui/core/SvgIcon"; import ArrowDownwardIcon from "@material-ui/icons/ArrowDownward"; import { createTree } from "models/tree"; import { DataTableMultiselectOption } from "../data-table-multiselect-popover/data-table-multiselect-popover"; +import { isExactlyOneSelected } from "store/multiselect/multiselect-actions"; import { PendingIcon } from "components/icon/icon"; export type DataColumns = Array>; @@ -50,11 +51,13 @@ export interface DataTableDataProps { working?: boolean; defaultViewIcon?: IconType; defaultViewMessages?: string[]; - currentItemUuid?: string; - currentRoute?: string; toggleMSToolbar: (isVisible: boolean) => void; setCheckedListOnStore: (checkedList: TCheckedList) => void; + currentRoute?: string; + currentRouteUuid: string; checkedList: TCheckedList; + selectedResourceUuid: string; + setSelectedUuid: (uuid: string | null) => void; isNotFound?: boolean; } @@ -156,18 +159,34 @@ export const DataTable = withStyles(styles)( componentDidMount(): void { this.initializeCheckedList([]); + // If table is initialized loaded but empty + // isLoaded won't be set true by componentDidUpdate later + // So we set it to true here + if (!this.props.working) { + this.setState({ isLoaded: true }); + } } componentDidUpdate(prevProps: Readonly>, prevState: DataTableState) { - const { items, setCheckedListOnStore } = this.props; + const { items, currentRouteUuid, setCheckedListOnStore } = this.props; const { isSelected } = this.state; + const singleSelected = isExactlyOneSelected(this.props.checkedList); if (prevProps.items !== items) { if (isSelected === true) this.setState({ isSelected: false }); if (items.length) this.initializeCheckedList(items); else setCheckedListOnStore({}); } if (prevProps.currentRoute !== this.props.currentRoute) { - this.initializeCheckedList([]) + this.initializeCheckedList([]); + } + if (singleSelected && singleSelected !== isExactlyOneSelected(prevProps.checkedList)) { + this.props.setSelectedUuid(singleSelected); + } + if (!singleSelected && !!currentRouteUuid && !this.isAnySelected()) { + this.props.setSelectedUuid(currentRouteUuid); + } + if (!singleSelected && this.isAnySelected()) { + this.props.setSelectedUuid(null); } if(prevProps.working === true && this.props.working === false) { this.setState({ isLoaded: true }); @@ -178,7 +197,7 @@ export const DataTable = withStyles(styles)( } componentWillUnmount(): void { - this.initializeCheckedList([]) + this.initializeCheckedList([]); } checkBoxColumn: DataColumn = { @@ -220,11 +239,12 @@ export const DataTable = withStyles(styles)( initializeCheckedList = (uuids: any[]): void => { const newCheckedList = { ...this.props.checkedList }; - uuids.forEach(uuid => { - if (!newCheckedList.hasOwnProperty(uuid)) { - newCheckedList[uuid] = false; + if(Object.keys(newCheckedList).length === 0){ + for(const uuid of uuids){ + newCheckedList[uuid] = false } - }); + } + for (const key in newCheckedList) { if (!uuids.includes(key)) { delete newCheckedList[key]; @@ -320,17 +340,17 @@ export const DataTable = withStyles(styles)( const dirty = columns.some(column => getTreeDirty("")(column.filters)); if (isNotFound && isLoaded) { return ( - ); - } else + } else if (isLoaded === false || working === true) { return ( - ); } else { @@ -354,7 +374,7 @@ export const DataTable = withStyles(styles)( key={key || index} className={classes.checkBoxCell}>
- + { - const { onRowClick, onRowDoubleClick, extractKey, classes, currentItemUuid, currentRoute } = this.props; + const { onRowClick, onRowDoubleClick, extractKey, classes, selectedResourceUuid, currentRoute } = this.props; return ( onRowClick && onRowClick(event, item)} onContextMenu={this.handleRowContextMenu(item)} onDoubleClick={event => onRowDoubleClick && onRowDoubleClick(event, item)} - selected={item === currentItemUuid}> + selected={item === selectedResourceUuid}> {this.mapVisibleColumns((column, index) => (