Skip to content

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

chore: simply the route (#10387)

ecmadaodbf7c0535fc3
diff --git a/frontend/src/layouts/InstanceLayout.vue b/frontend/src/layouts/InstanceLayout.vue
index 638d55292c..64c88acff6 100644
--- a/frontend/src/layouts/InstanceLayout.vue
+++ b/frontend/src/layouts/InstanceLayout.vue
@@ -12,21 +12,19 @@
</Suspense>
</template>
-<script lang="ts">
-import ProvideInstanceContext from "../components/ProvideInstanceContext.vue";
+<script lang="ts" setup>
+import { watchEffect } from "vue";
+import ProvideInstanceContext from "@/components/ProvideInstanceContext.vue";
+import { useInstanceV1Store } from "@/store";
+import { idFromSlug } from "@/utils";
-export default {
- name: "InstanceLayout",
- components: { ProvideInstanceContext },
- props: {
- instanceSlug: {
- required: true,
- type: String,
- },
- databaseSlug: {
- type: String,
- default: "",
- },
- },
-};
+const props = defineProps<{
+ instanceSlug: string;
+}>();
+
+watchEffect(async () => {
+ await useInstanceV1Store().getOrFetchInstanceByUID(
+ idFromSlug(props.instanceSlug)
+ );
+});
</script>
diff --git a/frontend/src/router/dashboard/instance.ts b/frontend/src/router/dashboard/instance.ts
index 58444e30ac..7db3eb2470 100644
--- a/frontend/src/router/dashboard/instance.ts
+++ b/frontend/src/router/dashboard/instance.ts
@@ -7,6 +7,8 @@ import { uidFromSlug, idFromSlug } from "@/utils";
import DashboardSidebar from "@/views/DashboardSidebar.vue";
import { INSTANCE_ROUTE_DASHBOARD } from "./workspaceRoutes";
+export const INSTANCE_ROUTE_DETAIL = "workspace.instance.detail";
+
const instanceRoutes: RouteRecordRaw[] = [
{
path: "instance",
@@ -33,7 +35,7 @@ const instanceRoutes: RouteRecordRaw[] = [
children: [
{
path: "",
- name: "workspace.instance.detail",
+ name: INSTANCE_ROUTE_DETAIL,
meta: {
title: (route: RouteLocationNormalized) => {
const slug = route.params.instanceSlug as string;
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 4417c18c80..865af79999 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -3,8 +3,6 @@ import { nextTick, ref } from "vue";
import { createRouter, createWebHistory } from "vue-router";
import {
hasFeature,
- useVCSV1Store,
- useSQLReviewStore,
useSheetV1Store,
useAuthStore,
useActuatorV1Store,
@@ -12,10 +10,8 @@ import {
useDBSchemaV1Store,
useOnboardingStateStore,
useTabStore,
- useIdentityProviderStore,
useUserStore,
useCurrentUserV1,
- useInstanceV1Store,
useDatabaseV1Store,
useChangeHistoryStore,
usePageMode,
@@ -32,6 +28,7 @@ import authRoutes, {
AUTH_SIGNUP_MODULE,
} from "./auth";
import dashboardRoutes from "./dashboard";
+import { INSTANCE_ROUTE_DETAIL } from "./dashboard/instance";
import { ISSUE_ROUTE_DASHBOARD } from "./dashboard/issue";
import { PROJECT_V1_ROUTE } from "./dashboard/projectV1";
import {
@@ -44,12 +41,7 @@ import {
WORKSPACE_ROUTE_EXPORT_CENTER,
WORKSPACE_ROUTE_ANOMALY_CENTER,
} from "./dashboard/workspaceRoutes";
-import {
- SETTING_ROUTE,
- SETTING_ROUTE_WORKSPACE_GITOPS_DETAIL,
- SETTING_ROUTE_WORKSPACE_SSO_DETAIL,
- SETTING_ROUTE_WORKSPACE_SQL_REVIEW_DETAIL,
-} from "./dashboard/workspaceSetting";
+import { SETTING_ROUTE } from "./dashboard/workspaceSetting";
import sqlEditorRoutes, {
SQL_EDITOR_HOME_MODULE,
SQL_EDITOR_SHARE_MODULE,
@@ -213,12 +205,10 @@ router.beforeEach((to, from, next) => {
to.name === PROJECT_V1_ROUTE_DASHBOARD ||
to.name === INSTANCE_ROUTE_DASHBOARD ||
to.name === DATABASE_ROUTE_DASHBOARD ||
+ to.name === INSTANCE_ROUTE_DETAIL ||
to.name === ISSUE_ROUTE_DASHBOARD ||
to.name === SQL_EDITOR_HOME_MODULE ||
- (to.name?.toString().startsWith(SETTING_ROUTE) &&
- to.name?.toString() != SETTING_ROUTE_WORKSPACE_GITOPS_DETAIL &&
- to.name?.toString() != SETTING_ROUTE_WORKSPACE_SQL_REVIEW_DETAIL &&
- to.name?.toString() != SETTING_ROUTE_WORKSPACE_SSO_DETAIL)
+ to.name?.toString().startsWith(SETTING_ROUTE)
) {
next();
return;
@@ -266,13 +256,9 @@ router.beforeEach((to, from, next) => {
const routerSlug = routerStore.routeSlug(to);
const principalEmail = routerSlug.principalEmail;
const issueSlug = routerSlug.issueSlug;
- const instanceSlug = routerSlug.instanceSlug;
const databaseSlug = routerSlug.databaseSlug;
- const vcsSlug = routerSlug.vcsSlug;
const connectionSlug = routerSlug.connectionSlug;
const sheetSlug = routerSlug.sheetSlug;
- const ssoName = routerSlug.ssoName;
- const sqlReviewPolicySlug = routerSlug.sqlReviewPolicySlug;
if (principalEmail) {
useUserStore()
@@ -325,56 +311,6 @@ router.beforeEach((to, from, next) => {
return;
}
- if (instanceSlug) {
- useInstanceV1Store()
- .getOrFetchInstanceByUID(String(uidFromSlug(instanceSlug)))
- .then(() => {
- next();
- })
- .catch((error) => {
- next({
- name: "error.404",
- replace: false,
- });
- throw error;
- });
- return;
- }
-
- if (vcsSlug) {
- useVCSV1Store()
- .fetchVCSByUid(uidFromSlug(vcsSlug))
- .then(() => {
- next();
- })
- .catch((error) => {
- next({
- name: "error.404",
- replace: false,
- });
- throw error;
- });
- return;
- }
-
- if (sqlReviewPolicySlug) {
- useSQLReviewStore()
- .getOrFetchReviewPolicyByEnvironmentId(
- String(idFromSlug(sqlReviewPolicySlug))
- )
- .then(() => {
- next();
- })
- .catch((error) => {
- next({
- name: "error.404",
- replace: false,
- });
- throw error;
- });
- return;
- }
-
if (sheetSlug) {
const sheetName = sheetNameFromSlug(sheetSlug);
useSheetV1Store()
@@ -384,14 +320,6 @@ router.beforeEach((to, from, next) => {
return;
}
- if (ssoName) {
- useIdentityProviderStore()
- .getOrFetchIdentityProviderByName(unescape(ssoName))
- .then(() => next())
- .catch(() => next());
- return;
- }
-
if (connectionSlug) {
// We've moved the preparation data fetch jobs into ProvideSQLEditorContext.
// so just next() here.
diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.ts
index 2886dfe6ee..cf6dbc6d4a 100644
--- a/frontend/src/store/modules/router.ts
+++ b/frontend/src/store/modules/router.ts
@@ -30,51 +30,6 @@ export const useRouterStore = defineStore("router", {
}
}
- {
- // /projects/:projectId/webhook/:hookSlug
- // Total 3 elements, 2nd element is the project slug, 3rd element is the project webhook slug
- const projectComponents = currentRoute.path.match(
- "/projects/([0-9a-zA-Z_-]+)/webhook/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined, undefined];
- if (projectComponents[1] && projectComponents[2]) {
- return {
- projectId: projectComponents[1],
- projectWebhookSlug:
- projectComponents[2].toLowerCase() == "new"
- ? undefined
- : projectComponents[2],
- };
- }
- }
-
- {
- // /projects/:projectId/changelists/:changelistName
- // Total 3 elements, 2nd element is the project slug, 3rd element is the project changelist name.
- const projectComponents = currentRoute.path.match(
- "/projects/([0-9a-zA-Z_-]+)/changelists/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined];
- if (projectComponents.length === 3) {
- return {
- projectId: projectComponents[1],
- changelistName: projectComponents[2],
- };
- }
- }
-
- {
- // /projects/:projectId/branches/:branchName
- // Total 3 elements, 2nd element is the project slug, 3rd element is the project changelist name.
- const projectComponents = currentRoute.path.match(
- "/projects/([0-9a-zA-Z_-]+)/branches/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined];
- if (projectComponents.length === 3) {
- return {
- projectId: projectComponents[1],
- branchName: projectComponents[2],
- };
- }
- }
-
{
// /issue/:issueSlug
// Total 2 elements, 2nd element is the issue slug
@@ -88,20 +43,6 @@ export const useRouterStore = defineStore("router", {
}
}
- {
- // /db/:databaseSlug/table/:tableName
- // Total 3 elements, 2nd element is the database slug, 3rd element is the table name
- const databaseComponents = currentRoute.path.match(
- "/db/([0-9a-zA-Z_-]+)/table/(.+)"
- ) || ["/", undefined, undefined];
- if (databaseComponents[1] && databaseComponents[2]) {
- return {
- databaseSlug: databaseComponents[1],
- tableName: databaseComponents[2],
- };
- }
- }
-
{
// /db/:databaseSlug
// Total 2 elements, 2nd element is the database slug
@@ -115,45 +56,6 @@ export const useRouterStore = defineStore("router", {
}
}
- {
- // /instance/:instanceSlug
- // Total 2 elements, 2nd element is the instance slug
- const instanceComponents = currentRoute.path.match(
- "/instance/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined];
- if (instanceComponents[1]) {
- return {
- instanceSlug: instanceComponents[1],
- };
- }
- }
-
- {
- // /setting/gitops/:vcsId
- // Total 2 elements, 2nd element is the version control system id
- const vcsComponents = currentRoute.path.match(
- "/setting/gitops/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined];
- if (vcsComponents[1]) {
- return {
- vcsSlug: vcsComponents[1],
- };
- }
- }
-
- {
- // /setting/sql-review/:sqlReviewPolicyId
- // Total 2 elements, 2nd element is the SQL review id
- const sqlReviewComponents = currentRoute.path.match(
- "/setting/sql-review/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined];
- if (sqlReviewComponents[1]) {
- return {
- sqlReviewPolicySlug: sqlReviewComponents[1],
- };
- }
- }
-
{
// /sql-editor/sheet/:sheetSlug
// match this route first
@@ -181,62 +83,6 @@ export const useRouterStore = defineStore("router", {
}
}
- {
- // /setting/sso/:ssoName
- const ssoComponents = currentRoute.path.match("/setting/sso/(.+)") || [
- "/",
- undefined,
- ];
-
- if (ssoComponents[1]) {
- return {
- ssoName: ssoComponents[1],
- };
- }
- }
-
- {
- // /projects/proj-nt-iq3z/database-groups/test/table-groups/asd123
- const schemaGroupDetailComponents = currentRoute.path.match(
- "/projects/([0-9a-zA-Z_-]+)/database-groups/([0-9a-zA-Z_-]+)/table-groups/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined];
-
- if (schemaGroupDetailComponents.length === 4) {
- return {
- projectId: schemaGroupDetailComponents[1],
- databaseGroupName: schemaGroupDetailComponents[2],
- schemaGroupName: schemaGroupDetailComponents[3],
- };
- }
- }
-
- {
- // /projects/proj-nt-iq3z/database-groups/test
- const schemaGroupDetailComponents = currentRoute.path.match(
- "/projects/([0-9a-zA-Z_-]+)/database-groups/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined];
-
- if (schemaGroupDetailComponents.length === 3) {
- return {
- projectId: schemaGroupDetailComponents[1],
- databaseGroupName: schemaGroupDetailComponents[2],
- };
- }
- }
-
- {
- // /projects/:projectId
- // Total 2 elements, 2nd element is the project slug
- const projectComponents = currentRoute.path.match(
- "/projects/([0-9a-zA-Z_-]+)"
- ) || ["/", undefined];
- if (projectComponents[1]) {
- return {
- projectId: projectComponents[1],
- };
- }
- }
-
return {};
},
},
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index 4cfabe3ded..a0aadd013c 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -1,3 +1,4 @@
+import { Environment as EnvironmentV1 } from "@/types/proto/v1/environment_service";
import { BackupSetting } from "./backup";
import { EMPTY_ID, UNKNOWN_ID } from "./const";
import { DataSource } from "./dataSource";
@@ -44,23 +45,10 @@ export type RowStatus = "NORMAL" | "ARCHIVED";
// Router
export type RouterSlug = {
principalEmail?: string;
- projectWebhookSlug?: string;
issueSlug?: string;
- instanceSlug?: string;
databaseSlug?: string;
- tableName?: string;
- vcsSlug?: string;
connectionSlug?: string;
sheetSlug?: string;
- sqlReviewPolicySlug?: string;
- ssoName?: string;
-
- // Resource names.
- projectId?: string;
- databaseGroupName?: string;
- schemaGroupName?: string;
- changelistName?: string;
- branchName?: string;
};
// Quick Action Type
@@ -290,6 +278,14 @@ const makeUnknown = (type: ResourceType) => {
secret: "",
};
+ const UNKNOWN_SQL_REVIEW_POLICY: SQLReviewPolicy = {
+ id: UNKNOWN_ID,
+ enforce: false,
+ name: "",
+ ruleList: [],
+ environment: EnvironmentV1.fromJSON({}),
+ };
+
switch (type) {
case "PRINCIPAL":
return UNKNOWN_PRINCIPAL;
@@ -319,6 +315,8 @@ const makeUnknown = (type: ResourceType) => {
return UNKNOWN_TASK;
case "VCS":
return UNKNOWN_VCS;
+ case "SQL_REVIEW":
+ return UNKNOWN_SQL_REVIEW_POLICY;
}
};
diff --git a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
index d62fd15db5..777a27b9ec 100644
--- a/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
+++ b/frontend/src/views/SettingWorkspaceSQLReviewDetail.vue
@@ -132,7 +132,7 @@
<script lang="ts" setup>
import { cloneDeep, groupBy } from "lodash-es";
-import { computed, reactive, toRef, watch } from "vue";
+import { computed, reactive, toRef, watch, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
import { useRouter } from "vue-router";
import { BBTextField } from "@/bbkit";
@@ -166,12 +166,9 @@ import { Engine } from "@/types/proto/v1/common";
import { SQLReviewRuleLevel } from "@/types/proto/v1/org_policy_service";
import { idFromSlug, hasWorkspacePermissionV2 } from "@/utils";
-const props = defineProps({
- sqlReviewPolicySlug: {
- required: true,
- type: String,
- },
-});
+const props = defineProps<{
+ sqlReviewPolicySlug: string;
+}>();
interface LocalState {
showDisableModal: boolean;
@@ -202,6 +199,12 @@ const state = reactive<LocalState>({
updating: false,
});
+watchEffect(async () => {
+ await store.getOrFetchReviewPolicyByEnvironmentId(
+ idFromSlug(props.sqlReviewPolicySlug)
+ );
+});
+
const hasPermission = computed(() => {
return hasWorkspacePermissionV2(currentUserV1.value, "bb.policies.update");
});
@@ -279,7 +282,7 @@ const changeName = async (name: string) => {
ruleList: policy.ruleList,
};
- await useSQLReviewStore().updateReviewPolicy({
+ await store.updateReviewPolicy({
id: policy.id,
...upsert,
});
@@ -336,7 +339,7 @@ const onApplyChanges = async () => {
state.updating = true;
try {
- await useSQLReviewStore().updateReviewPolicy({
+ await store.updateReviewPolicy({
id: policy.id,
name: policy.name,
ruleList,
diff --git a/frontend/src/views/SettingWorkspaceSSODetail.vue b/frontend/src/views/SettingWorkspaceSSODetail.vue
index 00cee6e896..c048b7ef7e 100644
--- a/frontend/src/views/SettingWorkspaceSSODetail.vue
+++ b/frontend/src/views/SettingWorkspaceSSODetail.vue
@@ -31,26 +31,34 @@
</template>
<script lang="ts" setup>
-import { computed, reactive } from "vue";
-import { useRoute } from "vue-router";
+import { computed, reactive, watchEffect } from "vue";
import IdentityProviderCreateForm from "@/components/IdentityProviderCreateForm.vue";
import { useIdentityProviderStore } from "@/store/modules/idp";
import { State } from "@/types/proto/v1/common";
+const props = defineProps<{
+ ssoName?: string;
+}>();
+
interface LocalState {
showFeatureModal: boolean;
}
-const route = useRoute();
const state = reactive<LocalState>({
showFeatureModal: false,
});
const identityProviderStore = useIdentityProviderStore();
+watchEffect(async () => {
+ if (props.ssoName) {
+ await identityProviderStore.getOrFetchIdentityProviderByName(
+ unescape(props.ssoName)
+ );
+ }
+});
+
const currentIdentityProvider = computed(() => {
- return identityProviderStore.getIdentityProviderByName(
- (route.params.ssoName as string) || ""
- );
+ return identityProviderStore.getIdentityProviderByName(props.ssoName ?? "");
});
const isDeleted = computed(() => {
diff --git a/frontend/src/views/SettingWorkspaceVCSDetail.vue b/frontend/src/views/SettingWorkspaceVCSDetail.vue
index 68bc0e6383..3f83443c87 100644
--- a/frontend/src/views/SettingWorkspaceVCSDetail.vue
+++ b/frontend/src/views/SettingWorkspaceVCSDetail.vue
@@ -155,6 +155,7 @@
import isEmpty from "lodash-es/isEmpty";
import { reactive, computed, watchEffect, onMounted, onUnmounted } from "vue";
import { useRouter } from "vue-router";
+import RepositoryTable from "@/components/RepositoryTable.vue";
import { vcsListByUIType } from "@/components/VCS/utils";
import { SETTING_ROUTE_WORKSPACE_GITOPS } from "@/router/dashboard/workspaceSetting";
import {
@@ -163,18 +164,22 @@ import {
useRepositoryV1Store,
useVCSV1Store,
} from "@/store";
+import {
+ openWindowForOAuth,
+ OAuthWindowEventPayload,
+ VCSUIType,
+} from "@/types";
import {
OAuthToken,
ExternalVersionControl,
ExternalVersionControl_Type,
} from "@/types/proto/v1/externalvs_service";
-import RepositoryTable from "../components/RepositoryTable.vue";
import {
- openWindowForOAuth,
- OAuthWindowEventPayload,
- VCSUIType,
-} from "../types";
-import { idFromSlug, getVCSUIType, hasWorkspacePermissionV2 } from "../utils";
+ idFromSlug,
+ uidFromSlug,
+ getVCSUIType,
+ hasWorkspacePermissionV2,
+} from "@/utils";
interface LocalState {
title: string;
@@ -183,12 +188,9 @@ interface LocalState {
oAuthResultCallback?: (token: OAuthToken | undefined) => void;
}
-const props = defineProps({
- vcsSlug: {
- required: true,
- type: String,
- },
-});
+const props = defineProps<{
+ vcsSlug: string;
+}>();
const router = useRouter();
const currentUser = useCurrentUserV1();
@@ -266,9 +268,11 @@ const eventListener = (event: Event) => {
};
watchEffect(async () => {
- if (vcs.value) {
- await repositoryV1Store.fetchRepositoryListByVCS(vcs.value.name);
- }
+ await vcsV1Store.fetchVCSByUid(uidFromSlug(props.vcsSlug)).then((vcs) => {
+ if (vcs) {
+ return repositoryV1Store.fetchRepositoryListByVCS(vcs.name);
+ }
+ });
});
const adminApplicationUrl = computed(() => {