Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(frontend): add pending tasks preview for rollout (#18917)
boojack0d51da4042ee
diff --git a/frontend/src/components/Plan/logic/rolloutPreview.ts b/frontend/src/components/Plan/logic/rolloutPreview.tsindex c457bcfb6c..03499ee7cb 100644--- a/frontend/src/components/Plan/logic/rolloutPreview.ts+++ b/frontend/src/components/Plan/logic/rolloutPreview.ts@@ -226,7 +226,6 @@ function createTask(payload: {case: "databaseUpdate",value: create(Task_DatabaseUpdateSchema, {- // Task.DatabaseUpdate now uses oneof source { sheet | release }source: {case: "sheet",value: taskCreate.sheet,diff --git a/frontend/src/components/RolloutV1/components/PendingTasksPreviewDrawer.vue b/frontend/src/components/RolloutV1/components/PendingTasksPreviewDrawer.vuenew file mode 100644index 0000000000..892ed134af--- /dev/null+++ b/frontend/src/components/RolloutV1/components/PendingTasksPreviewDrawer.vue@@ -0,0 +1,178 @@+<template>+ <Drawer :show="show" @close="$emit('close')">+ <DrawerContent :title="$t('rollout.pending-tasks-preview.title')">+ <div class="w-[400px] space-y-4">+ <p class="text-sm text-control-light">+ {{ $t("rollout.pending-tasks-preview.description") }}+ </p>++ <BBSpin v-if="isLoading" class="mx-auto py-8" />++ <p v-else-if="!pendingTasksByEnv.length" class="py-8 text-center text-control-light">+ {{ $t("rollout.pending-tasks-preview.no-pending-tasks") }}+ </p>++ <div v-for="group in pendingTasksByEnv" :key="group.environment" class="border rounded-lg">+ <div class="flex items-center gap-2 px-3 py-2 bg-gray-50">+ <div class="flex items-center gap-2 flex-1 cursor-pointer" @click="toggleEnv(group.environment)">+ <component+ :is="expandedEnvs.has(group.environment) ? ChevronDownIcon : ChevronRightIcon"+ class="w-4 h-4 text-gray-500"+ />+ <span class="font-medium">{{ extractEnvironmentResourceName(group.environment) }}</span>+ <span class="text-xs text-control-light">+ {{ $t("rollout.pending-tasks-preview.task-count", group.tasks.length) }}+ </span>+ </div>+ <NButton+ size="tiny"+ :loading="creatingEnv === group.environment"+ :disabled="!!creatingEnv"+ @click="handleCreateTasks(group.environment)"+ >+ {{ $t("common.create") }}+ </NButton>+ </div>+ <ul v-if="expandedEnvs.has(group.environment)" class="px-3 py-2 space-y-1">+ <li v-for="task in group.tasks" :key="task.target">+ <DatabaseDisplay :database="task.target" size="small" />+ </li>+ </ul>+ </div>+ </div>+ </DrawerContent>+ </Drawer>+</template>++<script lang="ts" setup>+import { create } from "@bufbuild/protobuf";+import { ChevronDownIcon, ChevronRightIcon } from "lucide-vue-next";+import { NButton } from "naive-ui";+import { ref, watch } from "vue";+import { useI18n } from "vue-i18n";+import BBSpin from "@/bbkit/BBSpin.vue";+import DatabaseDisplay from "@/components/Plan/components/common/DatabaseDisplay.vue";+import { generateRolloutPreview } from "@/components/Plan/logic";+import { Drawer, DrawerContent } from "@/components/v2";+import { rolloutServiceClientConnect } from "@/connect";+import { pushNotification } from "@/store/modules/notification";+import type { Plan } from "@/types/proto-es/v1/plan_service_pb";+import type { Rollout, Task } from "@/types/proto-es/v1/rollout_service_pb";+import { CreateRolloutRequestSchema } from "@/types/proto-es/v1/rollout_service_pb";+import {+ extractEnvironmentResourceName,+ extractPlanNameFromRolloutName,+} from "@/utils";++interface TaskGroup {+ environment: string;+ tasks: Task[];+}++const props = defineProps<{+ show: boolean;+ plan: Plan;+ rollout: Rollout;+ projectName: string;+}>();++const emit = defineEmits<{+ (event: "close"): void;+ (event: "created"): void;+}>();++const { t } = useI18n();+const isLoading = ref(false);+const creatingEnv = ref<string | null>(null);+const pendingTasksByEnv = ref<TaskGroup[]>([]);+const expandedEnvs = ref<Set<string>>(new Set());++const loadPendingTasks = async () => {+ if (pendingTasksByEnv.value.length > 0 || isLoading.value) return;+ isLoading.value = true;+ try {+ const preview = await generateRolloutPreview(props.plan, props.projectName);++ // Build set of existing tasks (target + specId)+ const existingTasks = new Set<string>();+ for (const stage of props.rollout.stages) {+ for (const task of stage.tasks) {+ existingTasks.add(`${task.target}:${task.specId}`);+ }+ }++ // Find uncreated tasks and group by environment+ const groups = new Map<string, Task[]>();+ for (const stage of preview.stages) {+ for (const task of stage.tasks) {+ const key = `${task.target}:${task.specId}`;+ if (!existingTasks.has(key)) {+ let tasks = groups.get(stage.environment);+ if (!tasks) {+ tasks = [];+ groups.set(stage.environment, tasks);+ }+ tasks.push(task);+ }+ }+ }++ pendingTasksByEnv.value = Array.from(groups.entries()).map(+ ([environment, tasks]) => ({ environment, tasks })+ );+ // Auto-expand all groups+ expandedEnvs.value = new Set(groups.keys());+ } finally {+ isLoading.value = false;+ }+};++const handleCreateTasks = async (environment: string) => {+ creatingEnv.value = environment;+ try {+ const request = create(CreateRolloutRequestSchema, {+ parent: extractPlanNameFromRolloutName(props.rollout.name),+ target: environment,+ });+ await rolloutServiceClientConnect.createRollout(request);+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.success"),+ });+ // Remove created group from list+ pendingTasksByEnv.value = pendingTasksByEnv.value.filter(+ (g) => g.environment !== environment+ );+ emit("created");+ } catch (error) {+ pushNotification({+ module: "bytebase",+ style: "CRITICAL",+ title: t("common.error"),+ description: String(error),+ });+ } finally {+ creatingEnv.value = null;+ }+};++// Load when drawer opens+watch(+ () => props.show,+ (show) => {+ if (show) {+ loadPendingTasks();+ }+ },+ { immediate: true }+);++const toggleEnv = (env: string) => {+ if (expandedEnvs.value.has(env)) {+ expandedEnvs.value.delete(env);+ } else {+ expandedEnvs.value.add(env);+ }+};+</script>diff --git a/frontend/src/components/RolloutV1/components/RolloutView.vue b/frontend/src/components/RolloutV1/components/RolloutView.vueindex b4466d6f66..645c605487 100644--- a/frontend/src/components/RolloutV1/components/RolloutView.vue+++ b/frontend/src/components/RolloutV1/components/RolloutView.vue@@ -1,25 +1,44 @@<template><div class="rollout-view-v2 w-full min-h-screen bg-gray-50">- <BBSpin v-if="!ready" class="flex justify-center py-12" />-+ <!-- Empty state: no stages created yet -->+ <div v-if="!hasStages" class="flex flex-col items-center justify-center py-20 gap-4">+ <p class="text-gray-500">{{ $t("rollout.no-tasks-created") }}</p>+ <NButton v-if="hasPendingTasks" type="primary" @click="showPreviewDrawer = true">+ <template #icon>+ <EyeIcon class="w-4 h-4" />+ </template>+ {{ $t("rollout.pending-tasks-preview.action") }}+ </NButton>+ </div>++ <!-- Normal view: stages exist --><template v-else><StageNavigationBar- :stages="mergedStages":selected-stage-id="selectedStage?.name"- :is-stage-created="isStageCreated"+ :rollout="rollout"+ :has-pending-tasks="hasPendingTasks"@select-stage="handleStageSelect"+ @open-preview="showPreviewDrawer = true"/><StageContentView:selected-stage="selectedStage":rollout="rollout"- :is-stage-created="isStageCreated"+ :is-stage-created="() => true"@run-stage="handleRunStage"@create-stage="handleCreateStage"/></template>- <!-- Stage run action panel -->+ <PendingTasksPreviewDrawer+ :show="showPreviewDrawer"+ :plan="plan"+ :rollout="rollout"+ :project-name="project.name"+ @close="showPreviewDrawer = false"+ @created="handleTasksCreated"+ />+<TaskRolloutActionPanelv-if="showStageActionPanel && stageActionTarget":show="showStageActionPanel"@@ -33,12 +52,12 @@<script lang="ts" setup>import { create } from "@bufbuild/protobuf";+import { EyeIcon } from "lucide-vue-next";+import { NButton } from "naive-ui";import { computed, ref, watch } from "vue";import { useI18n } from "vue-i18n";import { useRoute, useRouter } from "vue-router";-import BBSpin from "@/bbkit/BBSpin.vue";import { usePlanContextWithRollout } from "@/components/Plan/logic";-import { useRolloutPreview } from "@/components/RolloutV1/logic";import { rolloutServiceClientConnect } from "@/connect";import { PROJECT_V1_ROUTE_PLAN_ROLLOUT_STAGE } from "@/router/dashboard/projectV1";import { useCurrentProjectV1 } from "@/store";@@ -50,8 +69,10 @@ import {extractPlanUIDFromRolloutName,extractProjectResourceName,} from "@/utils";+import { useExpectedTaskCount } from "./composables/useExpectedTaskCount";import { useStageSelection } from "./composables/useStageSelection";import { useTaskInstancePreload } from "./composables/useTaskInstancePreload";+import PendingTasksPreviewDrawer from "./PendingTasksPreviewDrawer.vue";import StageContentView from "./StageContentView.vue";import StageNavigationBar from "./StageNavigationBar.vue";import type { TargetType } from "./TaskRolloutActionPanel.vue";@@ -62,35 +83,35 @@ const router = useRouter();const { t } = useI18n();const { project } = useCurrentProjectV1();const { rollout, plan, events } = usePlanContextWithRollout();-const { ready, mergedStages } = useRolloutPreview(- rollout,- plan,- project.value.name-);const routeStageId = computed(() => route.params.stageId as string | undefined);-const { selectedStage, isStageCreated } = useStageSelection(- mergedStages,+const { selectedStage } = useStageSelection(+ computed(() => rollout.value.stages),routeStageId,rollout);-// Preload instances for tasks in the selected stage to ensure engine icons displayuseTaskInstancePreload(() =>selectedStage.value ? [selectedStage.value] : []);-// Stage action panel state+const hasStages = computed(() => rollout.value.stages.length > 0);+const { expectedTaskCount } = useExpectedTaskCount(plan);+const hasPendingTasks = computed(() => {+ const actualCount = rollout.value.stages.flatMap((s) => s.tasks).length;+ return expectedTaskCount.value > actualCount;+});++const showPreviewDrawer = ref(false);const showStageActionPanel = ref(false);const stageAction = ref<"RUN" | "SKIP" | "CANCEL">("RUN");const stageActionTarget = ref<TargetType | null>(null);-// Auto-navigate to the selected stage if no stageId in routewatch(- () => [selectedStage.value, routeStageId.value, ready.value] as const,- ([stage, currentRouteStageId, isReady]) => {- if (isReady && stage && !currentRouteStageId) {+ () => [selectedStage.value, routeStageId.value] as const,+ ([stage, currentRouteStageId]) => {+ if (stage && !currentRouteStageId) {const stageId = stage.name.split("/").pop();const planId = extractPlanUIDFromRolloutName(rollout.value.name);router.replace({@@ -107,11 +128,8 @@ watch();const handleStageSelect = (stage: Stage) => {- // Navigate to the proper stage route- // Navigate to the proper stage routeconst stageId = stage.name.split("/").pop();const planId = extractPlanUIDFromRolloutName(rollout.value.name);-router.push({name: PROJECT_V1_ROUTE_PLAN_ROLLOUT_STAGE,params: {@@ -123,12 +141,8 @@ const handleStageSelect = (stage: Stage) => {};const handleRunStage = (stage: Stage) => {- // Show confirmation panel for running all runnable tasks in the stagestageAction.value = "RUN";- stageActionTarget.value = {- type: "tasks",- stage,- };+ stageActionTarget.value = { type: "tasks", stage };showStageActionPanel.value = true;};@@ -139,15 +153,12 @@ const handleCreateStage = async (stage: Stage) => {target: stage.environment,});await rolloutServiceClientConnect.createRollout(request);-pushNotification({module: "bytebase",style: "SUCCESS",title: t("common.success"),description: t("common.created"),});-- // Trigger immediate refresh of rollout dataevents.emit("status-changed", { eager: true });} catch (error) {pushNotification({@@ -160,10 +171,12 @@ const handleCreateStage = async (stage: Stage) => {};const handleStageActionConfirmed = () => {- // Refresh the rollout data after task action is confirmedevents.emit("status-changed", { eager: true });- // Close the panel and reset stateshowStageActionPanel.value = false;stageActionTarget.value = null;};++const handleTasksCreated = () => {+ events.emit("status-changed", { eager: true });+};</script>diff --git a/frontend/src/components/RolloutV1/components/StageNavigationBar.vue b/frontend/src/components/RolloutV1/components/StageNavigationBar.vueindex eedf8a9181..99013e379b 100644--- a/frontend/src/components/RolloutV1/components/StageNavigationBar.vue+++ b/frontend/src/components/RolloutV1/components/StageNavigationBar.vue@@ -2,51 +2,53 @@<div class="relative bg-white pt-3"><div class="absolute w-full bottom-0 leading-0 border-b border-b-gray-200" /><div class="flex items-center justify-between gap-x-4">- <!-- Left: Stage tabs --><div class="flex items-center overflow-x-auto px-4">- <template v-for="(stage, index) in stages" :key="stage.name">+ <template v-for="(stage, index) in rollout.stages" :key="stage.name"><divclass="relative px-4 py-2 transition-all border rounded-t-lg cursor-pointer":class="[selectedStageId === stage.name? 'bg-gray-50 border-gray-200 border-b-transparent': 'bg-white hover:bg-gray-50 border-transparent border-b-gray-200',- !isStageCreated(stage) && 'opacity-80',]"- @click="handleStageClick(stage)"+ @click="$emit('select-stage', stage)">- <StageProgressCard- :stage="stage"- :is-created="isStageCreated(stage)"- />+ <StageProgressCard :stage="stage" /></div><ArrowRightIcon- v-if="index < stages.length - 1"+ v-if="index < rollout.stages.length - 1":size="16"class="text-gray-400 shrink-0 mx-2"/></template></div>++ <div v-if="hasPendingTasks" class="flex items-center px-4 shrink-0">+ <NButton size="small" @click="$emit('open-preview')">+ <template #icon>+ <EyeIcon class="w-4 h-4" />+ </template>+ {{ $t("rollout.pending-tasks-preview.action") }}+ </NButton>+ </div></div></div></template><script lang="ts" setup>-import { ArrowRightIcon } from "lucide-vue-next";-import type { Stage } from "@/types/proto-es/v1/rollout_service_pb";+import { ArrowRightIcon, EyeIcon } from "lucide-vue-next";+import { NButton } from "naive-ui";+import type { Rollout, Stage } from "@/types/proto-es/v1/rollout_service_pb";import StageProgressCard from "./StageProgressCard.vue";defineProps<{- stages: Stage[];selectedStageId?: string;- isStageCreated: (stage: Stage) => boolean;+ rollout: Rollout;+ hasPendingTasks: boolean;}>();-const emit = defineEmits<{+defineEmits<{(event: "select-stage", stage: Stage): void;+ (event: "open-preview"): void;}>();--const handleStageClick = (stage: Stage) => {- emit("select-stage", stage);-};</script>diff --git a/frontend/src/components/RolloutV1/components/StageProgressCard.vue b/frontend/src/components/RolloutV1/components/StageProgressCard.vueindex cf5711a0cb..bb5395bdd4 100644--- a/frontend/src/components/RolloutV1/components/StageProgressCard.vue+++ b/frontend/src/components/RolloutV1/components/StageProgressCard.vue@@ -15,10 +15,15 @@ import { useEnvironmentV1Store } from "@/store";import type { Stage } from "@/types/proto-es/v1/rollout_service_pb";import { useStageStatus } from "./composables/useStageStatus";-const props = defineProps<{- stage: Stage;- isCreated: boolean;-}>();+const props = withDefaults(+ defineProps<{+ stage: Stage;+ isCreated?: boolean;+ }>(),+ {+ isCreated: true,+ }+);const environmentStore = useEnvironmentV1Store();diff --git a/frontend/src/components/RolloutV1/components/composables/useExpectedTaskCount.ts b/frontend/src/components/RolloutV1/components/composables/useExpectedTaskCount.tsnew file mode 100644index 0000000000..dadba63612--- /dev/null+++ b/frontend/src/components/RolloutV1/components/composables/useExpectedTaskCount.ts@@ -0,0 +1,39 @@+import type { Ref } from "vue";+import { ref, watch } from "vue";+import { useDBGroupStore } from "@/store";+import { isValidDatabaseGroupName } from "@/types";+import { DatabaseGroupView } from "@/types/proto-es/v1/database_group_service_pb";+import type { Plan } from "@/types/proto-es/v1/plan_service_pb";++export const useExpectedTaskCount = (plan: Ref<Plan>) => {+ const dbGroupStore = useDBGroupStore();+ const expectedTaskCount = ref(0);++ const update = async () => {+ let count = 0;+ for (const spec of plan.value.specs) {+ if (spec.config.case === "changeDatabaseConfig") {+ for (const target of spec.config.value.targets ?? []) {+ if (isValidDatabaseGroupName(target)) {+ try {+ const dbGroup = await dbGroupStore.getOrFetchDBGroupByName(+ target,+ { view: DatabaseGroupView.FULL, silent: true }+ );+ count += dbGroup.matchedDatabases?.length ?? 0;+ } catch {+ // Ignore errors+ }+ } else {+ count++;+ }+ }+ }+ }+ expectedTaskCount.value = count;+ };++ watch(() => plan.value.specs, update, { immediate: true });++ return { expectedTaskCount };+};diff --git a/frontend/src/components/RolloutV1/logic/index.ts b/frontend/src/components/RolloutV1/logic/index.tsindex 2b6c9fd4a7..979fea9a74 100644--- a/frontend/src/components/RolloutV1/logic/index.ts+++ b/frontend/src/components/RolloutV1/logic/index.ts@@ -1,2 +1 @@export * from "./task";-export * from "./useRolloutPreview";diff --git a/frontend/src/components/RolloutV1/logic/useRolloutPreview.ts b/frontend/src/components/RolloutV1/logic/useRolloutPreview.tsdeleted file mode 100644index 75803c306e..0000000000--- a/frontend/src/components/RolloutV1/logic/useRolloutPreview.ts+++ /dev/null@@ -1,34 +0,0 @@-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/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 69648cd46d..d25b3590b3 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1262,7 +1262,15 @@"view-full-details": "View Details","statement-truncated-hint": "Statement truncated due to large size."},- "no-stages": "No stages available"+ "no-stages": "No stages available",+ "no-tasks-created": "No tasks created yet",+ "pending-tasks-preview": {+ "title": "Pending Tasks",+ "description": "The following tasks have not been created yet.",+ "action": "Preview",+ "task-count": "{count} task | {count} tasks",+ "no-pending-tasks": "No pending tasks"+ }},"quick-action": {"create-db": "Create database",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex 02407a6bc2..af549d8b41 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -1262,7 +1262,15 @@"view-full-details": "Ver detalles","statement-truncated-hint": "Declaración truncada debido al gran tamaño."},- "no-stages": "No hay etapas disponibles"+ "no-stages": "No hay etapas disponibles",+ "no-tasks-created": "No hay tareas creadas todavía",+ "pending-tasks-preview": {+ "title": "Tareas pendientes",+ "description": "Las siguientes tareas aún no han sido creadas.",+ "action": "Avance",+ "task-count": "{count} tarea | {count} tareas",+ "no-pending-tasks": "No hay tareas pendientes"+ }},"quick-action": {"create-db": "Crear base de datos",diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex 5748521981..350a682e17 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -1262,7 +1262,15 @@"view-full-details": "詳細を表示","statement-truncated-hint": "サイズが大きいため、ステートメントは切り捨てられました。"},- "no-stages": "利用可能なステージはありません"+ "no-stages": "利用可能なステージはありません",+ "no-tasks-created": "まだタスクは作成されていません",+ "pending-tasks-preview": {+ "title": "保留中のタスク",+ "description": "以下のタスクはまだ作成されていません。",+ "action": "プレビュー",+ "task-count": "{count} タスク | {count} タスク",+ "no-pending-tasks": "保留中のタスクはありません"+ }},"quick-action": {"create-db": "データベースの作成",diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.jsonindex 53ef15453a..2db726d6d1 100644--- a/frontend/src/locales/vi-VN.json+++ b/frontend/src/locales/vi-VN.json@@ -1262,7 +1262,15 @@"view-full-details": "Xem chi tiết đầy đủ","statement-truncated-hint": "Câu lệnh bị cắt bớt do kích thước lớn."},- "no-stages": "Không có giai đoạn nào có sẵn"+ "no-stages": "Không có giai đoạn nào có sẵn",+ "no-tasks-created": "Chưa có tác vụ nào được tạo.",+ "pending-tasks-preview": {+ "title": "Các nhiệm vụ đang chờ xử lý",+ "description": "Các tác vụ sau chưa được tạo.",+ "action": "Xem trước",+ "task-count": "{count} nhiệm vụ | {count} nhiệm vụ",+ "no-pending-tasks": "Không có nhiệm vụ nào đang chờ xử lý"+ }},"quick-action": {"create-db": "Tạo cơ sở dữ liệu",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex c2f02bcb53..3fff60caf1 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1262,7 +1262,15 @@"view-full-details": "查看详情","statement-truncated-hint": "由于语句过长,已被截断。"},- "no-stages": "没有可用的阶段"+ "no-stages": "没有可用的阶段",+ "no-tasks-created": "尚未创建任何任务",+ "pending-tasks-preview": {+ "title": "待处理任务",+ "description": "以下任务尚未创建。",+ "action": "预览",+ "task-count": "{count} 个任务 | {count} 个任务",+ "no-pending-tasks": "没有待处理任务"+ }},"quick-action": {"create-db": "创建数据库",