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(plan): View in Statement no longer asks to leave while editing (#21696)
boojack35c3cc4e96b5
diff --git a/frontend/src/routes/project/plan-detail/components/PlanDetailChangesBranch.test.tsx b/frontend/src/routes/project/plan-detail/components/PlanDetailChangesBranch.test.tsxindex 1f5ed8e4b3..3f8a193a15 100644--- a/frontend/src/routes/project/plan-detail/components/PlanDetailChangesBranch.test.tsx+++ b/frontend/src/routes/project/plan-detail/components/PlanDetailChangesBranch.test.tsx@@ -46,6 +46,7 @@ const mocks = vi.hoisted(() => ({localSheetListeners: new Set<() => void>(),patchState: vi.fn(),routerPush: vi.fn(),+ setDisplayedSpecId: vi.fn(),databaseStore: {batchGetOrFetchDatabases: vi.fn(async () => []),fetchDatabases: vi.fn(),@@ -281,7 +282,11 @@ vi.mock("@/stores", () => ({vi.mock("../shared/stores/usePlanDetailStore", () => ({usePlanDetailStore: (selector: (state: unknown) => unknown) =>- selector({ placements: new Map(), placementTargets: new Map() }),+ selector({+ placements: new Map(),+ placementTargets: new Map(),+ setDisplayedSpecId: mocks.setDisplayedSpecId,+ }),}));// The migrated component reads resource state via imperative@@ -725,6 +730,29 @@ async function flush() {}describe("PlanDetailChangesBranch", () => {+ it("publishes the change on screen, which is the first when none is selected", async () => {+ const page = buildPageState();+ page.plan.specs = [+ { id: "spec-1", config: { case: "changeDatabaseConfig", value: { targets: [] } } },+ { id: "spec-2", config: { case: "changeDatabaseConfig", value: { targets: [] } } },+ ] as unknown as PlanDetailPageState["plan"]["specs"];+ const render = (selectedSpecId: string) =>+ act(() => {+ root.render(+ <PlanDetailProvider value={page}>+ <PlanDetailChangesBranch selectedSpecId={selectedSpecId} onSelectedSpecIdChange={vi.fn()} />+ </PlanDetailProvider>+ );+ });++ render("");+ expect(mocks.setDisplayedSpecId).toHaveBeenLastCalledWith("spec-1");+ render("spec-2");+ expect(mocks.setDisplayedSpecId).toHaveBeenLastCalledWith("spec-2");+ act(() => root.render(null));+ expect(mocks.setDisplayedSpecId).toHaveBeenLastCalledWith(undefined);+ });+it("shows a count of unresolved threads on the tabs of the changes they anchor to", async () => {const page = buildPageState();page.issue = { name: "projects/foo/issues/1" } as PlanDetailPageState["issue"];diff --git a/frontend/src/routes/project/plan-detail/components/PlanDetailChangesBranch.tsx b/frontend/src/routes/project/plan-detail/components/PlanDetailChangesBranch.tsxindex b61634389a..5a92302913 100644--- a/frontend/src/routes/project/plan-detail/components/PlanDetailChangesBranch.tsx+++ b/frontend/src/routes/project/plan-detail/components/PlanDetailChangesBranch.tsx@@ -121,6 +121,7 @@ import { extractDatabaseGroupName } from "@/utils/v1/databaseGroup";import { sheetNameOfSpec } from "@/utils/v1/issue/plan";import { extractSheetUID, getSheetStatement } from "@/utils/v1/sheet";import { usePlanChangeReferenceData } from "../hooks/usePlanChangeReferenceData";+import { usePlanDetailStore } from "../shared/stores/usePlanDetailStore";import { usePlanDetailContext } from "../shell/PlanDetailContext";import { derivePlanChangeReference } from "../utils/changeReference";import {@@ -261,6 +262,12 @@ export function PlanDetailChangesBranch({}return getSelectedSpec({ selectedSpecId, specs });}, [pendingNewSpec, isPendingSelected, selectedSpecId, specs]);+ const setDisplayedSpecId = usePlanDetailStore((s) => s.setDisplayedSpecId);+ const displayedSpecId = selectedSpec?.id;+ useEffect(() => {+ setDisplayedSpecId(displayedSpecId);+ return () => setDisplayedSpecId(undefined);+ }, [displayedSpecId, setDisplayedSpecId]);const canModifySpecs = useMemo(() => {if (page.plan.state === State.DELETED) return false;if (page.readonly) return false;diff --git a/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx b/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsxindex b79676e165..c21645e90c 100644--- a/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx+++ b/frontend/src/routes/project/plan-detail/components/review/ReviewActivityTimeline.test.tsx@@ -130,7 +130,6 @@ vi.mock("@/app/router", () => ({vi.mock("../../shared/stores/usePlanDetailStore", () => ({usePlanDetailStore: (selector: (state: unknown) => unknown) =>selector({- selectedSpecId: "spec-1",placements: mocks.placements,placementTargets: mocks.placementTargets,activityFocus: mocks.activityFocus,diff --git a/frontend/src/routes/project/plan-detail/hooks/useFocusThread.test.ts b/frontend/src/routes/project/plan-detail/hooks/useFocusThread.test.tsindex cccc3b93f5..67309fdd44 100644--- a/frontend/src/routes/project/plan-detail/hooks/useFocusThread.test.ts+++ b/frontend/src/routes/project/plan-detail/hooks/useFocusThread.test.ts@@ -28,7 +28,7 @@ vi.mock("../shared/stores/usePlanDetailStore", () => ({getState: () => ({requestActivityFocus: mocks.requestActivityFocus,requestThreadFocus: mocks.requestThreadFocus,- selectedSpecId: "spec-1",+ displayedSpecId: "spec-1",}),}),}));@@ -69,6 +69,17 @@ test("opens a thread on another change in that change's editor", () => {expect(mocks.requestActivityFocus).not.toHaveBeenCalled();});+test("opens a thread on the change on screen without navigating", () => {+ const { result } = renderHook(() => useFocusThread());+ result.current.focusInStatement(thread("spec-1"), 4);+ expect(mocks.requestThreadFocus).toHaveBeenCalledWith({+ commentName: "projects/p/issues/1/issueComments/7",+ specId: "spec-1",+ lineNumber: 4,+ });+ expect(mocks.push).not.toHaveBeenCalled();+});+test.each([["without an anchor", undefined],["anchored to a change the plan no longer has", "spec-gone"],diff --git a/frontend/src/routes/project/plan-detail/hooks/useFocusThread.ts b/frontend/src/routes/project/plan-detail/hooks/useFocusThread.tsindex 8f5592059e..c94bec2b72 100644--- a/frontend/src/routes/project/plan-detail/hooks/useFocusThread.ts+++ b/frontend/src/routes/project/plan-detail/hooks/useFocusThread.ts@@ -36,7 +36,7 @@ export function useFocusThread() {lineNumber: lineNumber ?? root.statementAnchor?.startPosition?.line,});focusPlanPhase("changes", expandPhase);- if (storeApi.getState().selectedSpecId !== specId) {+ if (storeApi.getState().displayedSpecId !== specId) {void router.push({name: PROJECT_V1_ROUTE_PLAN_DETAIL_SPEC_DETAIL,diff --git a/frontend/src/routes/project/plan-detail/shared/stores/selectionSlice.ts b/frontend/src/routes/project/plan-detail/shared/stores/selectionSlice.tsindex d0f3bc049f..df67c0bda9 100644--- a/frontend/src/routes/project/plan-detail/shared/stores/selectionSlice.ts+++ b/frontend/src/routes/project/plan-detail/shared/stores/selectionSlice.ts@@ -4,14 +4,14 @@ export const createSelectionSlice: PlanDetailSliceCreator<SelectionSlice> = (set) => ({routePhase: undefined,- selectedSpecId: undefined,selectedStageId: undefined,selectedTaskName: undefined,setRouteSelection: (selection) =>set({routePhase: selection.phase,- selectedSpecId: selection.specId,selectedStageId: selection.stageId,selectedTaskName: selection.taskName,}),+ displayedSpecId: undefined,+ setDisplayedSpecId: (displayedSpecId) => set({ displayedSpecId }),});diff --git a/frontend/src/routes/project/plan-detail/shared/stores/types.ts b/frontend/src/routes/project/plan-detail/shared/stores/types.tsindex 7e3140b28f..9868730175 100644--- a/frontend/src/routes/project/plan-detail/shared/stores/types.ts+++ b/frontend/src/routes/project/plan-detail/shared/stores/types.ts@@ -52,15 +52,17 @@ export type EditingSlice = {export type SelectionSlice = {routePhase: PlanDetailPhase | undefined;- selectedSpecId: string | undefined;selectedStageId: string | undefined;selectedTaskName: string | undefined;setRouteSelection: (selection: {phase?: PlanDetailPhase;- specId?: string;stageId?: string;taskName?: string;}) => void;+ // The spec the Changes phase shows, which a URL without a spec still+ // resolves to one. Undefined while the Changes phase is not rendered.+ displayedSpecId: string | undefined;+ setDisplayedSpecId: (specId: string | undefined) => void;};export type PollingSlice = {diff --git a/frontend/src/routes/project/plan-detail/shell/hooks/useLeaveGuard.test.tsx b/frontend/src/routes/project/plan-detail/shell/hooks/useLeaveGuard.test.tsxnew file mode 100644index 0000000000..8e6f225db9--- /dev/null+++ b/frontend/src/routes/project/plan-detail/shell/hooks/useLeaveGuard.test.tsx@@ -0,0 +1,63 @@+import { act, renderHook } from "@testing-library/react";+import type { ReactNode } from "react";+import { beforeEach, expect, test, vi } from "vitest";+import { PlanDetailStoreProvider } from "../../shared/stores/PlanDetailStoreProvider";+import { usePlanDetailStoreApi } from "../../shared/stores/usePlanDetailStore";+import { useLeaveGuard } from "./useLeaveGuard";++const mocks = vi.hoisted(() => ({ replace: vi.fn() }));++vi.mock("@/app/router", () => ({+ router: { beforeEach: () => () => {}, replace: mocks.replace },+}));++const wrapper = ({ children }: { children: ReactNode }) => (+ <PlanDetailStoreProvider>{children}</PlanDetailStoreProvider>+);++const renderGuard = () =>+ renderHook(+ () => ({ guard: useLeaveGuard(), store: usePlanDetailStoreApi() }),+ { wrapper }+ );++// Editing one change, the reviewer asks for a thread on another; the guard+// holds that navigation for confirmation.+const holdThreadNavigation = (+ store: ReturnType<typeof usePlanDetailStoreApi>+) =>+ act(() => {+ const state = store.getState();+ state.setEditing("statement:spec-1", true);+ state.requestThreadFocus({+ commentName: "projects/p/issues/1/issueComments/7",+ specId: "spec-2",+ lineNumber: 4,+ });+ state.setPendingLeaveTarget("/projects/p/plans/1/specs/spec-2");+ state.setPendingLeaveConfirm(true);+ });++beforeEach(() => vi.clearAllMocks());++test("cancelling the leave drops the thread focus waiting on it", () => {+ const { result } = renderGuard();+ holdThreadNavigation(result.current.store);++ act(() => result.current.guard.resolveLeaveConfirm(false));++ expect(result.current.store.getState().threadFocus).toBeUndefined();+ expect(mocks.replace).not.toHaveBeenCalled();+});++test("confirming the leave keeps the thread focus for the destination", () => {+ const { result } = renderGuard();+ holdThreadNavigation(result.current.store);++ act(() => result.current.guard.resolveLeaveConfirm(true));++ expect(result.current.store.getState().threadFocus?.specId).toBe("spec-2");+ expect(mocks.replace).toHaveBeenCalledWith(+ "/projects/p/plans/1/specs/spec-2"+ );+});diff --git a/frontend/src/routes/project/plan-detail/shell/hooks/useLeaveGuard.ts b/frontend/src/routes/project/plan-detail/shell/hooks/useLeaveGuard.tsindex 78f3bb888f..b185063aba 100644--- a/frontend/src/routes/project/plan-detail/shell/hooks/useLeaveGuard.ts+++ b/frontend/src/routes/project/plan-detail/shell/hooks/useLeaveGuard.ts@@ -26,6 +26,11 @@ export function useLeaveGuard() {const target = confirmed ? state.pendingLeaveTarget : null;setPendingLeaveTarget(null);setPendingLeaveConfirm(false);+ // A thread focus still pending was waiting on the cancelled navigation;+ // left in place, it would fire whenever that spec is next shown.+ if (!confirmed && state.threadFocus) {+ state.clearThreadFocus(state.threadFocus.nonce);+ }if (target) {state.bypassLeaveGuardOnce();// Replace (not push) so a confirmed-discard navigation doesn't leavediff --git a/frontend/src/routes/project/plan-detail/shell/hooks/useRouteSelection.test.tsx b/frontend/src/routes/project/plan-detail/shell/hooks/useRouteSelection.test.tsxindex 5b5b94802f..20e947f940 100644--- a/frontend/src/routes/project/plan-detail/shell/hooks/useRouteSelection.test.tsx+++ b/frontend/src/routes/project/plan-detail/shell/hooks/useRouteSelection.test.tsx@@ -24,9 +24,6 @@ const renderSelection = (initialProps: RouteSelectionParams) =>(params: RouteSelectionParams) => {const route = useRouteSelection(params);const routePhase = usePlanDetailStore((state) => state.routePhase);- const selectedSpecId = usePlanDetailStore(- (state) => state.selectedSpecId- );const selectedStageId = usePlanDetailStore((state) => state.selectedStageId);@@ -37,7 +34,6 @@ const renderSelection = (initialProps: RouteSelectionParams) =>route,store: {routePhase,- selectedSpecId,selectedStageId,selectedTaskName,},@@ -131,7 +127,6 @@ describe("useRouteSelection", () => {await waitFor(() =>expect(result.current.store).toEqual({routePhase: expected.phase,- selectedSpecId: expected.specId,selectedStageId: expected.stageId,selectedTaskName: expected.taskId,})@@ -184,7 +179,6 @@ describe("useRouteSelection", () => {await waitFor(() =>expect(result.current.store).toEqual({routePhase: "changes",- selectedSpecId: "path-spec",selectedStageId: undefined,selectedTaskName: undefined,})@@ -257,7 +251,6 @@ describe("useRouteSelection", () => {await waitFor(() =>expect(result.current.store).toEqual({routePhase: expected.phase,- selectedSpecId: expected.specId,selectedStageId: expected.stageId,selectedTaskName: expected.taskId,})@@ -286,7 +279,6 @@ describe("useRouteSelection", () => {await waitFor(() =>expect(result.current.store).toEqual({routePhase: "deploy",- selectedSpecId: undefined,selectedStageId: "prod",selectedTaskName: "42",})@@ -319,7 +311,6 @@ describe("useRouteSelection", () => {await waitFor(() =>expect(result.current.store).toEqual({routePhase: undefined,- selectedSpecId: undefined,selectedStageId: undefined,selectedTaskName: undefined,})diff --git a/frontend/src/routes/project/plan-detail/shell/hooks/useRouteSelection.ts b/frontend/src/routes/project/plan-detail/shell/hooks/useRouteSelection.tsindex f511a5fd77..52bd5dd3e5 100644--- a/frontend/src/routes/project/plan-detail/shell/hooks/useRouteSelection.ts+++ b/frontend/src/routes/project/plan-detail/shell/hooks/useRouteSelection.ts@@ -109,9 +109,8 @@ export function useRouteSelection(params: {phase,stageId,taskName: taskId,- specId,});- }, [setRouteSelection, phase, specId, stageId, taskId]);+ }, [setRouteSelection, phase, stageId, taskId]);return { phase, selectionKey, specId, stageId, taskId };}