Improvement in width size. Add Load More

This commit is contained in:
Laurent Nguyen
2024-02-29 17:22:05 +01:00
parent 7881ddf2b1
commit 6f7c8f2a20
2 changed files with 21 additions and 18 deletions

View File

@@ -443,12 +443,15 @@ const DocumentsTabComponent: React.FunctionComponent<{
}); });
const tableContainerRef = useRef(null); const tableContainerRef = useRef(null);
const [tableContainerHeightPx, setTableContainerHeightPx] = useState<number>(undefined); const [tableContainerSizePx, setTableContainerSizePx] = useState<{ height: number, width: number }>(undefined);
useEffect(() => { useEffect(() => {
if (!tableContainerRef.current) { if (!tableContainerRef.current) {
return undefined; return undefined;
} }
const resizeObserver = new ResizeObserver(() => setTableContainerHeightPx(tableContainerRef.current.offsetHeight)); const resizeObserver = new ResizeObserver(() => setTableContainerSizePx({
height: tableContainerRef.current.offsetHeight,
width: tableContainerRef.current.offsetWidth,
}));
resizeObserver.observe(tableContainerRef.current); resizeObserver.observe(tableContainerRef.current);
return () => resizeObserver.disconnect(); // clean up return () => resizeObserver.disconnect(); // clean up
}, []); }, []);
@@ -564,9 +567,10 @@ const DocumentsTabComponent: React.FunctionComponent<{
{/* <Split> doesn't like to be a flex child */} {/* <Split> doesn't like to be a flex child */}
<div style={{ overflow: "hidden", height: "100%" }}> <div style={{ overflow: "hidden", height: "100%" }}>
<Split> <Split>
<div style={{ minWidth: 440, width: "20%", display: "flex", height: "100%" }} <div style={{ minWidth: 480, width: "20%" }}
ref={tableContainerRef}> ref={tableContainerRef}>
<DocumentsTableComponent style={{ width: "100%" }} items={tableItems} onSelectedItem={onSelectedDocument} height={tableContainerHeightPx} /> <DocumentsTableComponent style={{ width: 200 }} items={tableItems} onSelectedItem={onSelectedDocument} size={tableContainerSizePx} />
<a className="loadMore" role="button" onClick={() => loadNextPage(false)}>Load more</a>
</div> </div>
<div style={{ minWidth: "20%" }}><pre>{JSON.stringify(currentDocument, undefined, " ")}</pre></div> <div style={{ minWidth: "20%" }}><pre>{JSON.stringify(currentDocument, undefined, " ")}</pre></div>
</Split> </Split>

View File

@@ -10,7 +10,7 @@ export type DocumentsTableComponentItem = {
export interface IDocumentsTableComponentProps { export interface IDocumentsTableComponentProps {
items: DocumentsTableComponentItem[]; items: DocumentsTableComponentItem[];
onSelectedItem: (index: number) => void; onSelectedItem: (index: number) => void;
height: number; size: { height: number; width: number };
style?: React.CSSProperties; style?: React.CSSProperties;
} }
@@ -25,7 +25,7 @@ const columns: TableColumnDefinition<DocumentsTableComponentItem>[] = [
}, },
renderCell: (item) => { renderCell: (item) => {
return ( return (
<TableCellLayout>{item.id}</TableCellLayout> <TableCellLayout truncate>{item.id}</TableCellLayout>
); );
}, },
}), }),
@@ -39,7 +39,7 @@ const columns: TableColumnDefinition<DocumentsTableComponentItem>[] = [
}, },
renderCell: (item) => { renderCell: (item) => {
return ( return (
<TableCellLayout>{item.type}</TableCellLayout> <TableCellLayout truncate>{item.type}</TableCellLayout>
); );
}, },
}), }),
@@ -56,7 +56,7 @@ interface ReactWindowRenderFnProps extends ListChildComponentProps {
} }
export const DocumentsTableComponent: React.FC<IDocumentsTableComponentProps> = ({ export const DocumentsTableComponent: React.FC<IDocumentsTableComponentProps> = ({
items, onSelectedItem, style, height, items, onSelectedItem, style, size,
}: IDocumentsTableComponentProps) => { }: IDocumentsTableComponentProps) => {
const { targetDocument } = useFluent(); const { targetDocument } = useFluent();
const scrollbarWidth = useScrollbarWidth({ targetDocument }); const scrollbarWidth = useScrollbarWidth({ targetDocument });
@@ -66,11 +66,12 @@ export const DocumentsTableComponent: React.FC<IDocumentsTableComponentProps> =
const [columnSizingOptions, setColumnSizingOptions] = React.useState<TableColumnSizingOptions>({ const [columnSizingOptions, setColumnSizingOptions] = React.useState<TableColumnSizingOptions>({
id: { id: {
idealWidth: 280, idealWidth: 280,
minWidth: 273, // minWidth: 273,
}, },
type: { type: {
minWidth: 110, defaultWidth: 100
defaultWidth: 120, // minWidth: 110,
// defaultWidth: 120,
}, },
}); });
@@ -94,8 +95,6 @@ export const DocumentsTableComponent: React.FC<IDocumentsTableComponentProps> =
aria-rowindex={index + 2} aria-rowindex={index + 2}
style={style} style={style}
key={item.id} key={item.id}
// onClick={onClick}
// onKeyDown={onKeyDown}
aria-selected={selected} aria-selected={selected}
appearance={appearance} appearance={appearance}
> >
@@ -206,7 +205,7 @@ export const DocumentsTableComponent: React.FC<IDocumentsTableComponentProps> =
onKeyDown={toggleAllKeydown} onKeyDown={toggleAllKeydown}
checkboxIndicator={{ "aria-label": "Select all rows " }} checkboxIndicator={{ "aria-label": "Select all rows " }}
/> />
{columns.map((column, index) => ( {columns.map((column, /* index */) => (
<Menu openOnContext key={column.columnId}> <Menu openOnContext key={column.columnId}>
<MenuTrigger> <MenuTrigger>
<TableHeaderCell <TableHeaderCell
@@ -233,12 +232,12 @@ export const DocumentsTableComponent: React.FC<IDocumentsTableComponentProps> =
<div role="presentation" style={{ width: scrollbarWidth }} /> <div role="presentation" style={{ width: scrollbarWidth }} />
</TableRow> </TableRow>
</TableHeader> </TableHeader>
<TableBody style={{ height: "100%", flex: 1 }}> <TableBody>
<List <List
height={height !== undefined ? height - 32 : 0} height={size !== undefined ? size.height - 32 /* table header */ - 21 /* load more */ : 0}
itemCount={items.length} itemCount={items.length}
itemSize={45} itemSize={30}
width="100%" width={size ? size.width : 0}
itemData={rows} itemData={rows}
> >
{RenderRow} {RenderRow}