Skip to content

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

Support add optional note when changing stage status

天舟36c0afc7e214
diff --git a/frontend/src/components/StageStatusTransitionForm.vue b/frontend/src/components/StageStatusTransitionForm.vue
new file mode 100644
index 0000000000..3ed77bc743
--- /dev/null
+++ b/frontend/src/components/StageStatusTransitionForm.vue
@@ -0,0 +1,97 @@
+<template>
+ <div class="px-4 space-y-6 divide-y divide-gray-200">
+ <div class="mt-2 grid grid-cols-1 gap-x-4 sm:grid-cols-4">
+ <div class="sm:col-span-4 w-112 min-w-full">
+ <label for="about" class="textlabel"> Note </label>
+ <div class="mt-1">
+ <textarea
+ ref="commentTextArea"
+ rows="3"
+ class="textarea block w-full resize-none mt-1 text-sm text-control rounded-md whitespace-pre-wrap"
+ placeholder="(Optional) Add a note..."
+ v-model="state.comment"
+ @input="
+ (e) => {
+ sizeToFit(e.target);
+ }
+ "
+ @focus="
+ (e) => {
+ sizeToFit(e.target);
+ }
+ "
+ ></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')"
+ >
+ No
+ </button>
+ <button
+ type="button"
+ class="ml-3 px-4 py-2"
+ v-bind:class="submitButtonStyle"
+ @click.prevent="$emit('submit', transition, state.comment)"
+ >
+ {{ okText }}
+ </button>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed, reactive, ref, PropType } from "vue";
+import { Task, StageStatusTransition } from "../types";
+
+interface LocalState {
+ comment: string;
+}
+
+export default {
+ name: "StageStatusTransitionForm",
+ emits: ["submit", "cancel"],
+ props: {
+ okText: {
+ type: String,
+ default: "OK",
+ },
+ task: {
+ required: true,
+ type: Object as PropType<Task>,
+ },
+ transition: {
+ required: true,
+ type: Object as PropType<StageStatusTransition>,
+ },
+ },
+ setup(props, ctx) {
+ const commentTextArea = ref("");
+
+ const state = reactive<LocalState>({
+ comment: "",
+ });
+
+ const submitButtonStyle = computed(() => {
+ switch (props.transition.type) {
+ case "STOP":
+ return "btn-danger";
+ default:
+ return "btn-primary";
+ }
+ });
+
+ return {
+ state,
+ commentTextArea,
+ submitButtonStyle,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 867d8d7dea..d7a48e2054 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -219,6 +219,57 @@ export const TASK_STATUS_TRANSITION_LIST: Map<
],
]);
+export type StageStatusTransitionType = "RUN" | "RETRY" | "STOP" | "SKIP";
+
+export interface StageStatusTransition {
+ type: StageStatusTransitionType;
+ actionName: string;
+ requireRunnable: boolean;
+ to: StageStatus;
+}
+
+export const STAGE_TRANSITION_LIST: Map<
+ StageStatusTransitionType,
+ StageStatusTransition
+> = new Map([
+ [
+ "RUN",
+ {
+ type: "RUN",
+ actionName: "Run",
+ requireRunnable: true,
+ to: "RUNNING",
+ },
+ ],
+ [
+ "RETRY",
+ {
+ type: "RETRY",
+ actionName: "Rerun",
+ requireRunnable: true,
+ to: "RUNNING",
+ },
+ ],
+ [
+ "STOP",
+ {
+ type: "STOP",
+ actionName: "Stop",
+ requireRunnable: true,
+ to: "PENDING",
+ },
+ ],
+ [
+ "SKIP",
+ {
+ type: "SKIP",
+ actionName: "Skip",
+ requireRunnable: false,
+ to: "SKIPPED",
+ },
+ ],
+]);
+
// Activity
export type TaskActionType =
| "bytebase.task.create"
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 15648f18ba..08c358c18d 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -495,9 +495,13 @@ export default {
});
};
- const changeStageStatus = (stageProgress: StageProgressPatch) => {
+ const changeStageStatus = (
+ stageProgress: StageProgressPatch,
+ comment?: string
+ ) => {
patchTask({
stageProgress,
+ comment,
});
};
diff --git a/frontend/src/views/TaskStageFlow.vue b/frontend/src/views/TaskStageFlow.vue
index bc776bc16a..63f783f688 100644
--- a/frontend/src/views/TaskStageFlow.vue
+++ b/frontend/src/views/TaskStageFlow.vue
@@ -224,83 +224,49 @@
</li>
</ol>
</nav>
- <BBAlert
+ <BBModal
v-if="modalState.show"
- :style="'INFO'"
- :okText="modalState.okText"
- :cancelText="'No'"
:title="modalState.title"
- :payload="modalState.payload"
- @ok="
- (transition) => {
- modalState.show = false;
- doChangeStageStatus(transition);
- }
- "
- @cancel="modalState.show = false"
+ @close="modalState.show = false"
>
- </BBAlert>
+ <StageStatusTransitionForm
+ :okText="modalState.okText"
+ :task="task"
+ :transition="modalState.transition"
+ @submit="
+ (transition, comment) => {
+ modalState.show = false;
+ doChangeStageStatus(transition, comment);
+ }
+ "
+ @cancel="
+ () => {
+ modalState.show = false;
+ }
+ "
+ />
+ </BBModal>
</template>
<script lang="ts">
import { computed, reactive, PropType } from "vue";
import { useStore } from "vuex";
-import { Task, StageId, StageStatus } from "../types";
+import StageStatusTransitionForm from "../components/StageStatusTransitionForm.vue";
+import {
+ Task,
+ StageId,
+ StageStatus,
+ StageStatusTransitionType,
+ StageStatusTransition,
+ STAGE_TRANSITION_LIST,
+} from "../types";
import { activeStage } from "../utils";
-type StageTransitionType = "RUN" | "RETRY" | "STOP" | "SKIP";
-
-interface Transition {
- type: StageTransitionType;
- actionName: string;
- requireRunnable: boolean;
- to: StageStatus;
-}
-
-const STAGE_TRANSITION_LIST: Map<StageTransitionType, Transition> = new Map([
- [
- "RUN",
- {
- type: "RUN",
- actionName: "Run",
- requireRunnable: true,
- to: "RUNNING",
- },
- ],
- [
- "RETRY",
- {
- type: "RETRY",
- actionName: "Rerun",
- requireRunnable: true,
- to: "RUNNING",
- },
- ],
- [
- "STOP",
- {
- type: "STOP",
- actionName: "Stop",
- requireRunnable: true,
- to: "PENDING",
- },
- ],
- [
- "SKIP",
- {
- type: "SKIP",
- actionName: "Skip",
- requireRunnable: false,
- to: "SKIPPED",
- },
- ],
-]);
-
// The first transition in the list is the primary action and the rests are
// the normal action which is hidden in the vertical dots icon.
const CREATOR_APPLICABLE_STAGE_ACTION_LIST: Map<
StageStatus,
- StageTransitionType[]
+ StageStatusTransitionType[]
> = new Map([
["PENDING", []],
["RUNNING", []],
@@ -311,7 +277,7 @@ const CREATOR_APPLICABLE_STAGE_ACTION_LIST: Map<
const ASSIGNEE_APPLICABLE_STAGE_ACTION_LIST: Map<
StageStatus,
- StageTransitionType[]
+ StageStatusTransitionType[]
> = new Map([
["PENDING", ["RUN", "SKIP"]],
["RUNNING", ["STOP"]],
@@ -331,7 +297,7 @@ interface ModalState {
show: boolean;
okText: string;
title: string;
- payload?: Transition;
+ transition?: StageStatusTransition;
}
export default {
@@ -343,7 +309,7 @@ export default {
type: Object as PropType<Task>,
},
},
- components: {},
+ components: { StageStatusTransitionForm },
setup(props, { emit }) {
const store = useStore();
@@ -413,7 +379,7 @@ export default {
if (stage.type != "ENVIRONMENT") {
return false;
}
- const list: StageTransitionType[] = [];
+ const list: StageStatusTransitionType[] = [];
if (currentUser.value.id === (props.task as Task).assignee?.id) {
list.push(...ASSIGNEE_APPLICABLE_STAGE_ACTION_LIST.get(stage.status)!);
}
@@ -434,22 +400,29 @@ export default {
.map((type) => STAGE_TRANSITION_LIST.get(type));
});
- const tryChangeStageStatus = (transition: Transition) => {
+ const tryChangeStageStatus = (transition: StageStatusTransition) => {
modalState.okText = transition.actionName;
modalState.title =
transition.actionName +
' "' +
activeStage(props.task as Task).name +
'" ?';
- modalState.payload = transition;
+ modalState.transition = transition;
modalState.show = true;
};
- const doChangeStageStatus = (transition: Transition) => {
- emit("change-stage-status", {
- id: activeStage(props.task as Task).id,
- status: transition.to,
- });
+ const doChangeStageStatus = (
+ transition: StageStatusTransition,
+ comment?: string
+ ) => {
+ emit(
+ "change-stage-status",
+ {
+ id: activeStage(props.task as Task).id,
+ status: transition.to,
+ },
+ comment
+ );
};
return {