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" | "msToolbarStyles" | "subpanelToolbarStyles" | "searchBox" | "headerMenu" | "toolbar" | "footer"| "loadMoreContainer" | "numResults" | "root" | "moreOptionsButton" | "title" | 'subProcessTitle' | "dataTable" | "container";
22 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
25 justifyContent: "space-between",
30 subpanelToolbarStyles: {
38 paddingRight: theme.spacing.unit,
59 marginBottom: '-0.5rem',
63 display: "inline-block",
64 paddingLeft: theme.spacing.unit * 2,
65 paddingTop: theme.spacing.unit * 2,
70 display: "inline-block",
71 paddingLeft: theme.spacing.unit * 2,
72 paddingTop: theme.spacing.unit * 2,
91 interface DataExplorerDataProps<T> {
92 fetchMode: DataTableFetchMode;
94 itemsAvailable: number;
95 columns: DataColumns<T, any>;
99 rowsPerPageOptions: number[];
101 contextMenuColumn: boolean;
102 defaultViewIcon?: IconType;
103 defaultViewMessages?: string[];
105 currentRoute?: string;
106 hideColumnSelector?: boolean;
107 paperProps?: PaperProps;
108 actions?: React.ReactNode;
109 hideSearchInput?: boolean;
110 title?: React.ReactNode;
111 progressBar?: React.ReactNode;
113 currentRouteUuid: string;
114 selectedResourceUuid: string;
115 elementPath?: string;
116 isMSToolbarVisible: boolean;
117 checkedList: TCheckedList;
119 searchBarValue: string;
122 interface DataExplorerActionProps<T> {
123 onSetColumns: (columns: DataColumns<T, any>) => void;
124 onSearch: (value: string) => void;
125 onRowClick: (item: T) => void;
126 onRowDoubleClick: (item: T) => void;
127 onColumnToggle: (column: DataColumn<T, any>) => void;
128 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: T) => void;
129 onSortToggle: (column: DataColumn<T, any>) => void;
130 onFiltersChange: (filters: DataTableFilters, column: DataColumn<T, any>) => void;
131 onChangePage: (page: number) => void;
132 onChangeRowsPerPage: (rowsPerPage: number) => void;
133 onLoadMore: (page: number) => void;
134 extractKey?: (item: T) => React.Key;
135 toggleMSToolbar: (isVisible: boolean) => void;
136 setCheckedListOnStore: (checkedList: TCheckedList) => void;
137 setSelectedUuid: (uuid: string) => void;
140 type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules> & MPVPanelProps;
142 export const DataExplorer = withStyles(styles)(
143 class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
145 msToolbarInDetailsCard: true,
148 multiSelectToolbarInTitle = !this.props.title && !this.props.progressBar;
149 maxItemsAvailable = 0;
151 componentDidMount() {
152 if (this.props.onSetColumns) {
153 this.props.onSetColumns(this.props.columns);
157 componentDidUpdate( prevProps: Readonly<DataExplorerProps<T>>, prevState: Readonly<{}>, snapshot?: any ): void {
158 const { selectedResourceUuid, currentRouteUuid } = this.props;
159 if(selectedResourceUuid !== prevProps.selectedResourceUuid || currentRouteUuid !== prevProps.currentRouteUuid) {
161 msToolbarInDetailsCard: selectedResourceUuid === this.props.currentRouteUuid,
164 if (this.props.itemsAvailable !== prevProps.itemsAvailable) {
165 this.maxItemsAvailable = Math.max(this.maxItemsAvailable, this.props.itemsAvailable);
167 if (this.props.searchBarValue !== prevProps.searchBarValue) {
168 this.maxItemsAvailable = 0;
198 selectedResourceUuid,
209 setCheckedListOnStore,
215 className={classes.root}
218 data-cy={this.props["data-cy"]}
224 className={classes.container}
226 <div data-cy="title-wrapper" className={classes.titleWrapper} style={currentRoute?.includes('search-results') || !!progressBar ? {marginBottom: '-20px'} : {}}>
231 className={!!progressBar ? classes.subProcessTitle : classes.title}
236 {!!progressBar && progressBar}
237 {this.multiSelectToolbarInTitle && !this.state.msToolbarInDetailsCard && <MultiselectToolbar injectedStyles={classes.msToolbarStyles} />}
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 isSubPanel={true} injectedStyles={classes.subpanelToolbarStyles}/>}
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 defaultViewIcon={defaultViewIcon}
320 defaultViewMessages={defaultViewMessages}
321 currentRoute={paperKey}
322 toggleMSToolbar={toggleMSToolbar}
323 setCheckedListOnStore={setCheckedListOnStore}
324 checkedList={checkedList}
325 selectedResourceUuid={selectedResourceUuid}
326 setSelectedUuid={this.props.setSelectedUuid}
327 currentRouteUuid={this.props.currentRouteUuid}
329 isNotFound={this.props.isNotFound}
336 <Toolbar className={classes.footer}>
339 <span data-cy="element-path">{elementPath.length > 2 ? elementPath : ''}</span>
343 container={!elementPath}
346 {fetchMode === DataTableFetchMode.PAGINATED ? (
348 count={itemsAvailable}
349 rowsPerPage={rowsPerPage}
350 rowsPerPageOptions={rowsPerPageOptions}
351 page={this.props.page}
352 onChangePage={this.changePage}
353 onChangeRowsPerPage={this.changeRowsPerPage}
354 // Disable next button on empty lists since that's not default behavior
355 nextIconButtonProps={itemsAvailable > 0 ? {} : { disabled: true }}
359 <Grid className={classes.loadMoreContainer}>
360 <Typography className={classes.numResults}>
361 Showing {items.length} / {this.maxItemsAvailable} results
365 onClick={this.loadMore}
368 style={{width: '100%', margin: '10px'}}
369 disabled={working || items.length >= itemsAvailable}
383 changePage = (event: React.MouseEvent<HTMLButtonElement>, page: number) => {
384 this.props.onChangePage(page);
387 changeRowsPerPage: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement> = event => {
388 this.props.onChangeRowsPerPage(parseInt(event.target.value, 10));
392 this.props.onLoadMore(this.props.page + 1);
395 renderContextMenuTrigger = (item: T) => (
405 className={this.props.classes.moreOptionsButton}
407 event.stopPropagation()
408 this.props.onContextMenu(event, item)
417 contextMenuColumn: DataColumn<any, any> = {
421 filters: createTree(),
422 key: "context-actions",
423 render: this.renderContextMenuTrigger,