]> git.arvados.org - arvados.git/blob - services/workbench2/src/views-components/data-explorer/data-explorer.tsx
22408: added condition for >1 selected
[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, DataColumns, } from "components/data-table/data-column";
12 import { TCheckedList } from "components/data-table/data-table";
13 import { DataTableFilters } from "components/data-table-filters/data-table-filters";
14 import { toggleMSToolbar, setCheckedListOnStore } from "store/multiselect/multiselect-actions";
15 import { setSelectedResourceUuid, setIsSelectedResourceInDataExplorer } from "store/selected-resource/selected-resource-actions";
16 import { usesDetailsCard } from "components/multiselect-toolbar/MultiselectToolbar";
17 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
18
19 interface Props {
20     id: string;
21     onRowClick: (item: any) => void;
22     onContextMenu?: (event: React.MouseEvent<HTMLElement>, item: any, isAdmin?: boolean) => void;
23     onRowDoubleClick: (item: any) => void;
24     extractKey?: (item: any) => React.Key;
25     working?: boolean;
26 }
27
28 const mapStateToProps = ({ progressIndicator, dataExplorer, router, multiselect, selectedResource, properties, searchBar, detailsPanel}: RootState, { id }: Props) => {
29     const working = progressIndicator.includes(id);
30     const dataExplorerState = getDataExplorer(dataExplorer, id);
31     const currentRoute = router.location ? router.location.pathname : "";
32     const isMSToolbarVisible = multiselect.isVisible;
33     return {
34         ...dataExplorerState,
35         path: currentRoute,
36         currentRouteUuid: properties.currentRouteUuid,
37         isMSToolbarVisible,
38         selectedResourceUuid: selectedResource.selectedResourceUuid,
39         isSelectedResourceInDataExplorer: selectedResource.isSelectedResourceInDataExplorer,
40         checkedList: multiselect.checkedList,
41         working,
42         searchBarValue: searchBar.searchValue,
43         detailsPanelResourceUuid: detailsPanel.resourceUuid,
44         isDetailsPanelOpen: detailsPanel.isOpened,
45     };
46 };
47
48 const mapDispatchToProps = () => {
49     return (dispatch: Dispatch, { id, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
50         onSetColumns: (columns: DataColumns<any, any>) => {
51             dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
52         },
53
54         onSearch: (searchValue: string) => {
55             dispatch(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id, searchValue }));
56         },
57
58         onColumnToggle: (column: DataColumn<any, any>) => {
59             dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
60         },
61
62         onSortToggle: (column: DataColumn<any, any>) => {
63             dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
64         },
65
66         onFiltersChange: (filters: DataTableFilters, column: DataColumn<any, any>) => {
67             dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
68         },
69
70         onPageChange: (page: number) => {
71             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
72         },
73
74         onChangeRowsPerPage: (rowsPerPage: number) => {
75             dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
76         },
77
78         onLoadMore: (page: number) => {
79             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
80         },
81
82         toggleMSToolbar: (isVisible: boolean) => {
83             dispatch<any>(toggleMSToolbar(isVisible));
84         },
85
86         setCheckedListOnStore: (checkedList: TCheckedList) => {
87             dispatch<any>(setCheckedListOnStore(checkedList));
88         },
89
90         setSelectedUuid: (uuid: string | null) => {
91             dispatch<any>(setSelectedResourceUuid(uuid));
92         },
93
94         loadDetailsPanel: (uuid: string) => {
95             dispatch<any>(loadDetailsPanel(uuid || ''));
96         },
97
98         setIsSelectedResourceInDataExplorer: (isIn: boolean) => {
99             dispatch<any>(setIsSelectedResourceInDataExplorer(isIn));
100         },
101
102         onRowClick,
103
104         onRowDoubleClick,
105
106         onContextMenu,
107
108         usesDetailsCard,
109     });
110 };
111
112 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);