Skip to content

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

refactor: split store init as SQL editor and dashboard have different context (#9540)

Danny Xuf4cc1110f58a
diff --git a/frontend/src/components/ProvideDashboardContext.vue b/frontend/src/components/ProvideDashboardContext.vue
index d399ae9bee..3fabbb9e63 100644
--- a/frontend/src/components/ProvideDashboardContext.vue
+++ b/frontend/src/components/ProvideDashboardContext.vue
@@ -5,16 +5,30 @@
<script lang="ts">
import { defineComponent } from "vue";
import {
+ useEnvironmentV1Store,
+ useInstanceV1Store,
+ usePolicyV1Store,
+ useProjectV1Store,
+ useRoleStore,
+ useSettingV1Store,
+ useUserStore,
useUIStateStore,
useDatabaseV1Store,
useDBGroupStore,
- initCommonModelStores,
} from "@/store";
export default defineComponent({
name: "ProvideDashboardContext",
async setup() {
- await initCommonModelStores();
+ await Promise.all([
+ useUserStore().fetchUserList(),
+ useSettingV1Store().fetchSettingList(),
+ useRoleStore().fetchRoleList(),
+ useEnvironmentV1Store().fetchEnvironments(),
+ useInstanceV1Store().fetchInstanceList(),
+ useProjectV1Store().fetchProjectList(true),
+ usePolicyV1Store().getOrFetchPolicyByName("policies/WORKSPACE_IAM"),
+ ]);
await Promise.all([
useDatabaseV1Store().fetchDatabaseList({
parent: "instances/-",
diff --git a/frontend/src/components/ProvideSQLEditorContext.vue b/frontend/src/components/ProvideSQLEditorContext.vue
index 582959a784..dcaaf04512 100644
--- a/frontend/src/components/ProvideSQLEditorContext.vue
+++ b/frontend/src/components/ProvideSQLEditorContext.vue
@@ -14,19 +14,22 @@ import { onMounted, computed, watch, ref } from "vue";
import { useI18n } from "vue-i18n";
import { useRoute, useRouter } from "vue-router";
import {
+ useEnvironmentV1Store,
+ useInstanceV1Store,
+ usePolicyV1Store,
+ useProjectV1Store,
+ useRoleStore,
+ useSettingV1Store,
+ useUserStore,
useSQLEditorStore,
useTabStore,
pushNotification,
- useProjectV1Store,
useCurrentUserV1,
useSheetV1Store,
- useInstanceV1Store,
useDatabaseV1Store,
- initCommonModelStores,
} from "@/store";
import { useSQLEditorTreeStore } from "@/store/modules/sqlEditorTree";
import { projectNamePrefix } from "@/store/modules/v1/common";
-import { usePolicyV1Store } from "@/store/modules/v1/policy";
import {
Connection,
CoreTabInfo,
@@ -84,8 +87,8 @@ const prepareAccessibleDatabaseList = async () => {
return;
}
let filter = "";
- if (treeStore.selectedProject) {
- filter = `project == "${treeStore.selectedProject.name}"`;
+ if (route.query.project) {
+ filter = `project == "${route.query.project}"`;
}
// `databaseList` is the database list accessible by current user.
@@ -332,7 +335,15 @@ onMounted(async () => {
if (treeStore.state === "UNSET") {
treeStore.state = "LOADING";
- await initCommonModelStores();
+ await Promise.all([
+ useUserStore().fetchUserList(),
+ useSettingV1Store().fetchSettingList(),
+ useRoleStore().fetchRoleList(),
+ useEnvironmentV1Store().fetchEnvironments(),
+ useInstanceV1Store().fetchInstanceList(),
+ useProjectV1Store().fetchProjectList(true),
+ usePolicyV1Store().getOrFetchPolicyByName("policies/WORKSPACE_IAM"),
+ ]);
await prepareProject();
await prepareAccessControlPolicy();
diff --git a/frontend/src/store/modules/utils.ts b/frontend/src/store/modules/utils.ts
index 7f41c8de5d..b96aa6e5cb 100644
--- a/frontend/src/store/modules/utils.ts
+++ b/frontend/src/store/modules/utils.ts
@@ -1,15 +1,6 @@
import { ClientError } from "nice-grpc-web";
import { t } from "@/plugins/i18n";
import { extractGrpcErrorMessage } from "@/utils/grpcweb";
-import {
- useEnvironmentV1Store,
- useInstanceV1Store,
- usePolicyV1Store,
- useProjectV1Store,
- useRoleStore,
- useSettingV1Store,
- useUserStore,
-} from ".";
import { pushNotification } from "./notification";
export const useGracefulRequest = async <T>(
@@ -31,15 +22,3 @@ export const useGracefulRequest = async <T>(
throw err;
}
};
-
-export const initCommonModelStores = async () => {
- await Promise.all([
- useUserStore().fetchUserList(),
- useSettingV1Store().fetchSettingList(),
- useRoleStore().fetchRoleList(),
- useEnvironmentV1Store().fetchEnvironments(),
- useInstanceV1Store().fetchInstanceList(),
- useProjectV1Store().fetchProjectList(true),
- usePolicyV1Store().getOrFetchPolicyByName("policies/WORKSPACE_IAM"),
- ]);
-};