Skip to content

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

feat(frontend): allow to approve current stage when some of the tasks were approved already (#3018)

Liu Ji94f1a5a091dd
diff --git a/frontend/src/components/Issue/logic/transition.ts b/frontend/src/components/Issue/logic/transition.ts
index a4f0c20b2b..260aaacebf 100644
--- a/frontend/src/components/Issue/logic/transition.ts
+++ b/frontend/src/components/Issue/logic/transition.ts
@@ -10,13 +10,14 @@ import {
IssueStatusTransition,
} from "@/types";
import {
+ activeStage,
allTaskList,
- applicableStageTransition,
applicableTaskTransition,
isDBAOrOwner,
isOwnerOfProject,
StageStatusTransition,
TaskStatusTransition,
+ TASK_STATUS_TRANSITION_LIST,
} from "@/utils";
import { useAllowProjectOwnerToApprove, useIssueLogic } from ".";
@@ -118,11 +119,24 @@ export const useIssueTransitionLogic = (issue: Ref<Issue>) => {
return [];
case "OPEN": {
if (isAllowedToApplyTaskTransition.value) {
- const currentTask = activeTaskOfPipeline(issue.pipeline);
- return applicableStageTransition(issue.pipeline).filter(
- (transition) =>
- allowApplyTaskStatusTransition(currentTask, transition.to)
+ // Only "Approve" can be applied to current stage by now.
+ const APPROVE = TASK_STATUS_TRANSITION_LIST.get("APPROVE")!;
+ const currentStage = activeStage(issue.pipeline);
+
+ const pendingApprovalTaskList = currentStage.taskList.filter(
+ (task) => {
+ return (
+ task.status === "PENDING_APPROVAL" &&
+ allowApplyTaskStatusTransition(task, APPROVE.to)
+ );
+ }
);
+
+ // Allowing "Approve" a stage when it has TWO OR MORE tasks
+ // are "PENDING_APPROVAL" (including the "activeTask" itself)
+ if (pendingApprovalTaskList.length >= 2) {
+ return [APPROVE];
+ }
}
return [];
diff --git a/frontend/src/utils/pipeline.ts b/frontend/src/utils/pipeline.ts
index b03e49c152..33144124c9 100644
--- a/frontend/src/utils/pipeline.ts
+++ b/frontend/src/utils/pipeline.ts
@@ -1,5 +1,4 @@
import { BBButtonType } from "@/bbkit/types";
-import { uniq } from "lodash-es";
import {
Database,
empty,
@@ -173,7 +172,7 @@ export interface TaskStatusTransition {
buttonType: BBButtonType;
}
-const TASK_STATUS_TRANSITION_LIST: Map<
+export const TASK_STATUS_TRANSITION_LIST: Map<
TaskStatusTransitionType,
TaskStatusTransition
> = new Map([
@@ -225,7 +224,7 @@ const TASK_STATUS_TRANSITION_LIST: Map<
]);
// The transition button are displayed from left to right on the UI, and the right-most one is the primary button
-const APPLICABLE_TASK_TRANSITION_LIST: Map<
+export const APPLICABLE_TASK_TRANSITION_LIST: Map<
TaskStatus,
TaskStatusTransitionType[]
> = new Map([
@@ -258,24 +257,3 @@ export function applicableTaskTransition(
// 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)!);
-}