1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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 { DataTableFilterItem } from "../../components/data-table-filters/data-table-filters";
13 import { DataColumns } from "../../components/data-table/data-table";
17 columns: DataColumns<any>;
18 onRowClick: (item: any) => void;
19 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: any) => void;
20 onRowDoubleClick: (item: any) => void;
21 extractKey?: (item: any) => React.Key;
24 const mapStateToProps = (state: RootState, { id }: Props) =>
25 getDataExplorer(state.dataExplorer, id);
27 const mapDispatchToProps = () => {
28 let prevColumns: DataColumns<any>;
29 return (dispatch: Dispatch, { id, columns, onRowClick, onRowDoubleClick, onContextMenu }: Props) => {
30 if (columns !== prevColumns) {
31 prevColumns = columns;
32 dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
35 onSearch: (searchValue: string) => {
36 dispatch(dataExplorerActions.SET_SEARCH_VALUE({ id, searchValue }));
39 onColumnToggle: (column: DataColumn<any>) => {
40 dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
43 onSortToggle: (column: DataColumn<any>) => {
44 dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
47 onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<any>) => {
48 dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
51 onChangePage: (page: number) => {
52 dispatch(dataExplorerActions.SET_PAGE({ id, page }));
55 onChangeRowsPerPage: (rowsPerPage: number) => {
56 dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
68 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps())(DataExplorerComponent);