1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { Grid, Paper, Toolbar, StyleRulesCallback, withStyles, WithStyles, TablePagination, IconButton, Tooltip, Button } from "@material-ui/core";
7 import { ColumnSelector } from "components/column-selector/column-selector";
8 import { DataTable, DataColumns, DataTableFetchMode } from "components/data-table/data-table";
9 import { DataColumn } from "components/data-table/data-column";
10 import { SearchInput } from "components/search-input/search-input";
11 import { ArvadosTheme } from "common/custom-theme";
12 import { MultiselectToolbar } from "components/multiselect-toolbar/MultiselectToolbar";
13 import { TCheckedList } from "components/data-table/data-table";
14 import { createTree } from "models/tree";
15 import { DataTableFilters } from "components/data-table-filters/data-table-filters-tree";
16 import { CloseIcon, IconType, MaximizeIcon, UnMaximizeIcon, MoreVerticalIcon } from "components/icon/icon";
17 import { PaperProps } from "@material-ui/core/Paper";
18 import { MPVPanelProps } from "components/multi-panel-view/multi-panel-view";
20 type CssRules = "titleWrapper" | "msToolbarStyles" | "subpanelToolbarStyles" | "searchBox" | "headerMenu" | "toolbar" | "footer" | "root" | "moreOptionsButton" | "title" | 'subProcessTitle' | "dataTable" | "container";
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
25 justifyContent: "space-between",
30 subpanelToolbarStyles: {
38 paddingRight: theme.spacing.unit,
53 display: "inline-block",
54 paddingLeft: theme.spacing.unit * 2,
55 paddingTop: theme.spacing.unit * 2,
60 display: "inline-block",
61 paddingLeft: theme.spacing.unit * 2,
62 paddingTop: theme.spacing.unit * 2,
81 interface DataExplorerDataProps<T> {
82 fetchMode: DataTableFetchMode;
84 itemsAvailable: number;
85 columns: DataColumns<T, any>;
89 rowsPerPageOptions: number[];
91 contextMenuColumn: boolean;
92 defaultViewIcon?: IconType;
93 defaultViewMessages?: string[];
95 currentRoute?: string;
96 hideColumnSelector?: boolean;
97 paperProps?: PaperProps;
98 actions?: React.ReactNode;
99 hideSearchInput?: boolean;
100 title?: React.ReactNode;
101 progressBar?: React.ReactNode;
103 currentRouteUuid: string;
104 selectedResourceUuid: string;
105 elementPath?: string;
106 isMSToolbarVisible: boolean;
107 checkedList: TCheckedList;
111 interface DataExplorerActionProps<T> {
112 onSetColumns: (columns: DataColumns<T, any>) => void;
113 onSearch: (value: string) => void;
114 onRowClick: (item: T) => void;
115 onRowDoubleClick: (item: T) => void;
116 onColumnToggle: (column: DataColumn<T, any>) => void;
117 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: T) => void;
118 onSortToggle: (column: DataColumn<T, any>) => void;
119 onFiltersChange: (filters: DataTableFilters, column: DataColumn<T, any>) => void;
120 onChangePage: (page: number) => void;
121 onChangeRowsPerPage: (rowsPerPage: number) => void;
122 onLoadMore: (page: number) => void;
123 extractKey?: (item: T) => React.Key;
124 toggleMSToolbar: (isVisible: boolean) => void;
125 setCheckedListOnStore: (checkedList: TCheckedList) => void;
126 setSelectedUuid: (uuid: string) => void;
129 type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules> & MPVPanelProps;
131 export const DataExplorer = withStyles(styles)(
132 class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
134 msToolbarInDetailsCard: true,
137 multiSelectToolbarInTitle = !this.props.title && !this.props.progressBar;
139 componentDidMount() {
140 if (this.props.onSetColumns) {
141 this.props.onSetColumns(this.props.columns);
145 componentDidUpdate( prevProps: Readonly<DataExplorerProps<T>>, prevState: Readonly<{}>, snapshot?: any ): void {
146 const { selectedResourceUuid, currentRouteUuid } = this.props;
147 if(selectedResourceUuid !== prevProps.selectedResourceUuid || currentRouteUuid !== prevProps.currentRouteUuid) {
149 msToolbarInDetailsCard: selectedResourceUuid === this.props.currentRouteUuid,
180 selectedResourceUuid,
191 setCheckedListOnStore,
197 className={classes.root}
200 data-cy={this.props["data-cy"]}
206 className={classes.container}
208 <div data-cy="title-wrapper" className={classes.titleWrapper} style={currentRoute?.includes('search-results') || !!progressBar ? {marginBottom: '-20px'} : {}}>
213 className={!!progressBar ? classes.subProcessTitle : classes.title}
218 {!!progressBar && progressBar}
219 {this.multiSelectToolbarInTitle && !this.state.msToolbarInDetailsCard && <MultiselectToolbar injectedStyles={classes.msToolbarStyles} />}
220 {(!hideColumnSelector || !hideSearchInput || !!actions) && (
222 className={classes.headerMenu}
226 <Toolbar className={classes.toolbar}>
227 <Grid container justify="space-between" wrap="nowrap" alignItems="center">
228 {!hideSearchInput && (
229 <div className={classes.searchBox}>
230 {!hideSearchInput && (
241 {!hideColumnSelector && (
244 onColumnToggle={onColumnToggle}
248 {doUnMaximizePanel && panelMaximized && (
250 title={`Unmaximize ${panelName || "panel"}`}
253 <IconButton onClick={doUnMaximizePanel}>
258 {doMaximizePanel && !panelMaximized && (
260 title={`Maximize ${panelName || "panel"}`}
263 <IconButton onClick={doMaximizePanel}>
270 title={`Close ${panelName || "panel"}`}
274 disabled={panelMaximized}
275 onClick={doHidePanel}
285 {!this.multiSelectToolbarInTitle && <MultiselectToolbar isSubPanel={true} injectedStyles={classes.subpanelToolbarStyles}/>}
289 className={classes.dataTable}
290 style={currentRoute?.includes('search-results') || !!progressBar ? {marginTop: '-10px'} : {}}
293 columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
295 onRowClick={(_, item: T) => onRowClick(item)}
296 onContextMenu={onContextMenu}
297 onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
298 onFiltersChange={onFiltersChange}
299 onSortToggle={onSortToggle}
300 extractKey={extractKey}
301 defaultViewIcon={defaultViewIcon}
302 defaultViewMessages={defaultViewMessages}
303 currentRoute={paperKey}
304 toggleMSToolbar={toggleMSToolbar}
305 setCheckedListOnStore={setCheckedListOnStore}
306 checkedList={checkedList}
307 selectedResourceUuid={selectedResourceUuid}
308 setSelectedUuid={this.props.setSelectedUuid}
309 currentRouteUuid={this.props.currentRouteUuid}
311 isNotFound={this.props.isNotFound}
318 <Toolbar className={classes.footer}>
321 <span data-cy="element-path">{elementPath}</span>
325 container={!elementPath}
328 {fetchMode === DataTableFetchMode.PAGINATED ? (
330 count={itemsAvailable}
331 rowsPerPage={rowsPerPage}
332 rowsPerPageOptions={rowsPerPageOptions}
333 page={this.props.page}
334 onChangePage={this.changePage}
335 onChangeRowsPerPage={this.changeRowsPerPage}
336 // Disable next button on empty lists since that's not default behavior
337 nextIconButtonProps={itemsAvailable > 0 ? {} : { disabled: true }}
344 onClick={this.loadMore}
357 changePage = (event: React.MouseEvent<HTMLButtonElement>, page: number) => {
358 this.props.onChangePage(page);
361 changeRowsPerPage: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement> = event => {
362 this.props.onChangeRowsPerPage(parseInt(event.target.value, 10));
366 this.props.onLoadMore(this.props.page + 1);
369 renderContextMenuTrigger = (item: T) => (
379 className={this.props.classes.moreOptionsButton}
381 event.stopPropagation()
382 this.props.onContextMenu(event, item)
391 contextMenuColumn: DataColumn<any, any> = {
395 filters: createTree(),
396 key: "context-actions",
397 render: this.renderContextMenuTrigger,