Skip to content

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

refactor: re-implement pipeline, stage, task store modules with pinia (#1103)

Liu Ji23569db73e83
diff --git a/frontend/src/components/CreateInstanceForm.vue b/frontend/src/components/CreateInstanceForm.vue
index ec1ccc30e3..731b95915e 100644
--- a/frontend/src/components/CreateInstanceForm.vue
+++ b/frontend/src/components/CreateInstanceForm.vue
@@ -229,7 +229,6 @@
<script lang="ts" setup>
import { computed, reactive } from "vue";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import EnvironmentSelect from "./EnvironmentSelect.vue";
import CreateDataSourceExample from "./CreateDataSourceExample.vue";
@@ -254,7 +253,6 @@ interface LocalState {
const emit = defineEmits(["dismiss"]);
-const store = useStore();
const router = useRouter();
const { t } = useI18n();
const sqlStore = useSQLStore();
diff --git a/frontend/src/components/Issue/IssueDetailLayout.vue b/frontend/src/components/Issue/IssueDetailLayout.vue
index 597fc90dfd..45cfdbf1b2 100644
--- a/frontend/src/components/Issue/IssueDetailLayout.vue
+++ b/frontend/src/components/Issue/IssueDetailLayout.vue
@@ -215,7 +215,6 @@ import {
PropType,
watchEffect,
} from "vue";
-import { useStore } from "vuex";
import { useRoute, useRouter } from "vue-router";
import { cloneDeep, isEqual } from "lodash-es";
import {
@@ -282,6 +281,7 @@ import {
useIssueStore,
useIssueSubscriberStore,
useProjectStore,
+ useTaskStore,
} from "@/store";
export default defineComponent({
@@ -314,13 +314,13 @@ export default defineComponent({
"status-changed": (eager: boolean) => true,
},
setup(props, { emit }) {
- const store = useStore();
const router = useRouter();
const route = useRoute();
- const issueStore = useIssueStore();
- const issueSubscriberStore = useIssueSubscriberStore();
const currentUser = useCurrentUser();
+ const issueStore = useIssueStore();
+ const issueSubscriberStore = useIssueSubscriberStore();
+ const taskStore = useTaskStore();
const projectStore = useProjectStore();
watchEffect(function prepare() {
@@ -548,9 +548,8 @@ export default defineComponent({
status: newStatus,
comment: comment,
};
-
- store
- .dispatch("task/updateStatus", {
+ taskStore
+ .updateStatus({
issueId: (props.issue as Issue).id,
pipelineId: (props.issue as Issue).pipeline.id,
taskId: task.id,
@@ -563,8 +562,8 @@ export default defineComponent({
};
const runTaskChecks = (task: Task) => {
- store
- .dispatch("task/runChecks", {
+ taskStore
+ .runChecks({
issueId: (props.issue as Issue).id,
pipelineId: (props.issue as Issue).pipeline.id,
taskId: task.id,
@@ -600,8 +599,8 @@ export default defineComponent({
taskPatch: TaskPatch,
postUpdated?: (updatedTask: Task) => void
) => {
- store
- .dispatch("task/patchTask", {
+ taskStore
+ .patchTask({
issueId: (props.issue as Issue).id,
pipelineId: (props.issue as Issue).pipeline.id,
taskId,
diff --git a/frontend/src/store/pinia-modules/index.ts b/frontend/src/store/pinia-modules/index.ts
index 89d108a27f..5e0c74631f 100644
--- a/frontend/src/store/pinia-modules/index.ts
+++ b/frontend/src/store/pinia-modules/index.ts
@@ -19,17 +19,20 @@ export * from "./label";
export * from "./member";
export * from "./notification";
export * from "./oauth";
+export * from "./pipeline";
export * from "./policy";
export * from "./principal";
export * from "./project";
export * from "./projectWebhook";
export * from "./router";
export * from "./setting";
+export * from "./stage";
export * from "./sql";
export * from "./sqlEditor";
export * from "./subscription";
export * from "./tab";
export * from "./table";
+export * from "./task";
export * from "./uistate";
export * from "./vcs";
export * from "./view";
diff --git a/frontend/src/store/pinia-modules/instance.ts b/frontend/src/store/pinia-modules/instance.ts
index 3e968f261e..6fe555f643 100644
--- a/frontend/src/store/pinia-modules/instance.ts
+++ b/frontend/src/store/pinia-modules/instance.ts
@@ -27,7 +27,6 @@ import { useEnvironmentStore } from "./environment";
import { useAnomalyStore } from "./anomaly";
import { useDataSourceStore } from "./dataSource";
import { useSQLStore } from "./sql";
-import { store } from "../index";
import { defineStore } from "pinia";
import { computed, watchEffect } from "vue";
@@ -84,6 +83,8 @@ function convert(
};
const environmentStore = useEnvironmentStore();
+ const anomalyStore = useAnomalyStore();
+ const dataSourceStore = useDataSourceStore();
for (const item of includedList || []) {
if (
item.type == "environment" &&
@@ -101,7 +102,7 @@ function convert(
(anomaly: Anomaly) => parseInt(item.id) == anomaly.id
);
if (i != -1) {
- anomalyList[i] = useAnomalyStore().convert(item);
+ anomalyList[i] = anomalyStore.convert(item);
anomalyList[i].instance = instancePartial;
}
}
@@ -114,7 +115,7 @@ function convert(
(dataSource: DataSource) => parseInt(item.id) == dataSource.id
);
if (i != -1) {
- dataSourceList[i] = useDataSourceStore().convert(item);
+ dataSourceList[i] = dataSourceStore.convert(item);
}
}
}
diff --git a/frontend/src/store/pinia-modules/issue.ts b/frontend/src/store/pinia-modules/issue.ts
index fda0120838..e93a17ba61 100644
--- a/frontend/src/store/pinia-modules/issue.ts
+++ b/frontend/src/store/pinia-modules/issue.ts
@@ -22,8 +22,8 @@ import { getPrincipalFromIncludedList } from "./principal";
import { useActivityStore } from "./activity";
import { useDatabaseStore } from "./database";
import { useInstanceStore } from "./instance";
+import { usePipelineStore } from "./pipeline";
import { useProjectStore } from "./project";
-import { store } from "../index";
import { defineStore } from "pinia";
function convert(issue: ResourceObject, includedList: ResourceObject[]): Issue {
@@ -38,6 +38,7 @@ function convert(issue: ResourceObject, includedList: ResourceObject[]): Issue {
pipeline.id = parseInt(pipelineId);
const projectStore = useProjectStore();
+ const pipelineStore = usePipelineStore();
for (const item of includedList || []) {
if (
item.type == "project" &&
@@ -51,7 +52,7 @@ function convert(issue: ResourceObject, includedList: ResourceObject[]): Issue {
issue.relationships!.pipeline.data &&
(issue.relationships!.pipeline.data as ResourceIdentifier).id == item.id
) {
- pipeline = store.getters["pipeline/convert"](item, includedList);
+ pipeline = pipelineStore.convert(item, includedList);
}
}
diff --git a/frontend/src/store/modules/pipeline.ts b/frontend/src/store/pinia-modules/pipeline.ts
similarity index 64%
rename from frontend/src/store/modules/pipeline.ts
rename to frontend/src/store/pinia-modules/pipeline.ts
index a89ebc4183..2cecdffc85 100644
--- a/frontend/src/store/modules/pipeline.ts
+++ b/frontend/src/store/pinia-modules/pipeline.ts
@@ -4,28 +4,25 @@ import {
Pipeline,
PipelineState,
Stage,
-} from "../../types";
-import { getPrincipalFromIncludedList } from "../pinia";
-
-const state: () => PipelineState = () => ({});
+} from "@/types";
+import { defineStore } from "pinia";
+import { getPrincipalFromIncludedList } from "./principal";
+import { useStageStore } from "./stage";
function convert(
pipeline: ResourceObject,
- includedList: ResourceObject[],
- rootGetters: any
+ includedList: ResourceObject[]
): Pipeline {
const stageList: Stage[] = [];
const stageIdList = pipeline.relationships!.stage
.data as ResourceIdentifier[];
+ const stageStore = useStageStore();
// Needs to iterate through stageIdList to maintain the order
for (const idItem of stageIdList) {
for (const item of includedList || []) {
if (item.type == "stage") {
if (idItem.id == item.id) {
- const stage: Stage = rootGetters["stage/convertPartial"](
- item,
- includedList
- );
+ const stage: Stage = stageStore.convertPartial(item, includedList);
stageList.push(stage);
}
}
@@ -60,23 +57,14 @@ function convert(
return result;
}
-
-const getters = {
- convert:
- (state: PipelineState, getters: any, rootState: any, rootGetters: any) =>
- (pipeline: ResourceObject, includedList: ResourceObject[]): Pipeline => {
- return convert(pipeline, includedList, rootGetters);
+export const usePipelineStore = defineStore("pipeline", {
+ state: (): PipelineState => ({}),
+ actions: {
+ convert(
+ pipeline: ResourceObject,
+ includedList: ResourceObject[]
+ ): Pipeline {
+ return convert(pipeline, includedList);
},
-};
-
-const actions = {};
-
-const mutations = {};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
+ },
+});
diff --git a/frontend/src/store/modules/stage.ts b/frontend/src/store/pinia-modules/stage.ts
similarity index 74%
rename from frontend/src/store/modules/stage.ts
rename to frontend/src/store/pinia-modules/stage.ts
index 6e394d9eb2..67ee038f81 100644
--- a/frontend/src/store/modules/stage.ts
+++ b/frontend/src/store/pinia-modules/stage.ts
@@ -1,3 +1,4 @@
+import { defineStore } from "pinia";
import {
ResourceIdentifier,
ResourceObject,
@@ -8,18 +9,14 @@ import {
PipelineId,
Pipeline,
Environment,
-} from "../../types";
-import {
- getPrincipalFromIncludedList,
- useEnvironmentStore,
-} from "../pinia-modules";
-
-const state: () => StageState = () => ({});
+} from "@/types";
+import { getPrincipalFromIncludedList } from "./principal";
+import { useEnvironmentStore } from "./environment";
+import { useTaskStore } from "./task";
function convertPartial(
stage: ResourceObject,
- includedList: ResourceObject[],
- rootGetters: any
+ includedList: ResourceObject[]
): Omit<Stage, "pipeline"> {
let environment = unknown("ENVIRONMENT") as Environment;
if (stage.relationships?.environment.data) {
@@ -31,15 +28,13 @@ function convertPartial(
const taskList: Task[] = [];
const taskIdList = stage.relationships!.task.data as ResourceIdentifier[];
+ const taskStore = useTaskStore();
// Needs to iterate through taskIdList to maintain the order
for (const idItem of taskIdList) {
for (const item of includedList || []) {
if (item.type == "task") {
if (idItem.id == item.id) {
- const task: Task = rootGetters["task/convertPartial"](
- item,
- includedList
- );
+ const task = taskStore.convertPartial(item, includedList);
taskList.push(task);
}
}
@@ -78,17 +73,20 @@ function convertPartial(
return result;
}
-const getters = {
- convertPartial:
- (state: StageState, getters: any, rootState: any, rootGetters: any) =>
- (stage: ResourceObject, includedList: ResourceObject[]): Stage => {
+export const useStageStore = defineStore("stage", {
+ state: (): StageState => ({}),
+ actions: {
+ convertPartial(
+ stage: ResourceObject,
+ includedList: ResourceObject[]
+ ): Stage {
// It's only called when pipeline tries to convert itself, so we don't have a issue yet.
const pipelineId = stage.attributes.pipelineId as PipelineId;
const pipeline: Pipeline = unknown("PIPELINE") as Pipeline;
pipeline.id = pipelineId;
const result: Stage = {
- ...convertPartial(stage, includedList, rootGetters),
+ ...convertPartial(stage, includedList),
pipeline,
};
@@ -99,16 +97,5 @@ const getters = {
return result;
},
-};
-
-const actions = {};
-
-const mutations = {};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
+ },
+});
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/pinia-modules/task.ts
similarity index 70%
rename from frontend/src/store/modules/task.ts
rename to frontend/src/store/pinia-modules/task.ts
index e2d46d36fe..d4776ab4ae 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/pinia-modules/task.ts
@@ -17,16 +17,16 @@ import {
TaskState,
TaskStatusPatch,
unknown,
-} from "../../types";
-import { getPrincipalFromIncludedList } from "../pinia";
-import { useDatabaseStore, useInstanceStore } from "../pinia-modules";
-
-const state: () => TaskState = () => ({});
+} from "@/types";
+import { getPrincipalFromIncludedList } from "./principal";
+import { useDatabaseStore } from "./database";
+import { useInstanceStore } from "./instance";
+import { useIssueStore } from "./issue";
+import { defineStore } from "pinia";
function convertTaskRun(
taskRun: ResourceObject,
- includedList: ResourceObject[],
- rootGetters: any
+ includedList: ResourceObject[]
): TaskRun {
const result = taskRun.attributes.result
? JSON.parse((taskRun.attributes.result as string) || "{}")
@@ -56,8 +56,7 @@ function convertTaskRun(
function convertTaskCheckRun(
taskCheckRun: ResourceObject,
- includedList: ResourceObject[],
- rootGetters: any
+ includedList: ResourceObject[]
): TaskCheckRun {
const result = taskCheckRun.attributes.result
? JSON.parse((taskCheckRun.attributes.result as string) || "{}")
@@ -88,8 +87,7 @@ function convertTaskCheckRun(
function convertPartial(
task: ResourceObject,
- includedList: ResourceObject[],
- rootGetters: any
+ includedList: ResourceObject[]
): Omit<Task, "pipeline" | "stage"> {
const payload = task.attributes.payload
? JSON.parse((task.attributes.payload as string) || "{}")
@@ -103,11 +101,7 @@ function convertPartial(
for (const item of includedList || []) {
if (item.type == "taskRun") {
if (idItem.id == item.id) {
- const taskRun: TaskRun = convertTaskRun(
- item,
- includedList,
- rootGetters
- );
+ const taskRun: TaskRun = convertTaskRun(item, includedList);
taskRunList.push(taskRun);
}
}
@@ -124,8 +118,7 @@ function convertPartial(
if (idItem.id == item.id) {
const taskCheckRun: TaskCheckRun = convertTaskCheckRun(
item,
- includedList,
- rootGetters
+ includedList
);
taskCheckRunList.push(taskCheckRun);
}
@@ -142,12 +135,13 @@ function convertPartial(
let database = undefined;
const databaseStore = useDatabaseStore();
+ const instanceStore = useInstanceStore();
for (const item of includedList || []) {
if (
item.type == "instance" &&
(task.relationships!.instance.data as ResourceIdentifier).id == item.id
) {
- instance = useInstanceStore().convert(item, includedList);
+ instance = instanceStore.convert(item, includedList);
}
if (
item.type == "database" &&
@@ -189,10 +183,10 @@ function convertPartial(
};
}
-const getters = {
- convertPartial:
- (state: TaskState, getters: any, rootState: any, rootGetters: any) =>
- (task: ResourceObject, includedList: ResourceObject[]): Task => {
+export const useTaskStore = defineStore("task", {
+ state: (): TaskState => ({}),
+ actions: {
+ convertPartial(task: ResourceObject, includedList: ResourceObject[]) {
// It's only called when pipeline/stage tries to convert itself, so we don't have a issue yet.
const pipelineId = task.attributes.pipelineId as PipelineId;
const pipeline: Pipeline = unknown("PIPELINE") as Pipeline;
@@ -203,17 +197,12 @@ const getters = {
stage.id = stageId;
return {
- ...convertPartial(task, includedList, rootGetters),
+ ...convertPartial(task, includedList),
pipeline,
stage,
- };
+ } as Task;
},
-};
-
-const actions = {
- async updateStatus(
- { dispatch, rootGetters }: any,
- {
+ async updateStatus({
issueId,
pipelineId,
taskId,
@@ -223,26 +212,22 @@ const actions = {
pipelineId: PipelineId;
taskId: TaskId;
taskStatusPatch: TaskStatusPatch;
- }
- ) {
- const data = (
- await axios.patch(`/api/pipeline/${pipelineId}/task/${taskId}/status`, {
- data: {
- type: "taskStatusPatch",
- attributes: taskStatusPatch,
- },
- })
- ).data;
- const task = convertPartial(data.data, data.included, rootGetters);
-
- dispatch("issue/fetchIssueById", issueId, { root: true });
+ }) {
+ const data = (
+ await axios.patch(`/api/pipeline/${pipelineId}/task/${taskId}/status`, {
+ data: {
+ type: "taskStatusPatch",
+ attributes: taskStatusPatch,
+ },
+ })
+ ).data;
+ const task = this.convertPartial(data.data, data.included);
- return task;
- },
+ useIssueStore().fetchIssueById(issueId);
- async patchTask(
- { dispatch, rootGetters }: any,
- {
+ return task;
+ },
+ async patchTask({
issueId,
pipelineId,
taskId,
@@ -252,26 +237,22 @@ const actions = {
pipelineId: PipelineId;
taskId: TaskId;
taskPatch: TaskPatch;
- }
- ) {
- const data = (
- await axios.patch(`/api/pipeline/${pipelineId}/task/${taskId}`, {
- data: {
- type: "taskPatch",
- attributes: taskPatch,
- },
- })
- ).data;
- const task = convertPartial(data.data, data.included, rootGetters);
-
- dispatch("issue/fetchIssueById", issueId, { root: true });
+ }) {
+ const data = (
+ await axios.patch(`/api/pipeline/${pipelineId}/task/${taskId}`, {
+ data: {
+ type: "taskPatch",
+ attributes: taskPatch,
+ },
+ })
+ ).data;
+ const task = this.convertPartial(data.data, data.included);
- return task;
- },
+ useIssueStore().fetchIssueById(issueId);
- async runChecks(
- { dispatch, rootGetters }: any,
- {
+ return task;
+ },
+ async runChecks({
issueId,
pipelineId,
taskId,
@@ -279,25 +260,15 @@ const actions = {
issueId: IssueId;
pipelineId: PipelineId;
taskId: TaskId;
- }
- ) {
- const data = (
- await axios.post(`/api/pipeline/${pipelineId}/task/${taskId}/check`)
- ).data;
- const task = convertPartial(data.data, data.included, rootGetters);
+ }) {
+ const data = (
+ await axios.post(`/api/pipeline/${pipelineId}/task/${taskId}/check`)
+ ).data;
+ const task = this.convertPartial(data.data, data.included);
- dispatch("issue/fetchIssueById", issueId, { root: true });
+ useIssueStore().fetchIssueById(issueId);
- return task;
+ return task;
+ },
},
-};
-
-const mutations = {};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
+});
diff --git a/frontend/src/views/InstanceDetail.vue b/frontend/src/views/InstanceDetail.vue
index a80a37fcde..945c618991 100644
--- a/frontend/src/views/InstanceDetail.vue
+++ b/frontend/src/views/InstanceDetail.vue
@@ -139,7 +139,6 @@
<script lang="ts" setup>
import { computed, reactive, watchEffect } from "vue";
-import { useStore } from "vuex";
import { idFromSlug, isDBAOrOwner } from "../utils";
import ArchiveBanner from "../components/ArchiveBanner.vue";
import DatabaseTable from "../components/DatabaseTable.vue";
@@ -186,7 +185,6 @@ const props = defineProps({
},
});
-const store = useStore();
const instanceStore = useInstanceStore();
const subscriptionStore = useSubscriptionStore();
const { t } = useI18n();