Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix(frontend): open the access-grant creation date whole, and measure it

zchpeter32b35411a7e5
diff --git a/docs/design/timestamp-display.md b/docs/design/timestamp-display.md
index 6005adbbd0..42d359ea86 100644
--- a/docs/design/timestamp-display.md
+++ b/docs/design/timestamp-display.md
@@ -134,18 +134,19 @@ history: the embedded lists, where width is contended and D6 keeps full precisio
Objective divider: **exportable-as-evidence or a detail view → full; scannable embedded list →
compact.**
-**Column width follows the form.** Moving a surface off relative wording lengthens its value — "3
-months ago" is about 125px in a table cell, the compact form 192, the operational 270, the full
-date-time 292 — so a column sized for the old wording breaks the new one across two lines or cuts
-it off. Each form has a width (`TIMESTAMP_COLUMN_WIDTH`) measured over every time zone and shipped
-locale, and a column holding it never opens narrower, 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 column — a title, a statement — 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, the 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.
+**Column width follows the form.** Every form has a width it needs on one line
+(`TIMESTAMP_COLUMN_WIDTH`), measured over every time zone and shipped locale: 184 for the
+work-queue form, whose widest is Spanish in the future tense, and 192, 270 and 292 for the
+compact, 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.
## Surface classification
diff --git a/frontend/src/components/timestampColumn.test.ts b/frontend/src/components/timestampColumn.test.ts
index 00eb9a0f79..e8ec379589 100644
--- a/frontend/src/components/timestampColumn.test.ts
+++ b/frontend/src/components/timestampColumn.test.ts
@@ -8,7 +8,12 @@ import {
// jsdom has no font metrics, so these were measured in a browser: every IANA
// zone, the five shipped locales, and every month and local hour of a year,
// at 14px in the macOS system font, plus 32px of cell padding.
-const MEASURED_FORM = { compact: 191, operational: 269, datetime: 291 };
+const MEASURED_FORM = {
+ queue: 183,
+ compact: 191,
+ operational: 269,
+ datetime: 291,
+};
const MEASURED_DATE = 140;
const forms = Object.keys(MEASURED_FORM) as (keyof typeof MEASURED_FORM)[];
diff --git a/frontend/src/components/timestampColumn.ts b/frontend/src/components/timestampColumn.ts
index 6b44d399be..36b7840903 100644
--- a/frontend/src/components/timestampColumn.ts
+++ b/frontend/src/components/timestampColumn.ts
@@ -4,10 +4,12 @@
/**
* 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. en-US in Chatham, GMT+12:45, is the widest in all
- * three forms. Measured with the macOS system font; Segoe UI is not.
+ * 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.
*/
export const TIMESTAMP_COLUMN_WIDTH = {
+ queue: 184,
compact: 192,
operational: 270,
datetime: 292,
diff --git a/frontend/src/hooks/useColumnWidths.test.tsx b/frontend/src/hooks/useColumnWidths.test.tsx
index 1f22c47976..d6d9627133 100644
--- a/frontend/src/hooks/useColumnWidths.test.tsx
+++ b/frontend/src/hooks/useColumnWidths.test.tsx
@@ -385,13 +385,16 @@ describe("distributeColumnWidths", () => {
});
test("its minimum floors a drag, not the width it opens at", () => {
- const [date] = distributeColumnWidths(
- [
- { key: "date", defaultWidth: 260, minWidth: 140, grow: false },
- { key: "title", defaultWidth: 400 },
- ],
- 500
- );
- expect(date).toBe(260);
+ const columns = [
+ { key: "date", defaultWidth: 260, minWidth: 140, grow: false },
+ { key: "title", defaultWidth: 400 },
+ ];
+ expect(distributeColumnWidths(columns, 500)[0]).toBe(260);
+ mount(columns);
+ startDrag(0, 400);
+ moveMouse(0);
+ expect(handle.current!.widths[0]).toBe(140);
+ releaseMouse();
+ unmount();
});
});
diff --git a/frontend/src/hooks/useColumnWidths.ts b/frontend/src/hooks/useColumnWidths.ts
index d50e7e8935..41a139cd39 100644
--- a/frontend/src/hooks/useColumnWidths.ts
+++ b/frontend/src/hooks/useColumnWidths.ts
@@ -10,9 +10,10 @@ export interface ColumnWithWidth {
defaultWidth: number;
minWidth?: number;
/**
- * False for a column whose content has a width of its own, such as a date:
- * it opens at `defaultWidth` however wide the table is, and `minWidth` only
- * floors a drag. Otherwise `minWidth` floors both.
+ * 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.
*/
grow?: boolean;
}
@@ -21,9 +22,9 @@ 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 `minWidth`). Falls back to the raw default widths when the
- * container is too narrow to honor the minimums (the table then scrolls).
+ * 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.
*/
export function distributeColumnWidths<
T extends ColumnWithWidth & { resizable?: boolean },
diff --git a/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx b/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx
index 5b6b05554d..10690ece08 100644
--- a/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx
+++ b/frontend/src/routes/project/ProjectAccessGrantsPage.test.tsx
@@ -1,31 +1,94 @@
-import { describe, expect, test, vi } from "vitest";
+import { create } from "@bufbuild/protobuf";
+import { timestampFromMs } from "@bufbuild/protobuf/wkt";
+import { act } from "react";
+import { createRoot } from "react-dom/client";
+import { afterEach, describe, expect, test, vi } from "vitest";
import {
TIMESTAMP_COLUMN_MIN_WIDTH,
TIMESTAMP_COLUMN_WIDTH,
} from "@/components/timestampColumn";
import { distributeColumnWidths } from "@/hooks/useColumnWidths";
+import { shownTimestampModes } from "@/test-utils/humanizeTs";
+import {
+ AccessGrant_Status,
+ AccessGrantSchema,
+} from "@/types/proto-es/v1/access_grant_service_pb";
vi.mock("react-i18next", () => ({
useTranslation: () => ({ t: (key: string) => key }),
initReactI18next: { type: "3rdParty", init: () => {} },
}));
-import { grantColumns } from "./ProjectAccessGrantsPage";
+vi.mock("@/components/HumanizeTs", async () => ({
+ ...(await import("@/test-utils/humanizeTs")).humanizeTsStub(),
+}));
+
+import { AccessGrantRow, grantColumns } from "./ProjectAccessGrantsPage";
+
+(
+ globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }
+).IS_REACT_ACT_ENVIRONMENT = true;
describe("grantColumns", () => {
const columns = grantColumns((key) => key);
- const expiry = columns.findIndex((column) => column.key === "expiration");
+ const at = (key: string) => columns.findIndex((column) => column.key === key);
test.each([1100, 1300, 1500, 1800])(
- "opens the expiry whole, zone included, in a %ipx table",
+ "opens both dates whole in a %ipx table",
(containerWidth) => {
- expect(distributeColumnWidths(columns, containerWidth)[expiry]).toBe(
- TIMESTAMP_COLUMN_WIDTH.operational
- );
+ const widths = distributeColumnWidths(columns, containerWidth);
+ expect(widths[at("created")]).toBe(TIMESTAMP_COLUMN_WIDTH.queue);
+ expect(widths[at("expiration")]).toBe(TIMESTAMP_COLUMN_WIDTH.operational);
}
);
- test("lets a reader narrow the expiry to the date", () => {
- expect(columns[expiry].minWidth).toBe(TIMESTAMP_COLUMN_MIN_WIDTH);
+ 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);
+ });
+});
+
+describe("AccessGrantRow", () => {
+ const roots: ReturnType<typeof createRoot>[] = [];
+ afterEach(() => {
+ for (const root of roots.splice(0)) {
+ act(() => root.unmount());
+ }
+ });
+
+ test("dates a grant in its forms, each ellipsizing when narrowed", () => {
+ const container = document.createElement("div");
+ const root = createRoot(container);
+ roots.push(root);
+ const nowMs = Date.now();
+ act(() =>
+ root.render(
+ <table>
+ <tbody>
+ <AccessGrantRow
+ grant={create(AccessGrantSchema, {
+ name: "projects/p1/accessGrants/1",
+ creator: "users/[email protected]",
+ status: AccessGrant_Status.ACTIVE,
+ createTime: timestampFromMs(nowMs - 60_000),
+ expiration: {
+ case: "expireTime",
+ value: timestampFromMs(nowMs + 86_400_000),
+ },
+ })}
+ canActivate={false}
+ canRevoke={false}
+ onActivate={() => {}}
+ onRevoke={() => {}}
+ />
+ </tbody>
+ </table>
+ )
+ );
+
+ expect(shownTimestampModes(container)).toEqual(["queue", "operational"]);
+ for (const date of container.querySelectorAll("[data-testid=humanize-ts]")) {
+ expect(date.className).toContain("truncate");
+ }
});
});
diff --git a/frontend/src/routes/project/ProjectAccessGrantsPage.tsx b/frontend/src/routes/project/ProjectAccessGrantsPage.tsx
index dec099aff7..72ab221a88 100644
--- a/frontend/src/routes/project/ProjectAccessGrantsPage.tsx
+++ b/frontend/src/routes/project/ProjectAccessGrantsPage.tsx
@@ -38,6 +38,7 @@ import {
import { BlockTooltip, Tooltip } from "@/components/ui/tooltip";
import { useCurrentUser } from "@/hooks/useAppState";
import {
+ type ColumnWithWidth,
distributeColumnWidths,
useColumnWidths,
} from "@/hooks/useColumnWidths";
@@ -73,21 +74,17 @@ type SortDir = "asc" | "desc";
// Column descriptor for the access-grants table. Position in the array is
// the `<colgroup>` order — keep this in sync with the cell order inside
-// `<AccessGrantRow>` (`useColumnWidths` indexes positionally).
+// `<AccessGrantRow>` (`useColumnWidths` indexes positionally). The width
+// fields are `ColumnWithWidth`'s.
//
-// - `title` — header label; omit for a blank header (actions col).
-// - `defaultWidth` — the width it opens at, before fitting to the container.
-// - `minWidth` — drag floor, and the fitting floor unless `grow` is false.
-// - `grow` — false to open at `defaultWidth` however wide the table.
-// - `sortKey` — present iff the column participates in server sort.
-// - `resizable` — defaults true; set false for purely action columns
-// where a too-narrow width clips the button row.
-type GrantColumn = {
+// - `title` — header label; omit for a blank header (actions col).
+// - `sortKey` — present iff the column participates in server sort.
+// - `resizable` — defaults true; set false for purely action columns where a
+// too-narrow width clips the button row.
+type GrantColumn = ColumnWithWidth & {
key: string;
title?: string;
- defaultWidth: number;
minWidth: number;
- grow?: boolean;
sortKey?: SortKey;
resizable?: boolean;
};
@@ -110,8 +107,9 @@ export const grantColumns = (t: (key: string) => string): GrantColumn[] => [
{
key: "created",
title: t("common.created-at"),
- defaultWidth: 200,
- minWidth: 132,
+ defaultWidth: TIMESTAMP_COLUMN_WIDTH.queue,
+ minWidth: TIMESTAMP_COLUMN_MIN_WIDTH,
+ grow: false,
sortKey: "create_time",
},
{
@@ -729,7 +727,7 @@ export function ProjectAccessGrantsPage({ projectId }: { projectId: string }) {
// AccessGrantRow
// ---------------------------------------------------------------------------
-function AccessGrantRow({
+export function AccessGrantRow({
grant,
issue,
canActivate,
diff --git a/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx b/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx
index ccb54db487..77bb3cd329 100644
--- a/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx
+++ b/frontend/src/routes/project/database-detail/changelog/DatabaseChangelogTable.test.tsx
@@ -81,9 +81,11 @@ describe("DatabaseChangelogTable", () => {
const [, created, rollout] = Array.from(container.querySelectorAll("col"));
expect(created.style.width).toBe(`${TIMESTAMP_COLUMN_WIDTH.compact}px`);
expect(rollout.style.width).toBe("");
- expect(
- container.querySelectorAll("[class*=cursor-col-resize]")
- ).toHaveLength(1);
+ const [, createdHeader, rolloutHeader] = Array.from(
+ container.querySelectorAll("th")
+ );
+ expect(createdHeader.querySelector("[class*=cursor-col-resize]")).not.toBeNull();
+ expect(rolloutHeader.querySelector("[class*=cursor-col-resize]")).toBeNull();
expect(
container.querySelector("tbody tr td:nth-child(2)")?.className
).toContain("truncate");