Skip to content

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

chore: some ui detail fix (#21657)

ecmadao4509e5cb2fdb
diff --git a/docs/agents/frontend-ux.md b/docs/agents/frontend-ux.md
index 6f17fff352..b99ce6a570 100644
--- a/docs/agents/frontend-ux.md
+++ b/docs/agents/frontend-ux.md
@@ -57,6 +57,8 @@ The product spacing vocabulary is 4, 6, 8, 12, 16, 24, and 32px.
| --- | ---: |
| Icon and adjacent label | 4-6px, according to control size |
| Sibling controls and buttons | 8px |
+| Field title and its direct description | 0px |
+| Section title and its direct description | 8px |
| Form label/title and its control | 6px |
| Controls within one field | 8px |
| Related content within a section | 16px |
@@ -185,9 +187,23 @@ behavior:
```
- A field has 6px between its label/title region and control.
+- A field title and its concise description have no added gap; the description
+ follows the title directly. With a description, the 6px field gap is between
+ the description and the control. Without one, it is between the title and
+ the control.
- Controls belonging to one field have 8px between them.
- A field group has 24px between fields.
- A section has 24px vertical padding and 16px internal rhythm.
+- A section title and its description have 8px between them. When a section
+ header and content stack, they have 16px between them. The default section
+ layout puts them side by side on large screens, so that vertical separation
+ applies only while stacked; `single-column` always uses it.
+- `FormSection`, `FormFieldGroup`, and `FormField` own these measurements.
+ Consumers MUST NOT add `gap-*`, `space-*`, or margin spacers to change their
+ title/description/control rhythm. Use `FormField spacing="section"` for a
+ field whose substantial control region needs 16px separation, and
+ `FormFieldGroup density="compact"` for the documented 16px dense-form
+ rhythm.
- On large screens, a section header uses 25% of the section width and content
uses the remainder. On smaller screens, they stack with 16px separation.
- A page that reads as one column uses `FormSection layout="single-column"`: the
diff --git a/docs/design/timestamp-display.md b/docs/design/timestamp-display.md
index e01be2b1bc..6f324bcad8 100644
--- a/docs/design/timestamp-display.md
+++ b/docs/design/timestamp-display.md
@@ -35,7 +35,9 @@ audit request.
**exactly when**. Display: absolute date-time, always.
Surfaces that are neither literally a queue nor a record (activity feeds, "created N ago" meta,
-sync freshness, agent chat) are freshness-first readings and follow the work-queue rendering.
+sync freshness) are freshness-first readings and follow the work-queue rendering by default. Agent
+chat uses a calendar-day reading: today and yesterday show their local time with a day label;
+older messages show the local date and minute without requiring hover.
The queue/history split covers *record* timestamps — times of things that already happened. A
**future-pointing time** is a third kind:
@@ -94,8 +96,9 @@ Consequence accepted: queue rows aged 1–29 days still read "x days ago". Rejec
7-day thresholds (would kill the complained-about string sooner, but diverge from the familiar
GitHub behavior).
-**D4 — Scope: switch everywhere + history-view carve-out.**
-`HumanizeTs` itself gains the 30-day switch, so every freshness-first surface behaves GitHub-style.
+**D4 — Scope: default switch + explicit absolute modes.**
+`HumanizeTs` itself gains the 30-day switch, so freshness-first surfaces behave GitHub-style by
+default. Agent chat explicitly uses the calendar-day mode for all messages, regardless of age.
The history views — database changelog, revision table, task-run history — flip to **absolute
date-time always**, consistent with the audit log. They are records of execution, not queues.
@@ -172,7 +175,7 @@ Every current `HumanizeTs` call site, classified under the principle:
| Deploy current status (latest-run times) | `routes/project/plan-detail/components/deploy/DeployTaskHeader.tsx`, `DeployLatestTaskRunInfo.tsx` | Freshness | 30d switch |
| **Scheduled rollout pill** | `DeployTaskHeader.tsx` (task pinned to a run time) | **Operational** | **Absolute + timezone** |
| 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 |
+| Agent chat | `modules/agent/components/AgentChat.tsx` | Feed | Today/Yesterday with local time, then local date and minute — calendar mode |
| Plan-check run time | `components/plan-check/PlanCheckSection.tsx` (bare `toLocaleString()` today — adopts `HumanizeTs`) | Freshness | 30d switch |
| AI review run finish time | `routes/project/plan-detail/components/PlanDetailAIReview.tsx` | 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, 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 the defaults together they give way first, down to the timestamp minimum, then the statement, the creator and the databases, with the status last. A narrow screen cuts each date's time and zone and keeps its day; the full date-time stays on the hover | Operational | Operational (D6 tooltip) |
diff --git a/frontend/src/components/DashboardSidebar.tsx b/frontend/src/components/DashboardSidebar.tsx
index 8346d855c0..e09eaa52c9 100644
--- a/frontend/src/components/DashboardSidebar.tsx
+++ b/frontend/src/components/DashboardSidebar.tsx
@@ -275,9 +275,9 @@ function filterSidebarList(items: SidebarItem[]): SidebarItem[] {
// ---------------------------------------------------------------------------
const parentRouteClass =
- "group flex items-center px-2 py-1.5 leading-normal font-medium rounded-xs text-main outline-item whitespace-nowrap text-sm!";
+ "group flex w-full items-center px-4 py-1.5 leading-normal font-medium rounded-xs text-main outline-item whitespace-nowrap text-sm!";
const childRouteClass =
- "group w-full flex items-center pl-9 pr-2 py-1 outline-item mb-0.5 rounded-xs whitespace-nowrap";
+ "group flex w-full items-center pl-11 pr-4 py-1 outline-item mb-0.5 rounded-xs whitespace-nowrap";
export function DashboardSidebar() {
const rawItems = useSidebarItems();
@@ -404,7 +404,7 @@ export function DashboardSidebar() {
return (
<div
key={index}
- className="border-t border-control-border my-2.5 mr-4 ml-2"
+ className="mx-4 my-2.5 border-t border-control-border"
/>
);
}
@@ -460,7 +460,7 @@ export function DashboardSidebar() {
return (
<nav className="flex-1 flex flex-col overflow-y-hidden border-r border-block-border">
<MobileSidebarSwitchers />
- <div className="flex-1 overflow-y-auto px-2.5 pt-3 pb-4 flex flex-col gap-y-1">
+ <div className="flex flex-1 flex-col gap-y-1 overflow-y-auto pt-3 pb-4">
{filteredItems.map((item, i) => renderItem(item, i))}
</div>
</nav>
diff --git a/frontend/src/components/DataExportButton.tsx b/frontend/src/components/DataExportButton.tsx
index 453e3a5063..6c9d9c8484 100644
--- a/frontend/src/components/DataExportButton.tsx
+++ b/frontend/src/components/DataExportButton.tsx
@@ -19,6 +19,12 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
+import {
+ FormControlGroup,
+ FormControlRow,
+ FormField,
+ FormFieldGroup,
+} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import {
Select,
@@ -402,25 +408,19 @@ export function DataExportButton({
</SheetTitle>
</SheetHeader>
<SheetBody>
- <div className="flex flex-col gap-y-4">
+ <FormFieldGroup>
{formContent}
- <div className="flex flex-col gap-y-1">
- <label className="text-sm text-control">
- {t("export-data.export-rows")}
- </label>
+ <FormField title={t("export-data.export-rows")}>
<MaxRowCountSelect
value={limit}
onChange={setLimit}
maximum={presetMax}
className="h-9"
/>
- </div>
+ </FormField>
- <div className="flex flex-col gap-y-1">
- <label className="text-sm text-control">
- {t("export-data.export-format")}
- </label>
+ <FormField title={t("export-data.export-format")}>
<Select
value={String(format)}
onValueChange={(value) => {
@@ -438,43 +438,42 @@ export function DataExportButton({
))}
</SelectContent>
</Select>
- </div>
+ </FormField>
{supportPassword && (
- <div className="flex flex-col gap-y-1">
- <label className="text-sm text-control">
- {t("export-data.password-optional")}
- </label>
+ <FormField title={t("export-data.password-optional")}>
<Input
type="password"
autoComplete="new-password"
value={password}
onChange={(e) => setPassword(e.target.value)}
/>
- <div className="flex items-center gap-x-2 mt-1">
- <Button
- type="button"
- appearance="outline"
- size="sm"
- onClick={handleGeneratePassword}
- >
- <Wand2 className="size-4 mr-1" />
- {t("export-data.generate-password")}
- </Button>
- <Button
- type="button"
- appearance="outline"
- size="sm"
- disabled={!password}
- onClick={() => void copyPasswordToClipboard(password)}
- >
- <Copy className="size-4 mr-1" />
- {t("common.copy")}
- </Button>
- </div>
- </div>
+ <FormControlGroup>
+ <FormControlRow>
+ <Button
+ type="button"
+ appearance="outline"
+ size="sm"
+ onClick={handleGeneratePassword}
+ >
+ <Wand2 className="size-4 mr-1" />
+ {t("export-data.generate-password")}
+ </Button>
+ <Button
+ type="button"
+ appearance="outline"
+ size="sm"
+ disabled={!password}
+ onClick={() => void copyPasswordToClipboard(password)}
+ >
+ <Copy className="size-4 mr-1" />
+ {t("common.copy")}
+ </Button>
+ </FormControlRow>
+ </FormControlGroup>
+ </FormField>
)}
- </div>
+ </FormFieldGroup>
</SheetBody>
<SheetFooter>
<Button appearance="outline" onClick={() => setShowDrawer(false)}>
diff --git a/frontend/src/components/DatabaseGroupForm.tsx b/frontend/src/components/DatabaseGroupForm.tsx
index 3986136af0..93230d1957 100644
--- a/frontend/src/components/DatabaseGroupForm.tsx
+++ b/frontend/src/components/DatabaseGroupForm.tsx
@@ -6,6 +6,7 @@ import { ExprEditor } from "@/components/ExprEditor";
import { MatchedDatabaseView } from "@/components/MatchedDatabaseView";
import { ResourceIdField } from "@/components/ResourceIdField";
import { Button } from "@/components/ui/button";
+import { FormControlGroup, FormField } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { StickyActionFooter } from "@/components/ui/sticky-action-footer";
import {
@@ -199,15 +200,14 @@ export function DatabaseGroupForm({
return (
<div className={`flex-1 flex flex-col ${className ?? ""}`}>
<div className="flex-1 mb-6">
- <div className="w-full">
- <p className="font-medium text-main mb-2">{t("common.name")}</p>
- <Input
- value={title}
- onChange={(e) => setTitle(e.target.value)}
- disabled={readonly}
- maxLength={200}
- />
- <div className="mt-2">
+ <FormField title={t("common.name")}>
+ <FormControlGroup>
+ <Input
+ value={title}
+ onChange={(e) => setTitle(e.target.value)}
+ disabled={readonly}
+ maxLength={200}
+ />
<ResourceIdField
suffix
value={resourceId}
@@ -218,8 +218,8 @@ export function DatabaseGroupForm({
onChange={setResourceId}
onValidationChange={setResourceIdValid}
/>
- </div>
- </div>
+ </FormControlGroup>
+ </FormField>
<hr className="my-6" />
diff --git a/frontend/src/components/ProjectSidebar.tsx b/frontend/src/components/ProjectSidebar.tsx
index e5114def03..cab2842ffb 100644
--- a/frontend/src/components/ProjectSidebar.tsx
+++ b/frontend/src/components/ProjectSidebar.tsx
@@ -244,9 +244,9 @@ function filterSidebarList(items: SidebarItem[]): SidebarItem[] {
// ---------------------------------------------------------------------------
const parentRouteClass =
- "group flex items-center px-2 py-1.5 leading-normal font-medium rounded-xs text-main outline-item whitespace-nowrap text-sm!";
+ "group flex w-full items-center px-4 py-1.5 leading-normal font-medium rounded-xs text-main outline-item whitespace-nowrap text-sm!";
const childRouteClass =
- "group w-full flex items-center pl-9 pr-2 py-1 outline-item mb-0.5 rounded-xs whitespace-nowrap";
+ "group flex w-full items-center pl-11 pr-4 py-1 outline-item mb-0.5 rounded-xs whitespace-nowrap";
export function ProjectSidebar() {
const rawItems = useSidebarItems();
@@ -432,7 +432,7 @@ export function ProjectSidebar() {
return (
<nav className="flex-1 flex flex-col overflow-y-hidden border-r border-block-border">
- <div className="flex-1 overflow-y-auto px-2.5 pt-3 pb-4 flex flex-col gap-y-1">
+ <div className="flex flex-1 flex-col gap-y-1 overflow-y-auto pt-3 pb-4">
{filteredItems.map((item, i) => renderItem(item, i))}
</div>
</nav>
diff --git a/frontend/src/components/instance/DataSourceForm.tsx b/frontend/src/components/instance/DataSourceForm.tsx
index 5954639bc7..44c92ce4dc 100644
--- a/frontend/src/components/instance/DataSourceForm.tsx
+++ b/frontend/src/components/instance/DataSourceForm.tsx
@@ -2240,7 +2240,7 @@ export function DataSourceForm({
>
{showExtraParameters || extraConnectionParamsList.length > 0 ? (
<>
- <FormControlGroup className="mt-2">
+ <FormControlGroup>
{allowEdit && (
<FormControlRow>
<Input
diff --git a/frontend/src/modules/sql-editor/components/SaveSheetModal.tsx b/frontend/src/modules/sql-editor/components/SaveSheetModal.tsx
index f0e60ce76c..72f462b431 100644
--- a/frontend/src/modules/sql-editor/components/SaveSheetModal.tsx
+++ b/frontend/src/modules/sql-editor/components/SaveSheetModal.tsx
@@ -2,6 +2,7 @@ import { useState } from "react";
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
+import { FormField, FormFieldGroup } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { useSQLEditorEvent } from "@/hooks/useSQLEditorEvent";
import { useSheetContextByView } from "@/modules/sql-editor/model/Sheet";
@@ -118,18 +119,19 @@ export function SaveSheetModal() {
<Dialog open={open} onOpenChange={(next) => !next && close()}>
<DialogContent className="w-[32rem] max-w-[calc(100vw-8rem)] 2xl:max-w-[calc(100vw-8rem)] p-4">
<DialogTitle>{t("sql-editor.save-sheet")}</DialogTitle>
- <div className="flex flex-col gap-y-3">
- <div className="flex flex-col gap-y-1">
- <p>{t("common.title")}</p>
- <Input
- value={title}
- onChange={(e) => setTitle(e.target.value)}
- placeholder={t("common.untitled")}
- maxLength={200}
- autoComplete="off"
- />
- </div>
- <FolderForm folder={folder} onFolderChange={setFolder} />
+ <div className="flex flex-col gap-y-4">
+ <FormFieldGroup density="compact">
+ <FormField title={t("common.title")}>
+ <Input
+ value={title}
+ onChange={(e) => setTitle(e.target.value)}
+ placeholder={t("common.untitled")}
+ maxLength={200}
+ autoComplete="off"
+ />
+ </FormField>
+ <FolderForm folder={folder} onFolderChange={setFolder} />
+ </FormFieldGroup>
<div className="flex justify-end gap-x-2 mt-4">
<Button appearance="outline" onClick={close}>
{t("common.close")}
diff --git a/frontend/src/routes/project/ProjectMaskingExemptionCreatePage.tsx b/frontend/src/routes/project/ProjectMaskingExemptionCreatePage.tsx
index 5f51e14802..244a794ba3 100644
--- a/frontend/src/routes/project/ProjectMaskingExemptionCreatePage.tsx
+++ b/frontend/src/routes/project/ProjectMaskingExemptionCreatePage.tsx
@@ -12,6 +12,7 @@ import { FeatureBadge } from "@/components/FeatureBadge";
import { Button } from "@/components/ui/button";
import { ExpirationPicker } from "@/components/ui/expiration-picker";
import { FeatureModal } from "@/components/ui/feature-modal";
+import { FormControlGroup, FormField } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { StickyActionFooter } from "@/components/ui/sticky-action-footer";
@@ -273,45 +274,49 @@ export function ProjectMaskingExemptionCreatePage({
</div>
{/* Reason */}
- <div className="w-full">
- <p className="mb-2 text-main">{t("common.reason")}</p>
+ <FormField className="w-full" title={t("common.reason")}>
<Input
value={description}
onChange={(e) => setDescription(e.target.value)}
placeholder={t("common.description")}
/>
- </div>
+ </FormField>
{/* Expiration */}
- <div className="w-full">
- <p className="mb-2 text-main">{t("common.expiration")}</p>
- <ExpirationPicker
- value={expirationTimestamp}
- onChange={setExpirationTimestamp}
- minDate={minDatetime}
- />
- {!expirationTimestamp && (
- <span className="textinfolabel">
- {t("settings.sensitive-data.never-expires")}
- </span>
- )}
- </div>
+ <FormField className="w-full" title={t("common.expiration")}>
+ <FormControlGroup>
+ <ExpirationPicker
+ value={expirationTimestamp}
+ onChange={setExpirationTimestamp}
+ minDate={minDatetime}
+ />
+ {!expirationTimestamp && (
+ <span className="textinfolabel">
+ {t("settings.sensitive-data.never-expires")}
+ </span>
+ )}
+ </FormControlGroup>
+ </FormField>
{/* Members */}
- <div className="w-full flex flex-col gap-y-2">
- <div className="flex text-main items-center gap-x-1">
- {t("settings.members.select-account", { count: 2 })}
- <span className="text-error">*</span>
- <Tooltip content={t("settings.members.select-account-hint")}>
- <CircleHelp className="size-4 textinfolabel" />
- </Tooltip>
- </div>
+ <FormField
+ className="w-full"
+ title={
+ <span className="flex items-center gap-x-1">
+ {t("settings.members.select-account", { count: 2 })}
+ <span className="text-error">*</span>
+ <Tooltip content={t("settings.members.select-account-hint")}>
+ <CircleHelp className="size-4 textinfolabel" />
+ </Tooltip>
+ </span>
+ }
+ >
<AccountMultiSelect
value={memberList}
onChange={setMemberList}
accountParents={accountParents}
/>
- </div>
+ </FormField>
</div>
</div>
diff --git a/frontend/src/routes/project/ProjectSettingsPage.tsx b/frontend/src/routes/project/ProjectSettingsPage.tsx
index 64c8643056..a569eb53e6 100644
--- a/frontend/src/routes/project/ProjectSettingsPage.tsx
+++ b/frontend/src/routes/project/ProjectSettingsPage.tsx
@@ -37,6 +37,7 @@ import { StickyActionFooter } from "@/components/ui/sticky-action-footer";
import { Switch } from "@/components/ui/switch";
import { Tooltip } from "@/components/ui/tooltip";
import { useProjectByName } from "@/hooks/useProjectByName";
+import { useUnsavedChangesGuard } from "@/hooks/useUnsavedChangesGuard";
import { pushNotification } from "@/stores";
import { useAppStore } from "@/stores/app";
import { projectNamePrefix } from "@/stores/modules/v1/common";
@@ -360,26 +361,7 @@ export function ProjectSettingsPage() {
parallelTasksPerRollout,
]);
- // Unsaved-changes protection: browser close + in-app navigation
- useEffect(() => {
- if (!isDirty) return;
- const onBeforeUnload = (e: BeforeUnloadEvent) => {
- e.returnValue = t("common.leave-without-saving");
- e.preventDefault();
- };
- window.addEventListener("beforeunload", onBeforeUnload);
- const removeGuard = router.beforeEach((_to, _from, next) => {
- if (window.confirm(t("common.leave-without-saving"))) {
- next();
- } else {
- next(false);
- }
- });
- return () => {
- window.removeEventListener("beforeunload", onBeforeUnload);
- removeGuard();
- };
- }, [isDirty, t]);
+ useUnsavedChangesGuard(isDirty);
// -----------------------------------------------------------------------
// Revert
diff --git a/frontend/src/routes/project/ProjectSyncSchemaPage.test.tsx b/frontend/src/routes/project/ProjectSyncSchemaPage.test.tsx
index 7a5415c95a..4fc10d70ff 100644
--- a/frontend/src/routes/project/ProjectSyncSchemaPage.test.tsx
+++ b/frontend/src/routes/project/ProjectSyncSchemaPage.test.tsx
@@ -24,6 +24,7 @@ const mocks = vi.hoisted(() => ({
engine: 1,
},
},
+ useUnsavedChangesGuard: vi.fn(),
}));
vi.mock("react-i18next", () => ({
@@ -102,6 +103,10 @@ vi.mock("@/hooks/useProjectByName", () => ({
useProjectByName: () => ({ name: "projects/project", title: "Project" }),
}));
+vi.mock("@/hooks/useUnsavedChangesGuard", () => ({
+ useUnsavedChangesGuard: mocks.useUnsavedChangesGuard,
+}));
+
vi.mock("@/components/monaco/core", () => ({
createMonacoDiffEditor: vi.fn(),
createMonacoEditor: vi.fn(),
@@ -183,6 +188,7 @@ describe("ProjectSyncSchemaPage target database search", () => {
let root: ReturnType<typeof createRoot>;
beforeEach(() => {
+ mocks.useUnsavedChangesGuard.mockReset();
mocks.routeQuery = {
changelog: "instances/source/databases/source-db/changelogs/1",
};
@@ -258,6 +264,15 @@ describe("ProjectSyncSchemaPage target database search", () => {
});
});
+ test("uses the shared unsaved changes guard", async () => {
+ act(() => {
+ root.render(<ProjectSyncSchemaPage projectId="project" />);
+ });
+ await flush();
+
+ expect(mocks.useUnsavedChangesGuard).toHaveBeenLastCalledWith(false);
+ });
+
test("allows an environmentless source database with a valid changelog", async () => {
mocks.routeQuery = {};
act(() => {
diff --git a/frontend/src/routes/project/ProjectSyncSchemaPage.tsx b/frontend/src/routes/project/ProjectSyncSchemaPage.tsx
index 01057c6eb3..2bd30759bf 100644
--- a/frontend/src/routes/project/ProjectSyncSchemaPage.tsx
+++ b/frontend/src/routes/project/ProjectSyncSchemaPage.tsx
@@ -34,6 +34,7 @@ import { Checkbox } from "@/components/ui/checkbox";
import { Combobox, type ComboboxOption } from "@/components/ui/combobox";
import { CopyButton } from "@/components/ui/copy-button";
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
+import { FormField } from "@/components/ui/form";
import { LAYER_SURFACE_CLASS } from "@/components/ui/layer";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { SearchInput } from "@/components/ui/search-input";
@@ -50,6 +51,7 @@ import { Table } from "@/components/ui/table";
import { useClickOutside } from "@/hooks/useClickOutside";
import { useEscapeKey } from "@/hooks/useEscapeKey";
import { useProjectByName } from "@/hooks/useProjectByName";
+import { useUnsavedChangesGuard } from "@/hooks/useUnsavedChangesGuard";
import { saveInitialSQL } from "@/lib/plan/initialSQLStorage";
import { applyPlanTitleToQuery } from "@/lib/plan/title";
import { cn } from "@/lib/utils";
@@ -175,35 +177,10 @@ export function ProjectSyncSchemaPage({ projectId }: { projectId: string }) {
setSourceSchemaString("");
}, [projectId]);
- // Route change guard: warn when leaving with unsaved raw SQL
- useEffect(() => {
- const shouldGuard =
- sourceSchemaType === SourceSchemaType.RAW_SQL &&
- rawSQLState.statement !== "";
- if (!shouldGuard) return;
-
- // Guard browser/tab unload
- const beforeUnload = (e: BeforeUnloadEvent) => {
- e.preventDefault();
- e.returnValue = "";
- };
- window.addEventListener("beforeunload", beforeUnload);
-
- // Guard in-app router navigation
- const removeRouterGuard = router.beforeEach((_to, _from, next) => {
- const answer = window.confirm(t("common.leave-without-saving"));
- if (answer) {
- next();
- } else {
- next(false);
- }
- });
-
- return () => {
- window.removeEventListener("beforeunload", beforeUnload);
- removeRouterGuard();
- };
- }, [sourceSchemaType, rawSQLState.statement, t]);
+ useUnsavedChangesGuard(
+ sourceSchemaType === SourceSchemaType.RAW_SQL &&
+ rawSQLState.statement !== ""
+ );
// Target databases state (lifted up so we can access from step controls)
const [selectedDatabaseNameList, setSelectedDatabaseNameList] = useState<
@@ -668,11 +645,11 @@ function DatabaseSchemaSelector({
allowedEngineTypeList={ALLOWED_ENGINES}
/>
</div>
- <div className="w-full flex flex-col gap-y-2">
- <div className="text-sm">
- {t("common.changelog")}
- <div className="textinfolabel">{t("changelog.select")}</div>
- </div>
+ <FormField
+ className="w-full"
+ title={t("common.changelog")}
+ description={t("changelog.select")}
+ >
<div className="w-full flex flex-row justify-start items-center relative">
<ChangelogSelector
database={databaseName}
@@ -680,7 +657,7 @@ function DatabaseSchemaSelector({
onChange={handleChangelogChange}
/>
</div>
- </div>
+ </FormField>
</div>
);
}
diff --git a/frontend/src/routes/project/ProjectWebhookForm.test.tsx b/frontend/src/routes/project/ProjectWebhookForm.test.tsx
index f2ed056f74..e1a118cbb1 100644
--- a/frontend/src/routes/project/ProjectWebhookForm.test.tsx
+++ b/frontend/src/routes/project/ProjectWebhookForm.test.tsx
@@ -123,15 +123,14 @@ describe("ProjectWebhookForm", () => {
expect(container.textContent).not.toContain("project.webhook.url-hidden");
});
- test("places the destination control below its label", () => {
+ test("uses shared field spacing for the destination control", () => {
const container = renderForm(true);
expect(
- container.querySelector('label[for="webhook-destination"]')
- ).toHaveClass("block");
- expect(container.querySelector("#webhook-destination")).toHaveClass(
- "mt-1",
- "w-full"
+ container.querySelector('[data-slot="form-field"]')
+ ).not.toBeNull();
+ expect(container.querySelector("#webhook-destination")).not.toHaveClass(
+ "mt-1"
);
});
});
diff --git a/frontend/src/routes/project/ProjectWebhookForm.tsx b/frontend/src/routes/project/ProjectWebhookForm.tsx
index 1a48145917..e5fd380d5c 100644
--- a/frontend/src/routes/project/ProjectWebhookForm.tsx
+++ b/frontend/src/routes/project/ProjectWebhookForm.tsx
@@ -26,6 +26,7 @@ import {
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
+import { FormField } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import {
Select,
@@ -374,11 +375,8 @@ export function ProjectWebhookForm({
<div className="flex flex-col gap-y-4">
{/* Destination type selector (create only) */}
{create && (
- <div>
- <label
- className="block font-medium text-main"
- htmlFor="webhook-destination"
- >
+ <FormField title={t("project.webhook.destination")}>
+ <label className="sr-only" htmlFor="webhook-destination">
{t("project.webhook.destination")}{" "}
<span className="text-error">*</span>
</label>
@@ -388,7 +386,7 @@ export function ProjectWebhookForm({
if (value) updateField("type", Number(value));
}}
>
- <SelectTrigger id="webhook-destination" className="mt-1 w-full">
+ <SelectTrigger id="webhook-destination" className="w-full">
<SelectValue>
{
webhookTypeItemList.find(
@@ -408,47 +406,55 @@ export function ProjectWebhookForm({
))}
</SelectContent>
</Select>
- </div>
+ </FormField>
)}
{/* Name */}
- <div>
- <label className="font-medium text-main">
- {t("common.name")} <span className="text-error">*</span>
- </label>
+ <FormField
+ title={
+ <>
+ {t("common.name")} <span className="text-error">*</span>
+ </>
+ }
+ >
<Input
- className="mt-1 w-full"
+ className="w-full"
placeholder={`${selectedWebhook?.name ?? "My"} Webhook`}
value={state.title}
onChange={(e) => updateField("title", e.target.value)}
disabled={!allowEdit}
/>
- </div>
+ </FormField>
{/* URL */}
- <div>
- <label className="font-medium text-main">
- {t("project.webhook.webhook-url")}{" "}
- <span className="text-error">*</span>
- </label>
- <div className="mt-1 text-sm text-control-light">
- {t("project.webhook.creation.desc", {
- destination: selectedWebhook?.name,
- })}{" "}
- <a
- href={selectedWebhook?.docUrl}
- target="_blank"
- rel="noreferrer"
- className="normal-link"
- >
- {t("project.webhook.creation.view-doc", {
+ <FormField
+ title={
+ <>
+ {t("project.webhook.webhook-url")}{" "}
+ <span className="text-error">*</span>
+ </>
+ }
+ description={
+ <>
+ {t("project.webhook.creation.desc", {
destination: selectedWebhook?.name,
- })}
- </a>
- .
- </div>
+ })}{" "}
+ <a
+ href={selectedWebhook?.docUrl}
+ target="_blank"
+ rel="noreferrer"
+ className="normal-link"
+ >
+ {t("project.webhook.creation.view-doc", {
+ destination: selectedWebhook?.name,
+ })}
+ </a>
+ .
+ </>
+ }
+ >
<Input
- className="mt-1 w-full"
+ className="w-full"
placeholder={selectedWebhook?.urlPlaceholder}
value={state.url}
onChange={(e) => updateField("url", e.target.value)}
@@ -459,7 +465,7 @@ export function ProjectWebhookForm({
{t("project.webhook.url-hidden")}
</div>
)}
- </div>
+ </FormField>
{/* Triggering activities */}
<div>
diff --git a/frontend/src/routes/project/database-detail/catalog/GrantAccessDialog.tsx b/frontend/src/routes/project/database-detail/catalog/GrantAccessDialog.tsx
index 11f2eb5d4b..9d6d448244 100644
--- a/frontend/src/routes/project/database-detail/catalog/GrantAccessDialog.tsx
+++ b/frontend/src/routes/project/database-detail/catalog/GrantAccessDialog.tsx
@@ -12,6 +12,7 @@ import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog";
import { ExpirationPicker } from "@/components/ui/expiration-picker";
import { FeatureModal } from "@/components/ui/feature-modal";
+import { FormControlGroup, FormField } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { Tooltip } from "@/components/ui/tooltip";
@@ -480,43 +481,47 @@ export function GrantAccessDialog({
)}
</div>
- <div className="w-full">
- <p className="mb-2 text-main">{t("common.reason")}</p>
+ <FormField className="w-full" title={t("common.reason")}>
<Input
value={description}
onChange={(event) => setDescription(event.target.value)}
placeholder={t("common.description")}
/>
- </div>
-
- <div className="w-full">
- <p className="mb-2 text-main">{t("common.expiration")}</p>
- <ExpirationPicker
- value={expirationTimestamp}
- onChange={setExpirationTimestamp}
- minDate={minDatetime}
- />
- {!expirationTimestamp && (
- <span className="textinfolabel">
- {t("settings.sensitive-data.never-expires")}
+ </FormField>
+
+ <FormField className="w-full" title={t("common.expiration")}>
+ <FormControlGroup>
+ <ExpirationPicker
+ value={expirationTimestamp}
+ onChange={setExpirationTimestamp}
+ minDate={minDatetime}
+ />
+ {!expirationTimestamp && (
+ <span className="textinfolabel">
+ {t("settings.sensitive-data.never-expires")}
+ </span>
+ )}
+ </FormControlGroup>
+ </FormField>
+
+ <FormField
+ className="w-full"
+ title={
+ <span className="flex items-center gap-x-1">
+ {t("settings.members.select-account", { count: 2 })}
+ <span className="text-error">*</span>
+ <Tooltip content={t("settings.members.select-account-hint")}>
+ <CircleHelp className="size-4 textinfolabel" />
+ </Tooltip>
</span>
- )}
- </div>
-
- <div className="w-full flex flex-col gap-y-2">
- <div className="flex text-main items-center gap-x-1">
- {t("settings.members.select-account", { count: 2 })}
- <span className="text-error">*</span>
- <Tooltip content={t("settings.members.select-account-hint")}>
- <CircleHelp className="size-4 textinfolabel" />
- </Tooltip>
- </div>
+ }
+ >
<AccountMultiSelect
value={memberList}
onChange={setMemberList}
accountParents={accountParents}
/>
- </div>
+ </FormField>
</div>
<div className="mt-6 flex justify-end gap-x-2">
diff --git a/frontend/src/routes/project/database-detail/panels/DatabaseSettingsPanel.tsx b/frontend/src/routes/project/database-detail/panels/DatabaseSettingsPanel.tsx
index cfce041a55..bfc0ced85c 100644
--- a/frontend/src/routes/project/database-detail/panels/DatabaseSettingsPanel.tsx
+++ b/frontend/src/routes/project/database-detail/panels/DatabaseSettingsPanel.tsx
@@ -7,6 +7,7 @@ import { EnvironmentSelect } from "@/components/EnvironmentSelect";
import { LabelListEditor } from "@/components/LabelListEditor";
import { PermissionGuard } from "@/components/PermissionGuard";
import { Button } from "@/components/ui/button";
+import { FormField } from "@/components/ui/form";
import { pushNotification } from "@/stores";
import { useAppStore } from "@/stores/app";
import type { Database } from "@/types/proto-es/v1/database_service_pb";
@@ -116,16 +117,13 @@ export function DatabaseSettingsPanel({ database }: { database: Database }) {
return (
<div className="divide-y">
<div className="flex flex-col gap-y-4 pb-7">
- <div>
- <p className="text-lg font-medium leading-7 text-main">
- {t("common.environment")}
- </p>
+ <FormField title={t("common.environment")}>
<PermissionGuard
permissions={["bb.databases.update"]}
project={getDatabaseProject(database)}
>
<EnvironmentSelect
- className="mt-1 max-w-md"
+ className="max-w-md"
value={database.effectiveEnvironment || ""}
clearable={allowClearEnvironment}
disabled={!allowUpdateDatabase}
@@ -139,7 +137,7 @@ export function DatabaseSettingsPanel({ database }: { database: Database }) {
onChange={handleSelectEnvironment}
/>
</PermissionGuard>
- </div>
+ </FormField>
</div>
<div className="flex flex-col gap-y-4 pt-7">
<div className="flex items-center">
diff --git a/frontend/src/routes/project/issue-detail/hooks/useIssueDetailPage.test.tsx b/frontend/src/routes/project/issue-detail/hooks/useIssueDetailPage.test.tsx
index cd90f70646..b2f36cd1ae 100644
--- a/frontend/src/routes/project/issue-detail/hooks/useIssueDetailPage.test.tsx
+++ b/frontend/src/routes/project/issue-detail/hooks/useIssueDetailPage.test.tsx
@@ -27,6 +27,7 @@ const mocks = vi.hoisted(() => ({
getRollout: vi.fn(),
listTaskRuns: vi.fn(),
setDocumentTitle: vi.fn(),
+ useUnsavedChangesGuard: vi.fn(),
}));
vi.mock("react-i18next", () => ({
@@ -57,6 +58,10 @@ vi.mock("@/hooks/useProjectByName", () => ({
}),
}));
+vi.mock("@/hooks/useUnsavedChangesGuard", () => ({
+ useUnsavedChangesGuard: mocks.useUnsavedChangesGuard,
+}));
+
vi.mock("@/app/router", () => ({
router: {
beforeEach: vi.fn(() => vi.fn()),
@@ -177,6 +182,17 @@ describe("useIssueDetailPage", () => {
);
});
+ test("uses the shared unsaved changes guard while editing", async () => {
+ const { result } = renderHook(() =>
+ useIssueDetailPage({ issueId: "1", pageHost: null, projectId: "foo" })
+ );
+ await waitFor(() => expect(result.current.ready).toBe(true));
+
+ expect(mocks.useUnsavedChangesGuard).toHaveBeenLastCalledWith(false);
+ act(() => result.current.setEditing("issue", true));
+ expect(mocks.useUnsavedChangesGuard).toHaveBeenLastCalledWith(true);
+ });
+
test("invalidates Issue and Plan lists when the linked Issue changes", async () => {
const { result } = renderHook(() =>
useIssueDetailPage({ issueId: "1", pageHost: null, projectId: "foo" })
diff --git a/frontend/src/routes/project/issue-detail/hooks/useIssueDetailPage.ts b/frontend/src/routes/project/issue-detail/hooks/useIssueDetailPage.ts
index 3ffcfb4162..b4585bb39a 100644
--- a/frontend/src/routes/project/issue-detail/hooks/useIssueDetailPage.ts
+++ b/frontend/src/routes/project/issue-detail/hooks/useIssueDetailPage.ts
@@ -1,7 +1,6 @@
import { create } from "@bufbuild/protobuf";
import { Code, ConnectError } from "@connectrpc/connect";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
-import { useTranslation } from "react-i18next";
import {
issueServiceClientConnect,
planServiceClientConnect,
@@ -12,6 +11,7 @@ import { router } from "@/app/router";
import { WORKSPACE_ROUTE_403, WORKSPACE_ROUTE_404 } from "@/app/router/handles";
import { buildPermissionDeniedRouteQuery } from "@/app/router/permissionDenied";
import { useProjectByName } from "@/hooks/useProjectByName";
+import { useUnsavedChangesGuard } from "@/hooks/useUnsavedChangesGuard";
import { invalidateProjectPagedDataCacheIfChanged } from "@/lib/projectPagedDataCache";
import { projectNamePrefix } from "@/stores";
import { useAppStore } from "@/stores/app";
@@ -269,7 +269,6 @@ export const useIssueDetailPage = ({
}: ProjectIssueDetailPageProps & {
pageHost: HTMLDivElement | null;
}): IssueDetailPageState => {
- const { t } = useTranslation();
// subscribe to re-render on project cache change
const projectsByName = useAppStore((s) => s.projectsByName);
void projectsByName;
@@ -481,29 +480,7 @@ export const useIssueDetailPage = ({
};
}, [pageHost, patchState]);
- useEffect(() => {
- if (!isEditing) {
- return;
- }
-
- const onBeforeUnload = (event: BeforeUnloadEvent) => {
- event.returnValue = t("common.leave-without-saving");
- event.preventDefault();
- };
- window.addEventListener("beforeunload", onBeforeUnload);
- const removeGuard = router.beforeEach((_to, _from, next) => {
- if (window.confirm(t("common.leave-without-saving"))) {
- next();
- } else {
- next(false);
- }
- });
-
- return () => {
- window.removeEventListener("beforeunload", onBeforeUnload);
- removeGuard();
- };
- }, [isEditing, t]);
+ useUnsavedChangesGuard(isEditing);
const isPlanDone = useMemo(() => {
if (!snapshot.rollout) {
diff --git a/frontend/src/routes/workspace/IDPDetailPage.tsx b/frontend/src/routes/workspace/IDPDetailPage.tsx
index 5c2f71de28..037dcd1e54 100644
--- a/frontend/src/routes/workspace/IDPDetailPage.tsx
+++ b/frontend/src/routes/workspace/IDPDetailPage.tsx
@@ -15,6 +15,12 @@ import {
AlertDialogTitle,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
+import {
+ FormControlGroup,
+ FormField,
+ FormFieldGroup,
+ FormSection,
+} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import { Switch } from "@/components/ui/switch";
@@ -1181,54 +1187,51 @@ export function IDPDetailPage() {
<div className="divide-y divide-block-border">
{/* General Section */}
- <div className="pb-6 lg:flex">
- <div className="text-left lg:w-1/4">
- <h1 className="text-2xl font-bold">{t("common.general")}</h1>
- </div>
- <div className="flex-1 mt-4 lg:px-4 lg:mt-0 flex flex-col gap-y-6">
- <div>
- <p className="text-base font-semibold text-main mb-2">
- {t("common.type")}
- </p>
+ <FormSection title={t("common.general")}>
+ <FormFieldGroup>
+ <FormField
+ title={t("common.type")}
+ description={t("settings.sso.form.provider-type-readonly-hint")}
+ >
<div className="flex items-center gap-x-3 p-3 bg-control-bg rounded-xs">
<ProviderIcon className="w-5 h-5 text-control-light" />
<span className="text-base font-medium text-main">
{identityProviderTypeToString(localIdp.type)}
</span>
</div>
- <p className="text-sm text-control-light mt-1">
- {t("settings.sso.form.provider-type-readonly-hint")}
- </p>
- </div>
-
- <div>
- <p className="text-base font-semibold mb-2">
- {t("settings.sso.form.name")}{" "}
- <span className="text-error">*</span>
- </p>
- <Input
- value={localIdp.title}
- disabled={!allowEdit}
- onChange={(e) =>
- setLocalIdp({ ...localIdp, title: e.target.value })
- }
- placeholder={t("settings.sso.form.name-description")}
- maxLength={200}
- />
- <div className="mt-1">
+ </FormField>
+
+ <FormField
+ title={
+ <>
+ {t("settings.sso.form.name")}{" "}
+ <span className="text-error">*</span>
+ </>
+ }
+ >
+ <FormControlGroup>
+ <Input
+ value={localIdp.title}
+ disabled={!allowEdit}
+ onChange={(e) =>
+ setLocalIdp({ ...localIdp, title: e.target.value })
+ }
+ placeholder={t("settings.sso.form.name-description")}
+ maxLength={200}
+ />
<ResourceIdField
suffix
resourceName="SSO"
readonly={true}
value={resourceId}
/>
- </div>
- </div>
+ </FormControlGroup>
+ </FormField>
- <div>
- <p className="text-base font-semibold text-main mb-2">
- {t("settings.sso.form.domain")}
- </p>
+ <FormField
+ title={t("settings.sso.form.domain")}
+ description={t("settings.sso.form.domain-optional-hint")}
+ >
<Input
value={localIdp.domain}
disabled={!allowEdit}
@@ -1237,62 +1240,47 @@ export function IDPDetailPage() {
}
placeholder={t("settings.sso.form.domain-description")}
/>
- <p className="text-sm text-control-light mt-1">
- {t("settings.sso.form.domain-optional-hint")}
- </p>
- </div>
- </div>
- </div>
+ </FormField>
+ </FormFieldGroup>
+ </FormSection>
{/* Configuration Section */}
- <div className="py-6 lg:flex">
- <div className="text-left lg:w-1/4">
- <h1 className="text-2xl font-bold">
- {t("settings.sso.form.configuration")}
- </h1>
- <p className="text-base text-control-light mt-3">
- {t("settings.sso.form.configuration-description")}
- </p>
- </div>
- <div className="flex-1 mt-4 lg:px-4 lg:mt-0 flex flex-col gap-y-6">
- <ProviderConfigForm
- providerType={localIdp.type}
- configForOAuth2={configForOAuth2}
- configForOIDC={configForOIDC}
- configForLDAP={configForLDAP}
- scopesString={scopesString}
- isEditMode={true}
- onUpdateOAuth2={handleOAuth2Update}
- onUpdateOIDC={handleOIDCUpdate}
- onUpdateLDAP={handleLDAPUpdate}
- onUpdateScopes={setScopesString}
- />
- </div>
- </div>
+ <FormSection
+ title={t("settings.sso.form.configuration")}
+ description={t("settings.sso.form.configuration-description")}
+ >
+ <ProviderConfigForm
+ providerType={localIdp.type}
+ configForOAuth2={configForOAuth2}
+ configForOIDC={configForOIDC}
+ configForLDAP={configForLDAP}
+ scopesString={scopesString}
+ isEditMode={true}
+ onUpdateOAuth2={handleOAuth2Update}
+ onUpdateOIDC={handleOIDCUpdate}
+ onUpdateLDAP={handleLDAPUpdate}
+ onUpdateScopes={setScopesString}
+ />
+ </FormSection>
{/* User Information Mapping Section */}
- <div className="py-6 lg:flex">
- <div className="text-left lg:w-1/4">
- <h1 className="text-2xl font-bold">
- {t("settings.sso.form.user-information-mapping")}
- </h1>
- <p className="text-base text-control-light mt-3">
- {t("settings.sso.form.user-information-mapping-description")}
- </p>
- </div>
- <div className="flex-1 mt-4 lg:px-4 lg:mt-0 flex flex-col gap-y-6">
+ <FormSection
+ title={t("settings.sso.form.user-information-mapping")}
+ description={t(
+ "settings.sso.form.user-information-mapping-description"
+ )}
+ >
+ <FormFieldGroup>
<FieldMappingForm
providerType={localIdp.type}
fieldMapping={fieldMapping}
onChange={setFieldMapping}
/>
- <div>
- {builtIdp && (
- <TestConnectionButton idp={builtIdp} disabled={!isFormValid} />
- )}
- </div>
- </div>
- </div>
+ {builtIdp && (
+ <TestConnectionButton idp={builtIdp} disabled={!isFormValid} />
+ )}
+ </FormFieldGroup>
+ </FormSection>
{/* Actions Section */}
<div className="py-6">
diff --git a/frontend/src/routes/workspace/IMPage.tsx b/frontend/src/routes/workspace/IMPage.tsx
index dafd0721bf..12a5483206 100644
--- a/frontend/src/routes/workspace/IMPage.tsx
+++ b/frontend/src/routes/workspace/IMPage.tsx
@@ -456,7 +456,7 @@ export function IMPage() {
</Select>
)}
- <FormFieldGroup className="mt-4 gap-y-4">
+ <FormFieldGroup density="compact" className="mt-4">
{item.fields.map((field) => (
<FormField key={field.key} title={<>{field.label}</>}>
<SecretInput
diff --git a/frontend/src/routes/workspace/SemanticTypesPage.test.tsx b/frontend/src/routes/workspace/SemanticTypesPage.test.tsx
index 6af23c2aa0..954b9ef36b 100644
--- a/frontend/src/routes/workspace/SemanticTypesPage.test.tsx
+++ b/frontend/src/routes/workspace/SemanticTypesPage.test.tsx
@@ -11,6 +11,7 @@ const mocks = vi.hoisted(() => ({
getOrFetchSettingByName: vi.fn(async () => undefined),
getSettingByName: vi.fn<() => unknown>(() => undefined),
upsertSetting: vi.fn(async (_request: unknown) => undefined),
+ useUnsavedChangesGuard: vi.fn(),
}));
vi.mock("react-i18next", async (importOriginal) => ({
@@ -22,6 +23,10 @@ vi.mock("@/components/FeatureAttention", () => ({
FeatureAttention: () => null,
}));
+vi.mock("@/hooks/useUnsavedChangesGuard", () => ({
+ useUnsavedChangesGuard: mocks.useUnsavedChangesGuard,
+}));
+
vi.mock("@/components/ui/tooltip", () => ({
Tooltip: ({
children,
@@ -88,6 +93,7 @@ afterEach(() => {
mocks.getOrFetchSettingByName.mockClear();
mocks.getSettingByName.mockClear();
mocks.upsertSetting.mockClear();
+ mocks.useUnsavedChangesGuard.mockClear();
});
describe("SemanticTypesPage", () => {
@@ -189,6 +195,61 @@ describe("SemanticTypesPage", () => {
);
});
+ test("guards navigation while a semantic type is being created or edited", async () => {
+ mocks.getSettingByName.mockReturnValue({
+ value: {
+ value: {
+ case: "semanticType",
+ value: { types: [{ id: "email", title: "Email" }] },
+ },
+ },
+ });
+ const container = document.createElement("div");
+ const root = createRoot(container);
+ roots.push(root);
+
+ await act(async () => {
+ root.render(<SemanticTypesPage />);
+ await Promise.resolve();
+ });
+
+ expect(mocks.useUnsavedChangesGuard).toHaveBeenLastCalledWith(false);
+
+ const createButton = Array.from(container.querySelectorAll("button")).find(
+ (button) => button.textContent === "common.create"
+ );
+ act(() => createButton?.click());
+ expect(mocks.useUnsavedChangesGuard).toHaveBeenLastCalledWith(true);
+
+ const cancelButton = Array.from(container.querySelectorAll("button")).find(
+ (button) => button.querySelector("svg.lucide-undo-2")
+ );
+ act(() => cancelButton?.click());
+ expect(mocks.useUnsavedChangesGuard).toHaveBeenLastCalledWith(false);
+
+ const emailRow = Array.from(container.querySelectorAll("tbody tr")).find(
+ (row) => row.querySelector("td:nth-child(2)")?.textContent === "email"
+ );
+ const editButton = Array.from(
+ emailRow?.querySelectorAll<HTMLButtonElement>("button") ?? []
+ ).at(-1);
+ act(() => editButton?.click());
+ expect(mocks.useUnsavedChangesGuard).toHaveBeenLastCalledWith(false);
+
+ const titleInput = emailRow?.querySelector<HTMLInputElement>(
+ 'input[placeholder="settings.sensitive-data.semantic-types.table.title"]'
+ );
+ act(() => {
+ const descriptor = Object.getOwnPropertyDescriptor(
+ HTMLInputElement.prototype,
+ "value"
+ );
+ descriptor?.set?.call(titleInput, "Email address");
+ titleInput?.dispatchEvent(new Event("input", { bubbles: true }));
+ });
+ expect(mocks.useUnsavedChangesGuard).toHaveBeenLastCalledWith(true);
+ });
+
test("preserves non-built-in bb-prefixed semantic types when saving", async () => {
mocks.getSettingByName.mockReturnValue({
value: {
diff --git a/frontend/src/routes/workspace/SemanticTypesPage.tsx b/frontend/src/routes/workspace/SemanticTypesPage.tsx
index b992116eb9..7ea5eb61d8 100644
--- a/frontend/src/routes/workspace/SemanticTypesPage.tsx
+++ b/frontend/src/routes/workspace/SemanticTypesPage.tsx
@@ -5,6 +5,7 @@ import { useTranslation } from "react-i18next";
import { v4 as uuidv4 } from "uuid";
import { FeatureAttention } from "@/components/FeatureAttention";
import { Button } from "@/components/ui/button";
+import { FormField } from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { NumberInput } from "@/components/ui/number-input";
import {
@@ -36,6 +37,7 @@ import {
WorkspacePageToolbar,
} from "@/components/WorkspacePageLayout";
import { useSemanticTypes } from "@/hooks/useSemanticTypes";
+import { useUnsavedChangesGuard } from "@/hooks/useUnsavedChangesGuard";
import { pushNotification } from "@/stores";
import { useAppStore } from "@/stores/app";
import type {
@@ -319,6 +321,11 @@ export function SemanticTypesPage() {
return undefined;
};
+ const hasUnsavedChanges = items.some(
+ ({ dirty, mode }) => mode === "CREATE" || (mode === "EDIT" && dirty)
+ );
+ useUnsavedChangesGuard(hasUnsavedChanges);
+
return (
<WorkspacePageLayout>
<FeatureAttention feature={PlanFeature.FEATURE_DATA_MASKING} />
@@ -633,12 +640,17 @@ function MaskingAlgorithmDrawer({
<SheetBody className="p-6">
{/* Masking type selector */}
- <div className="mb-6">
- <label className="text-sm font-medium">
- {t("settings.sensitive-data.algorithms.table.masking-type")}
- <span className="text-error ml-0.5">*</span>
- </label>
- <div className="grid grid-cols-3 gap-2 mt-2">
+ <FormField
+ className="mb-6"
+ title={
+ <>
+ {t("settings.sensitive-data.algorithms.table.masking-type")}
+ <span className="text-error ml-0.5">*</span>
+ </>
+ }
+ spacing="section"
+ >
+ <div className="grid grid-cols-3 gap-2">
{maskingTypeOptions.map((opt) => (
<Button
appearance="secondary"
@@ -655,31 +667,31 @@ function MaskingAlgorithmDrawer({
</Button>
))}
</div>
- </div>
+ </FormField>
<div className="border-t border-control-border pt-6 flex flex-col gap-y-6">
{maskingType === "full-mask" && (
- <div>
- <label className="text-sm font-medium">
- {t(
- "settings.sensitive-data.algorithms.full-mask.substitution"
- )}
- <span className="text-error ml-0.5">*</span>
- </label>
- <p className="text-sm text-control-placeholder mt-1">
- {t(
- "settings.sensitive-data.algorithms.full-mask.substitution-label"
- )}
- </p>
+ <FormField
+ title={
+ <>
+ {t(
+ "settings.sensitive-data.algorithms.full-mask.substitution"
+ )}
+ <span className="text-error ml-0.5">*</span>
+ </>
+ }
+ description={t(
+ "settings.sensitive-data.algorithms.full-mask.substitution-label"
+ )}
+ >
<Input
value={fullMaskSubstitution}
- className="mt-2"
placeholder={t(
"settings.sensitive-data.algorithms.full-mask.substitution"
)}
onChange={(e) => setFullMaskSubstitution(e.target.value)}
/>
- </div>
+ </FormField>
)}
{maskingType === "range-mask" && (
@@ -781,45 +793,50 @@ function MaskingAlgorithmDrawer({
)}
{maskingType === "md5-mask" && (
- <div>
- <label className="text-sm font-medium">
- {t("settings.sensitive-data.algorithms.md5-mask.salt")}
- <span className="text-error ml-0.5">*</span>
- </label>
- <p className="text-sm text-control-placeholder mt-1">
- {t("settings.sensitive-data.algorithms.md5-mask.salt-label")}
- </p>
+ <FormField
+ title={
+ <>
+ {t("settings.sensitive-data.algorithms.md5-mask.salt")}
+ <span className="text-error ml-0.5">*</span>
+ </>
+ }
+ description={t(
+ "settings.sensitive-data.algorithms.md5-mask.salt-label"
+ )}
+ >
<Input
value={md5Salt}
- className="mt-2"
placeholder={t(
"settings.sensitive-data.algorithms.md5-mask.salt"
)}
onChange={(e) => setMd5Salt(e.target.value)}
/>
- </div>
+ </FormField>
)}
{maskingType === "inner-outer-mask" && (
<>
- <div>
- <label className="text-sm font-medium">
- {t(
- "settings.sensitive-data.algorithms.inner-outer-mask.type"
- )}
- <span className="text-error ml-0.5">*</span>
- </label>
- <p className="text-sm text-control-placeholder mt-1">
- {innerOuterType === Algorithm_InnerOuterMask_MaskType.INNER
+ <FormField
+ title={
+ <>
+ {t(
+ "settings.sensitive-data.algorithms.inner-outer-mask.type"
+ )}
+ <span className="text-error ml-0.5">*</span>
+ </>
+ }
+ description={
+ innerOuterType === Algorithm_InnerOuterMask_MaskType.INNER
? t(
"settings.sensitive-data.algorithms.inner-outer-mask.inner-label"
)
: t(
"settings.sensitive-data.algorithms.inner-outer-mask.outer-label"
- )}
- </p>
+ )
+ }
+ >
<RadioGroup
- className="mt-2 gap-x-4"
+ className="gap-x-4"
value={String(innerOuterType)}
onValueChange={(value) =>
setInnerOuterType(
@@ -842,7 +859,7 @@ function MaskingAlgorithmDrawer({
)}
</RadioGroupItem>
</RadioGroup>
- </div>
+ </FormField>
<div className="flex gap-x-2 items-end">
<div className="flex flex-col gap-y-1">
<label className="text-sm font-medium">
diff --git a/frontend/src/routes/workspace/general/AnnouncementSection.test.tsx b/frontend/src/routes/workspace/general/AnnouncementSection.test.tsx
index aa7bed45ba..c049c54ced 100644
--- a/frontend/src/routes/workspace/general/AnnouncementSection.test.tsx
+++ b/frontend/src/routes/workspace/general/AnnouncementSection.test.tsx
@@ -105,6 +105,18 @@ beforeEach(async () => {
});
describe("AnnouncementSection", () => {
+ test("uses the default field rhythm for the theme selector", () => {
+ const { container, unmount } = renderIntoContainer(
+ <AnnouncementSection title="Announcement" onDirtyChange={() => {}} />
+ );
+
+ const themeField = container.querySelector('[data-slot="form-field"]');
+
+ expect(themeField?.className).not.toContain("gap-y-3");
+
+ unmount();
+ });
+
test("keeps announcement sections as peers for consistent field group spacing", () => {
const { container, unmount } = renderIntoContainer(
<AnnouncementSection title="Announcement" onDirtyChange={() => {}} />
diff --git a/frontend/src/routes/workspace/general/AnnouncementSection.tsx b/frontend/src/routes/workspace/general/AnnouncementSection.tsx
index e7ae9cc61c..438b6f4d8e 100644
--- a/frontend/src/routes/workspace/general/AnnouncementSection.tsx
+++ b/frontend/src/routes/workspace/general/AnnouncementSection.tsx
@@ -193,7 +193,6 @@ export const AnnouncementSection = forwardRef<
<FormFieldGroup>
{/* Theme selector */}
<FormField
- className="gap-y-3"
title={t("settings.general.workspace.announcement-theme.self")}
description={t(
"settings.general.workspace.announcement-theme.description"
diff --git a/frontend/src/routes/workspace/general/GeneralSection.tsx b/frontend/src/routes/workspace/general/GeneralSection.tsx
index 94e6ea3df2..d28f374c33 100644
--- a/frontend/src/routes/workspace/general/GeneralSection.tsx
+++ b/frontend/src/routes/workspace/general/GeneralSection.tsx
@@ -139,7 +139,7 @@ export const GeneralSection = forwardRef<SectionHandle, GeneralSectionProps>(
title={t(
"settings.general.workspace.default-landing-page.self"
)}
- className="gap-y-4"
+ spacing="section"
>
<RadioGroup
className="flex-col items-stretch gap-4"
diff --git a/frontend/src/routes/workspace/shared/AADSyncSheet.tsx b/frontend/src/routes/workspace/shared/AADSyncSheet.tsx
index b5d9e12c16..d0c061c434 100644
--- a/frontend/src/routes/workspace/shared/AADSyncSheet.tsx
+++ b/frontend/src/routes/workspace/shared/AADSyncSheet.tsx
@@ -7,6 +7,12 @@ import { LearnMoreLink } from "@/components/LearnMoreLink";
import { Alert } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { CopyButton } from "@/components/ui/copy-button";
+import {
+ FormControlGroup,
+ FormControlRow,
+ FormField,
+ FormFieldGroup,
+} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import {
Sheet,
@@ -109,7 +115,7 @@ export function AADSyncSheet({
</SheetHeader>
<SheetBody>
- <div className="flex flex-col gap-y-6">
+ <FormFieldGroup>
{/* Description */}
<p className="text-sm text-control-light">
{t("settings.members.entra-sync.description")}{" "}
@@ -120,14 +126,11 @@ export function AADSyncSheet({
<ExternalUrlAlert variant="warning" actionAppearance="outline" />
{/* SCIM Endpoint URL */}
- <div className="flex flex-col gap-y-2">
- <label className="block text-sm font-medium text-control">
- {t("settings.members.entra-sync.endpoint")}
- </label>
- <span className="textinfolabel text-sm">
- {t("settings.members.entra-sync.endpoint-tip")}
- </span>
- <div className="flex items-center gap-x-2">
+ <FormField
+ title={t("settings.members.entra-sync.endpoint")}
+ description={t("settings.members.entra-sync.endpoint-tip")}
+ >
+ <FormControlRow>
<Input readOnly value={scimUrl} className="flex-1 text-sm" />
<CopyButton
content={scimUrl}
@@ -135,62 +138,61 @@ export function AADSyncSheet({
size="sm"
disabled={!scimUrl}
/>
- </div>
- </div>
+ </FormControlRow>
+ </FormField>
{/* Secret Token */}
- <div className="flex flex-col gap-y-2">
- <label className="block text-sm font-medium text-control">
- {t("settings.members.entra-sync.secret-token")}
- </label>
- <span className="textinfolabel text-sm">
- {t("settings.members.entra-sync.secret-token-tip")}
- </span>
- {mintedToken ? (
- <>
- <div className="flex items-center gap-x-2">
- <Input
- readOnly
- value={mintedToken}
- className="flex-1 text-sm font-mono"
- />
- <CopyButton
- content={mintedToken}
- appearance="outline"
- size="sm"
+ <FormField
+ title={t("settings.members.entra-sync.secret-token")}
+ description={t("settings.members.entra-sync.secret-token-tip")}
+ >
+ <FormControlGroup>
+ {mintedToken ? (
+ <>
+ <FormControlRow>
+ <Input
+ readOnly
+ value={mintedToken}
+ className="flex-1 text-sm font-mono"
+ />
+ <CopyButton
+ content={mintedToken}
+ appearance="outline"
+ size="sm"
+ />
+ </FormControlRow>
+ <Alert
+ variant="warning"
+ description={t(
+ "settings.members.entra-sync.token-shown-once"
+ )}
/>
- </div>
- <Alert
- variant="warning"
- description={t(
- "settings.members.entra-sync.token-shown-once"
- )}
- />
- </>
- ) : (
- <span className="textinfolabel text-sm">
- {tokenConfigured
- ? t("settings.members.entra-sync.token-configured")
- : t("settings.members.entra-sync.token-not-configured")}
- </span>
- )}
- {hasWorkspacePermissionV2(
- "bb.workspaces.rotateDirectorySyncToken"
- ) && (
- <Button
- appearance="outline"
- size="sm"
- className="self-start"
- disabled={rotating}
- onClick={handleRotateToken}
- >
- {tokenConfigured
- ? t("settings.members.entra-sync.regenerate-token")
- : t("settings.members.entra-sync.generate-token")}
- </Button>
- )}
- </div>
- </div>
+ </>
+ ) : (
+ <span className="textinfolabel text-sm">
+ {tokenConfigured
+ ? t("settings.members.entra-sync.token-configured")
+ : t("settings.members.entra-sync.token-not-configured")}
+ </span>
+ )}
+ {hasWorkspacePermissionV2(
+ "bb.workspaces.rotateDirectorySyncToken"
+ ) && (
+ <Button
+ appearance="outline"
+ size="sm"
+ className="self-start"
+ disabled={rotating}
+ onClick={handleRotateToken}
+ >
+ {tokenConfigured
+ ? t("settings.members.entra-sync.regenerate-token")
+ : t("settings.members.entra-sync.generate-token")}
+ </Button>
+ )}
+ </FormControlGroup>
+ </FormField>
+ </FormFieldGroup>
</SheetBody>
<SheetFooter>