Skip to content

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

chore: update branch routes (#8635)

boojackee6f065ba184
diff --git a/frontend/src/components/Branch/BranchCreateView.vue b/frontend/src/components/Branch/BranchCreateView.vue
index c2578f09af..20306343c2 100644
--- a/frontend/src/components/Branch/BranchCreateView.vue
+++ b/frontend/src/components/Branch/BranchCreateView.vue
@@ -77,6 +77,7 @@ import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
import {
databaseNamePrefix,
getProjectAndSchemaDesignSheetId,
+ projectNamePrefix,
} from "@/store/modules/v1/common";
import { UNKNOWN_ID } from "@/types";
import {
@@ -132,9 +133,13 @@ const state = reactive<LocalState>({
});
const refreshId = ref<string>("");
-onMounted(() => {
- if (route.query.projectId) {
- state.projectId = route.query.projectId as string;
+onMounted(async () => {
+ const projectName = route.params.projectName;
+ if (projectName !== "-") {
+ const project = await projectStore.getOrFetchProjectByName(
+ `${projectNamePrefix}${projectName}`
+ );
+ state.projectId = project.uid;
}
});
@@ -272,13 +277,14 @@ const handleConfirm = async () => {
});
// Go to branch detail page after created.
- const [, sheetId] = getProjectAndSchemaDesignSheetId(
+ const [projectName, sheetId] = getProjectAndSchemaDesignSheetId(
createdSchemaDesign.name
);
router.replace({
name: "workspace.branch.detail",
params: {
- branchSlug: `${createdSchemaDesign.title}-${sheetId}`,
+ projectName,
+ branchName: sheetId,
},
});
};
diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vue
index b6d8cf4ae8..79f1829866 100644
--- a/frontend/src/components/Branch/BranchDetailView.vue
+++ b/frontend/src/components/Branch/BranchDetailView.vue
@@ -398,14 +398,15 @@ const handleSaveBranch = async () => {
closeOnEsc: true,
onNegativeClick: () => {
// Go to draft branch detail page after merge failed.
- const [, sheetId] = getProjectAndSchemaDesignSheetId(
+ const [projectName, sheetId] = getProjectAndSchemaDesignSheetId(
newBranch.name
);
state.isEditing = false;
router.replace({
name: "workspace.branch.detail",
params: {
- branchSlug: `${newBranch.title}-${sheetId}`,
+ projectName,
+ branchName: sheetId,
},
});
},
@@ -457,12 +458,12 @@ const handleSaveBranch = async () => {
const handleMergeAfterConflictResolved = (branchName: string) => {
state.showDiffEditor = false;
state.isEditing = false;
- const branch = schemaDesignStore.getSchemaDesignByName(branchName);
- const [, sheetId] = getProjectAndSchemaDesignSheetId(branchName);
+ const [projectName, sheetId] = getProjectAndSchemaDesignSheetId(branchName);
router.replace({
name: "workspace.branch.detail",
params: {
- branchSlug: `${branch.title}-${sheetId}`,
+ projectName,
+ branchName: sheetId,
},
});
};
diff --git a/frontend/src/components/Breadcrumb.vue b/frontend/src/components/Breadcrumb.vue
index c4c1604860..6364551d43 100644
--- a/frontend/src/components/Breadcrumb.vue
+++ b/frontend/src/components/Breadcrumb.vue
@@ -71,12 +71,8 @@ import {
useBookmarkV1Store,
useProjectV1Store,
useDatabaseV1Store,
- useSheetV1Store,
} from "@/store";
-import {
- getProjectAndSheetId,
- projectNamePrefix,
-} from "@/store/modules/v1/common";
+import { projectNamePrefix } from "@/store/modules/v1/common";
import { RouteMapList } from "@/types";
import { Bookmark } from "@/types/proto/v1/bookmark_service";
import { databaseV1Slug, idFromSlug, projectV1Slug } from "../utils";
@@ -98,7 +94,6 @@ export default defineComponent({
const { t } = useI18n();
const bookmarkV1Store = useBookmarkV1Store();
const projectV1Store = useProjectV1Store();
- const sheetStore = useSheetV1Store();
const documentTitle = useTitle(null, { observe: true });
@@ -131,7 +126,6 @@ export default defineComponent({
const projectWebhookSlug = routeSlug.projectWebhookSlug;
const instanceSlug = routeSlug.instanceSlug;
const databaseSlug = routeSlug.databaseSlug;
- const branchSlug = routeSlug.branchSlug;
const tableName = routeSlug.tableName;
const dataSourceSlug = routeSlug.dataSourceSlug;
const vcsSlug = routeSlug.vcsSlug;
@@ -183,21 +177,6 @@ export default defineComponent({
path: `/db/${databaseSlug}`,
});
}
- } else if (branchSlug) {
- const sheetId = idFromSlug(branchSlug);
- const sheet = sheetStore.getSheetByUID(`${sheetId}`);
- if (sheet) {
- const [projectName] = getProjectAndSheetId(sheet.name);
- const project = projectV1Store.getProjectByName(
- `${projectNamePrefix}${projectName}`
- );
- if (project) {
- list.push({
- name: project.title,
- path: `/project/${projectV1Slug(project)}#branches`,
- });
- }
- }
} else if (vcsSlug) {
list.push({
name: t("common.gitops"),
@@ -249,6 +228,23 @@ export default defineComponent({
path: `/changelists`,
});
}
+ if (route.name === "workspace.branch.detail") {
+ if (route.params.branchName !== "new") {
+ const project = projectV1Store.getProjectByName(
+ `${projectNamePrefix}${route.params.projectName}`
+ );
+ if (project) {
+ list.push({
+ name: project.title,
+ path: `/project/${projectV1Slug(project)}#branches`,
+ });
+ }
+ }
+ list.push({
+ name: t("common.branches"),
+ path: `/branches`,
+ });
+ }
const {
title: routeTitle,
diff --git a/frontend/src/components/ProjectBranchesPanel.vue b/frontend/src/components/ProjectBranchesPanel.vue
index 7301cb742a..8ec0e54f1b 100644
--- a/frontend/src/components/ProjectBranchesPanel.vue
+++ b/frontend/src/components/ProjectBranchesPanel.vue
@@ -33,7 +33,10 @@ import { useRouter } from "vue-router";
import BranchTable from "@/components/Branch/BranchTable.vue";
import { useProjectV1Store } from "@/store";
import { useSchemaDesignList } from "@/store/modules/schemaDesign";
-import { getProjectAndSchemaDesignSheetId } from "@/store/modules/v1/common";
+import {
+ getProjectAndSchemaDesignSheetId,
+ getProjectName,
+} from "@/store/modules/v1/common";
import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
const props = defineProps<{
@@ -70,23 +73,25 @@ const filteredBranches = computed(() => {
});
const handleCreateBranch = () => {
+ const projectName = getProjectName(project.value.name);
router.push({
name: "workspace.branch.detail",
params: {
- branchSlug: "new",
- },
- query: {
- projectId: props.projectId,
+ projectName: projectName,
+ branchName: "new",
},
});
};
const handleBranchClick = async (schemaDesign: SchemaDesign) => {
- const [, sheetId] = getProjectAndSchemaDesignSheetId(schemaDesign.name);
+ const [projectName, sheetId] = getProjectAndSchemaDesignSheetId(
+ schemaDesign.name
+ );
router.push({
name: "workspace.branch.detail",
params: {
- branchSlug: `${schemaDesign.title}-${sheetId}`,
+ projectName: projectName,
+ branchName: `${sheetId}`,
},
});
};
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 1590cda1c1..68808eee5d 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -40,6 +40,7 @@ import {
useDatabaseV1Store,
useChangeHistoryStore,
useChangelistStore,
+ useSchemaDesignStore,
} from "@/store";
import {
DEFAULT_PROJECT_ID,
@@ -271,6 +272,31 @@ const routes: Array<RouteRecordRaw> = [
leftSidebar: true,
},
},
+ {
+ path: "branches",
+ name: "workspace.branch.dashboard",
+ meta: {
+ title: () => t("common.branches"),
+ },
+ components: {
+ content: () => import("../views/branch/BranchDashboard.vue"),
+ leftSidebar: DashboardSidebar,
+ },
+ props: { content: true, leftSidebar: true },
+ },
+ {
+ path: "/projects/:projectName/branches/:branchName",
+ name: "workspace.branch.detail",
+ meta: {
+ allowBookmark: true,
+ overrideTitle: true,
+ },
+ components: {
+ content: () => import("../views/branch/BranchDetail.vue"),
+ leftSidebar: DashboardSidebar,
+ },
+ props: { content: true },
+ },
{
path: "sync-schema",
name: "workspace.sync-schema",
@@ -995,31 +1021,6 @@ const routes: Array<RouteRecordRaw> = [
},
],
},
- {
- path: "branch",
- name: "workspace.branch",
- meta: {
- title: () => t("common.branches"),
- },
- components: {
- content: () => import("../views/branch/BranchDashboard.vue"),
- leftSidebar: DashboardSidebar,
- },
- props: { content: true, leftSidebar: true },
- },
- {
- path: "branch/:branchSlug",
- name: "workspace.branch.detail",
- meta: {
- allowBookmark: true,
- overrideTitle: true,
- },
- components: {
- content: () => import("../views/branch/BranchDetail.vue"),
- leftSidebar: DashboardSidebar,
- },
- props: { content: true },
- },
],
},
],
@@ -1332,7 +1333,7 @@ router.beforeEach((to, from, next) => {
to.name === "workspace.database" ||
to.name === "workspace.archive" ||
to.name === "workspace.issue" ||
- to.name === "workspace.branch" ||
+ to.name === "workspace.branch.dashboard" ||
to.name === "workspace.environment" ||
to.name === "sql-editor.home" ||
to.name?.toString().startsWith("workspace.database-group") ||
@@ -1381,7 +1382,6 @@ router.beforeEach((to, from, next) => {
const projectSlug = routerSlug.projectSlug;
const projectWebhookSlug = routerSlug.projectWebhookSlug;
const issueSlug = routerSlug.issueSlug;
- const branchSlug = routerSlug.branchSlug;
const instanceSlug = routerSlug.instanceSlug;
const databaseSlug = routerSlug.databaseSlug;
const dataSourceSlug = routerSlug.dataSourceSlug;
@@ -1469,17 +1469,18 @@ router.beforeEach((to, from, next) => {
return;
}
- if (branchSlug) {
- if (branchSlug === "new") {
+ if (to.name === "workspace.branch.detail") {
+ if (to.params.branchName === "new") {
next();
return;
}
// Prepare the data for the branch detail page.
- useSheetV1Store()
- .getOrFetchSheetByUID(String(idFromSlug(branchSlug)))
- .then((sheet) => {
- if (sheet) {
+ const name = `projects/${to.params.projectName}/schemaDesigns/${to.params.branchName}`;
+ useSchemaDesignStore()
+ .getOrFetchSchemaDesignByName(name)
+ .then((branch) => {
+ if (branch) {
next();
} else {
next({
diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.ts
index 8af6ec16ba..00546190e8 100644
--- a/frontend/src/store/modules/router.ts
+++ b/frontend/src/store/modules/router.ts
@@ -86,20 +86,6 @@ export const useRouterStore = defineStore("router", {
}
}
- {
- // /branch/:branchSlug
- // Total 2 elements, 2nd element is the branch slug
- const branchComponents = currentRoute.path.match("/branch/(.+)") || [
- "/",
- undefined,
- ];
- if (branchComponents[1]) {
- return {
- branchSlug: branchComponents[1],
- };
- }
- }
-
{
// /db/:databaseSlug/table/:tableName
// Total 3 elements, 2nd element is the database slug, 3rd element is the table name
diff --git a/frontend/src/store/modules/v1/common.ts b/frontend/src/store/modules/v1/common.ts
index 9bb6e0e863..b7ec20c7d9 100644
--- a/frontend/src/store/modules/v1/common.ts
+++ b/frontend/src/store/modules/v1/common.ts
@@ -54,6 +54,12 @@ export const getLogId = (name: string): number => {
return getNumberId(name, logNamePrefix);
};
+export const getProjectName = (name: string): string => {
+ const tokens = getNameParentTokens(name, [projectNamePrefix]);
+ const projectId = tokens[0];
+ return projectId;
+};
+
export const getProjectAndSheetId = (name: string): string[] => {
const tokens = getNameParentTokens(name, [
projectNamePrefix,
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index eebd4fa2f8..f3126d3510 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -50,7 +50,6 @@ export type RouterSlug = {
projectSlug?: string;
projectWebhookSlug?: string;
issueSlug?: string;
- branchSlug?: string;
instanceSlug?: string;
databaseSlug?: string;
tableName?: string;
diff --git a/frontend/src/utils/slug.ts b/frontend/src/utils/slug.ts
index baf1baa20a..5969e7069f 100644
--- a/frontend/src/utils/slug.ts
+++ b/frontend/src/utils/slug.ts
@@ -55,10 +55,6 @@ export function issueSlug(issueName: string, issueId: IssueId): string {
return [slug(issueName), issueId].join("-");
}
-export function branchSlug(branchName: string, branchId: string): string {
- return [slug(branchName), branchId].join("-");
-}
-
// On the other hand, it's not possible to de-slug due to slug's one-way algorithm
export function environmentSlug(environment: Environment): string {
return [slug(environment.name), environment.id].join("-");
diff --git a/frontend/src/views/DashboardHeader.vue b/frontend/src/views/DashboardHeader.vue
index b831b98461..350008685e 100644
--- a/frontend/src/views/DashboardHeader.vue
+++ b/frontend/src/views/DashboardHeader.vue
@@ -13,9 +13,9 @@
>
<router-link
- to="/branch"
+ to="/branches"
class="bar-link px-2 py-1 rounded-md"
- :class="getRouteLinkClass('/branch')"
+ :class="getRouteLinkClass('/branches')"
>{{ $t("common.branches") }}</router-link
>
diff --git a/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue b/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
index 6a3d533aff..7117278692 100644
--- a/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
+++ b/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
@@ -154,18 +154,22 @@ const handleCreateBranch = () => {
const route = router.resolve({
name: "workspace.branch.detail",
params: {
- branchSlug: "new",
+ projectName: "-",
+ branchName: "new",
},
});
window.open(route.href, "_blank");
};
const handleViewSchemaDesign = (schemaDesign: SchemaDesign) => {
- const [, sheetId] = getProjectAndSchemaDesignSheetId(schemaDesign.name);
+ const [projectName, sheetId] = getProjectAndSchemaDesignSheetId(
+ schemaDesign.name
+ );
const route = router.resolve({
name: "workspace.branch.detail",
params: {
- branchSlug: `${schemaDesign.title}-${sheetId}`,
+ projectName,
+ branchName: sheetId,
},
});
window.open(route.href, "_blank");
diff --git a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
index 9ba227fe45..fb247adf61 100644
--- a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
+++ b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
@@ -446,13 +446,14 @@ const handleViewBranch = () => {
return;
}
- const [, sheetId] = getProjectAndSchemaDesignSheetId(
+ const [projectName, sheetId] = getProjectAndSchemaDesignSheetId(
selectedSchemaDesign.value.name
);
const route = router.resolve({
name: "workspace.branch.detail",
params: {
- branchSlug: `${selectedSchemaDesign.value.title}-${sheetId}`,
+ projectName,
+ branchName: sheetId,
},
});
window.open(route.href, "_blank");
diff --git a/frontend/src/views/branch/BranchDashboard.vue b/frontend/src/views/branch/BranchDashboard.vue
index a0e1d4bc0c..88a12aafa1 100644
--- a/frontend/src/views/branch/BranchDashboard.vue
+++ b/frontend/src/views/branch/BranchDashboard.vue
@@ -60,17 +60,21 @@ const handleCreateBranch = () => {
router.push({
name: "workspace.branch.detail",
params: {
- branchSlug: "new",
+ projectName: "-",
+ branchName: "new",
},
});
};
const handleBranchClick = async (schemaDesign: SchemaDesign) => {
- const [, sheetId] = getProjectAndSchemaDesignSheetId(schemaDesign.name);
+ const [projectName, sheetId] = getProjectAndSchemaDesignSheetId(
+ schemaDesign.name
+ );
router.push({
name: "workspace.branch.detail",
params: {
- branchSlug: `${schemaDesign.title}-${sheetId}`,
+ projectName,
+ branchName: sheetId,
},
});
};
diff --git a/frontend/src/views/branch/BranchDetail.vue b/frontend/src/views/branch/BranchDetail.vue
index 6293edd32a..2e05fda4a3 100644
--- a/frontend/src/views/branch/BranchDetail.vue
+++ b/frontend/src/views/branch/BranchDetail.vue
@@ -13,48 +13,34 @@
import { useTitle } from "@vueuse/core";
import { computed, ref, watchEffect } from "vue";
import { useI18n } from "vue-i18n";
+import { useRoute } from "vue-router";
import BranchCreateView from "@/components/Branch/BranchCreateView.vue";
import BranchDetailView from "@/components/Branch/BranchDetailView.vue";
import { useProjectV1Store, useSheetV1Store } from "@/store";
import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
import { getProjectAndSheetId } from "@/store/modules/v1/common";
-import { idFromSlug } from "@/utils";
-
-const props = defineProps({
- branchSlug: {
- required: true,
- type: String,
- },
-});
const { t } = useI18n();
+const route = useRoute();
const sheetStore = useSheetV1Store();
const projectStore = useProjectV1Store();
const schemaDesignStore = useSchemaDesignStore();
const initialized = ref(false);
-const isCreating = computed(() => props.branchSlug === "new");
+const isCreating = computed(() => route.params.branchName === "new");
const branchName = computed(() => {
- const sheetId = idFromSlug(props.branchSlug);
- const sheet = sheetStore.getSheetByUID(`${sheetId}`);
- if (!sheet) {
- return undefined;
- }
- const [project] = getProjectAndSheetId(sheet.name);
- return `projects/${project}/schemaDesigns/${sheetId}`;
+ return `projects/${route.params.projectName}/schemaDesigns/${route.params.branchName}`;
});
watchEffect(async () => {
if (!isCreating.value) {
- const sheetId = idFromSlug(props.branchSlug);
+ const sheetId = (route.params.branchName || "") as string;
const sheet = await sheetStore.getOrFetchSheetByUID(`${sheetId}`);
if (sheet) {
const [projectName] = getProjectAndSheetId(sheet.name);
- const project = await projectStore.getOrFetchProjectByName(
- `projects/${projectName}`
- );
+ await projectStore.getOrFetchProjectByName(`projects/${projectName}`);
await schemaDesignStore.getOrFetchSchemaDesignByName(
- `projects/${project}/schemaDesigns/${sheetId}`
+ `projects/${projectName}/schemaDesigns/${sheetId}`
);
}
}