Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
refactor(frontend): simplify rollout view by removing context wrapper (#18678)
boojackc01edaa6d83b
diff --git a/frontend/src/components/Project/useProjectSidebar.ts b/frontend/src/components/Project/useProjectSidebar.tsindex e60091283b..069d156f74 100644--- a/frontend/src/components/Project/useProjectSidebar.ts+++ b/frontend/src/components/Project/useProjectSidebar.ts@@ -222,15 +222,11 @@ export const useProjectSidebar = (project: MaybeRef<Project>) => {const checkIsActive = (item: SidebarItem) => {const { name: current } = route;-+ const currentRoute = current?.toString() ?? "";const isActiveRoute =- item.path === current?.toString() ||- current?.toString().startsWith(`${item.path}.`);+ item.path === currentRoute || currentRoute.startsWith(`${item.path}.`);- if (isActiveRoute) {- return true;- }- return false;+ return isActiveRoute;};const activeSidebar = computed(() => {diff --git a/frontend/src/components/RolloutV1/components/RolloutView.vue b/frontend/src/components/RolloutV1/components/RolloutView.vueindex ad49ccd9ba..4860fb9e86 100644--- a/frontend/src/components/RolloutV1/components/RolloutView.vue+++ b/frontend/src/components/RolloutV1/components/RolloutView.vue@@ -38,7 +38,7 @@ import { useI18n } from "vue-i18n";import { useRoute, useRouter } from "vue-router";import BBSpin from "@/bbkit/BBSpin.vue";import { usePlanContextWithRollout } from "@/components/Plan/logic";-import { useRolloutViewContext } from "@/components/RolloutV1/logic/context";+import { useRolloutPreview } from "@/components/RolloutV1/logic";import { rolloutServiceClientConnect } from "@/grpcweb";import { PROJECT_V1_ROUTE_PLAN_ROLLOUT_STAGE } from "@/router/dashboard/projectV1";import { useCurrentProjectV1 } from "@/store";@@ -60,9 +60,12 @@ const route = useRoute();const router = useRouter();const { t } = useI18n();const { project } = useCurrentProjectV1();-const { events } = usePlanContextWithRollout();--const { rollout, mergedStages, ready } = useRolloutViewContext();+const { rollout, plan, events } = usePlanContextWithRollout();+const { ready, mergedStages } = useRolloutPreview(+ rollout,+ plan,+ project.value.name+);const routeStageId = computed(() => route.params.stageId as string | undefined);@@ -87,10 +90,8 @@ watch(() => [selectedStage.value, routeStageId.value, ready.value] as const,([stage, currentRouteStageId, isReady]) => {if (isReady && stage && !currentRouteStageId) {- // Auto-selected a stage but no stageId in route, navigate to itconst stageId = stage.name.split("/").pop();const planId = extractPlanUIDFromRolloutName(rollout.value.name);-router.replace({name: PROJECT_V1_ROUTE_PLAN_ROLLOUT_STAGE,params: {diff --git a/frontend/src/components/RolloutV1/components/TaskItem.vue b/frontend/src/components/RolloutV1/components/TaskItem.vueindex b1642dc197..294008cd77 100644--- a/frontend/src/components/RolloutV1/components/TaskItem.vue+++ b/frontend/src/components/RolloutV1/components/TaskItem.vue@@ -272,11 +272,7 @@ const emit = defineEmits<{}>();const { t } = useI18n();-const {- taskRuns: allTaskRuns,- readonly: contextReadonly,- events,-} = usePlanContextWithRollout();+const { taskRuns: allTaskRuns, events } = usePlanContextWithRollout();// Task actions (Run/Skip/Cancel)const {@@ -293,8 +289,7 @@ const {closeActionPanel,} = useTaskActions(() => props.task,- () => props.stage,- { readonly: () => props.readonly || contextReadonly.value }+ () => props.stage);// Handle action confirmed - trigger data refreshdiff --git a/frontend/src/components/RolloutV1/components/TaskRolloutActionPanel.vue b/frontend/src/components/RolloutV1/components/TaskRolloutActionPanel.vueindex ae1adb1bc8..a79ba1b2fd 100644--- a/frontend/src/components/RolloutV1/components/TaskRolloutActionPanel.vue+++ b/frontend/src/components/RolloutV1/components/TaskRolloutActionPanel.vue@@ -251,7 +251,7 @@ import {NTooltip,NVirtualList,} from "naive-ui";-import { computed, ref, watchEffect } from "vue";+import { computed, ref, watch, watchEffect } from "vue";import { useI18n } from "vue-i18n";import { ErrorList } from "@/components/IssueV1/components/common";import CommonDrawer from "@/components/IssueV1/components/Panel/CommonDrawer.vue";@@ -330,6 +330,23 @@ const runTimeInMS = ref<number | undefined>(undefined);const bypassPolicyChecks = ref(false);const { statusSummary: planCheckStatus } = usePlanCheckStatus(plan);+// Cache permission check result to prevent flickering during poller refetches.+// Re-check only when the panel opens (show changes from false to true).+const canRolloutPermission = ref(true);+watch(+ () => props.show,+ (show) => {+ if (show) {+ // Check permission when panel opens+ canRolloutPermission.value = canRolloutTasks(+ props.target.stage.tasks || [],+ issue.value+ );+ }+ },+ { immediate: true }+);+// Check issue approval status using the review contextconst issueApprovalStatus = computed(() => {if (!issue?.value) {@@ -398,7 +415,8 @@ const validationErrors = computed(() => {const errors: string[] = [];// Permission errors - always block rollout- if (!canRolloutTasks(eligibleTasks.value, issue.value)) {+ // Use cached permission to prevent flickering during poller refetches+ if (!canRolloutPermission.value) {// Special message for data export issues when user is not the creatorif (issue.value &&diff --git a/frontend/src/components/RolloutV1/components/TaskTable.vue b/frontend/src/components/RolloutV1/components/TaskTable.vueindex 3849d549b8..99099e0862 100644--- a/frontend/src/components/RolloutV1/components/TaskTable.vue+++ b/frontend/src/components/RolloutV1/components/TaskTable.vue@@ -30,7 +30,6 @@ import Timestamp from "@/components/misc/Timestamp.vue";import DatabaseDisplay from "@/components/Plan/components/common/DatabaseDisplay.vue";import { usePlanContextWithRollout } from "@/components/Plan/logic";import TaskStatus from "@/components/Rollout/kits/TaskStatus.vue";-import { useRolloutViewContext } from "@/components/RolloutV1/logic/context";import { PROJECT_V1_ROUTE_PLAN_ROLLOUT_TASK } from "@/router/dashboard/projectV1";import { useDatabaseV1Store } from "@/store";import { getTimeForPbTimestampProtoEs } from "@/types";@@ -64,8 +63,7 @@ const emit = defineEmits<{const { t } = useI18n();const router = useRouter();const databaseStore = useDatabaseV1Store();-const { rollout, mergedStages } = useRolloutViewContext();-const { taskRuns } = usePlanContextWithRollout();+const { rollout, taskRuns } = usePlanContextWithRollout();const taskList = computed(() => {if (props.taskStatusFilter.length === 0) {@@ -88,7 +86,7 @@ const handleSelectionChange = (selectedKeys: Array<string | number>) => {emit("update:selected-tasks", selectedTasks);};-const stages = computed(() => mergedStages.value);+const stages = computed(() => rollout.value.stages);// Virtual scroll configurationconst virtualScrollEnabled = computed(() => taskList.value.length > 100);diff --git a/frontend/src/components/RolloutV1/components/composables/useTaskActions.ts b/frontend/src/components/RolloutV1/components/composables/useTaskActions.tsindex 698e89c453..34af4a04be 100644--- a/frontend/src/components/RolloutV1/components/composables/useTaskActions.ts+++ b/frontend/src/components/RolloutV1/components/composables/useTaskActions.ts@@ -1,5 +1,5 @@import type { ComputedRef, Ref } from "vue";-import { computed, ref } from "vue";+import { computed, ref, watch } from "vue";import type { Stage, Task } from "@/types/proto-es/v1/rollout_service_pb";import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";import { canRolloutTasks } from "../taskPermissions";@@ -13,79 +13,79 @@ export interface TaskActionTarget {}export interface UseTaskActionsReturn {- // Action availabilitycanRun: ComputedRef<boolean>;canSkip: ComputedRef<boolean>;canCancel: ComputedRef<boolean>;hasActions: ComputedRef<boolean>;-- // Panel stateshowActionPanel: Ref<boolean>;currentAction: ComputedRef<TaskAction | undefined>;actionTarget: ComputedRef<TaskActionTarget | undefined>;-- // Action handlersrunTask: () => void;skipTask: () => void;cancelTask: () => void;closeActionPanel: () => void;}+// Statuses that allow run/skip actions+const RUNNABLE_STATUSES = [+ Task_Status.NOT_STARTED,+ Task_Status.CANCELED,+ Task_Status.FAILED,+];++// Statuses that allow cancel action+const CANCELABLE_STATUSES = [Task_Status.PENDING, Task_Status.RUNNING];+export const useTaskActions = (task: () => Task,- stage: () => Stage | undefined,- options: {- readonly?: () => boolean;- } = {}+ stage: () => Stage | undefined): UseTaskActionsReturn => {const showActionPanel = ref(false);const selectedAction = ref<TaskAction>();- const canPerformActions = computed(() => {- if (options.readonly?.()) return false;- return canRolloutTasks([task()]);- });-- const canRun = computed(() => {- if (!canPerformActions.value) return false;- return [- Task_Status.NOT_STARTED,- Task_Status.CANCELED,- Task_Status.FAILED,- ].includes(task().status);- });-- const canSkip = computed(() => {- if (!canPerformActions.value) return false;- return [- Task_Status.NOT_STARTED,- Task_Status.FAILED,- Task_Status.CANCELED,- ].includes(task().status);- });-- const canCancel = computed(() => {- if (!canPerformActions.value) return false;- return [Task_Status.PENDING, Task_Status.RUNNING].includes(task().status);- });-- const hasActions = computed(() => {- return canRun.value || canSkip.value || canCancel.value;- });-- const currentAction = computed((): TaskAction | undefined => {- if (!showActionPanel.value || !selectedAction.value) return undefined;- return selectedAction.value;- });+ // Cache permission check - only re-evaluate when task name changes+ // This prevents flickering during poller refetches+ const canPerformActions = ref(false);+ watch(+ () => task().name,+ () => {+ canPerformActions.value = canRolloutTasks([task()]);+ },+ { immediate: true }+ );++ // Use stable primitive for status to prevent re-computation on object reference change+ const taskStatus = computed(() => task().status);++ const canRun = computed(+ () =>+ canPerformActions.value && RUNNABLE_STATUSES.includes(taskStatus.value)+ );++ const canSkip = computed(+ () =>+ canPerformActions.value && RUNNABLE_STATUSES.includes(taskStatus.value)+ );++ const canCancel = computed(+ () =>+ canPerformActions.value && CANCELABLE_STATUSES.includes(taskStatus.value)+ );++ const hasActions = computed(+ () => canRun.value || canSkip.value || canCancel.value+ );++ const currentAction = computed(() =>+ showActionPanel.value && selectedAction.value+ ? selectedAction.value+ : undefined+ );const actionTarget = computed((): TaskActionTarget | undefined => {const s = stage();if (!currentAction.value || !s) return undefined;- return {- type: "tasks",- tasks: [task()],- stage: s,- };+ return { type: "tasks", tasks: [task()], stage: s };});const runTask = () => {diff --git a/frontend/src/components/RolloutV1/index.ts b/frontend/src/components/RolloutV1/index.tsindex 26200cde2d..74dd9585a6 100644--- a/frontend/src/components/RolloutV1/index.ts+++ b/frontend/src/components/RolloutV1/index.ts@@ -21,8 +21,8 @@ export { default as TaskFilter } from "./components/TaskFilter.vue";// Task run log viewerexport * from "./components/TaskRunLogViewer";-// Logic/context-export * from "./logic/context";+// Logic+export * from "./logic";// Constantsexport * from "./constants/task";diff --git a/frontend/src/components/RolloutV1/logic/context.ts b/frontend/src/components/RolloutV1/logic/context.tsdeleted file mode 100644index cee8903702..0000000000--- a/frontend/src/components/RolloutV1/logic/context.ts+++ /dev/null@@ -1,101 +0,0 @@-import { create } from "@bufbuild/protobuf";-import type { InjectionKey } from "vue";-import { computed, inject, nextTick, onUnmounted, provide, ref } from "vue";-import {- generateRolloutPreview,- usePlanContextWithRollout,-} from "@/components/Plan/logic";-import { useCurrentProjectV1 } from "@/store";-import type { Rollout } from "@/types/proto-es/v1/rollout_service_pb";-import { RolloutSchema } from "@/types/proto-es/v1/rollout_service_pb";--export const KEY = Symbol(- "bb.plan.rollout-view"-) as InjectionKey<RolloutViewContext>;--export const useRolloutViewContext = () => {- return inject(KEY)!;-};--export const provideRolloutViewContext = () => {- const { events, rollout, plan } = usePlanContextWithRollout();- const { project } = useCurrentProjectV1();-- const ready = ref(false);- const rolloutPreview = ref<Rollout>(create(RolloutSchema, {}));-- const mergedStages = computed(() => {- // Merge preview stages with created rollout stages- const createdStages = rollout.value.stages;- const previewStages = rolloutPreview.value.stages;-- // Start with created stages- const merged = [...createdStages];-- // Add preview stages that don't exist in created stages- for (const previewStage of previewStages) {- const existingIndex = merged.findIndex(- (s) => s.environment === previewStage.environment- );- if (existingIndex === -1) {- merged.push(previewStage);- }- }-- return merged;- });-- const fetchRolloutPreview = async () => {- try {- // Validate that plan and project are available- if (!plan.value?.name || !project.value?.name) {- rolloutPreview.value = create(RolloutSchema, {});- return;- }-- // Generate rollout preview locally instead of calling backend- const preview = await generateRolloutPreview(- plan.value,- project.value.name- );- rolloutPreview.value = preview;- } catch (error) {- console.error("Failed to generate rollout preview:", error);- rolloutPreview.value = create(RolloutSchema, {});- } finally {- nextTick(() => {- ready.value = true;- });- }- };-- // Initial fetch- fetchRolloutPreview();-- // Listen for resource refresh completion- const unsubscribe = events.on(- "resource-refresh-completed",- async ({ resources }) => {- // Refresh rollout preview if rollout was refreshed- if (resources.includes("rollout")) {- await fetchRolloutPreview();- }- }- );-- // Clean up event listener when component unmounts.- onUnmounted(() => {- unsubscribe();- });-- const context = {- ready,- rollout,- mergedStages,- };-- provide(KEY, context);- return context;-};--type RolloutViewContext = ReturnType<typeof provideRolloutViewContext>;diff --git a/frontend/src/components/RolloutV1/logic/index.ts b/frontend/src/components/RolloutV1/logic/index.tsindex 2edd280c79..5234f1db83 100644--- a/frontend/src/components/RolloutV1/logic/index.ts+++ b/frontend/src/components/RolloutV1/logic/index.ts@@ -1 +1 @@-export * from "./context";+export * from "./useRolloutPreview";diff --git a/frontend/src/components/RolloutV1/logic/useRolloutPreview.ts b/frontend/src/components/RolloutV1/logic/useRolloutPreview.tsnew file mode 100644index 0000000000..75803c306e--- /dev/null+++ b/frontend/src/components/RolloutV1/logic/useRolloutPreview.ts@@ -0,0 +1,34 @@+import type { Ref } from "vue";+import { computed, ref } from "vue";+import { generateRolloutPreview } from "@/components/Plan/logic";+import type { Plan } from "@/types/proto-es/v1/plan_service_pb";+import type { Rollout, Stage } from "@/types/proto-es/v1/rollout_service_pb";++export const useRolloutPreview = (+ rollout: Ref<Rollout>,+ plan: Ref<Plan>,+ projectName: string+) => {+ const ready = ref(false);+ const previewStages = ref<Stage[]>([]);++ generateRolloutPreview(plan.value, projectName)+ .then((preview) => {+ previewStages.value = preview.stages;+ })+ .catch(() => {})+ .finally(() => {+ ready.value = true;+ });++ const mergedStages = computed(() => {+ const created = rollout.value.stages;+ const createdEnvs = new Set(created.map((s) => s.environment));+ return [+ ...created,+ ...previewStages.value.filter((s) => !createdEnvs.has(s.environment)),+ ];+ });++ return { ready, mergedStages };+};diff --git a/frontend/src/router/dashboard/projectV1.ts b/frontend/src/router/dashboard/projectV1.tsindex 2c33aaf3aa..28dd0f6f45 100644--- a/frontend/src/router/dashboard/projectV1.ts+++ b/frontend/src/router/dashboard/projectV1.ts@@ -29,8 +29,8 @@ export const PROJECT_V1_ROUTE_SETTINGS = `${PROJECT_V1_ROUTE_DASHBOARD}.settingsexport const PROJECT_V1_ROUTE_EXPORT_CENTER = `${PROJECT_V1_ROUTE_DASHBOARD}.export-center`;export const PROJECT_V1_ROUTE_RELEASES = `${PROJECT_V1_ROUTE_DASHBOARD}.release`;export const PROJECT_V1_ROUTE_RELEASE_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}.release.detail`;-export const PROJECT_V1_ROUTE_ROLLOUTS = `${PROJECT_V1_ROUTE_DASHBOARD}.rollout`;-export const PROJECT_V1_ROUTE_PLAN_ROLLOUT = `${PROJECT_V1_ROUTE_PLAN_DETAIL}.rollout`;+export const PROJECT_V1_ROUTE_ROLLOUTS = `${PROJECT_V1_ROUTE_DASHBOARD}.rollouts`;+export const PROJECT_V1_ROUTE_PLAN_ROLLOUT = `${PROJECT_V1_ROUTE_ROLLOUTS}.rollout`;export const PROJECT_V1_ROUTE_PLAN_ROLLOUT_STAGE = `${PROJECT_V1_ROUTE_PLAN_ROLLOUT}.stage`;export const PROJECT_V1_ROUTE_PLAN_ROLLOUT_TASK = `${PROJECT_V1_ROUTE_PLAN_ROLLOUT_STAGE}.task`;@@ -91,40 +91,33 @@ const rolloutRoutes: RouteRecordRaw[] = [children: [{path: "",- component: () => import("@/views/project/RolloutDetailLayout.vue"),+ name: PROJECT_V1_ROUTE_PLAN_ROLLOUT,+ component: () =>+ import("@/components/RolloutV1/components/RolloutView.vue"),props: true,- children: [- {- path: "",- name: PROJECT_V1_ROUTE_PLAN_ROLLOUT,- component: () =>- import("@/components/RolloutV1/components/RolloutView.vue"),- props: true,- meta: {- requiredPermissionList: () => ["bb.rollouts.get"],- },- },- {- path: "stages/:stageId",- name: PROJECT_V1_ROUTE_PLAN_ROLLOUT_STAGE,- component: () =>- import("@/components/RolloutV1/components/RolloutView.vue"),- props: true,- meta: {- requiredPermissionList: () => ["bb.rollouts.get"],- },- },- {- path: "stages/:stageId/tasks/:taskId",- name: PROJECT_V1_ROUTE_PLAN_ROLLOUT_TASK,- component: () =>- import("@/components/RolloutV1/components/TaskView.vue"),- props: true,- meta: {- requiredPermissionList: () => ["bb.rollouts.get"],- },- },- ],+ meta: {+ requiredPermissionList: () => ["bb.rollouts.get"],+ },+ },+ {+ path: "stages/:stageId",+ name: PROJECT_V1_ROUTE_PLAN_ROLLOUT_STAGE,+ component: () =>+ import("@/components/RolloutV1/components/RolloutView.vue"),+ props: true,+ meta: {+ requiredPermissionList: () => ["bb.rollouts.get"],+ },+ },+ {+ path: "stages/:stageId/tasks/:taskId",+ name: PROJECT_V1_ROUTE_PLAN_ROLLOUT_TASK,+ component: () =>+ import("@/components/RolloutV1/components/TaskView.vue"),+ props: true,+ meta: {+ requiredPermissionList: () => ["bb.rollouts.get"],+ },},],},diff --git a/frontend/src/views/project/RolloutDetailLayout.vue b/frontend/src/views/project/RolloutDetailLayout.vuedeleted file mode 100644index b09915768e..0000000000--- a/frontend/src/views/project/RolloutDetailLayout.vue+++ /dev/null@@ -1,41 +0,0 @@-<template>- <router-view />-</template>--<script lang="ts" setup>-import { watchEffect } from "vue";-import { usePlanContextWithRollout } from "@/components/Plan";-import { provideRolloutViewContext } from "@/components/RolloutV1/logic/context";-import { usePolicyV1Store } from "@/store";-import { PolicyType } from "@/types/proto-es/v1/org_policy_service_pb";--const { rollout } = usePlanContextWithRollout();-const policyStore = usePolicyV1Store();--provideRolloutViewContext();--// Prepare rollout policies for all stages in the rollout.-watchEffect(() => {- if (!rollout.value) return;-- const environmentNames = new Set<string>();- // Collect all unique environment names from stages- for (const stage of rollout.value.stages) {- if (stage.environment) {- environmentNames.add(stage.environment);- }- }-- // Fetch rollout policies for each environment- for (const environmentName of environmentNames) {- policyStore- .getOrFetchPolicyByParentAndType({- parentPath: environmentName,- policyType: PolicyType.ROLLOUT_POLICY,- })- .catch(() => {- // Silently ignore errors as policies might not exist- });- }-});-</script>diff --git a/frontend/src/views/project/RolloutLayout.vue b/frontend/src/views/project/RolloutLayout.vueindex f4f5042d03..852dfa4dfe 100644--- a/frontend/src/views/project/RolloutLayout.vue+++ b/frontend/src/views/project/RolloutLayout.vue@@ -29,7 +29,7 @@<script lang="ts" setup>import { useTitle } from "@vueuse/core";import { NSpin } from "naive-ui";-import { computed, ref, toRef } from "vue";+import { computed, ref, toRef, watchEffect } from "vue";import { useI18n } from "vue-i18n";import {providePlanContext,@@ -41,6 +41,8 @@ import { provideSidebarContext } from "@/components/Plan/logic/sidebar";import PollerProvider from "@/components/Plan/PollerProvider.vue";import RolloutBreadcrumb from "@/components/RolloutV1/components/RolloutBreadcrumb.vue";import { useBodyLayoutContext } from "@/layouts/common";+import { usePolicyV1Store } from "@/store";+import { PolicyType } from "@/types/proto-es/v1/org_policy_service_pb";const props = defineProps<{projectId: string;@@ -63,22 +65,25 @@ const planBaseContext = useBasePlanContext({issue,});const containerRef = ref<HTMLElement>();+const policyStore = usePolicyV1Store();-const ready = computed(() => {- // Ready when we have a rollout and initialization is complete- return !!rollout.value && !isInitializing.value;-});+const ready = computed(() => !!rollout.value && !isInitializing.value);-const title = computed(() => {- // Use issue title if available, otherwise plan title- if (issue.value?.title) {- return issue.value.title;- }- if (plan.value?.title) {- return plan.value.title;+// Prefetch rollout policies for all stages+watchEffect(() => {+ if (!rollout.value) return;+ for (const stage of rollout.value.stages) {+ if (stage.environment) {+ policyStore+ .getOrFetchPolicyByParentAndType({+ parentPath: stage.environment,+ policyType: PolicyType.ROLLOUT_POLICY,+ })+ .catch(() => {});+ }}- return "";});+const title = computed(() => issue.value?.title || plan.value?.title || "");providePlanContext({isCreating,@@ -92,20 +97,14 @@ providePlanContext({provideSidebarContext(containerRef);-const { overrideMainContainerClass } = useBodyLayoutContext();--overrideMainContainerClass("py-0! px-0!");+useBodyLayoutContext().overrideMainContainerClass("py-0! px-0!");-const documentTitle = computed(() => {- if (ready.value && rollout.value) {- // Use plan title if available, otherwise rollout name- if (plan.value?.title) {+useTitle(+ computed(() => {+ if (ready.value && plan.value?.title) {return plan.value.title;}- return t("common.rollout");- }- return t("common.loading");-});--useTitle(documentTitle);+ return ready.value ? t("common.rollout") : t("common.loading");+ })+);</script>