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, setSelectedUuid, isExactlyOneSelected } from "store/multiselect/multiselect-actions";
16 import { DetailsPanelState } from "store/details-panel/details-panel-reducer";
20 onRowClick: (item: any) => void;
21 onContextMenu?: (event: React.MouseEvent<HTMLElement>, item: any, isAdmin?: boolean) => void;
22 onRowDoubleClick: (item: any) => void;
23 extractKey?: (item: any) => React.Key;
26 const getCurrentItemUuid = (
28 workflowPanelDetailsUuid: string,
29 isDetailsResourceChecked: boolean,
30 isOnlyOneSelected: boolean,
31 detailsPanel: DetailsPanelState,
32 multiselectSelectedUuid: string
34 if(currentRoute === '/workflows') {
35 return workflowPanelDetailsUuid;
37 if(isDetailsResourceChecked && isOnlyOneSelected) {
38 return detailsPanel.resourceUuid;
40 if(!detailsPanel.isOpened){
41 return multiselectSelectedUuid;
43 return detailsPanel.resourceUuid;
46 const mapStateToProps = ({ progressIndicator, dataExplorer, router, multiselect, detailsPanel, properties}: RootState, { id }: Props) => {
47 const progress = progressIndicator.find(p => p.id === id);
48 const dataExplorerState = getDataExplorer(dataExplorer, id);
49 const currentRoute = router.location ? router.location.pathname : "";
50 const currentRefresh = localStorage.getItem(LAST_REFRESH_TIMESTAMP) || "";
51 const isDetailsResourceChecked = multiselect.checkedList[detailsPanel.resourceUuid]
52 const isOnlyOneSelected = Object.values(multiselect.checkedList).filter(x => x === true).length === 1;
53 const currentItemUuid = getCurrentItemUuid(currentRoute, properties.workflowPanelDetailsUuid, isDetailsResourceChecked, isOnlyOneSelected, detailsPanel, multiselect.selectedUuid);
54 const isMSToolbarVisible = multiselect.isVisible;
57 working: !!progress?.working,
58 currentRefresh: currentRefresh,
59 currentRoute: currentRoute,
60 paperKey: currentRoute,
63 checkedList: multiselect.checkedList,
67 const mapDispatchToProps = () => {
68 return (dispatch: Dispatch, { id, onRowClick, onRowDoubleClick, onContextMenu }: Props) => ({
69 onSetColumns: (columns: DataColumns<any, any>) => {
70 dispatch(dataExplorerActions.SET_COLUMNS({ id, columns }));
73 onSearch: (searchValue: string) => {
74 dispatch(dataExplorerActions.SET_EXPLORER_SEARCH_VALUE({ id, searchValue }));
77 onColumnToggle: (column: DataColumn<any, any>) => {
78 dispatch(dataExplorerActions.TOGGLE_COLUMN({ id, columnName: column.name }));
81 onSortToggle: (column: DataColumn<any, any>) => {
82 dispatch(dataExplorerActions.TOGGLE_SORT({ id, columnName: column.name }));
85 onFiltersChange: (filters: DataTableFilters, column: DataColumn<any, any>) => {
86 dispatch(dataExplorerActions.SET_FILTERS({ id, columnName: column.name, filters }));
89 onChangePage: (page: number) => {
90 dispatch(dataExplorerActions.SET_PAGE({ id, page }));
93 onChangeRowsPerPage: (rowsPerPage: number) => {
94 dispatch(dataExplorerActions.SET_ROWS_PER_PAGE({ id, rowsPerPage }));
97 onLoadMore: (page: number) => {
98 dispatch(dataExplorerActions.SET_PAGE({ id, page }));
101 toggleMSToolbar: (isVisible: boolean) => {
102 dispatch<any>(toggleMSToolbar(isVisible));
105 setCheckedListOnStore: (checkedList: TCheckedList) => {
106 dispatch<any>(setCheckedListOnStore(checkedList));
109 setSelectedUuid: (checkedList: TCheckedList) => {
110 dispatch<any>(setSelectedUuid(isExactlyOneSelected(checkedList)))
122 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);