Skip to content

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

refactor: re-implement environment store module with pinia (#1045)

Liu Ji13b97a687899
diff --git a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
index b8b85ff4a4..4e13baacec 100644
--- a/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
+++ b/frontend/src/components/AlterSchemaPrepForm/AlterSchemaPrepForm.vue
@@ -116,7 +116,7 @@ import CommonTenantView, {
} from "./CommonTenantView.vue";
import { NTabs, NTabPane } from "naive-ui";
import { useEventListener } from "@vueuse/core";
-import { hasFeature } from "@/store";
+import { hasFeature, useEnvironmentList } from "@/store";
type LocalState = ProjectStandardState &
ProjectTenantState &
@@ -186,9 +186,7 @@ export default defineComponent({
return state.project?.tenantMode === "TENANT";
});
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"](["NORMAL"]);
- });
+ const environmentList = useEnvironmentList(["NORMAL"]);
const databaseList = computed(() => {
var list;
diff --git a/frontend/src/components/AnomalyTable.vue b/frontend/src/components/AnomalyTable.vue
index 1cf0f11da3..ac4fd0a4d0 100644
--- a/frontend/src/components/AnomalyTable.vue
+++ b/frontend/src/components/AnomalyTable.vue
@@ -73,10 +73,9 @@
</template>
<script lang="ts">
-import { PropType, reactive } from "vue";
+import { defineComponent, PropType, reactive } from "vue";
import { useRouter } from "vue-router";
import { CodeDiff } from "v-code-diff";
-import { useStore } from "vuex";
import { useI18n } from "vue-i18n";
import { BBTableColumn, BBTableSectionDataSource } from "../bbkit/types";
@@ -90,6 +89,7 @@ import {
AnomalyType,
} from "../types";
import { databaseSlug, humanizeTs, instanceSlug } from "../utils";
+import { useEnvironmentStore } from "@/store";
type Action = {
onClick: () => void;
@@ -101,7 +101,7 @@ interface LocalState {
selectedAnomaly?: Anomaly;
}
-export default {
+export default defineComponent({
name: "AnomalyTable",
components: { CodeDiff },
props: {
@@ -115,7 +115,6 @@ export default {
},
},
setup() {
- const store = useStore();
const router = useRouter();
const { t } = useI18n();
@@ -167,7 +166,7 @@ export default {
case "bb.anomaly.instance.migration-schema":
return "Please create migration schema on the instance first.";
case "bb.anomaly.database.backup.policy-violation": {
- const environment = store.getters["environment/environmentById"](
+ const environment = useEnvironmentStore().getEnvironmentById(
anomaly.instance.environment.id
);
const payload =
@@ -288,5 +287,5 @@ export default {
dismissModal,
};
},
-};
+});
</script>
diff --git a/frontend/src/components/CreateDatabasePrepForm.vue b/frontend/src/components/CreateDatabasePrepForm.vue
index df145cf148..a84778cefd 100644
--- a/frontend/src/components/CreateDatabasePrepForm.vue
+++ b/frontend/src/components/CreateDatabasePrepForm.vue
@@ -236,7 +236,6 @@ import {
Project,
DatabaseLabel,
CreateDatabaseContext,
- Environment,
UNKNOWN_ID,
} from "../types";
import {
@@ -245,7 +244,7 @@ import {
issueSlug,
} from "../utils";
import { useEventListener } from "@vueuse/core";
-import { hasFeature } from "@/store";
+import { hasFeature, useEnvironmentStore } from "@/store";
interface LocalState {
projectId?: ProjectId;
@@ -500,9 +499,7 @@ export default defineComponent({
const key = "bb.environment";
const index = labelList.findIndex((label) => label.key === key);
if (envId) {
- const env = store.getters["environment/environmentById"](
- state.environmentId
- ) as Environment;
+ const env = useEnvironmentStore().getEnvironmentById(envId);
if (index >= 0) labelList[index].value = env.name;
else labelList.unshift({ key, value: env.name });
} else {
diff --git a/frontend/src/components/DatabaseListSidePanel.vue b/frontend/src/components/DatabaseListSidePanel.vue
index 563193f368..b80cb76586 100644
--- a/frontend/src/components/DatabaseListSidePanel.vue
+++ b/frontend/src/components/DatabaseListSidePanel.vue
@@ -22,7 +22,7 @@ import { BBOutlineItem } from "../bbkit/types";
import { Action, defineAction, useRegisterActions } from "@bytebase/vue-kbar";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
-import { useLabelStore } from "@/store";
+import { useEnvironmentList, useLabelStore } from "@/store";
import { storeToRefs } from "pinia";
export default defineComponent({
@@ -35,11 +35,10 @@ export default defineComponent({
const currentUser = computed(() => store.getters["auth/currentUser"]());
- const environmentList = computed(() => {
- return cloneDeep(
- store.getters["environment/environmentList"]()
- ).reverse();
- });
+ const rawEnvironmentList = useEnvironmentList();
+ const environmentList = computed(() =>
+ cloneDeep(rawEnvironmentList.value).reverse()
+ );
const prepareList = () => {
// It will also be called when user logout
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vue
index 0dc95e7f1f..0ee65f7bfa 100644
--- a/frontend/src/components/EnvironmentForm.vue
+++ b/frontend/src/components/EnvironmentForm.vue
@@ -49,7 +49,10 @@
<div class="-mt-0.5">
<div class="textlabel flex">
{{ $t("policy.approval.auto") }}
- <FeatureBadge feature="bb.feature.approval-policy" class="text-accent" />
+ <FeatureBadge
+ feature="bb.feature.approval-policy"
+ class="text-accent"
+ />
</div>
<div class="mt-1 textinfolabel">
{{ $t("policy.approval.auto-info") }}
@@ -91,7 +94,10 @@
<div class="-mt-0.5">
<div class="textlabel flex">
{{ $t("policy.backup.daily") }}
- <FeatureBadge feature="bb.feature.backup-policy" class="text-accent" />
+ <FeatureBadge
+ feature="bb.feature.backup-policy"
+ class="text-accent"
+ />
</div>
<div class="mt-1 textinfolabel">
{{ $t("policy.backup.daily-info") }}
@@ -110,7 +116,10 @@
<div class="-mt-0.5">
<div class="textlabel flex">
{{ $t("policy.backup.weekly") }}
- <FeatureBadge feature="bb.feature.backup-policy" class="text-accent" />
+ <FeatureBadge
+ feature="bb.feature.backup-policy"
+ class="text-accent"
+ />
</div>
<div class="mt-1 textinfolabel">
{{ $t("policy.backup.weekly-info") }}
@@ -192,7 +201,7 @@
</template>
<script lang="ts">
-import { computed, reactive, PropType, watch } from "vue";
+import { computed, reactive, PropType, watch, defineComponent } from "vue";
import { useStore } from "vuex";
import cloneDeep from "lodash-es/cloneDeep";
import isEqual from "lodash-es/isEqual";
@@ -204,6 +213,7 @@ import {
Policy,
} from "../types";
import { isDBAOrOwner } from "../utils";
+import { useEnvironmentList } from "@/store";
interface LocalState {
environment: Environment | EnvironmentCreate;
@@ -211,7 +221,7 @@ interface LocalState {
backupPolicy: Policy;
}
-export default {
+export default defineComponent({
name: "EnvironmentForm",
props: {
create: {
@@ -263,9 +273,7 @@ export default {
const currentUser = computed(() => store.getters["auth/currentUser"]());
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"]();
- });
+ const environmentList = useEnvironmentList();
const allowArchive = computed(() => {
return allowEdit.value && environmentList.value.length > 1;
@@ -357,5 +365,5 @@ export default {
restoreEnvironment,
};
},
-};
+});
</script>
diff --git a/frontend/src/components/EnvironmentSelect.vue b/frontend/src/components/EnvironmentSelect.vue
index 820812b07c..fbae0b10ab 100644
--- a/frontend/src/components/EnvironmentSelect.vue
+++ b/frontend/src/components/EnvironmentSelect.vue
@@ -32,9 +32,9 @@
<script lang="ts">
import { computed, defineComponent, reactive, watch } from "vue";
-import { useStore } from "vuex";
-import cloneDeep from "lodash-es/cloneDeep";
+import { cloneDeep } from "lodash-es";
import { Environment } from "../types";
+import { useEnvironmentList } from "@/store";
interface LocalState {
selectedId?: number;
@@ -58,16 +58,14 @@ export default defineComponent({
},
emits: ["select-environment-id"],
setup(props, { emit }) {
- const store = useStore();
const state = reactive<LocalState>({
selectedId: props.selectedId,
});
- const environmentList = computed(() => {
- return cloneDeep(
- store.getters["environment/environmentList"](["NORMAL", "ARCHIVED"])
- ).reverse();
- });
+ const rawEnvironmentList = useEnvironmentList(["NORMAL", "ARCHIVED"]);
+ const environmentList = computed(() =>
+ cloneDeep(rawEnvironmentList.value).reverse()
+ );
if (environmentList.value && environmentList.value.length > 0) {
if (
diff --git a/frontend/src/components/EnvironmentTabFilter.vue b/frontend/src/components/EnvironmentTabFilter.vue
index 5335633585..b5a7db79fa 100644
--- a/frontend/src/components/EnvironmentTabFilter.vue
+++ b/frontend/src/components/EnvironmentTabFilter.vue
@@ -16,11 +16,11 @@
<script lang="ts">
import { computed, defineComponent, reactive, watch } from "vue";
-import { useStore } from "vuex";
-import cloneDeep from "lodash-es/cloneDeep";
+import { cloneDeep } from "lodash-es";
import { Environment } from "../types";
import { BBTabFilterItem } from "../bbkit/types";
import { useI18n } from "vue-i18n";
+import { useEnvironmentList } from "@/store";
interface LocalState {
selectedIndex: number;
@@ -38,15 +38,13 @@ export default defineComponent({
emits: ["select-environment"],
setup(props) {
const { t } = useI18n();
- const store = useStore();
- const environmentList = computed(() => {
- // Usually env is ordered by ascending importance (dev -> test -> staging -> prod),
- // thus we reverse the order to put more important ones first.
- return cloneDeep(
- store.getters["environment/environmentList"]()
- ).reverse();
- });
+ // Usually env is ordered by ascending importance (dev -> test -> staging -> prod),
+ // thus we reverse the order to put more important ones first.
+ const rawEnvironmentList = useEnvironmentList();
+ const environmentList = computed(() =>
+ cloneDeep(rawEnvironmentList.value).reverse()
+ );
const state = reactive<LocalState>({
selectedIndex: props.selectedId
diff --git a/frontend/src/components/InstanceTable.vue b/frontend/src/components/InstanceTable.vue
index d3fffd21e6..e378b76100 100644
--- a/frontend/src/components/InstanceTable.vue
+++ b/frontend/src/components/InstanceTable.vue
@@ -39,21 +39,21 @@
</template>
<script lang="ts">
-import { reactive, PropType } from "vue";
-import { useStore } from "vuex";
+import { reactive, PropType, defineComponent } from "vue";
import { useRouter } from "vue-router";
import { BBTableColumn } from "../bbkit/types";
import InstanceEngineIcon from "./InstanceEngineIcon.vue";
import { urlfy, instanceSlug, environmentName } from "../utils";
import { EnvironmentId, Instance } from "../types";
import { useI18n } from "vue-i18n";
+import { useEnvironmentStore } from "@/store";
interface LocalState {
columnList: BBTableColumn[];
dataSource: any[];
}
-export default {
+export default defineComponent({
name: "InstanceTable",
components: { InstanceEngineIcon },
props: {
@@ -63,7 +63,6 @@ export default {
},
},
setup(props) {
- const store = useStore();
const { t } = useI18n();
const state = reactive<LocalState>({
@@ -98,7 +97,8 @@ export default {
};
const environmentNameFromId = function (id: EnvironmentId) {
- return environmentName(store.getters["environment/environmentById"](id));
+ const env = useEnvironmentStore().getEnvironmentById(id);
+ return environmentName(env);
};
const instanceLink = (instance: Instance): string => {
@@ -120,5 +120,5 @@ export default {
instanceLink,
};
},
-};
+});
</script>
diff --git a/frontend/src/components/Issue/IssueSidebar.vue b/frontend/src/components/Issue/IssueSidebar.vue
index b2324f3199..9732bef7a6 100644
--- a/frontend/src/components/Issue/IssueSidebar.vue
+++ b/frontend/src/components/Issue/IssueSidebar.vue
@@ -314,7 +314,7 @@ import {
import { useRouter } from "vue-router";
import dayjs from "dayjs";
import isSameOrAfter from "dayjs/plugin/isSameOrAfter";
-import { hasFeature, useLabelStore } from "@/store";
+import { hasFeature, useEnvironmentStore, useLabelStore } from "@/store";
import { storeToRefs } from "pinia";
dayjs.extend(isSameOrAfter);
@@ -433,9 +433,7 @@ export default defineComponent({
const environment = computed((): Environment => {
if (props.create) {
const stage = props.selectedStage as StageCreate;
- return store.getters["environment/environmentById"](
- stage.environmentId
- );
+ return useEnvironmentStore().getEnvironmentById(stage.environmentId);
}
const stage = props.selectedStage as Stage;
return stage.environment;
diff --git a/frontend/src/components/ProjectDeploymentConfigPanel.vue b/frontend/src/components/ProjectDeploymentConfigPanel.vue
index 6822e777d9..eec29c8ccf 100644
--- a/frontend/src/components/ProjectDeploymentConfigPanel.vue
+++ b/frontend/src/components/ProjectDeploymentConfigPanel.vue
@@ -128,7 +128,6 @@ import {
import { useStore } from "vuex";
import {
Project,
- Environment,
Database,
AvailableLabel,
DeploymentConfig,
@@ -143,7 +142,13 @@ import { cloneDeep, isEqual } from "lodash-es";
import { useI18n } from "vue-i18n";
import { NPopover, useDialog } from "naive-ui";
import { generateDefaultSchedule, validateDeploymentConfig } from "../utils";
-import { pushNotification, useDeploymentStore, useLabelStore } from "@/store";
+import {
+ pushNotification,
+ useDeploymentStore,
+ useEnvironmentList,
+ useEnvironmentStore,
+ useLabelStore,
+} from "@/store";
import { storeToRefs } from "pinia";
type LocalState = {
@@ -191,14 +196,12 @@ export default defineComponent({
});
const prepareList = () => {
- store.dispatch("environment/fetchEnvironmentList");
+ useEnvironmentStore().fetchEnvironmentList();
labelStore.fetchLabelList();
store.dispatch("database/fetchDatabaseListByProjectId", props.project.id);
};
- const environmentList = computed(
- () => store.getters["environment/environmentList"]() as Environment[]
- );
+ const environmentList = useEnvironmentList();
const { labelList } = storeToRefs(labelStore);
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index 26b3460106..adbae62ceb 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -3,7 +3,7 @@
</template>
<script lang="ts">
-import { useSettingStore, useUIStateStore } from "@/store";
+import { useEnvironmentStore, useSettingStore, useUIStateStore } from "@/store";
import { defineComponent } from "vue";
import { useStore } from "vuex";
import { DEFAULT_PROJECT_ID } from "../types";
@@ -22,7 +22,7 @@ export default defineComponent({
// the principal list as well.
// We also need this to render the proper inbox and activity entry.
store.dispatch("principal/fetchPrincipalList"),
- store.dispatch("environment/fetchEnvironmentList"),
+ useEnvironmentStore().fetchEnvironmentList(),
// The default project hosts databases not explicitly assigned to other users project.
store.dispatch("project/fetchProjectById", DEFAULT_PROJECT_ID),
useUIStateStore().restoreState(),
diff --git a/frontend/src/components/RequestDatabasePrepForm.vue b/frontend/src/components/RequestDatabasePrepForm.vue
index 8e7805a850..c76591a68b 100644
--- a/frontend/src/components/RequestDatabasePrepForm.vue
+++ b/frontend/src/components/RequestDatabasePrepForm.vue
@@ -128,7 +128,13 @@
</template>
<script lang="ts">
-import { computed, reactive, onMounted, onUnmounted } from "vue";
+import {
+ computed,
+ reactive,
+ onMounted,
+ onUnmounted,
+ defineComponent,
+} from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import isEmpty from "lodash-es/isEmpty";
@@ -137,6 +143,7 @@ import DatabaseSelect from "../components/DatabaseSelect.vue";
import EnvironmentSelect from "../components/EnvironmentSelect.vue";
import { DatabaseId, EnvironmentId, ProjectId, UNKNOWN_ID } from "../types";
import { allowDatabaseAccess } from "../utils";
+import { useEnvironmentStore } from "@/store";
interface LocalState {
environmentId: EnvironmentId;
@@ -148,7 +155,7 @@ interface LocalState {
readonly: boolean;
}
-export default {
+export default defineComponent({
name: "RequestDatabasePrepForm",
components: { ProjectSelect, DatabaseSelect, EnvironmentSelect },
props: {},
@@ -215,7 +222,7 @@ export default {
const request = () => {
emit("dismiss");
- const environment = store.getters["environment/environmentById"](
+ const environment = useEnvironmentStore().getEnvironmentById(
state.environmentId
);
if (state.create == "ON") {
@@ -263,5 +270,5 @@ export default {
request,
};
},
-};
+});
</script>
diff --git a/frontend/src/components/TenantDatabaseTable/TenantDatabaseTable.vue b/frontend/src/components/TenantDatabaseTable/TenantDatabaseTable.vue
index bd7f9be944..62459a540f 100644
--- a/frontend/src/components/TenantDatabaseTable/TenantDatabaseTable.vue
+++ b/frontend/src/components/TenantDatabaseTable/TenantDatabaseTable.vue
@@ -15,17 +15,11 @@
<script lang="ts">
import { computed, defineComponent, PropType, watchEffect } from "vue";
-import { useStore } from "vuex";
-import {
- Database,
- Environment,
- Label,
- Project,
- LabelKeyType,
-} from "../../types";
+import { Database, Label, Project, LabelKeyType } from "../../types";
import { groupBy } from "lodash-es";
import DatabaseMatrix from "./DatabaseMatrix.vue";
import { parseDatabaseNameByTemplate } from "../../utils";
+import { useEnvironmentList, useEnvironmentStore } from "@/store";
type Mode = "ALL" | "ALL_SHORT" | "INSTANCE" | "PROJECT" | "PROJECT_SHORT";
@@ -68,16 +62,12 @@ export default defineComponent({
},
},
setup(props) {
- const store = useStore();
-
const prepareList = () => {
- store.dispatch("environment/fetchEnvironmentList");
+ useEnvironmentStore().fetchEnvironmentList();
};
watchEffect(prepareList);
- const environmentList = computed(
- () => store.getters["environment/environmentList"]() as Environment[]
- );
+ const environmentList = useEnvironmentList();
const databaseListGroupByName = computed((): DatabaseGroupByName[] => {
if (props.project.dbNameTemplate) {
diff --git a/frontend/src/components/TransferDatabaseForm.vue b/frontend/src/components/TransferDatabaseForm.vue
index df8304cd8e..8467fd4b64 100644
--- a/frontend/src/components/TransferDatabaseForm.vue
+++ b/frontend/src/components/TransferDatabaseForm.vue
@@ -111,7 +111,7 @@ import {
DatabaseLabel,
} from "../types";
import { sortDatabaseList } from "../utils";
-import { pushNotification } from "@/store";
+import { pushNotification, useEnvironmentList } from "@/store";
type TransferSource = "DEFAULT" | "OTHER";
@@ -152,9 +152,7 @@ export default defineComponent({
watchEffect(prepareDatabaseListForDefaultProject);
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"](["NORMAL"]);
- });
+ const environmentList = useEnvironmentList(["NORMAL"]);
const databaseList = computed(() => {
var list;
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index e5e13c6143..9e175bc6d8 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -12,8 +12,8 @@ import InstanceLayout from "../layouts/InstanceLayout.vue";
import SplashLayout from "../layouts/SplashLayout.vue";
import SqlEditorLayout from "../layouts/SqlEditorLayout.vue";
import { t } from "../plugins/i18n";
-import { store, useRouterStore } from "../store";
-import { Database, QuickActionType, Sheet } from "../types";
+import { store, useEnvironmentStore, useRouterStore } from "../store";
+import { Database, QuickActionType, Sheet, UNKNOWN_ID } from "../types";
import { idFromSlug, isDBAOrOwner, isOwner } from "../utils";
// import PasswordReset from "../views/auth/PasswordReset.vue";
import Signin from "../views/auth/Signin.vue";
@@ -395,7 +395,7 @@ const routes: Array<RouteRecordRaw> = [
meta: {
title: (route: RouteLocationNormalized) => {
const slug = route.params.environmentSlug as string;
- return store.getters["environment/environmentById"](
+ return useEnvironmentStore().getEnvironmentById(
idFromSlug(slug)
).name;
},
@@ -795,6 +795,7 @@ export const router = createRouter({
router.beforeEach((to, from, next) => {
console.debug("Router %s -> %s", from.name, to.name);
+ const environmentStore = useEnvironmentStore();
const tabStore = useTabStore();
const routerStore = useRouterStore();
@@ -948,9 +949,12 @@ router.beforeEach((to, from, next) => {
}
if (environmentSlug) {
- if (
- store.getters["environment/environmentById"](idFromSlug(environmentSlug))
- ) {
+ const env = environmentStore.getEnvironmentById(
+ idFromSlug(environmentSlug)
+ );
+ // getEnvironmentById returns unknown("ENVIRONMENT") when it doesn't exist
+ // so we need to check the id here
+ if (env && env.id !== UNKNOWN_ID) {
next();
return;
}
diff --git a/frontend/src/store/modules/environment.ts b/frontend/src/store/modules/environment.ts
deleted file mode 100644
index 5c9a40ac68..0000000000
--- a/frontend/src/store/modules/environment.ts
+++ /dev/null
@@ -1,212 +0,0 @@
-import axios from "axios";
-import {
- empty,
- EMPTY_ID,
- Environment,
- EnvironmentCreate,
- EnvironmentId,
- EnvironmentPatch,
- EnvironmentState,
- ResourceObject,
- RowStatus,
- unknown,
-} from "../../types";
-import { usePolicyStore } from "../pinia-modules";
-import { getPrincipalFromIncludedList } from "./principal";
-
-function convert(
- environment: ResourceObject,
- includedList: ResourceObject[],
- rootGetters: any
-): Environment {
- return {
- ...(environment.attributes as Omit<
- Environment,
- "id" | "creator" | "updater"
- >),
- id: parseInt(environment.id),
- creator: getPrincipalFromIncludedList(
- environment.relationships!.creator.data,
- includedList
- ),
- updater: getPrincipalFromIncludedList(
- environment.relationships!.updater.data,
- includedList
- ),
- };
-}
-
-const state: () => EnvironmentState = () => ({
- environmentList: [],
-});
-
-const getters = {
- convert:
- (state: EnvironmentState, getters: any, rootState: any, rootGetters: any) =>
- (
- environment: ResourceObject,
- inlcudedList: ResourceObject[]
- ): Environment => {
- return convert(environment, inlcudedList, rootGetters);
- },
-
- environmentList:
- (state: EnvironmentState) =>
- (rowStatusList?: RowStatus[]): Environment[] => {
- return state.environmentList.filter((environment: Environment) => {
- return (
- (!rowStatusList && environment.rowStatus == "NORMAL") ||
- (rowStatusList && rowStatusList.includes(environment.rowStatus))
- );
- });
- },
-
- environmentById:
- (state: EnvironmentState) =>
- (environmentId: EnvironmentId): Environment => {
- if (environmentId == EMPTY_ID) {
- return empty("ENVIRONMENT") as Environment;
- }
-
- for (const environment of state.environmentList) {
- if (environment.id == environmentId) {
- return environment;
- }
- }
- return unknown("ENVIRONMENT") as Environment;
- },
-};
-
-const actions = {
- async fetchEnvironmentList(
- { dispatch, commit, rootGetters }: any,
- rowStatusList?: RowStatus[]
- ) {
- const path =
- "/api/environment" +
- (rowStatusList ? "?rowstatus=" + rowStatusList.join(",") : "");
- const data = (await axios.get(path)).data;
- const environmentList = data.data.map((env: ResourceObject) => {
- return convert(env, data.included, rootGetters);
- });
-
- commit("upsertEnvironmentList", environmentList);
-
- const policyStore = usePolicyStore();
- for (const environment of environmentList) {
- await policyStore.fetchPolicyByEnvironmentAndType({
- environmentId: environment.id,
- type: "bb.policy.pipeline-approval",
- });
- }
-
- return environmentList;
- },
-
- async createEnvironment(
- { dispatch, commit, rootGetters }: any,
- newEnvironment: EnvironmentCreate
- ) {
- const data = (
- await axios.post(`/api/environment`, {
- data: {
- type: "environment",
- attributes: newEnvironment,
- },
- })
- ).data;
- const createdEnvironment = convert(data.data, data.included, rootGetters);
-
- commit("upsertEnvironmentList", [createdEnvironment]);
-
- await usePolicyStore().fetchPolicyByEnvironmentAndType({
- environmentId: createdEnvironment.id,
- type: "bb.policy.pipeline-approval",
- });
-
- return createdEnvironment;
- },
-
- async reorderEnvironmentList(
- { commit, rootGetters }: any,
- orderedEnvironmentList: Environment[]
- ) {
- const list: any[] = [];
- orderedEnvironmentList.forEach((item, index) => {
- list.push({
- // Server uses google/jsonapi which expects a string type for the special id field.
- // Afterwards, server will automatically serialize into int as declared by the EnvironmentPatch interface.
- id: item.id.toString(),
- type: "environmentPatch",
- attributes: {
- order: index,
- },
- });
- });
- const data = (
- await axios.patch(`/api/environment/reorder`, {
- data: list,
- })
- ).data;
- const environmentList = data.data.map((env: ResourceObject) => {
- return convert(env, data.included, rootGetters);
- });
-
- commit("upsertEnvironmentList", environmentList);
-
- return environmentList;
- },
-
- async patchEnvironment(
- { commit, rootGetters }: any,
- {
- environmentId,
- environmentPatch,
- }: {
- environmentId: EnvironmentId;
- environmentPatch: EnvironmentPatch;
- }
- ) {
- const data = (
- await axios.patch(`/api/environment/${environmentId}`, {
- data: {
- type: "environmentPatch",
- attributes: environmentPatch,
- },
- })
- ).data;
- const updatedEnvironment = convert(data.data, data.included, rootGetters);
-
- commit("upsertEnvironmentList", [updatedEnvironment]);
-
- return updatedEnvironment;
- },
-};
-
-const mutations = {
- upsertEnvironmentList(
- state: EnvironmentState,
- environmentList: Environment[]
- ) {
- for (const environment of environmentList) {
- const i = state.environmentList.findIndex(
- (item: Environment) => item.id == environment.id
- );
- if (i != -1) {
- state.environmentList[i] = environment;
- } else {
- state.environmentList.push(environment);
- }
-
- state.environmentList.sort((a, b) => a.order - b.order);
- }
- },
-};
-
-export default {
- namespaced: true,
- state,
- getters,
- actions,
- mutations,
-};
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index e378d0334c..6b85bebbe7 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -22,6 +22,7 @@ import {
unknown,
} from "../../types";
import { InstanceUser } from "../../types/InstanceUser";
+import { useEnvironmentStore } from "../pinia-modules";
import { getPrincipalFromIncludedList } from "./principal";
function convert(
@@ -77,13 +78,14 @@ function convert(
dataSourceList: [],
};
+ const environmentStore = useEnvironmentStore();
for (const item of includedList || []) {
if (
item.type == "environment" &&
(instance.relationships!.environment.data as ResourceIdentifier).id ==
item.id
) {
- environment = rootGetters["environment/convert"](item, includedList);
+ environment = environmentStore.convert(item, includedList);
}
if (
diff --git a/frontend/src/store/modules/stage.ts b/frontend/src/store/modules/stage.ts
index f0939cb4e7..5cd31c7b73 100644
--- a/frontend/src/store/modules/stage.ts
+++ b/frontend/src/store/modules/stage.ts
@@ -9,6 +9,7 @@ import {
Pipeline,
Environment,
} from "../../types";
+import { useEnvironmentStore } from "../pinia-modules";
import { getPrincipalFromIncludedList } from "./principal";
const state: () => StageState = () => ({});
@@ -43,13 +44,14 @@ function convertPartial(
}
}
+ const environmentStore = useEnvironmentStore();
for (const item of includedList || []) {
if (
item.type == "environment" &&
(stage.relationships!.environment.data as ResourceIdentifier).id ==
item.id
) {
- environment = rootGetters["environment/convert"](item, includedList);
+ environment = environmentStore.convert(item, includedList);
}
}
diff --git a/frontend/src/store/pinia-modules/environment.ts b/frontend/src/store/pinia-modules/environment.ts
new file mode 100644
index 0000000000..2da638eb9f
--- /dev/null
+++ b/frontend/src/store/pinia-modules/environment.ts
@@ -0,0 +1,181 @@
+import axios from "axios";
+import {
+ empty,
+ EMPTY_ID,
+ Environment,
+ EnvironmentCreate,
+ EnvironmentId,
+ EnvironmentPatch,
+ EnvironmentState,
+ ResourceObject,
+ RowStatus,
+ unknown,
+} from "../../types";
+import { usePolicyStore } from "./policy";
+import { getPrincipalFromIncludedList } from "../modules/principal";
+import { defineStore } from "pinia";
+import { computed } from "vue";
+
+function convert(
+ environment: ResourceObject,
+ includedList: ResourceObject[]
+): Environment {
+ return {
+ ...(environment.attributes as Omit<
+ Environment,
+ "id" | "creator" | "updater"
+ >),
+ id: parseInt(environment.id),
+ creator: getPrincipalFromIncludedList(
+ environment.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ environment.relationships!.updater.data,
+ includedList
+ ),
+ };
+}
+
+export const useEnvironmentStore = defineStore("environment", {
+ state: (): EnvironmentState => ({
+ environmentList: [],
+ }),
+ actions: {
+ convert(
+ environment: ResourceObject,
+ includedList: ResourceObject[]
+ ): Environment {
+ return convert(environment, includedList);
+ },
+ getEnvironmentList(rowStatusList?: RowStatus[]): Environment[] {
+ return this.environmentList.filter((environment: Environment) => {
+ return (
+ (!rowStatusList && environment.rowStatus == "NORMAL") ||
+ (rowStatusList && rowStatusList.includes(environment.rowStatus))
+ );
+ });
+ },
+ getEnvironmentById(environmentId: EnvironmentId): Environment {
+ if (environmentId == EMPTY_ID) {
+ return empty("ENVIRONMENT") as Environment;
+ }
+
+ for (const environment of this.environmentList) {
+ if (environment.id == environmentId) {
+ return environment;
+ }
+ }
+ return unknown("ENVIRONMENT") as Environment;
+ },
+ upsertEnvironmentList(environmentList: Environment[]) {
+ for (const environment of environmentList) {
+ const i = this.environmentList.findIndex(
+ (item: Environment) => item.id == environment.id
+ );
+ if (i != -1) {
+ this.environmentList[i] = environment;
+ } else {
+ this.environmentList.push(environment);
+ }
+
+ this.environmentList.sort((a, b) => a.order - b.order);
+ }
+ },
+ async fetchEnvironmentList(rowStatusList?: RowStatus[]) {
+ const path =
+ "/api/environment" +
+ (rowStatusList ? "?rowstatus=" + rowStatusList.join(",") : "");
+ const data = (await axios.get(path)).data;
+ const environmentList: Environment[] = data.data.map(
+ (env: ResourceObject) => {
+ return convert(env, data.included);
+ }
+ );
+ this.upsertEnvironmentList(environmentList);
+
+ const policyStore = usePolicyStore();
+ for (const environment of environmentList) {
+ await policyStore.fetchPolicyByEnvironmentAndType({
+ environmentId: environment.id,
+ type: "bb.policy.pipeline-approval",
+ });
+ }
+
+ return environmentList;
+ },
+ async createEnvironment(newEnvironment: EnvironmentCreate) {
+ const data = (
+ await axios.post(`/api/environment`, {
+ data: {
+ type: "environment",
+ attributes: newEnvironment,
+ },
+ })
+ ).data;
+ const createdEnvironment = convert(data.data, data.included);
+
+ this.upsertEnvironmentList([createdEnvironment]);
+
+ await usePolicyStore().fetchPolicyByEnvironmentAndType({
+ environmentId: createdEnvironment.id,
+ type: "bb.policy.pipeline-approval",
+ });
+
+ return createdEnvironment;
+ },
+ async reorderEnvironmentList(orderedEnvironmentList: Environment[]) {
+ const list: any[] = [];
+ orderedEnvironmentList.forEach((item, index) => {
+ list.push({
+ // Server uses google/jsonapi which expects a string type for the special id field.
+ // Afterwards, server will automatically serialize into int as declared by the EnvironmentPatch interface.
+ id: item.id.toString(),
+ type: "environmentPatch",
+ attributes: {
+ order: index,
+ },
+ });
+ });
+ const data = (
+ await axios.patch(`/api/environment/reorder`, {
+ data: list,
+ })
+ ).data;
+ const environmentList: Environment[] = data.data.map(
+ (env: ResourceObject) => {
+ return convert(env, data.included);
+ }
+ );
+ this.upsertEnvironmentList(environmentList);
+
+ return environmentList;
+ },
+ async patchEnvironment({
+ environmentId,
+ environmentPatch,
+ }: {
+ environmentId: EnvironmentId;
+ environmentPatch: EnvironmentPatch;
+ }) {
+ const data = (
+ await axios.patch(`/api/environment/${environmentId}`, {
+ data: {
+ type: "environmentPatch",
+ attributes: environmentPatch,
+ },
+ })
+ ).data;
+ const updatedEnvironment = convert(data.data, data.included);
+
+ this.upsertEnvironmentList([updatedEnvironment]);
+
+ return updatedEnvironment;
+ },
+ },
+});
+
+export const useEnvironmentList = (rowStatusList?: RowStatus[]) => {
+ const store = useEnvironmentStore();
+ return computed(() => store.getEnvironmentList(rowStatusList));
+};
diff --git a/frontend/src/store/pinia-modules/index.ts b/frontend/src/store/pinia-modules/index.ts
index fae2197d3a..35c0fb6381 100644
--- a/frontend/src/store/pinia-modules/index.ts
+++ b/frontend/src/store/pinia-modules/index.ts
@@ -4,6 +4,7 @@ export * from "./bookmark";
export * from "./command";
export * from "./debug";
export * from "./deployment";
+export * from "./environment";
export * from "./issueSubscriber";
export * from "./label";
export * from "./notification";
diff --git a/frontend/src/store/pinia-modules/policy.ts b/frontend/src/store/pinia-modules/policy.ts
index ab51788d3e..6ea62aa3a3 100644
--- a/frontend/src/store/pinia-modules/policy.ts
+++ b/frontend/src/store/pinia-modules/policy.ts
@@ -9,8 +9,8 @@ import {
} from "@/types";
import { Policy, PolicyType, PolicyUpsert } from "@/types/policy";
import { getPrincipalFromIncludedList } from "../modules/principal";
-import { store } from "../index";
import { defineStore } from "pinia";
+import { useEnvironmentStore } from "./environment";
function convert(
policy: ResourceObject,
@@ -22,13 +22,14 @@ function convert(
let environment: Environment = unknown("ENVIRONMENT") as Environment;
environment.id = parseInt(environmentId);
+ const environmentStore = useEnvironmentStore();
for (const item of includedList || []) {
if (
item.type == "environment" &&
(policy.relationships!.environment.data as ResourceIdentifier).id ==
item.id
) {
- environment = store.getters["environment/convert"](item, includedList);
+ environment = environmentStore.convert(item, includedList);
}
}
diff --git a/frontend/src/views/AnomalyCenterDashboard.vue b/frontend/src/views/AnomalyCenterDashboard.vue
index 9ee5be6e74..e8f719b316 100644
--- a/frontend/src/views/AnomalyCenterDashboard.vue
+++ b/frontend/src/views/AnomalyCenterDashboard.vue
@@ -141,7 +141,7 @@ import {
} from "../utils";
import { BBTabFilterItem, BBTableSectionDataSource } from "../bbkit/types";
import { cloneDeep } from "lodash-es";
-import { featureToRef } from "@/store";
+import { featureToRef, useEnvironmentList } from "@/store";
const DATABASE_TAB = 0;
const INSTANCE_TAB = 1;
@@ -174,9 +174,7 @@ export default defineComponent({
searchText: "",
});
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"](["NORMAL"]);
- });
+ const environmentList = useEnvironmentList(["NORMAL"]);
const prepareDatabaseList = () => {
// It will also be called when user logout
diff --git a/frontend/src/views/Archive.vue b/frontend/src/views/Archive.vue
index 13230918c4..175f075ae1 100644
--- a/frontend/src/views/Archive.vue
+++ b/frontend/src/views/Archive.vue
@@ -39,7 +39,13 @@
</template>
<script lang="ts">
-import { computed, ComputedRef, reactive, watchEffect } from "vue";
+import {
+ computed,
+ ComputedRef,
+ defineComponent,
+ reactive,
+ watchEffect,
+} from "vue";
import { useStore } from "vuex";
import EnvironmentTable from "../components/EnvironmentTable.vue";
import InstanceTable from "../components/InstanceTable.vue";
@@ -54,6 +60,7 @@ import {
import { isDBAOrOwner } from "../utils";
import { BBTabFilterItem } from "../bbkit/types";
import { useI18n } from "vue-i18n";
+import { useEnvironmentList, useEnvironmentStore } from "@/store";
const PROJECT_TAB = 0;
const INSTANCE_TAB = 1;
@@ -64,7 +71,7 @@ interface LocalState {
searchText: string;
}
-export default {
+export default defineComponent({
name: "Archive",
components: { EnvironmentTable, InstanceTable, ProjectTable },
setup() {
@@ -93,7 +100,7 @@ export default {
if (isDBAOrOwner(currentUser.value.role)) {
store.dispatch("instance/fetchInstanceList", ["ARCHIVED"]);
- store.dispatch("environment/fetchEnvironmentList", ["ARCHIVED"]);
+ useEnvironmentStore().fetchEnvironmentList(["ARCHIVED"]);
}
};
@@ -109,9 +116,7 @@ export default {
return store.getters["instance/instanceList"](["ARCHIVED"]);
});
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"](["ARCHIVED"]);
- });
+ const environmentList = useEnvironmentList(["ARCHIVED"]);
const tabItemList = computed((): BBTabFilterItem[] => {
return isDBAOrOwner(currentUser.value.role)
@@ -175,5 +180,5 @@ export default {
changeSearchText,
};
},
-};
+});
</script>
diff --git a/frontend/src/views/DatabaseDashboard.vue b/frontend/src/views/DatabaseDashboard.vue
index 6380db314e..32b0c754e5 100644
--- a/frontend/src/views/DatabaseDashboard.vue
+++ b/frontend/src/views/DatabaseDashboard.vue
@@ -48,7 +48,11 @@ import DatabaseTable from "../components/DatabaseTable.vue";
import { Environment, Database, UNKNOWN_ID } from "../types";
import { sortDatabaseList } from "../utils";
import { cloneDeep } from "lodash-es";
-import { useUIStateStore } from "@/store";
+import {
+ useEnvironmentList,
+ useEnvironmentStore,
+ useUIStateStore,
+} from "@/store";
interface LocalState {
searchText: string;
@@ -74,8 +78,8 @@ export default defineComponent({
searchText: "",
databaseList: [],
selectedEnvironment: router.currentRoute.value.query.environment
- ? store.getters["environment/environmentById"](
- router.currentRoute.value.query.environment
+ ? useEnvironmentStore().getEnvironmentById(
+ parseInt(router.currentRoute.value.query.environment as string, 10)
)
: undefined,
showGuide: false,
@@ -83,9 +87,7 @@ export default defineComponent({
const currentUser = computed(() => store.getters["auth/currentUser"]());
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"](["NORMAL"]);
- });
+ const environmentList = useEnvironmentList(["NORMAL"]);
onMounted(() => {
// Focus on the internal search field when mounted
diff --git a/frontend/src/views/EnvironmentDashboard.vue b/frontend/src/views/EnvironmentDashboard.vue
index a517276a04..9b1d598859 100644
--- a/frontend/src/views/EnvironmentDashboard.vue
+++ b/frontend/src/views/EnvironmentDashboard.vue
@@ -77,7 +77,6 @@
<script lang="ts">
import { onMounted, computed, reactive, watch, defineComponent } from "vue";
-import { useStore } from "vuex";
import { useRouter } from "vue-router";
import { array_swap } from "../utils";
import EnvironmentDetail from "../views/EnvironmentDetail.vue";
@@ -98,6 +97,8 @@ import {
useUIStateStore,
hasFeature,
usePolicyStore,
+ useEnvironmentStore,
+ useEnvironmentList,
} from "@/store";
const DEFAULT_NEW_ENVIRONMENT: EnvironmentCreate = {
@@ -137,7 +138,7 @@ export default defineComponent({
},
props: {},
setup() {
- const store = useStore();
+ const environmentStore = useEnvironmentStore();
const uiStateStore = useUIStateStore();
const policyStore = usePolicyStore();
const router = useRouter();
@@ -155,8 +156,8 @@ export default defineComponent({
if (router.currentRoute.value.hash) {
for (let i = 0; i < environmentList.value.length; i++) {
if (
- environmentList.value[i].id ==
- router.currentRoute.value.hash.slice(1)
+ environmentList.value[i].id ===
+ parseInt(router.currentRoute.value.hash.slice(1), 10)
) {
selectEnvironment(i);
break;
@@ -206,20 +207,17 @@ export default defineComponent({
}
);
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"]();
- });
+ const environmentList = useEnvironmentList();
const tabItemList = computed((): BBTabItem[] => {
if (environmentList.value) {
const list = state.reorder
? state.reorderedEnvironmentList
: environmentList.value;
- return list.map((item: Environment, index: number) => {
- return {
- title: (index + 1).toString() + ". " + item.name,
- id: item.id,
- };
+ return list.map((item: Environment, index: number): BBTabItem => {
+ const title = `${index + 1}. ${item.name}`;
+ const id = item.id.toString();
+ return { title, id };
});
}
return [];
@@ -252,8 +250,8 @@ export default defineComponent({
return;
}
- store
- .dispatch("environment/createEnvironment", newEnvironment)
+ environmentStore
+ .createEnvironment(newEnvironment)
.then((environment: Environment) => {
Promise.all([
policyStore.upsertPolicyByEnvironmentAndType({
@@ -312,11 +310,8 @@ export default defineComponent({
};
const doReorder = () => {
- store
- .dispatch(
- "environment/reorderEnvironmentList",
- state.reorderedEnvironmentList
- )
+ environmentStore
+ .reorderEnvironmentList(state.reorderedEnvironmentList)
.then(() => {
stopReorder();
});
diff --git a/frontend/src/views/EnvironmentDetail.vue b/frontend/src/views/EnvironmentDetail.vue
index 28cb43a2d9..2b4cae635c 100644
--- a/frontend/src/views/EnvironmentDetail.vue
+++ b/frontend/src/views/EnvironmentDetail.vue
@@ -21,7 +21,6 @@
<script lang="ts">
import { defineComponent, reactive, watchEffect } from "vue";
-import { useStore } from "vuex";
import ArchiveBanner from "../components/ArchiveBanner.vue";
import EnvironmentForm from "../components/EnvironmentForm.vue";
import {
@@ -36,7 +35,7 @@ import {
PolicyBackupPlanPolicyPayload,
} from "../types";
import { idFromSlug } from "../utils";
-import { hasFeature, usePolicyStore } from "@/store";
+import { hasFeature, useEnvironmentStore, usePolicyStore } from "@/store";
interface LocalState {
environment: Environment;
@@ -62,11 +61,11 @@ export default defineComponent({
},
emits: ["archive"],
setup(props, { emit }) {
- const store = useStore();
+ const environmentStore = useEnvironmentStore();
const policyStore = usePolicyStore();
const state = reactive<LocalState>({
- environment: store.getters["environment/environmentById"](
+ environment: environmentStore.getEnvironmentById(
idFromSlug(props.environmentSlug)
),
showArchiveModal: false,
@@ -99,8 +98,8 @@ export default defineComponent({
};
const doUpdate = (environmentPatch: EnvironmentPatch) => {
- store
- .dispatch("environment/patchEnvironment", {
+ environmentStore
+ .patchEnvironment({
environmentId: idFromSlug(props.environmentSlug),
environmentPatch,
})
@@ -110,8 +109,8 @@ export default defineComponent({
};
const doArchive = (environment: Environment) => {
- store
- .dispatch("environment/patchEnvironment", {
+ environmentStore
+ .patchEnvironment({
environmentId: environment.id,
environmentPatch: {
rowStatus: "ARCHIVED",
@@ -124,8 +123,8 @@ export default defineComponent({
};
const doRestore = (environment: Environment) => {
- store
- .dispatch("environment/patchEnvironment", {
+ environmentStore
+ .patchEnvironment({
environmentId: environment.id,
environmentPatch: {
rowStatus: "NORMAL",
diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vue
index b6821f94db..35a75ebb98 100644
--- a/frontend/src/views/Home.vue
+++ b/frontend/src/views/Home.vue
@@ -48,13 +48,21 @@
</template>
<script lang="ts">
-import { watchEffect, computed, onMounted, reactive, ref } from "vue";
+import {
+ watchEffect,
+ computed,
+ onMounted,
+ reactive,
+ ref,
+ defineComponent,
+} from "vue";
import { useStore } from "vuex";
import { useRouter } from "vue-router";
import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
import { IssueTable } from "../components/Issue";
import { activeEnvironment, activeTask } from "../utils";
import { Environment, Issue, TaskStatus, UNKNOWN_ID } from "../types";
+import { useEnvironmentStore } from "@/store";
// Show at most 10 recently closed issues
const MAX_CLOSED_ISSUE_COUNT = 10;
@@ -68,7 +76,7 @@ interface LocalState {
selectedEnvironment?: Environment;
}
-export default {
+export default defineComponent({
name: "HomePage",
components: {
EnvironmentTabFilter,
@@ -87,8 +95,8 @@ export default {
closedList: [],
searchText: "",
selectedEnvironment: router.currentRoute.value.query.environment
- ? store.getters["environment/environmentById"](
- router.currentRoute.value.query.environment
+ ? useEnvironmentStore().getEnvironmentById(
+ parseInt(router.currentRoute.value.query.environment as string, 10)
)
: undefined,
});
@@ -220,5 +228,5 @@ export default {
openIssueSorter,
};
},
-};
+});
</script>
diff --git a/frontend/src/views/InstanceDashboard.vue b/frontend/src/views/InstanceDashboard.vue
index 1377962207..6cc23516d2 100644
--- a/frontend/src/views/InstanceDashboard.vue
+++ b/frontend/src/views/InstanceDashboard.vue
@@ -55,7 +55,12 @@ import { Environment, Instance } from "../types";
import { cloneDeep } from "lodash-es";
import { sortInstanceList } from "../utils";
import { useI18n } from "vue-i18n";
-import { useUIStateStore, useSubscriptionStore } from "@/store";
+import {
+ useUIStateStore,
+ useSubscriptionStore,
+ useEnvironmentStore,
+ useEnvironmentList,
+} from "@/store";
interface LocalState {
searchText: string;
@@ -78,15 +83,13 @@ export default defineComponent({
const router = useRouter();
const { t } = useI18n();
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"](["NORMAL"]);
- });
+ const environmentList = useEnvironmentList(["NORMAL"]);
const state = reactive<LocalState>({
searchText: "",
selectedEnvironment: router.currentRoute.value.query.environment
- ? store.getters["environment/environmentById"](
- router.currentRoute.value.query.environment
+ ? useEnvironmentStore().getEnvironmentById(
+ parseInt(router.currentRoute.value.query.environment as string, 10)
)
: undefined,
showGuide: false,
diff --git a/frontend/src/views/IssueDashboard.vue b/frontend/src/views/IssueDashboard.vue
index 6ddb3020f3..5272cc6668 100644
--- a/frontend/src/views/IssueDashboard.vue
+++ b/frontend/src/views/IssueDashboard.vue
@@ -46,10 +46,18 @@ import EnvironmentTabFilter from "../components/EnvironmentTabFilter.vue";
import { IssueTable } from "../components/Issue";
import MemberSelect from "../components/MemberSelect.vue";
import { Environment, Issue, PrincipalId, ProjectId } from "../types";
-import { reactive, ref, computed, onMounted, watchEffect } from "vue";
+import {
+ reactive,
+ ref,
+ computed,
+ onMounted,
+ watchEffect,
+ defineComponent,
+} from "vue";
import { activeEnvironment, projectSlug } from "../utils";
import { BBTableSectionDataSource } from "../bbkit/types";
import { useI18n } from "vue-i18n";
+import { useEnvironmentStore } from "@/store";
interface LocalState {
showOpen: boolean;
@@ -62,7 +70,7 @@ interface LocalState {
selectedProjectId?: ProjectId;
}
-export default {
+export default defineComponent({
name: "IssueDashboard",
components: { EnvironmentTabFilter, IssueTable, MemberSelect },
setup() {
@@ -96,8 +104,8 @@ export default {
searchText: "",
selectedPrincipalId: currentUser.value.id,
selectedEnvironment: router.currentRoute.value.query.environment
- ? store.getters["environment/environmentById"](
- router.currentRoute.value.query.environment
+ ? useEnvironmentStore().getEnvironmentById(
+ parseInt(router.currentRoute.value.query.environment as string, 10)
)
: undefined,
selectedProjectId: router.currentRoute.value.query.project
@@ -241,5 +249,5 @@ export default {
goProject,
};
},
-};
+});
</script>
diff --git a/frontend/src/views/ProjectDetail.vue b/frontend/src/views/ProjectDetail.vue
index 23b1e04dd9..89e4961ed8 100644
--- a/frontend/src/views/ProjectDetail.vue
+++ b/frontend/src/views/ProjectDetail.vue
@@ -59,6 +59,7 @@ import ProjectSettingPanel from "../components/ProjectSettingPanel.vue";
import ProjectDeploymentConfigPanel from "../components/ProjectDeploymentConfigPanel.vue";
import { cloneDeep } from "lodash-es";
import { useRoute } from "vue-router";
+import { useEnvironmentList } from "@/store";
export default defineComponent({
name: "ProjectDetail",
@@ -97,9 +98,7 @@ export default defineComponent({
);
});
- const environmentList = computed(() => {
- return store.getters["environment/environmentList"](["NORMAL"]);
- });
+ const environmentList = useEnvironmentList(["NORMAL"]);
const prepareDatabaseList = () => {
store.dispatch("database/fetchDatabaseListByProjectId", project.value.id);