21224: removed dataexplorer component state Arvados-DCO-1.1-Signed-off-by: Lisa Knox...
[arvados.git] / services / workbench2 / src / views-components / data-explorer / data-explorer.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { connect } from "react-redux";
6 import { RootState } from "store/store";
7 import { DataExplorer as DataExplorerComponent } from "components/data-explorer/data-explorer";
8 import { getDataExplorer } from "store/data-explorer/data-explorer-reducer";
9 import { Dispatch } from "redux";
10 import { dataExplorerActions } from "store/data-explorer/data-explorer-action";
11 import { DataColumn } from "components/data-table/data-column";
12 import { DataColumns, TCheckedList } from "components/data-table/data-table";
13 import { DataTableFilters } from "components/data-table-filters/data-table-filters-tree";
14 import { LAST_REFRESH_TIMESTAMP } from "components/refresh-button/refresh-button";
15 import { toggleMSToolbar, setCheckedListOnStore } from "store/multiselect/multiselect-actions";
16
17 interface Props {
18     id: string;
19     onRowClick: (item: any) => void;
20     onContextMenu?: (event: React.MouseEvent<HTMLElement>, item: any, isAdmin?: boolean) => void;
21     onRowDoubleClick: (item: any) => void;
22     extractKey?: (item: any) => React.Key;
23     working?: boolean;
24 }
25
26 const mapStateToProps = ({ progressIndicator, dataExplorer, router, multiselect, detailsPanel, properties}: RootState, { id }: Props) => {
27     const working = !!progressIndicator.some(p => p.id === id && p.working);
28     const dataExplorerState = getDataExplorer(dataExplorer, id);
29     const currentRoute = router.location ? router.location.pathname : "";
30     // const currentRefresh = localStorage.getItem(LAST_REFRESH_TIMESTAMP) || "";
31     const isDetailsResourceChecked = multiselect.checkedList[detailsPanel.resourceUuid]
32     const isOnlyOneSelected = Object.values(multiselect.checkedList).filter(x => x === true).length === 1;
33     const currentItemUuid =
34         currentRoute === '/workflows' ? properties.workflowPanelDetailsUuid : isDetailsResourceChecked && isOnlyOneSelected ? detailsPanel.resourceUuid : multiselect.selectedUuid;
35     const isMSToolbarVisible = multiselect.isVisible;
36     return {
37         ...dataExplorerState,
38         // currentRefresh: currentRefresh,
39         currentRoute: currentRoute,
40         paperKey: currentRoute,
41         currentItemUuid,
42         isMSToolbarVisible,
43         checkedList: multiselect.checkedList,
44         working,
45         isNotFound: dataExplorerState.isNotFound,
46     };
47 };
48
49 const mapDispatchToProps = () => {
50     return (dispatch: Dispatch, { id, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
51         onSetColumns: (columns: DataColumns<any, any>) => {
52             dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
53         },
54
55         onSearch: (searchValue: string) => {
56             dispatch(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id, searchValue }));
57         },
58
59         onColumnToggle: (column: DataColumn<any, any>) => {
60             dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
61         },
62
63         onSortToggle: (column: DataColumn<any, any>) => {
64             dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
65         },
66
67         onFiltersChange: (filters: DataTableFilters, column: DataColumn<any, any>) => {
68             dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
69         },
70
71         onChangePage: (page: number) => {
72             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
73         },
74
75         onChangeRowsPerPage: (rowsPerPage: number) => {
76             dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
77         },
78
79         onLoadMore: (page: number) => {
80             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
81         },
82
83         toggleMSToolbar: (isVisible: boolean) => {
84             dispatch<any>(toggleMSToolbar(isVisible));
85         },
86
87         setCheckedListOnStore: (checkedList: TCheckedList) => {
88             dispatch<any>(setCheckedListOnStore(checkedList));
89         },
90
91         onRowClick,
92
93         onRowDoubleClick,
94
95         onContextMenu,
96     });
97 };
98
99 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);