Skip to content

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

Simplify task and stage status

Tianzhou Chen8abed8cf10f3
diff --git a/frontend/src/bbkit/BBStepBar.vue b/frontend/src/bbkit/BBStepBar.vue
index 1d06419fb8..c9f24a35b4 100644
--- a/frontend/src/bbkit/BBStepBar.vue
+++ b/frontend/src/bbkit/BBStepBar.vue
@@ -14,13 +14,13 @@
class="relative w-6 h-6 flex items-center justify-center rounded-full"
:class="stepClass(step.status)"
>
- <template v-if="step.status == `CREATED`">
+ <template v-if="step.status == `PENDING`">
<span
class="h-1.5 w-1.5 bg-gray-300 hover:bg-gray-400 rounded-full"
aria-hidden="true"
></span>
</template>
- <template v-else-if="step.status == `PENDING`">
+ <template v-else-if="step.status == `PENDING_ACTIVE`">
<span
class="h-1.5 w-1.5 bg-blue-600 hover:bg-blue-700 rounded-full"
aria-hidden="true"
@@ -114,9 +114,9 @@ export default {
setup(props, ctx) {
const stepClass = (status: BBStepStatus) => {
switch (status) {
- case "CREATED":
- return "bg-white border-2 border-gray-300 hover:border-gray-400";
case "PENDING":
+ return "bg-white border-2 border-gray-300 hover:border-gray-400";
+ case "PENDING_ACTIVE":
return "bg-white border-2 border-blue-600 text-blue-600 hover:text-blue-700 hover:border-blue-700";
case "RUNNING":
return "bg-white border-2 border-blue-600 text-blue-600 hover:text-blue-700 hover:border-blue-700";
diff --git a/frontend/src/bbkit/types.ts b/frontend/src/bbkit/types.ts
index 5ccd6b548d..28209c1210 100644
--- a/frontend/src/bbkit/types.ts
+++ b/frontend/src/bbkit/types.ts
@@ -8,8 +8,8 @@ export type BBTableSectionDataSource<T> = {
};
export type BBStepStatus =
- | "CREATED"
| "PENDING"
+ | "PENDING_ACTIVE"
| "RUNNING"
| "DONE"
| "FAILED"
diff --git a/frontend/src/components/TaskTable.vue b/frontend/src/components/TaskTable.vue
index 8e6e7e5451..d0000bb80b 100644
--- a/frontend/src/components/TaskTable.vue
+++ b/frontend/src/components/TaskTable.vue
@@ -9,22 +9,28 @@
<BBTableCell :leftPadding="4" class="w-4 table-cell">
<span
class="w-5 h-5 flex items-center justify-center rounded-full"
- :class="iconStatusMap[task.attributes.status].class"
+ :class="taskIconClass(task)"
>
- <template v-if="task.attributes.status == `PENDING`">
- <span
- class="h-1.5 w-1.5 bg-blue-600 hover:bg-blue-700 rounded-full"
- aria-hidden="true"
- ></span>
- </template>
- <template v-else-if="task.attributes.status == `RUNNING`">
+ <template v-if="task.attributes.status == `OPEN`">
<span
+ v-if="activeStage(task).status == 'RUNNING'"
class="h-2 w-2 bg-blue-600 hover:bg-blue-700 rounded-full"
style="
animation: pulse 2.5s cubic-bezier(0.4, 0, 0.6, 1) infinite;
"
aria-hidden="true"
></span>
+ <span
+ v-else-if="activeStage(task).status == 'FAILED'"
+ class="h-2 w-2 rounded-full text-center pb-6 font-normal text-base"
+ aria-hidden="true"
+ >!</span
+ >
+ <span
+ v-else
+ class="h-1.5 w-1.5 bg-blue-600 hover:bg-blue-700 rounded-full"
+ aria-hidden="true"
+ ></span>
</template>
<template v-else-if="task.attributes.status == `DONE`">
<svg
@@ -41,13 +47,6 @@
/>
</svg>
</template>
- <template v-else-if="task.attributes.status == `FAILED`">
- <span
- class="h-2 w-2 rounded-full text-center pb-6 font-normal text-base"
- aria-hidden="true"
- >!</span
- >
- </template>
<template v-else-if="task.attributes.status == `CANCELED`">
<svg
class="w-5 h-5"
@@ -78,7 +77,11 @@
</span>
</BBTableCell>
<BBTableCell class="w-24 table-cell">
- {{ environmentName(task.attributes.currentStageId) }}
+ {{
+ activeEnvironmentId(task)
+ ? environmentName(activeEnvironmentId(task))
+ : ""
+ }}
</BBTableCell>
<BBTableCell :leftPadding="1" class="w-auto">
{{ task.attributes.name }}
@@ -106,7 +109,7 @@ import {
BBStep,
BBStepStatus,
} from "../bbkit/types";
-import { humanize, taskSlug } from "../utils";
+import { humanize, taskSlug, activeEnvironmentId, activeStage } from "../utils";
import { EnvironmentId, Task } from "../types";
interface LocalState {
@@ -114,32 +117,6 @@ interface LocalState {
dataSource: Object[];
}
-const iconStatusMap = {
- PENDING: {
- name: "Pending",
- class:
- "bg-white border-2 border-blue-600 text-blue-600 hover:text-blue-700 hover:border-blue-700",
- },
- RUNNING: {
- name: "Running",
- class:
- "bg-white border-2 border-blue-600 text-blue-600 hover:text-blue-700 hover:border-blue-700",
- },
- DONE: {
- name: "Done",
- class: "bg-success hover:bg-success-hover text-white",
- },
- FAILED: {
- name: "Failed",
- class: "bg-error text-white hover:text-white hover:bg-error-hover",
- },
- CANCELED: {
- name: "Canceled",
- class:
- "bg-white border-2 text-gray-400 border-gray-400 hover:text-gray-500 hover:border-gray-500",
- },
-};
-
export default {
name: "TaskTable",
components: {},
@@ -190,13 +167,14 @@ export default {
const stageList = function (task: Task): BBStep[] {
return task.attributes.stageProgressList.map((stageProgress) => {
- let stepStatus: BBStepStatus = "CREATED";
+ let stepStatus: BBStepStatus;
switch (stageProgress.status) {
- case "CREATED":
- stepStatus = "CREATED";
- break;
case "PENDING":
- stepStatus = "PENDING";
+ if (activeStage(task).id === stageProgress.id) {
+ stepStatus = "PENDING_ACTIVE";
+ } else {
+ stepStatus = "PENDING";
+ }
break;
case "RUNNING":
stepStatus = "RUNNING";
@@ -218,12 +196,32 @@ export default {
title: stageProgress.name,
status: stepStatus,
link: (): string => {
- return `/task/${task.id}#${stageProgress.id}`;
+ return `/task/${task.id}`;
},
};
});
};
+ const taskIconClass = (task: Task) => {
+ switch (task.attributes.status) {
+ case "OPEN":
+ switch (activeStage(task).status) {
+ case "FAILED":
+ return "bg-error text-white hover:text-white hover:bg-error-hover";
+ case "RUNNING":
+ case "PENDING":
+ case "DONE":
+ case "CANCELED":
+ case "SKIPPED":
+ return "bg-white border-2 border-blue-600 text-blue-600 hover:text-blue-700 hover:border-blue-700";
+ }
+ case "CANCELED":
+ return "bg-white border-2 text-gray-400 border-gray-400 hover:text-gray-500 hover:border-gray-500";
+ case "DONE":
+ return "bg-success hover:bg-success-hover text-white";
+ }
+ };
+
const clickTask = function (section: number, row: number) {
const task = props.taskSectionList[section].list[row];
router.push(`/task/${taskSlug(task.attributes.name, task.id)}`);
@@ -232,9 +230,11 @@ export default {
return {
state,
environmentName,
- iconStatusMap,
stageList,
+ taskIconClass,
humanize,
+ activeEnvironmentId,
+ activeStage,
clickTask,
};
},
diff --git a/frontend/src/miragejs/factories/task.js b/frontend/src/miragejs/factories/task.js
index 80f0597149..a1a6347574 100644
--- a/frontend/src/miragejs/factories/task.js
+++ b/frontend/src/miragejs/factories/task.js
@@ -13,7 +13,7 @@ export default {
return Date.now() - i * 3600 * 1000;
},
status() {
- return "RUNNING";
+ return "OPEN";
},
category() {
let dice = Math.random();
@@ -31,9 +31,6 @@ export default {
content() {
return faker.fake("{{lorem.paragraphs}}");
},
- currentStageId() {
- return "1";
- },
stageProgressList() {
return [
{
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 0af783b429..622f6586ca 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -84,8 +84,7 @@ export default function routes() {
...attrs,
createdTs: ts,
lastUpdatedTs: ts,
- status: "CREATED",
- currentStageId: attrs.stageProgressList[0].id,
+ status: "OPEN",
workspaceId: WORKSPACE_ID,
};
return schema.tasks.create(newTask);
diff --git a/frontend/src/miragejs/seeds/index.js b/frontend/src/miragejs/seeds/index.js
index c6cee650e7..d667dbec2a 100644
--- a/frontend/src/miragejs/seeds/index.js
+++ b/frontend/src/miragejs/seeds/index.js
@@ -58,7 +58,29 @@ const workspacesSeeder = (server) => {
const ws2DBA = server.schema.users.find(4);
const ws2Dev = server.schema.users.find(1);
- for (let i = 0; i < 15; i++) {
+ server.create("task", {
+ type: "bytebase.general",
+ creator: {
+ id: ws1Dev1.id,
+ name: ws1Dev1.name,
+ },
+ assignee: {
+ id: ws1Owner.id,
+ name: ws1Owner.name,
+ },
+ subscriberIdList: [ws1DBA.id, ws1Dev2.id],
+ stageProgressList: [
+ {
+ id: "1",
+ name: "Request",
+ type: "SIMPLE",
+ status: "PENDING",
+ },
+ ],
+ workspace: workspace1,
+ });
+
+ for (let i = 0; i < 5; i++) {
server.create("task", {
creator: {
id: ws1Dev1.id,
@@ -248,125 +270,156 @@ const fillStage = (environmentList) => {
const i = Math.floor(Math.random() * 5);
if (i % 5 == 0) {
return {
- status: "PENDING",
- currentStageId: environmentList[0].id,
+ status: "OPEN",
stageProgressList: [
{
- stageId: environmentList[0].id,
- stageName: environmentList[0].name,
+ id: "1",
+ name: environmentList[0].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[0].id,
status: "PENDING",
},
{
- stageId: environmentList[1].id,
- stageName: environmentList[1].name,
- status: "CREATED",
+ id: "2",
+ name: environmentList[1].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[1].id,
+ status: "PENDING",
},
],
};
} else if (i % 5 == 1) {
return {
- status: "RUNNING",
- currentStageId: environmentList[2].id,
+ status: "OPEN",
stageProgressList: [
{
- stageId: environmentList[0].id,
- stageName: environmentList[0].name,
+ id: "1",
+ name: environmentList[0].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[0].id,
status: "DONE",
},
{
- stageId: environmentList[1].id,
- stageName: environmentList[1].name,
+ id: "2",
+ name: environmentList[1].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[1].id,
status: "DONE",
},
{
- stageId: environmentList[2].id,
- stageName: environmentList[2].name,
+ id: "3",
+ name: environmentList[2].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[2].id,
status: "RUNNING",
},
{
- stageId: environmentList[3].id,
- stageName: environmentList[3].name,
- status: "CREATED",
+ id: "4",
+ name: environmentList[3].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[3].id,
+ status: "PENDING",
},
],
};
} else if (i % 5 == 2) {
return {
status: "DONE",
- currentStageId: environmentList[3].id,
stageProgressList: [
{
- stageId: environmentList[0].id,
- stageName: environmentList[0].name,
+ id: "1",
+ name: environmentList[0].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[0].id,
status: "DONE",
},
{
- stageId: environmentList[1].id,
- stageName: environmentList[1].name,
+ id: "2",
+ name: environmentList[1].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[1].id,
status: "SKIPPED",
},
{
- stageId: environmentList[2].id,
- stageName: environmentList[2].name,
+ id: "3",
+ name: environmentList[2].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[2].id,
status: "DONE",
},
{
- stageId: environmentList[3].id,
- stageName: environmentList[3].name,
+ id: "4",
+ name: environmentList[3].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[3].id,
status: "DONE",
},
],
};
} else if (i % 5 == 3) {
return {
- status: "FAILED",
- currentStageId: environmentList[1].id,
+ status: "OPEN",
stageProgressList: [
{
- stageId: environmentList[0].id,
- stageName: environmentList[0].name,
+ id: "1",
+ name: environmentList[0].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[0].id,
status: "DONE",
},
{
- stageId: environmentList[1].id,
- stageName: environmentList[1].name,
+ id: "2",
+ name: environmentList[1].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[1].id,
status: "FAILED",
},
{
- stageId: environmentList[2].id,
- stageName: environmentList[2].name,
- status: "CREATED",
+ id: "3",
+ name: environmentList[2].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[2].id,
+ status: "PENDING",
},
{
- stageId: environmentList[3].id,
- stageName: environmentList[3].name,
- status: "CREATED",
+ id: "4",
+ name: environmentList[3].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[3].id,
+ status: "PENDING",
},
],
};
} else {
return {
status: "CANCELED",
- currentStageId: environmentList[3].id,
stageProgressList: [
{
- stageId: environmentList[0].id,
- stageName: environmentList[0].name,
+ id: "1",
+ name: environmentList[0].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[0].id,
status: "DONE",
},
{
- stageId: environmentList[1].id,
- stageName: environmentList[1].name,
+ id: "2",
+ name: environmentList[1].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[1].id,
status: "SKIPPED",
},
{
- stageId: environmentList[2].id,
- stageName: environmentList[2].name,
+ id: "3",
+ name: environmentList[2].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[2].id,
status: "DONE",
},
{
- stageId: environmentList[3].id,
- stageName: environmentList[3].name,
+ id: "4",
+ name: environmentList[3].name,
+ type: "ENVIRONMENT",
+ environmentId: environmentList[3].id,
status: "CANCELED",
},
],
diff --git a/frontend/src/plugins/task/template.ts b/frontend/src/plugins/task/template.ts
index a5896ac208..24c9df886b 100644
--- a/frontend/src/plugins/task/template.ts
+++ b/frontend/src/plugins/task/template.ts
@@ -1,4 +1,4 @@
-import { TaskTemplate, TemplateContext, Stage } from "../types";
+import { TaskTemplate, TemplateContext } from "../types";
import { TaskNew } from "../../types";
export const taskTemplateList: TaskTemplate[] = [
@@ -13,10 +13,10 @@ export const taskTemplateList: TaskTemplate[] = [
content: "blablabla",
stageProgressList: [
{
- id: 1,
+ id: "1",
name: "Request",
type: "SIMPLE",
- status: "CREATED",
+ status: "PENDING",
},
],
creator: {
@@ -38,10 +38,10 @@ export const taskTemplateList: TaskTemplate[] = [
content: "blablabla",
stageProgressList: [
{
- id: 1,
+ id: "1",
name: "Request Data Source",
type: "ENVIRONMENT",
- status: "CREATED",
+ status: "PENDING",
},
],
creator: {
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
index d19879a5a4..6fb58cd695 100644
--- a/frontend/src/plugins/types.ts
+++ b/frontend/src/plugins/types.ts
@@ -1,15 +1,5 @@
import { Environment, TaskNew, User } from "../types";
-// Stage
-export type StageType = "SIMPLE" | "ENVIRONMENT";
-
-export type Stage = {
- // Similar to TaskField.id below
- id: number;
- name: string;
- type: StageType;
-};
-
// Task
export type TaskFieldType = "String";
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index aaba1a9261..5fae0472ff 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -1,11 +1,12 @@
import { ResourceObject } from "./jsonapi";
import { BBNotificationStyle } from "../bbkit/types";
-import { StageType } from "../plugins";
// These ID format may change in the future, so we encapsulate with a type.
// Also good for readability.
export type UserId = string;
+export type StageId = string;
+
export type TaskId = string;
export type GroupId = string;
@@ -38,27 +39,36 @@ export type NewBookmark = Omit<Bookmark, "id">;
export type Activity = ResourceObject & {};
export type ActivityNew = Omit<Activity, "id">;
-type TaskTypeGeneral = "bytebase.genera.create";
+// Stage
+export type StageType = "SIMPLE" | "ENVIRONMENT";
-type TaskTypeDataSource = "bytebase.datasource.create";
+export type StageStatus =
+ | "PENDING"
+ | "RUNNING"
+ | "DONE"
+ | "FAILED"
+ | "CANCELED"
+ | "SKIPPED";
-export type TaskType = TaskTypeGeneral & TaskTypeDataSource;
-
-export type StageProgress = {
- id: number;
+export type Stage = {
+ id: StageId;
name: string;
type: StageType;
- status:
- | "CREATED"
- | "PENDING"
- | "RUNNING"
- | "DONE"
- | "FAILED"
- | "CANCELED"
- | "SKIPPED";
+ environmentId?: EnvironmentId;
+};
+
+export type StageProgress = Stage & {
+ status: StageStatus;
};
-export type TaskStatus = "PENDING" | "RUNNING" | "DONE" | "FAILED" | "CANCELED";
+// Task
+type TaskTypeGeneral = "bytebase.genera.create";
+
+type TaskTypeDataSource = "bytebase.datasource.create";
+
+export type TaskType = TaskTypeGeneral & TaskTypeDataSource;
+
+export type TaskStatus = "OPEN" | "DONE" | "CANCELED";
export type Task = ResourceObject & {
attributes: {
@@ -69,7 +79,6 @@ export type Task = ResourceObject & {
category: "DDL" | "DML" | "OPS";
type: TaskType;
content: string;
- currentStageId: string;
stageProgressList: StageProgress[];
creator: {
id: string;
@@ -113,6 +122,7 @@ export type TaskPatch = {
payload?: any;
};
+// Environment
export type Environment = ResourceObject & {
attributes: {
name: string;
@@ -121,6 +131,7 @@ export type Environment = ResourceObject & {
};
export type EnvironmentNew = Omit<Environment, "id">;
+// Instance
export type Instance = ResourceObject & {
attributes: {
name: string;
@@ -132,6 +143,7 @@ export type Instance = ResourceObject & {
};
export type InstanceNew = Omit<Instance, "id">;
+// Data Source
export type DataSource = ResourceObject & {
attributes: {
name: string;
@@ -143,15 +155,19 @@ export type DataSource = ResourceObject & {
};
export type DataSourceNew = Omit<DataSource, "id">;
+// Group
export type Group = ResourceObject & {};
export type GroupNew = Omit<Group, "id">;
+// Project
export type Project = ResourceObject & {};
export type ProjectNew = Omit<Project, "id">;
+// Repository
export type Repository = ResourceObject & {};
export type RepositoryNew = Omit<Repository, "id">;
+// Auth
export type LoginInfo = Omit<
ResourceObject & {
attributes: {
diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts
index f78cf25193..bda445233b 100644
--- a/frontend/src/utils/index.ts
+++ b/frontend/src/utils/index.ts
@@ -1,3 +1,4 @@
export * from "./env";
export * from "./slug";
+export * from "./task";
export * from "./util";
diff --git a/frontend/src/utils/task.ts b/frontend/src/utils/task.ts
new file mode 100644
index 0000000000..db404c91e9
--- /dev/null
+++ b/frontend/src/utils/task.ts
@@ -0,0 +1,26 @@
+import { Task, StageProgress, EnvironmentId } from "../types";
+
+export function activeStage(task: Task): StageProgress {
+ for (const stageProgress of task.attributes.stageProgressList) {
+ if (
+ stageProgress.status === "PENDING" ||
+ stageProgress.status === "RUNNING" ||
+ // "FAILED" is also a transient stage status, which requires user
+ // to take further action (e.g. Cancel, Skip, Retry)
+ stageProgress.status === "FAILED"
+ ) {
+ return stageProgress;
+ }
+ }
+ return task.attributes.stageProgressList[
+ task.attributes.stageProgressList.length - 1
+ ];
+}
+
+export function activeEnvironmentId(task: Task): EnvironmentId | null {
+ const stageProgress = activeStage(task);
+ if (stageProgress.type === "ENVIRONMENT") {
+ return stageProgress.environmentId!;
+ }
+ return null;
+}
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index e0975994ca..ee5359e83c 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -71,16 +71,12 @@ export default {
for (const task of taskList) {
if (
task.attributes.assignee.id === currentUser!.id &&
- (task.attributes.status === "PENDING" ||
- task.attributes.status === "RUNNING" ||
- task.attributes.status === "FAILED")
+ task.attributes.status === "OPEN"
) {
state.attentionList.push(task);
} else if (
task.attributes.subscriberIdList.includes(currentUser!.id) &&
- (task.attributes.status === "PENDING" ||
- task.attributes.status === "RUNNING" ||
- task.attributes.status === "FAILED")
+ task.attributes.status === "OPEN"
) {
state.subscribeList.push(task);
} else if (
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index dddfb19a8c..e178668f2b 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -17,28 +17,83 @@
Create
</button>
</template>
- <template v-else>
+ <!-- Action Buttons only applicable to creator -->
+ <template
+ v-else-if="currentUser.id === state.task.attributes.creator.id"
+ >
<template v-if="pendingState() !== 'CLOSED'">
<button
type="button"
class="btn-normal px-4 py-2"
+ @click.prevent="doAbort"
:disabled="pendingState() === 'RUNNING'"
>
- Close
+ Abort
</button>
</template>
+ <template v-if="pendingState() === 'RESOLVE'">
+ <button
+ type="button"
+ class="btn-success px-4 py-2"
+ @click.prevent="doResolve"
+ >
+ Resolve
+ </button>
+ </template>
+ <template v-else-if="pendingState() === 'RUNNING'">
+ <button
+ type="button"
+ class="btn-primary px-4 py-2"
+ @click.prevent="doAbort"
+ >
+ Cancel
+ </button>
+ </template>
+ <template v-else-if="pendingState() === 'CLOSED'">
+ <button
+ type="button"
+ class="btn-normal px-4 py-2"
+ @click.prevent="doReopen"
+ >
+ Reopen
+ </button>
+ </template>
+ </template>
+ <!-- Action Buttons only applicable to assignee -->
+ <template
+ v-else-if="currentUser.id === state.task.attributes.assignee?.id"
+ >
<template v-if="pendingState() === 'APPROVAL'">
- <button type="button" class="btn-primary px-4 py-2">Approve</button>
+ <button
+ type="button"
+ class="btn-primary px-4 py-2"
+ @click.prevent="doApprove"
+ >
+ Approve
+ </button>
</template>
<template v-else-if="pendingState() === 'RESOLVE'">
- <button type="button" class="btn-success px-4 py-2">Resolve</button>
+ <button
+ v-if="
+ currentUser.id === state.task.attributes.assignee?.id ||
+ currentUser.id === state.task.attributes.creator.id
+ "
+ type="button"
+ class="btn-success px-4 py-2"
+ @click.prevent="doResolve"
+ >
+ Resolve
+ </button>
</template>
<template v-else-if="pendingState() === 'RUNNING'">
- <button type="button" class="btn-primary px-4 py-2">Cancel</button>
- </template>
- <template v-else-if="pendingState() === 'CLOSED'">
- <button type="button" class="btn-normal px-4 py-2">Reopen</button>
+ <button
+ type="button"
+ class="btn-primary px-4 py-2"
+ @click.prevent="doAbort"
+ >
+ Cancel
+ </button>
</template>
</template>
</TaskHighlightPanel>
@@ -106,8 +161,8 @@ import TaskContentBar from "../views/TaskContentBar.vue";
import TaskContent from "../views/TaskContent.vue";
import TaskActivityPanel from "../views/TaskActivityPanel.vue";
import TaskSidebar from "../views/TaskSidebar.vue";
-import { User, Task, TaskNew } from "../types";
-import { taskTemplateList, TaskField, Stage } from "../plugins";
+import { User, Task, TaskNew, TaskPatch } from "../types";
+import { taskTemplateList, TaskField } from "../plugins";
interface LocalState {
new: boolean;
@@ -166,13 +221,13 @@ export default {
(template) => template.type == state.task.attributes.type
)!;
- const prepareTask = () => {
- const updatededState = refreshState();
- state.new = updatededState.new;
- state.task = updatededState.task;
+ const refreshTask = () => {
+ const updatedState = refreshState();
+ state.new = updatedState.new;
+ state.task = updatedState.task;
};
- watchEffect(prepareTask);
+ watchEffect(refreshTask);
onMounted(() => {
// Always scroll to top, the scrollBehavior doesn't seem to work.
@@ -190,7 +245,6 @@ export default {
};
const doCreate = () => {
- console.log("Create", state.task);
store
.dispatch("task/createTask", state.task)
.then((createdTask) => {
@@ -203,6 +257,40 @@ export default {
});
};
+ const patchTask = (taskPatch: TaskPatch) => {
+ store
+ .dispatch("task/patchTask", {
+ taskId: (state.task as Task).id,
+ taskPatch,
+ })
+ .then((updatedTask) => {
+ state.task = cloneDeep(updatedTask);
+ })
+ .catch((error) => {
+ console.log(error);
+ });
+ };
+
+ const doAbort = () => {
+ patchTask({
+ status: "CANCELED",
+ });
+ };
+
+ const doApprove = () => {};
+
+ const doReopen = () => {
+ patchTask({
+ status: "OPEN",
+ });
+ };
+
+ const doResolve = () => {
+ patchTask({
+ status: "DONE",
+ });
+ };
+
const enableHighlightButton = (buttonIndex: number): boolean => {
if (state.new) {
// Create
@@ -236,7 +324,7 @@ export default {
if (currentStage.type === "SIMPLE") {
return "RESOLVE";
} else if (currentStage.type === "ENVIRONMENT") {
- if (state.task.attributes.status === "RUNNING") {
+ if (state.task.attributes.status === "OPEN") {
return "RUNNING";
}
return "APPROVAL";
@@ -252,8 +340,13 @@ export default {
humanize,
updateField,
doCreate,
+ doAbort,
+ doApprove,
+ doReopen,
+ doResolve,
enableHighlightButton,
pendingState,
+ currentUser,
};
},
};
diff --git a/frontend/src/views/TaskFlow.vue b/frontend/src/views/TaskFlow.vue
index 2bccd27b23..090854ff75 100644
--- a/frontend/src/views/TaskFlow.vue
+++ b/frontend/src/views/TaskFlow.vue
@@ -13,17 +13,17 @@
<span class="px-4 py-3 flex items-center text-sm font-medium">
<template
class="relative w-6 h-6 flex items-center justify-center rounded-full"
- :class="stepIconClass(stage.status)"
+ :class="stageIconClass(stage)"
>
- <template v-if="stage.status == 'CREATED'">
+ <template v-if="stage.status === 'PENDING'">
<span
- class="h-1.5 w-1.5 bg-gray-300 hover:bg-gray-400 rounded-full"
+ v-if="activeStage(task) === stage.id"
+ class="h-1.5 w-1.5 bg-blue-600 hover:bg-blue-700 rounded-full"
aria-hidden="true"
></span>
- </template>
- <template v-else-if="stage.status == 'PENDING'">
<span
- class="h-1.5 w-1.5 bg-blue-600 hover:bg-blue-700 rounded-full"
+ v-else
+ class="h-1.5 w-1.5 bg-gray-300 hover:bg-gray-400 rounded-full"
aria-hidden="true"
></span>
</template>
@@ -97,7 +97,7 @@
<span
class="ml-4 text-sm"
:class="
- stepTextClass(
+ stageTextClass(
task.currentStageId == stage.stageId,
stage.status
)
@@ -133,9 +133,11 @@
<script lang="ts">
import { PropType } from "vue";
-import { Task } from "../types";
+import { Task, Stage, StageId, StageStatus } from "../types";
+import { activeStage } from "../utils";
interface FlowItem {
+ id: StageId;
title: string;
status: string;
link: () => string;
@@ -154,21 +156,23 @@ export default {
const stageList: FlowItem[] = props.task.attributes.stageProgressList.map(
(stageProgress) => {
return {
+ id: stageProgress.id,
title: stageProgress.name,
status: stageProgress.status,
link: (): string => {
- return `/task/${props.task.id}#${stageProgress.id}`;
+ return `/task/${props.task.id}`;
},
};
}
);
- const stepIconClass = (status: string) => {
+ const stageIconClass = (stage: Stage) => {
switch (status) {
- case "CREATED":
- return "bg-white border-2 border-gray-300 hover:border-gray-400";
case "PENDING":
- return "bg-white border-2 border-blue-600 text-blue-600 hover:text-blue-700 hover:border-blue-700";
+ if (activeStage(props.task).id === stage.id) {
+ return "bg-white border-2 border-blue-600 text-blue-600 hover:text-blue-700 hover:border-blue-700";
+ }
+ return "bg-white border-2 border-gray-300 hover:border-gray-400";
case "RUNNING":
return "bg-white border-2 border-blue-600 text-blue-600 hover:text-blue-700 hover:border-blue-700";
case "DONE":
@@ -182,10 +186,9 @@ export default {
}
};
- const stepTextClass = (isCurrentStep: boolean, status: string) => {
+ const stageTextClass = (isCurrentStep: boolean, status: StageStatus) => {
let textClass = isCurrentStep ? "font-medium " : "font-normal ";
switch (status) {
- case "CREATED":
case "CANCELED":
case "SKIPPED":
return textClass + "text-gray-500";
@@ -201,8 +204,9 @@ export default {
return {
stageList,
- stepIconClass,
- stepTextClass,
+ activeStage,
+ stageIconClass,
+ stageTextClass,
};
},
};