Skip to content

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

feat(frontend): implement the logic part to patch stage all task status (#1496)

Liu Ji633b38b55e64
diff --git a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
index 1ed8b6fd30..808b5e4be3 100644
--- a/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
+++ b/frontend/src/components/Issue/IssueStatusTransitionButtonGroup.vue
@@ -181,6 +181,7 @@ const issueContext = computed((): IssueContext => {
const {
applicableTaskStatusTransitionList,
+ applicableStageStatusTransitionList,
applicableIssueStatusTransitionList,
getApplicableIssueStatusTransitionList,
getApplicableTaskStatusTransitionList,
@@ -346,4 +347,21 @@ const onSubmit = async (comment: string) => {
cleanup();
};
+
+const allowApplyTransitionToStage = (transition: TaskStatusTransition) => {
+ const stage = currentTask.value.stage;
+
+ // Only available when the stage has multiple tasks.
+ if (stage.taskList.length <= 1) {
+ return false;
+ }
+
+ // Available to apply a taskStatusTransition to the stage when the transition
+ // type is also applicable to the stage.
+ return (
+ applicableStageStatusTransitionList.value.findIndex(
+ (t) => t.type === transition.type
+ ) >= 0
+ );
+};
</script>
diff --git a/frontend/src/components/Issue/logic/extra.ts b/frontend/src/components/Issue/logic/extra.ts
index c72ae5a84d..70a35c3455 100644
--- a/frontend/src/components/Issue/logic/extra.ts
+++ b/frontend/src/components/Issue/logic/extra.ts
@@ -12,6 +12,8 @@ import {
IssueStatus,
IssueStatusPatch,
PrincipalId,
+ Stage,
+ StageAllTaskStatusPatch,
Task,
TaskCreate,
TaskPatch,
@@ -171,6 +173,35 @@ export const useExtraIssueLogic = () => {
});
};
+ const changeStageAllTaskStatus = (
+ stage: Stage,
+ newStatus: TaskStatus,
+ comment: string
+ ) => {
+ // Switch to the last task in this stage
+ const lastTask = stage.taskList[stage.taskList.length - 1];
+ selectStageOrTask(stage.id);
+ nextTick(() => {
+ selectTask(lastTask);
+ });
+
+ // Patch the stage
+ const stageAllTaskStatusPatch: StageAllTaskStatusPatch = {
+ id: stage.id,
+ status: newStatus,
+ comment,
+ };
+ taskStore
+ .updateStageAllTaskStatus({
+ issue: issue.value as Issue,
+ stage,
+ patch: stageAllTaskStatusPatch,
+ })
+ .then(() => {
+ onStatusChanged(true);
+ });
+ };
+
const changeTaskStatus = (
task: Task,
newStatus: TaskStatus,
@@ -221,6 +252,7 @@ export const useExtraIssueLogic = () => {
removeSubscriberId,
updateCustomField,
changeIssueStatus,
+ changeStageAllTaskStatus,
changeTaskStatus,
runTaskChecks,
};
diff --git a/frontend/src/components/Issue/logic/transition.ts b/frontend/src/components/Issue/logic/transition.ts
index ab3868a276..bf2d9d52ea 100644
--- a/frontend/src/components/Issue/logic/transition.ts
+++ b/frontend/src/components/Issue/logic/transition.ts
@@ -12,8 +12,10 @@ import {
} from "@/types";
import {
allTaskList,
+ applicableStageTransition,
applicableTaskTransition,
isDBAOrOwner,
+ StageStatusTransition,
TaskStatusTransition,
} from "@/utils";
import { useIssueLogic } from ".";
@@ -78,6 +80,32 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {
.reverse();
};
+ const getApplicableStageStatusTransitionList = (issue: Issue) => {
+ if (issue.id == ONBOARDING_ISSUE_ID) {
+ return [];
+ }
+ switch (issue.status) {
+ case "DONE":
+ case "CANCELED":
+ return [];
+ case "OPEN": {
+ let list: TaskStatusTransition[] = [];
+
+ // Allow assignee, or assignee is the system bot and current user is DBA or owner
+ if (
+ currentUser.value.id === issue.assignee?.id ||
+ (issue.assignee?.id == SYSTEM_BOT_ID &&
+ isDBAOrOwner(currentUser.value.role))
+ ) {
+ list = applicableStageTransition(issue.pipeline);
+ }
+
+ return list;
+ }
+ }
+ console.assert(false, "Should never reach this line");
+ };
+
const getApplicableTaskStatusTransitionList = (
issue: Issue
): TaskStatusTransition[] => {
@@ -110,20 +138,26 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {
getApplicableTaskStatusTransitionList(issue.value)
);
+ const applicableStageStatusTransitionList = computed(() =>
+ getApplicableStageStatusTransitionList(issue.value)
+ );
+
const applicableIssueStatusTransitionList = computed(() =>
getApplicableIssueStatusTransitionList(issue.value)
);
return {
getApplicableIssueStatusTransitionList,
+ getApplicableStageStatusTransitionList,
getApplicableTaskStatusTransitionList,
applicableIssueStatusTransitionList,
+ applicableStageStatusTransitionList,
applicableTaskStatusTransitionList,
};
};
export function isApplicableTransition<
- T extends IssueStatusTransition | TaskStatusTransition
+ T extends IssueStatusTransition | TaskStatusTransition | StageStatusTransition
>(target: T, list: T[]): boolean {
return (
list.findIndex((applicable) => {
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index 04dd5e4f5f..d86efd4c49 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -3,12 +3,14 @@ import axios from "axios";
import {
empty,
Instance,
+ Issue,
IssueId,
Pipeline,
PipelineId,
ResourceIdentifier,
ResourceObject,
Stage,
+ StageAllTaskStatusPatch,
StageId,
Task,
TaskCheckRun,
@@ -227,6 +229,28 @@ export const useTaskStore = defineStore("task", {
return task;
},
+ async updateStageAllTaskStatus({
+ issue,
+ stage,
+ patch,
+ }: {
+ issue: Issue;
+ stage: Stage;
+ patch: StageAllTaskStatusPatch;
+ }) {
+ const { pipeline } = stage;
+ await axios.patch(
+ `/api/pipeline/${pipeline.id}/stage/${stage.id}/status`,
+ {
+ data: {
+ type: "stageAllTaskStatusPatch",
+ attributes: patch,
+ },
+ }
+ );
+
+ useIssueStore().fetchIssueById(issue.id);
+ },
async patchTask({
issueId,
pipelineId,
diff --git a/frontend/src/types/pipeline/stage.ts b/frontend/src/types/pipeline/stage.ts
index aeeb21ecac..a776f57a6f 100644
--- a/frontend/src/types/pipeline/stage.ts
+++ b/frontend/src/types/pipeline/stage.ts
@@ -4,7 +4,7 @@ import { Environment } from "../environment";
import { EnvironmentId, StageId } from "../id";
import { Principal } from "../principal";
import { Pipeline } from "./pipeline";
-import { Task, TaskCreate } from "./task";
+import { Task, TaskCreate, TaskStatus } from "./task";
// THus stage can access both instance and environment info.
export type Stage = {
@@ -33,3 +33,10 @@ export type StageCreate = {
// Domain specific fields
name: string;
};
+
+export type StageAllTaskStatusPatch = {
+ id: StageId;
+
+ status: TaskStatus;
+ comment?: string;
+};
diff --git a/frontend/src/utils/pipeline.ts b/frontend/src/utils/pipeline.ts
index bf4803df7b..34c3e1a7fd 100644
--- a/frontend/src/utils/pipeline.ts
+++ b/frontend/src/utils/pipeline.ts
@@ -1,3 +1,4 @@
+import { uniq } from "lodash-es";
import {
Database,
empty,
@@ -238,3 +239,28 @@ export function applicableTaskTransition(
return TASK_STATUS_TRANSITION_LIST.get(type)!;
});
}
+
+// The status transition applying to a stage is applying to all tasks in the
+// stage simultaneously.
+export type StageStatusTransition = TaskStatusTransition;
+
+export function applicableStageTransition(
+ pipeline: Pipeline
+): StageStatusTransition[] {
+ const task = activeTask(pipeline);
+ if (task.id === EMPTY_ID || task.id === UNKNOWN_ID) {
+ return [];
+ }
+ const stage = task.stage;
+ const statusList = uniq(stage.taskList.map((t) => t.status));
+
+ // Only allowed to apply status patch to a stage when all it's tasks' status
+ // are the same.
+ if (statusList.length > 1) {
+ return [];
+ }
+
+ const transitionTypes = APPLICABLE_TASK_TRANSITION_LIST.get(statusList[0])!;
+
+ return transitionTypes.map((type) => TASK_STATUS_TRANSITION_LIST.get(type)!);
+}