Changed the layout for tables from block layout to flex layout to fix the width of the columns as per the dialog size.

This commit is contained in:
Aditya Toshniwal authored and Akshay Joshi committed 2021-09-22 18:11:50 +05:30
1 parent f538546c4d
commit fc86faf51e
2 files changed
+16 -12

No files matched your search

@@ -58,7 +58,7 @@ export default class PrivilegeRoleSchema extends BaseUISchema {
type: 'text', group: null, type: 'text', group: null,
cell: ()=>({cell: 'privilege', controlProps: { cell: ()=>({cell: 'privilege', controlProps: {
supportedPrivs: this.supportedPrivs, supportedPrivs: this.supportedPrivs,
}}), minWidth: 230, }}),
disabled : function(state) { disabled : function(state) {
return !( return !(
obj.nodeInfo && obj.nodeInfo &&
@@ -69,7 +69,6 @@ export default class PrivilegeRoleSchema extends BaseUISchema {
{ {
id: 'grantor', label: gettext('Grantor'), type: 'text', readonly: true, id: 'grantor', label: gettext('Grantor'), type: 'text', readonly: true,
editable: false, cell: ()=>({cell: 'select', options: obj.grantorOptions}), editable: false, cell: ()=>({cell: 'select', options: obj.grantorOptions}),
minWidth: 150,
}]; }];
} }
@@ -17,7 +17,7 @@ import AddIcon from '@material-ui/icons/AddOutlined';
import { MappedCellControl } from './MappedControl'; import { MappedCellControl } from './MappedControl';
import EditRoundedIcon from '@material-ui/icons/EditRounded'; import EditRoundedIcon from '@material-ui/icons/EditRounded';
import DeleteRoundedIcon from '@material-ui/icons/DeleteRounded'; import DeleteRoundedIcon from '@material-ui/icons/DeleteRounded';
import { useTable, useBlockLayout, useResizeColumns, useSortBy, useExpanded } from 'react-table'; import { useTable, useFlexLayout, useResizeColumns, useSortBy, useExpanded } from 'react-table';
import clsx from 'clsx'; import clsx from 'clsx';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import _ from 'lodash'; import _ from 'lodash';
@@ -88,6 +88,9 @@ const useStyles = makeStyles((theme)=>({
padding: theme.spacing(1, 0.5), padding: theme.spacing(1, 0.5),
textAlign: 'left', textAlign: 'left',
}, },
tableContentWidth: {
width: 'calc(100% - 3px)',
},
btnCell: { btnCell: {
padding: theme.spacing(0.5, 0), padding: theme.spacing(0.5, 0),
textAlign: 'center', textAlign: 'center',
@@ -117,7 +120,7 @@ const useStyles = makeStyles((theme)=>({
function DataTableHeader({headerGroups}) { function DataTableHeader({headerGroups}) {
const classes = useStyles(); const classes = useStyles();
return ( return (
<div> <div className={classes.tableContentWidth}>
{headerGroups.map((headerGroup, hi) => ( {headerGroups.map((headerGroup, hi) => (
<div key={hi} {...headerGroup.getHeaderGroupProps()}> <div key={hi} {...headerGroup.getHeaderGroupProps()}>
{headerGroup.headers.map((column, ci) => ( {headerGroup.headers.map((column, ci) => (
@@ -253,11 +256,12 @@ export default function DataGridView({
Header: <>&nbsp;</>, Header: <>&nbsp;</>,
id: 'btn-edit', id: 'btn-edit',
accessor: ()=>{}, accessor: ()=>{},
resizable: false, disableResizing: true,
sortable: false, sortable: false,
dataType: 'edit', dataType: 'edit',
width: 26, width: 26,
minWidth: '0', minWidth: 26,
maxWidth: 26,
Cell: ({row})=>{ Cell: ({row})=>{
let canEditRow = true; let canEditRow = true;
if(props.canEditRow) { if(props.canEditRow) {
@@ -281,11 +285,12 @@ export default function DataGridView({
Header: <>&nbsp;</>, Header: <>&nbsp;</>,
id: 'btn-delete', id: 'btn-delete',
accessor: ()=>{}, accessor: ()=>{},
resizable: false, disableResizing: true,
sortable: false, sortable: false,
dataType: 'delete', dataType: 'delete',
width: 26, width: 26,
minWidth: '0', minWidth: 26,
maxWidth: 26,
Cell: ({row}) => { Cell: ({row}) => {
let canDeleteRow = true; let canDeleteRow = true;
if(props.canDeleteRow) { if(props.canDeleteRow) {
@@ -332,6 +337,8 @@ export default function DataGridView({
sortable: true, sortable: true,
...(field.minWidth ? {minWidth: field.minWidth} : {}), ...(field.minWidth ? {minWidth: field.minWidth} : {}),
...(field.width ? {width: field.width} : {}), ...(field.width ? {width: field.width} : {}),
...(field.maxWidth ? {maxWidth: field.maxWidth} : {}),
...(field.disableResizing ? {disableResizing: field.disableResizing} : {}),
Cell: ({value, row, ...other}) => { Cell: ({value, row, ...other}) => {
/* Make sure to take the latest field info from schema */ /* Make sure to take the latest field info from schema */
field = _.find(schemaRef.current.fields, (f)=>f.id==field.id) || field; field = _.find(schemaRef.current.fields, (f)=>f.id==field.id) || field;
@@ -385,12 +392,10 @@ export default function DataGridView({
}, [props.canAddRow]); }, [props.canAddRow]);
const defaultColumn = useMemo(()=>({ const defaultColumn = useMemo(()=>({
minWidth: 175,
width: 0,
}), []); }), []);
let tablePlugins = [ let tablePlugins = [
useBlockLayout, useFlexLayout,
useResizeColumns, useResizeColumns,
useSortBy, useSortBy,
useExpanded, useExpanded,
@@ -445,7 +450,7 @@ export default function DataGridView({
{(props.label || props.canAdd) && <DataGridHeader label={props.label} canAdd={props.canAdd} onAddClick={onAddClick} />} {(props.label || props.canAdd) && <DataGridHeader label={props.label} canAdd={props.canAdd} onAddClick={onAddClick} />}
<div {...getTableProps()} className={classes.table}> <div {...getTableProps()} className={classes.table}>
<DataTableHeader headerGroups={headerGroups} /> <DataTableHeader headerGroups={headerGroups} />
<div {...getTableBodyProps()}> <div {...getTableBodyProps()} className={classes.tableContentWidth}>
{rows.map((row, i) => { {rows.map((row, i) => {
prepareRow(row); prepareRow(row);
return <React.Fragment key={i}> return <React.Fragment key={i}>