Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor: extract TaskItem logic into composables (#18196)

boojack74dd68f3f671
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue b/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue
index f5ee7ffd14..27d372aca5 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskOperations.vue
@@ -88,7 +88,6 @@ const props = defineProps<{
}>();
const emit = defineEmits<{
- (event: "refresh"): void;
(event: "action-confirmed"): void;
}>();
@@ -261,7 +260,6 @@ const actions = computed((): TaskAction[] => {
});
const handleActionPanelConfirm = () => {
- emit("refresh");
emit("action-confirmed");
handleActionPanelClose();
};
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue b/frontend/src/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue
index 4942968691..3ac81325bf 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue
@@ -883,11 +883,6 @@ const handleConfirm = async () => {
}
emit("confirm");
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("common.success"),
- });
} catch (error) {
pushNotification({
module: "bytebase",
diff --git a/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue b/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue
index 25ccebe8b7..0fb0439e7c 100644
--- a/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue
+++ b/frontend/src/components/Plan/components/RolloutView/TaskTableView.vue
@@ -5,7 +5,6 @@
:tasks="selectedTasks"
:rollout="rollout"
:stage="props.stage"
- @refresh="handleRefresh"
@action-confirmed="handleTaskActionConfirmed"
/>
@@ -45,13 +44,9 @@ const handleSelectedTasksUpdate = (tasks: Task[]) => {
selectedTasks.value = tasks;
};
-const handleRefresh = () => {
- events.emit("status-changed", { eager: true });
-};
-
const handleTaskActionConfirmed = () => {
// Clear selection after action is confirmed.
selectedTasks.value = [];
- handleRefresh();
+ events.emit("status-changed", { eager: true });
};
</script>
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/StageContentView.vue b/frontend/src/components/Plan/components/RolloutView/v2/StageContentView.vue
index 8c2bd91bbe..046f9b67d3 100644
--- a/frontend/src/components/Plan/components/RolloutView/v2/StageContentView.vue
+++ b/frontend/src/components/Plan/components/RolloutView/v2/StageContentView.vue
@@ -4,9 +4,8 @@
<div class="px-4">
<div class="w-full flex flex-row items-center justify-between py-4 gap-2">
<!-- Left: Stage info and filters -->
- <div class="flex flex-row items-center gap-4">
+ <div class="flex flex-row items-center gap-3">
<div class="flex flex-row items-center gap-2">
-
<NTag round>{{ $t("common.stage") }}</NTag>
<span class="font-medium text-lg">
<EnvironmentV1Name
@@ -24,6 +23,22 @@
:selected-statuses="filterStatuses"
@update:selected-statuses="handleFilterStatusesChange"
/>
+ <!-- Rollback entry -->
+ <NButton
+ v-if="
+ isStageCreated(selectedStage) && rollbackableTaskRuns.length > 0
+ "
+ size="small"
+ quaternary
+ @click="showRollbackDrawer = true"
+ >
+ <template #icon>
+ <DatabaseBackupIcon :size="16" />
+ </template>
+ {{
+ $t("task-run.rollback.available", rollbackableTaskRuns.length)
+ }}
+ </NButton>
</div>
<!-- Right: Stage actions -->
@@ -62,6 +77,14 @@
:filter-statuses="filterStatuses"
:readonly="!isStageCreated(selectedStage)"
/>
+
+ <!-- Rollback drawer -->
+ <TaskRunRollbackDrawer
+ v-model:show="showRollbackDrawer"
+ :rollout="rollout"
+ :rollbackable-task-runs="rollbackableTaskRuns"
+ @close="showRollbackDrawer = false"
+ />
</div>
<div v-else class="flex items-center justify-center py-12">
@@ -72,13 +95,16 @@
</template>
<script lang="ts" setup>
-import { PlayIcon, PlusIcon } from "lucide-vue-next";
+import { DatabaseBackupIcon, PlayIcon, PlusIcon } from "lucide-vue-next";
import { NButton, NTag } from "naive-ui";
-import { computed, ref } from "vue";
+import { computed, ref, toRef } from "vue";
import { EnvironmentV1Name } from "@/components/v2";
import { useEnvironmentV1Store } from "@/store";
import type { Rollout, Stage } from "@/types/proto-es/v1/rollout_service_pb";
import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
+import { usePlanContextWithRollout } from "../../../logic";
+import TaskRunRollbackDrawer from "../TaskRunRollbackDrawer.vue";
+import { useRollbackableTasks } from "./composables/useRollbackableTasks";
import TaskFilter from "./TaskFilter.vue";
import TaskList from "./TaskList.vue";
@@ -96,6 +122,15 @@ defineEmits<{
const environmentStore = useEnvironmentV1Store();
const filterStatuses = ref<Task_Status[]>([]);
+// Rollback functionality
+const { taskRuns } = usePlanContextWithRollout();
+const selectedStageRef = toRef(props, "selectedStage");
+const { rollbackableTaskRuns } = useRollbackableTasks(
+ selectedStageRef,
+ taskRuns
+);
+const showRollbackDrawer = ref(false);
+
const canRunStage = computed(() => {
if (!props.selectedStage || !props.isStageCreated(props.selectedStage)) {
return false;
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue b/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue
index 8f3eaa2d23..7a3ac5eeec 100644
--- a/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue
+++ b/frontend/src/components/Plan/components/RolloutView/v2/TaskItem.vue
@@ -23,7 +23,7 @@
<div class="w-full" :class="isExpanded ? 'p-4 space-y-3' : 'py-3 px-4'">
<!-- Header section -->
<div class="flex items-center justify-between gap-x-3 mb-2">
- <div class="flex items-center gap-x-2">
+ <div class="flex items-center gap-x-2 flex-1 min-w-0">
<div
:class="readonly ? '' : 'cursor-pointer hover:opacity-80'"
class="transition-opacity"
@@ -42,6 +42,35 @@
:link="false"
/>
</div>
+ <div v-if="!isExpanded" class="flex items-center gap-x-2 ml-auto shrink-0">
+ <NTag size="tiny" round class="opacity-80">
+ {{ taskTypeDisplay }}
+ </NTag>
+ <!-- Scheduled time indicator -->
+ <span
+ v-if="timingType === 'scheduled'"
+ class="flex items-center gap-x-1 text-xs text-blue-600"
+ :title="t('task.scheduled-time')"
+ >
+ <ClockIcon class="w-3 h-3" />
+ {{ timingDisplay }}
+ </span>
+ <!-- Running indicator -->
+ <span
+ v-else-if="timingType === 'running'"
+ class="flex items-center gap-x-1 text-xs text-yellow-600"
+ >
+ <LoaderCircleIcon class="w-3 h-3 animate-spin" />
+ {{ timingDisplay }}
+ </span>
+ <!-- Completed duration -->
+ <span
+ v-else-if="timingDisplay"
+ class="text-xs text-gray-600"
+ >
+ {{ timingDisplay }}
+ </span>
+ </div>
</div>
<!-- Expand/Collapse button -->
@@ -56,72 +85,174 @@
</div>
<!-- SQL preview - collapsed only -->
- <div
- v-if="!isExpanded"
- class="flex flex-row justify-start items-start gap-2"
- >
- <NTag size="tiny" round class="opacity-80">
- {{ $t("common.statement") }}
- </NTag>
- <div
- :class="readonly ? '' : 'cursor-pointer'"
- class="text-xs text-gray-600 font-mono truncate"
- @click="handleNavigateToDetail">
-
- {{ statementPreview }}
- </div>
- </div>
-
- <!-- SQL Statement section - expanded only -->
- <div v-else>
- <div class="flex items-center justify-between mb-2">
- <span class="text-sm font-medium text-gray-700">{{ t("common.statement") }}</span>
+ <div v-if="!isExpanded" class="space-y-1">
+ <div class="flex flex-row justify-start items-start gap-2">
+ <NTag size="tiny" round class="opacity-80">
+ {{ t("common.statement") }}
+ </NTag>
+ <div
+ :class="readonly ? '' : 'cursor-pointer'"
+ class="text-xs text-gray-600 font-mono truncate"
+ @click="handleNavigateToDetail"
+ >
+ {{ statementPreview }}
+ </div>
+ </div>
+ <!-- Error preview for failed tasks -->
+ <div v-if="errorPreview" class="text-xs text-red-600 truncate pl-1">
+ {{ t("common.error") }}: {{ errorPreview }}
+ </div>
+ <!-- Skipped reason -->
+ <div v-if="task.status === Task_Status.SKIPPED && task.skippedReason" class="text-xs text-gray-500 italic truncate pl-1">
+ {{ task.skippedReason }}
</div>
-
- <BBSpin v-if="loading" />
- <HighlightCodeBlock
- v-else
- :code="displayedStatement"
- language="sql"
- :lazy="true"
- :virtual="true"
- class="text-sm whitespace-pre-wrap wrap-break-word max-h-64 rounded p-2 bg-white border border-gray-200"
- />
</div>
- <!-- Latest Task Run Info - expanded only -->
- <div v-if="isExpanded && latestTaskRun">
- <div class="flex items-center justify-between mb-2">
- <div class="flex items-center gap-x-2">
- <span class="text-sm font-medium text-gray-700">{{ t("task-run.latest") }}</span>
- <span class="text-sm text-gray-500">
- <Timestamp :timestamp="latestTaskRun.updateTime" />
- </span>
+ <!-- Task metadata - expanded only -->
+ <div v-else class="space-y-3">
+ <!-- Task information line with quick actions -->
+ <div class="flex items-center justify-between gap-x-2">
+ <div class="flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-gray-600">
+ <span>{{ t("common.type") }}: {{ taskTypeDisplay }}</span>
+ <span v-if="executorEmail" class="text-gray-400">·</span>
+ <span v-if="executorEmail">{{ t("task.executed-by") }}: {{ executorEmail }}</span>
+ <span v-if="timingDisplay" class="text-gray-400">·</span>
+ <span v-if="timingDisplay">{{ t("common.duration") }}: {{ timingDisplay }}</span>
+ <span v-if="affectedRowsDisplay" class="text-gray-400">·</span>
+ <span v-if="affectedRowsDisplay">{{ t("task.affected-rows") }}: {{ affectedRowsDisplay }}</span>
+ </div>
+ <!-- Quick action buttons -->
+ <div v-if="hasActions" class="flex items-center gap-x-2 shrink-0">
+ <NButton
+ v-if="canRun"
+ size="tiny"
+ type="primary"
+ @click.stop="runTask"
+ >
+ <template #icon>
+ <PlayIcon class="w-3 h-3" />
+ </template>
+ {{ task.status === Task_Status.FAILED ? t("common.retry") : t("common.run") }}
+ </NButton>
+ <NButton
+ v-if="canSkip"
+ size="tiny"
+ @click.stop="skipTask"
+ >
+ <template #icon>
+ <SkipForwardIcon class="w-3 h-3" />
+ </template>
+ {{ t("common.skip") }}
+ </NButton>
+ <NButton
+ v-if="canCancel"
+ size="tiny"
+ @click.stop="cancelTask"
+ >
+ <template #icon>
+ <XIcon class="w-3 h-3" />
+ </template>
+ {{ t("common.cancel") }}
+ </NButton>
</div>
- <a
- v-if="!readonly"
- href="javascript:void(0)"
- class="text-xs text-blue-600 hover:text-blue-700"
- @click="handleNavigateToDetail"
- >
- {{ t("rollout.task.view-full-details") }} →
- </a>
</div>
- <div v-if="latestTaskRun.detail" class="text-sm text-gray-700 whitespace-pre-wrap">
- {{ latestTaskRun.detail }}
+
+ <!-- SQL Statement section -->
+ <div>
+ <div class="flex items-center justify-between mb-2">
+ <span class="text-sm font-medium text-gray-700">{{ t("common.statement") }}</span>
+ </div>
+
+ <BBSpin v-if="loading" />
+ <HighlightCodeBlock
+ v-else
+ :code="displayedStatement"
+ language="sql"
+ :lazy="true"
+ :virtual="true"
+ class="text-sm whitespace-pre-wrap wrap-break-word max-h-64 rounded p-2 bg-white border border-gray-200"
+ />
</div>
- <div v-else class="text-xs text-gray-500 italic">
- {{ t("task-run.no-detail") }}
+
+ <!-- Latest Task Run Info -->
+ <div v-if="latestTaskRun">
+ <div class="flex items-center justify-between mb-2">
+ <div class="flex items-center gap-x-2">
+ <span class="text-sm font-medium text-gray-700">{{ t("task-run.latest") }}</span>
+ <span class="text-sm text-gray-500">
+ <Timestamp :timestamp="latestTaskRun.updateTime" />
+ </span>
+ </div>
+ <a
+ v-if="!readonly"
+ href="javascript:void(0)"
+ class="text-xs text-blue-600 hover:text-blue-700"
+ @click="handleNavigateToDetail"
+ >
+ {{ t("rollout.task.view-full-details") }} →
+ </a>
+ </div>
+
+ <!-- Error message for failed tasks -->
+ <div v-if="task.status === Task_Status.FAILED && latestTaskRun.detail" class="mb-2 p-2 bg-red-50 border border-red-200 rounded">
+ <div class="text-sm font-medium text-red-700 mb-1">{{ t("common.error") }}</div>
+ <div class="text-sm text-red-600 whitespace-pre-wrap">
+ {{ latestTaskRun.detail }}
+ </div>
+ </div>
+
+ <!-- Waiting message for pending tasks -->
+ <div v-else-if="waitingMessage" class="mb-2 p-2 bg-blue-50 border border-blue-200 rounded">
+ <div class="text-sm text-blue-700 flex items-center gap-x-1">
+ <span>⏳</span>
+ <span>{{ waitingMessage }}</span>
+ </div>
+ </div>
+
+ <!-- Success message with result summary -->
+ <div v-else-if="task.status === Task_Status.DONE">
+ <div class="flex items-center gap-x-2 text-sm text-green-700 mb-1">
+ <span>✓</span>
+ <span>{{ t("common.success") }}</span>
+ <span v-if="resultSummary" class="text-gray-600">· {{ resultSummary }}</span>
+ </div>
+ </div>
+
+ <!-- Default detail display for other statuses -->
+ <div v-else-if="latestTaskRun.detail" class="text-sm text-gray-700 whitespace-pre-wrap">
+ {{ latestTaskRun.detail }}
+ </div>
+ <div v-else class="text-xs text-gray-500 italic">
+ {{ t("task-run.no-detail") }}
+ </div>
</div>
</div>
</div>
+
+ <!-- Task Rollout Action Panel -->
+ <TaskRolloutActionPanel
+ v-if="currentAction && actionTarget"
+ :show="showActionPanel"
+ :action="currentAction"
+ :target="actionTarget"
+ @close="closeActionPanel"
+ @confirm="handleActionConfirm"
+ />
</div>
</template>
<script lang="ts" setup>
import { last } from "lodash-es";
-import { ChevronDownIcon, ChevronRightIcon } from "lucide-vue-next";
-import { NCheckbox, NTag } from "naive-ui";
+import {
+ ChevronDownIcon,
+ ChevronRightIcon,
+ ClockIcon,
+ LoaderCircleIcon,
+ PlayIcon,
+ SkipForwardIcon,
+ XIcon,
+} from "lucide-vue-next";
+import { NButton, NCheckbox, NTag } from "naive-ui";
import { computed } from "vue";
import { useI18n } from "vue-i18n";
import BBSpin from "@/bbkit/BBSpin.vue";
@@ -129,11 +260,17 @@ import HighlightCodeBlock from "@/components/HighlightCodeBlock";
import Timestamp from "@/components/misc/Timestamp.vue";
import { usePlanContextWithRollout } from "@/components/Plan";
import DatabaseDisplay from "@/components/Plan/components/common/DatabaseDisplay.vue";
+import TaskRolloutActionPanel from "@/components/Plan/components/RolloutView/TaskRolloutActionPanel.vue";
import TaskStatus from "@/components/Rollout/kits/TaskStatus.vue";
import { taskRunNamePrefix } from "@/store";
import type { Task } from "@/types/proto-es/v1/rollout_service_pb";
+import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
+import { getTaskTypeI18nKey } from "@/utils";
+import { useTaskActions } from "./composables/useTaskActions";
import { useTaskNavigation } from "./composables/useTaskNavigation";
+import { useTaskRunSummary } from "./composables/useTaskRunSummary";
import { useTaskStatement } from "./composables/useTaskStatement";
+import { useTaskTiming } from "./composables/useTaskTiming";
import { getTaskBorderClass } from "./utils/taskStatus";
const props = withDefaults(
@@ -156,9 +293,48 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
-const { taskRuns: allTaskRuns } = usePlanContextWithRollout();
+const {
+ rollout,
+ taskRuns: allTaskRuns,
+ readonly: contextReadonly,
+ events,
+} = usePlanContextWithRollout();
const { navigateToTaskDetail } = useTaskNavigation();
+// Get the stage for the current task
+const stage = computed(() => {
+ for (const s of rollout.value.stages) {
+ if (s.tasks.some((t) => t.name === props.task.name)) {
+ return s;
+ }
+ }
+ return undefined;
+});
+
+// Task actions (Run/Skip/Cancel)
+const {
+ canRun,
+ canSkip,
+ canCancel,
+ hasActions,
+ showActionPanel,
+ currentAction,
+ actionTarget,
+ runTask,
+ skipTask,
+ cancelTask,
+ closeActionPanel,
+} = useTaskActions(
+ () => props.task,
+ () => stage.value,
+ { readonly: () => props.readonly || contextReadonly.value }
+);
+
+// Handle action confirmed - trigger data refresh
+const handleActionConfirm = () => {
+ events.emit("status-changed", { eager: true });
+};
+
const { loading, statementPreview, displayedStatement } = useTaskStatement(
() => props.task,
() => props.isExpanded
@@ -175,6 +351,82 @@ const latestTaskRun = computed(() => {
return last(taskRunsForTask);
});
+const { timingDisplay, timingType } = useTaskTiming(
+ () => props.task,
+ () => latestTaskRun.value
+);
+
+const { totalAffectedRows } = useTaskRunSummary(
+ () => latestTaskRun.value,
+ () => props.isExpanded
+);
+
+const affectedRowsDisplay = computed(() => {
+ const rows = totalAffectedRows.value;
+ if (rows === undefined) return "";
+ return `${rows.toLocaleString()} row${rows === BigInt(1) ? "" : "s"}`;
+});
+
+const taskTypeDisplay = computed(() => {
+ const i18nKey = getTaskTypeI18nKey(props.task);
+ return i18nKey ? t(i18nKey) : "";
+});
+
+const errorPreview = computed(() => {
+ if (props.task.status !== Task_Status.FAILED) return "";
+ const detail = latestTaskRun.value?.detail || "";
+ const firstLine = detail.split("\n")[0];
+ const maxLength = 80;
+ return firstLine.length > maxLength
+ ? firstLine.substring(0, maxLength) + "..."
+ : firstLine;
+});
+
+const executorEmail = computed(() => {
+ const creator = latestTaskRun.value?.creator || "";
+ // Extract email from format: users/[email protected]
+ const match = creator.match(/users\/([^/]+)/);
+ return match?.[1] || "";
+});
+
+const resultSummary = computed(() => {
+ const taskRun = latestTaskRun.value;
+ if (!taskRun) return "";
+
+ // For migrations and SDL, show schema version
+ if (taskRun.schemaVersion) {
+ return t("task.result.schema-version", { version: taskRun.schemaVersion });
+ }
+
+ // For exports, show archive status
+ if (taskRun.exportArchiveStatus) {
+ return t("task.result.export-archive-ready");
+ }
+
+ return "";
+});
+
+const waitingMessage = computed(() => {
+ const taskRun = latestTaskRun.value;
+ if (!taskRun || props.task.status !== Task_Status.PENDING) return "";
+
+ const schedulerInfo = taskRun.schedulerInfo;
+ if (!schedulerInfo?.waitingCause) return "";
+
+ const cause = schedulerInfo.waitingCause.cause;
+ if (cause.case === "connectionLimit") {
+ return t("task.waiting.connection-limit");
+ }
+ if (cause.case === "parallelTasksLimit") {
+ return t("task.waiting.parallel-tasks-limit");
+ }
+ if (cause.case === "task") {
+ return t("task.waiting.blocking-task");
+ }
+
+ return "";
+});
+
const handleNavigateToDetail = () => {
if (props.readonly) {
return;
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/composables/useRollbackableTasks.ts b/frontend/src/components/Plan/components/RolloutView/v2/composables/useRollbackableTasks.ts
new file mode 100644
index 0000000000..32ee99b447
--- /dev/null
+++ b/frontend/src/components/Plan/components/RolloutView/v2/composables/useRollbackableTasks.ts
@@ -0,0 +1,55 @@
+import { computed, type Ref } from "vue";
+import { useCurrentProjectV1 } from "@/store";
+import { taskRunNamePrefix } from "@/store/modules/v1/common";
+import type {
+ Stage,
+ Task,
+ TaskRun,
+} from "@/types/proto-es/v1/rollout_service_pb";
+import { TaskRun_Status } from "@/types/proto-es/v1/rollout_service_pb";
+import { databaseForTask } from "@/utils";
+
+export type RollbackableTaskRun = {
+ task: Task;
+ taskRun: TaskRun;
+ database: ReturnType<typeof databaseForTask>;
+};
+
+export const useRollbackableTasks = (
+ stage: Ref<Stage | null | undefined>,
+ taskRuns: Ref<TaskRun[]>
+) => {
+ const { project } = useCurrentProjectV1();
+
+ const rollbackableTaskRuns = computed<RollbackableTaskRun[]>(() => {
+ if (!stage.value) {
+ return [];
+ }
+
+ const result: RollbackableTaskRun[] = [];
+
+ for (const task of stage.value.tasks) {
+ // Find the latest successful task run with prior backup
+ const rollbackableRun = taskRuns.value.find(
+ (run) =>
+ run.name.startsWith(`${task.name}/${taskRunNamePrefix}`) &&
+ run.status === TaskRun_Status.DONE &&
+ run.priorBackupDetail !== undefined
+ );
+
+ if (rollbackableRun) {
+ result.push({
+ task,
+ taskRun: rollbackableRun,
+ database: databaseForTask(project.value, task),
+ });
+ }
+ }
+
+ return result;
+ });
+
+ return {
+ rollbackableTaskRuns,
+ };
+};
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskActions.ts b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskActions.ts
new file mode 100644
index 0000000000..434786b2f2
--- /dev/null
+++ b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskActions.ts
@@ -0,0 +1,123 @@
+import type { ComputedRef, Ref } from "vue";
+import { computed, ref } from "vue";
+import { canRolloutTasks } from "@/components/Plan/components/RolloutView/taskPermissions";
+import type { Stage, Task } from "@/types/proto-es/v1/rollout_service_pb";
+import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
+
+export type TaskAction = "RUN" | "SKIP" | "CANCEL";
+
+export interface TaskActionTarget {
+ type: "tasks";
+ tasks: Task[];
+ stage: Stage;
+}
+
+export interface UseTaskActionsReturn {
+ // Action availability
+ canRun: ComputedRef<boolean>;
+ canSkip: ComputedRef<boolean>;
+ canCancel: ComputedRef<boolean>;
+ hasActions: ComputedRef<boolean>;
+
+ // Panel state
+ showActionPanel: Ref<boolean>;
+ currentAction: ComputedRef<TaskAction | undefined>;
+ actionTarget: ComputedRef<TaskActionTarget | undefined>;
+
+ // Action handlers
+ runTask: () => void;
+ skipTask: () => void;
+ cancelTask: () => void;
+ closeActionPanel: () => void;
+}
+
+export const useTaskActions = (
+ task: () => Task,
+ stage: () => Stage | undefined,
+ options: {
+ readonly?: () => boolean;
+ } = {}
+): UseTaskActionsReturn => {
+ const showActionPanel = ref(false);
+ const selectedAction = ref<TaskAction>();
+
+ const canPerformActions = computed(() => {
+ if (options.readonly?.()) return false;
+ return canRolloutTasks([task()]);
+ });
+
+ const canRun = computed(() => {
+ if (!canPerformActions.value) return false;
+ return [
+ Task_Status.NOT_STARTED,
+ Task_Status.CANCELED,
+ Task_Status.FAILED,
+ ].includes(task().status);
+ });
+
+ const canSkip = computed(() => {
+ if (!canPerformActions.value) return false;
+ return [
+ Task_Status.NOT_STARTED,
+ Task_Status.FAILED,
+ Task_Status.CANCELED,
+ ].includes(task().status);
+ });
+
+ const canCancel = computed(() => {
+ if (!canPerformActions.value) return false;
+ return [Task_Status.PENDING, Task_Status.RUNNING].includes(task().status);
+ });
+
+ const hasActions = computed(() => {
+ return canRun.value || canSkip.value || canCancel.value;
+ });
+
+ const currentAction = computed((): TaskAction | undefined => {
+ if (!showActionPanel.value || !selectedAction.value) return undefined;
+ return selectedAction.value;
+ });
+
+ const actionTarget = computed((): TaskActionTarget | undefined => {
+ const s = stage();
+ if (!currentAction.value || !s) return undefined;
+ return {
+ type: "tasks",
+ tasks: [task()],
+ stage: s,
+ };
+ });
+
+ const runTask = () => {
+ selectedAction.value = "RUN";
+ showActionPanel.value = true;
+ };
+
+ const skipTask = () => {
+ selectedAction.value = "SKIP";
+ showActionPanel.value = true;
+ };
+
+ const cancelTask = () => {
+ selectedAction.value = "CANCEL";
+ showActionPanel.value = true;
+ };
+
+ const closeActionPanel = () => {
+ showActionPanel.value = false;
+ };
+
+ return {
+ canRun,
+ canSkip,
+ canCancel,
+ hasActions,
+ showActionPanel,
+ currentAction,
+ actionTarget,
+ runTask,
+ skipTask,
+ cancelTask,
+ closeActionPanel,
+ };
+};
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunSummary.ts b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunSummary.ts
new file mode 100644
index 0000000000..12a6fde49b
--- /dev/null
+++ b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskRunSummary.ts
@@ -0,0 +1,65 @@
+import type { ComputedRef } from "vue";
+import { computed, ref, watch } from "vue";
+import { useTaskRunLogStore } from "@/store/modules/v1/taskRunLog";
+import type { TaskRun } from "@/types/proto-es/v1/rollout_service_pb";
+import { TaskRunLogEntry_Type } from "@/types/proto-es/v1/rollout_service_pb";
+
+export interface UseTaskRunSummaryReturn {
+ totalAffectedRows: ComputedRef<bigint | undefined>;
+ isLoadingLog: ComputedRef<boolean>;
+}
+
+export const useTaskRunSummary = (
+ latestTaskRun: () => TaskRun | undefined,
+ isExpanded: () => boolean
+): UseTaskRunSummaryReturn => {
+ const taskRunLogStore = useTaskRunLogStore();
+ const isLoadingLog = ref(false);
+
+ // Fetch log when expanded and has task run
+ watch(
+ [() => latestTaskRun()?.name, isExpanded],
+ async ([taskRunName, expanded]) => {
+ if (expanded && taskRunName) {
+ isLoadingLog.value = true;
+ try {
+ await taskRunLogStore.fetchTaskRunLog(taskRunName);
+ } finally {
+ isLoadingLog.value = false;
+ }
+ }
+ },
+ { immediate: true }
+ );
+
+ const taskRunLog = computed(() => {
+ const taskRun = latestTaskRun();
+ if (!taskRun?.name) return undefined;
+ return taskRunLogStore.getTaskRunLog(taskRun.name);
+ });
+
+ const totalAffectedRows = computed((): bigint | undefined => {
+ const log = taskRunLog.value;
+ if (!log?.entries?.length) return undefined;
+
+ let total = BigInt(0);
+ let hasAffectedRows = false;
+
+ for (const entry of log.entries) {
+ if (entry.type === TaskRunLogEntry_Type.COMMAND_EXECUTE) {
+ const response = entry.commandExecute?.response;
+ if (response?.affectedRows !== undefined) {
+ total += response.affectedRows;
+ hasAffectedRows = true;
+ }
+ }
+ }
+
+ return hasAffectedRows ? total : undefined;
+ });
+
+ return {
+ totalAffectedRows,
+ isLoadingLog: computed(() => isLoadingLog.value),
+ };
+};
diff --git a/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskTiming.ts b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskTiming.ts
new file mode 100644
index 0000000000..e089f605f8
--- /dev/null
+++ b/frontend/src/components/Plan/components/RolloutView/v2/composables/useTaskTiming.ts
@@ -0,0 +1,115 @@
+import type { ComputedRef } from "vue";
+import { computed } from "vue";
+import type { Task, TaskRun } from "@/types/proto-es/v1/rollout_service_pb";
+import { Task_Status } from "@/types/proto-es/v1/rollout_service_pb";
+
+export type TimingType = "scheduled" | "running" | "completed" | "none";
+
+export interface UseTaskTimingReturn {
+ timingDisplay: ComputedRef<string>;
+ timingType: ComputedRef<TimingType>;
+ duration: ComputedRef<number | undefined>;
+ scheduledTime: ComputedRef<Date | undefined>;
+}
+
+export const useTaskTiming = (
+ task: () => Task,
+ latestTaskRun: () => TaskRun | undefined
+): UseTaskTimingReturn => {
+ const duration = computed(() => {
+ const taskRun = latestTaskRun();
+ if (!taskRun) return undefined;
+
+ const startTime = taskRun.startTime;
+ const updateTime = taskRun.updateTime;
+
+ if (!startTime || !updateTime) {
+ return undefined;
+ }
+
+ const startMs = Number(startTime.seconds) * 1000;
+ const updateMs = Number(updateTime.seconds) * 1000;
+ return updateMs - startMs;
+ });
+
+ const scheduledTime = computed(() => {
+ const currentTask = task();
+ if (currentTask.status === Task_Status.PENDING && currentTask.runTime) {
+ const runTimeMs = Number(currentTask.runTime.seconds) * 1000;
+ if (runTimeMs > Date.now()) {
+ return new Date(runTimeMs);
+ }
+ }
+ return undefined;
+ });
+
+ const timingType = computed((): TimingType => {
+ const currentTask = task();
+ const status = currentTask.status;
+
+ if (scheduledTime.value) {
+ return "scheduled";
+ }
+
+ if (status === Task_Status.RUNNING) {
+ return "running";
+ }
+
+ if (
+ (status === Task_Status.DONE ||
+ status === Task_Status.FAILED ||
+ status === Task_Status.CANCELED) &&
+ duration.value !== undefined
+ ) {
+ return "completed";
+ }
+
+ return "none";
+ });
+
+ const timingDisplay = computed(() => {
+ const type = timingType.value;
+
+ if (type === "completed" && duration.value !== undefined) {
+ return formatDuration(duration.value);
+ }
+
+ if (type === "running" && duration.value !== undefined) {
+ return formatDuration(duration.value);
+ }
+
+ if (type === "scheduled" && scheduledTime.value) {
+ return scheduledTime.value.toLocaleTimeString([], {
+ hour: "2-digit",
+ minute: "2-digit",
+ });
+ }
+
+ return "";
+ });
+
+ return {
+ timingDisplay,
+ timingType,
+ duration,
+ scheduledTime,
+ };
+};
+
+const formatDuration = (durationMs: number): string => {
+ const seconds = Math.floor(durationMs / 1000);
+ const minutes = Math.floor(seconds / 60);
+ const hours = Math.floor(minutes / 60);
+
+ if (hours > 0) {
+ const remainingMinutes = minutes % 60;
+ return `${hours}h ${remainingMinutes}m`;
+ }
+
+ if (minutes > 0) {
+ const remainingSeconds = seconds % 60;
+ return `${minutes}m ${remainingSeconds}s`;
+ }
+
+ return `${seconds}s`;
+};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 49194c9deb..ad688709f8 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -339,6 +339,17 @@
"database-create": {
"created": "Created",
"pending": "Pending"
+ },
+ "executed-by": "Executed by",
+ "affected-rows": "Affected rows",
+ "result": {
+ "schema-version": "Schema: {version}",
+ "export-archive-ready": "Archive: Ready for download"
+ },
+ "waiting": {
+ "connection-limit": "Waiting for available connections",
+ "parallel-tasks-limit": "Waiting for other tasks to complete",
+ "blocking-task": "Waiting for another task"
}
},
"task-run": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 9e378de84a..234106068b 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -339,6 +339,17 @@
"database-create": {
"created": "Creado",
"pending": "Pendiente"
+ },
+ "executed-by": "Ejecutado por",
+ "affected-rows": "Filas afectadas",
+ "result": {
+ "schema-version": "Esquema: {version}",
+ "export-archive-ready": "Archivo: Listo para descargar"
+ },
+ "waiting": {
+ "connection-limit": "Esperando conexiones disponibles",
+ "parallel-tasks-limit": "Esperando a que se completen otras tareas",
+ "blocking-task": "Esperando otra tarea"
}
},
"task-run": {
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 0b5706d762..66ee205272 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -339,6 +339,17 @@
"database-create": {
"created": "作成済み",
"pending": "保留中"
+ },
+ "executed-by": "実行者",
+ "affected-rows": "影響を受けた行数",
+ "result": {
+ "schema-version": "スキーマ: {version}",
+ "export-archive-ready": "アーカイブ: ダウンロード可能"
+ },
+ "waiting": {
+ "connection-limit": "利用可能な接続を待機しています",
+ "parallel-tasks-limit": "他のタスクが完了するのを待っています",
+ "blocking-task": "別のタスクを待っています"
}
},
"task-run": {
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index d675331719..2e32a535ed 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -339,6 +339,17 @@
"database-create": {
"created": "Đã tạo",
"pending": "Đang chờ xử lý"
+ },
+ "executed-by": "Được thực hiện bởi",
+ "affected-rows": "Hàng bị ảnh hưởng",
+ "result": {
+ "schema-version": "Sơ đồ: {version}",
+ "export-archive-ready": "Lưu trữ: Sẵn sàng để tải xuống"
+ },
+ "waiting": {
+ "connection-limit": "Đang chờ kết nối khả dụng",
+ "parallel-tasks-limit": "Đang chờ các tác vụ khác hoàn thành",
+ "blocking-task": "Đang chờ nhiệm vụ khác"
}
},
"task-run": {
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 3f0a515c08..b306ed7d5d 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -339,6 +339,17 @@
"database-create": {
"created": "已创建",
"pending": "待创建"
+ },
+ "executed-by": "执行者",
+ "affected-rows": "影响行数",
+ "result": {
+ "schema-version": "版本: {version}",
+ "export-archive-ready": "归档: 可下载"
+ },
+ "waiting": {
+ "connection-limit": "等待可用连接",
+ "parallel-tasks-limit": "等待其他任务完成",
+ "blocking-task": "等待另一个任务"
}
},
"task-run": {
diff --git a/frontend/src/utils/v1/issue/rollout.ts b/frontend/src/utils/v1/issue/rollout.ts
index 42154f8674..858d5faf20 100644
--- a/frontend/src/utils/v1/issue/rollout.ts
+++ b/frontend/src/utils/v1/issue/rollout.ts
@@ -14,6 +14,7 @@ import {
unknownStage,
unknownTask,
} from "@/types";
+import { MigrationType } from "@/types/proto-es/v1/common_pb";
import type { Project } from "@/types/proto-es/v1/project_service_pb";
import {
type Rollout,
@@ -218,6 +219,37 @@ export const stringifyTaskStatus = (
}
};
+export const getTaskTypeI18nKey = (task: Task): string => {
+ switch (task.type) {
+ case Task_Type.DATABASE_CREATE:
+ return "task.type.database-create";
+ case Task_Type.DATABASE_MIGRATE:
+ // For migrate tasks, check the migration type from payload
+ if (task.payload?.case === "databaseUpdate") {
+ const migrationType = task.payload.value.migrationType;
+ switch (migrationType) {
+ case MigrationType.DDL:
+ return "release.change-type.ddl";
+ case MigrationType.DML:
+ return "release.change-type.dml";
+ case MigrationType.GHOST:
+ return "release.change-type.ddl-ghost";
+ default:
+ return "task.type.database-migrate";
+ }
+ }
+ return "task.type.database-migrate";
+ case Task_Type.DATABASE_SDL:
+ return "task.type.database-sdl";
+ case Task_Type.DATABASE_EXPORT:
+ return "task.type.database-export";
+ case Task_Type.GENERAL:
+ return "task.type.general";
+ default:
+ return "";
+ }
+};
+
export const getStageStatus = (stage: Stage): Task_Status => {
const tasks = stage.tasks;
if (tasks.length === 0) return Task_Status.NOT_STARTED;