1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-06-18 01:18:23 +02:00

fix: pagination and column width

This commit is contained in:
Tymoteusz Czech 2023-12-19 16:24:43 +01:00
parent 8306073e1f
commit dce91b0e90
No known key found for this signature in database
GPG Key ID: 133555230D88D75F
4 changed files with 62 additions and 52 deletions

View File

@ -9,12 +9,15 @@ import { TableCell } from '../TableCell/TableCell';
import { CellSortable } from '../SortableTableHeader/CellSortable/CellSortable'; import { CellSortable } from '../SortableTableHeader/CellSortable/CellSortable';
import { StickyPaginationBar } from 'component/common/Table/StickyPaginationBar/StickyPaginationBar'; import { StickyPaginationBar } from 'component/common/Table/StickyPaginationBar/StickyPaginationBar';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender'; import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { styled } from '@mui/material';
const HeaderCell = <T extends object>(header: Header<T, unknown>) => { const HeaderCell = <T extends object>(header: Header<T, unknown>) => {
const column = header.column; const column = header.column;
const isDesc = column.getIsSorted() === 'desc'; const isDesc = column.getIsSorted() === 'desc';
const align = column.columnDef.meta?.align || undefined; const align = column.columnDef.meta?.align || undefined;
const width = column.columnDef.meta?.width || undefined; const width = column.columnDef.meta?.width || undefined;
const fixedWidth = width && typeof width === 'number' ? width : undefined;
const content = column.columnDef.header;
return ( return (
<CellSortable <CellSortable
@ -28,15 +31,22 @@ const HeaderCell = <T extends object>(header: Header<T, unknown>) => {
paddingTop: 0, paddingTop: 0,
paddingBottom: 0, paddingBottom: 0,
width, width,
maxWidth: fixedWidth,
minWidth: fixedWidth,
}} }}
ariaTitle={typeof content === 'string' ? content : undefined}
> >
{header.isPlaceholder {header.isPlaceholder
? null ? null
: flexRender(column.columnDef.header, header.getContext())} : flexRender(content, header.getContext())}
</CellSortable> </CellSortable>
); );
}; };
const TableContainer = styled('div')(({ theme }) => ({
overflowX: 'auto',
}));
/** /**
* Use with react-table v8 * Use with react-table v8
*/ */
@ -51,6 +61,7 @@ export const PaginatedTable = <T extends object>({
return ( return (
<> <>
<TableContainer>
<Table> <Table>
<TableHead> <TableHead>
{tableInstance.getHeaderGroups().map((headerGroup) => ( {tableInstance.getHeaderGroups().map((headerGroup) => (
@ -87,6 +98,7 @@ export const PaginatedTable = <T extends object>({
))} ))}
</TableBody> </TableBody>
</Table> </Table>
</TableContainer>
<ConditionallyRender <ConditionallyRender
condition={tableInstance.getRowModel().rows.length > 0} condition={tableInstance.getRowModel().rows.length > 0}
show={ show={

View File

@ -91,7 +91,6 @@ export const CellSortable: FC<ICellSortableProps> = ({
}, [align]); }, [align]);
useEffect(() => { useEffect(() => {
const updateTitle = () => {
const newTitle = const newTitle =
ariaTitle && ariaTitle &&
ref.current && ref.current &&
@ -102,10 +101,7 @@ export const CellSortable: FC<ICellSortableProps> = ({
if (newTitle !== title) { if (newTitle !== title) {
setTitle(newTitle); setTitle(newTitle);
} }
}; }, [setTitle, ariaTitle]);
updateTitle();
}, [setTitle, ariaTitle]); // eslint-disable-line react-hooks/exhaustive-deps
return ( return (
<StyledTableCell <StyledTableCell

View File

@ -251,7 +251,7 @@ export const PaginatedProjectFeatureToggles = ({
header: name, header: name,
meta: { meta: {
align: 'center', align: 'center',
width: '1%', width: 90,
}, },
cell: ({ getValue }) => { cell: ({ getValue }) => {
const { const {
@ -439,6 +439,8 @@ export const PaginatedProjectFeatureToggles = ({
} }
/> />
} }
bodyClass='noop'
style={{ cursor: 'inherit' }}
> >
<div <div
ref={bodyLoadingRef} ref={bodyLoadingRef}
@ -461,7 +463,7 @@ export const PaginatedProjectFeatureToggles = ({
<ConditionallyRender <ConditionallyRender
condition={featuresExportImport && !loading} condition={featuresExportImport && !loading}
show={ show={
// FIXME: export only selected rows? // TODO: `export all` backend
<ExportDialog <ExportDialog
showExportDialog={showExportDialog} showExportDialog={showExportDialog}
data={data} data={data}

View File

@ -39,7 +39,7 @@ const StyledContentContainer = styled(Box)(({ theme }) => ({
const PaginatedProjectOverview: FC<{ const PaginatedProjectOverview: FC<{
storageKey?: string; storageKey?: string;
}> = ({ storageKey = 'project-overview' }) => { }> = ({ storageKey = 'project-overview-v2' }) => {
const projectId = useRequiredPathParam('projectId'); const projectId = useRequiredPathParam('projectId');
const { project } = useProjectOverview(projectId, { const { project } = useProjectOverview(projectId, {
refreshInterval, refreshInterval,