Skip to content

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

feat: implement branch detail page (#8304)

boojack55a57140cd90
diff --git a/frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue b/frontend/src/components/Branch/BaselineSchemaSelector.vue
similarity index 100%
rename from frontend/src/components/SchemaDesigner/BaselineSchemaSelector.vue
rename to frontend/src/components/Branch/BaselineSchemaSelector.vue
diff --git a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue b/frontend/src/components/Branch/BranchCreateView.vue
similarity index 66%
rename from frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
rename to frontend/src/components/Branch/BranchCreateView.vue
index 674c6aefb2..543dbc66bd 100644
--- a/frontend/src/components/SchemaDesigner/CreateSchemaDesignPanel.vue
+++ b/frontend/src/components/Branch/BranchCreateView.vue
@@ -1,90 +1,70 @@
<template>
- <NDrawer
- class="min-w-[calc(100%-10rem)] max-w-full"
- :show="true"
- :auto-focus="false"
- :trap-focus="false"
- :close-on-esc="true"
- :native-scrollbar="true"
- resizable
- @update:show="(show: boolean) => !show && emit('dismiss')"
- >
- <NDrawerContent :title="$t('database.new-branch')" :closable="true">
- <div class="space-y-3 w-full overflow-x-auto">
- <div class="w-full flex flex-row justify-start items-center pt-1">
- <span class="flex w-40 items-center shrink-0 text-sm">
- {{ $t("common.project") }}
- </span>
- <ProjectSelect
- class="!w-60 shrink-0"
- :selected-id="state.projectId"
- @select-project-id="handleProjectSelect"
- />
- </div>
- <div class="w-full flex flex-row justify-start items-center mt-1">
- <span class="flex w-40 items-center text-sm">{{
- $t("database.branch-name")
- }}</span>
- <BBTextField
- class="w-60 text-sm"
- :value="state.schemaDesignTitle"
- :placeholder="'feature/add-billing'"
- @input="
- state.schemaDesignTitle = (
- $event.target as HTMLInputElement
- ).value
- "
- />
- </div>
- <NDivider />
- <div class="w-full flex flex-row justify-start items-center mt-1">
- <span class="flex w-40 items-center text-sm font-medium">{{
- $t("schema-designer.baseline-version")
- }}</span>
- </div>
- <BaselineSchemaSelector
- :project-id="state.projectId"
- :baseline-schema="state.baselineSchema"
- @update="handleBaselineSchemaChange"
- />
- <div class="!mt-6 w-full h-[32rem]">
- <SchemaEditorV1
- :key="refreshId"
- :project="project"
- :resource-type="'branch'"
- :branches="[state.schemaDesign]"
- :readonly="true"
- />
- </div>
- </div>
-
- <template #footer>
- <div class="flex-1 flex items-center justify-between">
- <div></div>
+ <div class="space-y-3 w-full overflow-x-auto px-4">
+ <div class="w-full flex flex-row justify-start items-center pt-1">
+ <span class="flex w-40 items-center shrink-0 text-sm">
+ {{ $t("common.project") }}
+ </span>
+ <ProjectSelect
+ class="!w-60 shrink-0"
+ :selected-id="state.projectId"
+ @select-project-id="handleProjectSelect"
+ />
+ </div>
+ <div class="w-full flex flex-row justify-start items-center mt-1">
+ <span class="flex w-40 items-center text-sm">{{
+ $t("database.branch-name")
+ }}</span>
+ <BBTextField
+ class="w-60 text-sm"
+ :value="state.schemaDesignTitle"
+ :placeholder="'feature/add-billing'"
+ @input="
+ state.schemaDesignTitle = ($event.target as HTMLInputElement).value
+ "
+ />
+ </div>
+ <NDivider />
+ <div class="w-full flex flex-row justify-start items-center mt-1">
+ <span class="flex w-40 items-center text-sm font-medium">{{
+ $t("schema-designer.baseline-version")
+ }}</span>
+ </div>
+ <BaselineSchemaSelector
+ :project-id="state.projectId"
+ :baseline-schema="state.baselineSchema"
+ @update="handleBaselineSchemaChange"
+ />
+ <div class="!mt-6 w-full h-[32rem]">
+ <SchemaEditorV1
+ :key="refreshId"
+ :project="project"
+ :resource-type="'branch'"
+ :branches="[state.schemaDesign]"
+ :readonly="true"
+ />
+ </div>
+ <div class="w-full flex items-center justify-between mt-4">
+ <div></div>
- <div class="flex items-center justify-end gap-x-3">
- <NButton @click.prevent="cancel">
- {{ cancelText }}
- </NButton>
- <NButton
- type="primary"
- :disabled="!allowConfirm"
- @click.prevent="handleConfirm"
- >
- {{ confirmText }}
- </NButton>
- </div>
- </div>
- </template>
- </NDrawerContent>
- </NDrawer>
+ <div class="flex items-center justify-end gap-x-3">
+ <NButton
+ type="primary"
+ :disabled="!allowConfirm"
+ @click.prevent="handleConfirm"
+ >
+ {{ confirmText }}
+ </NButton>
+ </div>
+ </div>
+ </div>
</template>
<script lang="ts" setup>
import { cloneDeep, uniqueId } from "lodash-es";
-import { NButton, NDrawer, NDrawerContent, NDivider } from "naive-ui";
+import { NButton, NDivider } from "naive-ui";
import { computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
import SchemaEditorV1 from "@/components/SchemaEditorV1/index.vue";
import {
pushNotification,
@@ -94,7 +74,10 @@ import {
useSheetV1Store,
} from "@/store";
import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
-import { databaseNamePrefix } from "@/store/modules/v1/common";
+import {
+ databaseNamePrefix,
+ getProjectAndSchemaDesignSheetId,
+} from "@/store/modules/v1/common";
import { UNKNOWN_ID } from "@/types";
import {
ChangeHistory,
@@ -131,12 +114,9 @@ const props = defineProps({
default: undefined,
},
});
-const emit = defineEmits<{
- (event: "dismiss"): void;
- (event: "created", schemaDesign: SchemaDesign): void;
-}>();
const { t } = useI18n();
+const router = useRouter();
const projectStore = useProjectV1Store();
const databaseStore = useDatabaseV1Store();
const schemaDesignStore = useSchemaDesignStore();
@@ -190,10 +170,6 @@ const allowConfirm = computed(() => {
);
});
-const cancelText = computed(() => {
- return t("common.cancel");
-});
-
const confirmText = computed(() => {
return t("common.create");
});
@@ -214,10 +190,6 @@ const handleBaselineSchemaChange = async (baselineSchema: BaselineSchema) => {
state.schemaDesign = await prepareSchemaDesign();
};
-const cancel = () => {
- emit("dismiss");
-};
-
const project = computed(() => {
const project = projectStore.getProjectByUID(state.projectId || "");
return project;
@@ -291,6 +263,16 @@ const handleConfirm = async () => {
style: "SUCCESS",
title: t("schema-designer.message.created-succeed"),
});
- emit("created", createdSchemaDesign);
+
+ // Go to branch detail page after created.
+ const [, sheetId] = getProjectAndSchemaDesignSheetId(
+ createdSchemaDesign.name
+ );
+ router.push({
+ name: "workspace.branch.detail",
+ params: {
+ branchSlug: `${createdSchemaDesign.title}-${sheetId}`,
+ },
+ });
};
</script>
diff --git a/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue b/frontend/src/components/Branch/BranchDetailView.vue
similarity index 70%
rename from frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
rename to frontend/src/components/Branch/BranchDetailView.vue
index 68c381d39b..7ed1732ac0 100644
--- a/frontend/src/components/SchemaDesigner/EditSchemaDesignPanel.vue
+++ b/frontend/src/components/Branch/BranchDetailView.vue
@@ -1,185 +1,156 @@
<template>
- <NDrawer
- class="min-w-[calc(100%-10rem)] max-w-full"
- :show="true"
- :auto-focus="false"
- :trap-focus="false"
- :close-on-esc="true"
- :native-scrollbar="true"
- resizable
- @update:show="(show: boolean) => !show && emit('dismiss')"
- >
- <NDrawerContent :title="$t('database.branch')" :closable="true">
- <div class="space-y-3 w-full overflow-x-auto">
+ <div class="space-y-3 w-full overflow-x-auto px-4">
+ <div class="w-full flex flex-row justify-between items-center">
+ <div class="w-full flex flex-row justify-start items-center">
+ <span class="flex w-40 items-center shrink-0 text-sm">
+ {{ $t("common.project") }}
+ </span>
+ <a
+ class="normal-link inline-flex items-center"
+ :href="`/project/${projectV1Slug(project)}`"
+ >{{ project.title }}</a
+ >
+ </div>
+ <div>
<div class="w-full flex flex-row justify-between items-center">
- <div class="w-full flex flex-row justify-start items-center">
- <span class="flex w-40 items-center shrink-0 text-sm">
- {{ $t("common.project") }}
- </span>
- <a
- class="normal-link inline-flex items-center"
- :href="`/project/${projectV1Slug(project)}`"
- >{{ project.title }}</a
- >
- </div>
- <div>
- <div class="w-full flex flex-row justify-between items-center">
- <div
- v-if="!viewMode && !state.isEditing"
- class="flex flex-row justify-end items-center space-x-2"
- >
- <NButton
- v-if="parentBranch"
- @click="() => (state.showDiffEditor = true)"
- >{{ $t("schema-designer.merge-branch") }}</NButton
- >
- <NButton type="primary" @click="handleApplySchemaDesignClick">{{
- $t("schema-designer.apply-to-database")
- }}</NButton>
- </div>
- </div>
- </div>
- </div>
-
- <div class="w-full flex flex-row justify-start items-center mt-1">
- <span class="flex w-40 items-center text-sm">{{
- $t("database.branch-name")
- }}</span>
- <div class="flex flex-row justify-start items-center gap-x-4">
- <BBTextField
- class="w-60 text-sm"
- :readonly="!state.isEditingTitle"
- :value="state.schemaDesignTitle"
- :placeholder="'feature/add-billing'"
- @input="
- state.schemaDesignTitle = (
- $event.target as HTMLInputElement
- ).value
- "
- />
-
+ <div
+ v-if="!viewMode && !state.isEditing"
+ class="flex flex-row justify-end items-center space-x-2"
+ >
<NButton
- v-if="!state.isEditingTitle"
- text
- @click="state.isEditingTitle = true"
+ v-if="parentBranch"
+ @click="() => (state.showDiffEditor = true)"
+ >{{ $t("schema-designer.merge-branch") }}</NButton
>
- <template #icon>
- <NIcon size="16">
- <Pen />
- </NIcon>
- </template>
- </NButton>
- <template v-else>
- <NButton text type="warning" @click="handleCancelEditTitle">
- <template #icon>
- <NIcon>
- <X />
- </NIcon>
- </template>
- </NButton>
- <NButton type="success" text @click="handleSaveBranchTitle">
- <template #icon>
- <NIcon>
- <Check />
- </NIcon>
- </template>
- </NButton>
- </template>
-
- <NTag v-if="parentBranch" round>
- {{ $t("schema-designer.parent-branch") }}:
- {{ parentBranch.title }}
- </NTag>
+ <NButton type="primary" @click="handleApplySchemaDesignClick">{{
+ $t("schema-designer.apply-to-database")
+ }}</NButton>
</div>
</div>
+ </div>
+ </div>
+
+ <div class="w-full flex flex-row justify-start items-center mt-1">
+ <span class="flex w-40 items-center text-sm">{{
+ $t("database.branch-name")
+ }}</span>
+ <div class="flex flex-row justify-start items-center gap-x-4">
+ <BBTextField
+ class="w-60 text-sm"
+ :readonly="!state.isEditingTitle"
+ :value="state.schemaDesignTitle"
+ :placeholder="'feature/add-billing'"
+ @input="
+ state.schemaDesignTitle = ($event.target as HTMLInputElement).value
+ "
+ />
+
+ <NButton
+ v-if="!state.isEditingTitle"
+ text
+ @click="state.isEditingTitle = true"
+ >
+ <template #icon>
+ <NIcon size="16">
+ <Pen />
+ </NIcon>
+ </template>
+ </NButton>
+ <template v-else>
+ <NButton text type="warning" @click="handleCancelEditTitle">
+ <template #icon>
+ <NIcon>
+ <X />
+ </NIcon>
+ </template>
+ </NButton>
+ <NButton type="success" text @click="handleSaveBranchTitle">
+ <template #icon>
+ <NIcon>
+ <Check />
+ </NIcon>
+ </template>
+ </NButton>
+ </template>
- <NDivider />
-
- <div class="w-full flex flex-row justify-start items-center mt-1">
- <span class="flex w-40 items-center text-sm font-medium">{{
- $t("schema-designer.baseline-version")
- }}</span>
- </div>
-
- <div class="w-full flex flex-row justify-start items-center">
- <span class="flex w-40 items-center shrink-0 text-sm">
- {{ $t("common.database") }}
+ <NTag v-if="parentBranch" round>
+ {{ $t("schema-designer.parent-branch") }}:
+ {{ parentBranch.title }}
+ </NTag>
+ </div>
+ </div>
+
+ <NDivider />
+
+ <div class="w-full flex flex-row justify-start items-center mt-1">
+ <span class="flex w-40 items-center text-sm font-medium">{{
+ $t("schema-designer.baseline-version")
+ }}</span>
+ </div>
+
+ <div class="w-full flex flex-row justify-start items-center">
+ <span class="flex w-40 items-center shrink-0 text-sm">
+ {{ $t("common.database") }}
+ </span>
+ <DatabaseInfo :database="baselineDatabase" />
+ </div>
+
+ <div class="w-full flex flex-row justify-start items-center">
+ <span class="flex w-40 items-center shrink-0 text-sm">
+ {{ $t("schema-designer.schema-version") }}
+ </span>
+ <div class="w-[calc(100%-10rem)]">
+ <div
+ v-if="changeHistory"
+ class="w-full flex flex-row justify-start items-center"
+ >
+ <span class="block pr-2 w-full max-w-[80%] truncate">
+ {{ changeHistory.version }} -
+ {{ changeHistory.description }}
</span>
- <DatabaseInfo :database="baselineDatabase" />
- </div>
-
- <div class="w-full flex flex-row justify-start items-center">
- <span class="flex w-40 items-center shrink-0 text-sm">
- {{ $t("schema-designer.schema-version") }}
+ <span class="text-control-light">
+ {{ humanizeDate(changeHistory.updateTime) }}
</span>
- <div class="w-[calc(100%-10rem)]">
- <div
- v-if="changeHistory"
- class="w-full flex flex-row justify-start items-center"
- >
- <span class="block pr-2 w-full max-w-[80%] truncate">
- {{ changeHistory.version }} -
- {{ changeHistory.description }}
- </span>
- <span class="text-control-light">
- {{ humanizeDate(changeHistory.updateTime) }}
- </span>
- </div>
- <template v-else>
- {{ "Previously latest schema" }}
- </template>
- </div>
- </div>
-
- <NDivider />
-
- <div class="w-full flex flex-row justify-end gap-2">
- <template v-if="!state.isEditing">
- <NButton @click="handleEdit">{{ $t("common.edit") }}</NButton>
- </template>
- <template v-else>
- <NButton @click="handleCancelEdit">{{
- $t("common.cancel")
- }}</NButton>
- <NButton type="primary" @click="handleSaveSchemaDesignDraft">{{
- $t("common.save")
- }}</NButton>
- </template>
- </div>
-
- <div class="w-full h-[32rem]">
- <SchemaEditorV1
- :key="schemaEditorKey"
- :readonly="!state.isEditing"
- :project="project"
- :resource-type="'branch'"
- :branches="[schemaDesign]"
- />
- </div>
- <!-- Don't show delete button in view mode. -->
- <div v-if="!viewMode">
- <BBButtonConfirm
- :style="'DELETE'"
- :button-text="$t('database.delete-this-branch')"
- :require-confirm="true"
- @confirm="deleteSchemaDesign"
- />
</div>
+ <template v-else>
+ {{ "Previously latest schema" }}
+ </template>
</div>
+ </div>
- <template v-if="viewMode" #footer>
- <div class="flex-1 flex items-center justify-between">
- <div></div>
+ <NDivider />
- <div class="flex items-center justify-end gap-x-3">
- <NButton @click.prevent="emit('dismiss')">
- {{ $t("common.close") }}
- </NButton>
- </div>
- </div>
+ <div class="w-full flex flex-row justify-end gap-2">
+ <template v-if="!state.isEditing">
+ <NButton @click="handleEdit">{{ $t("common.edit") }}</NButton>
+ </template>
+ <template v-else>
+ <NButton @click="handleCancelEdit">{{ $t("common.cancel") }}</NButton>
+ <NButton type="primary" @click="handleSaveSchemaDesignDraft">{{
+ $t("common.save")
+ }}</NButton>
</template>
- </NDrawerContent>
- </NDrawer>
+ </div>
+
+ <div class="w-full h-[32rem]">
+ <SchemaEditorV1
+ :key="schemaEditorKey"
+ :readonly="!state.isEditing"
+ :project="project"
+ :resource-type="'branch'"
+ :branches="[schemaDesign]"
+ />
+ </div>
+ <!-- Don't show delete button in view mode. -->
+ <div v-if="!viewMode">
+ <BBButtonConfirm
+ :style="'DELETE'"
+ :button-text="$t('database.delete-this-branch')"
+ :require-confirm="true"
+ @confirm="deleteSchemaDesign"
+ />
+ </div>
+ </div>
<MergeBranchPanel
v-if="state.showDiffEditor"
@@ -194,15 +165,7 @@
import dayjs from "dayjs";
import { cloneDeep, isEqual, uniqueId } from "lodash-es";
import { Pen, X, Check } from "lucide-vue-next";
-import {
- NButton,
- NDrawer,
- NDrawerContent,
- NDivider,
- useDialog,
- NTag,
- NIcon,
-} from "naive-ui";
+import { NButton, NDivider, useDialog, NTag, NIcon } from "naive-ui";
import { Status } from "nice-grpc-common";
import { computed, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
@@ -245,7 +208,6 @@ const props = defineProps<{
schemaDesignName: string;
viewMode?: boolean;
}>();
-const emit = defineEmits(["dismiss"]);
const { t } = useI18n();
const router = useRouter();
@@ -637,6 +599,8 @@ const handleApplySchemaDesignClick = () => {
const deleteSchemaDesign = async () => {
await schemaDesignStore.deleteSchemaDesign(schemaDesign.value.name);
- emit("dismiss");
+ router.replace({
+ name: "workspace.branch",
+ });
};
</script>
diff --git a/frontend/src/components/SchemaDesigner/BranchTable.vue b/frontend/src/components/Branch/BranchTable.vue
similarity index 98%
rename from frontend/src/components/SchemaDesigner/BranchTable.vue
rename to frontend/src/components/Branch/BranchTable.vue
index 43e2503165..3093ce2395 100644
--- a/frontend/src/components/SchemaDesigner/BranchTable.vue
+++ b/frontend/src/components/Branch/BranchTable.vue
@@ -4,6 +4,7 @@
:show-placeholder="true"
:column-list="COLUMN_LIST"
:data-source="branches"
+ :ready="ready"
v-bind="$attrs"
@click-row="clickBranch"
>
@@ -54,6 +55,7 @@ const emit = defineEmits<{
const props = defineProps<{
branches: SchemaDesign[];
hideProjectColumn?: boolean;
+ ready?: boolean;
}>();
const { t } = useI18n();
diff --git a/frontend/src/components/SchemaDesigner/MergeBranchPanel.vue b/frontend/src/components/Branch/MergeBranchPanel.vue
similarity index 100%
rename from frontend/src/components/SchemaDesigner/MergeBranchPanel.vue
rename to frontend/src/components/Branch/MergeBranchPanel.vue
diff --git a/frontend/src/components/SchemaDesigner/utils.ts b/frontend/src/components/Branch/utils.ts
similarity index 100%
rename from frontend/src/components/SchemaDesigner/utils.ts
rename to frontend/src/components/Branch/utils.ts
diff --git a/frontend/src/components/BranchTablePanel.vue b/frontend/src/components/BranchTablePanel.vue
deleted file mode 100644
index ba8da54a51..0000000000
--- a/frontend/src/components/BranchTablePanel.vue
+++ /dev/null
@@ -1,103 +0,0 @@
-<template>
- <div class="space-y-3 pt-1 w-full overflow-x-auto">
- <div
- class="w-full border-b pb-2 mb-2 flex flex-row justify-between items-center"
- >
- <div class="flex flex-row justify-start items-center space-x-2"></div>
- <div class="flex flex-row justify-end items-center gap-x-2">
- <NInput
- v-model:value="state.searchKeyword"
- class="!w-36"
- clearable
- :placeholder="$t('schema-designer.action.filter-by-name')"
- />
- <NButton type="primary" @click="state.showCreatePanel = true">
- <heroicons-solid:plus class="w-4 h-auto mr-0.5" />
- <span>{{ $t("database.new-branch") }}</span>
- </NButton>
- </div>
- </div>
-
- <BranchTable
- v-if="ready"
- :branches="filteredBranches"
- :hide-project-column="hideProjectColumn"
- @click="handleBranchClick"
- />
- <div v-else class="w-full h-[20rem] flex items-center justify-center">
- <BBSpin />
- </div>
- </div>
-
- <CreateSchemaDesignPanel
- v-if="state.showCreatePanel"
- :project-id="projectId"
- @dismiss="state.showCreatePanel = false"
- @created="
- (schemaDesign: SchemaDesign) => {
- state.showCreatePanel = false;
- handleBranchClick(schemaDesign);
- }
- "
- />
-
- <EditSchemaDesignPanel
- v-if="state.selectedSchemaDesignName"
- :schema-design-name="state.selectedSchemaDesignName"
- @dismiss="state.selectedSchemaDesignName = undefined"
- />
-</template>
-
-<script lang="ts" setup>
-import { orderBy } from "lodash-es";
-import { NButton, NInput } from "naive-ui";
-import { computed, reactive } from "vue";
-import BranchTable from "@/components/SchemaDesigner/BranchTable.vue";
-import CreateSchemaDesignPanel from "@/components/SchemaDesigner/CreateSchemaDesignPanel.vue";
-import EditSchemaDesignPanel from "@/components/SchemaDesigner/EditSchemaDesignPanel.vue";
-import { useProjectV1Store } from "@/store";
-import { useSchemaDesignList } from "@/store/modules/schemaDesign";
-import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
-
-const props = defineProps<{
- projectId?: string;
- hideProjectColumn?: boolean;
-}>();
-
-interface LocalState {
- searchKeyword: string;
- showCreatePanel: boolean;
- selectedSchemaDesignName?: string;
-}
-
-const projectV1Store = useProjectV1Store();
-const { schemaDesignList, ready } = useSchemaDesignList();
-const state = reactive<LocalState>({
- searchKeyword: "",
- showCreatePanel: false,
-});
-
-const project = computed(() =>
- projectV1Store.getProjectByUID(props.projectId || "")
-);
-
-const filteredBranches = computed(() => {
- return orderBy(
- props.projectId
- ? schemaDesignList.value.filter((schemaDesign) =>
- schemaDesign.name.startsWith(project.value.name)
- )
- : schemaDesignList.value,
- "updateTime",
- "desc"
- ).filter((branch) => {
- return state.searchKeyword
- ? branch.title.includes(state.searchKeyword)
- : true;
- });
-});
-
-const handleBranchClick = async (schemaDesign: SchemaDesign) => {
- state.selectedSchemaDesignName = schemaDesign.name;
-};
-</script>
diff --git a/frontend/src/components/ProjectBranchesPanel.vue b/frontend/src/components/ProjectBranchesPanel.vue
index 32e416b890..b631e81e23 100644
--- a/frontend/src/components/ProjectBranchesPanel.vue
+++ b/frontend/src/components/ProjectBranchesPanel.vue
@@ -1,11 +1,93 @@
<template>
- <BranchTablePanel :project-id="projectId" :hide-project-column="true" />
+ <div class="space-y-3 pt-2 w-full overflow-x-auto">
+ <div class="w-full flex flex-row justify-between items-center">
+ <div class="flex flex-row justify-start items-center space-x-2">
+ <NButton type="primary" @click="handleCreateBranch">
+ <heroicons-solid:plus class="w-4 h-auto mr-0.5" />
+ <span>{{ $t("database.new-branch") }}</span>
+ </NButton>
+ </div>
+ <div class="flex flex-row justify-end items-center gap-x-2">
+ <NInput
+ v-model:value="state.searchKeyword"
+ class="!w-36"
+ clearable
+ :placeholder="$t('schema-designer.action.filter-by-name')"
+ />
+ </div>
+ </div>
+
+ <BranchTable
+ :branches="filteredBranches"
+ :hide-project-column="true"
+ :ready="ready"
+ @click="handleBranchClick"
+ />
+ </div>
</template>
<script lang="ts" setup>
-import BranchTablePanel from "@/components/BranchTablePanel.vue";
+import { orderBy } from "lodash-es";
+import { NButton, NInput } from "naive-ui";
+import { computed, reactive } from "vue";
+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 { SchemaDesign } from "@/types/proto/v1/schema_design_service";
-defineProps<{
+const props = defineProps<{
projectId?: string;
}>();
+
+interface LocalState {
+ searchKeyword: string;
+}
+
+const router = useRouter();
+const projectV1Store = useProjectV1Store();
+const { schemaDesignList, ready } = useSchemaDesignList();
+const state = reactive<LocalState>({
+ searchKeyword: "",
+});
+
+const project = computed(() =>
+ projectV1Store.getProjectByUID(props.projectId || "")
+);
+
+const filteredBranches = computed(() => {
+ return orderBy(
+ props.projectId
+ ? schemaDesignList.value.filter((schemaDesign) =>
+ schemaDesign.name.startsWith(project.value.name)
+ )
+ : schemaDesignList.value,
+ "updateTime",
+ "desc"
+ ).filter((branch) => {
+ return state.searchKeyword
+ ? branch.title.includes(state.searchKeyword)
+ : true;
+ });
+});
+
+const handleCreateBranch = () => {
+ router.push({
+ name: "workspace.branch.detail",
+ params: {
+ branchSlug: "new",
+ },
+ });
+};
+
+const handleBranchClick = async (schemaDesign: SchemaDesign) => {
+ const [, sheetId] = getProjectAndSchemaDesignSheetId(schemaDesign.name);
+ router.push({
+ name: "workspace.branch.detail",
+ params: {
+ branchSlug: `${schemaDesign.title}-${sheetId}`,
+ },
+ });
+};
</script>
diff --git a/frontend/src/components/SchemaDesigner/PrepForm/index.vue b/frontend/src/components/SchemaDesigner/PrepForm/index.vue
deleted file mode 100644
index 3428758be5..0000000000
--- a/frontend/src/components/SchemaDesigner/PrepForm/index.vue
+++ /dev/null
@@ -1,24 +0,0 @@
-<template>
- <DrawerContent>
- <template #header>
- <div class="flex flex-col gap-y-1">
- <span>{{ $t("database.branches") }}</span>
- </div>
- </template>
-
- <div
- class="w-full sm:w-[calc(100vw-16rem)] max-w-[calc(100vw-8rem)] overflow-x-auto"
- >
- <BranchTablePanel :project-id="projectId" />
- </div>
- </DrawerContent>
-</template>
-
-<script lang="ts" setup>
-import BranchTablePanel from "@/components/BranchTablePanel.vue";
-import { DrawerContent } from "@/components/v2";
-
-defineProps<{
- projectId?: string;
-}>();
-</script>
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index d3afb7abc1..4e2c83cfc0 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2951,6 +2951,7 @@
"schema-version": "Schema version",
"personal-draft": "Personal draft",
"baseline-version": "Baseline version",
+ "new-branch": "New branch",
"parent-branch": "Parent branch",
"save-draft": "Save draft",
"merge-branch": "Merge branch",
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 12739d012d..38d57813a8 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2949,6 +2949,7 @@
"schema-version": "Versión del esquema",
"personal-draft": "Borrador personal",
"baseline-version": "Versión de referencia",
+ "new-branch": "Nueva rama",
"parent-branch": "Rama principal",
"save-draft": "Guardar borrador",
"merge-branch": "Fusionar rama",
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index f645439dfc..e86d368dac 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2944,6 +2944,7 @@
"schema-version": "Schema 版本",
"personal-draft": "个人草稿",
"baseline-version": "基线版本",
+ "new-branch": "新建分支",
"parent-branch": "父分支",
"save-draft": "保存草稿",
"merge-branch": "合并分支",
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 210bcde830..0dc770a105 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -1373,6 +1373,7 @@ 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;
@@ -1460,6 +1461,13 @@ router.beforeEach((to, from, next) => {
return;
}
+ if (branchSlug) {
+ // We've moved the preparation data fetch jobs into BranchDetail page
+ // so just next() here.
+ next();
+ return;
+ }
+
if (databaseSlug) {
if (databaseSlug.toLowerCase() == "grant") {
next();
diff --git a/frontend/src/store/modules/router.ts b/frontend/src/store/modules/router.ts
index 00546190e8..40ef37b6ba 100644
--- a/frontend/src/store/modules/router.ts
+++ b/frontend/src/store/modules/router.ts
@@ -86,6 +86,19 @@ export const useRouterStore = defineStore("router", {
}
}
+ {
+ // /branch/:branchSlug
+ // Total 2 elements, 2nd element is the branch slug
+ const branchComponents = currentRoute.path.match(
+ "/branch/([0-9a-zA-Z_-]+)"
+ ) || ["/", 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/types/common.ts b/frontend/src/types/common.ts
index f3126d3510..eebd4fa2f8 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -50,6 +50,7 @@ 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 5969e7069f..baf1baa20a 100644
--- a/frontend/src/utils/slug.ts
+++ b/frontend/src/utils/slug.ts
@@ -55,6 +55,10 @@ 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/SyncDatabaseSchema/SchemaDesignSelector.vue b/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
index d849a82ba9..6a3d533aff 100644
--- a/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
+++ b/frontend/src/views/SyncDatabaseSchema/SchemaDesignSelector.vue
@@ -7,7 +7,7 @@
{{ $t("database.select-branch") }}
</span>
<div>
- <NButton @click="state.showCreatePanel = true">
+ <NButton @click="handleCreateBranch">
<heroicons-solid:plus class="w-4 h-auto mr-0.5" />
<span>{{ $t("database.new-branch") }}</span>
</NButton>
@@ -55,35 +55,16 @@
</template>
</BBGrid>
</div>
-
- <CreateSchemaDesignPanel
- v-if="state.showCreatePanel"
- @dismiss="state.showCreatePanel = false"
- @created="
- (schemaDesign) => {
- state.showCreatePanel = false;
- clickSchemaDesign(schemaDesign);
- }
- "
- />
-
- <EditSchemaDesignPanel
- v-if="state.showEditPanel && selectedSchemaDesign"
- :schema-design-name="selectedSchemaDesign.name"
- :view-mode="true"
- @dismiss="state.showEditPanel = false"
- />
</template>
<script lang="ts" setup>
import dayjs from "dayjs";
import { NRadio, NButton, NEllipsis } from "naive-ui";
-import { computed, ref, reactive } from "vue";
+import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
+import { useRouter } from "vue-router";
import { BBGridColumn } from "@/bbkit";
import DatabaseInfo from "@/components/DatabaseInfo.vue";
-import CreateSchemaDesignPanel from "@/components/SchemaDesigner/CreateSchemaDesignPanel.vue";
-import EditSchemaDesignPanel from "@/components/SchemaDesigner/EditSchemaDesignPanel.vue";
import { useDatabaseV1Store, useProjectV1Store, useUserStore } from "@/store";
import {
useSchemaDesignList,
@@ -96,11 +77,6 @@ import {
} from "@/types/proto/v1/schema_design_service";
import { projectV1Name } from "@/utils";
-interface LocalState {
- showCreatePanel: boolean;
- showEditPanel: boolean;
-}
-
const emit = defineEmits<{
(event: "select", schemaDesign: SchemaDesign): void;
}>();
@@ -110,15 +86,12 @@ const props = defineProps<{
}>();
const { t } = useI18n();
+const router = useRouter();
const userV1Store = useUserStore();
const projectV1Store = useProjectV1Store();
const databaseV1Store = useDatabaseV1Store();
const schemaDesignStore = useSchemaDesignStore();
const { schemaDesignList } = useSchemaDesignList();
-const state = reactive<LocalState>({
- showCreatePanel: false,
- showEditPanel: false,
-});
const selectedSchemaDesign = ref<SchemaDesign | undefined>(
props.selectedSchemaDesign
);
@@ -177,8 +150,24 @@ const clickSchemaDesign = (schemaDesign: SchemaDesign) => {
emit("select", schemaDesign);
};
+const handleCreateBranch = () => {
+ const route = router.resolve({
+ name: "workspace.branch.detail",
+ params: {
+ branchSlug: "new",
+ },
+ });
+ window.open(route.href, "_blank");
+};
+
const handleViewSchemaDesign = (schemaDesign: SchemaDesign) => {
- clickSchemaDesign(schemaDesign);
- state.showEditPanel = true;
+ const [, sheetId] = getProjectAndSchemaDesignSheetId(schemaDesign.name);
+ const route = router.resolve({
+ name: "workspace.branch.detail",
+ params: {
+ branchSlug: `${schemaDesign.title}-${sheetId}`,
+ },
+ });
+ window.open(route.href, "_blank");
};
</script>
diff --git a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
index 0801ba5bfd..ecbdb909bf 100644
--- a/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
+++ b/frontend/src/views/SyncDatabaseSchema/SelectTargetDatabasesView.vue
@@ -66,7 +66,7 @@
<span>{{ $t("database.branch") }} - </span>
<span
class="normal-link inline-flex items-center"
- @click="state.showViewSchemaDesignPanel = true"
+ @click="handleViewBranch"
>
<EngineIcon class="mr-1" :engine="engine" />
{{ selectedSchemaDesign?.title || "Unknown" }}
@@ -241,13 +241,6 @@
@update="handleSelectedDatabaseIdListChanged"
/>
- <EditSchemaDesignPanel
- v-if="state.showViewSchemaDesignPanel && selectedSchemaDesign"
- :schema-design-name="selectedSchemaDesign.name"
- :view-mode="true"
- @dismiss="state.showViewSchemaDesignPanel = false"
- />
-
<RawSQLEditorPanel
v-if="state.showViewRawSQLPanel && rawSqlState"
:raw-sql-state="rawSqlState"
@@ -262,7 +255,7 @@ import { head } from "lodash-es";
import { NEllipsis } from "naive-ui";
import { computed, nextTick, onMounted, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
-import EditSchemaDesignPanel from "@/components/SchemaDesigner/EditSchemaDesignPanel.vue";
+import { useRouter } from "vue-router";
import { InstanceV1EngineIcon } from "@/components/v2";
import { sqlServiceClient } from "@/grpcweb";
import {
@@ -273,6 +266,7 @@ import {
useSheetV1Store,
} from "@/store";
import { useSchemaDesignStore } from "@/store/modules/schemaDesign";
+import { getProjectAndSchemaDesignSheetId } from "@/store/modules/v1/common";
import { ComposedDatabase, UNKNOWN_ID } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import { ChangeHistory } from "@/types/proto/v1/database_service";
@@ -307,6 +301,7 @@ const props = defineProps<{
}>();
const { t } = useI18n();
+const router = useRouter();
const environmentV1Store = useEnvironmentV1Store();
const databaseStore = useDatabaseV1Store();
const schemaDesignStore = useSchemaDesignStore();
@@ -446,6 +441,23 @@ onMounted(async () => {
}
});
+const handleViewBranch = () => {
+ if (!selectedSchemaDesign.value) {
+ return;
+ }
+
+ const [, sheetId] = getProjectAndSchemaDesignSheetId(
+ selectedSchemaDesign.value.name
+ );
+ const route = router.resolve({
+ name: "workspace.branch.detail",
+ params: {
+ branchSlug: `${selectedSchemaDesign.value.title}-${sheetId}`,
+ },
+ });
+ window.open(route.href, "_blank");
+};
+
const getSourceDatabase = () => {
if (!props.databaseSourceSchema) {
return;
diff --git a/frontend/src/views/branch/BranchDashboard.vue b/frontend/src/views/branch/BranchDashboard.vue
index 0fc57dd1dc..f3f2971e13 100644
--- a/frontend/src/views/branch/BranchDashboard.vue
+++ b/frontend/src/views/branch/BranchDashboard.vue
@@ -2,7 +2,7 @@
<div class="space-y-3 pt-2 w-full overflow-x-auto">
<div class="w-full px-4 flex flex-row justify-between items-center">
<div class="flex flex-row justify-start items-center space-x-2">
- <NButton type="primary" @click="state.showCreatePanel = true">
+ <NButton type="primary" @click="handleCreateBranch">
<heroicons-solid:plus class="w-4 h-auto mr-0.5" />
<span>{{ $t("database.new-branch") }}</span>
</NButton>
@@ -18,86 +18,60 @@
</div>
<BranchTable
- v-if="ready"
:branches="filteredBranches"
- :hide-project-column="hideProjectColumn"
+ :ready="ready"
class="border-x-0"
@click="handleBranchClick"
/>
- <div v-else class="w-full h-[20rem] flex items-center justify-center">
- <BBSpin />
- </div>
</div>
-
- <CreateSchemaDesignPanel
- v-if="state.showCreatePanel"
- :project-id="projectId"
- @dismiss="state.showCreatePanel = false"
- @created="
- (schemaDesign: SchemaDesign) => {
- state.showCreatePanel = false;
- handleBranchClick(schemaDesign);
- }
- "
- />
-
- <EditSchemaDesignPanel
- v-if="state.selectedSchemaDesignName"
- :schema-design-name="state.selectedSchemaDesignName"
- @dismiss="state.selectedSchemaDesignName = undefined"
- />
</template>
<script lang="ts" setup>
import { orderBy } from "lodash-es";
import { NButton, NInput } from "naive-ui";
import { computed, reactive } from "vue";
-import BranchTable from "@/components/SchemaDesigner/BranchTable.vue";
-import CreateSchemaDesignPanel from "@/components/SchemaDesigner/CreateSchemaDesignPanel.vue";
-import EditSchemaDesignPanel from "@/components/SchemaDesigner/EditSchemaDesignPanel.vue";
-import { useProjectV1Store } from "@/store";
+import { useRouter } from "vue-router";
+import BranchTable from "@/components/Branch/BranchTable.vue";
import { useSchemaDesignList } from "@/store/modules/schemaDesign";
+import { getProjectAndSchemaDesignSheetId } from "@/store/modules/v1/common";
import { SchemaDesign } from "@/types/proto/v1/schema_design_service";
-const props = defineProps<{
- projectId?: string;
- hideProjectColumn?: boolean;
-}>();
-
interface LocalState {
searchKeyword: string;
- showCreatePanel: boolean;
- selectedSchemaDesignName?: string;
}
-const projectV1Store = useProjectV1Store();
+const router = useRouter();
const { schemaDesignList, ready } = useSchemaDesignList();
const state = reactive<LocalState>({
searchKeyword: "",
- showCreatePanel: false,
});
-const project = computed(() =>
- projectV1Store.getProjectByUID(props.projectId || "")
-);
-
const filteredBranches = computed(() => {
- return orderBy(
- props.projectId
- ? schemaDesignList.value.filter((schemaDesign) =>
- schemaDesign.name.startsWith(project.value.name)
- )
- : schemaDesignList.value,
- "updateTime",
- "desc"
- ).filter((branch) => {
- return state.searchKeyword
- ? branch.title.includes(state.searchKeyword)
- : true;
- });
+ return orderBy(schemaDesignList.value, "updateTime", "desc").filter(
+ (branch) => {
+ return state.searchKeyword
+ ? branch.title.includes(state.searchKeyword)
+ : true;
+ }
+ );
});
+const handleCreateBranch = () => {
+ router.push({
+ name: "workspace.branch.detail",
+ params: {
+ branchSlug: "new",
+ },
+ });
+};
+
const handleBranchClick = async (schemaDesign: SchemaDesign) => {
- state.selectedSchemaDesignName = schemaDesign.name;
+ const [, sheetId] = getProjectAndSchemaDesignSheetId(schemaDesign.name);
+ router.push({
+ name: "workspace.branch.detail",
+ params: {
+ branchSlug: `${schemaDesign.title}-${sheetId}`,
+ },
+ });
};
</script>
diff --git a/frontend/src/views/branch/BranchDetail.vue b/frontend/src/views/branch/BranchDetail.vue
index 6f90a1d71b..e3295a88be 100644
--- a/frontend/src/views/branch/BranchDetail.vue
+++ b/frontend/src/views/branch/BranchDetail.vue
@@ -1,4 +1,78 @@
<template>
- <!-- TBC -->
- <p>Detail page placeholder</p>
+ <template v-if="initialized">
+ <template v-if="isCreating">
+ <BranchCreateView />
+ </template>
+ <template v-else-if="branchName">
+ <BranchDetailView :schema-design-name="branchName" />
+ </template>
+ </template>
</template>
+
+<script lang="ts" setup>
+import { useTitle } from "@vueuse/core";
+import { computed, onMounted, ref } from "vue";
+import { useI18n } from "vue-i18n";
+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 sheetStore = useSheetV1Store();
+const projectStore = useProjectV1Store();
+const schemaDesignStore = useSchemaDesignStore();
+const initialized = ref(false);
+
+const isCreating = computed(() => props.branchSlug === "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}`;
+});
+
+onMounted(async () => {
+ if (!isCreating.value) {
+ const sheetId = idFromSlug(props.branchSlug);
+ const sheet = await sheetStore.getOrFetchSheetByUID(`${sheetId}`);
+ if (sheet) {
+ const [projectName] = getProjectAndSheetId(sheet.name);
+ const project = await projectStore.getOrFetchProjectByName(
+ `projects/${projectName}`
+ );
+ await schemaDesignStore.getOrFetchSchemaDesignByName(
+ `projects/${project}/schemaDesigns/${sheetId}`
+ );
+ }
+ }
+ initialized.value = true;
+});
+
+const documentTitle = computed(() => {
+ if (isCreating.value) {
+ return t("schema-designer.new-branch");
+ } else {
+ if (branchName.value) {
+ const schemaDesign = schemaDesignStore.getSchemaDesignByName(
+ branchName.value
+ );
+ return `${schemaDesign.title} - ${t("common.branch")}`;
+ }
+ }
+ return t("common.loading");
+});
+useTitle(documentTitle);
+</script>