From be08fb8e49a63d2e44fce9c9cac1354e8d8b669a Mon Sep 17 00:00:00 2001 From: Samir Kamal <1954121+skamril@users.noreply.github.com> Date: Wed, 29 Jan 2025 11:20:45 +0100 Subject: [PATCH] fix(ui-tablemode): prevent small values from being cut off and remove empty space at the bottom (#2321) --- webapp/src/components/common/DataGrid.tsx | 19 +++++++--- webapp/src/components/common/DataGridForm.tsx | 17 +++------ webapp/src/utils/dataGridUtils.ts | 38 +++++++++++++++++++ 3 files changed, 57 insertions(+), 17 deletions(-) create mode 100644 webapp/src/utils/dataGridUtils.ts diff --git a/webapp/src/components/common/DataGrid.tsx b/webapp/src/components/common/DataGrid.tsx index 4ef299cd8e..39659f4e24 100644 --- a/webapp/src/components/common/DataGrid.tsx +++ b/webapp/src/components/common/DataGrid.tsx @@ -45,6 +45,9 @@ export interface DataGridProps extends Omit({ rows: CompactSelection.empty(), @@ -268,14 +276,15 @@ function DataGrid({ return ( >; @@ -114,15 +114,9 @@ function DataGridForm({ () => columns.map((column) => ({ ...column, - width: - "width" in column - ? column.width - : Math.max( - measureTextWidth(column.title), - ...rowNames.map((rowName) => - measureTextWidth(defaultData[rowName][column.id].toString()), - ), - ), + width: getColumnWidth(column, () => + rowNames.map((rowName) => defaultData[rowName][column.id].toString()), + ), })), [columns, defaultData, rowNames], ); @@ -134,7 +128,7 @@ function DataGridForm({ rowMarkersFromProps || { kind: "clickable-string", getTitle: (index) => rowNames[index], - width: Math.max(...rowNames.map((name) => measureTextWidth(name))), + width: getColumnWidth({ title: "", id: "" }, () => rowNames), }, [rowMarkersFromProps, rowNames], ); @@ -311,7 +305,6 @@ function DataGridForm({ mt: 1.5, }} > - string[]) { + if ("width" in column) { + return column.width; + } + + const width = Math.max( + measureTextWidth(column.title), + // `values` is a function to prevent unnecessary computation if the column already has a width + ...values().map((value) => measureTextWidth(value)), + ); + + // Under 110px, add a margin to the width to prevent text from being cut off + return width < 110 ? width + 15 : width; +}