Skip to content

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

Make BBSelect TaskStatusSelect support callback and emit transition instead of status.

天舟f1501c9bd8c1
diff --git a/frontend/src/bbkit/BBSelect.vue b/frontend/src/bbkit/BBSelect.vue
index e2e4ef4e08..b1ab7376e0 100644
--- a/frontend/src/bbkit/BBSelect.vue
+++ b/frontend/src/bbkit/BBSelect.vue
@@ -83,8 +83,9 @@
class="text-main hover:text-main-text hover:bg-main-hover cursor-default select-none relative py-2 pl-3 pr-9"
@click="
if (item !== state.selectedItem) {
- $emit('select-item', item);
- state.selectedItem = item;
+ $emit('select-item', item, () => {
+ state.selectedItem = item;
+ });
}
close();
"
diff --git a/frontend/src/components/TaskStatusSelect.vue b/frontend/src/components/TaskStatusSelect.vue
index 677de272a8..14971fc65c 100644
--- a/frontend/src/components/TaskStatusSelect.vue
+++ b/frontend/src/components/TaskStatusSelect.vue
@@ -4,7 +4,7 @@
:itemList="['OPEN', 'DONE', 'CANCELED']"
:placeholder="'Unknown Status'"
:disabled="disabled"
- @select-item="(status) => $emit('change-status', status)"
+ @select-item="(status, didSelect) => changeStatus(status, didSelect)"
>
<template v-slot:menuItem="{ item }">
<span class="flex items-center space-x-2">
@@ -20,11 +20,11 @@
<script lang="ts">
import { PropType } from "vue";
import TaskStatusIcon from "../components/TaskStatusIcon.vue";
-import { TaskStatus } from "../types";
+import { TaskStatus, TaskStatusTransitionType } from "../types";
export default {
name: "TaskStatusSelect",
- emits: ["change-status"],
+ emits: ["start-transition"],
components: { TaskStatusIcon },
props: {
selectedStatus: {
@@ -35,8 +35,24 @@ export default {
type: Boolean,
},
},
- setup() {
- return {};
+ setup(_, { emit }) {
+ const changeStatus = (newStatus: TaskStatus, didChange: () => {}) => {
+ let transition: TaskStatusTransitionType;
+ switch (newStatus) {
+ case "OPEN":
+ transition = "REOPEN";
+ break;
+ case "DONE":
+ transition = "RESOLVE";
+ break;
+ case "CANCELED":
+ transition = "ABORT";
+ break;
+ }
+ emit("start-transition", transition, didChange);
+ };
+
+ return { changeStatus };
},
};
</script>
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index a843393ab0..4343b316d9 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -181,6 +181,44 @@ export type TaskPatch = {
payload?: TaskPayload;
};
+export type TaskStatusTransitionType = "RESOLVE" | "ABORT" | "REOPEN";
+
+export interface TaskStatusTransition {
+ type: TaskStatusTransitionType;
+ actionName: string;
+ to: TaskStatus;
+}
+
+export const TASK_STATUS_TRANSITION_LIST: Map<
+ TaskStatusTransitionType,
+ TaskStatusTransition
+> = new Map([
+ [
+ "RESOLVE",
+ {
+ type: "RESOLVE",
+ actionName: "Resolve",
+ to: "DONE",
+ },
+ ],
+ [
+ "ABORT",
+ {
+ type: "ABORT",
+ actionName: "Abort",
+ to: "CANCELED",
+ },
+ ],
+ [
+ "REOPEN",
+ {
+ type: "REOPEN",
+ actionName: "Reopen",
+ to: "OPEN",
+ },
+ ],
+]);
+
// Activity
export type TaskActionType =
| "bytebase.task.create"
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index ddc6509a3a..ee8a358c1c 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -32,8 +32,16 @@
>
<button
type="button"
- :class="index == 0 ? 'btn-primary' : 'btn-normal mr-2'"
- @click.prevent="updateTaskStatus(transition.to)"
+ :class="
+ index == 0
+ ? transition.type == 'RESOLVE'
+ ? 'btn-success'
+ : transition.type == 'ABORT'
+ ? 'btn-normal'
+ : 'btn-primary'
+ : 'btn-normal mr-2'
+ "
+ @click.prevent="tryStartTaskStatusTransition(transition.type)"
>
{{ transition.actionName }}
</button>
@@ -82,7 +90,7 @@
:task="state.task"
:new="state.new"
:fieldList="inputFieldList"
- @update-task-status="updateTaskStatus"
+ @start-status-transition="tryStartTaskStatusTransition"
@update-assignee-id="updateAssigneeId"
@update-custom-field="updateCustomField"
/>
@@ -109,6 +117,22 @@
</div>
</main>
</div>
+ <BBAlert
+ v-if="updateStatusModalState.show"
+ :style="updateStatusModalState.style"
+ :okText="updateStatusModalState.okText"
+ :cancelText="'No'"
+ :title="updateStatusModalState.title"
+ :payload="updateStatusModalState.payload"
+ @ok="
+ (payload) => {
+ updateStatusModalState.show = false;
+ doTaskStatusTransition(payload);
+ }
+ "
+ @cancel="updateStatusModalState.show = false"
+ >
+ </BBAlert>
</template>
<script lang="ts">
@@ -138,8 +162,11 @@ import {
TaskType,
TaskPatch,
TaskStatus,
+ TaskStatusTransition,
+ TaskStatusTransitionType,
StageProgressPatch,
PrincipalId,
+ TASK_STATUS_TRANSITION_LIST,
} from "../types";
import {
defaulTemplate,
@@ -148,44 +175,6 @@ import {
TaskTemplate,
} from "../plugins";
-type TaskStatusTransitionType = "RESOLVE" | "ABORT" | "REOPEN";
-
-interface Transition {
- type: TaskStatusTransitionType;
- actionName: string;
- to: TaskStatus;
-}
-
-const STATUS_TRANSITION_LIST: Map<
- TaskStatusTransitionType,
- Transition
-> = new Map([
- [
- "RESOLVE",
- {
- type: "RESOLVE",
- actionName: "Resolve",
- to: "DONE",
- },
- ],
- [
- "ABORT",
- {
- type: "ABORT",
- actionName: "Abort",
- to: "CANCELED",
- },
- ],
- [
- "REOPEN",
- {
- type: "REOPEN",
- actionName: "Reopen",
- to: "OPEN",
- },
- ],
-]);
-
// The first transition in the list is the primary action and the rests are
// the normal action. For now there are at most 1 primary 1 normal action.
const CREATOR_APPLICABLE_ACTION_LIST: Map<
@@ -206,6 +195,19 @@ const ASSIGNEE_APPLICABLE_ACTION_LIST: Map<
["CANCELED", ["REOPEN"]],
]);
+type UpdateStatusModalStatePayload = {
+ transition: TaskStatusTransition;
+ didTransit: () => {};
+};
+
+interface UpdateStatusModalState {
+ show: boolean;
+ style: string;
+ okText: string;
+ title: string;
+ payload?: UpdateStatusModalStatePayload;
+}
+
interface LocalState {
new: boolean;
task: ComputedRef<Task | TaskNew>;
@@ -232,6 +234,13 @@ export default {
const store = useStore();
const router = useRouter();
+ const updateStatusModalState = reactive<UpdateStatusModalState>({
+ show: false,
+ style: "INFO",
+ okText: "OK",
+ title: "",
+ });
+
onMounted(() => {
// Always scroll to top, the scrollBehavior doesn't seem to work.
// The hypothesis is that because the scroll bar is in the nested
@@ -351,10 +360,42 @@ export default {
);
};
- const updateTaskStatus = (newStatus: TaskStatus) => {
- patchTask({
- status: newStatus,
- });
+ const tryStartTaskStatusTransition = (
+ type: TaskStatusTransitionType,
+ didTransit: () => {}
+ ) => {
+ const transition = TASK_STATUS_TRANSITION_LIST.get(type)!;
+ updateStatusModalState.okText = transition.actionName;
+ switch (transition.to) {
+ case "OPEN":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = "Reopen task?";
+ break;
+ case "DONE":
+ updateStatusModalState.style = "SUCCESS";
+ updateStatusModalState.title = "Resolve task?";
+ break;
+ case "CANCELED":
+ updateStatusModalState.style = "INFO";
+ updateStatusModalState.title = "Abort task?";
+ break;
+ }
+ updateStatusModalState.payload = {
+ transition,
+ didTransit,
+ };
+ updateStatusModalState.show = true;
+ };
+
+ const doTaskStatusTransition = (payload: UpdateStatusModalStatePayload) => {
+ patchTask(
+ {
+ status: payload.transition.to,
+ },
+ () => {
+ payload.didTransit();
+ }
+ );
};
const updateAssigneeId = (newAssigneeId: PrincipalId) => {
@@ -472,15 +513,17 @@ export default {
});
}
return list.map((type: TaskStatusTransitionType) =>
- STATUS_TRANSITION_LIST.get(type)
+ TASK_STATUS_TRANSITION_LIST.get(type)
);
});
return {
+ updateStatusModalState,
state,
updateName,
updateDescription,
- updateTaskStatus,
+ tryStartTaskStatusTransition,
+ doTaskStatusTransition,
updateAssigneeId,
updateCustomField,
doCreate,
diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vue
index c86241b8de..25ee3cac03 100644
--- a/frontend/src/views/TaskSidebar.vue
+++ b/frontend/src/views/TaskSidebar.vue
@@ -8,9 +8,9 @@
<TaskStatusSelect
:disabled="activeStageIsRunning(task)"
:selectedStatus="task.status"
- @change-status="
- (value) => {
- $emit('update-task-status', value);
+ @start-transition="
+ (transition, didTransit) => {
+ $emit('start-status-transition', transition, didTransit);
}
"
/>
@@ -282,7 +282,11 @@ interface LocalState {
export default {
name: "TaskSidebar",
- emits: ["update-task-status", "update-assignee-id", "update-custom-field"],
+ emits: [
+ "start-status-transition",
+ "update-assignee-id",
+ "update-custom-field",
+ ],
props: {
task: {
required: true,