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 { DataColumns, TCheckedList } from "components/data-table/data-table";
13 import { DataTableFilters } from "components/data-table-filters/data-table-filters-tree";
14 import { toggleMSToolbar, setCheckedListOnStore } from "store/multiselect/multiselect-actions";
15 import { setSelectedResourceUuid } from "store/selected-resource/selected-resource-actions";
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;
26 const mapStateToProps = ({ progressIndicator, dataExplorer, router, multiselect, selectedResourceUuid, properties}: RootState, { id }: Props) => {
27 const working = !!progressIndicator.some(p => p.id === id && p.working);
28 const dataExplorerState = getDataExplorer(dataExplorer, id);
29 const currentRoute = router.location ? router.location.pathname : "";
30 const isMSToolbarVisible = multiselect.isVisible;
33 currentRoute: currentRoute,
34 paperKey: currentRoute,
35 currentRouteUuid: properties.currentRouteUuid,
38 checkedList: multiselect.checkedList,
43 const mapDispatchToProps = () => {
44 return (dispatch: Dispatch, { id, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
45 onSetColumns: (columns: DataColumns<any, any>) => {
46 dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
49 onSearch: (searchValue: string) => {
50 dispatch(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id, searchValue }));
53 onColumnToggle: (column: DataColumn<any, any>) => {
54 dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
57 onSortToggle: (column: DataColumn<any, any>) => {
58 dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
61 onFiltersChange: (filters: DataTableFilters, column: DataColumn<any, any>) => {
62 dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
65 onChangePage: (page: number) => {
66 dispatch(dataExplorerActions.SET_PAGE({ id, page }));
69 onChangeRowsPerPage: (rowsPerPage: number) => {
70 dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
73 onLoadMore: (page: number) => {
74 dispatch(dataExplorerActions.SET_PAGE({ id, page }));
77 toggleMSToolbar: (isVisible: boolean) => {
78 dispatch<any>(toggleMSToolbar(isVisible));
81 setCheckedListOnStore: (checkedList: TCheckedList) => {
82 dispatch<any>(setCheckedListOnStore(checkedList));
85 setSelectedUuid: (uuid: string | null) => {
86 dispatch<any>(setSelectedResourceUuid(uuid));
97 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);