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): consolidate Plan Actions with declarative registry pattern (#18639)
boojack36d1d7b9c8c4
diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/ACTIONS.md b/frontend/src/components/Plan/components/HeaderSection/Actions/ACTIONS.mdindex 46e053a7f7..67c5a58a66 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/ACTIONS.md+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/ACTIONS.md@@ -2,18 +2,61 @@This document describes all available actions in the Plan Header section, including visibility rules, permissions, and disabled states.-## Overview+## Architecture++The action system uses a **Registry Pattern** for maintainability and type safety.++### Core Components++```+Actions/+├── registry/ # Action Registry (source of truth)+│ ├── types.ts # ActionContext, ActionDefinition interfaces+│ ├── context.ts # buildActionContext() - context builder+│ ├── useActionRegistry.ts # Main composable+│ ├── actions/+│ │ ├── plan.ts # PLAN_CLOSE, PLAN_REOPEN+│ │ ├── issue.ts # ISSUE_CREATE, ISSUE_REVIEW, ISSUE_STATUS_*+│ │ └── rollout.ts # ROLLOUT_CREATE, ROLLOUT_START, ROLLOUT_CANCEL+│ └── components/+│ ├── ActionButton.vue # Single action button+│ └── ActionDropdown.vue # Secondary actions dropdown+├── unified/ # Legacy components (compatibility layer)+│ ├── UnifiedActionGroup.vue # Button group with dropdown+│ └── IssueReviewButton.vue # Special review popover+└── Actions.vue # Main orchestrator+```++### Key Concepts++**ActionContext**: Single reactive object containing all state needed for action decisions:+- Entities: plan, issue, rollout, project+- Derived flags: isIssueOnly, isExportPlan, isCreator+- Permissions: updatePlan, createIssue, updateIssue, createRollout, runTasks+- Validation: hasEmptySpec, planChecksRunning, planChecksFailed++**ActionDefinition**: Declarative action with pure functions:+```typescript+interface ActionDefinition {+ id: UnifiedActionType;+ label: (ctx: ActionContext) => string;+ buttonType: "primary" | "success" | "default";+ category: "primary" | "secondary";+ priority: number; // Lower = higher priority+ isVisible: (ctx: ActionContext) => boolean;+ isDisabled: (ctx: ActionContext) => boolean;+ disabledReason: (ctx: ActionContext) => string | undefined;+ executeType: ExecuteType;+}+```-Actions are displayed in the Plan Header based on the current state of the plan, issue, and rollout. Actions are divided into:--- **Primary Actions**: Displayed as prominent buttons (usually blue or green)-- **Secondary Actions**: Displayed in the dropdown menu (three-dot menu)+---## Action Types### Plan Actions-#### `ISSUE_CREATE` (Primary)+#### `ISSUE_CREATE` (Primary, Priority: 5)**Label**: "Ready for review"**Description**: Creates an issue from the plan and initiates the approval workflow.@@ -29,85 +72,51 @@ Actions are displayed in the Plan Header based on the current state of the plan,- Plan checks are currently running- Plan checks failed and SQL review is enforced (`project.enforceSqlReview`)-**Disabled Tooltip**:-- "Missing statement"-- "Plan checks are running"-- "Some task checks didn't pass" (when SQL review enforced)-----#### `PLAN_CLOSE` (Secondary)+#### `PLAN_CLOSE` (Secondary, Priority: 100)**Label**: "Close"**Description**: Closes (archives) the plan.**Visibility**:-- Plan has no issue attached (`plan.issue === ""`)-- Plan has no rollout attached (`plan.rollout === ""`)+- Plan has no issue attached+- Plan has no rollout attached- Plan is in ACTIVE state- User is the plan creator OR has `bb.plans.update` permission----#### `PLAN_REOPEN` (Primary)+#### `PLAN_REOPEN` (Primary, Priority: 10)**Label**: "Reopen"**Description**: Reopens a closed (archived) plan.**Visibility**:-- Plan has no issue attached (`plan.issue === ""`)-- Plan has no rollout attached (`plan.rollout === ""`)+- Plan has no issue attached+- Plan has no rollout attached- Plan is in DELETED state- User is the plan creator OR has `bb.plans.update` permission----### Issue Review Actions+### Issue Review Action-#### `ISSUE_REVIEW_APPROVE` (Primary)-**Label**: "Approve"+#### `ISSUE_REVIEW` (Primary, Priority: 30)+**Label**: "Review"-**Description**: Approves the current approval step.+**Description**: Opens the unified review popover for approve/reject/comment.**Visibility**:- Issue exists and is OPEN-- Issue approval status is PENDING or REJECTED (not yet approved)-- User is in the current approval step's candidate list--**Notes**:-- When issue has been rejected, only APPROVE action is shown (no REJECT)-- Approval flow is determined by the approval template roles-------#### `ISSUE_REVIEW_REJECT` (Secondary)-**Label**: "Send back"--**Description**: Rejects the current approval step and sends the issue back.--**Visibility**:-- Issue exists and is OPEN-- Issue approval status is PENDING (not yet approved)-- Issue has NOT been rejected yet-- User is in the current approval step's candidate list-------#### `ISSUE_REVIEW_RE_REQUEST` (Primary)-**Label**: "Re-request review"--**Description**: Re-requests approval after the issue was rejected.--**Visibility**:-- Issue exists and is OPEN-- Issue has been rejected (at least one approver has REJECTED status)-- User is the issue creator+- Issue approval status is not APPROVED or SKIPPED+- User is a candidate for the current approval step (canApprove or canReject)---### Issue Status Actions-#### `ISSUE_STATUS_RESOLVE` (Primary)+#### `ISSUE_STATUS_RESOLVE` (Primary, Priority: 50)**Label**: "Resolve"**Description**: Marks the issue as resolved (DONE).@@ -120,18 +129,19 @@ Actions are displayed in the Plan Header based on the current state of the plan,----#### `ISSUE_STATUS_CLOSE` (Secondary)+#### `ISSUE_STATUS_CLOSE` (Secondary, Priority: 90)**Label**: "Close"**Description**: Closes the issue without resolving it (CANCELED).**Visibility**:- Issue exists and is OPEN+- No rollout exists (can't close after rollout starts)- User has `bb.issues.update` permission----#### `ISSUE_STATUS_REOPEN` (Primary)+#### `ISSUE_STATUS_REOPEN` (Primary, Priority: 20)**Label**: "Reopen"**Description**: Reopens a closed or resolved issue.@@ -144,7 +154,20 @@ Actions are displayed in the Plan Header based on the current state of the plan,### Rollout Actions-#### `ROLLOUT_START` (Primary)+#### `ROLLOUT_CREATE` (Primary, Priority: 55)+**Label**: "Create Rollout"++**Description**: Creates a rollout from the approved issue.++**Visibility**:+- Plan has no rollout attached+- Issue exists+- User has `bb.rollouts.create` permission+- Rollout preconditions met (approval status, plan checks)++---++#### `ROLLOUT_START` (Primary, Priority: 60)**Label**:- "Export" (for export data issues)- "Rollout" (for other issues)@@ -152,35 +175,39 @@ Actions are displayed in the Plan Header based on the current state of the plan,**Description**: Starts or retries tasks in the rollout.**Visibility**:-- Issue exists and is OPEN+- Rollout exists- Issue approval status is APPROVED or SKIPPED-- Rollout has at least one DATABASE_CREATE or DATABASE_EXPORT task-- At least one task is in NOT_STARTED, FAILED, or CANCELED status-- **Permission**:- - For DATABASE_EXPORT issues: User must be the issue creator- - For other issues: User must have `bb.taskRuns.create` permission OR match roles in environment rollout policy--**Notes**:-- For DATABASE_EXPORT issues, only the creator can export data (security restriction)-- For other issues, the two-tier permission check applies:- 1. Users with `bb.taskRuns.create` permission can always rollout- 2. OR users with matching roles in the environment rollout policy can rollout+- Has DATABASE_CREATE or DATABASE_EXPORT tasks+- At least one task is startable (NOT_STARTED, FAILED, or CANCELED)+- **Permission**: User has `bb.taskRuns.create` permission OR is creator (for exports)----#### `ROLLOUT_CANCEL` (Secondary)+#### `ROLLOUT_CANCEL` (Secondary, Priority: 80)**Label**: "Cancel"**Description**: Cancels running or pending tasks.**Visibility**:-- Issue exists and is OPEN+- Rollout exists- Issue approval status is APPROVED or SKIPPED- At least one task is in PENDING or RUNNING status- **Permission**: Same as ROLLOUT_START---+#### `EXPORT_DOWNLOAD` (Primary, Priority: 0)+**Label**: "Download"++**Description**: Downloads completed export archive.++**Visibility**:+- Plan is an export plan+- Export archive is ready+- User is the issue creator++---+## Global Disabled StatesAll actions are disabled when:@@ -191,22 +218,21 @@ All actions are disabled when:## Action Priority Order-When multiple actions are available, they are prioritized as follows:--### Primary Actions (first match wins):-1. `ISSUE_CREATE` - Create issue from plan-2. `PLAN_REOPEN` - Reopen deleted plan-3. `ISSUE_STATUS_REOPEN` - Reopen closed/done issue-4. `ISSUE_REVIEW_APPROVE` - Approve current step-5. `ISSUE_REVIEW_RE_REQUEST` - Re-request review after rejection-6. `ISSUE_STATUS_RESOLVE` - Resolve completed issue-7. `ROLLOUT_START` - Start/retry tasks--### Secondary Actions (all matching actions shown):-1. `ISSUE_REVIEW_REJECT` - Reject current approval step-2. `ROLLOUT_CANCEL` - Cancel running tasks-3. `ISSUE_STATUS_CLOSE` - Close issue-4. `PLAN_CLOSE` - Close plan+Actions are sorted by priority (lower number = higher priority). The first visible primary action is shown as the main button.++| Priority | Action | Category |+|----------|--------|----------|+| 0 | EXPORT_DOWNLOAD | primary |+| 5 | ISSUE_CREATE | primary |+| 10 | PLAN_REOPEN | primary |+| 20 | ISSUE_STATUS_REOPEN | primary |+| 30 | ISSUE_REVIEW | primary |+| 50 | ISSUE_STATUS_RESOLVE | primary |+| 55 | ROLLOUT_CREATE | primary |+| 60 | ROLLOUT_START | primary |+| 80 | ROLLOUT_CANCEL | secondary |+| 90 | ISSUE_STATUS_CLOSE | secondary |+| 100 | PLAN_CLOSE | secondary |---@@ -220,42 +246,57 @@ When multiple actions are available, they are prioritized as follows:- `bb.issues.update`: Close, reopen, or resolve issues### Rollout Permissions-- `bb.taskRuns.create`: Run rollout tasks (for non-export issues)+- `bb.rollouts.create`: Create rollouts+- `bb.taskRuns.create`: Run rollout tasks- **Issue creator**: Run export tasks (for DATABASE_EXPORT issues)-- **Environment rollout policy roles**: Run tasks based on role matching### Approval Permissions- **Approval template roles**: Approve or reject based on current approval step----## Special Cases--### Plan Actions Without Issue/Rollout-Plan actions (PLAN_CLOSE, PLAN_REOPEN, ISSUE_CREATE) are only available when:-- No issue is attached to the plan-- No rollout is attached to the plan--**Rationale**: Once an issue or rollout is created, the plan enters a workflow state where plan-level actions are no longer appropriate. Users should interact with the issue/rollout instead.--### Export Data Issues-- Export button is labeled "Export" instead of "Rollout"-- Only the issue creator can start the export (security restriction)-- Export button shows only when approval is APPROVED or SKIPPED (not during review)--### Environment Rollout Policy-When a user lacks `bb.taskRuns.create` permission, the system checks the environment rollout policy:-1. Gets the database's effective environment-2. Checks if a rollout policy exists for that environment-3. If no policy exists: Allow rollout (no restrictions)-4. If policy exists: Check if user has any of the required roles in the policy--This allows fine-grained control over who can rollout tasks in specific environments.+## Usage++### Using the Action Registry++```typescript+import { useActionRegistry } from "./registry";++const {+ context, // Reactive ActionContext+ primaryAction, // First visible primary action+ secondaryActions, // All visible secondary actions+ isActionDisabled, // Check if action is disabled+ getDisabledReason, // Get disabled tooltip+ executeAction, // Execute action by ID+} = useActionRegistry();+```++### Adding a New Action++1. Define the action in the appropriate file (`registry/actions/*.ts`):+```typescript+export const MY_NEW_ACTION: ActionDefinition = {+ id: "MY_NEW_ACTION",+ label: () => t("my-action.label"),+ buttonType: "primary",+ category: "primary",+ priority: 45,+ isVisible: (ctx) => /* visibility logic */,+ isDisabled: (ctx) => /* disabled logic */,+ disabledReason: (ctx) => /* reason or undefined */,+ executeType: "immediate",+};+```++2. Add to the actions array in the same file+3. Add the type to `registry/types.ts`+4. Handle execution in `Actions.vue` if needed---## Implementation Files-- **Actions.vue**: Main action logic and visibility rules (frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue)-- **UnifiedActionGroup.vue**: Action button rendering (frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue)-- **taskPermissions.ts**: Rollout permission checks (frontend/src/components/Plan/components/RolloutView/taskPermissions.ts)+- **registry/**: Action registry (source of truth)+- **Actions.vue**: Main orchestrator+- **unified/**: Legacy components (compatibility layer)diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vueindex ade85db431..48a72dc152 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/Actions.vue@@ -1,59 +1,40 @@<template><CreateButton v-if="isCreating" />- <template v-else>- <!-- Show CreateIssueButton when ISSUE_CREATE is the primary action -->- <template v-if="showCreateIssueButton">- <div class="flex items-center gap-x-2">- <CreateIssueButton />- <!-- Secondary actions dropdown -->- <UnifiedActionGroup- v-if="secondaryActions.length > 0"- :secondary-actions="secondaryActions"- :disabled="actionsDisabled"- :disabled-tooltip="disabledTooltip"- @perform-action="handlePerformAction"- />- </div>- </template>-- <!-- Show IssueReviewButton when review actions are available -->- <template v-else-if="showReviewButton">- <div class="flex items-center gap-x-2">- <IssueReviewButton- :can-approve="canApprove"- :can-reject="canReject"- :disabled="actionsDisabled"- :disabled-tooltip="disabledTooltip"- />- <!-- Secondary actions dropdown (excluding review actions) -->- <UnifiedActionGroup- v-if="nonReviewSecondaryActions.length > 0"- :secondary-actions="nonReviewSecondaryActions"- :disabled="actionsDisabled"- :disabled-tooltip="disabledTooltip"- @perform-action="handlePerformAction"- />- </div>- </template>-- <!-- Show unified actions for other plan states -->- <template v-else>- <UnifiedActionGroup- :primary-action="primaryAction"- :secondary-actions="secondaryActions"- :disabled="actionsDisabled"- :disabled-tooltip="disabledTooltip"- @perform-action="handlePerformAction"- />- </template>-- <!-- Panels -->- <template v-if="issue">- <IssueStatusActionPanel- :action="pendingStatusAction"- @close="pendingStatusAction = undefined"- />- </template>+ <div v-else class="flex items-center gap-x-2">+ <!-- Rollout ready link for database change issues -->+ <RolloutReadyLink v-if="shouldShowRolloutReadyLink" />++ <!-- Primary action: special components for specific actions -->+ <CreateIssueButton v-if="primaryAction?.id === 'ISSUE_CREATE'" />+ <IssueReviewButton+ v-else-if="primaryAction?.id === 'ISSUE_REVIEW'"+ :can-approve="context.permissions.canApprove"+ :can-reject="context.permissions.canReject"+ :disabled="isActionDisabled(primaryAction)"+ />+ <ExportArchiveDownloadAction+ v-else-if="primaryAction?.id === 'EXPORT_DOWNLOAD'"+ />+ <ActionButton+ v-else-if="primaryAction"+ :action="primaryAction"+ :context="context"+ :disabled="isActionDisabled(primaryAction)"+ :disabled-reason="getDisabledReason(primaryAction)"+ @execute="handlePerformAction"+ />++ <!-- Secondary actions dropdown -->+ <ActionDropdown+ v-if="secondaryActions.length > 0"+ :actions="secondaryActions"+ :context="context"+ :global-disabled="globalDisabled"+ :global-disabled-reason="globalDisabledReason"+ :is-action-disabled="isActionDisabled"+ :get-disabled-reason="getDisabledReason"+ @execute="handlePerformAction"+ /><!-- Rollout Action Panel --><template v-if="rollout && rolloutStage">@@ -71,7 +52,7 @@@confirm="handleRolloutActionConfirm"/></template>- </template>+ </div></template><script setup lang="ts">@@ -80,37 +61,36 @@ import { useDialog } from "naive-ui";import { computed, ref } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";-import { usePlanContext } from "@/components/Plan/logic";+import { usePlanContext, useRolloutReadyLink } from "@/components/Plan/logic";import { useResourcePoller } from "@/components/Plan/logic/poller";-import { useEditorState } from "@/components/Plan/logic/useEditorState";import TaskRolloutActionPanel from "@/components/RolloutV1/components/TaskRolloutActionPanel.vue";-import { rolloutServiceClientConnect } from "@/grpcweb";+import {+ issueServiceClientConnect,+ rolloutServiceClientConnect,+} from "@/grpcweb";import { PROJECT_V1_ROUTE_ROLLOUT_DETAIL } from "@/router/dashboard/projectV1";import { pushNotification, useCurrentProjectV1 } from "@/store";import { usePlanStore } from "@/store/modules/v1/plan";import { State } from "@/types/proto-es/v1/common_pb";+import {+ BatchUpdateIssuesStatusRequestSchema,+ IssueStatus,+} from "@/types/proto-es/v1/issue_service_pb";import {CreateRolloutRequestSchema,Task_Type,} from "@/types/proto-es/v1/rollout_service_pb";-import {- extractProjectResourceName,- extractRolloutUID,- isValidIssueName,- isValidPlanName,-} from "@/utils";+import { extractProjectResourceName, extractRolloutUID } from "@/utils";import { CreateButton, CreateIssueButton } from "./create";-import { IssueStatusActionPanel } from "./panels";-import {- type ActionConfig,- IssueReviewButton,- type IssueStatusAction,- type PlanAction,- type RolloutAction,- type UnifiedAction,- UnifiedActionGroup,- usePlanAction,-} from "./unified";+import { ExportArchiveDownloadAction } from "./export";+import RolloutReadyLink from "./RolloutReadyLink.vue";+import { ActionButton, ActionDropdown, useActionRegistry } from "./registry";+import type {+ IssueStatusAction,+ RolloutAction,+ UnifiedAction,+} from "./registry/types";+import { IssueReviewButton } from "./unified";const { t } = useI18n();const router = useRouter();@@ -119,32 +99,35 @@ const resourcePoller = useResourcePoller();const { project } = useCurrentProjectV1();const { isCreating, plan, issue, rollout, events } = usePlanContext();const planStore = usePlanStore();-const editorState = useEditorState();-const { availableActions, canApprove, canReject } = usePlanAction();const creatingRollout = ref(false);--// Computed property for actions disabled state.-const actionsDisabled = computed(() => {- return editorState.isEditing.value;+const { shouldShow: shouldShowRolloutReadyLink } = useRolloutReadyLink();++// Use the action registry+const {+ context,+ primaryAction,+ secondaryActions,+ isActionDisabled,+ getDisabledReason,+} = useActionRegistry();++// Global disabled state (for dropdown)+const globalDisabled = computed(() => {+ if (!primaryAction.value) return false;+ return isActionDisabled(primaryAction.value);});-// Tooltip message for disabled state.-const disabledTooltip = computed(() => {- if (editorState.isEditing.value) {- return t("plan.editor.save-changes-before-continuing");- }- return "";+const globalDisabledReason = computed(() => {+ if (!primaryAction.value) return undefined;+ return getDisabledReason(primaryAction.value);});// Panel visibility state-const pendingStatusAction = ref<IssueStatusAction | undefined>(undefined);const pendingRolloutAction = ref<RolloutAction | undefined>(undefined);// Get the stage that contains database creation or export tasksconst rolloutStage = computed(() => {if (!rollout.value) return undefined;-- // Find the first stage with database creation or export tasksreturn rollout.value.stages.find((stage) =>stage.tasks.some((task) =>@@ -154,94 +137,12 @@ const rolloutStage = computed(() => {);});-// Issue-only mode: when viewing an issue without a valid plan (legacy issues)-const isIssueOnly = computed(() => {- return (- !isValidPlanName(plan.value.name) && isValidIssueName(issue.value?.name)- );-});--// Check if we should show CreateIssueButton instead of UnifiedActionGroup-const showCreateIssueButton = computed(() => {- // Show CreateIssueButton when ISSUE_CREATE is available and not issue-only- return !isIssueOnly.value && availableActions.value.includes("ISSUE_CREATE");-});--// Show the unified review button when ISSUE_REVIEW is available-const showReviewButton = computed(() => {- return availableActions.value.includes("ISSUE_REVIEW");-});--// Secondary actions excluding review action (for when review button is shown)-const nonReviewSecondaryActions = computed((): ActionConfig[] => {- return secondaryActions.value.filter(- (config) => config.action !== "ISSUE_REVIEW"- );-});--const primaryAction = computed((): ActionConfig | undefined => {- const actions = availableActions.value;-- // PLAN_REOPEN is primary when plan is deleted (skip for issue-only)- if (!isIssueOnly.value && actions.includes("PLAN_REOPEN")) {- return { action: "PLAN_REOPEN" };- }-- // ISSUE_STATUS_REOPEN is primary when issue is closed or done- if (actions.includes("ISSUE_STATUS_REOPEN")) {- return { action: "ISSUE_STATUS_REOPEN" };- }-- // ISSUE_REVIEW is handled by IssueReviewButton, not UnifiedActionGroup- // So we skip it here and let showReviewButton handle it-- // ISSUE_STATUS_RESOLVE is primary when issue can be resolved- if (actions.includes("ISSUE_STATUS_RESOLVE")) {- return { action: "ISSUE_STATUS_RESOLVE" };- }-- // ROLLOUT_CREATE is primary when issue exists but rollout doesn't- if (actions.includes("ROLLOUT_CREATE")) {- return { action: "ROLLOUT_CREATE" };- }-- // Rollout actions as primary actions (high priority for force rollout scenarios)- if (actions.includes("ROLLOUT_START")) {- return { action: "ROLLOUT_START" };- }-- return undefined;-});--const secondaryActions = computed((): ActionConfig[] => {- const actions = availableActions.value;- const secondary: ActionConfig[] = [];-- // ISSUE_REVIEW is handled by IssueReviewButton, not in secondary actions- if (actions.includes("ROLLOUT_CREATE")) {- secondary.push({ action: "ROLLOUT_CREATE" });- }- if (actions.includes("ROLLOUT_CANCEL")) {- secondary.push({ action: "ROLLOUT_CANCEL" });- }- if (actions.includes("ISSUE_STATUS_CLOSE")) {- secondary.push({ action: "ISSUE_STATUS_CLOSE" });- }- // Skip PLAN_CLOSE for issue-only cases- if (!isIssueOnly.value && actions.includes("PLAN_CLOSE")) {- secondary.push({ action: "PLAN_CLOSE" });- }-- return secondary;-});-const handlePerformAction = async (action: UnifiedAction) => {switch (action) {- // ISSUE_REVIEW is handled directly by IssueReviewButtoncase "ISSUE_STATUS_CLOSE":case "ISSUE_STATUS_REOPEN":case "ISSUE_STATUS_RESOLVE":- pendingStatusAction.value = action as IssueStatusAction;+ await handleIssueStatusChange(action as IssueStatusAction);break;case "PLAN_CLOSE":await handlePlanStateChange("PLAN_CLOSE");@@ -259,7 +160,56 @@ const handlePerformAction = async (action: UnifiedAction) => {}};-const handlePlanStateChange = async (action: PlanAction) => {+const handleIssueStatusChange = async (action: IssueStatusAction) => {+ const issueValue = issue?.value;+ if (!issueValue) return;++ const actionConfig = {+ ISSUE_STATUS_CLOSE: {+ title: t("common.close"),+ content: t("issue.status-transition.modal.close"),+ status: IssueStatus.CANCELED,+ },+ ISSUE_STATUS_REOPEN: {+ title: t("common.reopen"),+ content: t("issue.status-transition.modal.reopen"),+ status: IssueStatus.OPEN,+ },+ ISSUE_STATUS_RESOLVE: {+ title: t("issue.batch-transition.resolve"),+ content: t("issue.status-transition.modal.resolve"),+ status: IssueStatus.DONE,+ },+ }[action];++ const d = dialog.warning({+ title: actionConfig.title,+ content: actionConfig.content,+ positiveText: actionConfig.title,+ negativeText: t("common.cancel"),+ onPositiveClick: async () => {+ d.loading = true;+ try {+ const request = create(BatchUpdateIssuesStatusRequestSchema, {+ parent: project.value.name,+ issues: [issueValue.name],+ status: actionConfig.status,+ });+ await issueServiceClientConnect.batchUpdateIssuesStatus(request);+ events.emit("perform-issue-status-action", { action });+ } catch (error) {+ pushNotification({+ module: "bytebase",+ style: "CRITICAL",+ title: t("common.failed"),+ description: String(error),+ });+ }+ },+ });+};++const handlePlanStateChange = async (action: "PLAN_CLOSE" | "PLAN_REOPEN") => {if (!plan?.value) return;const isClosing = action === "PLAN_CLOSE";@@ -280,7 +230,6 @@ const handlePlanStateChange = async (action: PlanAction) => {await planStore.updatePlan({ ...plan.value, state: newState }, ["state",]);- // The plan context should automatically refresh and redirect or update the UI.await resourcePoller.refreshResources();} catch (error) {pushNotification({@@ -314,7 +263,6 @@ const handleCreateRollout = async () => {title: t("common.created"),});- // Redirect to rollout pagerouter.push({name: PROJECT_V1_ROUTE_ROLLOUT_DETAIL,params: {@@ -335,8 +283,6 @@ const handleCreateRollout = async () => {};const handleRolloutActionConfirm = () => {- // The TaskRolloutActionPanel handles the actual execution- // We just need to emit status change to refresh the UIevents.emit("status-changed", { eager: true });pendingRolloutAction.value = undefined;};diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/panels/IssueStatusActionPanel.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/panels/IssueStatusActionPanel.vuedeleted file mode 100644index 421cbcbc7d..0000000000--- a/frontend/src/components/Plan/components/HeaderSection/Actions/panels/IssueStatusActionPanel.vue+++ /dev/null@@ -1,148 +0,0 @@-<template>- <CommonDrawer- :show="action !== undefined"- :title="title"- :loading="state.loading"- @show="resetState"- @close="$emit('close')"- >- <template #default>- <div v-if="action" class="flex flex-col gap-y-4 px-1">- <div class="flex flex-col gap-y-1">- <div class="font-medium text-control">- {{ $t("common.issue") }}- </div>- <div class="textinfolabel">- {{ issue.title }}- </div>- </div>-- <div class="flex flex-col gap-y-1">- <p class="font-medium text-control">- {{ $t("common.comment") }}- </p>- <NInput- v-model:value="comment"- type="textarea"- :placeholder="$t('issue.leave-a-comment')"- :autosize="{- minRows: 3,- maxRows: 10,- }"- />- </div>- </div>- </template>- <template #footer>- <div- v-if="action"- class="w-full flex flex-row justify-between items-center gap-2"- >- <div></div>- <div class="flex justify-end gap-x-2">- <NButton quaternary @click="$emit('close')">- {{ $t("common.close") }}- </NButton>-- <NButton type="primary" @click="handleConfirm">- {{ $t("common.confirm") }}- </NButton>- </div>- </div>- </template>- </CommonDrawer>-</template>--<script setup lang="ts">-import { create } from "@bufbuild/protobuf";-import { NButton, NInput } from "naive-ui";-import { computed, reactive, ref } from "vue";-import { useI18n } from "vue-i18n";-import CommonDrawer from "@/components/IssueV1/components/Panel/CommonDrawer.vue";-import { usePlanContextWithIssue } from "@/components/Plan/logic";-import { issueServiceClientConnect } from "@/grpcweb";-import { useCurrentProjectV1 } from "@/store";-import {- BatchUpdateIssuesStatusRequestSchema,- IssueStatus,- IssueStatus as NewIssueStatus,-} from "@/types/proto-es/v1/issue_service_pb";-import type { IssueStatusAction } from "../unified";--type LocalState = {- loading: boolean;-};--const props = defineProps<{- action?: IssueStatusAction;-}>();-const emit = defineEmits<{- (event: "close"): void;-}>();--const { t } = useI18n();-const state = reactive<LocalState>({- loading: false,-});-const { project } = useCurrentProjectV1();-const { issue, events } = usePlanContextWithIssue();-const comment = ref("");--const title = computed(() => {- switch (props.action) {- case "ISSUE_STATUS_CLOSE":- return t("issue.batch-transition.close");- case "ISSUE_STATUS_REOPEN":- return t("issue.batch-transition.reopen");- case "ISSUE_STATUS_RESOLVE":- return t("issue.batch-transition.resolve");- }- return "";-});--const handleConfirm = async () => {- const { action } = props;- if (!action) return;- state.loading = true;- try {- let issueStatus: IssueStatus;- switch (action) {- case "ISSUE_STATUS_CLOSE":- issueStatus = IssueStatus.CANCELED;- break;- case "ISSUE_STATUS_REOPEN":- issueStatus = IssueStatus.OPEN;- break;- case "ISSUE_STATUS_RESOLVE":- issueStatus = IssueStatus.DONE;- break;- default:- throw new Error(`Unsupported action: ${action}`);- }- // Convert old enum to new enum (values match)- const newStatus =- issueStatus === IssueStatus.OPEN- ? NewIssueStatus.OPEN- : issueStatus === IssueStatus.DONE- ? NewIssueStatus.DONE- : NewIssueStatus.CANCELED;-- const request = create(BatchUpdateIssuesStatusRequestSchema, {- parent: project.value.name,- issues: [issue.value.name],- status: newStatus,- reason: comment.value ?? "",- });- await issueServiceClientConnect.batchUpdateIssuesStatus(request);- // Emit event to trigger polling- events.emit("perform-issue-status-action", { action });- } finally {- state.loading = false;- emit("close");- }-};--const resetState = () => {- comment.value = "";-};-</script>diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/panels/index.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/panels/index.tsdeleted file mode 100644index 4faff460a0..0000000000--- a/frontend/src/components/Plan/components/HeaderSection/Actions/panels/index.ts+++ /dev/null@@ -1 +0,0 @@-export { default as IssueStatusActionPanel } from "./IssueStatusActionPanel.vue";diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/index.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/index.tsnew file mode 100644index 0000000000..a210f4e8ca--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/index.ts@@ -0,0 +1,16 @@+import type { ActionDefinition } from "../types";+import { issueActions } from "./issue";+import { planActions } from "./plan";+import { rolloutActions } from "./rollout";++// All actions in priority order for filtering+export const allActions: ActionDefinition[] = [+ ...planActions,+ ...issueActions,+ ...rolloutActions,+].sort((a, b) => a.priority - b.priority);++// Re-export individual actions for testing+export * from "./plan";+export * from "./issue";+export * from "./rollout";diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/issue.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/issue.tsnew file mode 100644index 0000000000..9a8afab8f5--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/issue.ts@@ -0,0 +1,130 @@+import { t } from "@/plugins/i18n";+import { State } from "@/types/proto-es/v1/common_pb";+import {+ Issue_ApprovalStatus,+ IssueStatus,+} from "@/types/proto-es/v1/issue_service_pb";+import type { ActionDefinition } from "../types";++export const ISSUE_CREATE: ActionDefinition = {+ id: "ISSUE_CREATE",+ label: () => t("plan.ready-for-review"),+ buttonType: "primary",+ category: "primary",+ priority: 5,++ isVisible: (ctx) =>+ !ctx.isIssueOnly &&+ ctx.plan.issue === "" &&+ !ctx.plan.hasRollout &&+ ctx.planState === State.ACTIVE &&+ ctx.permissions.createIssue,++ isDisabled: (ctx) =>+ ctx.validation.hasEmptySpec ||+ ctx.validation.planChecksRunning ||+ (ctx.validation.planChecksFailed && ctx.project.enforceSqlReview),++ disabledReason: (ctx) => {+ if (ctx.validation.hasEmptySpec) {+ return t("plan.navigator.statement-empty");+ }+ if (ctx.validation.planChecksRunning) {+ return t(+ "custom-approval.issue-review.disallow-approve-reason.some-task-checks-are-still-running"+ );+ }+ if (ctx.validation.planChecksFailed && ctx.project.enforceSqlReview) {+ return t(+ "custom-approval.issue-review.disallow-approve-reason.some-task-checks-didnt-pass"+ );+ }+ return undefined;+ },++ executeType: "popover:labels",+};++export const ISSUE_REVIEW: ActionDefinition = {+ id: "ISSUE_REVIEW",+ label: () => t("issue.review.self"),+ buttonType: "primary",+ category: "primary",+ priority: 30,++ isVisible: (ctx) =>+ ctx.issueStatus === IssueStatus.OPEN &&+ ctx.approvalStatus !== Issue_ApprovalStatus.APPROVED &&+ ctx.approvalStatus !== Issue_ApprovalStatus.SKIPPED &&+ ctx.permissions.isApprovalCandidate,++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "popover:review",+};++export const ISSUE_STATUS_RESOLVE: ActionDefinition = {+ id: "ISSUE_STATUS_RESOLVE",+ label: () => t("issue.batch-transition.resolve"),+ buttonType: "success",+ category: "primary",+ priority: 50,++ isVisible: (ctx) =>+ ctx.issueStatus === IssueStatus.OPEN &&+ (ctx.approvalStatus === Issue_ApprovalStatus.APPROVED ||+ ctx.approvalStatus === Issue_ApprovalStatus.SKIPPED) &&+ ctx.allTasksFinished &&+ ctx.plan.hasRollout &&+ ctx.permissions.updateIssue,++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "panel:issue-status",+};++export const ISSUE_STATUS_CLOSE: ActionDefinition = {+ id: "ISSUE_STATUS_CLOSE",+ label: () => t("issue.batch-transition.close"),+ buttonType: "default",+ category: "secondary",+ priority: 90,++ isVisible: (ctx) =>+ ctx.issueStatus === IssueStatus.OPEN &&+ !ctx.plan.hasRollout &&+ ctx.permissions.updateIssue,++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "panel:issue-status",+};++export const ISSUE_STATUS_REOPEN: ActionDefinition = {+ id: "ISSUE_STATUS_REOPEN",+ label: () => t("issue.batch-transition.reopen"),+ buttonType: "default",+ category: "primary",+ priority: 20,++ isVisible: (ctx) =>+ (ctx.issueStatus === IssueStatus.CANCELED ||+ ctx.issueStatus === IssueStatus.DONE) &&+ ctx.permissions.updateIssue,++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "panel:issue-status",+};++export const issueActions: ActionDefinition[] = [+ ISSUE_CREATE,+ ISSUE_REVIEW,+ ISSUE_STATUS_RESOLVE,+ ISSUE_STATUS_CLOSE,+ ISSUE_STATUS_REOPEN,+];diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/plan.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/plan.tsnew file mode 100644index 0000000000..58786d9353--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/plan.ts@@ -0,0 +1,49 @@+import { t } from "@/plugins/i18n";+import { State } from "@/types/proto-es/v1/common_pb";+import type { ActionDefinition } from "../types";++export const PLAN_CLOSE: ActionDefinition = {+ id: "PLAN_CLOSE",+ label: () => t("common.close"),+ buttonType: "default",+ category: "secondary",+ priority: 100,++ isVisible: (ctx) =>+ !ctx.isIssueOnly &&+ ctx.plan.issue === "" &&+ !ctx.plan.hasRollout &&+ ctx.planState === State.ACTIVE &&+ ctx.permissions.updatePlan,++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "confirm-dialog",+ confirmTitle: () => t("common.close"),+ confirmContent: () => t("plan.state.close-confirm"),+};++export const PLAN_REOPEN: ActionDefinition = {+ id: "PLAN_REOPEN",+ label: () => t("common.reopen"),+ buttonType: "default",+ category: "primary",+ priority: 10,++ isVisible: (ctx) =>+ !ctx.isIssueOnly &&+ ctx.plan.issue === "" &&+ !ctx.plan.hasRollout &&+ ctx.planState === State.DELETED &&+ ctx.permissions.updatePlan,++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "confirm-dialog",+ confirmTitle: () => t("common.reopen"),+ confirmContent: () => t("plan.state.reopen-confirm"),+};++export const planActions: ActionDefinition[] = [PLAN_CLOSE, PLAN_REOPEN];diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/rollout.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/rollout.tsnew file mode 100644index 0000000000..4dc63d7ca3--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/actions/rollout.ts@@ -0,0 +1,99 @@+import { t } from "@/plugins/i18n";+import { Issue_ApprovalStatus } from "@/types/proto-es/v1/issue_service_pb";+import type { ActionDefinition } from "../types";++export const ROLLOUT_CREATE: ActionDefinition = {+ id: "ROLLOUT_CREATE",+ label: () => t("issue.create-rollout"),+ buttonType: "default",+ category: "primary",+ priority: 55,++ isVisible: (ctx) =>+ !ctx.isIssueOnly &&+ !ctx.plan.hasRollout &&+ ctx.issue !== undefined &&+ ctx.permissions.createRollout &&+ ctx.rolloutPreconditionsMet,++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "immediate",+};++export const ROLLOUT_START: ActionDefinition = {+ id: "ROLLOUT_START",+ label: (ctx) => (ctx.isExportPlan ? t("common.export") : t("common.rollout")),+ buttonType: "primary",+ category: "primary",+ priority: 60,++ isVisible: (ctx) => {+ if (!ctx.rollout) return false;+ if (+ ctx.approvalStatus !== Issue_ApprovalStatus.APPROVED &&+ ctx.approvalStatus !== Issue_ApprovalStatus.SKIPPED+ ) {+ return false;+ }+ if (!ctx.hasDatabaseCreateOrExportTasks) return false;+ if (!ctx.hasStartableTasks) return false;++ return ctx.permissions.runTasks;+ },++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "panel:rollout",+};++export const ROLLOUT_CANCEL: ActionDefinition = {+ id: "ROLLOUT_CANCEL",+ label: () => t("common.cancel"),+ buttonType: "default",+ category: "secondary",+ priority: 80,++ isVisible: (ctx) => {+ if (!ctx.rollout) return false;+ if (+ ctx.approvalStatus !== Issue_ApprovalStatus.APPROVED &&+ ctx.approvalStatus !== Issue_ApprovalStatus.SKIPPED+ ) {+ return false;+ }+ if (!ctx.hasRunningTasks) return false;++ return ctx.permissions.runTasks;+ },++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "panel:rollout",+};++export const EXPORT_DOWNLOAD: ActionDefinition = {+ id: "EXPORT_DOWNLOAD",+ label: () => t("common.download"),+ buttonType: "primary",+ category: "primary",+ priority: 0,++ isVisible: (ctx) =>+ ctx.isExportPlan && ctx.exportArchiveReady && ctx.isCreator,++ isDisabled: () => false,+ disabledReason: () => undefined,++ executeType: "immediate",+};++export const rolloutActions: ActionDefinition[] = [+ ROLLOUT_CREATE,+ ROLLOUT_START,+ ROLLOUT_CANCEL,+ EXPORT_DOWNLOAD,+];diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/ActionButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/ActionButton.vuenew file mode 100644index 0000000000..9b4981bf26--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/ActionButton.vue@@ -0,0 +1,34 @@+<template>+ <NTooltip :disabled="!disabledReason" placement="top">+ <template #trigger>+ <NButton+ :type="action.buttonType"+ :disabled="disabled"+ size="medium"+ tag="div"+ @click="$emit('execute', action.id)"+ >+ {{ action.label(context) }}+ </NButton>+ </template>+ <template #default>+ {{ disabledReason }}+ </template>+ </NTooltip>+</template>++<script setup lang="ts">+import { NButton, NTooltip } from "naive-ui";+import type { ActionContext, ActionDefinition, UnifiedAction } from "../types";++defineProps<{+ action: ActionDefinition;+ context: ActionContext;+ disabled?: boolean;+ disabledReason?: string;+}>();++defineEmits<{+ (e: "execute", id: UnifiedAction): void;+}>();+</script>diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/ActionDropdown.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/ActionDropdown.vuenew file mode 100644index 0000000000..5cd3326444--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/ActionDropdown.vue@@ -0,0 +1,59 @@+<template>+ <NDropdown+ trigger="click"+ placement="bottom-end"+ :options="dropdownOptions"+ :disabled="globalDisabled"+ @select="handleSelect"+ >+ <NButton+ class="px-1!"+ quaternary+ size="medium"+ :disabled="globalDisabled"+ :title="globalDisabled ? globalDisabledReason : undefined"+ >+ <EllipsisVerticalIcon class="w-4 h-4" />+ </NButton>+ </NDropdown>+</template>++<script setup lang="ts">+import { EllipsisVerticalIcon } from "lucide-vue-next";+import { type DropdownOption, NButton, NDropdown } from "naive-ui";+import { computed } from "vue";+import type { ActionContext, ActionDefinition, UnifiedAction } from "../types";++const props = defineProps<{+ actions: ActionDefinition[];+ context: ActionContext;+ globalDisabled?: boolean;+ globalDisabledReason?: string;+ isActionDisabled: (action: ActionDefinition) => boolean;+ getDisabledReason: (action: ActionDefinition) => string | undefined;+}>();++const emit = defineEmits<{+ (e: "execute", id: UnifiedAction): void;+}>();++const dropdownOptions = computed((): DropdownOption[] => {+ return props.actions.map((action) => {+ const disabled = props.isActionDisabled(action);+ const reason = disabled ? props.getDisabledReason(action) : undefined;+ return {+ key: action.id,+ label: action.label(props.context),+ disabled,+ props: reason ? { title: reason } : undefined,+ };+ });+});++const handleSelect = (key: string) => {+ const action = props.actions.find((a) => a.id === key);+ if (action && !props.isActionDisabled(action)) {+ emit("execute", action.id);+ }+};+</script>diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/index.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/index.tsnew file mode 100644index 0000000000..3a7557551d--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/components/index.ts@@ -0,0 +1,2 @@+export { default as ActionButton } from "./ActionButton.vue";+export { default as ActionDropdown } from "./ActionDropdown.vue";diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/context.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/context.tsnew file mode 100644index 0000000000..c6661c2ebc--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/context.ts@@ -0,0 +1,254 @@+import { first, orderBy } from "lodash-es";+import { candidatesOfApprovalStepV1, extractUserId } from "@/store";+import type { Issue } from "@/types/proto-es/v1/issue_service_pb";+import {+ Issue_ApprovalStatus,+ Issue_Approver_Status,+ Issue_Type,+ IssueStatus,+} from "@/types/proto-es/v1/issue_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 { Rollout, TaskRun } from "@/types/proto-es/v1/rollout_service_pb";+import {+ Task_Status,+ Task_Type,+ TaskRun_ExportArchiveStatus,+ TaskRun_Status,+} from "@/types/proto-es/v1/rollout_service_pb";+import { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";+import type { User } from "@/types/proto-es/v1/user_service_pb";+import {+ extractTaskRunUID,+ extractTaskUID,+ hasProjectPermissionV2,+ isUserIncludedInList,+ isValidIssueName,+ isValidPlanName,+} from "@/utils";+import type {+ ActionContext,+ ActionPermissions,+ ActionValidation,+} from "./types";++export interface ContextBuilderInput {+ plan: Plan;+ issue: Issue | undefined;+ rollout: Rollout | undefined;+ project: Project;+ currentUser: User;+ taskRuns: TaskRun[];+ isCreating: boolean;+ planCheckStatus: Advice_Level;+ hasRunningPlanChecks: boolean;+ isSpecEmpty: (spec: Plan["specs"][0]) => boolean;+}++function computeIsApprovalCandidate(+ issue: Issue | undefined,+ currentUser: User+): boolean {+ if (!issue) return false;++ const issueApproved =+ issue.approvalStatus === Issue_ApprovalStatus.APPROVED ||+ issue.approvalStatus === Issue_ApprovalStatus.SKIPPED;+ if (issueApproved) return false;++ const { approvers, approvalTemplate } = issue;+ const hasRejection = approvers.some(+ (app: Issue["approvers"][0]) =>+ app.status === Issue_Approver_Status.REJECTED+ );++ // Cannot approve or reject if already rejected+ if (hasRejection) return false;++ const roles = approvalTemplate?.flow?.roles ?? [];+ if (roles.length === 0) return false;++ const rejectedIndex = approvers.findIndex(+ (ap: Issue["approvers"][0]) => ap.status === Issue_Approver_Status.REJECTED+ );+ const currentRoleIndex =+ rejectedIndex >= 0 ? rejectedIndex : approvers.length;+ const currentRole = roles[currentRoleIndex];+ if (!currentRole) return false;++ const candidates = candidatesOfApprovalStepV1(issue, currentRole);+ return isUserIncludedInList(currentUser.email, candidates);+}++function computeExportArchiveReady(+ rollout: Rollout | undefined,+ taskRuns: TaskRun[],+ issue: Issue | undefined,+ currentUserEmail: string+): boolean {+ if (!issue) return false;+ if (![IssueStatus.OPEN, IssueStatus.DONE].includes(issue.status))+ return false;+ if (currentUserEmail !== extractUserId(issue.creator)) return false;++ const exportTasks =+ rollout?.stages+ .flatMap((stage) => stage.tasks)+ .filter((task) => task.type === Task_Type.DATABASE_EXPORT) || [];++ if (exportTasks.length === 0) return false;++ if (+ !exportTasks.every((task) =>+ [Task_Status.DONE, Task_Status.SKIPPED].includes(task.status)+ )+ ) {+ return false;+ }++ const exportTaskRuns = exportTasks+ .map((task) => {+ const taskRunsForTask = taskRuns.filter(+ (taskRun) => extractTaskUID(taskRun.name) === extractTaskUID(task.name)+ );+ return first(+ orderBy(+ taskRunsForTask,+ (taskRun) => Number(extractTaskRunUID(taskRun.name)),+ "desc"+ )+ );+ })+ .filter(Boolean) as TaskRun[];++ if (+ exportTaskRuns.length === 0 ||+ exportTaskRuns.some(+ (taskRun) =>+ taskRun.status !== TaskRun_Status.DONE ||+ taskRun.exportArchiveStatus ===+ TaskRun_ExportArchiveStatus.EXPORT_ARCHIVE_STATUS_UNSPECIFIED+ )+ ) {+ return false;+ }++ return true;+}++export function buildActionContext(input: ContextBuilderInput): ActionContext {+ const {+ plan,+ issue,+ rollout,+ project,+ currentUser,+ taskRuns,+ isCreating,+ planCheckStatus,+ hasRunningPlanChecks,+ isSpecEmpty,+ } = input;++ const currentUserEmail = currentUser.email;+ const isIssueOnly =+ !isValidPlanName(plan.name) && !!isValidIssueName(issue?.name);+ const isExportPlan = plan.specs.some(+ (spec) => spec.config?.case === "exportDataConfig"+ );+ const isCreator =+ currentUserEmail === extractUserId(plan.creator || "") ||+ (issue ? currentUserEmail === extractUserId(issue.creator) : false);++ // Compute permissions+ const isApprovalCandidate = computeIsApprovalCandidate(issue, currentUser);+ const permissions: ActionPermissions = {+ updatePlan:+ currentUserEmail === extractUserId(plan.creator || "") ||+ hasProjectPermissionV2(project, "bb.plans.update"),+ createIssue: hasProjectPermissionV2(project, "bb.issues.create"),+ updateIssue: hasProjectPermissionV2(project, "bb.issues.update"),+ createRollout: hasProjectPermissionV2(project, "bb.rollouts.create"),+ runTasks:+ issue?.type === Issue_Type.DATABASE_EXPORT+ ? currentUserEmail === extractUserId(issue.creator)+ : hasProjectPermissionV2(project, "bb.taskRuns.create"),+ isApprovalCandidate,+ canApprove: isApprovalCandidate,+ canReject: isApprovalCandidate,+ };++ // Compute validation state+ const validation: ActionValidation = {+ hasEmptySpec: plan.specs.some((spec) => isSpecEmpty(spec)),+ planChecksRunning: hasRunningPlanChecks,+ planChecksFailed: planCheckStatus === Advice_Level.ERROR,+ };++ // Compute task-related flags+ const allTasks = rollout?.stages.flatMap((stage) => stage.tasks) || [];++ const allTasksFinished = allTasks.every((task) =>+ [Task_Status.DONE, Task_Status.SKIPPED].includes(task.status)+ );++ const hasDatabaseCreateOrExportTasks = allTasks.some(+ (task) =>+ task.type === Task_Type.DATABASE_CREATE ||+ task.type === Task_Type.DATABASE_EXPORT+ );++ const hasStartableTasks = allTasks.some((task) =>+ [+ Task_Status.NOT_STARTED,+ Task_Status.FAILED,+ Task_Status.CANCELED,+ ].includes(task.status)+ );++ const hasRunningTasks = allTasks.some((task) =>+ [Task_Status.PENDING, Task_Status.RUNNING].includes(task.status)+ );++ // Compute rollout preconditions+ const issueApproved =+ issue?.approvalStatus === Issue_ApprovalStatus.APPROVED ||+ issue?.approvalStatus === Issue_ApprovalStatus.SKIPPED;++ const { requireIssueApproval, requirePlanCheckNoError } = project;+ const issueReady = !requireIssueApproval || issueApproved;+ const planCheckReady =+ !requirePlanCheckNoError ||+ (!hasRunningPlanChecks && planCheckStatus !== Advice_Level.ERROR);+ const rolloutPreconditionsMet = issueReady && planCheckReady;++ return {+ plan,+ issue,+ rollout,+ project,++ planState: plan.state,+ issueStatus: issue?.status,+ approvalStatus: issue?.approvalStatus,++ isCreating,+ isIssueOnly,+ isExportPlan,+ isCreator,+ exportArchiveReady: computeExportArchiveReady(+ rollout,+ taskRuns,+ issue,+ currentUserEmail+ ),+ allTasksFinished,+ hasDatabaseCreateOrExportTasks,+ hasStartableTasks,+ hasRunningTasks,+ rolloutPreconditionsMet,++ permissions,+ validation,+ };+}diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/index.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/index.tsnew file mode 100644index 0000000000..e9aedc690e--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/index.ts@@ -0,0 +1,39 @@+export * from "./types";+export * from "./context";+export * from "./useActionRegistry";+export * from "./actions";+export { ActionButton, ActionDropdown } from "./components";++// Standalone helper to get action label without full registry+import { t } from "@/plugins/i18n";+import type { UnifiedAction } from "./types";++export function getActionLabel(+ actionId: UnifiedAction,+ isExportPlan = false+): string {+ switch (actionId) {+ case "ISSUE_REVIEW":+ return t("issue.review.self");+ case "ISSUE_STATUS_CLOSE":+ return t("issue.batch-transition.close");+ case "ISSUE_STATUS_REOPEN":+ return t("issue.batch-transition.reopen");+ case "ISSUE_STATUS_RESOLVE":+ return t("issue.batch-transition.resolve");+ case "ISSUE_CREATE":+ return t("plan.ready-for-review");+ case "PLAN_CLOSE":+ return t("common.close");+ case "PLAN_REOPEN":+ return t("common.reopen");+ case "ROLLOUT_CREATE":+ return t("issue.create-rollout");+ case "ROLLOUT_START":+ return isExportPlan ? t("common.export") : t("common.rollout");+ case "ROLLOUT_CANCEL":+ return t("common.cancel");+ case "EXPORT_DOWNLOAD":+ return t("common.download");+ }+}diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/types.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/types.tsnew file mode 100644index 0000000000..6c9c4f73a6--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/types.ts@@ -0,0 +1,101 @@+import type { ComputedRef } from "vue";+import type { State } from "@/types/proto-es/v1/common_pb";+import type {+ Issue,+ Issue_ApprovalStatus,+ IssueStatus,+} from "@/types/proto-es/v1/issue_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 { Rollout } from "@/types/proto-es/v1/rollout_service_pb";+import type { UnifiedAction } from "../unified/types";++// Re-export action types from unified+export type {+ ExportAction,+ IssueAction,+ IssueReviewAction,+ IssueStatusAction,+ PlanAction,+ RolloutAction,+ UnifiedAction,+} from "../unified/types";++export type ExecuteType =+ | "immediate"+ | "confirm-dialog"+ | "popover:labels"+ | "popover:review"+ | "panel:issue-status"+ | "panel:rollout";++export interface ActionPermissions {+ updatePlan: boolean;+ createIssue: boolean;+ updateIssue: boolean;+ createRollout: boolean;+ runTasks: boolean;+ isApprovalCandidate: boolean;+ canApprove: boolean;+ canReject: boolean;+}++export interface ActionValidation {+ hasEmptySpec: boolean;+ planChecksRunning: boolean;+ planChecksFailed: boolean;+}++export interface ActionContext {+ // Entities+ plan: Plan;+ issue: Issue | undefined;+ rollout: Rollout | undefined;+ project: Project;++ // Proto enums directly+ planState: State;+ issueStatus: IssueStatus | undefined;+ approvalStatus: Issue_ApprovalStatus | undefined;++ // Derived flags+ isCreating: boolean;+ isIssueOnly: boolean;+ isExportPlan: boolean;+ isCreator: boolean;+ exportArchiveReady: boolean;+ allTasksFinished: boolean;+ hasDatabaseCreateOrExportTasks: boolean;+ hasStartableTasks: boolean;+ hasRunningTasks: boolean;+ rolloutPreconditionsMet: boolean;++ // Grouped+ permissions: ActionPermissions;+ validation: ActionValidation;+}++export interface ActionDefinition {+ id: UnifiedAction;+ label: (ctx: ActionContext) => string;+ buttonType: "primary" | "success" | "default";+ category: "primary" | "secondary";+ priority: number;++ isVisible: (ctx: ActionContext) => boolean;+ isDisabled: (ctx: ActionContext) => boolean;+ disabledReason: (ctx: ActionContext) => string | undefined;++ executeType: ExecuteType;+ execute?: (ctx: ActionContext) => Promise<void>;+ confirmTitle?: (ctx: ActionContext) => string;+ confirmContent?: (ctx: ActionContext) => string;+}++export interface ActionRegistryReturn {+ context: ComputedRef<ActionContext>;+ primaryAction: ComputedRef<ActionDefinition | undefined>;+ secondaryActions: ComputedRef<ActionDefinition[]>;+ isActionDisabled: (action: ActionDefinition) => boolean;+ getDisabledReason: (action: ActionDefinition) => string | undefined;+}diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/registry/useActionRegistry.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/useActionRegistry.tsnew file mode 100644index 0000000000..4489fd5c55--- /dev/null+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/registry/useActionRegistry.ts@@ -0,0 +1,82 @@+import { computed } from "vue";+import { useSpecsValidation } from "@/components/Plan/components/common";+import { usePlanContext } from "@/components/Plan/logic";+import { useEditorState } from "@/components/Plan/logic/useEditorState";+import { usePlanCheckStatus } from "@/components/Plan/logic/usePlanCheckStatus";+import { t } from "@/plugins/i18n";+import { useCurrentProjectV1, useCurrentUserV1 } from "@/store";+import { allActions } from "./actions";+import { buildActionContext } from "./context";+import type { ActionDefinition, ActionRegistryReturn } from "./types";++export function useActionRegistry(): ActionRegistryReturn {+ const currentUser = useCurrentUserV1();+ const { project } = useCurrentProjectV1();+ const { isCreating, plan, issue, rollout, taskRuns } = usePlanContext();+ const editorState = useEditorState();+ const { isSpecEmpty } = useSpecsValidation(computed(() => plan.value.specs));+ const {+ getOverallStatus: planCheckStatus,+ hasRunning: hasRunningPlanChecks,+ } = usePlanCheckStatus(plan);++ // Build context reactively+ const context = computed(() =>+ buildActionContext({+ plan: plan.value,+ issue: issue.value,+ rollout: rollout.value,+ project: project.value,+ currentUser: currentUser.value,+ taskRuns: taskRuns.value,+ isCreating: isCreating.value,+ planCheckStatus: planCheckStatus.value,+ hasRunningPlanChecks: hasRunningPlanChecks.value,+ isSpecEmpty,+ })+ );++ // Global disabled state (editor is editing)+ const globalDisabled = computed(() => editorState.isEditing.value);+ const globalDisabledReason = computed(() =>+ globalDisabled.value+ ? t("plan.editor.save-changes-before-continuing")+ : undefined+ );++ // Filter visible actions (no actions during plan creation)+ const visibleActions = computed(() => {+ if (isCreating.value) return [];+ return allActions.filter((action) => action.isVisible(context.value));+ });++ // Primary action (first visible by priority, category=primary)+ const primaryAction = computed(() =>+ visibleActions.value.find((a) => a.category === "primary")+ );++ // Secondary actions: all secondary-category actions + remaining primary actions (excluding the chosen primary)+ const secondaryActions = computed(() =>+ visibleActions.value.filter(+ (a) =>+ a.category === "secondary" ||+ (a.category === "primary" && a.id !== primaryAction.value?.id)+ )+ );++ // Check if action is disabled (global or action-specific)+ const isActionDisabled = (action: ActionDefinition) =>+ globalDisabled.value || action.isDisabled(context.value);++ // Get disabled reason (global takes precedence)+ const getDisabledReason = (action: ActionDefinition) =>+ globalDisabledReason.value || action.disabledReason(context.value);++ return {+ context,+ primaryAction,+ secondaryActions,+ isActionDisabled,+ getDisabledReason,+ };+}diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionButton.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionButton.vuedeleted file mode 100644index 0e31ce7827..0000000000--- a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionButton.vue+++ /dev/null@@ -1,60 +0,0 @@-<template>- <NTooltip :disabled="!disabledTooltip" placement="bottom-end">- <template #trigger>- <NButton- size="medium"- tag="div"- v-bind="actionButtonProps(action)"- :disabled="disabled"- @click="$emit('perform-action', action)"- >- {{ actionDisplayName(action) }}- </NButton>- </template>- <template #default>- {{ disabledTooltip }}- </template>- </NTooltip>-</template>--<script setup lang="ts">-import { NButton, NTooltip } from "naive-ui";-import { usePlanAction } from "./action";-import type { UnifiedAction } from "./types";--defineProps<{- action: UnifiedAction;- disabled?: boolean;- disabledTooltip?: string;-}>();--defineEmits<{- (event: "perform-action", action: UnifiedAction): void;-}>();--const { actionDisplayName } = usePlanAction();--const actionButtonProps = (action: UnifiedAction) => {- switch (action) {- case "ISSUE_REVIEW":- case "ISSUE_CREATE":- case "ROLLOUT_START":- return {- type: "primary" as const,- };- case "ISSUE_STATUS_RESOLVE":- return {- type: "success" as const,- };- case "ISSUE_STATUS_REOPEN":- case "ISSUE_STATUS_CLOSE":- case "PLAN_CLOSE":- case "PLAN_REOPEN":- case "ROLLOUT_CANCEL":- case "ROLLOUT_CREATE":- return {- type: "default" as const,- };- }-};-</script>diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vuedeleted file mode 100644index 80c0abaf3f..0000000000--- a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/UnifiedActionGroup.vue+++ /dev/null@@ -1,205 +0,0 @@-<template>- <div class="flex items-center gap-x-2">- <!-- Rollout ready link for database change issues -->- <RolloutReadyLink v-if="shouldShowRolloutReadyLink" />-- <!-- Export Archive Download Action for export data issues (replaces primary action) -->- <ExportArchiveDownloadAction v-if="shouldShowExportDownload" />-- <!-- Primary action button (hidden when export download is shown) -->- <UnifiedActionButton- v-else-if="primaryAction"- :action="primaryAction.action"- :disabled="disabled || primaryAction.disabled"- :disabled-tooltip="disabled ? disabledTooltip : primaryAction.description"- @perform-action="handleAction"- />-- <!-- Dropdown for secondary actions -->- <NDropdown- v-if="secondaryActions.length > 0"- trigger="click"- placement="bottom-end"- :options="dropdownOptions"- :render-option="renderDropdownOption"- :disabled="disabled"- @select="handleDropdownSelect"- >- <NButton- class="px-1!"- quaternary- size="medium"- :disabled="disabled"- :title="disabled ? disabledTooltip : undefined"- >- <EllipsisVerticalIcon class="w-4 h-4" />- </NButton>- </NDropdown>- </div>-</template>--<script setup lang="ts">-import { first, orderBy } from "lodash-es";-import { EllipsisVerticalIcon } from "lucide-vue-next";-import { type DropdownOption, NButton, NDropdown } from "naive-ui";-import type { VNode } from "vue";-import { computed, h } from "vue";-import { useI18n } from "vue-i18n";-import { DropdownItemWithErrorList } from "@/components/IssueV1/components/common";-import { extractUserId, useCurrentUserV1 } from "@/store";-import { IssueStatus } from "@/types/proto-es/v1/issue_service_pb";-import {- Task_Status,- Task_Type,- type TaskRun,- TaskRun_ExportArchiveStatus,- TaskRun_Status,-} from "@/types/proto-es/v1/rollout_service_pb";-import { extractTaskRunUID, extractTaskUID } from "@/utils";-import { usePlanContext, useRolloutReadyLink } from "../../../../logic";-import { ExportArchiveDownloadAction } from "../export";-import RolloutReadyLink from "../RolloutReadyLink.vue";-import { usePlanAction } from "./action";-import type { ActionConfig, UnifiedAction } from "./types";-import UnifiedActionButton from "./UnifiedActionButton.vue";--type DropdownActionOption = DropdownOption & {- key: UnifiedAction;- label: string;- description?: string;-};--const props = defineProps<{- primaryAction?: ActionConfig;- secondaryActions: ActionConfig[];- disabled?: boolean;- disabledTooltip?: string;-}>();--const emit = defineEmits<{- (event: "perform-action", action: UnifiedAction): void;-}>();--const { t } = useI18n();-const { issue, rollout, taskRuns } = usePlanContext();-const currentUser = useCurrentUserV1();-const { shouldShow: shouldShowRolloutReadyLink } = useRolloutReadyLink();-const { actionDisplayName } = usePlanAction();--const shouldShowExportDownload = computed(() => {- // Must have an issue- if (!issue?.value) return false;-- // Issue status must be OPEN or DONE- if (![IssueStatus.OPEN, IssueStatus.DONE].includes(issue.value.status)) {- return false;- }-- // Current user must be the issue creator- if (currentUser.value.email !== extractUserId(issue.value.creator)) {- return false;- }-- const exportTasks =- rollout.value?.stages- .flatMap((stage) => stage.tasks)- .filter((task) => {- return task.type === Task_Type.DATABASE_EXPORT;- }) || [];-- // Must have export data tasks- if (exportTasks.length === 0) return false;-- // Check if all export tasks have done or skipped status- if (- !exportTasks.every((task) =>- [Task_Status.DONE, Task_Status.SKIPPED].includes(task.status)- )- ) {- return false;- }-- // Get latest task run for each export task- const exportTaskRuns = exportTasks- .map((task) => {- const taskRunsForTask = taskRuns.value.filter(- (taskRun) => extractTaskUID(taskRun.name) === extractTaskUID(task.name)- );- return first(- orderBy(- taskRunsForTask,- (taskRun) => Number(extractTaskRunUID(taskRun.name)),- "desc"- )- );- })- .filter(Boolean) as TaskRun[];-- // Check if export archive is ready- if (- exportTaskRuns.length === 0 ||- exportTaskRuns.some(- (taskRun) =>- taskRun.status !== TaskRun_Status.DONE ||- taskRun.exportArchiveStatus ===- TaskRun_ExportArchiveStatus.EXPORT_ARCHIVE_STATUS_UNSPECIFIED- )- ) {- return false;- }-- return true;-});--const dropdownOptions = computed((): DropdownActionOption[] => {- return props.secondaryActions.map((config) => ({- key: config.action,- label: actionDisplayName(config.action),- disabled: props.disabled || config.disabled,- description: props.disabled ? props.disabledTooltip : config.description,- }));-});--const renderDropdownOption = ({- node,- option,-}: {- node: VNode;- option: DropdownOption;-}) => {- const actionOption = props.secondaryActions.find(- (config) => config.action === (option as DropdownActionOption).key- );- const disabled = props.disabled || actionOption?.disabled;- const description = props.disabled- ? props.disabledTooltip- : actionOption?.description;- const errors = disabled- ? [- description ||- t("issue.error.you-are-not-allowed-to-perform-this-action"),- ]- : [];- return h(- DropdownItemWithErrorList,- {- errors,- placement: "left",- },- {- default: () => node,- }- );-};--const handleAction = (action: UnifiedAction) => {- emit("perform-action", action);-};--const handleDropdownSelect = (key: string) => {- const option = dropdownOptions.value.find((opt) => opt.key === key);- if (option && !option.disabled) {- handleAction(option.key);- }-};-</script>diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/action.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/action.tsdeleted file mode 100644index bc83ac26a1..0000000000--- a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/action.ts+++ /dev/null@@ -1,333 +0,0 @@-import { computed } from "vue";-import { usePlanCheckStatus, usePlanContext } from "@/components/Plan/logic";-import { t } from "@/plugins/i18n";-import {- candidatesOfApprovalStepV1,- extractUserId,- useCurrentProjectV1,- useCurrentUserV1,-} from "@/store";-import { State } from "@/types/proto-es/v1/common_pb";-import {- Issue_ApprovalStatus,- Issue_Approver_Status,- Issue_Type,- IssueStatus,-} from "@/types/proto-es/v1/issue_service_pb";-import { Task_Status, Task_Type } from "@/types/proto-es/v1/rollout_service_pb";-import { Advice_Level } from "@/types/proto-es/v1/sql_service_pb";-import {- hasProjectPermissionV2,- isUserIncludedInList,- isValidIssueName,- isValidPlanName,-} from "@/utils";-import { type UnifiedAction } from "./types";--export const usePlanAction = () => {- const currentUser = useCurrentUserV1();- const { project } = useCurrentProjectV1();-- const { isCreating, plan, issue, rollout } = usePlanContext();-- // Plan check status for rollout creation validation- const {- getOverallStatus: planCheckStatus,- hasRunning: hasRunningPlanChecks,- } = usePlanCheckStatus(plan);-- // Check if user can approve (is a candidate for current approval step)- const canApprove = computed(() => {- const issueValue = issue?.value;- if (!issueValue) return false;-- const issueApproved =- issueValue.approvalStatus === Issue_ApprovalStatus.APPROVED ||- issueValue.approvalStatus === Issue_ApprovalStatus.SKIPPED;- if (issueApproved) return false;-- const { approvers, approvalTemplate } = issueValue;- const hasRejection = approvers.some(- (app) => app.status === Issue_Approver_Status.REJECTED- );- // Cannot approve if already rejected- if (hasRejection) return false;-- const roles = approvalTemplate?.flow?.roles ?? [];- if (roles.length === 0) return false;-- const currentRoleIndex = approvers.length;- const currentRole = roles[currentRoleIndex];- if (!currentRole) return false;-- const candidates = candidatesOfApprovalStepV1(issueValue, currentRole);- return isUserIncludedInList(currentUser.value.email, candidates);- });-- // Check if user can reject (same as approve, but only if no rejection yet)- const canReject = computed(() => {- const issueValue = issue?.value;- if (!issueValue) return false;-- const issueApproved =- issueValue.approvalStatus === Issue_ApprovalStatus.APPROVED ||- issueValue.approvalStatus === Issue_ApprovalStatus.SKIPPED;- if (issueApproved) return false;-- const { approvers, approvalTemplate } = issueValue;- const hasRejection = approvers.some(- (app) => app.status === Issue_Approver_Status.REJECTED- );- // Cannot reject if already rejected- if (hasRejection) return false;-- const roles = approvalTemplate?.flow?.roles ?? [];- if (roles.length === 0) return false;-- const rejectedIndex = approvers.findIndex(- (ap) => ap.status === Issue_Approver_Status.REJECTED- );- const currentRoleIndex =- rejectedIndex >= 0 ? rejectedIndex : approvers.length;- const currentRole = roles[currentRoleIndex];- if (!currentRole) return false;-- const candidates = candidatesOfApprovalStepV1(issueValue, currentRole);- return isUserIncludedInList(currentUser.value.email, candidates);- });-- /**- * Compute available actions based on issue state and user permissions.- *- * Action priority order:- * 1. Plan-level actions (for draft plans): PLAN_REOPEN, PLAN_CLOSE, ISSUE_CREATE- * 2. Issue review action: ISSUE_REVIEW (unified approve/reject/comment)- * 3. Issue status actions: ISSUE_STATUS_RESOLVE, ISSUE_STATUS_CLOSE, ISSUE_STATUS_REOPEN- * 4. Rollout actions: ROLLOUT_START, ROLLOUT_CANCEL- *- * Special cases:- * - Grant requests: Issue-only (no plan), only show issue-related actions- * - Draft plans: Plans without issues, show plan management + issue creation- * - Deleted plans: Only show PLAN_REOPEN- * - Cancelled/Done issues: Only show ISSUE_STATUS_REOPEN- */- const availableActions = computed(() => {- const actions: UnifiedAction[] = [];-- if (isCreating.value) return actions;-- const currentUserEmail = currentUser.value.email;- const isIssueOnly =- !isValidPlanName(plan.value.name) && isValidIssueName(issue.value?.name);-- // For issue-only cases (grant requests, etc.), skip plan-specific actions- // and go directly to issue-related actions- if (isIssueOnly) {- // Issue-only cases should not show plan actions- // Continue to issue-related actions below- }- // If no issue exists, show create issue action or close plan action.- else if (plan.value.issue === "") {- // If rollout exists, no actions are available.- if (plan.value.hasRollout) {- return actions;- }-- const canUpdatePlan =- currentUserEmail === extractUserId(plan.value.creator || "") ||- hasProjectPermissionV2(project.value, "bb.plans.update");-- // Check if user can reopen the plan- if (plan.value.state === State.DELETED) {- if (canUpdatePlan) {- actions.push("PLAN_REOPEN");- }- return actions; // For deleted plans, only show reopen action- }-- // Check if user can close the plan- if (canUpdatePlan) {- actions.push("PLAN_CLOSE");- }-- // Check if user can create an issue- if (hasProjectPermissionV2(project.value, "bb.issues.create")) {- actions.push("ISSUE_CREATE");- }-- return actions;- }-- const issueValue = issue?.value;- // Should not reach here.- if (!issueValue) return actions;- const isCanceled = issueValue.status === IssueStatus.CANCELED;- const isDone = issueValue.status === IssueStatus.DONE;- const canUpdateIssue = hasProjectPermissionV2(- project.value,- "bb.issues.update"- );-- // If issue is canceled, check for re-open action- if (isCanceled) {- if (canUpdateIssue) {- actions.push("ISSUE_STATUS_REOPEN");- }- return actions;- }-- // If issue is done, check for reopen action- if (isDone) {- if (canUpdateIssue) {- actions.push("ISSUE_STATUS_REOPEN");- }- return actions;- }-- // Check for review action - show unified review button if user can approve or reject- const issueApproved =- issueValue.approvalStatus === Issue_ApprovalStatus.APPROVED ||- issueValue.approvalStatus === Issue_ApprovalStatus.SKIPPED;- if (!issueApproved) {- if (canApprove.value || canReject.value) {- actions.push("ISSUE_REVIEW");- }- }-- if (canUpdateIssue) {- if (rollout.value) {- // Check if issue can be resolved (all tasks must be finished)- const allTasksFinished = rollout.value.stages- .flatMap((stage) => stage.tasks)- .every((task) =>- [Task_Status.DONE, Task_Status.SKIPPED].includes(task.status)- );- if (allTasksFinished && issueApproved) {- actions.push("ISSUE_STATUS_RESOLVE");- }- } else {- // Only allow closing issue when rollout doesn't exist- actions.push("ISSUE_STATUS_CLOSE");- }- }-- // Check for rollout creation action- // Only shown when issue exists, rollout doesn't, and all preconditions are met.- if (!plan.value.hasRollout && !isIssueOnly) {- const canCreateRollout = hasProjectPermissionV2(- project.value,- "bb.rollouts.create"- );-- if (canCreateRollout) {- const { requireIssueApproval, requirePlanCheckNoError } = project.value;-- // Issue must be approved/skipped if requireIssueApproval is enabled- const issueReady =- !requireIssueApproval ||- issueValue.approvalStatus === Issue_ApprovalStatus.APPROVED ||- issueValue.approvalStatus === Issue_ApprovalStatus.SKIPPED;-- // Plan checks must pass if requirePlanCheckNoError is enabled- const planCheckReady =- !requirePlanCheckNoError ||- (!hasRunningPlanChecks.value &&- planCheckStatus.value !== Advice_Level.ERROR);-- if (issueReady && planCheckReady) {- actions.push("ROLLOUT_CREATE");- }- }- }-- // Check for rollout actions when rollout has database creation/export tasks- // Only allow rollout actions when approval is ready (APPROVED or SKIPPED)- // For database change tasks, we'll handle in other places- if (rollout.value && issueApproved) {- // Check if there are any database creation or export tasks- const hasDatabaseCreateOrExportTasks = rollout.value.stages.some(- (stage) =>- stage.tasks.some(- (task) =>- task.type === Task_Type.DATABASE_CREATE ||- task.type === Task_Type.DATABASE_EXPORT- )- );- // Different permission checks based on issue type- // For export data issues: only the creator can run tasks- // For other issues: need bb.taskRuns.create permission- const canRunTasks =- issueValue.type === Issue_Type.DATABASE_EXPORT- ? currentUserEmail === extractUserId(issueValue.creator)- : hasProjectPermissionV2(project.value, "bb.taskRuns.create");-- if (hasDatabaseCreateOrExportTasks && canRunTasks) {- // Show ROLLOUT_START if there are actionable database creation/export tasks- // This includes both normal rollout and force rollout scenarios- const hasStartableTasks = rollout.value.stages- .flatMap((stage) => stage.tasks)- .some((task) =>- [- Task_Status.NOT_STARTED,- Task_Status.FAILED,- Task_Status.CANCELED,- ].includes(task.status)- );- if (hasStartableTasks) {- actions.push("ROLLOUT_START");- }-- // Check for cancel action on running/pending tasks- const runningTask = rollout.value.stages- .flatMap((stage) => stage.tasks)- .find((task) =>- [Task_Status.PENDING, Task_Status.RUNNING].includes(task.status)- );-- if (runningTask) {- actions.push("ROLLOUT_CANCEL");- }- }- }-- return actions;- });-- const isExportPlan = computed(() => {- return plan.value.specs.some(- (spec) => spec.config?.case === "exportDataConfig"- );- });-- const actionDisplayName = (action: UnifiedAction): string => {- switch (action) {- case "ISSUE_REVIEW":- return t("issue.review.self");- case "ISSUE_STATUS_CLOSE":- return t("issue.batch-transition.close");- case "ISSUE_STATUS_REOPEN":- return t("issue.batch-transition.reopen");- case "ISSUE_STATUS_RESOLVE":- return t("issue.batch-transition.resolve");- case "ISSUE_CREATE":- return t("plan.ready-for-review");- case "PLAN_CLOSE":- return t("common.close");- case "PLAN_REOPEN":- return t("common.reopen");- case "ROLLOUT_CREATE":- return t("issue.create-rollout");- case "ROLLOUT_START":- return isExportPlan.value ? t("common.export") : t("common.rollout");- case "ROLLOUT_CANCEL":- return t("common.cancel");- }- };-- return {- availableActions,- canApprove,- canReject,- actionDisplayName,- };-};diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/index.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/index.tsindex 5187c5b849..e3438d9e53 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/index.ts+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/index.ts@@ -1,5 +1,2 @@-export { usePlanAction } from "./action";export { default as IssueReviewButton } from "./IssueReviewButton.vue";-export { default as UnifiedActionButton } from "./UnifiedActionButton.vue";-export { default as UnifiedActionGroup } from "./UnifiedActionGroup.vue";export * from "./types";diff --git a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/types.ts b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/types.tsindex f196520c66..da482b3f45 100644--- a/frontend/src/components/Plan/components/HeaderSection/Actions/unified/types.ts+++ b/frontend/src/components/Plan/components/HeaderSection/Actions/unified/types.ts@@ -17,11 +17,11 @@ export type RolloutAction =| "ROLLOUT_START"| "ROLLOUT_CANCEL";-// All unified actions-export type UnifiedAction = IssueAction | PlanAction | RolloutAction;+export type ExportAction = "EXPORT_DOWNLOAD";-export interface ActionConfig {- action: UnifiedAction;- disabled?: boolean;- description?: string;-}+// All unified actions+export type UnifiedAction =+ | IssueAction+ | PlanAction+ | RolloutAction+ | ExportAction;diff --git a/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentList.vue b/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentList.vueindex 0f5be4cb2f..5aa6bfaf87 100644--- a/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentList.vue+++ b/frontend/src/components/Plan/components/IssueReviewView/ActivitySection/IssueCommentList.vue@@ -116,8 +116,9 @@ const fetchIssueComments = async () => {watchEffect(fetchIssueComments);-// Refresh comments when a review action is performed (approve/reject/re-request)+// Refresh comments when a review or status action is performedevents.on("perform-issue-review-action", fetchIssueComments);+events.on("perform-issue-status-action", fetchIssueComments);const issueComments = computed(() => {if (!issueName.value) return [];diff --git a/frontend/src/components/Plan/logic/initialize/index.ts b/frontend/src/components/Plan/logic/initialize/index.tsindex 188d2df985..d9dd3899b2 100644--- a/frontend/src/components/Plan/logic/initialize/index.ts+++ b/frontend/src/components/Plan/logic/initialize/index.ts@@ -146,17 +146,18 @@ export function useInitializePlan(// Fetch the plan using the issue's plan referenceplanResult = await planStore.fetchPlanByName(issueResult.plan);- // Fetch the associated rollout (derive from plan name)- const rolloutName = getRolloutFromPlan(planResult.name);- try {- const rolloutRequest = create(GetRolloutRequestSchema, {- name: rolloutName,- });- const newRollout =- await rolloutServiceClientConnect.getRollout(rolloutRequest);- rolloutResult = newRollout;- } catch {- // Rollout might not exist yet, that's ok+ if (planResult.hasRollout) {+ try {+ const rolloutName = getRolloutFromPlan(planResult.name);+ const rolloutRequest = create(GetRolloutRequestSchema, {+ name: rolloutName,+ });+ const newRollout =+ await rolloutServiceClientConnect.getRollout(rolloutRequest);+ rolloutResult = newRollout;+ } catch {+ // Rollout might not exist yet, that's ok+ }}} else {// Direct plan ID@@ -173,17 +174,18 @@ export function useInitializePlan(issueResult = newIssue;}- // If we have a plan, try to fetch the associated rollout (derive from plan name)- const rolloutName = getRolloutFromPlan(planResult.name);- try {- const rolloutRequest = create(GetRolloutRequestSchema, {- name: rolloutName,- });- const newRollout =- await rolloutServiceClientConnect.getRollout(rolloutRequest);- rolloutResult = newRollout;- } catch {- // Rollout might not exist yet, that's ok+ if (planResult.hasRollout) {+ try {+ const rolloutName = getRolloutFromPlan(planResult.name);+ const rolloutRequest = create(GetRolloutRequestSchema, {+ name: rolloutName,+ });+ const newRollout =+ await rolloutServiceClientConnect.getRollout(rolloutRequest);+ rolloutResult = newRollout;+ } catch {+ // Rollout might not exist yet, that's ok+ }}}diff --git a/frontend/src/components/Plan/logic/poller/poller.ts b/frontend/src/components/Plan/logic/poller/poller.tsindex 0029479193..4b9d3b88ca 100644--- a/frontend/src/components/Plan/logic/poller/poller.ts+++ b/frontend/src/components/Plan/logic/poller/poller.ts@@ -108,11 +108,13 @@ export const provideResourcePoller = () => {},canInitialize: () => {if (!plan.value?.name) return false;+ if (!plan.value.hasRollout) return false;const rolloutName = getRolloutFromPlan(plan.value.name);return isValidRolloutName(rolloutName);},initialize: async () => {if (!plan.value?.name) return;+ if (!plan.value.hasRollout) return;const rolloutName = getRolloutFromPlan(plan.value.name);rollout.value = create(RolloutSchema, { name: rolloutName });await resourceStrategies.rollout.refresh();