Skip to content

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

feat(frontend): support run task checks in batch mode (#5788)

Liu Jic797253df54f
diff --git a/frontend/src/components/Issue/IssueActivityPanel.vue b/frontend/src/components/Issue/IssueActivityPanel.vue
index 52c17909eb..7d43df5399 100644
--- a/frontend/src/components/Issue/IssueActivityPanel.vue
+++ b/frontend/src/components/Issue/IssueActivityPanel.vue
@@ -159,7 +159,6 @@ import type {
ActivityIssueFieldUpdatePayload,
ActivityCreate,
IssueSubscriber,
- Task,
ActivityIssueCommentCreatePayload,
} from "@/types";
import { sizeToFit } from "@/utils";
@@ -182,9 +181,6 @@ interface LocalState {
editCommentMode: boolean;
activeActivity?: Activity;
}
-const emit = defineEmits<{
- (event: "run-checks", task: Task): void;
-}>();
const activityStore = useActivityStore();
const route = useRoute();
@@ -298,10 +294,6 @@ const doCreateComment = (comment: string, clear = true) => {
if (!isSubscribed) {
addSubscriberId(currentUser.value.id);
}
-
- if (comment === "LGTM") {
- emit("run-checks", logic.selectedTask.value as Task);
- }
});
};
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index 82a976320f..5080abc028 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -83,7 +83,7 @@
aria-labelledby="activity-title"
class="mt-4"
>
- <IssueActivityPanel @run-checks="runTaskChecks" />
+ <IssueActivityPanel />
</section>
</div>
</div>
@@ -206,16 +206,17 @@ const issueTemplate = computed(
() => templateForType(props.issue.type) || defaultTemplate()
);
-const runTaskChecks = (task: Task) => {
- taskStore
- .runChecks({
+const runTaskChecks = (taskList: Task[]) => {
+ const requests = taskList.map((task) => {
+ return taskStore.runChecks({
issueId: (props.issue as Issue).id,
pipelineId: (props.issue as Issue).pipeline.id,
taskId: task.id,
- })
- .then(() => {
- emit("status-changed", true);
});
+ });
+ Promise.allSettled(requests).then(() => {
+ emit("status-changed", true);
+ });
};
const currentPipelineType = computed((): PipelineType => {
diff --git a/frontend/src/components/Issue/RunTaskCheckButton.vue b/frontend/src/components/Issue/RunTaskCheckButton.vue
new file mode 100644
index 0000000000..4ec4676b06
--- /dev/null
+++ b/frontend/src/components/Issue/RunTaskCheckButton.vue
@@ -0,0 +1,106 @@
+<template>
+ <ContextMenuButton
+ v-if="actionList.length > 0"
+ :action-list="actionList"
+ :disabled="hasRunningTaskCheck"
+ preference-key="issue.task.run-checks"
+ default-action-key="RUN-CHECKS"
+ @click="$emit('run-checks', ($event as ButtonAction).params.taskList)"
+ >
+ <template #icon>
+ <BBSpin v-if="hasRunningTaskCheck" class="w-4 h-4" />
+ <heroicons-outline:play v-else class="w-4 h-4" />
+ </template>
+ <template #default="{ action }">
+ <template v-if="hasRunningTaskCheck">
+ {{ $t("task.checking") }}
+ </template>
+ <template v-else>
+ {{ action.text }}
+ </template>
+ </template>
+ </ContextMenuButton>
+</template>
+
+<script setup lang="ts">
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+
+import { useIssueLogic } from "./logic";
+import { ContextMenuButton, ContextMenuButtonAction } from "../v2";
+import { Issue, Task } from "@/types";
+
+type ButtonAction = ContextMenuButtonAction<{
+ taskList: Task[];
+}>;
+
+defineEmits<{
+ (event: "run-checks", taskList: Task[]): void;
+}>();
+
+const { t } = useI18n();
+const context = useIssueLogic();
+
+const allowRunCheckForIssue = computed(() => {
+ if (context.create.value) {
+ return false;
+ }
+ const issue = context.issue.value as Issue;
+ if (issue.status !== "OPEN") {
+ return false;
+ }
+ return true;
+});
+
+const actionList = computed(() => {
+ if (!allowRunCheckForIssue.value) return [];
+
+ const actionList: ButtonAction[] = [];
+ const selectedTask = context.selectedTask.value as Task;
+ if (allowRunChecksForTask(selectedTask)) {
+ actionList.push({
+ key: "RUN-CHECKS",
+ text: t("task.run-checks"),
+ params: {
+ taskList: [selectedTask],
+ },
+ });
+
+ // Don't only show 'run checks in current stage' if we don't show 'run checks'
+ // since that might be weird.
+ const taskListInStage = context.selectedStage.value.taskList as Task[];
+ const runnableTaskList = taskListInStage.filter((task) =>
+ allowRunChecksForTask(task)
+ );
+ if (runnableTaskList.length > 1) {
+ actionList.push({
+ key: "RUN-CHECKS-IN-CURRENT-STAGE",
+ text: t("task.run-checks-in-current-stage"),
+ params: {
+ taskList: runnableTaskList,
+ },
+ });
+ }
+ }
+ return actionList;
+});
+
+const hasRunningTaskCheck = computed((): boolean => {
+ if (context.create.value) return false;
+
+ const selectedTask = context.selectedTask.value as Task;
+
+ return selectedTask.taskCheckRunList.some(
+ (checkRun) => checkRun.status === "RUNNING"
+ );
+});
+
+const allowRunChecksForTask = (task: Task) => {
+ return (
+ task.status == "PENDING" ||
+ task.status == "PENDING_APPROVAL" ||
+ task.status == "RUNNING" ||
+ task.status == "FAILED"
+ );
+};
+</script>
diff --git a/frontend/src/components/Issue/TaskCheckBar.vue b/frontend/src/components/Issue/TaskCheckBar.vue
index b05fe1165b..7b0220b8da 100644
--- a/frontend/src/components/Issue/TaskCheckBar.vue
+++ b/frontend/src/components/Issue/TaskCheckBar.vue
@@ -12,22 +12,7 @@
@select-task-check-type="viewCheckRunDetail"
/>
- <button
- v-if="showRunCheckButton"
- type="button"
- class="btn-small py-0.5 inline-flex items-center gap-1"
- :disabled="hasRunningTaskCheck"
- @click.prevent="runChecks"
- >
- <template v-if="hasRunningTaskCheck">
- <BBSpin class="w-4 h-4" />
- {{ $t("task.checking") }}
- </template>
- <template v-else>
- <heroicons-outline:play class="w-4 h-4" />
- {{ $t("task.run-task") }}
- </template>
- </button>
+ <RunTaskCheckButton v-if="allowRunTask" @run-checks="runChecks" />
<BBModal
v-if="state.showModal"
@@ -82,6 +67,7 @@ import { cloneDeep } from "lodash-es";
import { Task, TaskCheckRun, TaskCheckStatus, TaskCheckType } from "@/types";
import TaskCheckBadgeBar from "./TaskCheckBadgeBar.vue";
import TaskCheckRunPanel from "./TaskCheckRunPanel.vue";
+import RunTaskCheckButton from "./RunTaskCheckButton.vue";
import { BBTabFilterItem } from "@/bbkit/types";
import { humanizeTs } from "@/utils";
@@ -93,7 +79,7 @@ interface LocalState {
export default defineComponent({
name: "TaskCheckBar",
- components: { TaskCheckBadgeBar, TaskCheckRunPanel },
+ components: { TaskCheckBadgeBar, TaskCheckRunPanel, RunTaskCheckButton },
props: {
allowRunTask: {
type: Boolean,
@@ -148,25 +134,6 @@ export default defineComponent({
return tabTaskCheckRunList.value[index];
});
- const showRunCheckButton = computed((): boolean => {
- if (!props.allowRunTask) return false;
- return (
- props.task.status == "PENDING" ||
- props.task.status == "PENDING_APPROVAL" ||
- props.task.status == "RUNNING" ||
- props.task.status == "FAILED"
- );
- });
-
- const hasRunningTaskCheck = computed((): boolean => {
- for (const check of props.task.taskCheckRunList) {
- if (check.status == "RUNNING") {
- return true;
- }
- }
- return false;
- });
-
// Returns the most severe status
const taskCheckStatus = (taskCheckRun: TaskCheckRun): TaskCheckStatus => {
let value: TaskCheckStatus = "SUCCESS";
@@ -192,8 +159,8 @@ export default defineComponent({
state.selectedTaskCheckType = undefined;
};
- const runChecks = () => {
- emit("run-checks", props.task);
+ const runChecks = (taskList: Task[]) => {
+ emit("run-checks", taskList);
};
return {
@@ -201,8 +168,6 @@ export default defineComponent({
tabTaskCheckRunList,
tabItemList,
selectedTaskCheckRun,
- showRunCheckButton,
- hasRunningTaskCheck,
taskCheckStatus,
viewCheckRunDetail,
dismissDialog,
diff --git a/frontend/src/components/v2/Button/ContextMenuButton.vue b/frontend/src/components/v2/Button/ContextMenuButton.vue
new file mode 100644
index 0000000000..60f97bdfa6
--- /dev/null
+++ b/frontend/src/components/v2/Button/ContextMenuButton.vue
@@ -0,0 +1,100 @@
+<template>
+ <NButtonGroup size="small">
+ <NButton
+ v-if="currentAction"
+ v-bind="currentAction.props"
+ @click="$emit('click', currentAction)"
+ >
+ <template #icon>
+ <slot name="icon" :action="currentAction!" />
+ </template>
+ <slot name="default" :action="currentAction!">
+ {{ currentAction?.text }}
+ </slot>
+ </NButton>
+
+ <NPopselect
+ v-if="options.length > 1"
+ :value="currentActionKey"
+ :options="options"
+ placement="bottom-end"
+ trigger="click"
+ @update:value="changeActionKey"
+ >
+ <NButton style="--n-padding: 0 6px" v-bind="currentAction?.props">
+ <heroicons-outline:chevron-down />
+ </NButton>
+ </NPopselect>
+ </NButtonGroup>
+</template>
+
+<script setup lang="ts">
+import { ref } from "vue";
+import { NButton, NButtonGroup, NPopselect, SelectOption } from "naive-ui";
+import { ContextMenuButtonAction } from "./types";
+import { useLocalStorage } from "@vueuse/core";
+import { computed } from "vue";
+
+const STORE_PREFIX = "bb.context-menu-button";
+
+const props = defineProps<{
+ preferenceKey: string;
+ actionList: ContextMenuButtonAction[];
+ defaultActionKey: string;
+}>();
+
+defineEmits<{
+ (event: "click", action: ContextMenuButtonAction): void;
+}>();
+
+const getStorage = () => {
+ const { preferenceKey } = props;
+ if (!preferenceKey) return undefined;
+ // e.g key = "bb.button-with-context-menu.task-status-transition"
+ const key = `${STORE_PREFIX}.${preferenceKey}`;
+ return useLocalStorage(key, props.defaultActionKey, {
+ listenToStorageChanges: false,
+ });
+};
+
+// Load user stored default action from localStorage if possible.
+// The stored default action may not be in the actionList this time.
+// Fallback to the first action if not found.
+// But we won't mutate the stored value.
+const getDefaultActionKey = (): string | undefined => {
+ const storage = getStorage();
+ if (storage && storage.value) {
+ return storage.value;
+ }
+ if (props.defaultActionKey) {
+ return props.defaultActionKey;
+ }
+
+ return props.actionList[0]?.key;
+};
+
+const currentActionKey = ref(getDefaultActionKey());
+const currentAction = computed(() => {
+ const key = currentActionKey.value;
+ if (!key) return undefined;
+ return props.actionList.find((action) => action.key === key);
+});
+
+const options = computed(() => {
+ return props.actionList.map<SelectOption>((action) => ({
+ label: action.text,
+ value: action.key,
+ }));
+});
+
+const changeActionKey = (key: string) => {
+ const action = props.actionList.find((action) => action.key === key);
+ if (action) {
+ const storage = getStorage();
+ if (storage) {
+ storage.value = action.key;
+ }
+ }
+ currentActionKey.value = key;
+};
+</script>
diff --git a/frontend/src/components/v2/Button/index.ts b/frontend/src/components/v2/Button/index.ts
new file mode 100644
index 0000000000..6dcf5c1f58
--- /dev/null
+++ b/frontend/src/components/v2/Button/index.ts
@@ -0,0 +1,4 @@
+import ContextMenuButton from "./ContextMenuButton.vue";
+
+export { ContextMenuButton };
+export * from "./types";
diff --git a/frontend/src/components/v2/Button/types.ts b/frontend/src/components/v2/Button/types.ts
new file mode 100644
index 0000000000..013c2bb899
--- /dev/null
+++ b/frontend/src/components/v2/Button/types.ts
@@ -0,0 +1,8 @@
+import { type ButtonProps } from "naive-ui";
+
+export type ContextMenuButtonAction<T = unknown> = {
+ key: string;
+ text: string;
+ props?: ButtonProps;
+ params: T;
+};
diff --git a/frontend/src/components/v2/index.ts b/frontend/src/components/v2/index.ts
index 897fd18554..df30366a22 100644
--- a/frontend/src/components/v2/index.ts
+++ b/frontend/src/components/v2/index.ts
@@ -2,4 +2,4 @@ export * from "./Select";
export * from "./TabFilter";
export * from "./Model";
export * from "./Form";
-export * from "./Select";
+export * from "./Button";
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 0d9f85886e..7ac675e35d 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -336,7 +336,9 @@
"self": "Apply change to all pending tasks",
"current-only": "Only apply change to current task"
},
- "execution-time": "Execution time"
+ "execution-time": "Execution time",
+ "run-checks": "Run checks",
+ "run-checks-in-current-stage": "Run checks in current stage"
},
"banner": {
"update-license": "Update license",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index d666df5823..030383f25c 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -328,7 +328,9 @@
"cancel-generating": "Cancelar la generación de la reversión SQL",
"sql-rollback-tips": "Cuando se habilita, Bytebase mantendrá los registros de reversión para el cambio de datos\ny le permitirá crear una nueva incidencia para revertir este cambio. {link}"
},
- "skip-failed-in-current-stage": "Saltar tareas fallidas en la etapa actual"
+ "skip-failed-in-current-stage": "Saltar tareas fallidas en la etapa actual",
+ "run-checks": "Ejecutar comprobaciones",
+ "run-checks-in-current-stage": "Ejecutar comprobaciones en la etapa actual"
},
"banner": {
"update-license": "Actualizar licencia",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 90090a64d7..e47028b8f1 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -334,7 +334,9 @@
"self": "应用到所有未执行任务",
"current-only": "只应用到当前任务"
},
- "execution-time": "执行时间"
+ "execution-time": "执行时间",
+ "run-checks": "运行检查",
+ "run-checks-in-current-stage": "运行当前阶段的所有检查"
},
"banner": {
"update-license": "更新证书",