[ARVADOS-WORKBENCH2] created: 1.2.0-284-g5ddd6fa
Git user
git at public.curoverse.com
Wed Sep 5 06:29:20 EDT 2018
at 5ddd6fac483453d3dae5cb59962defe03a58abc8 (commit)
commit 5ddd6fac483453d3dae5cb59962defe03a58abc8
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Wed Sep 5 12:29:06 2018 +0200
Create noItemPlaceholder in data-table
Feature #14160
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/components/data-explorer/data-explorer.tsx b/src/components/data-explorer/data-explorer.tsx
index ea400b1..2ff4e7f 100644
--- a/src/components/data-explorer/data-explorer.tsx
+++ b/src/components/data-explorer/data-explorer.tsx
@@ -11,7 +11,6 @@ import { DataColumn, SortDirection } from "../data-table/data-column";
import { DataTableFilterItem } from '../data-table-filters/data-table-filters';
import { SearchInput } from '../search-input/search-input';
import { ArvadosTheme } from "~/common/custom-theme";
-import { DefaultView } from '../default-view/default-view';
import { IconType } from '../icon/icon';
type CssRules = 'searchBox' | "toolbar" | 'defaultRoot' | 'defaultMessage' | 'defaultIcon';
@@ -49,6 +48,7 @@ interface DataExplorerDataProps<T> {
defaultIcon: IconType;
defaultMessages: string[];
contextMenuColumn: boolean;
+ noItemsPlaceholder?: React.ReactNode;
}
interface DataExplorerActionProps<T> {
@@ -78,54 +78,46 @@ export const DataExplorer = withStyles(styles)(
const {
columns, onContextMenu, onFiltersChange, onSortToggle, extractKey,
rowsPerPage, rowsPerPageOptions, onColumnToggle, searchValue, onSearch,
- items, itemsAvailable, onRowClick, onRowDoubleClick, defaultIcon, defaultMessages, classes
+ items, itemsAvailable, onRowClick, onRowDoubleClick, defaultIcon, defaultMessages, classes,
+ noItemsPlaceholder
} = this.props;
- return <div>
- { items.length > 0 ? (
- <Paper>
- <Toolbar className={classes.toolbar}>
- <Grid container justify="space-between" wrap="nowrap" alignItems="center">
- <div className={classes.searchBox}>
- <SearchInput
- value={searchValue}
- onSearch={onSearch}/>
- </div>
- <ColumnSelector
- columns={columns}
- onColumnToggle={onColumnToggle}/>
- </Grid>
- </Toolbar>
- <DataTable
- columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
- items={items}
- onRowClick={(_, item: T) => onRowClick(item)}
- onContextMenu={onContextMenu}
- onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
- onFiltersChange={onFiltersChange}
- onSortToggle={onSortToggle}
- extractKey={extractKey}/>
- <Toolbar>
- <Grid container justify="flex-end">
- <TablePagination
- count={itemsAvailable}
- rowsPerPage={rowsPerPage}
- rowsPerPageOptions={rowsPerPageOptions}
- page={this.props.page}
- onChangePage={this.changePage}
- onChangeRowsPerPage={this.changeRowsPerPage}
- component="div" />
- </Grid>
- </Toolbar>
- </Paper>
- ) : (
- <DefaultView
- classRoot={classes.defaultRoot}
- icon={defaultIcon}
- classIcon={classes.defaultIcon}
- messages={defaultMessages}
- classMessage={classes.defaultMessage} />
- )}
- </div>;
+ return <Paper>
+ <Toolbar className={classes.toolbar}>
+ <Grid container justify="space-between" wrap="nowrap" alignItems="center">
+ <div className={classes.searchBox}>
+ <SearchInput
+ value={searchValue}
+ onSearch={onSearch} />
+ </div>
+ <ColumnSelector
+ columns={columns}
+ onColumnToggle={onColumnToggle} />
+ </Grid>
+ </Toolbar>
+ <DataTable
+ columns={this.props.contextMenuColumn ? [...columns, this.contextMenuColumn] : columns}
+ items={items}
+ onRowClick={(_, item: T) => onRowClick(item)}
+ onContextMenu={onContextMenu}
+ onRowDoubleClick={(_, item: T) => onRowDoubleClick(item)}
+ onFiltersChange={onFiltersChange}
+ onSortToggle={onSortToggle}
+ extractKey={extractKey}
+ noItemsPlaceholder={noItemsPlaceholder}
+ />
+ <Toolbar>
+ <Grid container justify="flex-end">
+ <TablePagination
+ count={itemsAvailable}
+ rowsPerPage={rowsPerPage}
+ rowsPerPageOptions={rowsPerPageOptions}
+ page={this.props.page}
+ onChangePage={this.changePage}
+ onChangeRowsPerPage={this.changeRowsPerPage}
+ component="div" />
+ </Grid>
+ </Toolbar>
+ </Paper>;
}
changePage = (event: React.MouseEvent<HTMLButtonElement>, page: number) => {
@@ -139,7 +131,7 @@ export const DataExplorer = withStyles(styles)(
renderContextMenuTrigger = (item: T) =>
<Grid container justify="flex-end">
<IconButton onClick={event => this.props.onContextMenu(event, item)}>
- <MoreVertIcon/>
+ <MoreVertIcon />
</IconButton>
</Grid>
diff --git a/src/components/data-table/data-table.tsx b/src/components/data-table/data-table.tsx
index 5a6f9e5..2216160 100644
--- a/src/components/data-table/data-table.tsx
+++ b/src/components/data-table/data-table.tsx
@@ -5,7 +5,9 @@
import * as React from 'react';
import { Table, TableBody, TableRow, TableCell, TableHead, TableSortLabel, StyleRulesCallback, Theme, WithStyles, withStyles } from '@material-ui/core';
import { DataColumn, SortDirection } from './data-column';
-import { DataTableFilters, DataTableFilterItem } from "../data-table-filters/data-table-filters";
+import { DataTableFilters, DataTableFilterItem } from "../data-table-filters/data-table-filters";
+import { DefaultView } from '~/components/default-view/default-view';
+import { DetailsIcon } from '~/components/icon/icon';
export type DataColumns<T, F extends DataTableFilterItem = DataTableFilterItem> = Array<DataColumn<T, F>>;
@@ -18,21 +20,29 @@ export interface DataTableDataProps<T> {
onSortToggle: (column: DataColumn<T>) => void;
onFiltersChange: (filters: DataTableFilterItem[], column: DataColumn<T>) => void;
extractKey?: (item: T) => React.Key;
+ noItemsPlaceholder?: React.ReactNode;
}
-type CssRules = "tableBody" | "tableContainer" | "noItemsInfo";
+type CssRules = "tableBody" | "root" | "content" | "noItemsInfo" | "noItemsPlaceholder";
const styles: StyleRulesCallback<CssRules> = (theme: Theme) => ({
- tableContainer: {
+ root: {
overflowX: 'auto',
overflowY: 'hidden'
},
+ content: {
+ display: 'inline-block',
+ },
tableBody: {
background: theme.palette.background.paper
},
noItemsInfo: {
textAlign: "center",
padding: theme.spacing.unit
+ },
+ noItemsPlaceholder: {
+ marginTop: theme.spacing.unit * 4,
+ marginBottom: theme.spacing.unit * 4,
}
});
@@ -42,21 +52,31 @@ export const DataTable = withStyles(styles)(
class Component<T> extends React.Component<DataTableProps<T>> {
render() {
const { items, classes } = this.props;
- return <div
- className={classes.tableContainer}>
- <Table>
- <TableHead>
- <TableRow>
- {this.mapVisibleColumns(this.renderHeadCell)}
- </TableRow>
- </TableHead>
- <TableBody className={classes.tableBody}>
- {items.map(this.renderBodyRow)}
- </TableBody>
- </Table>
+ return <div className={classes.root}>
+ <div className={classes.content}>
+ <Table>
+ <TableHead>
+ <TableRow>
+ {this.mapVisibleColumns(this.renderHeadCell)}
+ </TableRow>
+ </TableHead>
+ <TableBody className={classes.tableBody}>
+ {items.map(this.renderBodyRow)}
+ </TableBody>
+ </Table>
+ {items.length === 0 && this.renderNoItemsPlaceholder()}
+ </div>
</div>;
}
+ renderNoItemsPlaceholder = () => {
+ return this.props.noItemsPlaceholder
+ ? this.props.noItemsPlaceholder
+ : <div className={this.props.classes.noItemsPlaceholder}>
+ <DefaultView icon={DetailsIcon} messages={['No items found']} />
+ </div>;
+ }
+
renderHeadCell = (column: DataColumn<T>, index: number) => {
const { name, key, renderHeader, filters, sortDirection } = column;
const { onSortToggle, onFiltersChange } = this.props;
@@ -94,7 +114,7 @@ export const DataTable = withStyles(styles)(
key={extractKey ? extractKey(item) : index}
onClick={event => onRowClick && onRowClick(event, item)}
onContextMenu={this.handleRowContextMenu(item)}
- onDoubleClick={event => onRowDoubleClick && onRowDoubleClick(event, item) }>
+ onDoubleClick={event => onRowDoubleClick && onRowDoubleClick(event, item)}>
{this.mapVisibleColumns((column, index) => (
<TableCell key={column.key || index}>
{column.render(item)}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list