Skip to content

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

Initialize stageProgress upon creating the task

Tianzhou Chenec651cb2d951
diff --git a/frontend/src/components/TaskTable.vue b/frontend/src/components/TaskTable.vue
index dfe610ca92..9d862403c7 100644
--- a/frontend/src/components/TaskTable.vue
+++ b/frontend/src/components/TaskTable.vue
@@ -215,10 +215,10 @@ export default {
break;
}
return {
- title: stageProgress.stageName,
+ title: stageProgress.name,
status: stepStatus,
link: (): string => {
- return `/task/${task.id}#${stageProgress.stageId}`;
+ return `/task/${task.id}#${stageProgress.id}`;
},
};
});
diff --git a/frontend/src/plugins/task/template.ts b/frontend/src/plugins/task/template.ts
index 5f6234765f..a5896ac208 100644
--- a/frontend/src/plugins/task/template.ts
+++ b/frontend/src/plugins/task/template.ts
@@ -1,28 +1,55 @@
import { TaskTemplate, TemplateContext, Stage } from "../types";
+import { TaskNew } from "../../types";
export const taskTemplateList: TaskTemplate[] = [
{
type: "bytebase.general",
- stageListBuilder: (ctx: TemplateContext): Stage[] => {
- return [
- {
- id: 1,
- name: "Request",
- type: "SIMPLE",
+ buildTask: (ctx: TemplateContext): TaskNew => {
+ return {
+ type: "task",
+ attributes: {
+ name: "New General Task",
+ type: "bytebase.general",
+ content: "blablabla",
+ stageProgressList: [
+ {
+ id: 1,
+ name: "Request",
+ type: "SIMPLE",
+ status: "CREATED",
+ },
+ ],
+ creator: {
+ id: ctx.currentUser.id,
+ name: ctx.currentUser.attributes.name,
+ },
},
- ];
+ };
},
},
{
type: "bytebase.datasource.create",
- stageListBuilder: (ctx: TemplateContext): Stage[] => {
- return [
- {
- id: 1,
- name: "Request Data Source",
- type: "ENVIRONMENT",
+ buildTask: (ctx: TemplateContext): TaskNew => {
+ return {
+ type: "task",
+ attributes: {
+ name: "New Data Source",
+ type: "bytebase.datasource.create",
+ content: "blablabla",
+ stageProgressList: [
+ {
+ id: 1,
+ name: "Request Data Source",
+ type: "ENVIRONMENT",
+ status: "CREATED",
+ },
+ ],
+ creator: {
+ id: ctx.currentUser.id,
+ name: ctx.currentUser.attributes.name,
+ },
},
- ];
+ };
},
outputFieldList: [
{
diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.ts
index 9dcbc65870..d19879a5a4 100644
--- a/frontend/src/plugins/types.ts
+++ b/frontend/src/plugins/types.ts
@@ -1,11 +1,13 @@
-import { Environment } from "../types";
+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: "SIMPLE" | "ENVIRONMENT";
+ type: StageType;
};
// Task
@@ -38,6 +40,7 @@ export type TaskField = {
// Template
export type TemplateContext = {
environmentList: Environment[];
+ currentUser: User;
};
export type TemplateOutputField = {
@@ -49,7 +52,7 @@ export type TemplateOutputField = {
export type TaskTemplate = {
type: string;
- stageListBuilder: (ctx: TemplateContext) => Stage[];
+ buildTask: (ctx: TemplateContext) => TaskNew;
outputFieldList?: TemplateOutputField[];
fieldList?: TaskField[];
};
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index b6922c02dd..b466bba135 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -1,5 +1,6 @@
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.
@@ -43,6 +44,20 @@ type TaskTypeDataSource = "bytebase.datasource.create";
export type TaskType = TaskTypeGeneral & TaskTypeDataSource;
+export type StageProgress = {
+ id: number;
+ name: string;
+ type: StageType;
+ status:
+ | "CREATED"
+ | "PENDING"
+ | "RUNNING"
+ | "DONE"
+ | "FAILED"
+ | "CANCELED"
+ | "SKIPPED";
+};
+
export type Task = ResourceObject & {
attributes: {
name: string;
@@ -53,18 +68,7 @@ export type Task = ResourceObject & {
type: TaskType;
content: string;
currentStageId: string;
- stageProgressList: {
- stageId: string;
- stageName: string;
- status:
- | "CREATED"
- | "PENDING"
- | "RUNNING"
- | "DONE"
- | "FAILED"
- | "CANCELED"
- | "SKIPPED";
- }[];
+ stageProgressList: StageProgress[];
creator: {
id: string;
name: string;
@@ -83,15 +87,16 @@ export type TaskNew = Omit<ResourceObject, "id"> & {
name: string;
type: string;
content: string;
+ stageProgressList: StageProgress[];
creator: {
id: string;
name: string;
};
- assignee: {
+ assignee?: {
id: string;
name: string;
};
- payload: any;
+ payload?: any;
};
};
diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vue
index 2d0d8e8d7e..f663350ec2 100644
--- a/frontend/src/views/TaskDetail.vue
+++ b/frontend/src/views/TaskDetail.vue
@@ -136,25 +136,24 @@ export default {
const store = useStore();
const router = useRouter();
+ const environmentList = computed(() => {
+ return store.getters["environment/environmentList"]();
+ });
+
const currentUser = inject<User>(UserStateSymbol);
const refreshState = () => {
+ const generalTaskTemplate = taskTemplateList.find(
+ (template) => template.type == "bytebase.general"
+ )!;
return {
new: props.taskSlug.toLowerCase() == "new",
task:
props.taskSlug.toLowerCase() == "new"
- ? {
- type: "task",
- attributes: {
- name: "New General Task",
- type: "bytebase.general",
- content: "blablabla",
- creator: {
- id: currentUser!.id,
- name: currentUser!.attributes.name,
- },
- },
- }
+ ? generalTaskTemplate.buildTask({
+ environmentList: environmentList.value,
+ currentUser: currentUser!,
+ })
: cloneDeep(
store.getters["task/taskById"](idFromSlug(props.taskSlug))
),
@@ -163,6 +162,10 @@ export default {
const state = reactive<LocalState>(refreshState());
+ const template = taskTemplateList.find(
+ (template) => template.type == state.task.attributes.type
+ )!;
+
const prepareTask = () => {
const updatededState = refreshState();
state.new = updatededState.new;
@@ -171,18 +174,6 @@ export default {
watchEffect(prepareTask);
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"]();
- });
-
- const template = taskTemplateList.find(
- (template) => template.type == state.task.attributes.type
- )!;
-
- const stageList = template.stageListBuilder({
- environmentList: environmentList.value,
- });
-
onMounted(() => {
// Always scroll to top, the scrollBehavior doesn't seem to work.
// The hypothesis is that because the scroll bar is in the nested
@@ -238,7 +229,7 @@ export default {
) {
return "CLOSED";
} else {
- const currentStage = stageList.find(
+ const currentStage = (state.task as Task).attributes.stageProgressList.find(
(stage) => stage.id == state.task.attributes.currentStageId
);
if (currentStage) {
diff --git a/frontend/src/views/TaskFlow.vue b/frontend/src/views/TaskFlow.vue
index 61e0b532f1..513389a530 100644
--- a/frontend/src/views/TaskFlow.vue
+++ b/frontend/src/views/TaskFlow.vue
@@ -154,10 +154,10 @@ export default {
const stageList: FlowItem[] = props.task.attributes.stageProgressList.map(
(stageProgress) => {
return {
- title: stageProgress.stageName,
+ title: stageProgress.name,
status: stageProgress.status,
link: (): string => {
- return `/task/${props.task.id}#${stageProgress.stageId}`;
+ return `/task/${props.task.id}#${stageProgress.id}`;
},
};
}