22198: Remove href field from API responses.
[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 } 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, selectedResourceUuid, properties, searchBar, detailsPanel}: RootState, { id }: Props) => {
29     const working = !!progressIndicator.some(p => p.working);
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,
39         checkedList: multiselect.checkedList,
40         working,
41         searchBarValue: searchBar.searchValue,
42         detailsPanelResourceUuid: detailsPanel.resourceUuid,
43     };
44 };
45
46 const mapDispatchToProps = () => {
47     return (dispatch: Dispatch, { id, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
48         onSetColumns: (columns: DataColumns<any, any>) => {
49             dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
50         },
51
52         onSearch: (searchValue: string) => {
53             dispatch(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id, searchValue }));
54         },
55
56         onColumnToggle: (column: DataColumn<any, any>) => {
57             dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
58         },
59
60         onSortToggle: (column: DataColumn<any, any>) => {
61             dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
62         },
63
64         onFiltersChange: (filters: DataTableFilters, column: DataColumn<any, any>) => {
65             dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
66         },
67
68         onPageChange: (page: number) => {
69             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
70         },
71
72         onChangeRowsPerPage: (rowsPerPage: number) => {
73             dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
74         },
75
76         onLoadMore: (page: number) => {
77             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
78         },
79
80         toggleMSToolbar: (isVisible: boolean) => {
81             dispatch<any>(toggleMSToolbar(isVisible));
82         },
83
84         setCheckedListOnStore: (checkedList: TCheckedList) => {
85             dispatch<any>(setCheckedListOnStore(checkedList));
86         },
87
88         setSelectedUuid: (uuid: string | null) => {
89             dispatch<any>(setSelectedResourceUuid(uuid));
90         },
91
92         loadDetailsPanel: (uuid: string) => {
93             dispatch<any>(loadDetailsPanel(uuid || ''));
94         },
95
96         onRowClick,
97
98         onRowDoubleClick,
99
100         onContextMenu,
101
102         usesDetailsCard,
103     });
104 };
105
106 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);