Skip to content

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

Remove the TaskStatus for now to reduce complexity

天舟b27de4a31ffe
diff --git a/frontend/src/components/TaskStatusTransitionForm.vue b/frontend/src/components/StepStatusTransitionForm.vue
similarity index 91%
rename from frontend/src/components/TaskStatusTransitionForm.vue
rename to frontend/src/components/StepStatusTransitionForm.vue
index 347b133643..725a2c2e44 100644
--- a/frontend/src/components/TaskStatusTransitionForm.vue
+++ b/frontend/src/components/StepStatusTransitionForm.vue
@@ -48,14 +48,15 @@
<script lang="ts">
import { computed, reactive, ref, PropType } from "vue";
-import { Issue, TaskStatusTransition } from "../types";
+import { Issue } from "../types";
+import { StepStatusTransition } from "../utils";
interface LocalState {
comment: string;
}
export default {
- name: "TaskStatusTransitionForm",
+ name: "StepStatusTransitionForm",
emits: ["submit", "cancel"],
props: {
okText: {
@@ -68,7 +69,7 @@ export default {
},
transition: {
required: true,
- type: Object as PropType<TaskStatusTransition>,
+ type: Object as PropType<StepStatusTransition>,
},
},
setup(props, ctx) {
@@ -80,7 +81,7 @@ export default {
const submitButtonStyle = computed(() => {
switch (props.transition.type) {
- case "STOP":
+ case "CANCEL":
return "btn-danger";
default:
return "btn-primary";
diff --git a/frontend/src/miragejs/factories/task.js b/frontend/src/miragejs/factories/task.js
index f52bde3152..48b4146f76 100644
--- a/frontend/src/miragejs/factories/task.js
+++ b/frontend/src/miragejs/factories/task.js
@@ -22,9 +22,6 @@ export default {
type() {
return "bytebase.task.unknown";
},
- status() {
- return "PENDING";
- },
databaseId() {
return UNKNOWN_ID;
},
diff --git a/frontend/src/miragejs/routes/issue.js b/frontend/src/miragejs/routes/issue.js
index 08941dc737..c0a17d9e64 100644
--- a/frontend/src/miragejs/routes/issue.js
+++ b/frontend/src/miragejs/routes/issue.js
@@ -302,22 +302,8 @@ export default function configureIssue(route) {
const taskList = schema.tasks.where({ pipelineId: pipeline.id }).models;
if (attrs.status == "DONE") {
- // We check each of the task and its steps. Returns error if any of them is not finished.
+ // Returns error if any of the steps is not in the end status.
for (let i = 0; i < taskList.length; i++) {
- if (
- taskList[i].status != "DONE" &&
- taskList[i].status != "CANCELED" &&
- taskList[i].status != "SKIPPED"
- ) {
- return new Response(
- 404,
- {},
- {
- errors: `Can't resolve issue ${issue.name}. Task ${taskList[i].name} is in ${taskList[i].status} status`,
- }
- );
- }
-
const stepList = schema.steps.where({
issueId: issue.id,
taskId: taskList[i].id,
diff --git a/frontend/src/miragejs/routes/task.js b/frontend/src/miragejs/routes/task.js
deleted file mode 100644
index 05df53c323..0000000000
--- a/frontend/src/miragejs/routes/task.js
+++ /dev/null
@@ -1,121 +0,0 @@
-import { Response } from "miragejs";
-import isEqual from "lodash-es/isEqual";
-import { WORKSPACE_ID } from "./index";
-import { IssueBuiltinFieldId } from "../../plugins";
-import { UNKNOWN_ID, DEFAULT_PROJECT_ID } from "../../types";
-
-export default function configureTask(route) {
- route.patch(
- "/issue/:issueId/task/:taskId/status",
- function (schema, request) {
- const attrs = this.normalizedRequestAttrs("task-status-patch");
- const issue = schema.issues.find(request.params.issueId);
-
- if (!issue) {
- return new Response(
- 404,
- {},
- { errors: "Issue " + request.params.issueId + " not found" }
- );
- }
-
- const task = schema.tasks.find(request.params.taskId);
- if (!task) {
- return new Response(
- 404,
- {},
- { errors: "Task " + request.params.taskId + " not found" }
- );
- }
-
- const ts = Date.now();
-
- if (attrs.status == "DONE") {
- // We check each steps. Returns error if any of them is not finished.
- const stepList = schema.steps.where({
- issueId: issue.id,
- taskId: task.id,
- }).models;
-
- for (let j = 0; j < stepList.length; j++) {
- if (step[j].status != "DONE" || step[j].status != "SKIPPED") {
- return new Response(
- 404,
- {},
- {
- errors: `Can't resolve issue ${issue.name}. Step ${step[j].name} in task ${task[i].name} is in ${step[j].status} status`,
- }
- );
- }
- }
- }
-
- const changeList = [];
- const messageList = [];
- const messageTemplate = {
- containerId: issue.id,
- creatorId: attrs.updaterId,
- createdTs: ts,
- updaterId: attrs.updaterId,
- updatedTs: ts,
- status: "DELIVERED",
- workspaceId: WORKSPACE_ID,
- };
-
- if (attrs.status && task.status != attrs.status) {
- changeList.push({
- fieldId: IssueBuiltinFieldId.TASK_STATUS,
- oldValue: task.status,
- newValue: attrs.status,
- });
-
- messageTemplate.type = "bb.msg.issue.task.status.update";
- messageTemplate.payload = {
- issueName: task.name,
- oldAssigneeId: task.status,
- newAssigneeId: attrs.status,
- };
- }
-
- if (changeList.length) {
- task.update({ ...attrs, updatedTs: ts });
-
- const payload = {
- changeList,
- };
-
- schema.activities.create({
- creatorId: attrs.updaterId,
- createdTs: ts,
- updaterId: attrs.updaterId,
- updatedTs: ts,
- actionType: "bytebase.issue.task.status.update",
- containerId: updatedIssue.id,
- comment: attrs.comment,
- payload,
- workspaceId: WORKSPACE_ID,
- });
-
- postIssueMessageToReceiver(
- schema,
- updatedIssue,
- attrs.updaterId,
- messageTemplate
- );
-
- if (messageList.length > 0) {
- for (const message of messageList) {
- // We only send out message if it's NOT destined to self.
- if (attrs.updaterId != message.receiverId) {
- schema.messages.create(message);
- }
- }
- }
-
- return updatedIssue;
- }
-
- return issue;
- }
- );
-}
diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.ts
index e66cd0e2d8..b6e2e3633f 100644
--- a/frontend/src/miragejs/seeds/index.ts
+++ b/frontend/src/miragejs/seeds/index.ts
@@ -12,7 +12,6 @@ import {
IssueNew,
IssueStatus,
TaskNew,
- TaskStatus,
TaskId,
DatabaseId,
ProjectId,
@@ -374,28 +373,28 @@ const workspacesSeeder = (server: any) => {
workspace: workspace1,
});
- const task = server.create("task", {
- creatorId: ws1Dev1.id,
- updaterId: ws1Dev1.id,
- name: "Create database",
- type: "bytebase.task.database.create",
- status: "PENDING",
- environmentId: environmentList1[1].id,
- databaseId: databaseList1[1].id,
- pipeline,
- workspace: workspace1,
- });
-
- server.create("step", {
- creatorId: ws1Dev1.id,
- updaterId: ws1Dev1.id,
- name: "Waiting approval",
- type: "bytebase.step.approve",
- status: "PENDING",
- pipeline,
- task,
- workspace: workspace1,
- });
+ // const task = server.create("task", {
+ // creatorId: ws1Dev1.id,
+ // updaterId: ws1Dev1.id,
+ // name: "Create database",
+ // type: "bytebase.task.database.create",
+ // status: "PENDING",
+ // environmentId: environmentList1[1].id,
+ // databaseId: databaseList1[1].id,
+ // pipeline,
+ // workspace: workspace1,
+ // });
+
+ // server.create("step", {
+ // creatorId: ws1Dev1.id,
+ // updaterId: ws1Dev1.id,
+ // name: "Waiting approval",
+ // type: "bytebase.step.approve",
+ // status: "PENDING",
+ // pipeline,
+ // task,
+ // workspace: workspace1,
+ // });
server.create("activity", {
actionType: "bytebase.issue.create",
@@ -464,32 +463,26 @@ const workspacesSeeder = (server: any) => {
const statusSetList: {
issueStatus: IssueStatus;
- taskStatusList: TaskStatus[];
stepStatusList: StepStatus[];
}[] = [
{
issueStatus: "OPEN",
- taskStatusList: ["PENDING"],
stepStatusList: ["PENDING"],
},
{
issueStatus: "OPEN",
- taskStatusList: ["DONE", "DONE", "RUNNING", "PENDING"],
stepStatusList: ["DONE", "DONE", "RUNNING", "PENDING"],
},
{
issueStatus: "DONE",
- taskStatusList: ["DONE", "SKIPPED", "DONE", "DONE"],
stepStatusList: ["DONE", "SKIPPED", "DONE", "DONE"],
},
{
issueStatus: "OPEN",
- taskStatusList: ["DONE", "FAILED", "PENDING", "PENDING"],
stepStatusList: ["DONE", "FAILED", "PENDING", "PENDING"],
},
{
issueStatus: "CANCELED",
- taskStatusList: ["DONE", "SKIPPED", "DONE", "PENDING"],
stepStatusList: ["DONE", "SKIPPED", "DONE", "PENDING"],
},
];
@@ -528,7 +521,6 @@ const workspacesSeeder = (server: any) => {
ws1Dev1.id,
environmentList1,
databaseList1,
- statusSet.taskStatusList,
statusSet.stepStatusList
);
@@ -587,7 +579,6 @@ const workspacesSeeder = (server: any) => {
ws1Owner.id,
environmentList1,
databaseList1,
- statusSet.taskStatusList,
statusSet.stepStatusList
);
@@ -646,7 +637,6 @@ const workspacesSeeder = (server: any) => {
ws1Dev2.id,
environmentList1,
databaseList1,
- statusSet.taskStatusList,
statusSet.stepStatusList
);
@@ -703,7 +693,6 @@ const workspacesSeeder = (server: any) => {
ws2Dev.id,
environmentList2,
databaseList2,
- ["PENDING"],
["PENDING"]
);
@@ -823,32 +812,30 @@ const createUpdateSchemaTask = (
creatorId: PrincipalId,
environmentList: Environment[],
databaseList: Database[],
- taskStatusList: TaskStatus[],
stepStatusList: StepStatus[]
) => {
- for (let i = 0; i < taskStatusList.length; i++) {
+ for (let i = 0; i < stepStatusList.length; i++) {
const task = server.create("task", {
creatorId: creatorId,
updaterId: creatorId,
name: `${environmentList[i].name}`,
type: "bytebase.task.schema.update",
- status: taskStatusList[i],
environmentId: environmentList[i].id,
databaseId: databaseList[i].id,
pipelineId,
workspaceId,
});
- server.create("step", {
- creatorId: creatorId,
- updaterId: creatorId,
- name: "Waiting approval",
- type: "bytebase.step.approve",
- status: stepStatusList[i],
- pipelineId,
- task,
- workspaceId,
- });
+ // server.create("step", {
+ // creatorId: creatorId,
+ // updaterId: creatorId,
+ // name: "Waiting approval",
+ // type: "bytebase.step.approve",
+ // status: stepStatusList[i],
+ // pipelineId,
+ // task,
+ // workspaceId,
+ // });
server.create("step", {
creatorId: creatorId,
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index 64948de7bc..d3fd8d820f 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -5,7 +5,6 @@ import {
Task,
TaskId,
TaskState,
- TaskStatusPatch,
Step,
Issue,
IssueId,
@@ -95,30 +94,6 @@ const getters = {
return result;
},
-
- async updateTaskStatus(
- { dispatch }: any,
- {
- issueId,
- taskId,
- taskStatusPatch,
- }: {
- issueId: IssueId;
- taskId: TaskId;
- taskStatusPatch: TaskStatusPatch;
- }
- ) {
- const data = (
- await axios.patch(`/api/issue/${issueId}/task/${taskId}/status`, {
- data: {
- type: "taskstatuspatch",
- attributes: taskStatusPatch,
- },
- })
- ).data;
-
- dispatch("issue/fetchIssueById", issueId, { root: true });
- },
};
const actions = {};
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 1ca1c84e8f..1d0998f1d4 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -200,7 +200,6 @@ export const unknown = (
updatedTs: 0,
name: "<<Unknown task>>",
type: "bytebase.task.unknown",
- status: "DONE",
environment: UNKNOWN_ENVIRONMENT,
database: UNKNOWN_DATABASE,
stepList: [],
@@ -457,7 +456,6 @@ export const empty = (
updatedTs: 0,
name: "",
type: "bytebase.task.unknown",
- status: "DONE",
environment: EMPTY_ENVIRONMENT,
database: EMPTY_DATABASE,
stepList: [],
@@ -548,34 +546,6 @@ export const empty = (
}
};
-export const FINAL_TASK: Task = {
- id: EMPTY_ID,
- pipeline: empty("PIPELINE") as Pipeline,
- environment: empty("ENVIRONMENT") as Environment,
- database: empty("DATABASE") as Database,
- stepList: [],
- creator: empty("PRINCIPAL") as Principal,
- createdTs: 0,
- updater: empty("PRINCIPAL") as Principal,
- updatedTs: 0,
- name: "Final task",
- type: "bytebase.task.final",
- status: "PENDING",
-};
-
-export const FINAL_STEP: Step = {
- id: EMPTY_ID,
- pipeline: empty("PIPELINE") as Pipeline,
- task: FINAL_TASK,
- creator: empty("PRINCIPAL") as Principal,
- createdTs: 0,
- updater: empty("PRINCIPAL") as Principal,
- updatedTs: 0,
- name: "Final step",
- type: "bytebase.step.final",
- status: "PENDING",
-};
-
// These ID format may change in the future, so we encapsulate with a type.
// Also good for readability.
@@ -1078,8 +1048,6 @@ export type TaskType =
| "bytebase.task.database.grant"
| "bytebase.task.schema.update";
-export type TaskStatus = "PENDING" | "RUNNING" | "DONE" | "FAILED" | "SKIPPED";
-
export type TaskRunnable = {
auto: boolean;
run: () => void;
@@ -1106,7 +1074,6 @@ export type Task = {
// Domain specific fields
name: string;
type: TaskType;
- status: TaskStatus;
runnable?: TaskRunnable;
};
@@ -1121,63 +1088,6 @@ export type TaskNew = {
type: TaskType;
};
-export type TaskStatusPatch = {
- updaterId: PrincipalId;
- status: TaskStatus;
- comment?: string;
-};
-
-export type TaskStatusTransitionType = "RUN" | "RETRY" | "STOP" | "SKIP";
-
-export interface TaskStatusTransition {
- type: TaskStatusTransitionType;
- actionName: string;
- requireRunnable: boolean;
- to: TaskStatus;
-}
-
-export const TASK_TRANSITION_LIST: Map<
- TaskStatusTransitionType,
- TaskStatusTransition
-> = 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",
- },
- ],
-]);
-
// Step
export type StepType =
| "bytebase.step.unknown"
diff --git a/frontend/src/utils/issue.ts b/frontend/src/utils/issue.ts
index 37fc12c846..a0c07c21f0 100644
--- a/frontend/src/utils/issue.ts
+++ b/frontend/src/utils/issue.ts
@@ -1,5 +1,4 @@
import { Issue, TaskId } from "../types";
-import { activeTask } from "./pipeline";
export function taskName(issue: Issue, taskId: TaskId): string {
for (const task of issue.pipeline.taskList) {
diff --git a/frontend/src/utils/pipeline.ts b/frontend/src/utils/pipeline.ts
index 2669e42750..11493f25c4 100644
--- a/frontend/src/utils/pipeline.ts
+++ b/frontend/src/utils/pipeline.ts
@@ -42,36 +42,18 @@ export function allStepList(pipeline: Pipeline): Step[] {
return list;
}
-export function activeTask(pipeline: Pipeline): Task {
- for (const task of pipeline.taskList) {
- if (
- task.status == "PENDING" ||
- task.status == "RUNNING" ||
- // "FAILED" is also a transient task status, which requires user
- // to take further action (e.g. Cancel, Skip, Retry)
- task.status == "FAILED"
- ) {
- return task;
- }
- }
- return empty("TASK") as Task;
-}
-
-export function activeTaskIsRunning(pipeline: Pipeline): boolean {
- return activeTask(pipeline).status === "RUNNING";
-}
-
export function activeStep(pipeline: Pipeline): Step {
- const task = activeTask(pipeline);
- for (const step of task.stepList) {
- if (
- step.status == "PENDING" ||
- step.status == "RUNNING" ||
- // "FAILED" is also a transient step status, which requires user
- // to take further action (e.g. Skip, Retry)
- step.status == "FAILED"
- ) {
- return step;
+ for (const task of pipeline.taskList) {
+ for (const step of task.stepList) {
+ if (
+ step.status == "PENDING" ||
+ step.status == "RUNNING" ||
+ // "FAILED" is also a transient step status, which requires user
+ // to take further action (e.g. Skip, Retry)
+ step.status == "FAILED"
+ ) {
+ return step;
+ }
}
}
return empty("STEP") as Step;
@@ -174,3 +156,20 @@ export function applicableStepTransition(
return STEP_STATUS_TRANSITION_LIST.get(type)!;
});
}
+
+function activeTask(pipeline: Pipeline): Task {
+ for (const task of pipeline.taskList) {
+ for (const step of task.stepList) {
+ if (
+ step.status == "PENDING" ||
+ step.status == "RUNNING" ||
+ // "FAILED" is also a transient step status, which requires user
+ // to take further action (e.g. Skip, Retry)
+ step.status == "FAILED"
+ ) {
+ return task;
+ }
+ }
+ }
+ return empty("TASK") as Task;
+}
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index 9d1ffba76b..8684c13db8 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -41,13 +41,13 @@
</template>
<script lang="ts">
-import { watchEffect, computed, nextTick, onMounted, reactive, ref } from "vue";
+import { watchEffect, computed, onMounted, reactive, ref } from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
import IssueTable from "../components/IssueTable.vue";
-import { activeTask, activeEnvironment } from "../utils";
-import { Environment, Issue, TaskStatus } from "../types";
+import { activeEnvironment, activeStep } from "../utils";
+import { Environment, Issue, StepStatus } from "../types";
interface LocalState {
createdList: Issue[];
@@ -165,7 +165,7 @@ export default {
};
const openIssueSorter = (a: Issue, b: Issue) => {
- const statusOrder = (status: TaskStatus) => {
+ const statusOrder = (status: StepStatus) => {
switch (status) {
case "FAILED":
return 0;
@@ -179,8 +179,8 @@ export default {
return 4;
}
};
- const aStatusOrder = statusOrder(activeTask(a.pipeline).status);
- const bStatusOrder = statusOrder(activeTask(b.pipeline).status);
+ const aStatusOrder = statusOrder(activeStep(a.pipeline).status);
+ const bStatusOrder = statusOrder(activeStep(b.pipeline).status);
if (aStatusOrder == bStatusOrder) {
return b.updatedTs - a.updatedTs;
}
diff --git a/frontend/src/views/IssueDetail.vue b/frontend/src/views/IssueDetail.vue
index f67ee52d9c..4f3e9e5a24 100644
--- a/frontend/src/views/IssueDetail.vue
+++ b/frontend/src/views/IssueDetail.vue
@@ -131,7 +131,7 @@
</template>
<!-- Output Panel -->
- <!-- Only render the top border if IssueTaskFlow is not displayed, otherwise it would overlap with the bottom border of the IssueTaskFlow -->
+ <!-- Only render the top border if PipelineFlowBar is not displayed, otherwise it would overlap with the bottom border of that -->
<div
v-if="showIssueOutputPanel"
class="px-2 py-4 md:flex md:flex-col"
@@ -255,7 +255,6 @@ import {
PipelineType,
} from "../utils";
import IssueHighlightPanel from "../views/IssueHighlightPanel.vue";
-import IssueTaskFlow from "./IssueTaskFlow.vue";
import IssueOutputPanel from "../views/IssueOutputPanel.vue";
import IssueSqlPanel from "../views/IssueSqlPanel.vue";
import IssueDescriptionPanel from "./IssueDescriptionPanel.vue";
@@ -270,21 +269,17 @@ import {
IssuePatch,
IssueStatusTransition,
IssueStatusTransitionType,
- TaskStatusPatch,
PrincipalId,
ISSUE_STATUS_TRANSITION_LIST,
Database,
ASSIGNEE_APPLICABLE_ACTION_LIST,
CREATOR_APPLICABLE_ACTION_LIST,
IssueStatusPatch,
- TaskStatus,
- TaskId,
UNKNOWN_ID,
ProjectId,
Environment,
StepStatusPatch,
StepId,
- Pipeline,
EMPTY_ID,
} from "../types";
import {
@@ -325,7 +320,6 @@ export default {
},
components: {
IssueHighlightPanel,
- IssueTaskFlow,
IssueOutputPanel,
IssueSqlPanel,
IssueDescriptionPanel,
@@ -615,24 +609,6 @@ export default {
});
};
- const changeStepStatus = (
- taskId: TaskId,
- taskStatus: TaskStatus,
- comment?: string
- ) => {
- const taskStatusPatch: TaskStatusPatch = {
- updaterId: currentUser.value.id,
- status: taskStatus,
- comment: comment ? comment.trim() : undefined,
- };
-
- store.dispatch("task/updateTaskStatus", {
- issueId: (state.issue as Issue).id,
- taskId,
- taskStatusPatch,
- });
- };
-
const tryStartIssueStatusTransition = (
transition: IssueStatusTransition
) => {
@@ -685,24 +661,6 @@ export default {
});
};
- const changeTaskStatus = (
- taskId: TaskId,
- taskStatus: TaskStatus,
- comment?: string
- ) => {
- const taskStatusPatch: TaskStatusPatch = {
- updaterId: currentUser.value.id,
- status: taskStatus,
- comment: comment ? comment.trim() : undefined,
- };
-
- store.dispatch("task/updateTaskStatus", {
- issueId: (state.issue as Issue).id,
- taskId,
- taskStatusPatch,
- });
- };
-
const updateAssigneeId = (newAssigneeId: PrincipalId) => {
if (state.new) {
(state.issue as IssueNew).assigneeId = newAssigneeId;
@@ -938,10 +896,8 @@ export default {
allowTransition,
tryStartStepStatusTransition,
doStepStatusTransition,
- changeStepStatus,
tryStartIssueStatusTransition,
doIssueStatusTransition,
- changeTaskStatus,
updateAssigneeId,
updateSubscriberIdList,
updateCustomField,
diff --git a/frontend/src/views/IssueTaskFlow.vue b/frontend/src/views/IssueTaskFlow.vue
deleted file mode 100644
index e7dd102d79..0000000000
--- a/frontend/src/views/IssueTaskFlow.vue
+++ /dev/null
@@ -1,438 +0,0 @@
-<template>
- <nav aria-label="Progress">
- <ol
- class="border-t border-b border-block-border divide-y divide-gray-300 lg:flex lg:divide-y-0"
- >
- <li
- v-for="(task, index) in taskList"
- :key="index"
- class="relative md:flex-1 md:flex"
- >
- <div
- class="cursor-default group flex items-center justify-between w-full"
- >
- <span class="pl-4 py-3 flex items-center text-sm font-medium">
- <div
- class="relative w-6 h-6 flex items-center justify-center rounded-full select-none"
- :class="taskIconClass(task)"
- >
- <template v-if="task.status === 'PENDING'">
- <span
- v-if="activeTask(issue.pipeline).id === task.id"
- class="h-1.5 w-1.5 bg-blue-600 rounded-full"
- aria-hidden="true"
- ></span>
- <span
- v-else
- class="h-1.5 w-1.5 bg-gray-300 rounded-full"
- aria-hidden="true"
- ></span>
- </template>
- <template v-else-if="task.status == 'RUNNING'">
- <span
- class="h-2.5 w-2.5 bg-blue-600 rounded-full"
- style="
- animation: pulse 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
- "
- aria-hidden="true"
- ></span>
- </template>
- <template v-else-if="task.status == 'DONE'">
- <svg
- class="w-5 h-5"
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 20 20"
- fill="currentColor"
- aria-hidden="true"
- >
- <path
- fill-rule="evenodd"
- d="M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z"
- clip-rule="evenodd"
- />
- </svg>
- </template>
- <template v-else-if="task.status == 'FAILED'">
- <span
- class="h-2.5 w-2.5 rounded-full text-center pb-6 font-medium text-base"
- aria-hidden="true"
- >!</span
- >
- </template>
- <template v-else-if="task.status == 'SKIPPED'">
- <svg
- class="w-5 h-5"
- fill="currentColor"
- viewBox="0 0 20 20"
- xmlns="http://www.w3.org/2000/svg"
- aria-hidden="true"
- >
- >
- <path
- fill-rule="evenodd"
- d="M3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1z"
- clip-rule="evenodd"
- ></path>
- </svg>
- </template>
- </div>
- <span class="ml-2 text-sm" :class="taskTextClass(task)">{{
- task.title
- }}</span>
- </span>
- <div
- v-if="
- activeTask(issue.pipeline).id === task.id &&
- applicableTaskTransitionList.length > 0
- "
- class="flex flex-row space-x-1 mr-4"
- >
- <button
- class="btn-icon"
- @click.prevent="
- tryChangeTaskStatus(task.id, applicableTaskTransitionList[0])
- "
- >
- <template v-if="applicableTaskTransitionList[0].type == 'RUN'">
- <svg
- class="w-6 h-6"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M14.752 11.168l-3.197-2.132A1 1 0 0010 9.87v4.263a1 1 0 001.555.832l3.197-2.132a1 1 0 000-1.664z"
- ></path>
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
- ></path>
- </svg>
- </template>
- <template
- v-else-if="applicableTaskTransitionList[0].type == 'RETRY'"
- >
- <svg
- class="w-5 h-5"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"
- ></path>
- </svg>
- </template>
- <template
- v-else-if="applicableTaskTransitionList[0].type == 'STOP'"
- >
- <svg
- class="w-6 h-6"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M21 12a9 9 0 11-18 0 9 9 0 0118 0z"
- ></path>
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M9 10a1 1 0 011-1h4a1 1 0 011 1v4a1 1 0 01-1 1h-4a1 1 0 01-1-1v-4z"
- ></path>
- </svg>
- </template>
- </button>
- <template v-if="applicableTaskTransitionList.length > 1">
- <button
- class="btn-icon"
- @click.prevent="$refs.menu.toggle($event)"
- >
- <svg
- class="w-5 h-5"
- fill="none"
- stroke="currentColor"
- viewBox="0 0 24 24"
- xmlns="http://www.w3.org/2000/svg"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M12 5v.01M12 12v.01M12 19v.01M12 6a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2zm0 7a1 1 0 110-2 1 1 0 010 2z"
- ></path>
- </svg>
- </button>
- <BBContextMenu
- ref="menu"
- class="origin-bottom-right absolute mt-6 -right-8 w-16 rounded-md shadow-lg"
- >
- <template
- v-for="(
- transition, index
- ) in applicableTaskTransitionList.slice(1)"
- :key="index"
- >
- <a
- @click.prevent="tryChangeTaskStatus(task.id, transition)"
- class="menu-item"
- role="menuitem"
- >
- {{ transition.actionName }}
- </a>
- </template>
- </BBContextMenu>
- </template>
- </div>
- </div>
-
- <!-- Arrow separator -->
- <div
- v-if="index != taskList.length - 1"
- class="hidden lg:block absolute top-0 right-0 h-full w-5"
- aria-hidden="true"
- >
- <svg
- class="h-full w-full text-gray-300"
- viewBox="0 0 22 80"
- fill="none"
- preserveAspectRatio="none"
- >
- <path
- d="M0 -2L20 40L0 82"
- vector-effect="non-scaling-stroke"
- stroke="currentcolor"
- stroke-linejoin="round"
- />
- </svg>
- </div>
- </li>
- </ol>
- </nav>
- <BBModal
- v-if="modalState.show"
- :title="modalState.title"
- @close="modalState.show = false"
- >
- <TaskStatusTransitionForm
- :okText="modalState.okText"
- :issue="issue"
- :transition="modalState.transition"
- @submit="
- (transition, comment) => {
- modalState.show = false;
- doChangeTaskStatus(modalState.taskId, transition, comment);
- }
- "
- @cancel="
- () => {
- modalState.show = false;
- }
- "
- />
- </BBModal>
-</template>
-
-<script lang="ts">
-import { computed, reactive, PropType } from "vue";
-import { useStore } from "vuex";
-import TaskStatusTransitionForm from "../components/TaskStatusTransitionForm.vue";
-import {
- Issue,
- TaskId,
- TaskStatus,
- TaskStatusTransitionType,
- TaskStatusTransition,
- TASK_TRANSITION_LIST,
- UNKNOWN_ID,
-} from "../types";
-import { activeTask } from "../utils";
-
-// 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_TASK_ACTION_LIST: Map<
- TaskStatus,
- TaskStatusTransitionType[]
-> = new Map([
- ["PENDING", []],
- ["RUNNING", []],
- ["DONE", []],
- ["FAILED", []],
- ["SKIPPED", []],
-]);
-
-const ASSIGNEE_APPLICABLE_TASK_ACTION_LIST: Map<
- TaskStatus,
- TaskStatusTransitionType[]
-> = new Map([
- ["PENDING", ["RUN", "SKIP"]],
- ["RUNNING", ["STOP"]],
- ["DONE", []],
- ["FAILED", ["RETRY", "SKIP"]],
- ["SKIPPED", []],
-]);
-
-interface FlowItem {
- id: TaskId;
- title: string;
- status: string;
- link: () => string;
-}
-
-interface ModalState {
- taskId: TaskId;
- show: boolean;
- okText: string;
- title: string;
- transition?: TaskStatusTransition;
-}
-
-export default {
- name: "IssueTaskFlow",
- emits: ["change-task-status"],
- props: {
- issue: {
- required: true,
- type: Object as PropType<Issue>,
- },
- },
- components: { TaskStatusTransitionForm },
- setup(props, { emit }) {
- const store = useStore();
-
- const modalState = reactive<ModalState>({
- taskId: UNKNOWN_ID,
- show: false,
- okText: "OK",
- title: "",
- });
-
- const currentUser = computed(() => store.getters["auth/currentUser"]());
-
- const taskList = computed<FlowItem[]>(() => {
- return props.issue.pipeline.taskList.map((task) => {
- return {
- id: task.id,
- title: task.name,
- status: task.status,
- link: (): string => {
- return `/issue/${props.issue.id}`;
- },
- };
- });
- });
-
- const taskIconClass = (task: FlowItem) => {
- switch (task.status) {
- case "PENDING":
- if (activeTask(props.issue.pipeline).id === task.id) {
- return "bg-white border-2 border-blue-600 text-blue-600 ";
- }
- return "bg-white border-2 border-gray-300";
- case "RUNNING":
- return "bg-white border-2 border-blue-600 text-blue-600";
- case "DONE":
- return "bg-success text-white";
- case "FAILED":
- return "bg-error text-white";
- case "SKIPPED":
- return "bg-white border-2 text-gray-400 border-gray-400";
- }
- };
-
- const taskTextClass = (task: FlowItem) => {
- let textClass =
- activeTask(props.issue.pipeline).id === task.id
- ? "font-medium "
- : "font-normal ";
- switch (task.status) {
- case "SKIPPED":
- return textClass + "text-gray-500";
- case "DONE":
- return textClass + "text-control";
- case "PENDING":
- if (activeTask(props.issue.pipeline).id === task.id) {
- return textClass + "text-blue-600";
- }
- return textClass + "text-control";
- case "RUNNING":
- return textClass + "text-blue-600";
- case "FAILED":
- return textClass + "text-red-500";
- }
- };
-
- const applicableTaskTransitionList = computed(() => {
- const task = activeTask((props.issue as Issue).pipeline);
- const list: TaskStatusTransitionType[] = [];
- if (currentUser.value.id === (props.issue as Issue).assignee?.id) {
- list.push(...ASSIGNEE_APPLICABLE_TASK_ACTION_LIST.get(task.status)!);
- }
- if (currentUser.value.id === (props.issue as Issue).creator.id) {
- CREATOR_APPLICABLE_TASK_ACTION_LIST.get(task.status)!.forEach(
- (item) => {
- if (list.indexOf(item) == -1) {
- list.push(item);
- }
- }
- );
- }
- return list
- .filter((type) => {
- const transition = TASK_TRANSITION_LIST.get(type)!;
- return !transition.requireRunnable || task.runnable;
- })
- .map((type) => TASK_TRANSITION_LIST.get(type));
- });
-
- const tryChangeTaskStatus = (
- taskId: TaskId,
- transition: TaskStatusTransition
- ) => {
- modalState.taskId = taskId;
- modalState.okText = transition.actionName;
- modalState.title =
- transition.actionName +
- ' "' +
- activeTask((props.issue as Issue).pipeline).name +
- '" ?';
- modalState.transition = transition;
- modalState.show = true;
- };
-
- const doChangeTaskStatus = (
- taskId: TaskId,
- transition: TaskStatusTransition,
- comment?: string
- ) => {
- emit("change-task-status", taskId, transition.to, comment);
- };
-
- return {
- modalState,
- taskList,
- activeTask,
- taskIconClass,
- taskTextClass,
- applicableTaskTransitionList,
- tryChangeTaskStatus,
- doChangeTaskStatus,
- };
- },
-};
-</script>