Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix(frontend): keep a create-database issue on Issue Detail after Rollout (#21686)
boojackca165e763531
diff --git a/frontend/src/components/issue-activity/IssueCommentActivity.test.tsx b/frontend/src/components/issue-activity/IssueCommentActivity.test.tsxindex 6094610627..bc8e79d522 100644--- a/frontend/src/components/issue-activity/IssueCommentActivity.test.tsx+++ b/frontend/src/components/issue-activity/IssueCommentActivity.test.tsx@@ -16,6 +16,7 @@ import {} from "@/types/proto-es/v1/issue_service_pb";import {Plan_ChangeDatabaseConfigSchema,+ Plan_CreateDatabaseConfigSchema,Plan_SpecSchema,PlanSchema,} from "@/types/proto-es/v1/plan_service_pb";@@ -130,6 +131,18 @@ const changeSpec = ({},});+// The issue-update comment the server writes when a rollout is created.+const rolloutCreatedComment = create(IssueCommentSchema, {+ creator: "users/[email protected]",+ event: {+ case: "issueUpdate",+ value: {+ fromStatus: IssueStatus.OPEN,+ toStatus: IssueStatus.DONE,+ },+ },+});+describe("canEditIssueComment", () => {const project = { name: "projects/p1" } as Parameters<typeof canEditIssueComment>[1];const own = create(IssueCommentSchema, {@@ -228,6 +241,59 @@ describe("IssueCommentRow", () => {).toBeInTheDocument();});+ test("links the rollout of a change plan from Issue Detail", () => {+ const { container } = render(+ <IssueCommentRow+ comment={rolloutCreatedComment}+ isLast+ issue={create(IssueSchema, { type: Issue_Type.DATABASE_CHANGE })}+ plan={create(PlanSchema, {+ name: "projects/p1/plans/677",+ hasRollout: true,+ specs: [changeSpec({ sheet: "s1", target: "db1" })],+ })}+ />+ );++ expect(+ screen.getByText(+ "activity.sentence.review-skipped-rollout-created-for-plan"+ )+ ).toBeInTheDocument();+ expect(container.querySelector("a")?.textContent).toBe("#677");+ });++ test("a create-database rollout lives on Issue Detail, so no plan link", () => {+ const { container } = render(+ <IssueCommentRow+ comment={rolloutCreatedComment}+ isLast+ issue={create(IssueSchema, { type: Issue_Type.DATABASE_CHANGE })}+ plan={create(PlanSchema, {+ name: "projects/p1/plans/677",+ hasRollout: true,+ specs: [+ create(Plan_SpecSchema, {+ id: "spec-1",+ config: {+ case: "createDatabaseConfig",+ value: create(Plan_CreateDatabaseConfigSchema, {+ target: "instances/i1",+ database: "db1",+ }),+ },+ }),+ ],+ })}+ />+ );++ expect(+ screen.getByText("activity.sentence.review-skipped-rollout-created")+ ).toBeInTheDocument();+ expect(container.querySelector("a")).toBeNull();+ });+test("names the service account that approved and marks its account type", () => {const comment = create(IssueCommentSchema, {creator: "users/[email protected]",diff --git a/frontend/src/components/issue-activity/IssueCommentActivity.tsx b/frontend/src/components/issue-activity/IssueCommentActivity.tsxindex 6c0b2f5af6..16f333fd93 100644--- a/frontend/src/components/issue-activity/IssueCommentActivity.tsx+++ b/frontend/src/components/issue-activity/IssueCommentActivity.tsx@@ -30,6 +30,7 @@ import {diffPlanSpecsForEvent,type SpecDiffEntry,} from "@/lib/plan/diffPlanSpecs";+import { shouldStayOnPlanDetailPage } from "@/lib/plan/workflow";import { cn } from "@/lib/utils";import { useAppStore } from "@/stores/app";import {@@ -517,13 +518,17 @@ function IssueCommentActionSentence({if (fromStatus !== undefined && toStatus !== undefined) {if (toStatus === IssueStatus.DONE) {if (isDoneRolloutComment(issue, plan, comment)) {- // On the plan-detail timeline (linkless) the rollout is for the plan- // you're already viewing, so drop the "for plan #id" link entirely.- const planUID = linkless || !plan ? "" : extractPlanUID(plan.name);- const planRoute =- linkless || !plan- ? undefined- : buildPlanRolloutRouteFromPlanName(plan.name);+ // Drop the "for plan #id" link on the plan-detail timeline (linkless),+ // where the rollout is for the plan being viewed, and for a+ // create-database plan, whose rollout lives on Issue Detail itself.+ const linkedPlan =+ !linkless && plan && shouldStayOnPlanDetailPage(plan)+ ? plan+ : undefined;+ const planUID = linkedPlan ? extractPlanUID(linkedPlan.name) : "";+ const planRoute = linkedPlan+ ? buildPlanRolloutRouteFromPlanName(linkedPlan.name)+ : undefined;const sentence =issue?.approvalStatus === ApprovalStatus.APPROVED? planUIDdiff --git a/frontend/src/routes/project/issue-detail/components/IssueDetailActionBar.tsx b/frontend/src/routes/project/issue-detail/components/IssueDetailActionBar.tsxindex db33582f63..1210d48869 100644--- a/frontend/src/routes/project/issue-detail/components/IssueDetailActionBar.tsx+++ b/frontend/src/routes/project/issue-detail/components/IssueDetailActionBar.tsx@@ -23,10 +23,7 @@ import {PROJECT_V1_ROUTE_ISSUE_DETAIL,PROJECT_V1_ROUTE_PLAN_DETAIL,} from "@/app/router/handles";-import {- buildPlanDeployRouteFromRolloutName,- buildPlanRolloutRouteFromPlanName,-} from "@/app/router/routeHelpers";+import { buildPlanRolloutRouteFromPlanName } from "@/app/router/routeHelpers";import { MarkdownEditor } from "@/components/MarkdownEditor";import { RouterLink } from "@/components/RouterLink";import { Button, buttonVariants } from "@/components/ui/button";@@ -77,6 +74,7 @@ import {} from "../utils/actionRegistry";import { isApprovalCompleted } from "../utils/approval";import { refreshIssueDetailState } from "../utils/refreshIssueDetailState";+import { routeAfterRolloutCreated } from "../utils/rollout";import { IssueDetailTaskRolloutActionPanel } from "./IssueDetailTaskRolloutActionPanel";export function IssueDetailActionBar() {@@ -230,12 +228,13 @@ export function IssueDetailActionBar() {const handleCreateRollout = useCallback(async (options?: { runAllTasks?: boolean }) => {- if (!page.plan) {+ const plan = page.plan;+ if (!plan) {return;}const createdRollout = await rolloutServiceClientConnect.createRollout(create(CreateRolloutRequestSchema, {- parent: page.plan.name,+ parent: plan.name,}));@@ -252,10 +251,9 @@ export function IssueDetailActionBar() {await handleRefreshIssueDetailState();- if (createdRollout.stages.length > 0) {- void router.push(- buildPlanDeployRouteFromRolloutName(createdRollout.name)- );+ const nextRoute = routeAfterRolloutCreated(plan, createdRollout);+ if (nextRoute) {+ void router.push(nextRoute);}},[handleRefreshIssueDetailState, page.plan]diff --git a/frontend/src/routes/project/issue-detail/utils/rollout.test.ts b/frontend/src/routes/project/issue-detail/utils/rollout.test.tsnew file mode 100644index 0000000000..9a14a85e0d--- /dev/null+++ b/frontend/src/routes/project/issue-detail/utils/rollout.test.ts@@ -0,0 +1,71 @@+// @vitest-environment node+import { create } from "@bufbuild/protobuf";+import { describe, expect, test } from "vitest";+import {+ Plan_ChangeDatabaseConfigSchema,+ Plan_CreateDatabaseConfigSchema,+ Plan_SpecSchema,+ PlanSchema,+} from "@/types/proto-es/v1/plan_service_pb";+import {+ RolloutSchema,+ StageSchema,+} from "@/types/proto-es/v1/rollout_service_pb";+import { routeAfterRolloutCreated } from "./rollout";++const changePlan = create(PlanSchema, {+ name: "projects/p1/plans/677",+ specs: [+ create(Plan_SpecSchema, {+ config: {+ case: "changeDatabaseConfig",+ value: create(Plan_ChangeDatabaseConfigSchema, {+ targets: ["instances/i1/databases/db1"],+ }),+ },+ }),+ ],+});++const createDatabasePlan = create(PlanSchema, {+ name: "projects/p1/plans/677",+ specs: [+ create(Plan_SpecSchema, {+ config: {+ case: "createDatabaseConfig",+ value: create(Plan_CreateDatabaseConfigSchema, {+ target: "instances/i1",+ database: "db1",+ }),+ },+ }),+ ],+});++const rollout = create(RolloutSchema, {+ name: "projects/p1/plans/677/rollout",+ stages: [+ create(StageSchema, { name: "projects/p1/plans/677/rollout/stages/prod" }),+ ],+});++describe("routeAfterRolloutCreated", () => {+ test("a change plan moves on to its rollout on Plan Detail", () => {+ expect(routeAfterRolloutCreated(changePlan, rollout)).toBeDefined();+ });++ test("a create-database plan stays on Issue Detail", () => {+ expect(+ routeAfterRolloutCreated(createDatabasePlan, rollout)+ ).toBeUndefined();+ });++ test("a rollout without stages has nowhere to go", () => {+ expect(+ routeAfterRolloutCreated(+ changePlan,+ create(RolloutSchema, { name: rollout.name })+ )+ ).toBeUndefined();+ });+});diff --git a/frontend/src/routes/project/issue-detail/utils/rollout.ts b/frontend/src/routes/project/issue-detail/utils/rollout.tsindex 96dc4b4bf1..5cc0fbcad5 100644--- a/frontend/src/routes/project/issue-detail/utils/rollout.ts+++ b/frontend/src/routes/project/issue-detail/utils/rollout.ts@@ -1,9 +1,13 @@+import type { RouteTarget } from "@/app/router";+import { buildPlanDeployRouteFromRolloutName } from "@/app/router/routeHelpers";+import { shouldStayOnPlanDetailPage } from "@/lib/plan/workflow";import { useAppStore } from "@/stores/app";import { roleNamePrefix } from "@/stores/modules/v1/common";import type { Issue } from "@/types/proto-es/v1/issue_service_pb";import { PolicyType } from "@/types/proto-es/v1/org_policy_service_pb";+import type { Plan } from "@/types/proto-es/v1/plan_service_pb";import type { Project } from "@/types/proto-es/v1/project_service_pb";-import type { Task } from "@/types/proto-es/v1/rollout_service_pb";+import type { Rollout, Task } from "@/types/proto-es/v1/rollout_service_pb";import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";import type { User } from "@/types/proto-es/v1/user_service_pb";import {@@ -125,3 +129,17 @@ export const preloadRolloutPermissionContext = async ({policyResults[0]?.status === "fulfilled" ? "loaded" : "unavailable");};++// The route to open once the Rollout action has created a rollout, or+// undefined to stay on Issue Detail. A create-database issue keeps its rollout+// on Issue Detail and Plan Detail redirects it straight back, so leaving would+// only flash Plan Detail and add a history entry.+export const routeAfterRolloutCreated = (+ plan: Plan,+ rollout: Rollout+): RouteTarget | undefined => {+ if (rollout.stages.length === 0 || !shouldStayOnPlanDetailPage(plan)) {+ return undefined;+ }+ return buildPlanDeployRouteFromRolloutName(rollout.name);+};diff --git a/frontend/tests/e2e/framework/api-client.ts b/frontend/tests/e2e/framework/api-client.tsindex aa4f6416a8..e12a2bacb9 100644--- a/frontend/tests/e2e/framework/api-client.ts+++ b/frontend/tests/e2e/framework/api-client.ts@@ -602,7 +602,17 @@ export class BytebaseApiClient {async createCreateDatabasePlan(project: string,title: string,- spec: { id: string; target: string; database: string; environment?: string },+ spec: {+ id: string;+ target: string;+ database: string;+ environment?: string;+ // Rolling the plan out on Postgres needs all three; a plan that is only+ // opened, never rolled out, can leave them off.+ characterSet?: string;+ collation?: string;+ owner?: string;+ },): Promise<{ name: string }> {return this.request<{ name: string }>("POST", `/v1/${project}/plans`, {title,@@ -613,6 +623,9 @@ export class BytebaseApiClient {target: spec.target,database: spec.database,...(spec.environment ? { environment: spec.environment } : {}),+ ...(spec.characterSet ? { characterSet: spec.characterSet } : {}),+ ...(spec.collation ? { collation: spec.collation } : {}),+ ...(spec.owner ? { owner: spec.owner } : {}),},},],diff --git a/frontend/tests/e2e/issue-detail/issue-detail-redirect.spec.ts b/frontend/tests/e2e/issue-detail/issue-detail-redirect.spec.tsindex 6e9852133d..659f47d7e0 100644--- a/frontend/tests/e2e/issue-detail/issue-detail-redirect.spec.ts+++ b/frontend/tests/e2e/issue-detail/issue-detail-redirect.spec.ts@@ -9,6 +9,8 @@//// B1 — a change issue redirects to Plan Detail, query string preserved.// B2 — a create-database issue (same DATABASE_CHANGE type) stays on Issue Detail.+// B3 — Rollout on a create-database issue stays put: no bounce through Plan+// Detail, no extra history entry, no plan link in Activity (BYT-10356).import {test,@@ -18,6 +20,7 @@ import {} from "@playwright/test";import { loadTestEnv, type TestEnv } from "../framework/env";import { BytebaseApiClient } from "../framework/api-client";+import { execSql, getInstancePgPort } from "../framework/psql";test.setTimeout(180_000);test.describe.configure({ mode: "serial" });@@ -113,3 +116,75 @@ test.describe("A create-database issue stays on Issue Detail (B2)", () => {expect(page.url()).not.toContain("/plans/");});});++test.describe("Rollout on a create-database issue stays on Issue Detail (B3)", () => {+ let issueId = "";+ let planId = "";+ let databaseName = "";++ test.beforeAll(async () => {+ const ts = Date.now();+ databaseName = `e2e_redirect_rollout_${ts}`;+ const plan = await env.api.createCreateDatabasePlan(+ env.project,+ `E2E Redirect B3 ${ts}`,+ {+ id: `spec-${ts}`,+ target: env.instance,+ database: databaseName,+ // The rollout runs for real on the sample Postgres, which needs an+ // owner, and a stage needs an environment.+ environment: "environments/prod",+ characterSet: "UTF8",+ collation: "en_US.UTF-8",+ owner: "bbsample",+ },+ );+ planId = plan.name.split("/").pop()!;+ const issue = await env.api.createIssue(+ env.project,+ `E2E Redirect B3 ${ts}`,+ plan.name,+ );+ issueId = issue.name.split("/").pop()!;+ });++ test.afterAll(async () => {+ // The rollout creates the database on the sample instance; drop it so the+ // instance does not accumulate one per run.+ try {+ const port = await getInstancePgPort(env);+ execSql("postgres", port, `DROP DATABASE IF EXISTS "${databaseName}"`);+ } catch {+ /* best effort */+ }+ });++ test("clicking Rollout keeps the user on the issue without a bounce through Plan Detail", async () => {+ const issuePath = `/projects/${projectId}/issues/${issueId}`;+ await page.goto(`${env.baseURL}${issuePath}`);+ const rolloutButton = page.getByRole("button", { name: "Rollout", exact: true });+ await expect(rolloutButton).toBeEnabled({ timeout: 20_000 });++ // The bug pushed /plans/{id}/rollout and Plan Detail replaced it with the+ // issue URL: a visible bounce plus one extra history entry. Record both.+ const historyBefore = await page.evaluate(() => window.history.length);+ const visited: string[] = [];+ page.on("framenavigated", (frame) => {+ if (frame === page.mainFrame()) visited.push(frame.url());+ });++ await rolloutButton.click();+ // The create-database task runs on rollout; wait for it to report done.+ await expect(page.getByText("(Created)")).toBeVisible({ timeout: 60_000 });++ expect(new URL(page.url()).pathname).toBe(issuePath);+ expect(visited.filter((url) => url.includes("/plans/"))).toEqual([]);+ expect(await page.evaluate(() => window.history.length)).toBe(historyBefore);++ // Activity records the rollout without a "for plan #id" link, which would+ // bounce the same way.+ await expect(page.getByText(/rollout created/)).toBeVisible({ timeout: 20_000 });+ await expect(page.locator(`a[href*="/plans/${planId}"]`)).toHaveCount(0);+ });+});