15768: checkedlist in redux store Arvados-DCO-1.1-Signed-off-by: Lisa Knox <lisa...
[arvados-workbench2.git] / 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 }
24
25 const mapStateToProps = (state: RootState, { id }: Props) => {
26     const progress = state.progressIndicator.find((p) => p.id === id);
27     const dataExplorerState = getDataExplorer(state.dataExplorer, id);
28     const currentRoute = state.router.location ? state.router.location.pathname : '';
29     const currentRefresh = localStorage.getItem(LAST_REFRESH_TIMESTAMP) || '';
30     const currentItemUuid = currentRoute === '/workflows' ? state.properties.workflowPanelDetailsUuid : state.detailsPanel.resourceUuid;
31     const isMSToolbarVisible = state.multiselect.isVisible;
32     return {
33         ...dataExplorerState,
34         working: !!progress?.working,
35         currentRefresh: currentRefresh,
36         currentRoute: currentRoute,
37         paperKey: currentRoute,
38         currentItemUuid,
39         isMSToolbarVisible,
40     };
41 };
42
43 const mapDispatchToProps = (dispatchFn) => {
44     return (dispatch: Dispatch, { id, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
45         onSetColumns: (columns: DataColumns<any, any>) => {
46             dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
47         },
48
49         onSearch: (searchValue: string) => {
50             dispatch(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id, searchValue }));
51         },
52
53         onColumnToggle: (column: DataColumn<any, any>) => {
54             dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
55         },
56
57         onSortToggle: (column: DataColumn<any, any>) => {
58             dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
59         },
60
61         onFiltersChange: (filters: DataTableFilters, column: DataColumn<any, any>) => {
62             dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
63         },
64
65         onChangePage: (page: number) => {
66             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
67         },
68
69         onChangeRowsPerPage: (rowsPerPage: number) => {
70             dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
71         },
72
73         onLoadMore: (page: number) => {
74             dispatch(dataExplorerActions.SET_PAGE({ id, page }));
75         },
76
77         toggleMSToolbar: (isVisible: boolean) => {
78             dispatchFn(toggleMSToolbar(isVisible));
79         },
80
81         setCheckedListOnStore: (checkedList: TCheckedList) => {
82             dispatchFn(setCheckedListOnStore(checkedList));
83         },
84
85         onRowClick,
86
87         onRowDoubleClick,
88
89         onContextMenu,
90     });
91 };
92
93 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);