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, Typography } 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" | "loadMoreContainer" | "numResults" | "root" | "moreOptionsButton" | "title" | 'subProcessTitle' | "dataTable" | "container";
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
25 justifyContent: "space-between",
32 paddingRight: theme.spacing.unit,
51 marginBottom: '-0.5rem',
55 display: "inline-block",
56 paddingLeft: theme.spacing.unit * 2,
57 paddingTop: theme.spacing.unit * 2,
62 display: "inline-block",
63 paddingLeft: theme.spacing.unit * 2,
64 paddingTop: theme.spacing.unit * 2,
83 interface DataExplorerDataProps<T> {
84 fetchMode: DataTableFetchMode;
86 itemsAvailable: number;
87 columns: DataColumns<T, any>;
91 rowsPerPageOptions: number[];
93 contextMenuColumn: boolean;
94 defaultViewIcon?: IconType;
95 defaultViewMessages?: string[];
97 currentRoute?: string;
98 hideColumnSelector?: boolean;
99 paperProps?: PaperProps;
100 actions?: React.ReactNode;
101 hideSearchInput?: boolean;
102 title?: React.ReactNode;
103 progressBar?: React.ReactNode;
105 currentItemUuid: string;
106 elementPath?: string;
107 isMSToolbarVisible: boolean;
108 checkedList: TCheckedList;
110 searchBarValue: string;
113 interface DataExplorerActionProps<T> {
114 onSetColumns: (columns: DataColumns<T, any>) => void;
115 onSearch: (value: string) => void;
116 onRowClick: (item: T) => void;
117 onRowDoubleClick: (item: T) => void;
118 onColumnToggle: (column: DataColumn<T, any>) => void;
119 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: T) => void;
120 onSortToggle: (column: DataColumn<T, any>) => void;
121 onFiltersChange: (filters: DataTableFilters, column: DataColumn<T, any>) => void;
122 onChangePage: (page: number) => void;
123 onChangeRowsPerPage: (rowsPerPage: number) => void;
124 onLoadMore: (page: number) => void;
125 extractKey?: (item: T) => React.Key;
126 toggleMSToolbar: (isVisible: boolean) => void;
127 setCheckedListOnStore: (checkedList: TCheckedList) => void;
130 type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules> & MPVPanelProps;
132 export const DataExplorer = withStyles(styles)(
133 class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
135 multiSelectToolbarInTitle = !this.props.title && !this.props.progressBar;
136 maxItemsAvailable = 0;
138 componentDidMount() {
139 if (this.props.onSetColumns) {
140 this.props.onSetColumns(this.props.columns);
144 componentDidUpdate( prevProps: Readonly<DataExplorerProps<T>>, prevState: Readonly<{}>, snapshot?: any ): void {
145 if (this.props.itemsAvailable !== prevProps.itemsAvailable) {
146 this.maxItemsAvailable = Math.max(this.maxItemsAvailable, this.props.itemsAvailable);
148 if (this.props.searchBarValue !== prevProps.searchBarValue) {
149 this.maxItemsAvailable = 0;
190 setCheckedListOnStore,
196 className={classes.root}
199 data-cy={this.props["data-cy"]}
205 className={classes.container}
207 <div className={classes.titleWrapper} style={currentRoute?.includes('search-results') || !!progressBar ? {marginBottom: '-20px'} : {}}>
212 className={!!progressBar ? classes.subProcessTitle : classes.title}
217 {!!progressBar && progressBar}
218 {this.multiSelectToolbarInTitle && <MultiselectToolbar />}
219 {(!hideColumnSelector || !hideSearchInput || !!actions) && (
221 className={classes.headerMenu}
225 <Toolbar className={classes.toolbar}>
226 <Grid container justify="space-between" wrap="nowrap" alignItems="center">
227 {!hideSearchInput && (
228 <div className={classes.searchBox}>
229 {!hideSearchInput && (
240 {!hideColumnSelector && (
243 onColumnToggle={onColumnToggle}
247 {doUnMaximizePanel && panelMaximized && (
249 title={`Unmaximize ${panelName || "panel"}`}
252 <IconButton onClick={doUnMaximizePanel}>
257 {doMaximizePanel && !panelMaximized && (
259 title={`Maximize ${panelName || "panel"}`}
262 <IconButton onClick={doMaximizePanel}>
269 title={`Close ${panelName || "panel"}`}
273 disabled={panelMaximized}
274 onClick={doHidePanel}
284 {!this.multiSelectToolbarInTitle && <MultiselectToolbar />}
288 className={classes.dataTable}
289 style={currentRoute?.includes('search-results') || !!progressBar ? {marginTop: '-10px'} : {}}
292 columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
294 onRowClick={(_, item: T) => onRowClick(item)}
295 onContextMenu={onContextMenu}
296 onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
297 onFiltersChange={onFiltersChange}
298 onSortToggle={onSortToggle}
299 extractKey={extractKey}
300 defaultViewIcon={defaultViewIcon}
301 defaultViewMessages={defaultViewMessages}
302 currentItemUuid={currentItemUuid}
303 currentRoute={paperKey}
304 toggleMSToolbar={toggleMSToolbar}
305 setCheckedListOnStore={setCheckedListOnStore}
306 checkedList={checkedList}
308 isNotFound={this.props.isNotFound}
315 <Toolbar className={classes.footer}>
318 <span data-cy="element-path">{elementPath.length > 2 ? elementPath : ''}</span>
322 container={!elementPath}
325 {fetchMode === DataTableFetchMode.PAGINATED ? (
327 count={itemsAvailable}
328 rowsPerPage={rowsPerPage}
329 rowsPerPageOptions={rowsPerPageOptions}
330 page={this.props.page}
331 onChangePage={this.changePage}
332 onChangeRowsPerPage={this.changeRowsPerPage}
333 // Disable next button on empty lists since that's not default behavior
334 nextIconButtonProps={itemsAvailable > 0 ? {} : { disabled: true }}
338 <Grid className={classes.loadMoreContainer}>
339 <Typography className={classes.numResults}>
340 Showing {items.length} / {this.maxItemsAvailable} results
344 onClick={this.loadMore}
347 style={{width: '100%', margin: '10px'}}
348 disabled={working || items.length >= itemsAvailable}
362 changePage = (event: React.MouseEvent<HTMLButtonElement>, page: number) => {
363 this.props.onChangePage(page);
366 changeRowsPerPage: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement> = event => {
367 this.props.onChangeRowsPerPage(parseInt(event.target.value, 10));
371 this.props.onLoadMore(this.props.page + 1);
374 renderContextMenuTrigger = (item: T) => (
384 className={this.props.classes.moreOptionsButton}
386 event.stopPropagation()
387 this.props.onContextMenu(event, item)
396 contextMenuColumn: DataColumn<any, any> = {
400 filters: createTree(),
401 key: "context-actions",
402 render: this.renderContextMenuTrigger,