Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): let a table say which columns give way first
zchpeterbc2f1168f0ac
diff --git a/docs/design/timestamp-display.md b/docs/design/timestamp-display.mdindex 7aaf82c16f..12a1ea5743 100644--- a/docs/design/timestamp-display.md+++ b/docs/design/timestamp-display.md@@ -138,17 +138,18 @@ compact.**(`TIMESTAMP_COLUMN_WIDTH`), measured over every time zone and shipped locale: 192, 270 and 292 forthe compact, operational and full date-time forms. Moving a surface off relative wording lengthensits 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. The work-queue form has no sized column here; its widest reading is-Spanish in the future tense, 183px, so a queue-form column elsewhere may 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.+off. A column this design sizes opens at its form's width, so nothing is cut unless the reader+chooses it or the table has ruled which columns give way first when it is narrower than every+default — the access grants have, and their dates give way first. The work-queue form has no sized+column here; its widest reading is Spanish in the future tense, 183px, so a queue-form column+elsewhere may 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 takes none of the spare width, and a column raised to its floor+takes that width from the others rather than overrunning the container. The 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 classification@@ -167,7 +168,7 @@ Every current `HumanizeTs` call site, classified under the principle:| Schema sync status | `modules/sql-editor/components/SchemaPane/SyncSchemaButton.tsx`, `routes/project/ProjectSyncSchemaPage.tsx`, `components/database/DatabaseOverviewInfo.tsx` | Freshness | 30d switch || Agent chat | `modules/agent/components/AgentWindow.tsx` | Feed | 30d switch || Plan-check run time | `components/plan-check/PlanCheckSection.tsx` (bare `toLocaleString()` today — adopts `HumanizeTs`) | Freshness | 30d switch |-| Access-grant creation time | `routes/project/ProjectAccessGrantsPage.tsx` (`AccessGrantRow`; full absolute today — adopts `HumanizeTs`). Shares the operational form with the expiration beside it: two dates in one row read in one format, and consistency outranks the freshness a relative age would add. The row's status, statement and creator carry what a reader acts on — the status turns Expired by itself — so the dates hold their width and the spare goes to those columns | Operational | Operational (D6 tooltip) |+| Access-grant creation time | `routes/project/ProjectAccessGrantsPage.tsx` (`AccessGrantRow`; full absolute today — adopts `HumanizeTs`). Shares the operational form with the expiration beside it: two dates in one row read in one format, and consistency outranks the freshness a relative age would add. The row's status, statement, creator and databases carry what a reader acts on — the status turns Expired by itself — so the dates take none of the spare width, and when the table is narrower than every column's default they give way first, down to the date alone, then the statement, the creator and the databases, with the status last. The zone is the first thing cut on a narrow screen; the full date-time stays on the hover | Operational | Operational (D6 tooltip) || **Database changelog** | `routes/project/database-detail/changelog/DatabaseChangelogTable.tsx` | **History view** | **Absolute always — compact tier (D7)** || **Database revisions** | `routes/project/database-detail/revision/DatabaseRevisionTable.tsx` | **History view** | **Absolute always — compact tier (D7)** || **Task-run history** | `routes/project/plan-detail/components/deploy/DeployTaskRunHistorySheet.tsx`, `routes/project/issue-detail/components/IssueDetailTaskRunTable.tsx` | **History view** | **Absolute always — compact tier (D7)** |diff --git a/frontend/src/hooks/useColumnWidths.test.tsx b/frontend/src/hooks/useColumnWidths.test.tsxindex f54d986e26..52b910a124 100644--- a/frontend/src/hooks/useColumnWidths.test.tsx+++ b/frontend/src/hooks/useColumnWidths.test.tsx@@ -433,3 +433,38 @@ describe("distributeColumnWidths", () => {unmount();});});++describe("distributeColumnWidths with a yield order", () => {+ const columns = [+ { key: "date", defaultWidth: 270, minWidth: 140, grow: false, yieldOrder: 1 },+ { key: "title", defaultWidth: 400, minWidth: 180, yieldOrder: 2 },+ { key: "owner", defaultWidth: 200, minWidth: 128, yieldOrder: 3 },+ { key: "actions", defaultWidth: 140, resizable: false },+ ];+ const preferred = 270 + 400 + 200 + 140;+ const floors = 140 + 180 + 128 + 140;++ test("gives way in order, each column to its floor before the next", () => {+ for (let width = floors; width < preferred; width++) {+ const [date, title, owner, actions] = distributeColumnWidths(+ columns,+ width+ );+ expect(date + title + owner + actions).toBe(width);+ expect(actions).toBe(140);+ if (title < 400) {+ expect(date).toBe(140);+ }+ if (owner < 200) {+ expect(title).toBe(180);+ }+ }+ });++ test("keeps every preferred width once the container holds them", () => {+ const [date, title, owner] = distributeColumnWidths(columns, preferred);+ expect([date, title, owner]).toEqual([270, 400, 200]);+ // Spare width still goes to the columns that grow, not the date.+ expect(distributeColumnWidths(columns, preferred + 300)[0]).toBe(270);+ });+});diff --git a/frontend/src/hooks/useColumnWidths.ts b/frontend/src/hooks/useColumnWidths.tsindex 1a03fb3dc1..cd5a1ed327 100644--- a/frontend/src/hooks/useColumnWidths.ts+++ b/frontend/src/hooks/useColumnWidths.ts@@ -10,12 +10,20 @@ export interface ColumnWithWidth {defaultWidth: number;minWidth?: number;/**- * False for a column whose content has a width of its own, such as a date.- * `distributeColumnWidths` then opens it at `defaultWidth` however wide the- * table is, and `minWidth` only floors a drag; otherwise `minWidth` floors- * both. Tables that leave spare width to the browser do not read it.+ * False for a column whose content has a width of its own, such as a date:+ * `distributeColumnWidths` gives it none of the spare width, and `minWidth`+ * floors a drag rather than the width it opens at. Without a `yieldOrder`+ * it keeps `defaultWidth` at any width. Tables that leave spare width to+ * the browser do not read it.*/grow?: boolean;+ /**+ * When the container is narrower than every column's `defaultWidth`,+ * columns give width back in ascending order, each down to its `minWidth`+ * before the next gives any. A column without one gives last; one that is+ * not resizable never does. Without any, the shortfall is shared.+ */+ yieldOrder?: number;}/**@@ -31,6 +39,13 @@ export interface ColumnWithWidth {export function distributeColumnWidths<T extends ColumnWithWidth & { resizable?: boolean },>(columns: T[], containerWidth: number): number[] {+ const preferredTotal = columns.reduce((sum, c) => sum + c.defaultWidth, 0);+ if (+ containerWidth < preferredTotal &&+ columns.some((c) => c.yieldOrder !== undefined)+ ) {+ return yieldInOrder(columns, preferredTotal - containerWidth);+ }const keepsWidth = (c: T) => c.resizable === false || c.grow === false;const floorOf = (c: T) => c.minWidth ?? 40;const fixedTotal = columns@@ -77,6 +92,53 @@ export function distributeColumnWidths<return widths;}+// Starts every column at its default and takes `deficit` back, a yield+// group at a time: within a group in proportion to how far each column can+// shrink, and never past a floor. If every group reaches its floors first,+// the widths add up past the container and the table scrolls.+function yieldInOrder<T extends ColumnWithWidth & { resizable?: boolean }>(+ columns: T[],+ deficit: number+): number[] {+ const floorOf = (c: T) => c.minWidth ?? 40;+ const orderOf = (c: T) => c.yieldOrder ?? Number.POSITIVE_INFINITY;+ const widths = columns.map((c) => c.defaultWidth);+ let remaining = deficit;+ const orders = [+ ...new Set(columns.filter((c) => c.resizable !== false).map(orderOf)),+ ].sort((a, b) => a - b);+ for (const order of orders) {+ if (remaining <= 0) {+ break;+ }+ const group = columns+ .map((_, i) => i)+ .filter(+ (i) => columns[i].resizable !== false && orderOf(columns[i]) === order+ );+ const room = group.map((i) =>+ Math.max(0, columns[i].defaultWidth - floorOf(columns[i]))+ );+ const groupRoom = room.reduce((sum, r) => sum + r, 0);+ const take = Math.min(remaining, groupRoom);+ let taken = 0;+ group.forEach((i, j) => {+ const cut = groupRoom > 0 ? Math.floor((take * room[j]) / groupRoom) : 0;+ widths[i] -= cut;+ taken += cut;+ });+ // Flooring each cut leaves a few pixels; the widest in the group gives+ // them, within its floor.+ for (const i of [...group].sort((a, b) => widths[b] - widths[a])) {+ const cut = Math.min(take - taken, widths[i] - floorOf(columns[i]));+ widths[i] -= cut;+ taken += cut;+ }+ remaining -= take;+ }+ return widths;+}+/*** Tracks per-column widths for a `table-fixed` table and exposes a mouse* handler to start a drag-to-resize gesture on a column header. State isdiff --git a/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx b/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsxindex bce5e45385..a0f92fc5a8 100644--- a/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx+++ b/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx@@ -35,33 +35,45 @@ import { AccessGrantRow, grantColumns } from "./ProjectAccessGrantsPage";describe("grantColumns", () => {const columns = grantColumns((key) => key);const at = (key: string) => columns.findIndex((column) => column.key === key);+ const preferred = columns.reduce((sum, c) => sum + c.defaultWidth, 0);+ const floors = columns.reduce(+ (sum, c) => sum + (c.resizable === false ? c.defaultWidth : c.minWidth),+ 0+ );+ const full = (widths: number[], key: string) =>+ widths[at(key)] === columns[at(key)].defaultWidth;+ const floored = (widths: number[], key: string) =>+ widths[at(key)] === columns[at(key)].minWidth;- test.each([1100, 1300, 1500, 1800])(- "opens both dates whole in a %ipx table",- (containerWidth) => {- const widths = distributeColumnWidths(columns, containerWidth);+ test("opens both dates whole once the table holds every column", () => {+ for (const width of [preferred, preferred + 300]) {+ const widths = distributeColumnWidths(columns, width);expect(widths[at("created")]).toBe(TIMESTAMP_COLUMN_WIDTH.operational);expect(widths[at("expiration")]).toBe(TIMESTAMP_COLUMN_WIDTH.operational);}- );+ });- 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);+ test("gives way dates first, then statement, then creator, then databases", () => {+ for (let width = floors; width < preferred; width++) {+ const widths = distributeColumnWidths(columns, width);+ expect(widths.reduce((sum, w) => sum + w, 0)).toBe(width);columns.forEach((column, i) => {expect(widths[i]).toBeGreaterThanOrEqual(column.minWidth);});- expect(widths[at("created")]).toBe(TIMESTAMP_COLUMN_WIDTH.operational);- expect(widths[at("expiration")]).toBe(TIMESTAMP_COLUMN_WIDTH.operational);+ if (!full(widths, "statement")) {+ expect(floored(widths, "created") && floored(widths, "expiration")).toBe(+ true+ );+ }+ if (!full(widths, "creator")) {+ expect(floored(widths, "statement")).toBe(true);+ }+ if (!full(widths, "databases")) {+ expect(floored(widths, "creator")).toBe(true);+ }+ if (!full(widths, "status")) {+ expect(floored(widths, "databases")).toBe(true);+ }}});diff --git a/frontend/src/routes/project/ProjectAccessGrantsPage.tsx b/frontend/src/routes/project/ProjectAccessGrantsPage.tsxindex 19fefb101c..6cffbdcba8 100644--- a/frontend/src/routes/project/ProjectAccessGrantsPage.tsx+++ b/frontend/src/routes/project/ProjectAccessGrantsPage.tsx@@ -103,6 +103,7 @@ export const grantColumns = (t: (key: string) => string): GrantColumn[] => [defaultWidth: 200,minWidth: 128,sortKey: "creator",+ yieldOrder: 3,},{key: "created",@@ -111,6 +112,7 @@ export const grantColumns = (t: (key: string) => string): GrantColumn[] => [minWidth: TIMESTAMP_COLUMN_MIN_WIDTH,grow: false,sortKey: "create_time",+ yieldOrder: 1,},{key: "expiration",@@ -119,18 +121,21 @@ export const grantColumns = (t: (key: string) => string): GrantColumn[] => [minWidth: TIMESTAMP_COLUMN_MIN_WIDTH,grow: false,sortKey: "expire_time",+ yieldOrder: 1,},{key: "statement",title: t("common.statement"),defaultWidth: 400,minWidth: 180,+ yieldOrder: 2,},{key: "databases",title: t("common.databases"),defaultWidth: 240,minWidth: 128,+ yieldOrder: 4,},// Trailing actions column — no title (blank header), fixed// width sized for two ghost buttons + "View issue".