fix: make dataframe output format identify and show truncation (#7312)
* Added pagination info on table options * Added pagination info on table component * Added truncated rows and truncate message when row count is > 1000
This commit is contained in:
parent
d3104e15ae
commit
1d42e4b877
3 changed files with 25 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ import TableComponent from "@/components/core/parameterRenderComponent/component
|
||||||
import { ColDef, ColGroupDef } from "ag-grid-community";
|
import { ColDef, ColGroupDef } from "ag-grid-community";
|
||||||
import "ag-grid-community/styles/ag-grid.css"; // Mandatory CSS required by the grid
|
import "ag-grid-community/styles/ag-grid.css"; // Mandatory CSS required by the grid
|
||||||
import "ag-grid-community/styles/ag-theme-balham.css"; // Optional Theme applied to the grid
|
import "ag-grid-community/styles/ag-theme-balham.css"; // Optional Theme applied to the grid
|
||||||
|
import { useEffect, useState } from "react";
|
||||||
import { extractColumnsFromRows } from "../../../utils/utils";
|
import { extractColumnsFromRows } from "../../../utils/utils";
|
||||||
|
|
||||||
function DataOutputComponent({
|
function DataOutputComponent({
|
||||||
|
|
@ -13,12 +14,18 @@ function DataOutputComponent({
|
||||||
rows: any[];
|
rows: any[];
|
||||||
columnMode?: "intersection" | "union";
|
columnMode?: "intersection" | "union";
|
||||||
}) {
|
}) {
|
||||||
// If the rows are not an array of objects, convert them to an array of objects
|
const [rowsInternal, setRowsInternal] = useState(rows.slice(0, 1000));
|
||||||
if (rows.some((row) => typeof row !== "object")) {
|
|
||||||
rows = rows.map((row) => ({ data: row }));
|
|
||||||
}
|
|
||||||
|
|
||||||
const columns = extractColumnsFromRows(rows, columnMode);
|
useEffect(() => {
|
||||||
|
const rowsSliced = rows.slice(0, 1000);
|
||||||
|
if (rowsSliced.some((row) => typeof row !== "object")) {
|
||||||
|
setRowsInternal(rowsSliced.map((row) => ({ data: row })));
|
||||||
|
} else {
|
||||||
|
setRowsInternal(rowsSliced);
|
||||||
|
}
|
||||||
|
}, [rows]);
|
||||||
|
|
||||||
|
const columns = extractColumnsFromRows(rowsInternal, columnMode);
|
||||||
|
|
||||||
const columnDefs = columns.map((col, idx) => ({
|
const columnDefs = columns.map((col, idx) => ({
|
||||||
...col,
|
...col,
|
||||||
|
|
@ -30,10 +37,11 @@ function DataOutputComponent({
|
||||||
autoSizeStrategy={{ type: "fitGridWidth", defaultMinWidth: 100 }}
|
autoSizeStrategy={{ type: "fitGridWidth", defaultMinWidth: 100 }}
|
||||||
key={"dataOutputComponent"}
|
key={"dataOutputComponent"}
|
||||||
overlayNoRowsTemplate="No data available"
|
overlayNoRowsTemplate="No data available"
|
||||||
|
paginationInfo={rows.length > 1000 ? rows[1000] : undefined}
|
||||||
suppressRowClickSelection={true}
|
suppressRowClickSelection={true}
|
||||||
pagination={pagination}
|
pagination={pagination}
|
||||||
columnDefs={columnDefs}
|
columnDefs={columnDefs}
|
||||||
rowData={rows}
|
rowData={rowsInternal}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ export default function TableOptions({
|
||||||
deleteRow,
|
deleteRow,
|
||||||
hasSelection,
|
hasSelection,
|
||||||
stateChange,
|
stateChange,
|
||||||
|
paginationInfo,
|
||||||
addRow,
|
addRow,
|
||||||
tableOptions,
|
tableOptions,
|
||||||
}: {
|
}: {
|
||||||
|
|
@ -20,6 +21,7 @@ export default function TableOptions({
|
||||||
hasSelection: boolean;
|
hasSelection: boolean;
|
||||||
stateChange: boolean;
|
stateChange: boolean;
|
||||||
tableOptions?: TableOptionsTypeAPI;
|
tableOptions?: TableOptionsTypeAPI;
|
||||||
|
paginationInfo?: string;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
return (
|
return (
|
||||||
<div className={cn("absolute bottom-3 left-6")}>
|
<div className={cn("absolute bottom-3 left-6")}>
|
||||||
|
|
@ -119,6 +121,13 @@ export default function TableOptions({
|
||||||
</Button>
|
</Button>
|
||||||
</ShadTooltip>
|
</ShadTooltip>
|
||||||
</div>
|
</div>
|
||||||
|
{paginationInfo && (
|
||||||
|
<div className="ml-2 text-xs text-muted-foreground">
|
||||||
|
<ShadTooltip content="Pagination Info">
|
||||||
|
<span>{paginationInfo}</span>
|
||||||
|
</ShadTooltip>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -38,6 +38,7 @@ export interface TableComponentProps extends AgGridReactProps {
|
||||||
onDuplicate?: () => void;
|
onDuplicate?: () => void;
|
||||||
addRow?: () => void;
|
addRow?: () => void;
|
||||||
tableOptions?: TableOptionsTypeAPI;
|
tableOptions?: TableOptionsTypeAPI;
|
||||||
|
paginationInfo?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const TableComponent = forwardRef<
|
const TableComponent = forwardRef<
|
||||||
|
|
@ -268,6 +269,7 @@ const TableComponent = forwardRef<
|
||||||
<TableOptions
|
<TableOptions
|
||||||
tableOptions={props.tableOptions}
|
tableOptions={props.tableOptions}
|
||||||
stateChange={columnStateChange}
|
stateChange={columnStateChange}
|
||||||
|
paginationInfo={props.paginationInfo}
|
||||||
hasSelection={realRef.current?.api?.getSelectedRows()?.length > 0}
|
hasSelection={realRef.current?.api?.getSelectedRows()?.length > 0}
|
||||||
duplicateRow={props.onDuplicate ? props.onDuplicate : undefined}
|
duplicateRow={props.onDuplicate ? props.onDuplicate : undefined}
|
||||||
deleteRow={props.onDelete ? props.onDelete : undefined}
|
deleteRow={props.onDelete ? props.onDelete : undefined}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue