21225: Move progressWrapper to data explorer for conditional styles
[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 { toggleMSToolbar, setCheckedListOnStore } from "store/multiselect/multiselect-actions";
15 import { setSelectedResourceUuid } from "store/selected-resource/selected-resource-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, selectedResourceUuid, properties, searchBar}: RootState, { id }: Props) => {
27     const working = !!progressIndicator.some(p => p.working);
28     const dataExplorerState = getDataExplorer(dataExplorer, id);
29     const currentRoute = router.location ? router.location.pathname : "";
30     const isMSToolbarVisible = multiselect.isVisible;
31     return {
32         ...dataExplorerState,
33         currentRoute: currentRoute,
34         paperKey: currentRoute,
35         currentRouteUuid: properties.currentRouteUuid,
36         isMSToolbarVisible,
37         selectedResourceUuid,
38         checkedList: multiselect.checkedList,
39         working,
40         searchBarValue: searchBar.searchValue,
41     };
42 };
43
44 const mapDispatchToProps = () => {
45     return (dispatch: Dispatch, { id, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
46         onSetColumns: (columns: DataColumns<any, any>) => {
47             dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
48         },
49
50         onSearch: (searchValue: string) => {
51             dispatch(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id, searchValue }));
52         },
53
54         onColumnToggle: (column: DataColumn<any, any>) => {
55             dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
56         },
57
58         onSortToggle: (column: DataColumn<any, any>) => {
59             dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
60         },
61
62         onFiltersChange: (filters: DataTableFilters, column: DataColumn<any, any>) => {
63             dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
64         },
65
66         onChangePage: (page: number) => {
67             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
68         },
69
70         onChangeRowsPerPage: (rowsPerPage: number) => {
71             dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
72         },
73
74         onLoadMore: (page: number) => {
75             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
76         },
77
78         toggleMSToolbar: (isVisible: boolean) => {
79             dispatch<any>(toggleMSToolbar(isVisible));
80         },
81
82         setCheckedListOnStore: (checkedList: TCheckedList) => {
83             dispatch<any>(setCheckedListOnStore(checkedList));
84         },
85
86         setSelectedUuid: (uuid: string | null) => {
87             dispatch<any>(setSelectedResourceUuid(uuid));
88         },
89         
90         onRowClick,
91
92         onRowDoubleClick,
93
94         onContextMenu,
95     });
96 };
97
98 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);