merge-commit
[arvados.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 from "../../components/data-explorer/data-explorer";
8 import { getDataExplorer } from "../../store/data-explorer/data-explorer-reducer";
9 import { Dispatch } from "redux";
10 import actions from "../../store/data-explorer/data-explorer-action";
11 import { DataColumn } from "../../components/data-table/data-column";
12 import { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters";
13 import { ContextMenuAction, ContextMenuActionGroup } from "../../components/context-menu/context-menu";
14
15 interface Props {
16     id: string;
17     contextActions: ContextMenuActionGroup[];
18     onRowClick: (item: any) => void;
19     onContextAction: (action: ContextMenuAction, item: any) => void;
20 }
21
22 const mapStateToProps = (state: RootState, { id, contextActions }: Props) =>
23     getDataExplorer(state.dataExplorer, id);
24
25 const mapDispatchToProps = (dispatch: Dispatch, { id, contextActions, onRowClick, onContextAction }: Props) => ({
26     onSearch: (searchValue: string) => {
27         dispatch(actions.SET_SEARCH_VALUE({ id, searchValue }));
28     },
29
30     onColumnToggle: (column: DataColumn<any>) => {
31         dispatch(actions.TOGGLE_COLUMN({ id, columnName: column.name }));
32     },
33
34     onSortToggle: (column: DataColumn<any>) => {
35         dispatch(actions.TOGGLE_SORT({ id, columnName: column.name }));
36     },
37
38     onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<any>) => {
39         dispatch(actions.SET_FILTERS({ id, columnName: column.name, filters }));
40     },
41
42     onChangePage: (page: number) => {
43         dispatch(actions.SET_PAGE({ id, page }));
44     },
45
46     onChangeRowsPerPage: (rowsPerPage: number) => {
47         dispatch(actions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
48     },
49
50     contextActions,
51
52     onRowClick,
53
54     onContextAction
55 });
56
57 export default connect(mapStateToProps, mapDispatchToProps)(DataExplorer);
58