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;
121 type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules> & MPVPanelProps;
123 export const DataExplorer = withStyles(styles)(
124 class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
131 multiSelectToolbarInTitle = !this.props.title && !this.props.progressBar;
133 componentDidUpdate(prevProps: DataExplorerProps<T>) {
134 const currentRefresh = this.props.currentRefresh || "";
135 const currentRoute = this.props.currentRoute || "";
137 if (currentRoute !== this.state.prevRoute) {
138 // Component already mounted, but the user comes from a route change,
139 // like browsing through a project hierarchy.
141 showLoading: this.props.working,
142 prevRoute: currentRoute,
146 if (currentRefresh !== this.state.prevRefresh) {
147 // Component already mounted, but the user just clicked the
150 showLoading: this.props.working,
151 prevRefresh: currentRefresh,
154 if (this.state.showLoading && !this.props.working) {
161 componentDidMount() {
162 if (this.props.onSetColumns) {
163 this.props.onSetColumns(this.props.columns);
165 // Component just mounted, so we need to show the loading indicator.
167 showLoading: this.props.working,
168 prevRefresh: this.props.currentRefresh || "",
169 prevRoute: this.props.currentRoute || "",
210 setCheckedListOnStore,
215 className={classes.root}
218 data-cy={this.props["data-cy"]}
224 className={classes.container}
226 <div className={classes.titleWrapper} style={currentRoute?.includes('search-results') || !!progressBar ? {marginBottom: '-20px'} : {}}>
231 className={!!progressBar ? classes.subProcessTitle : classes.title}
236 {!!progressBar && progressBar}
237 {this.multiSelectToolbarInTitle && <MultiselectToolbar />}
238 {(!hideColumnSelector || !hideSearchInput || !!actions) && (
240 className={classes.headerMenu}
244 <Toolbar className={classes.toolbar}>
245 <Grid container justify="space-between" wrap="nowrap" alignItems="center">
246 {!hideSearchInput && (
247 <div className={classes.searchBox}>
248 {!hideSearchInput && (
259 {!hideColumnSelector && (
262 onColumnToggle={onColumnToggle}
266 {doUnMaximizePanel && panelMaximized && (
268 title={`Unmaximize ${panelName || "panel"}`}
271 <IconButton onClick={doUnMaximizePanel}>
276 {doMaximizePanel && !panelMaximized && (
278 title={`Maximize ${panelName || "panel"}`}
281 <IconButton onClick={doMaximizePanel}>
288 title={`Close ${panelName || "panel"}`}
292 disabled={panelMaximized}
293 onClick={doHidePanel}
303 {!this.multiSelectToolbarInTitle && <MultiselectToolbar />}
307 className={classes.dataTable}
308 style={currentRoute?.includes('search-results') || !!progressBar ? {marginTop: '-10px'} : {}}
311 columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
313 onRowClick={(_, item: T) => onRowClick(item)}
314 onContextMenu={onContextMenu}
315 onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
316 onFiltersChange={onFiltersChange}
317 onSortToggle={onSortToggle}
318 extractKey={extractKey}
319 working={this.state.showLoading}
320 defaultViewIcon={defaultViewIcon}
321 defaultViewMessages={defaultViewMessages}
322 currentItemUuid={currentItemUuid}
323 currentRoute={paperKey}
324 toggleMSToolbar={toggleMSToolbar}
325 setCheckedListOnStore={setCheckedListOnStore}
326 checkedList={checkedList}
333 <Toolbar className={classes.footer}>
336 <span data-cy="element-path">{elementPath}</span>
340 container={!elementPath}
343 {fetchMode === DataTableFetchMode.PAGINATED ? (
345 count={itemsAvailable}
346 rowsPerPage={rowsPerPage}
347 rowsPerPageOptions={rowsPerPageOptions}
348 page={this.props.page}
349 onChangePage={this.changePage}
350 onChangeRowsPerPage={this.changeRowsPerPage}
351 // Disable next button on empty lists since that's not default behavior
352 nextIconButtonProps={itemsAvailable > 0 ? {} : { disabled: true }}
359 onClick={this.loadMore}
372 changePage = (event: React.MouseEvent<HTMLButtonElement>, page: number) => {
373 this.props.onChangePage(page);
376 changeRowsPerPage: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement> = event => {
377 this.props.onChangeRowsPerPage(parseInt(event.target.value, 10));
381 this.props.onLoadMore(this.props.page + 1);
384 renderContextMenuTrigger = (item: T) => (
394 className={this.props.classes.moreOptionsButton}
396 event.stopPropagation()
397 this.props.onContextMenu(event, item)
406 contextMenuColumn: DataColumn<any, any> = {
410 filters: createTree(),
411 key: "context-actions",
412 render: this.renderContextMenuTrigger,