From d0fc4329aa47fa3fdcc3a9f3af31e977ad21b979 Mon Sep 17 00:00:00 2001 From: Aijana Schumann Date: Wed, 12 Feb 2020 09:08:39 +0100 Subject: Update odlux Fix scrolling and resizing bug in all tables, update the ui, minior bugfixes Issue-ID: SDNC-1067 Signed-off-by: Aijana Schumann Change-Id: I6322d5f612dcbc0c044b4b67ef3c73d6d2c90949 --- .../src/components/material-table/index.tsx | 67 ++++++++++++++++------ 1 file changed, 50 insertions(+), 17 deletions(-) (limited to 'sdnr/wt/odlux/framework/src/components/material-table/index.tsx') diff --git a/sdnr/wt/odlux/framework/src/components/material-table/index.tsx b/sdnr/wt/odlux/framework/src/components/material-table/index.tsx index 520674441..b85319b40 100644 --- a/sdnr/wt/odlux/framework/src/components/material-table/index.tsx +++ b/sdnr/wt/odlux/framework/src/components/material-table/index.tsx @@ -21,6 +21,7 @@ import { withStyles, WithStyles, createStyles, Theme } from '@material-ui/core/s import Table from '@material-ui/core/Table'; import TableBody from '@material-ui/core/TableBody'; import TableCell from '@material-ui/core/TableCell'; +import TableContainer from '@material-ui/core/TableContainer'; import TablePagination from '@material-ui/core/TablePagination'; import TableRow from '@material-ui/core/TableRow'; import Paper from '@material-ui/core/Paper'; @@ -31,10 +32,13 @@ import { EnhancedTableHead } from './tableHead'; import { EnhancedTableFilter } from './tableFilter'; import { ColumnModel, ColumnType } from './columnModel'; -import { Omit } from '@material-ui/core'; +import { Omit, Menu } from '@material-ui/core'; + import { SvgIconProps } from '@material-ui/core/SvgIcon/SvgIcon'; -import { replaceHyphen } from '../../utilities/yangHelper'; -import { string } from 'prop-types'; + +import { DividerTypeMap } from '@material-ui/core/Divider'; +import { MenuItemProps } from '@material-ui/core/MenuItem'; +import { flexbox } from '@material-ui/system'; export { ColumnModel, ColumnType } from './columnModel'; type propType = string | number | null | undefined | (string | number)[]; @@ -70,14 +74,19 @@ function getSorting(order: 'asc' | 'desc' | null, orderBy: string) { const styles = (theme: Theme) => createStyles({ root: { width: '100%', + overflow: "hidden", marginTop: theme.spacing(3), + position: "relative", + boxSizing: "border-box", + display: "flex", + flexDirection: "column", }, - table: { - minWidth: 1020, - }, - tableWrapper: { - overflowX: 'auto', + container: { + flex: "1 1 100%" }, + pagination: { + overflow: "hidden" + } }); export type MaterialTableComponentState = { @@ -100,11 +109,13 @@ type MaterialTableComponentBaseProps = WithStyles & { idProperty: keyof TData | ((data: TData) => React.Key); tableId?: string; title?: string; + stickyHeader?: boolean; enableSelection?: boolean; disableSorting?: boolean; disableFilter?: boolean; customActionButtons?: { icon: React.ComponentType, tooltip?: string, onClick: () => void }[]; onHandleClick?(event: React.MouseEvent, rowData: TData): void; + createContextMenu?: (row: TData) => React.ReactElement, React.ComponentType>>[]; }; type MaterialTableComponentPropsWithRows = MaterialTableComponentBaseProps & { rows: TData[]; asynchronus?: boolean; }; @@ -139,7 +150,7 @@ function isMaterialTableComponentPropsWithRowsAndRequestData(props: MaterialTabl propsWithExternalState.onHandleRequestSort instanceof Function } -class MaterialTableComponent extends React.Component { +class MaterialTableComponent extends React.Component { constructor(props: MaterialTableComponentProps) { super(props); @@ -148,6 +159,7 @@ class MaterialTableComponent extends React.Component extends React.Component { !this.props.disableFilter && this.setState({ showFilter: !showFilter }, this.update) } return ( - -
- + + +
extends React.Component { const entryId = getId(entry); const isSelected = this.isSelected(entryId); + const contextMenu = (this.props.createContextMenu && this.state.contextMenuInfo.index === index && this.props.createContextMenu(entry)) || null; return ( this.handleClick(event, entry, entryId)} + onClick={event => { + if (this.props.createContextMenu) { + this.setState({ + contextMenuInfo: { + index: -1 + } + }); + } + this.handleClick(event, entry, entryId); + }} + onContextMenu={event => { + if (this.props.createContextMenu) { + event.preventDefault(); + event.stopPropagation(); + this.setState({ contextMenuInfo: { index, mouseX: event.clientX - 2, mouseY: event.clientY - 4 } }); + } + }} role="checkbox" aria-checked={isSelected} aria-label={`${(this.props.tableId ? this.props.tableId : 'table')}-row-${(index + 1)}`} @@ -230,6 +259,10 @@ class MaterialTableComponent extends React.Component this.setState({ contextMenuInfo: { index: -1 } })} anchorReference="anchorPosition" keepMounted + anchorPosition={this.state.contextMenuInfo.mouseY != null && this.state.contextMenuInfo.mouseX != null ? { top: this.state.contextMenuInfo.mouseY, left: this.state.contextMenuInfo.mouseX } : undefined}> + {contextMenu} + || null} ); })} @@ -240,8 +273,8 @@ class MaterialTableComponent extends React.Component
-
- + extends React.Component