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 { LAST_REFRESH_TIMESTAMP } from "components/refresh-button/refresh-button";
15 import { toggleMSToolbar, setCheckedListOnStore } from "store/multiselect/multiselect-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, detailsPanel, properties}: RootState, { id }: Props) => {
27 const dataExplorerState = getDataExplorer(dataExplorer, id);
28 const currentRoute = router.location ? router.location.pathname : "";
29 const currentRefresh = localStorage.getItem(LAST_REFRESH_TIMESTAMP) || "";
30 const isDetailsResourceChecked = multiselect.checkedList[detailsPanel.resourceUuid]
31 const isOnlyOneSelected = Object.values(multiselect.checkedList).filter(x => x === true).length === 1;
32 const currentItemUuid =
33 currentRoute === '/workflows' ? properties.workflowPanelDetailsUuid : isDetailsResourceChecked && isOnlyOneSelected ? detailsPanel.resourceUuid : multiselect.selectedUuid;
34 const isMSToolbarVisible = multiselect.isVisible;
37 currentRefresh: currentRefresh,
38 currentRoute: currentRoute,
39 paperKey: currentRoute,
42 checkedList: multiselect.checkedList,
46 const mapDispatchToProps = () => {
47 return (dispatch: Dispatch, { id, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
48 onSetColumns: (columns: DataColumns<any, any>) => {
49 dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
52 onSearch: (searchValue: string) => {
53 dispatch(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id, searchValue }));
56 onColumnToggle: (column: DataColumn<any, any>) => {
57 dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
60 onSortToggle: (column: DataColumn<any, any>) => {
61 dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
64 onFiltersChange: (filters: DataTableFilters, column: DataColumn<any, any>) => {
65 dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
68 onChangePage: (page: number) => {
69 dispatch(dataExplorerActions.SET_PAGE({ id, page }));
72 onChangeRowsPerPage: (rowsPerPage: number) => {
73 dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
76 onLoadMore: (page: number) => {
77 dispatch(dataExplorerActions.SET_PAGE({ id, page }));
80 toggleMSToolbar: (isVisible: boolean) => {
81 dispatch<any>(toggleMSToolbar(isVisible));
84 setCheckedListOnStore: (checkedList: TCheckedList) => {
85 dispatch<any>(setCheckedListOnStore(checkedList));
96 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);