Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(frontend): let a column raised to its floor take the width from the others
zchpeter57991eca9823
diff --git a/docs/design/timestamp-display.md b/docs/design/timestamp-display.mdindex 42d359ea86..e7477d2006 100644--- a/docs/design/timestamp-display.md+++ b/docs/design/timestamp-display.md@@ -138,15 +138,17 @@ compact.**(`TIMESTAMP_COLUMN_WIDTH`), measured over every time zone and shipped locale: 184 for thework-queue form, whose widest is Spanish in the future tense, and 192, 270 and 292 for thecompact, operational and full date-time forms. Moving a surface off relative wording lengthens its-value, so a column sized for the old wording breaks the new one across two lines or cuts it off. A-column holding a form never opens narrower than that width, so nothing is cut unless the reader-chooses it. How it is kept there depends on the table. Where the browser spreads spare width-across every sized column, the open-ended title column is left unsized to take it, so the date-neither wraps nor swells; the audit log does not do this yet, and its date grows with the rest.-Where a table fits its columns to the container itself, a date column does not grow, so its-minimum floors a drag without also flooring the width it opens at. That minimum is one value for-every form, room for the date; narrower than its form a cell ellipsizes, and one drag gives the-rest back.+value, so a column sized for the old wording breaks the new one across two lines or cuts it off.+The columns this design sizes never open narrower than their form's width, so nothing is cut+unless the reader chooses it; a queue-form column elsewhere may still be sized for the past tense+alone. How the width is kept depends on the table. Where the browser spreads spare width across+every sized column, the open-ended column — a title, a run's detail — is left unsized to take it,+so the date neither wraps nor swells; the audit log does not do this yet, and its date grows with+the rest. Where a table fits its columns to the container itself, a date column does not grow, so+its minimum floors a drag without also flooring the width it opens at, and a column raised to its+floor takes that width from the others rather than overrunning the container. That minimum is one+value for every form, room for the date; narrower than its form a cell ellipsizes, and one drag+gives the rest back.## Surface classificationdiff --git a/frontend/src/components/timestampColumn.ts b/frontend/src/components/timestampColumn.tsindex 36b7840903..b5a71a3f20 100644--- a/frontend/src/components/timestampColumn.ts+++ b/frontend/src/components/timestampColumn.ts@@ -4,9 +4,10 @@/*** The width a table column opens at to hold a form on one line: the widest* rendering across every time zone and shipped locale at a table's 14px, plus- * a cell's 32px of padding. For the absolute forms that is en-US in Chatham,- * GMT+12:45; for the work-queue form, es-ES in the future tense. Measured- * with the macOS system font; Segoe UI is not.+ * a cell's 32px of padding. For the forms that show a zone that is en-US in+ * Chatham, GMT+12:45; for compact, en-US at a two-digit hour in any zone; for+ * the work-queue form, es-ES in the future tense. Measured with the macOS+ * system font; Segoe UI is not.*/export const TIMESTAMP_COLUMN_WIDTH = {queue: 184,diff --git a/frontend/src/hooks/useColumnWidths.test.tsx b/frontend/src/hooks/useColumnWidths.test.tsxindex d6d9627133..f54d986e26 100644--- a/frontend/src/hooks/useColumnWidths.test.tsx+++ b/frontend/src/hooks/useColumnWidths.test.tsx@@ -384,6 +384,41 @@ describe("distributeColumnWidths", () => {}});+ test("fills the container exactly whenever every floor fits", () => {+ // A column raised to its floor has to take that width from the others,+ // or the table overruns a container it could have filled.+ const columns = [+ { key: "status", defaultWidth: 160, minWidth: 128 },+ { key: "creator", defaultWidth: 200, minWidth: 128 },+ { key: "date", defaultWidth: 270, minWidth: 140, grow: false },+ { key: "statement", defaultWidth: 400, minWidth: 180 },+ { key: "actions", defaultWidth: 140, resizable: false },+ ];+ const floors = 128 + 128 + 270 + 180 + 140;+ for (let containerWidth = floors; containerWidth <= 1800; containerWidth++) {+ const widths = distributeColumnWidths(columns, containerWidth);+ expect(widths.reduce((sum, w) => sum + w, 0)).toBe(containerWidth);+ columns.forEach((column, i) => {+ expect(widths[i]).toBeGreaterThanOrEqual(+ column.minWidth ?? column.defaultWidth+ );+ });+ expect(widths[2]).toBe(270);+ expect(widths[4]).toBe(140);+ }+ });++ test("keeps every floor when the container is too narrow for them", () => {+ const widths = distributeColumnWidths(+ [+ { key: "a", defaultWidth: 200, minWidth: 150 },+ { key: "b", defaultWidth: 200, minWidth: 150 },+ ],+ 200+ );+ expect(widths).toEqual([150, 150]);+ });+test("its minimum floors a drag, not the width it opens at", () => {const columns = [{ key: "date", defaultWidth: 260, minWidth: 140, grow: false },diff --git a/frontend/src/hooks/useColumnWidths.ts b/frontend/src/hooks/useColumnWidths.tsindex 41a139cd39..1a03fb3dc1 100644--- a/frontend/src/hooks/useColumnWidths.ts+++ b/frontend/src/hooks/useColumnWidths.ts@@ -22,29 +22,59 @@ export interface ColumnWithWidth {* Distributes `containerWidth` across columns so the table fills its container* on first render instead of overflowing at the sum of `defaultWidth`s.* Columns that are not resizable, or do not grow, keep their `defaultWidth`;- * the rest share the remaining space proportionally to their `defaultWidth`,- * each clamped to its `minWidth`. When the container is too narrow for those- * minimums the widths add up past it, and the table scrolls.+ * the rest share the remaining space in proportion to their `defaultWidth`.+ * A column whose share falls under its `minWidth` is held there and the rest+ * is shared again, so the widths add up to exactly the container whenever it+ * can hold every floor. When it cannot, every column sits at its floor and+ * the table scrolls.*/export function distributeColumnWidths<T extends ColumnWithWidth & { resizable?: boolean },>(columns: T[], containerWidth: number): number[] {const keepsWidth = (c: T) => c.resizable === false || c.grow === false;+ const floorOf = (c: T) => c.minWidth ?? 40;const fixedTotal = columns.filter(keepsWidth).reduce((sum, c) => sum + c.defaultWidth, 0);- const flexBaseTotal = columns- .filter((c) => !keepsWidth(c))- .reduce((sum, c) => sum + c.defaultWidth, 0);const available = Math.max(0, containerWidth - fixedTotal);- return columns.map((c) => {++ // Raising a column to its floor has to take that width from the others, so+ // floored columns are set aside and the remainder re-shared until every+ // share clears its floor. Each pass sets aside at least one column.+ const floored = new Set<T>();+ let shares = new Map<T, number>();+ for (;;) {+ const open = columns.filter((c) => !keepsWidth(c) && !floored.has(c));+ const base = open.reduce((sum, c) => sum + c.defaultWidth, 0);+ const rest =+ available - [...floored].reduce((sum, c) => sum + floorOf(c), 0);+ shares = new Map(+ open.map((c) => [c, base > 0 ? (rest * c.defaultWidth) / base : 0])+ );+ const under = open.filter((c) => (shares.get(c) ?? 0) < floorOf(c));+ if (under.length === 0) {+ break;+ }+ for (const c of under) {+ floored.add(c);+ }+ }++ const widths = columns.map((c) => {if (keepsWidth(c)) return c.defaultWidth;- const proportional =- flexBaseTotal > 0- ? Math.round(available * (c.defaultWidth / flexBaseTotal))- : c.defaultWidth;- return Math.max(c.minWidth ?? 40, proportional);+ if (floored.has(c)) return floorOf(c);+ return Math.floor(shares.get(c) ?? 0);});+ // Flooring each share leaves a few pixels unassigned; the widest column+ // still sharing takes them, so the total lands on the container.+ const sharing = columns+ .map((_, i) => i)+ .filter((i) => shares.has(columns[i]));+ if (sharing.length > 0) {+ const widest = sharing.reduce((a, b) => (widths[b] > widths[a] ? b : a));+ widths[widest] += containerWidth - widths.reduce((sum, w) => sum + w, 0);+ }+ return widths;}/**diff --git a/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx b/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsxindex 10690ece08..edd87ad7e9 100644--- a/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx+++ b/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx@@ -8,7 +8,10 @@ import {TIMESTAMP_COLUMN_WIDTH,} from "@/components/timestampColumn";import { distributeColumnWidths } from "@/hooks/useColumnWidths";-import { shownTimestampModes } from "@/test-utils/humanizeTs";+import {+ shownTimestampInstants,+ shownTimestampModes,+} from "@/test-utils/humanizeTs";import {AccessGrant_Status,AccessGrantSchema,@@ -42,6 +45,26 @@ describe("grantColumns", () => {});+ test("fits the container exactly at every width that holds its floors", () => {+ const floors = columns.reduce(+ (sum, column) =>+ sum ++ (column.resizable === false || column.grow === false+ ? column.defaultWidth+ : column.minWidth),+ 0+ );+ for (let containerWidth = floors; containerWidth <= 1800; containerWidth++) {+ const widths = distributeColumnWidths(columns, containerWidth);+ expect(widths.reduce((sum, w) => sum + w, 0)).toBe(containerWidth);+ columns.forEach((column, i) => {+ expect(widths[i]).toBeGreaterThanOrEqual(column.minWidth);+ });+ expect(widths[at("created")]).toBe(TIMESTAMP_COLUMN_WIDTH.queue);+ expect(widths[at("expiration")]).toBe(TIMESTAMP_COLUMN_WIDTH.operational);+ }+ });+test("lets a reader narrow either date to the date alone", () => {expect(columns[at("created")].minWidth).toBe(TIMESTAMP_COLUMN_MIN_WIDTH);expect(columns[at("expiration")].minWidth).toBe(TIMESTAMP_COLUMN_MIN_WIDTH);@@ -87,6 +110,10 @@ describe("AccessGrantRow", () => {);expect(shownTimestampModes(container)).toEqual(["queue", "operational"]);+ expect(shownTimestampInstants(container)).toEqual([+ String(nowMs - 60_000),+ String(nowMs + 86_400_000),+ ]);for (const date of container.querySelectorAll("[data-testid=humanize-ts]")) {expect(date.className).toContain("truncate");}