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" | "searchBox" | "headerMenu" | "toolbar" | "footer" | "root" | "moreOptionsButton" | "title" | 'subProcessTitle' | "dataTable" | "container";
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
25 justifyContent: "space-between",
32 paddingRight: theme.spacing.unit,
47 display: "inline-block",
48 paddingLeft: theme.spacing.unit * 2,
49 paddingTop: theme.spacing.unit * 2,
54 display: "inline-block",
55 paddingLeft: theme.spacing.unit * 2,
56 paddingTop: theme.spacing.unit * 2,
75 interface DataExplorerDataProps<T> {
76 fetchMode: DataTableFetchMode;
78 itemsAvailable: number;
79 columns: DataColumns<T, any>;
83 rowsPerPageOptions: number[];
85 contextMenuColumn: boolean;
86 defaultViewIcon?: IconType;
87 defaultViewMessages?: string[];
89 currentRefresh?: string;
90 currentRoute?: string;
91 hideColumnSelector?: boolean;
92 paperProps?: PaperProps;
93 actions?: React.ReactNode;
94 hideSearchInput?: boolean;
95 title?: React.ReactNode;
96 progressBar?: React.ReactNode;
98 currentItemUuid: string;
100 isMSToolbarVisible: boolean;
101 checkedList: TCheckedList;
104 interface DataExplorerActionProps<T> {
105 onSetColumns: (columns: DataColumns<T, any>) => void;
106 onSearch: (value: string) => void;
107 onRowClick: (item: T) => void;
108 onRowDoubleClick: (item: T) => void;
109 onColumnToggle: (column: DataColumn<T, any>) => void;
110 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: T) => void;
111 onSortToggle: (column: DataColumn<T, any>) => void;
112 onFiltersChange: (filters: DataTableFilters, column: DataColumn<T, any>) => void;
113 onChangePage: (page: number) => void;
114 onChangeRowsPerPage: (rowsPerPage: number) => void;
115 onLoadMore: (page: number) => void;
116 extractKey?: (item: T) => React.Key;
117 toggleMSToolbar: (isVisible: boolean) => void;
118 setCheckedListOnStore: (checkedList: TCheckedList) => void;
119 setSelectedUuid: (checkedList: TCheckedList) => void;
122 type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules> & MPVPanelProps;
124 export const DataExplorer = withStyles(styles)(
125 class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
132 multiSelectToolbarInTitle = !this.props.title && !this.props.progressBar;
134 componentDidUpdate(prevProps: DataExplorerProps<T>) {
135 const currentRefresh = this.props.currentRefresh || "";
136 const currentRoute = this.props.currentRoute || "";
138 if (currentRoute !== this.state.prevRoute) {
139 // Component already mounted, but the user comes from a route change,
140 // like browsing through a project hierarchy.
142 showLoading: this.props.working,
143 prevRoute: currentRoute,
147 if (currentRefresh !== this.state.prevRefresh) {
148 // Component already mounted, but the user just clicked the
151 showLoading: this.props.working,
152 prevRefresh: currentRefresh,
155 if (this.state.showLoading && !this.props.working) {
162 componentDidMount() {
163 if (this.props.onSetColumns) {
164 this.props.onSetColumns(this.props.columns);
166 // Component just mounted, so we need to show the loading indicator.
168 showLoading: this.props.working,
169 prevRefresh: this.props.currentRefresh || "",
170 prevRoute: this.props.currentRoute || "",
211 setCheckedListOnStore,
216 className={classes.root}
219 data-cy={this.props["data-cy"]}
225 className={classes.container}
227 <div className={classes.titleWrapper} style={currentRoute?.includes('search-results') || !!progressBar ? {marginBottom: '-20px'} : {}}>
232 className={!!progressBar ? classes.subProcessTitle : classes.title}
237 {!!progressBar && progressBar}
238 {this.multiSelectToolbarInTitle && <MultiselectToolbar />}
239 {(!hideColumnSelector || !hideSearchInput || !!actions) && (
241 className={classes.headerMenu}
245 <Toolbar className={classes.toolbar}>
246 <Grid container justify="space-between" wrap="nowrap" alignItems="center">
247 {!hideSearchInput && (
248 <div className={classes.searchBox}>
249 {!hideSearchInput && (
260 {!hideColumnSelector && (
263 onColumnToggle={onColumnToggle}
267 {doUnMaximizePanel && panelMaximized && (
269 title={`Unmaximize ${panelName || "panel"}`}
272 <IconButton onClick={doUnMaximizePanel}>
277 {doMaximizePanel && !panelMaximized && (
279 title={`Maximize ${panelName || "panel"}`}
282 <IconButton onClick={doMaximizePanel}>
289 title={`Close ${panelName || "panel"}`}
293 disabled={panelMaximized}
294 onClick={doHidePanel}
304 {!this.multiSelectToolbarInTitle && <MultiselectToolbar />}
308 className={classes.dataTable}
309 style={currentRoute?.includes('search-results') || !!progressBar ? {marginTop: '-10px'} : {}}
312 columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
314 onRowClick={(_, item: T) => onRowClick(item)}
315 onContextMenu={onContextMenu}
316 onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
317 onFiltersChange={onFiltersChange}
318 onSortToggle={onSortToggle}
319 extractKey={extractKey}
320 working={this.state.showLoading}
321 defaultViewIcon={defaultViewIcon}
322 defaultViewMessages={defaultViewMessages}
323 currentItemUuid={currentItemUuid}
324 currentRoute={paperKey}
325 toggleMSToolbar={toggleMSToolbar}
326 setCheckedListOnStore={setCheckedListOnStore}
327 checkedList={checkedList}
328 setSelectedUuid={this.props.setSelectedUuid}
335 <Toolbar className={classes.footer}>
338 <span data-cy="element-path">{elementPath}</span>
342 container={!elementPath}
345 {fetchMode === DataTableFetchMode.PAGINATED ? (
347 count={itemsAvailable}
348 rowsPerPage={rowsPerPage}
349 rowsPerPageOptions={rowsPerPageOptions}
350 page={this.props.page}
351 onChangePage={this.changePage}
352 onChangeRowsPerPage={this.changeRowsPerPage}
353 // Disable next button on empty lists since that's not default behavior
354 nextIconButtonProps={itemsAvailable > 0 ? {} : { disabled: true }}
361 onClick={this.loadMore}
374 changePage = (event: React.MouseEvent<HTMLButtonElement>, page: number) => {
375 this.props.onChangePage(page);
378 changeRowsPerPage: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement> = event => {
379 this.props.onChangeRowsPerPage(parseInt(event.target.value, 10));
383 this.props.onLoadMore(this.props.page + 1);
386 renderContextMenuTrigger = (item: T) => (
396 className={this.props.classes.moreOptionsButton}
398 event.stopPropagation()
399 this.props.onContextMenu(event, item)
408 contextMenuColumn: DataColumn<any, any> = {
412 filters: createTree(),
413 key: "context-actions",
414 render: this.renderContextMenuTrigger,