Merge remote-tracking branch 'origin' into 13694-Data-operations-Project-creation
[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 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     onRowClick: (item: any) => void;
18     onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
19 }
20
21 const mapStateToProps = (state: RootState, { id }: Props) =>
22     getDataExplorer(state.dataExplorer, id);
23
24 const mapDispatchToProps = (dispatch: Dispatch, { id, onRowClick, onContextMenu }: Props) => ({
25     onSearch: (searchValue: string) => {
26         dispatch(actions.SET_SEARCH_VALUE({ id, searchValue }));
27     },
28
29     onColumnToggle: (column: DataColumn<any>) => {
30         dispatch(actions.TOGGLE_COLUMN({ id, columnName: column.name }));
31     },
32
33     onSortToggle: (column: DataColumn<any>) => {
34         dispatch(actions.TOGGLE_SORT({ id, columnName: column.name }));
35     },
36
37     onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<any>) => {
38         dispatch(actions.SET_FILTERS({ id, columnName: column.name, filters }));
39     },
40
41     onChangePage: (page: number) => {
42         dispatch(actions.SET_PAGE({ id, page }));
43     },
44
45     onChangeRowsPerPage: (rowsPerPage: number) => {
46         dispatch(actions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
47     },
48
49     onRowClick,
50
51     onContextMenu
52 });
53
54 export default connect(mapStateToProps, mapDispatchToProps)(DataExplorer);
55