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";
19 import classNames from "classnames";
21 type CssRules = "titleWrapper" | "msToolbarStyles" | "subToolbarWrapper" | "searchBox" | "headerMenu" | "toolbar" | "footer"| "loadMoreContainer" | "numResults" | "root" | "moreOptionsButton" | "title" | 'subProcessTitle' | 'progressWrapper' | 'progressWrapperNoTitle' | "dataTable" | "container";
23 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
26 justifyContent: "space-between",
34 marginBottom: "-20px",
43 paddingRight: theme.spacing.unit,
64 marginBottom: '-0.5rem',
68 display: "inline-block",
69 paddingLeft: theme.spacing.unit * 2,
70 paddingTop: theme.spacing.unit * 2,
75 display: "inline-block",
76 paddingLeft: theme.spacing.unit * 2,
77 paddingTop: theme.spacing.unit * 2,
87 progressWrapperNoTitle: {
104 interface DataExplorerDataProps<T> {
105 fetchMode: DataTableFetchMode;
107 itemsAvailable: number;
108 columns: DataColumns<T, any>;
109 searchLabel?: string;
112 rowsPerPageOptions: number[];
114 contextMenuColumn: boolean;
115 defaultViewIcon?: IconType;
116 defaultViewMessages?: string[];
118 hideColumnSelector?: boolean;
119 paperProps?: PaperProps;
120 actions?: React.ReactNode;
121 hideSearchInput?: boolean;
122 title?: React.ReactNode;
123 progressBar?: React.ReactNode;
125 currentRouteUuid: string;
126 selectedResourceUuid: string;
127 elementPath?: string;
128 isMSToolbarVisible: boolean;
129 checkedList: TCheckedList;
131 searchBarValue: string;
132 paperClassName?: string;
133 forceMultiSelectMode?: boolean;
136 interface DataExplorerActionProps<T> {
137 onSetColumns: (columns: DataColumns<T, any>) => void;
138 onSearch: (value: string) => void;
139 onRowClick: (item: T) => void;
140 onRowDoubleClick: (item: T) => void;
141 onColumnToggle: (column: DataColumn<T, any>) => void;
142 onContextMenu: (event: React.MouseEvent<HTMLElement>, item: T) => void;
143 onSortToggle: (column: DataColumn<T, any>) => void;
144 onFiltersChange: (filters: DataTableFilters, column: DataColumn<T, any>) => void;
145 onChangePage: (page: number) => void;
146 onChangeRowsPerPage: (rowsPerPage: number) => void;
147 onLoadMore: (page: number) => void;
148 extractKey?: (item: T) => React.Key;
149 toggleMSToolbar: (isVisible: boolean) => void;
150 setCheckedListOnStore: (checkedList: TCheckedList) => void;
151 setSelectedUuid: (uuid: string) => void;
154 type DataExplorerProps<T> = DataExplorerDataProps<T> & DataExplorerActionProps<T> & WithStyles<CssRules> & MPVPanelProps;
156 export const DataExplorer = withStyles(styles)(
157 class DataExplorerGeneric<T> extends React.Component<DataExplorerProps<T>> {
162 multiSelectToolbarInTitle = !this.props.title && !this.props.progressBar;
163 maxItemsAvailable = 0;
165 componentDidMount() {
166 if (this.props.onSetColumns) {
167 this.props.onSetColumns(this.props.columns);
171 componentDidUpdate( prevProps: Readonly<DataExplorerProps<T>>, prevState: Readonly<{}>, snapshot?: any ): void {
172 const { selectedResourceUuid, currentRouteUuid } = this.props;
173 if(selectedResourceUuid !== prevProps.selectedResourceUuid || currentRouteUuid !== prevProps.currentRouteUuid) {
175 hideToolbar: selectedResourceUuid === this.props.currentRouteUuid,
178 if (this.props.itemsAvailable !== prevProps.itemsAvailable) {
179 this.maxItemsAvailable = Math.max(this.maxItemsAvailable, this.props.itemsAvailable);
181 if (this.props.searchBarValue !== prevProps.searchBarValue) {
182 this.maxItemsAvailable = 0;
212 selectedResourceUuid,
222 setCheckedListOnStore,
226 forceMultiSelectMode,
230 className={classNames(classes.root, paperClassName)}
233 data-cy={this.props["data-cy"]}
239 className={classes.container}
241 <div data-cy="title-wrapper" className={classes.titleWrapper}>
246 className={!!progressBar ? classes.subProcessTitle : classes.title}
252 <div className={classNames({
253 [classes.progressWrapper]: true,
254 [classes.progressWrapperNoTitle]: !title,
255 })}>{progressBar}</div>
257 {this.multiSelectToolbarInTitle && !this.state.hideToolbar && <MultiselectToolbar injectedStyles={classes.msToolbarStyles} />}
258 {(!hideColumnSelector || !hideSearchInput || !!actions) && (
260 className={classes.headerMenu}
264 <Toolbar className={classes.toolbar}>
265 <Grid container justify="space-between" wrap="nowrap" alignItems="center">
266 {!hideSearchInput && (
267 <div className={classes.searchBox}>
268 {!hideSearchInput && (
279 {!hideColumnSelector && (
282 onColumnToggle={onColumnToggle}
286 {doUnMaximizePanel && panelMaximized && (
288 title={`Unmaximize ${panelName || "panel"}`}
291 <IconButton onClick={doUnMaximizePanel}>
296 {doMaximizePanel && !panelMaximized && (
298 title={`Maximize ${panelName || "panel"}`}
301 <IconButton onClick={doMaximizePanel}>
308 title={`Close ${panelName || "panel"}`}
312 disabled={panelMaximized}
313 onClick={doHidePanel}
323 {!this.multiSelectToolbarInTitle &&
324 <div className={classes.subToolbarWrapper}>
325 {!this.state.hideToolbar && <MultiselectToolbar
326 forceMultiSelectMode={forceMultiSelectMode}
333 className={classes.dataTable}
336 columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
338 onRowClick={(_, item: T) => onRowClick(item)}
339 onContextMenu={onContextMenu}
340 onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
341 onFiltersChange={onFiltersChange}
342 onSortToggle={onSortToggle}
343 extractKey={extractKey}
344 defaultViewIcon={defaultViewIcon}
345 defaultViewMessages={defaultViewMessages}
346 currentRoute={paperKey}
347 toggleMSToolbar={toggleMSToolbar}
348 setCheckedListOnStore={setCheckedListOnStore}
349 checkedList={checkedList}
350 selectedResourceUuid={selectedResourceUuid}
351 setSelectedUuid={this.props.setSelectedUuid}
352 currentRouteUuid={this.props.currentRouteUuid}
354 isNotFound={this.props.isNotFound}
361 <Toolbar className={classes.footer}>
364 <span data-cy="element-path">{elementPath.length > 2 ? elementPath : ''}</span>
368 container={!elementPath}
371 {fetchMode === DataTableFetchMode.PAGINATED ? (
373 count={itemsAvailable}
374 rowsPerPage={rowsPerPage}
375 rowsPerPageOptions={rowsPerPageOptions}
376 page={this.props.page}
377 onChangePage={this.changePage}
378 onChangeRowsPerPage={this.changeRowsPerPage}
379 // Disable next button on empty lists since that's not default behavior
380 nextIconButtonProps={itemsAvailable > 0 ? {} : { disabled: true }}
384 <Grid className={classes.loadMoreContainer}>
385 <Typography className={classes.numResults}>
386 Showing {items.length} / {this.maxItemsAvailable} results
390 onClick={this.loadMore}
393 style={{width: '100%', margin: '10px'}}
394 disabled={working || items.length >= itemsAvailable}
408 changePage = (event: React.MouseEvent<HTMLButtonElement>, page: number) => {
409 this.props.onChangePage(page);
412 changeRowsPerPage: React.ChangeEventHandler<HTMLTextAreaElement | HTMLInputElement> = event => {
413 this.props.onChangeRowsPerPage(parseInt(event.target.value, 10));
417 this.props.onLoadMore(this.props.page + 1);
420 renderContextMenuTrigger = (item: T) => (
430 className={this.props.classes.moreOptionsButton}
432 event.stopPropagation()
433 this.props.onContextMenu(event, item)
442 contextMenuColumn: DataColumn<any, any> = {
446 filters: createTree(),
447 key: "context-actions",
448 render: this.renderContextMenuTrigger,