Skip to content

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

Wire task to stage, task/stage to stage model properly.

天舟d8128f6cfee0
diff --git a/frontend/src/store/modules/stage.ts b/frontend/src/store/modules/stage.ts
index 82b0c0803c..450b14befb 100644
--- a/frontend/src/store/modules/stage.ts
+++ b/frontend/src/store/modules/stage.ts
@@ -5,6 +5,9 @@ import {
Stage,
StageState,
Step,
+ Task,
+ TaskId,
+ unknown,
} from "../../types";
const state: () => StageState = () => ({});
@@ -13,7 +16,7 @@ function convertPartial(
stage: ResourceObject,
includedList: ResourceObject[],
rootGetters: any
-): Omit<Stage, "Task"> {
+): Omit<Stage, "task"> {
const creator = rootGetters["principal/principalById"](
stage.attributes.creatorId
);
@@ -36,7 +39,7 @@ function convertPartial(
}
}
- return {
+ const result: Omit<Stage, "task"> = {
...(stage.attributes as Omit<
Stage,
"id" | "creator" | "updater" | "task" | "database" | "stepList"
@@ -47,6 +50,8 @@ function convertPartial(
database,
stepList,
};
+
+ return result;
}
const getters = {
@@ -55,12 +60,23 @@ const getters = {
getters: any,
rootState: any,
rootGetters: any
- ) => (
- stage: ResourceObject,
- includedList: ResourceObject[]
- ): Omit<Stage, "Task"> => {
- // It's only called when task tries to convert itself. So we pass empty includedList here to avoid circular dependency.
- return convertPartial(stage, includedList, rootGetters);
+ ) => (stage: ResourceObject, includedList: ResourceObject[]): Stage => {
+ // It's only called when task tries to convert itself, so we don't have a task yet.
+ const taskId = stage.attributes.taskId as TaskId;
+ let task: Task = unknown("TASK") as Task;
+ task.id = taskId;
+
+ const result: Stage = {
+ ...convertPartial(stage, includedList, rootGetters),
+ task,
+ };
+
+ for (const step of result.stepList) {
+ step.stage = result;
+ step.task = task;
+ }
+
+ return result;
},
};
diff --git a/frontend/src/store/modules/step.ts b/frontend/src/store/modules/step.ts
index f42fe5f172..7c09216842 100644
--- a/frontend/src/store/modules/step.ts
+++ b/frontend/src/store/modules/step.ts
@@ -5,6 +5,9 @@ import {
Step,
Task,
Stage,
+ unknown,
+ TaskId,
+ StageId,
} from "../../types";
const state: () => StepState = () => ({});
@@ -47,9 +50,21 @@ const getters = {
getters: any,
rootState: any,
rootGetters: any
- ) => (step: ResourceObject): Omit<Step, "task" | "stage"> => {
- // It's only called when task/stage tries to convert themselves. So we pass empty includedList here to avoid circular dependency.
- return convertPartial(step, rootGetters);
+ ) => (step: ResourceObject): Step => {
+ // It's only called when task/stage tries to convert themselves, so we don't have a task/stage yet.
+ const taskId = step.attributes.taskId as TaskId;
+ let task: Task = unknown("TASK") as Task;
+ task.id = taskId;
+
+ const stageId = step.attributes.stageId as StageId;
+ let stage: Stage = unknown("STAGE") as Stage;
+ stage.id = stageId;
+
+ return {
+ ...convertPartial(step, rootGetters),
+ task,
+ stage,
+ };
},
};
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index 91ec5ec450..4ce5eebaef 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -50,21 +50,24 @@ function convert(
item.type == "stage" &&
(item.relationships!.task.data as ResourceIdentifier).id == task.id
) {
- const stage = rootGetters["stage/convertPartial"](item, includedList);
+ const stage: Stage = rootGetters["stage/convertPartial"](
+ item,
+ includedList
+ );
stageList.push(stage);
}
if (
item.type == "project" &&
(item.relationships!.task.data as ResourceIdentifier[]).find(
- (item) => item.id == projectId
+ (item) => item.id == task.id
)
) {
project = rootGetters["project/convert"](item);
}
}
- return {
+ const result: Task = {
...(task.attributes as Omit<
Task,
| "id"
@@ -72,17 +75,28 @@ function convert(
| "creator"
| "updater"
| "assignee"
- | "stageList"
| "subscriberList"
+ | "stageList"
>),
id: task.id,
project,
creator,
updater,
assignee,
- stageList,
subscriberList,
+ stageList,
};
+
+ // Now we have a complate task, we assign it back to stage and step
+ for (const stage of result.stageList) {
+ stage.task = result;
+ for (const step of stage.stepList) {
+ step.task = result;
+ step.stage = stage;
+ }
+ }
+
+ return result;
}
const state: () => TaskState = () => ({
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 66babd7284..61c1d36322 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -182,6 +182,7 @@ export const unknown = (
name: "<<Unknown stage>>",
type: "bytebase.stage.general",
status: "PENDING",
+ task: UNKNOWN_TASK,
database: UNKNOWN_DATABASE,
stepList: [],
};
@@ -705,6 +706,7 @@ export type Stage = {
// Related fields
stepList: Step[];
+ task: Task;
database: Database;
// Standard fields