Skip to content

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

feat(frontend): batch skip failed tasks in current stage (#5352)

Liu Ji87489c5d47f3
diff --git a/frontend/src/components/Issue/BatchTaskActionForm.vue b/frontend/src/components/Issue/BatchTaskActionForm.vue
new file mode 100644
index 0000000000..35ec7ae2eb
--- /dev/null
+++ b/frontend/src/components/Issue/BatchTaskActionForm.vue
@@ -0,0 +1,230 @@
+<template>
+ <div class="px-4 flex flex-col gap-y-6 divide-y divide-block-border">
+ <div class="mt-2 grid grid-cols-1 gap-x-4 sm:grid-cols-4">
+ <div class="sm:col-span-4 mb-4">
+ <label for="about" class="textlabel">
+ {{ $t("common.tasks") }}
+ </label>
+ <ul class="mt-1 max-h-[6rem] overflow-y-auto">
+ <li
+ v-for="item in distinctTaskList"
+ :key="item.task.id"
+ class="text-sm textinfolabel"
+ >
+ <span class="textinfolabel">
+ {{ item.task.name }}
+ </span>
+ <span v-if="item.similar.length > 0" class="ml-2 text-gray-400">
+ {{
+ $t("task.n-similar-tasks", {
+ count: item.similar.length + 1,
+ })
+ }}
+ </span>
+ </li>
+ </ul>
+ </div>
+
+ <div class="sm:col-span-4 w-112 min-w-full">
+ <label for="about" class="textlabel">
+ {{ $t("issue.status-transition.form.note") }}
+ </label>
+ <div class="mt-1">
+ <textarea
+ ref="commentTextArea"
+ v-model="state.comment"
+ rows="3"
+ class="textarea block w-full resize-none mt-1 text-sm text-control rounded-md whitespace-pre-wrap"
+ :placeholder="$t('issue.status-transition.form.placeholder')"
+ @input="
+ (e) => {
+ sizeToFit(e.target as HTMLTextAreaElement);
+ }
+ "
+ @focus="
+ (e) => {
+ sizeToFit(e.target as HTMLTextAreaElement);
+ }
+ "
+ ></textarea>
+ </div>
+ </div>
+ </div>
+
+ <!-- Update button group -->
+ <div class="flex justify-end items-center pt-5">
+ <button
+ type="button"
+ class="btn-normal mt-3 px-4 py-2 sm:mt-0 sm:w-auto"
+ @click.prevent="$emit('cancel')"
+ >
+ {{ cancelText }}
+ </button>
+ <button
+ type="button"
+ class="ml-3 px-4 py-2"
+ :class="submitButtonStyle"
+ @click.prevent="handleSubmit"
+ >
+ {{ displayingOkText }}
+ </button>
+ </div>
+
+ <div
+ v-if="state.loading"
+ class="absolute inset-0 flex flex-col items-center justify-center bg-white/50 gap-y-1"
+ >
+ <BBSpin />
+ <div
+ class="flex items-center justify-center space-x-1 text-sm text-control"
+ >
+ <span>{{ progress.finished }}</span>
+ <span>/</span>
+ <span>{{ progress.total }}</span>
+ </div>
+ </div>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed, reactive, ref } from "vue";
+import { groupBy } from "lodash-es";
+import { Issue, Task, TaskStatusPatch } from "@/types";
+import { TaskStatusTransition } from "@/utils";
+import { useI18n } from "vue-i18n";
+import { useIssueLogic } from "./logic";
+import { pushNotification, useTaskStore } from "@/store";
+
+interface LocalState {
+ success: Set<Task>;
+ failed: Set<Task>;
+ comment: string;
+ loading: boolean;
+}
+const props = withDefaults(
+ defineProps<{
+ issue: Issue;
+ okText?: string;
+ taskList: Task[];
+ transition: TaskStatusTransition;
+ title: string;
+ }>(),
+ {
+ okText: "",
+ loading: false,
+ }
+);
+
+const emit = defineEmits<{
+ (event: "cancel"): void;
+ (event: "finish"): void;
+}>();
+
+const { t } = useI18n();
+const commentTextArea = ref("");
+const taskStore = useTaskStore();
+const { onStatusChanged } = useIssueLogic();
+
+const state = reactive<LocalState>({
+ success: new Set(),
+ failed: new Set(),
+ comment: "",
+ loading: false,
+});
+
+const progress = computed(() => {
+ const finished = state.success.size + state.failed.size;
+ const total = props.taskList.length;
+ return { finished, total };
+});
+
+const cancelText = computed(() => t("common.cancel"));
+const displayingOkText = computed(() => {
+ if (props.okText === cancelText.value) {
+ // We don't want to see [Cancel] [Cancel]
+ // So fall back to [Cancel] [Confirm] if okText===cancelText
+ return t("common.confirm");
+ }
+ return props.okText;
+});
+
+const submitButtonStyle = computed(() => {
+ switch (props.transition.type) {
+ case "RUN":
+ return "btn-primary";
+ case "ROLLOUT":
+ return "btn-primary";
+ case "RETRY":
+ return "btn-primary";
+ case "CANCEL":
+ return "btn-danger";
+ case "SKIP":
+ return "btn-primary";
+ case "RESTART":
+ return "btn-normal";
+ }
+ return ""; // only to make eslint happy
+});
+
+const distinctTaskList = computed(() => {
+ type DistinctTaskList = { task: Task; similar: Task[] };
+ const groups = groupBy(props.taskList, (task) => task.name);
+
+ return Object.keys(groups).map<DistinctTaskList>((taskName) => {
+ const [task, ...similar] = groups[taskName];
+ return { task, similar };
+ });
+});
+
+const patchTaskStatus = async (task: Task) => {
+ const status = props.transition.to;
+ const comment = state.comment;
+
+ const taskStatusPatch: TaskStatusPatch = {
+ status,
+ comment,
+ };
+ try {
+ const { issue } = props;
+ await taskStore.updateStatus({
+ issueId: issue.id,
+ pipelineId: issue.pipeline.id,
+ taskId: task.id,
+ taskStatusPatch,
+ });
+ state.success.add(task);
+ } catch {
+ state.failed.add(task);
+ }
+};
+
+const handleSubmit = async () => {
+ state.loading = true;
+ state.success.clear();
+ state.failed.clear();
+ try {
+ const requests = props.taskList.map(patchTaskStatus);
+ await Promise.allSettled(requests);
+ const parts = [`${t("common.total")}: ${props.taskList.length}`];
+ const successCount = state.success.size;
+ const failedCount = state.failed.size;
+ if (successCount > 0) {
+ parts.push(`${t("common.success")}: ${successCount}`);
+ }
+ if (failedCount > 0) {
+ parts.push(`${t("common.failed")}: ${failedCount}`);
+ }
+ pushNotification({
+ module: "bytebase",
+ style:
+ failedCount > 0 ? (successCount > 0 ? "WARN" : "CRITICAL") : "SUCCESS",
+ title: props.title,
+ description: parts.join(", "),
+ });
+ emit("finish");
+ } finally {
+ onStatusChanged(true);
+ state.loading = false;
+ }
+};
+</script>
diff --git a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
index b321182288..cec1f4690b 100644
--- a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
+++ b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
@@ -27,16 +27,17 @@
@click="(action) => onClickTaskStatusTransitionActionButton(action as TaskStatusTransitionButtonAction)"
/>
</template>
- <template v-if="applicableIssueStatusTransitionList.length > 0">
+ <template v-if="mergedDropdownActionList.length > 0">
<NDropdown
trigger="click"
- :options="issueStatusTransitionDropdownOptions"
- @select="handleIssueStatusTransitionDropdownSelect"
+ placement="bottom-end"
+ :options="mergedDropdownActionList"
+ @select="handleDropdownSelect"
>
<button
id="user-menu"
type="button"
- class="text-control-light"
+ class="text-control-light p-0.5 rounded hover:bg-control-bg-hover"
aria-label="User menu"
aria-haspopup="true"
>
@@ -63,6 +64,25 @@
{{ $t(transition.buttonName) }}
</button>
</template>
+
+ <template v-if="extraActionList.length > 0">
+ <NDropdown
+ trigger="click"
+ placement="bottom-end"
+ :options="extraActionList"
+ @select="handleDropdownSelect"
+ >
+ <button
+ id="user-menu"
+ type="button"
+ class="text-control-light p-0.5 rounded hover:bg-control-bg-hover"
+ aria-label="User menu"
+ aria-haspopup="true"
+ >
+ <heroicons-solid:dots-vertical class="w-6 h-6" />
+ </button>
+ </NDropdown>
+ </template>
</div>
</template>
</template>
@@ -93,15 +113,34 @@
"
/>
</BBModal>
+
+ <BBModal
+ v-if="batchTaskActionState"
+ :title="batchTaskActionState.title"
+ class="relative overflow-hidden"
+ @close="batchTaskActionState = undefined"
+ >
+ <BatchTaskActionForm
+ :issue="(issue as Issue)"
+ :transition="batchTaskActionState.transition"
+ :task-list="batchTaskActionState.taskList"
+ :ok-text="batchTaskActionState.transition.buttonName"
+ :title="batchTaskActionState.title"
+ @cancel="batchTaskActionState = undefined"
+ @finish="batchTaskActionState = undefined"
+ />
+ </BBModal>
</template>
<script lang="ts" setup>
-import { computed, reactive, Ref } from "vue";
+import { computed, reactive, ref, Ref } from "vue";
import { isEmpty } from "lodash-es";
import { useI18n } from "vue-i18n";
import { DropdownOption, NDropdown } from "naive-ui";
import {
+ activeStage,
+ canSkipTask,
StageStatusTransition,
taskCheckRunSummary,
TaskStatusTransition,
@@ -130,6 +169,7 @@ import {
import BBContextMenuButton, {
type ButtonAction,
} from "@/bbkit/BBContextMenuButton.vue";
+import BatchTaskActionForm from "./BatchTaskActionForm.vue";
export type IssueContext = {
currentUser: Principal;
@@ -151,15 +191,33 @@ interface UpdateStatusModalState {
isTransiting: boolean;
}
+type BatchTaskActionState = {
+ taskList: Task[];
+ transition: TaskStatusTransition;
+ title: string;
+ okText: string;
+};
+
type TaskStatusTransitionButtonAction = ButtonAction<{
transition: TaskStatusTransition;
target: "TASK" | "STAGE";
}>;
-type IssueStatusTransitionDropdownOption = DropdownOption & {
- transition: IssueStatusTransition;
+type ExtraAction<T extends "ISSUE" | "TASK" | "TASK-BATCH"> = {
+ type: T;
+ transition: T extends "ISSUE" ? IssueStatusTransition : TaskStatusTransition;
+ target: T extends "ISSUE"
+ ? Issue
+ : T extends "TASK"
+ ? Task
+ : T extends "TASK-BATCH"
+ ? Task[]
+ : unknown;
};
+type ExtraActionOption = DropdownOption &
+ ExtraAction<"ISSUE" | "TASK" | "TASK-BATCH">;
+
const { t } = useI18n();
const {
@@ -182,6 +240,8 @@ const updateStatusModalState = reactive<UpdateStatusModalState>({
isTransiting: false,
});
+const batchTaskActionState = ref<BatchTaskActionState>();
+
const currentUser = useCurrentUser();
const issueContext = computed((): IssueContext => {
@@ -202,18 +262,100 @@ const {
} = useIssueTransitionLogic(issue as Ref<Issue>);
const issueStatusTransitionDropdownOptions = computed(() => {
- return applicableIssueStatusTransitionList.value.map<IssueStatusTransitionDropdownOption>(
+ return applicableIssueStatusTransitionList.value.map<ExtraActionOption>(
(transition) => {
- return { label: t(transition.buttonName), transition };
+ return {
+ key: transition.type,
+ label: t(transition.buttonName),
+ type: "ISSUE",
+ transition,
+ target: issue.value as Issue,
+ };
}
);
});
-const handleIssueStatusTransitionDropdownSelect = (
- key: string,
- option: IssueStatusTransitionDropdownOption
+const skippableTaskList = computed(() => {
+ if (create.value) return [];
+
+ const issueEntity = issue.value as Issue;
+ if (issueEntity.status !== "OPEN") {
+ return [];
+ }
+
+ const currentStage = activeStage(issueEntity.pipeline);
+ return currentStage.taskList.filter((task) =>
+ canSkipTask(
+ task,
+ issueEntity,
+ false /* !activeOnly */,
+ true /* failedOnly */
+ )
+ );
+});
+
+const extraActionList = computed(() => {
+ const list: ExtraActionOption[] = [];
+
+ if (skippableTaskList.value.length > 0) {
+ list.push({
+ label: t("task.skip-failed-in-current-stage"),
+ key: "skip-failed-tasks-in-current-stage",
+ type: "TASK-BATCH",
+ transition: {
+ buttonType: "PRIMARY",
+ buttonName: t("task.skip"),
+ type: "SKIP",
+ to: "DONE",
+ },
+ target: skippableTaskList.value,
+ });
+ }
+
+ return list;
+});
+
+const mergedDropdownActionList = computed(() => {
+ if (applicableTaskStatusTransitionList.value.length > 0) {
+ // When there are something to do with tasks, they will be shown as big
+ // buttons.
+ // Now we display issue-level actions as a dropdown together with "extra"
+ // actions.
+ return [
+ ...issueStatusTransitionDropdownOptions.value,
+ ...extraActionList.value,
+ ];
+ } else {
+ // When we have nothing to do with tasks, show issue-level actions as big
+ // buttons. And show only "extra" actions as a dropdown.
+ return [...extraActionList.value];
+ }
+});
+
+const handleDropdownSelect = (key: string, option: ExtraActionOption) => {
+ if (option.type === "ISSUE") {
+ tryStartIssueStatusTransition(option.transition as IssueStatusTransition);
+ }
+ if (option.type === "TASK-BATCH") {
+ tryStartBatchTaskTransition(
+ option.transition as TaskStatusTransition,
+ option.target as Task[]
+ );
+ }
+};
+
+const tryStartBatchTaskTransition = (
+ transition: TaskStatusTransition,
+ taskList: Task[]
) => {
- tryStartIssueStatusTransition(option.transition);
+ if (transition.type === "SKIP") {
+ batchTaskActionState.value = {
+ okText: transition.buttonName,
+ title: t("task.skip-failed-in-current-stage"),
+ transition,
+ taskList,
+ };
+ }
};
const tryStartStageOrTaskStatusTransition = (
diff --git a/frontend/src/components/Issue/TaskExtraActionsButton.vue b/frontend/src/components/Issue/TaskExtraActionsButton.vue
index c14a5b9147..574006ffb4 100644
--- a/frontend/src/components/Issue/TaskExtraActionsButton.vue
+++ b/frontend/src/components/Issue/TaskExtraActionsButton.vue
@@ -24,12 +24,6 @@
class="relative overflow-hidden"
@close="state.showModal = false"
>
- <div
- v-if="state.isLoading"
- class="absolute inset-0 flex items-center justify-center bg-white/50"
- >
- <BBSpin />
- </div>
<StatusTransitionForm
mode="TASK"
:ok-text="confirmButtonText"
@@ -48,14 +42,9 @@ import { computed, PropType, reactive } from "vue";
import { useI18n } from "vue-i18n";
import { DropdownOption, NDropdown } from "naive-ui";
-import type { Issue, Task, TaskStatus } from "@/types";
-import { useCurrentUser } from "@/store";
+import type { Issue, Task } from "@/types";
import { useExtraIssueLogic, useIssueLogic } from "./logic";
-import {
- activeTask,
- hasWorkspacePermission,
- TaskStatusTransition,
-} from "@/utils";
+import { canSkipTask, TaskStatusTransition } from "@/utils";
import StatusTransitionForm from "./StatusTransitionForm.vue";
type LocalState = {
@@ -76,7 +65,6 @@ const state = reactive<LocalState>({
});
const { t } = useI18n();
-const currentUser = useCurrentUser();
const { create, issue } = useIssueLogic();
const { changeTaskStatus } = useExtraIssueLogic();
@@ -86,34 +74,12 @@ const allowSkipTask = computed(() => {
return false;
}
- const { task } = props;
-
- const pipeline = (issue.value as Issue).pipeline;
- const isActiveTask = task.id === activeTask(pipeline).id;
- if (!isActiveTask) {
- return false;
- }
-
- const applicableStatusList: TaskStatus[] = ["PENDING_APPROVAL", "FAILED"];
-
- if (!applicableStatusList.includes(task.status)) {
- return false;
- }
-
- if (
- hasWorkspacePermission(
- "bb.permission.workspace.manage-issue",
- currentUser.value.role
- )
- ) {
- return true;
- }
-
- if (currentUser.value.id === (issue.value as Issue).assignee.id) {
- return true;
- }
-
- return false;
+ return canSkipTask(
+ props.task,
+ issue.value as Issue,
+ true /* activeOnly */,
+ false /* !failedOnly */
+ );
});
const options = computed(() => {
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index b75c94c1c6..02f68a7731 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -208,6 +208,7 @@
"sync-now": "Sync Now",
"show-help": "Show help",
"success": "Succeed",
+ "failed": "Failed",
"load-more": "Load more",
"access-denied": "Access denied",
"no": "No",
@@ -321,7 +322,8 @@
"empty-rollback-statement": "The rollback statement is empty",
"cancel-generating": "Cancel generating the SQL rollback",
"sql-rollback-tips": "When enabled, Bytebase will keep the rollback logs for the data change\nand allow you to create a new issue to revert this change. {link}"
- }
+ },
+ "skip-failed-in-current-stage": "Skip failed tasks in current stage"
},
"banner": {
"update-license": "Update license",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 9b0b427ee4..83a4b106c2 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -208,6 +208,7 @@
"sync-now": "现在同步",
"show-help": "查看帮助",
"success": "成功",
+ "failed": "失败",
"load-more": "加载更多",
"access-denied": "拒绝访问",
"no": "否",
@@ -319,7 +320,8 @@
"empty-rollback-statement": "回滚语句为空",
"cancel-generating": "取消生成回滚语句",
"sql-rollback-tips": "开启时,Bytebase 会保留数据变更的回滚日志,\n可以用于创建一个新的工单来回滚这次变更。{link}"
- }
+ },
+ "skip-failed-in-current-stage": "跳过当前阶段失败的任务"
},
"banner": {
"update-license": "更新证书",
diff --git a/frontend/src/utils/task.ts b/frontend/src/utils/task.ts
index 64a82016d1..abf09874e8 100644
--- a/frontend/src/utils/task.ts
+++ b/frontend/src/utils/task.ts
@@ -1,6 +1,6 @@
import { groupBy, maxBy } from "lodash-es";
-import { useDatabaseStore } from "@/store";
+import { useCurrentUser, useDatabaseStore } from "@/store";
import {
Issue,
Task,
@@ -13,10 +13,13 @@ import {
TaskDatabaseSchemaUpdateGhostSyncPayload,
TaskDatabaseSchemaUpdatePayload,
TaskDatabaseSchemaUpdateSDLPayload,
+ TaskStatus,
TaskType,
unknown,
} from "@/types";
import { issueSlug, stageSlug, taskSlug } from "./slug";
+import { activeTask } from "./pipeline";
+import { hasWorkspacePermission } from "./role";
export const extractDatabaseNameFromTask = (
task: Task | TaskCreate
@@ -196,3 +199,48 @@ export const isTaskEntity = (task: Task | TaskCreate): task is Task => {
export const isTaskCreate = (task: Task | TaskCreate): task is TaskCreate => {
return !isTaskEntity(task);
};
+
+/**
+ *
+ * @param task
+ * @param issue
+ * @param activeOnly if true, only "Active Task" can be skipped
+ * @returns
+ */
+export const canSkipTask = (
+ task: Task,
+ issue: Issue,
+ activeOnly = false,
+ failedOnly = false
+) => {
+ const pipeline = issue.pipeline;
+ const isActiveTask = task.id === activeTask(pipeline).id;
+ if (activeOnly && !isActiveTask) {
+ return false;
+ }
+
+ const applicableStatusList: TaskStatus[] = failedOnly
+ ? ["FAILED"]
+ : ["PENDING_APPROVAL", "FAILED"];
+
+ if (!applicableStatusList.includes(task.status)) {
+ return false;
+ }
+
+ const currentUser = useCurrentUser();
+
+ if (
+ hasWorkspacePermission(
+ "bb.permission.workspace.manage-issue",
+ currentUser.value.role
+ )
+ ) {
+ return true;
+ }
+
+ if (currentUser.value.id === issue.assignee.id) {
+ return true;
+ }
+
+ return false;
+};