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, DataColumns, } from "components/data-table/data-column";
12 import { TCheckedList } from "components/data-table/data-table";
13 import { DataTableFilters } from "components/data-table-filters/data-table-filters";
14 import { toggleMSToolbar, setCheckedListOnStore } from "store/multiselect/multiselect-actions";
15 import { setSelectedResourceUuid } from "store/selected-resource/selected-resource-actions";
16 import { usesDetailsCard } from "components/multiselect-toolbar/MultiselectToolbar";
17 import { loadDetailsPanel } from "store/details-panel/details-panel-action";
21 onRowClick: (item: any) => void;
22 onContextMenu?: (event: React.MouseEvent<HTMLElement>, item: any, isAdmin?: boolean) => void;
23 onRowDoubleClick: (item: any) => void;
24 extractKey?: (item: any) => React.Key;
28 const mapStateToProps = ({ progressIndicator, dataExplorer, router, multiselect, selectedResourceUuid, properties, searchBar, detailsPanel}: RootState, { id }: Props) => {
29 const working = !!progressIndicator.some(p => p.working);
30 const dataExplorerState = getDataExplorer(dataExplorer, id);
31 const currentRoute = router.location ? router.location.pathname : "";
32 const isMSToolbarVisible = multiselect.isVisible;
36 currentRouteUuid: properties.currentRouteUuid,
39 checkedList: multiselect.checkedList,
41 searchBarValue: searchBar.searchValue,
42 detailsPanelResourceUuid: detailsPanel.resourceUuid,
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 onPageChange: (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));
88 setSelectedUuid: (uuid: string | null) => {
89 dispatch<any>(setSelectedResourceUuid(uuid));
92 loadDetailsPanel: (uuid: string) => {
93 dispatch<any>(loadDetailsPanel(uuid || ''));
106 export const DataExplorer = connect(mapStateToProps, mapDispatchToProps)(DataExplorerComponent);