Skip to content

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

feat(branching): merge and rebase branch (#10019)

Liu Ji753180b934fe
diff --git a/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue b/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue
index e40fb725a7..99f8f78883 100644
--- a/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue
+++ b/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue
@@ -1,5 +1,5 @@
<template>
- <div class="flex flex-row justify-start items-center gap-1">
+ <div class="flex flex-row justify-start items-center gap-1 whitespace-nowrap">
<div
class="flex flex-row gap-x-1 mr-1 justify-start items-center border border-gray-200 rounded-md p-0.5 px-2"
>
diff --git a/frontend/src/components/Branch/BranchDataTable/index.vue b/frontend/src/components/Branch/BranchDataTable/index.vue
index 2110213575..7c174623aa 100644
--- a/frontend/src/components/Branch/BranchDataTable/index.vue
+++ b/frontend/src/components/Branch/BranchDataTable/index.vue
@@ -62,7 +62,7 @@ const columns = computed(() => {
{
title: t("schema-designer.baseline-version"),
key: "baselineVersion",
- width: 256,
+ width: 300,
render: (row: Branch) => {
return h(BranchBaseline, {
branch: row,
@@ -73,7 +73,7 @@ const columns = computed(() => {
{
title: t("common.updated"),
key: "updated",
- width: 256,
+ width: 200,
render: (row: Branch) => {
return h(BranchUpdatedCell, {
branch: row,
diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vue
index 0f0a740ceb..91d94e95b6 100644
--- a/frontend/src/components/Branch/BranchDetailView.vue
+++ b/frontend/src/components/Branch/BranchDetailView.vue
@@ -48,11 +48,12 @@
>
<template v-if="!state.isEditing">
<NButton @click="handleEdit">{{ $t("common.edit") }}</NButton>
- <NButton
- :disabled="!branchListReady"
- @click="handleMergeBranch"
- >{{ $t("schema-designer.merge-branch") }}</NButton
- >
+ <NButton @click="handleGotoMergeBranch">
+ {{ $t("branch.merge-rebase.merge-branch") }}
+ </NButton>
+ <NButton @click="handleGotoRebaseBranch">
+ {{ $t("branch.merge-rebase.rebase-branch") }}
+ </NButton>
<NButton
v-if="showApplyBranchButton"
type="primary"
@@ -117,21 +118,12 @@
@close="selectTargetDatabasesContext.show = false"
@update="handleApplyToDatabase"
/>
-
- <MergeBranchPanel
- v-if="state.showDiffEditor && mergeBranchPanelContext"
- :project="project"
- :head-branch-name="mergeBranchPanelContext.headBranchName"
- :branch-name="mergeBranchPanelContext.branchName"
- @dismiss="state.showDiffEditor = false"
- @merged="handleMergeAfterConflictResolved"
- />
</template>
<script lang="ts" setup>
import { asyncComputed } from "@vueuse/core";
import dayjs from "dayjs";
-import { cloneDeep, head } from "lodash-es";
+import { cloneDeep } from "lodash-es";
import { NButton, NDivider, NInput } from "naive-ui";
import { CSSProperties, computed, nextTick, reactive, ref, watch } from "vue";
import { useI18n } from "vue-i18n";
@@ -140,11 +132,8 @@ import DatabaseInfo from "@/components/DatabaseInfo.vue";
import { validateDatabaseMetadata } from "@/components/SchemaEditorV1/utils";
import TargetDatabasesSelectPanel from "@/components/SyncDatabaseSchema/TargetDatabasesSelectPanel.vue";
import { pushNotification, useDatabaseV1Store } from "@/store";
-import { useBranchListByProject, useBranchStore } from "@/store/modules/branch";
-import {
- getProjectAndBranchId,
- projectNamePrefix,
-} from "@/store/modules/v1/common";
+import { useBranchStore } from "@/store/modules/branch";
+import { getProjectAndBranchId } from "@/store/modules/v1/common";
import { ComposedProject } from "@/types";
import { Branch } from "@/types/proto/v1/branch_service";
import { DatabaseMetadata } from "@/types/proto/v1/database_service";
@@ -152,7 +141,6 @@ import { projectV1Slug } from "@/utils";
import { provideSQLCheckContext } from "../SQLCheck";
import { generateDiffDDL } from "../SchemaEditorLite";
import MaskSpinner from "../misc/MaskSpinner.vue";
-import MergeBranchPanel from "./MergeBranchPanel.vue";
import SchemaDesignEditorLite from "./SchemaDesignEditorLite.vue";
import { validateBranchName } from "./utils";
@@ -180,9 +168,6 @@ const { t } = useI18n();
const router = useRouter();
const databaseStore = useDatabaseV1Store();
const branchStore = useBranchStore();
-const { branchList, ready: branchListReady } = useBranchListByProject(
- computed(() => props.project.name)
-);
const { runSQLCheck } = provideSQLCheckContext();
const schemaDesignerRef = ref<InstanceType<typeof SchemaDesignEditorLite>>();
const state = reactive<LocalState>({
@@ -194,10 +179,6 @@ const state = reactive<LocalState>({
savingStatus: "",
applyingToDatabaseStatus: false,
});
-const mergeBranchPanelContext = ref<{
- headBranchName: string;
- branchName: string;
-}>();
const selectTargetDatabasesContext = ref<{
show: boolean;
}>({
@@ -322,35 +303,6 @@ const handleParentBranchClick = async () => {
});
};
-const handleMergeBranch = () => {
- const branch = props.dirtyBranch;
- const tempList = branchList.value.filter((item) => {
- const [projectName] = getProjectAndBranchId(item.name);
- return (
- `${projectNamePrefix}${projectName}` === props.project.name &&
- item.engine === branch.engine &&
- item.name !== branch.name
- );
- });
- const branchName = parentBranch.value
- ? parentBranch.value.name
- : head(tempList)?.name;
- if (!branchName) {
- pushNotification({
- module: "bytebase",
- style: "CRITICAL",
- title: "No branch to merge.",
- });
- return;
- }
-
- mergeBranchPanelContext.value = {
- headBranchName: branch.name,
- branchName: branchName,
- };
- state.showDiffEditor = true;
-};
-
const handleEdit = async () => {
state.isEditing = true;
};
@@ -437,15 +389,21 @@ const handleSaveBranch = async () => {
cleanup(/* success */ true);
};
-const handleMergeAfterConflictResolved = (branchName: string) => {
- state.showDiffEditor = false;
- state.isEditing = false;
- const [_, branchId] = getProjectAndBranchId(branchName);
- router.replace({
- name: "workspace.project.branch.detail",
+const handleGotoMergeBranch = () => {
+ router.push({
+ name: "workspace.project.branch.merge",
params: {
projectSlug: projectV1Slug(props.project),
- branchName: branchId,
+ branchName: props.cleanBranch.branchId,
+ },
+ });
+};
+const handleGotoRebaseBranch = () => {
+ router.push({
+ name: "workspace.project.branch.rebase",
+ params: {
+ projectSlug: projectV1Slug(props.project),
+ branchName: props.cleanBranch.branchId,
},
});
};
diff --git a/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue b/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue
new file mode 100644
index 0000000000..deff65b5be
--- /dev/null
+++ b/frontend/src/components/Branch/BranchMergeView/BranchMergeView.vue
@@ -0,0 +1,254 @@
+<template>
+ <div class="h-full relative">
+ <StepTab
+ :step-list="stepList"
+ :current-index="state.currentStepIndex"
+ :show-cancel="false"
+ :allow-next="allowNextStep"
+ class="h-full flex flex-col !space-y-0 gap-y-4"
+ pane-class="flex-1 flex flex-col gap-y-2 relative"
+ footer-class="!space-y-0 !border-0 !pt-0"
+ @update:current-index="tryChangeStep"
+ @finish="handleMergeBranch"
+ >
+ <template #0>
+ <SelectBranchStep
+ v-model:delete-branch-after-merged="state.deleteBranchAfterMerged"
+ :project="project"
+ :head-branch="headBranch"
+ :target-branch="targetBranch"
+ :is-loading-head-branch="isLoadingHeadBranch"
+ :is-loading-target-branch="isLoadingTargetBranch"
+ :is-validating="isValidating"
+ :validation-state="validationState"
+ @update:head-branch-name="handleUpdateHeadBranch"
+ @update:target-branch-name="state.targetBranchName = $event || null"
+ />
+ </template>
+ <template #1>
+ <MergeBranchStep
+ v-if="targetBranch && headBranch && validationState?.branch"
+ :project="project"
+ :merged-branch="validationState.branch"
+ />
+ </template>
+ </StepTab>
+ <MaskSpinner v-if="state.isMerging" />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computedAsync } from "@vueuse/core";
+import { Status } from "nice-grpc-common";
+import { computed, reactive, ref, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import MaskSpinner from "@/components/misc/MaskSpinner.vue";
+import { StepTab } from "@/components/v2";
+import { branchServiceClient } from "@/grpcweb";
+import { pushNotification, useBranchStore } from "@/store";
+import { ComposedProject } from "@/types";
+import { Branch } from "@/types/proto/v1/branch_service";
+import { getErrorCode } from "@/utils/grpcweb";
+import MergeBranchStep from "./MergeBranchStep.vue";
+import SelectBranchStep from "./SelectBranchStep.vue";
+import { MergeBranchValidationState } from "./types";
+
+interface LocalState {
+ currentStepIndex: number;
+ targetBranchName: string | null;
+ deleteBranchAfterMerged: boolean;
+ isMerging: boolean;
+}
+
+const props = defineProps<{
+ project: ComposedProject;
+ headBranchName: string | null;
+}>();
+
+const emit = defineEmits<{
+ (
+ event: "merged",
+ mergedBranch: Branch,
+ headBranchName: string,
+ headBranch: Branch | undefined
+ ): void;
+ (event: "update:head-branch-name", branchName: string | null): void;
+}>();
+
+const state = reactive<LocalState>({
+ currentStepIndex: 0,
+ targetBranchName: null,
+ deleteBranchAfterMerged: false,
+ isMerging: false,
+});
+const { t } = useI18n();
+const branchStore = useBranchStore();
+const isLoadingHeadBranch = ref(false);
+const isLoadingTargetBranch = ref(false);
+const isValidating = ref(false);
+const combinedIsLoadingBranch = computed(() => {
+ return isLoadingHeadBranch.value || isLoadingTargetBranch.value;
+});
+
+const stepList = computed(() => [
+ { title: t("branch.select-branch") },
+ { title: t("common.preview") },
+]);
+const STEP_SELECT_BRANCH = 0;
+const STEP_MERGE_BRANCH = 1;
+
+const headBranch = computedAsync(
+ async () => {
+ const name = props.headBranchName;
+ if (!name) {
+ return undefined;
+ }
+ // Don't use local store cache since we need to ensure the branch is
+ // fresh clean here
+ return await branchStore.fetchBranchByName(name, /* !useCache */ false);
+ },
+ undefined,
+ {
+ evaluating: isLoadingHeadBranch,
+ }
+);
+
+const targetBranch = computedAsync(
+ async () => {
+ const name = state.targetBranchName;
+ if (!name) {
+ return undefined;
+ }
+ // Don't use local store cache since we need to ensure the branch is
+ // fresh clean here
+ return await branchStore.fetchBranchByName(name, /* !useCache */ false);
+ },
+ undefined,
+ {
+ evaluating: isLoadingTargetBranch,
+ }
+);
+
+const validationState = computedAsync(
+ async (): Promise<MergeBranchValidationState | undefined> => {
+ const head = headBranch.value;
+ const target = targetBranch.value;
+ if (!head) return;
+ if (!target) return;
+ try {
+ const branch = await branchServiceClient.mergeBranch(
+ {
+ name: target.name,
+ headBranch: head.name,
+ validateOnly: true,
+ },
+ {
+ silent: true,
+ }
+ );
+ return {
+ status: Status.OK,
+ branch,
+ };
+ } catch (err) {
+ const status = getErrorCode(err);
+ return {
+ status,
+ };
+ }
+ },
+ undefined,
+ {
+ evaluating: isValidating,
+ }
+);
+const handleUpdateHeadBranch = (branchName: string | undefined) => {
+ emit("update:head-branch-name", branchName || null);
+};
+
+const tryChangeStep = (nextStepIndex: number) => {
+ if (combinedIsLoadingBranch.value) {
+ return;
+ }
+ state.currentStepIndex = nextStepIndex;
+};
+
+const allowNextStep = computed(() => {
+ if (state.currentStepIndex === STEP_SELECT_BRANCH) {
+ return (
+ headBranch.value !== undefined &&
+ targetBranch.value !== undefined &&
+ validationState.value?.status === Status.OK
+ );
+ }
+ if (state.currentStepIndex === STEP_MERGE_BRANCH) {
+ return true;
+ }
+
+ console.error("[BranchMergeView.allowNextStep] should never reach this line");
+ return false;
+});
+
+const handleMergeBranch = async () => {
+ const target = targetBranch.value;
+ if (!target) return;
+ const head = headBranch.value;
+ if (!head) return;
+ state.isMerging = true;
+
+ try {
+ const mergedBranch = await branchStore.mergeBranch({
+ name: target.name,
+ headBranch: head.name,
+ etag: "",
+ validateOnly: false,
+ });
+ if (state.deleteBranchAfterMerged) {
+ await branchStore.deleteBranch(head.name);
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("common.deleted"),
+ });
+ }
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("branch.merge-rebase.merge-succeeded"),
+ });
+
+ emit(
+ "merged",
+ mergedBranch,
+ head.name,
+ state.deleteBranchAfterMerged ? undefined : head
+ );
+ } catch (error: any) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: `Request error occurred`,
+ description: error.details,
+ });
+ } finally {
+ state.isMerging = false;
+ }
+};
+
+watch(
+ headBranch,
+ (head) => {
+ if (head) {
+ // Automatically select the branch's parent as merge target branch
+ // if merge target is empty
+ if (head.parentBranch && !state.targetBranchName) {
+ state.targetBranchName = head.parentBranch;
+ }
+ }
+ },
+ {
+ immediate: true,
+ }
+);
+</script>
diff --git a/frontend/src/components/Branch/BranchMergeView/MergeBranchStep.vue b/frontend/src/components/Branch/BranchMergeView/MergeBranchStep.vue
new file mode 100644
index 0000000000..e8a2a3c163
--- /dev/null
+++ b/frontend/src/components/Branch/BranchMergeView/MergeBranchStep.vue
@@ -0,0 +1,65 @@
+<template>
+ <div class="flex-1 flex flex-col gap-y-1 text-sm">
+ <NTabs v-model:value="tab">
+ <NTab name="schema-editor">
+ {{ $t("schema-editor.self") }}
+ </NTab>
+ <NTab name="raw-schema-text">
+ {{ $t("schema-editor.raw-sql") }}
+ </NTab>
+ </NTabs>
+ <div
+ v-show="tab === 'schema-editor'"
+ class="w-full flex-1 relative text-sm"
+ >
+ <SchemaEditorLite
+ ref="schemaEditorRef"
+ resource-type="branch"
+ :project="project"
+ :readonly="true"
+ :branch="mergedBranch"
+ />
+ </div>
+ <div
+ v-show="tab === 'raw-schema-text'"
+ class="w-full flex-1 relative text-sm border rounded overflow-clip"
+ >
+ <DiffEditor
+ :readonly="true"
+ :original="mergedBranch.baselineSchema"
+ :modified="mergedBranch.schema"
+ class="h-full"
+ />
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { ref, watch } from "vue";
+import SchemaEditorLite from "@/components/SchemaEditorLite";
+import { useDatabaseV1Store } from "@/store";
+import { ComposedProject } from "@/types";
+import { Branch } from "@/types/proto/v1/branch_service";
+import { DatabaseMetadata } from "@/types/proto/v1/database_service";
+
+type TabValue = "schema-editor" | "raw-schema-text";
+
+const props = defineProps<{
+ project: ComposedProject;
+ mergedBranch: Branch;
+}>();
+
+const schemaEditorRef = ref<InstanceType<typeof SchemaEditorLite>>();
+const tab = ref<TabValue>("raw-schema-text");
+
+watch([() => props.mergedBranch, schemaEditorRef], ([branch, editor]) => {
+ if (branch && editor) {
+ const db = useDatabaseV1Store().getDatabaseByName(branch.baselineDatabase);
+ editor.rebuildMetadataEdit(
+ db,
+ branch.baselineSchemaMetadata ?? DatabaseMetadata.fromPartial({}),
+ branch.schemaMetadata ?? DatabaseMetadata.fromPartial({})
+ );
+ }
+});
+</script>
diff --git a/frontend/src/components/Branch/BranchMergeView/SelectBranchStep.vue b/frontend/src/components/Branch/BranchMergeView/SelectBranchStep.vue
new file mode 100644
index 0000000000..08b9c64819
--- /dev/null
+++ b/frontend/src/components/Branch/BranchMergeView/SelectBranchStep.vue
@@ -0,0 +1,201 @@
+<template>
+ <div
+ class="w-full grid grid-cols-4 items-center text-sm gap-x-2"
+ style="grid-template-columns: 1fr auto 1fr auto"
+ >
+ <BranchSelector
+ class="!w-full text-center"
+ :clearable="false"
+ :project="project"
+ :branch="targetBranch?.name"
+ :filter="targetBranchFilter"
+ @update:branch="$emit('update:target-branch-name', $event)"
+ />
+ <div class="flex flex-row justify-center px-2">
+ <MoveLeftIcon :size="40" stroke-width="1" />
+ </div>
+ <BranchSelector
+ class="!full text-center"
+ :clearable="false"
+ :project="project"
+ :branch="headBranch?.name"
+ :filter="headBranchFilter"
+ @update:branch="$emit('update:head-branch-name', $event)"
+ />
+ <NCheckbox
+ :checked="deleteBranchAfterMerged"
+ @update:checked="
+ $emit('update:delete-branch-after-merged', $event as boolean)
+ "
+ >
+ {{ $t("branch.merge-rebase.delete-branch-after-merged") }}
+ </NCheckbox>
+ </div>
+ <div class="w-full flex-1 flex flex-col relative text-sm gap-y-1">
+ <div class="flex flex-row items-center gap-x-1">
+ <span v-if="!headBranch || !targetBranch">
+ {{ $t("branch.merge-rebase.select-branches-to-merge") }}
+ </span>
+ <template v-else>
+ <template v-if="isValidating">
+ <BBSpin class="!w-4 !h-4" />
+ <span>{{ $t("branch.merge-rebase.validating-branch") }}</span>
+ </template>
+ <template v-else-if="validationState">
+ <template v-if="validationState.status === Status.OK">
+ <CheckIcon class="w-4 h-4 text-success" />
+ <span>{{ $t("branch.merge-rebase.able-to-merge") }}</span>
+ </template>
+ <template v-else>
+ <XCircleIcon class="w-4 h-4 text-error" />
+ <i18n-t
+ keypath="branch.merge-rebase.cannot-automatically-merge"
+ tag="span"
+ class="text-error"
+ >
+ <template #rebase_branch>
+ <router-link
+ :to="rebaseLink(headBranch, targetBranch)"
+ class="normal-link"
+ >
+ {{ $t("branch.merge-rebase.go-rebase") }}
+ </router-link>
+ </template>
+ </i18n-t>
+ </template>
+ </template>
+ </template>
+ </div>
+ <NTabs v-model:value="tab">
+ <template v-if="headBranch" #prefix>
+ <div class="text-control-placeholder">
+ {{
+ $t("branch.merge-rebase.changes-of-branch", {
+ branch: headBranch.branchId,
+ })
+ }}
+ </div>
+ </template>
+ <NTab name="schema-editor">
+ {{ $t("schema-editor.self") }}
+ </NTab>
+ <NTab name="raw-schema-text">
+ {{ $t("schema-editor.raw-sql") }}
+ </NTab>
+ </NTabs>
+ <div
+ v-show="tab === 'schema-editor'"
+ class="w-full flex-1 relative text-sm"
+ >
+ <SchemaEditorLite
+ ref="schemaEditorRef"
+ :key="headBranch?.name"
+ resource-type="branch"
+ :project="project"
+ :readonly="true"
+ :loading="isLoadingHeadBranch"
+ :branch="headBranch ?? Branch.fromPartial({})"
+ />
+ <MaskSpinner v-if="isLoadingHeadBranch" />
+ </div>
+ <div
+ v-show="tab === 'raw-schema-text'"
+ class="w-full flex-1 relative text-sm border rounded overflow-clip"
+ >
+ <DiffEditor
+ :readonly="true"
+ :original="headBranch?.baselineSchema"
+ :modified="headBranch?.schema"
+ class="h-full"
+ />
+
+ <MaskSpinner v-if="isLoadingHeadBranch || isLoadingTargetBranch" />
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { CheckIcon, XCircleIcon, MoveLeftIcon } from "lucide-vue-next";
+import { NCheckbox, NTab, NTabs } from "naive-ui";
+import { Status } from "nice-grpc-common";
+import { ref, watch } from "vue";
+import { DiffEditor } from "@/components/MonacoEditor";
+import SchemaEditorLite from "@/components/SchemaEditorLite";
+import MaskSpinner from "@/components/misc/MaskSpinner.vue";
+import { useDatabaseV1Store } from "@/store";
+import { ComposedProject } from "@/types";
+import { Branch } from "@/types/proto/v1/branch_service";
+import { DatabaseMetadata } from "@/types/proto/v1/database_service";
+import { projectSlugV1 } from "@/utils";
+import { MergeBranchValidationState } from "./types";
+
+type TabValue = "schema-editor" | "raw-schema-text";
+
+const props = defineProps<{
+ project: ComposedProject;
+ targetBranch: Branch | undefined;
+ headBranch: Branch | undefined;
+ isLoadingTargetBranch?: boolean;
+ isLoadingHeadBranch?: boolean;
+ isValidating?: boolean;
+ validationState: MergeBranchValidationState | undefined;
+ deleteBranchAfterMerged: boolean;
+}>();
+
+defineEmits<{
+ (event: "update:head-branch-name", branch: string | undefined): void;
+ (event: "update:target-branch-name", branch: string | undefined): void;
+ (event: "update:delete-branch-after-merged", on: boolean): void;
+}>();
+
+const schemaEditorRef = ref<InstanceType<typeof SchemaEditorLite>>();
+const tab = ref<TabValue>("schema-editor");
+
+const targetBranchFilter = (branch: Branch) => {
+ const { headBranch } = props;
+ if (!headBranch) {
+ return true;
+ }
+ return branch.engine === headBranch.engine && branch.name !== headBranch.name;
+};
+const headBranchFilter = (branch: Branch) => {
+ const { targetBranch } = props;
+ if (!targetBranch) {
+ return true;
+ }
+ return (
+ branch.engine === targetBranch.engine && branch.name !== targetBranch.name
+ );
+};
+
+const rebaseLink = (headBranch: Branch, targetBranch: Branch) => {
+ return {
+ name: "workspace.project.branch.rebase",
+ params: {
+ projectSlug: projectSlugV1(props.project),
+ branchName: headBranch.branchId,
+ },
+ query: {
+ source: targetBranch.branchId,
+ },
+ };
+};
+
+// re-calculate diff for coloring when branch changed
+watch(
+ [() => props.headBranch, schemaEditorRef],
+ ([head, editor]) => {
+ if (head && editor) {
+ const db = useDatabaseV1Store().getDatabaseByName(head.baselineDatabase);
+ editor.rebuildMetadataEdit(
+ db,
+ head.baselineSchemaMetadata ?? DatabaseMetadata.fromPartial({}),
+ head.schemaMetadata ?? DatabaseMetadata.fromPartial({})
+ );
+ }
+ },
+ {
+ immediate: true,
+ }
+);
+</script>
diff --git a/frontend/src/components/Branch/BranchMergeView/index.ts b/frontend/src/components/Branch/BranchMergeView/index.ts
new file mode 100644
index 0000000000..50e87949fe
--- /dev/null
+++ b/frontend/src/components/Branch/BranchMergeView/index.ts
@@ -0,0 +1,3 @@
+import BranchMergeView from "./BranchMergeView.vue";
+
+export default BranchMergeView;
diff --git a/frontend/src/components/Branch/BranchMergeView/types.ts b/frontend/src/components/Branch/BranchMergeView/types.ts
new file mode 100644
index 0000000000..2adf1ccd9b
--- /dev/null
+++ b/frontend/src/components/Branch/BranchMergeView/types.ts
@@ -0,0 +1,7 @@
+import { Status } from "nice-grpc-common";
+import { Branch } from "@/types/proto/v1/branch_service";
+
+export type MergeBranchValidationState = {
+ status: Status;
+ branch?: Branch;
+};
diff --git a/frontend/src/components/Branch/BranchRebaseView/BranchRebaseView.vue b/frontend/src/components/Branch/BranchRebaseView/BranchRebaseView.vue
new file mode 100644
index 0000000000..67a7ef0fc3
--- /dev/null
+++ b/frontend/src/components/Branch/BranchRebaseView/BranchRebaseView.vue
@@ -0,0 +1,303 @@
+<template>
+ <div class="h-full relative">
+ <StepTab
+ :step-list="stepList"
+ :current-index="state.currentStepIndex"
+ :show-cancel="false"
+ :allow-next="allowNextStep"
+ class="h-full flex flex-col !space-y-0 gap-y-2"
+ pane-class="flex-1 flex flex-col gap-y-2 relative"
+ footer-class="!space-y-0 !border-0 !pt-0"
+ @update:current-index="tryChangeStep"
+ @finish="handleRebaseBranch"
+ >
+ <template #0>
+ <SelectBranchStep
+ :project="project"
+ :source-type="state.sourceType"
+ :head-branch="headBranch"
+ :source-branch="sourceBranch"
+ :source-database="sourceDatabase"
+ :is-loading-head-branch="isLoadingHeadBranch"
+ :is-loading-source-branch="isLoadingSourceBranch"
+ :is-validating="isValidating"
+ :validation-state="validationState"
+ @update:source-type="state.sourceType = $event"
+ @update:head-branch-name="handleUpdateHeadBranch"
+ @update:source-branch-name="state.sourceBranchName = $event || null"
+ @update:source-database-uid="state.sourceDatabaseUID = $event || null"
+ />
+ </template>
+ <template #1>
+ <RebaseBranchStep
+ v-if="headBranch && sourceBranchOrDatabase && validationState"
+ ref="rebaseBranchStepRef"
+ :project="project"
+ :validation-state="validationState"
+ />
+ </template>
+ </StepTab>
+ <MaskSpinner v-if="state.isRebasing" :zindexable="false" />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computedAsync } from "@vueuse/core";
+import { useDialog } from "naive-ui";
+import { ClientError, Status } from "nice-grpc-common";
+import { computed, onMounted, reactive, ref, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import { useRoute } from "vue-router";
+import MaskSpinner from "@/components/misc/MaskSpinner.vue";
+import { StepTab } from "@/components/v2";
+import { branchServiceClient } from "@/grpcweb";
+import { pushNotification, useBranchStore, useDatabaseV1Store } from "@/store";
+import { ComposedProject, UNKNOWN_ID } from "@/types";
+import { Branch } from "@/types/proto/v1/branch_service";
+import { defer } from "@/utils";
+import RebaseBranchStep from "./RebaseBranchStep.vue";
+import SelectBranchStep from "./SelectBranchStep.vue";
+import { RebaseBranchValidationState, RebaseSourceType } from "./types";
+
+interface LocalState {
+ currentStepIndex: number;
+ sourceBranchName: string | null;
+ sourceDatabaseUID: string | null;
+ sourceType: RebaseSourceType;
+ isRebasing: boolean;
+}
+
+const props = defineProps<{
+ project: ComposedProject;
+ headBranchName: string | null;
+}>();
+
+const emit = defineEmits<{
+ (event: "rebased", rebasedBranch: Branch): void;
+ (event: "update:head-branch-name", branchName: string | null): void;
+}>();
+
+const state = reactive<LocalState>({
+ currentStepIndex: 0,
+ sourceBranchName: null,
+ sourceDatabaseUID: null,
+ sourceType: "BRANCH",
+ isRebasing: false,
+});
+const { t } = useI18n();
+const route = useRoute();
+const $dialog = useDialog();
+const rebaseBranchStepRef = ref<InstanceType<typeof RebaseBranchStep>>();
+const branchStore = useBranchStore();
+const isLoadingHeadBranch = ref(false);
+const isLoadingSourceBranch = ref(false);
+const isValidating = ref(false);
+const combinedIsLoadingBranch = computed(() => {
+ return isLoadingHeadBranch.value || isLoadingSourceBranch.value;
+});
+
+const stepList = computed(() => [
+ { title: t("branch.select-branch") },
+ { title: t("common.preview") },
+]);
+const STEP_SELECT_BRANCH = 0;
+const STEP_REBASE_BRANCH = 1;
+
+const headBranch = computedAsync(
+ async () => {
+ const name = props.headBranchName;
+ if (!name) {
+ return undefined;
+ }
+ // Don't use local store cache since we need to ensure the branch is
+ // fresh clean here
+ return await branchStore.fetchBranchByName(name, /* !useCache */ false);
+ },
+ undefined,
+ {
+ evaluating: isLoadingHeadBranch,
+ }
+);
+
+const sourceBranch = computedAsync(
+ async () => {
+ if (state.sourceType === "DATABASE") {
+ return undefined;
+ }
+ const name = state.sourceBranchName;
+ if (!name) {
+ return undefined;
+ }
+ // Don't use local store cache since we need to ensure the branch is
+ // fresh clean here
+ return await branchStore.fetchBranchByName(name, /* !useCache */ false);
+ },
+ undefined,
+ {
+ evaluating: isLoadingSourceBranch,
+ }
+);
+const sourceDatabase = computed(() => {
+ if (state.sourceType === "BRANCH") {
+ return undefined;
+ }
+ const uid = state.sourceDatabaseUID;
+ if (!uid || uid === String(UNKNOWN_ID)) {
+ return undefined;
+ }
+ return useDatabaseV1Store().getDatabaseByUID(uid);
+});
+const sourceBranchOrDatabase = computed(() => {
+ if (state.sourceType === "BRANCH") {
+ return sourceBranch.value;
+ }
+ return sourceDatabase.value;
+});
+
+const validationState = computedAsync(
+ async (): Promise<RebaseBranchValidationState | undefined> => {
+ const head = headBranch.value;
+ const source = sourceBranchOrDatabase.value;
+ if (!head) return;
+ if (!source) return;
+ const response = await branchServiceClient.rebaseBranch({
+ name: head.name,
+ sourceBranch: state.sourceType === "BRANCH" ? source.name : undefined,
+ sourceDatabase: state.sourceType === "DATABASE" ? source.name : undefined,
+ });
+ return response;
+ },
+ undefined,
+ {
+ evaluating: isValidating,
+ }
+);
+const handleUpdateHeadBranch = (branchName: string | undefined) => {
+ emit("update:head-branch-name", branchName || null);
+};
+
+const tryChangeStep = (nextStepIndex: number) => {
+ if (combinedIsLoadingBranch.value) {
+ return;
+ }
+ state.currentStepIndex = nextStepIndex;
+};
+
+const allowNextStep = computed(() => {
+ if (state.currentStepIndex === STEP_SELECT_BRANCH) {
+ return (
+ headBranch.value !== undefined &&
+ sourceBranchOrDatabase.value !== undefined &&
+ validationState.value !== undefined
+ );
+ }
+ if (state.currentStepIndex === STEP_REBASE_BRANCH) {
+ return true;
+ }
+
+ console.error(
+ "[BranchRebaseView.allowNextStep] should never reach this line"
+ );
+ return false;
+});
+
+const confirmRebaseWithMaybeConflict = () => {
+ const d = defer<boolean>();
+ $dialog.warning({
+ title: t("branch.merge-rebase.confirm-rebase"),
+ content: t("branch.merge-rebase.conflict-not-resolved"),
+ style: "z-index: 100000",
+ negativeText: t("common.cancel"),
+ positiveText: t("common.confirm"),
+ onNegativeClick: () => {
+ d.resolve(false);
+ },
+ onPositiveClick: () => {
+ d.resolve(true);
+ },
+ });
+ return d.promise;
+};
+
+const handleRebaseBranch = async () => {
+ const source = sourceBranchOrDatabase.value;
+ if (!source) return;
+ const head = headBranch.value;
+ if (!head) return;
+ const rebaseBranchStep = rebaseBranchStepRef.value;
+ if (!rebaseBranchStep) return;
+ state.isRebasing = true;
+
+ try {
+ const validation = rebaseBranchStep.validateConflictSchema();
+ if (!validation.valid) {
+ const confirmed = await confirmRebaseWithMaybeConflict();
+ if (!confirmed) return;
+ }
+ const response = await branchStore.rebaseBranch({
+ name: head.name,
+ sourceBranch: state.sourceType === "BRANCH" ? source.name : "",
+ sourceDatabase: state.sourceType === "DATABASE" ? source.name : "",
+ mergedSchema: validation.schema ?? "",
+ etag: "",
+ validateOnly: false,
+ });
+ if (!response.branch) {
+ throw new ClientError(
+ "BranchService.RebaseBranch",
+ Status.ABORTED,
+ "rebase failed"
+ );
+ }
+
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("branch.merge-rebase.rebase-succeeded"),
+ });
+
+ emit("rebased", response.branch);
+ } catch (error: any) {
+ pushNotification({
+ module: "bytebase",
+ style: "CRITICAL",
+ title: `Request error occurred`,
+ description: error.details,
+ });
+ } finally {
+ state.isRebasing = false;
+ }
+};
+
+watch(
+ headBranch,
+ (head) => {
+ if (head) {
+ // Automatically set the sourceDatabase to the branch's baselineDatabase
+ // if sourceDatabase is empty
+ if (!state.sourceDatabaseUID) {
+ const db = useDatabaseV1Store().getDatabaseByName(
+ head.baselineDatabase
+ );
+ state.sourceDatabaseUID = db.uid;
+ }
+
+ // Automatically select the branch's parent as rebase source branch
+ // if rebase source is empty
+ if (head.parentBranch && !state.sourceBranchName) {
+ state.sourceBranchName = head.parentBranch;
+ }
+ }
+ },
+ {
+ immediate: true,
+ }
+);
+
+onMounted(() => {
+ if (route.query.source) {
+ const source = `${props.project.name}/branches/${route.query.source}`;
+ state.sourceBranchName = source;
+ }
+});
+</script>
diff --git a/frontend/src/components/Branch/BranchRebaseView/RebaseBranchStep.vue b/frontend/src/components/Branch/BranchRebaseView/RebaseBranchStep.vue
new file mode 100644
index 0000000000..894190b09f
--- /dev/null
+++ b/frontend/src/components/Branch/BranchRebaseView/RebaseBranchStep.vue
@@ -0,0 +1,184 @@
+<template>
+ <div class="flex-1 flex flex-col gap-y-1 text-sm">
+ <template v-if="validationState.branch">
+ <div class="flex flex-row items-center gap-x-1">
+ <CheckIcon class="w-4 h-4 text-success" />
+ <span>{{ $t("branch.merge-rebase.able-to-merge") }}</span>
+ </div>
+ <!-- BranchService.RebaseBranch now returns empty schema and metadata -->
+ <!-- so we have nothing to show by now -->
+ <NTabs v-model:value="tab">
+ <NTab name="schema-editor">
+ {{ $t("schema-editor.self") }}
+ </NTab>
+ <NTab name="raw-schema-text">
+ {{ $t("schema-editor.raw-sql") }}
+ </NTab>
+ </NTabs>
+ <div
+ v-show="tab === 'schema-editor'"
+ class="w-full flex-1 relative text-sm"
+ >
+ <SchemaEditorLite
+ ref="schemaEditorRef"
+ resource-type="branch"
+ :project="project"
+ :readonly="true"
+ :branch="validationState.branch"
+ />
+ </div>
+ <div
+ v-show="tab === 'raw-schema-text'"
+ class="w-full flex-1 relative text-sm border rounded overflow-clip"
+ >
+ <DiffEditor
+ :readonly="true"
+ :original="validationState.branch.baselineSchema"
+ :modified="validationState.branch.schema"
+ class="h-full"
+ />
+ </div>
+ </template>
+ <template v-else>
+ <div class="text-error">解决冲突以进行 rebase</div>
+ <div
+ class="w-full flex-1 relative text-sm border rounded overflow-clip bb-resolve-conflict-editor"
+ >
+ <MonacoEditor
+ v-model:content="state.editingSchema"
+ :line-highlights="lineHighlightOptions"
+ class="h-full"
+ />
+ </div>
+ </template>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { CheckIcon } from "lucide-vue-next";
+import { computed, reactive, ref, watch } from "vue";
+import {
+ LineHighlightOption,
+ LineHighlightOverviewRulerPosition,
+ MonacoEditor,
+} from "@/components/MonacoEditor";
+import SchemaEditorLite from "@/components/SchemaEditorLite";
+import { useDatabaseV1Store } from "@/store";
+import { ComposedProject } from "@/types";
+import { DatabaseMetadata } from "@/types/proto/v1/database_service";
+import { RebaseBranchValidationState } from "./types";
+
+type TabValue = "schema-editor" | "raw-schema-text";
+type LocalState = {
+ editingSchema: string;
+};
+const ConflictMarkers = [
+ {
+ pattern: "<<<<<<",
+ type: "current",
+ color: "rgb(16 185 129)", // bg-emerald-500
+ position: "LEFT" as LineHighlightOverviewRulerPosition,
+ },
+ {
+ pattern: "======",
+ type: "gutter",
+ color: "rgb(107 114 128)", // bg-gray-500
+ position: "FULL" as LineHighlightOverviewRulerPosition,
+ },
+ {
+ pattern: ">>>>>>",
+ type: "incoming",
+ color: "rgb(59 130 246)", // bg-blue-500
+ position: "RIGHT" as LineHighlightOverviewRulerPosition,
+ },
+];
+
+const props = defineProps<{
+ project: ComposedProject;
+ validationState: RebaseBranchValidationState;
+}>();
+
+const schemaEditorRef = ref<InstanceType<typeof SchemaEditorLite>>();
+const tab = ref<TabValue>("raw-schema-text");
+const state = reactive<LocalState>({
+ editingSchema: "",
+});
+
+const lineHighlightOptions = computed(() => {
+ const options: LineHighlightOption[] = [];
+ state.editingSchema.split("\n").forEach((line, index) => {
+ const marker = ConflictMarkers.find((m) => line.startsWith(m.pattern));
+ if (marker) {
+ options.push({
+ lineNumber: index + 1,
+ className: `bb-conflict-line--${marker.type}`,
+ overviewRuler: {
+ color: marker.color,
+ position: marker.position,
+ },
+ });
+ }
+ });
+ return options;
+});
+
+const validateConflictSchema = () => {
+ if (props.validationState.branch) {
+ // Auto rebase
+ return {
+ valid: true,
+ schema: undefined,
+ };
+ }
+ if (lineHighlightOptions.value.length === 0) {
+ // Conflict resolved
+ return {
+ valid: true,
+ schema: state.editingSchema,
+ };
+ }
+ return {
+ valid: false,
+ schema: state.editingSchema,
+ };
+};
+
+watch(
+ [() => props.validationState.branch, schemaEditorRef],
+ ([branch, editor]) => {
+ if (branch && editor) {
+ const db = useDatabaseV1Store().getDatabaseByName(
+ branch.baselineDatabase
+ );
+ editor.rebuildMetadataEdit(
+ db,
+ branch.baselineSchemaMetadata ?? DatabaseMetadata.fromPartial({}),
+ branch.schemaMetadata ?? DatabaseMetadata.fromPartial({})
+ );
+ }
+ }
+);
+watch(
+ () => props.validationState.conflictSchema,
+ (conflictSchema) => {
+ state.editingSchema = conflictSchema ?? "";
+ },
+ {
+ immediate: true,
+ }
+);
+
+defineExpose({ validateConflictSchema });
+</script>
+
+<style lang="postcss" scoped>
+.bb-resolve-conflict-editor :deep(.bb-conflict-line--current) {
+ @apply bg-emerald-300;
+}
+.bb-resolve-conflict-editor :deep(.bb-conflict-line--gutter) {
+ @apply bg-gray-300;
+}
+.bb-resolve-conflict-editor :deep(.bb-conflict-line--incoming) {
+ @apply bg-blue-300;
+}
+</style>
diff --git a/frontend/src/components/Branch/BranchRebaseView/SelectBranchStep.vue b/frontend/src/components/Branch/BranchRebaseView/SelectBranchStep.vue
new file mode 100644
index 0000000000..e87779e00c
--- /dev/null
+++ b/frontend/src/components/Branch/BranchRebaseView/SelectBranchStep.vue
@@ -0,0 +1,200 @@
+<template>
+ <div
+ class="w-full grid grid-cols-3 items-end text-sm gap-x-2"
+ style="grid-template-columns: 1fr auto 1fr"
+ >
+ <BranchSelector
+ class="!full text-center"
+ :clearable="false"
+ :project="project"
+ :branch="headBranch?.name"
+ :filter="headBranchFilter"
+ @update:branch="$emit('update:head-branch-name', $event)"
+ />
+ <div class="flex flex-row justify-center px-2 h-[34px]">
+ <MoveLeftIcon :size="40" stroke-width="1" />
+ </div>
+ <div class="flex flex-col">
+ <NRadioGroup
+ :value="sourceType"
+ class="space-x-2"
+ @update:value="$emit('update:source-type', $event as RebaseSourceType)"
+ >
+ <NRadio value="BRANCH">{{ $t("common.branch") }}</NRadio>
+ <NRadio value="DATABASE">{{ $t("common.database") }}</NRadio>
+ </NRadioGroup>
+ <BranchSelector
+ v-if="sourceType === 'BRANCH'"
+ class="!w-full text-center"
+ :clearable="false"
+ :project="project"
+ :branch="sourceBranch?.name"
+ :filter="sourceBranchFilter"
+ @update:branch="$emit('update:source-branch-name', $event)"
+ />
+ <DatabaseSelect
+ v-if="sourceType === 'DATABASE'"
+ :database="sourceDatabase?.uid"
+ :project="project.uid"
+ :allowed-engine-type-list="headBranch ? [headBranch.engine] : undefined"
+ style="width: 100%"
+ @update:database="$emit('update:source-database-uid', $event)"
+ />
+ </div>
+ </div>
+ <div class="w-full flex-1 flex flex-col relative text-sm gap-y-1">
+ <div class="flex flex-row items-center gap-x-1">
+ <span v-if="!headBranch || !sourceBranchOrDatabase">
+ {{ $t("branch.merge-rebase.select-branches-to-rebase") }}
+ </span>
+ <template v-else>
+ <template v-if="isValidating">
+ <BBSpin class="!w-4 !h-4" />
+ <span>{{ $t("branch.merge-rebase.validating-branch") }}</span>
+ </template>
+ <template v-else-if="validationState">
+ <template v-if="validationState.branch">
+ <CheckIcon class="w-4 h-4 text-success" />
+ <span>{{ $t("branch.merge-rebase.able-to-rebase") }}</span>
+ </template>
+ <template v-else>
+ <XCircleIcon class="w-4 h-4 text-error" />
+ <span>
+ {{ $t("branch.merge-rebase.cannot-automatically-rebase") }}
+ </span>
+ </template>
+ </template>
+ </template>
+ </div>
+ <NTabs v-model:value="tab">
+ <template v-if="headBranch" #prefix>
+ <div class="text-control-placeholder">
+ {{
+ $t("branch.merge-rebase.changes-of-branch", {
+ branch: headBranch.branchId,
+ })
+ }}
+ </div>
+ </template>
+ <NTab name="schema-editor">
+ {{ $t("schema-editor.self") }}
+ </NTab>
+ <NTab name="raw-schema-text">
+ {{ $t("schema-editor.raw-sql") }}
+ </NTab>
+ </NTabs>
+ <div
+ v-show="tab === 'schema-editor'"
+ class="w-full flex-1 relative text-sm"
+ >
+ <SchemaEditorLite
+ ref="schemaEditorRef"
+ :key="headBranch?.name"
+ resource-type="branch"
+ :project="project"
+ :readonly="true"
+ :loading="isLoadingHeadBranch"
+ :branch="headBranch ?? Branch.fromPartial({})"
+ />
+ <MaskSpinner v-if="isLoadingHeadBranch" />
+ </div>
+ <div
+ v-show="tab === 'raw-schema-text'"
+ class="w-full flex-1 relative text-sm border rounded overflow-clip"
+ >
+ <DiffEditor
+ :readonly="true"
+ :original="headBranch?.baselineSchema"
+ :modified="headBranch?.schema"
+ class="h-full"
+ />
+
+ <MaskSpinner v-if="isLoadingHeadBranch || isLoadingSourceBranch" />
+ </div>
+ </div>
+</template>
+
+<script setup lang="ts">
+import { CheckIcon, XCircleIcon, MoveLeftIcon } from "lucide-vue-next";
+import { NRadioGroup, NTab, NTabs } from "naive-ui";
+import { computed, ref, watch } from "vue";
+import { DiffEditor } from "@/components/MonacoEditor";
+import SchemaEditorLite from "@/components/SchemaEditorLite";
+import MaskSpinner from "@/components/misc/MaskSpinner.vue";
+import { DatabaseSelect } from "@/components/v2";
+import { useDatabaseV1Store } from "@/store";
+import { ComposedDatabase, ComposedProject } from "@/types";
+import { Branch } from "@/types/proto/v1/branch_service";
+import { DatabaseMetadata } from "@/types/proto/v1/database_service";
+import { RebaseBranchValidationState, RebaseSourceType } from "./types";
+
+type TabValue = "schema-editor" | "raw-schema-text";
+
+const props = defineProps<{
+ project: ComposedProject;
+ sourceType: RebaseSourceType;
+ headBranch: Branch | undefined;
+ sourceBranch: Branch | undefined;
+ sourceDatabase: ComposedDatabase | undefined;
+ isLoadingSourceBranch?: boolean;
+ isLoadingHeadBranch?: boolean;
+ isValidating?: boolean;
+ validationState: RebaseBranchValidationState | undefined;
+}>();
+
+defineEmits<{
+ (event: "update:source-type", type: RebaseSourceType): void;
+ (event: "update:head-branch-name", branch: string | undefined): void;
+ (event: "update:source-branch-name", branch: string | undefined): void;
+ (event: "update:source-database-uid", uid: string | undefined): void;
+}>();
+
+const schemaEditorRef = ref<InstanceType<typeof SchemaEditorLite>>();
+const tab = ref<TabValue>("schema-editor");
+const sourceBranchOrDatabase = computed(() => {
+ return props.sourceType === "BRANCH"
+ ? props.sourceBranch
+ : props.sourceDatabase;
+});
+
+const sourceBranchFilter = (branch: Branch) => {
+ const { headBranch } = props;
+ if (!headBranch) {
+ return true;
+ }
+ return branch.engine === headBranch.engine && branch.name !== headBranch.name;
+};
+const headBranchFilter = (branch: Branch) => {
+ const source = sourceBranchOrDatabase.value;
+ if (!source) {
+ return true;
+ }
+ if (props.sourceType === "BRANCH") {
+ const sourceBranch = source as Branch;
+ return (
+ branch.engine === sourceBranch.engine && branch.name !== sourceBranch.name
+ );
+ } else {
+ const sourceDatabase = source as ComposedDatabase;
+ return branch.engine === sourceDatabase.instanceEntity.engine;
+ }
+};
+
+// re-calculate diff for coloring when branch changed
+watch(
+ [() => props.headBranch, schemaEditorRef],
+ ([head, editor]) => {
+ if (head && editor) {
+ const db = useDatabaseV1Store().getDatabaseByName(head.baselineDatabase);
+ editor.rebuildMetadataEdit(
+ db,
+ head.baselineSchemaMetadata ?? DatabaseMetadata.fromPartial({}),
+ head.schemaMetadata ?? DatabaseMetadata.fromPartial({})
+ );
+ }
+ },
+ {
+ immediate: true,
+ }
+);
+</script>
diff --git a/frontend/src/components/Branch/BranchRebaseView/index.ts b/frontend/src/components/Branch/BranchRebaseView/index.ts
new file mode 100644
index 0000000000..6e5af6abe8
--- /dev/null
+++ b/frontend/src/components/Branch/BranchRebaseView/index.ts
@@ -0,0 +1,3 @@
+import BranchRebaseView from "./BranchRebaseView.vue";
+
+export default BranchRebaseView;
diff --git a/frontend/src/components/Branch/BranchRebaseView/types.ts b/frontend/src/components/Branch/BranchRebaseView/types.ts
new file mode 100644
index 0000000000..800760ceee
--- /dev/null
+++ b/frontend/src/components/Branch/BranchRebaseView/types.ts
@@ -0,0 +1,8 @@
+import { Branch } from "@/types/proto/v1/branch_service";
+
+export type RebaseSourceType = "BRANCH" | "DATABASE";
+
+export type RebaseBranchValidationState = {
+ branch?: Branch;
+ conflictSchema?: string;
+};
diff --git a/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue b/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
index 22d667be1a..2a64ce413d 100644
--- a/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
+++ b/frontend/src/components/Branch/BranchRolloutView/BranchRolloutView.vue
@@ -63,12 +63,11 @@
</div>
<div
- v-if="state.selectedTab === 'schema-editor'"
+ v-show="state.selectedTab === 'schema-editor'"
class="flex-1 overflow-hidden relative"
>
<SchemaEditorLite
- v-if="database"
- :key="virtualBranch.name"
+ v-show="database"
ref="schemaEditorRef"
v-model:selected-rollout-objects="selectedRolloutObjects"
:project="project"
@@ -76,27 +75,26 @@
:resource-type="'branch'"
:branch="virtualBranch"
:loading="isLoadingVirtualBranch"
- :diff-when-ready="true"
/>
<!-- used as a placeholder -->
- <template v-else>
- <SchemaEditorLite
- :project="project"
- :readonly="true"
- :resource-type="'branch'"
- :branch="emptyBranch"
- />
- <div
- class="absolute inset-0 bg-white/75 text-sm flex flex-col items-center justify-center"
- >
- {{ $t("branch.rollout.select-target-database") }}
- </div>
- </template>
+ <SchemaEditorLite
+ v-show="!database"
+ :project="project"
+ :readonly="true"
+ :resource-type="'branch'"
+ :branch="emptyBranch"
+ />
+ <div
+ v-show="!database"
+ class="absolute inset-0 bg-white/75 text-sm flex flex-col items-center justify-center"
+ >
+ {{ $t("branch.rollout.select-target-database") }}
+ </div>
</div>
<div
- v-if="state.selectedTab === 'raw-sql-preview'"
+ v-show="state.selectedTab === 'raw-sql-preview'"
class="w-full h-full overflow-y-auto relative"
>
<MaskSpinner v-if="rawSQLPreviewState.isFetching">
@@ -141,6 +139,7 @@ import {
} from "@/store";
import { ComposedDatabase, ComposedProject, UNKNOWN_ID } from "@/types";
import { Branch } from "@/types/proto/v1/branch_service";
+import { DatabaseMetadata } from "@/types/proto/v1/database_service";
import { Environment } from "@/types/proto/v1/environment_service";
import {
Sheet,
@@ -220,18 +219,15 @@ const allowPreviewIssue = computed(() => {
});
const handleChangeTab = async (tab: TabType) => {
+ if (state.selectedTab === tab) return;
state.selectedTab = tab;
+
if (tab === "raw-sql-preview") {
await fetchRawSQLPreview();
}
};
const fetchRawSQLPreview = async () => {
- if (rawSQLPreviewState.isFetching) {
- return;
- }
- rawSQLPreviewState.isFetching = true;
-
const cleanup = (errors: string[], fatal: boolean) => {
if (errors.length > 0) {
pushNotification({
@@ -243,8 +239,18 @@ const fetchRawSQLPreview = async () => {
}
rawSQLPreviewState.isFetching = false;
};
- const source = cloneDeep(virtualBranch.value.baselineSchemaMetadata);
- const target = cloneDeep(virtualBranch.value.schemaMetadata);
+
+ if (rawSQLPreviewState.isFetching) {
+ return;
+ }
+ const vb = virtualBranch.value;
+ if (!vb) {
+ return;
+ }
+ rawSQLPreviewState.isFetching = true;
+
+ const source = cloneDeep(vb.baselineSchemaMetadata);
+ const target = cloneDeep(vb.schemaMetadata);
const db = database.value;
const editor = schemaEditorRef.value;
if (!source) return;
@@ -285,8 +291,12 @@ const handlePreviewIssue = async () => {
isGeneratingDDL.value = false;
};
- const source = cloneDeep(virtualBranch.value.baselineSchemaMetadata);
- const target = cloneDeep(virtualBranch.value.schemaMetadata);
+ const vb = virtualBranch.value;
+ if (!vb) {
+ return;
+ }
+ const source = cloneDeep(vb.baselineSchemaMetadata);
+ const target = cloneDeep(vb.schemaMetadata);
const db = database.value;
const editor = schemaEditorRef.value;
if (!source) return;
@@ -370,4 +380,23 @@ watch(
},
{ immediate: true }
);
+watch(
+ () => virtualBranch.value,
+ (vb) => {
+ if (!vb) return;
+ if ((vb as any).__rebuildMetadataEditFinished) {
+ console.warn("unexpected: should never reach this line");
+ return;
+ }
+ (vb as any).__rebuildMetadataEditFinished = true;
+
+ selectedRolloutObjects.value = [];
+ const db = useDatabaseV1Store().getDatabaseByName(vb.baselineDatabase);
+ schemaEditorRef.value?.rebuildMetadataEdit(
+ db,
+ vb.baselineSchemaMetadata ?? DatabaseMetadata.fromPartial({}),
+ vb.schemaMetadata ?? DatabaseMetadata.fromPartial({})
+ );
+ }
+);
</script>
diff --git a/frontend/src/components/Branch/BranchRolloutView/useVirtualBranch.ts b/frontend/src/components/Branch/BranchRolloutView/useVirtualBranch.ts
index 357c8930a9..9d0fd0d2fd 100644
--- a/frontend/src/components/Branch/BranchRolloutView/useVirtualBranch.ts
+++ b/frontend/src/components/Branch/BranchRolloutView/useVirtualBranch.ts
@@ -1,12 +1,7 @@
-import { uniqueId } from "lodash-es";
+import { cloneDeep, uniqueId } from "lodash-es";
import { computed, reactive, ref, unref, watchEffect } from "vue";
import { useDBSchemaV1Store } from "@/store";
-import {
- ComposedDatabase,
- ComposedProject,
- MaybeRef,
- unknownDatabase,
-} from "@/types";
+import { ComposedDatabase, ComposedProject, MaybeRef } from "@/types";
import { Branch } from "@/types/proto/v1/branch_service";
import {
DatabaseMetadata,
@@ -56,13 +51,19 @@ export const useVirtualBranch = (
});
const virtualBranch = computed(() => {
- const db = unref(database) ?? unknownDatabase();
+ const db = unref(database);
+ if (!db) {
+ return undefined;
+ }
+ if (state.isLoadingDatabaseMetadata) {
+ return undefined;
+ }
return Branch.fromPartial({
name: `${unref(project).name}/branches/-${uniqueId()}`,
engine: db.instanceEntity.engine,
baselineDatabase: db.name,
- schemaMetadata: unref(branch).schemaMetadata,
- baselineSchemaMetadata: databaseHeadMetadata.value,
+ schemaMetadata: cloneDeep(unref(branch).schemaMetadata),
+ baselineSchemaMetadata: cloneDeep(databaseHeadMetadata.value),
});
});
diff --git a/frontend/src/components/Branch/BranchSelector.vue b/frontend/src/components/Branch/BranchSelector.vue
index ff39a5a4a7..6ada7e5480 100644
--- a/frontend/src/components/Branch/BranchSelector.vue
+++ b/frontend/src/components/Branch/BranchSelector.vue
@@ -1,7 +1,7 @@
<template>
<NSelect
v-bind="$attrs"
- :value="branch"
+ :value="branch || null"
:options="options"
:placeholder="$t('database.select-branch')"
:filterable="true"
@@ -30,7 +30,7 @@ interface BranchSelectOption extends SelectOption {
const props = defineProps<{
project: ComposedProject;
- branch?: string;
+ branch?: string | null;
clearable?: boolean;
loading?: boolean;
disabled?: boolean;
diff --git a/frontend/src/components/Branch/MergeBranchPanel.vue b/frontend/src/components/Branch/MergeBranchPanel.vue
deleted file mode 100644
index b7786f1c7f..0000000000
--- a/frontend/src/components/Branch/MergeBranchPanel.vue
+++ /dev/null
@@ -1,228 +0,0 @@
-<template>
- <Drawer
- :show="true"
- width="auto"
- @update:show="(show: boolean) => !show && emit('dismiss')"
- >
- <DrawerContent :title="$t('schema-designer.merge-branch')" :closable="true">
- <div
- class="space-y-3 w-[calc(100vw-24rem)] min-w-[64rem] max-w-[calc(100vw-8rem)] h-full overflow-x-auto"
- >
- <div class="w-full flex flex-row justify-end items-center gap-2">
- <NButton type="primary" @click="handleMergeBranch">
- {{ $t("common.merge") }}
- </NButton>
- </div>
- <div class="w-full flex flex-row justify-end items-center gap-2">
- <NCheckbox v-model:checked="state.deleteBranchAfterMerged">
- {{ $t("schema-designer.delete-branch-after-merged") }}
- </NCheckbox>
- </div>
- <div class="w-full pr-12 pt-4 pb-6 grid grid-cols-3">
- <div class="flex flex-row justify-end">
- <BranchSelector
- class="!w-4/5 text-center"
- :clearable="false"
- :project="project"
- :branch="state.branchName"
- :filter="targetBranchFilter"
- @update:branch="(branch) => (state.branchName = branch ?? '')"
- />
- </div>
- <div class="flex flex-row justify-center">
- <MoveLeft :size="40" stroke-width="1" />
- </div>
- <div class="flex flex-row justify-start">
- <NInput
- class="!w-4/5 text-center"
- readonly
- :value="sourceBranch.branchId"
- size="large"
- />
- </div>
- </div>
- <div class="w-full grid grid-cols-2">
- <div class="col-span-1">
- <span>base</span>
- </div>
- <div class="col-span-1">
- <span>compare</span>
- </div>
- </div>
- <div class="w-full h-[calc(100%-14rem)] border relative">
- <DiffEditor
- v-if="ready"
- :key="state.branchName"
- class="h-full"
- :original="targetBranch.schema"
- :modified="state.editingSchema"
- @update:modified="state.editingSchema = $event"
- />
- <div
- v-else
- class="inset-0 absolute flex flex-col justify-center items-center"
- >
- <BBSpin />
- </div>
- </div>
- </div>
- </DrawerContent>
- </Drawer>
-</template>
-
-<script lang="ts" setup>
-import { asyncComputed } from "@vueuse/core";
-import { MoveLeft } from "lucide-vue-next";
-import { NButton, NInput, NCheckbox, useDialog } from "naive-ui";
-import { Status } from "nice-grpc-common";
-import { computed, reactive, ref, watch } from "vue";
-import { useI18n } from "vue-i18n";
-import { Drawer, DrawerContent } from "@/components/v2";
-import { pushNotification } from "@/store";
-import { useBranchStore } from "@/store/modules/branch";
-import { ComposedProject } from "@/types";
-import { Branch } from "@/types/proto/v1/branch_service";
-import { DiffEditor } from "../MonacoEditor";
-
-interface LocalState {
- branchName: string;
- editingSchema: string;
- deleteBranchAfterMerged: boolean;
-}
-
-const props = defineProps<{
- project: ComposedProject;
- headBranchName: string;
- branchName: string;
-}>();
-
-const emit = defineEmits<{
- (event: "dismiss"): void;
- (event: "merged", branchName: string): void;
-}>();
-
-const state = reactive<LocalState>({
- branchName: "",
- editingSchema: "",
- deleteBranchAfterMerged: false,
-});
-const { t } = useI18n();
-const dialog = useDialog();
-const branchStore = useBranchStore();
-const isLoadingSourceBranch = ref(false);
-const isLoadingTargetBranch = ref(false);
-const emptyBranch = () => Branch.fromPartial({});
-
-const sourceBranch = asyncComputed(
- async () => {
- const name = props.headBranchName;
- if (!name) {
- return emptyBranch();
- }
- // Don't use local store cache since we need to ensure the branch is
- // fresh clean here
- return await branchStore.fetchBranchByName(name, /* !useCache */ false);
- },
- emptyBranch(),
- {
- evaluating: isLoadingSourceBranch,
- }
-);
-
-const targetBranch = asyncComputed(
- async () => {
- const name = state.branchName;
- if (!name) {
- return emptyBranch();
- }
- // Don't use local store cache since we need to ensure the branch is
- // fresh clean here
- return await branchStore.fetchBranchByName(name, /* !useCache */ false);
- },
- emptyBranch(),
- {
- evaluating: isLoadingTargetBranch,
- }
-);
-
-// ready when both source and target branch are loaded
-const ready = computed(() => {
- return !isLoadingSourceBranch.value && !isLoadingTargetBranch.value;
-});
-
-const targetBranchFilter = (branch: Branch) => {
- return (
- branch.name !== props.headBranchName &&
- branch.engine === sourceBranch.value.engine
- );
-};
-
-const handleMergeBranch = async () => {
- try {
- await branchStore.mergeBranch({
- name: targetBranch.value.name,
- headBranch: sourceBranch.value.name,
- mergedSchema: "",
- etag: "",
- validateOnly: false,
- });
- } catch (error: any) {
- // TODO(Jim): this needs to be updated.
- // If there is conflict, we need to show the conflict and let user resolve it.
- if (error.code === Status.ABORTED) {
- dialog.create({
- positiveText: t("schema-designer.diff-editor.resolve"),
- title: t("schema-designer.diff-editor.auto-merge-failed"),
- content: t("schema-designer.diff-editor.need-to-resolve-conflicts"),
- autoFocus: true,
- closable: true,
- maskClosable: true,
- closeOnEsc: true,
- onPositiveClick: async () => {
- // TODO(d): open resolve window.
- // Fetching the latest base branch.
- await branchStore.fetchBranchByName(
- state.branchName,
- false /* !useCache */
- );
- },
- });
- } else {
- pushNotification({
- module: "bytebase",
- style: "CRITICAL",
- title: `Request error occurred`,
- description: error.details,
- });
- }
- return;
- }
-
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("schema-designer.message.merge-to-main-successfully"),
- });
-
- emit("merged", state.branchName);
- if (state.deleteBranchAfterMerged) {
- await branchStore.deleteBranch(props.headBranchName);
- }
-};
-
-watch(
- [sourceBranch, targetBranch],
- () => {
- state.editingSchema = sourceBranch.value.schema;
- },
- { immediate: true }
-);
-
-watch(
- () => props.branchName,
- () => {
- state.branchName = props.branchName;
- },
- { immediate: true }
-);
-</script>
diff --git a/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue b/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
index cb6134fa7e..5becd12d54 100644
--- a/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
+++ b/frontend/src/components/MonacoEditor/MonacoTextModelEditor.vue
@@ -35,6 +35,7 @@ import {
useOptions,
useSelectedContent,
useSuggestOptionByLanguage,
+ useLineHighlights,
} from "./composables";
import { shouldUseNewLSP } from "./dev";
import monaco, { createMonacoEditor } from "./editor";
@@ -43,6 +44,7 @@ import type {
IStandaloneCodeEditor,
IStandaloneEditorConstructionOptions,
ITextModel,
+ LineHighlightOption,
MonacoModule,
} from "./types";
@@ -55,6 +57,7 @@ const props = withDefaults(
autoHeight?: AutoHeightOptions;
autoCompleteContext?: AutoCompleteContext;
advices?: AdviceOption[];
+ lineHighlights?: LineHighlightOption[];
options?: IStandaloneEditorConstructionOptions;
}>(),
{
@@ -65,6 +68,7 @@ const props = withDefaults(
autoHeight: undefined,
autoCompleteContext: undefined,
advices: () => [],
+ lineHighlights: () => [],
options: undefined,
}
);
@@ -110,6 +114,7 @@ onMounted(async () => {
const content = useContent(monaco, editor);
const selectedContent = useSelectedContent(monaco, editor);
useAdvices(monaco, editor, toRef(props, "advices"));
+ useLineHighlights(monaco, editor, toRef(props, "lineHighlights"));
useAutoHeight(monaco, editor, containerRef, toRef(props, "autoHeight"));
if (shouldUseNewLSP()) {
useAutoComplete(monaco, editor, toRef(props, "autoCompleteContext"));
diff --git a/frontend/src/components/MonacoEditor/composables/index.ts b/frontend/src/components/MonacoEditor/composables/index.ts
index 4ffbf9d57d..f8df53d64b 100644
--- a/frontend/src/components/MonacoEditor/composables/index.ts
+++ b/frontend/src/components/MonacoEditor/composables/index.ts
@@ -5,5 +5,6 @@ export * from "./useSelectedContent";
export * from "./useFormatContent";
export * from "./useSuggestOptionByLanguage";
export * from "./useAdvices";
+export * from "./useLineHighlights";
export * from "./useAutoHeight";
export * from "./useAutoComplete";
diff --git a/frontend/src/components/MonacoEditor/composables/useLineHighlights.ts b/frontend/src/components/MonacoEditor/composables/useLineHighlights.ts
new file mode 100644
index 0000000000..5979886b42
--- /dev/null
+++ b/frontend/src/components/MonacoEditor/composables/useLineHighlights.ts
@@ -0,0 +1,44 @@
+import type monaco from "monaco-editor";
+import { unref, watchEffect } from "vue";
+import type { MaybeRef } from "@/types";
+import type { LineHighlightOption, MonacoModule } from "../types";
+
+export const useLineHighlights = (
+ monaco: MonacoModule,
+ editor: monaco.editor.IStandaloneCodeEditor,
+ options: MaybeRef<LineHighlightOption[]>
+) => {
+ const OverviewRulerPositionMap = {
+ LEFT: monaco.editor.OverviewRulerLane.Left,
+ RIGHT: monaco.editor.OverviewRulerLane.Right,
+ CENTER: monaco.editor.OverviewRulerLane.Center,
+ FULL: monaco.editor.OverviewRulerLane.Full,
+ };
+
+ watchEffect((onCleanup) => {
+ const opts = unref(options);
+ const decorators = editor.createDecorationsCollection(
+ opts.map((opt) => {
+ return {
+ range: new monaco.Range(opt.lineNumber, 1, opt.lineNumber, Infinity),
+ options: {
+ isWholeLine: true,
+ inlineClassName: opt.className,
+ overviewRuler: opt.overviewRuler
+ ? {
+ color: opt.overviewRuler.color,
+ position:
+ OverviewRulerPositionMap[opt.overviewRuler.position],
+ }
+ : undefined,
+ stickiness:
+ monaco.editor.TrackedRangeStickiness.NeverGrowsWhenTypingAtEdges,
+ },
+ };
+ })
+ );
+ onCleanup(() => {
+ decorators.clear();
+ });
+ });
+};
diff --git a/frontend/src/components/MonacoEditor/types.ts b/frontend/src/components/MonacoEditor/types.ts
index 1834adbb49..a8de92c229 100644
--- a/frontend/src/components/MonacoEditor/types.ts
+++ b/frontend/src/components/MonacoEditor/types.ts
@@ -21,6 +21,21 @@ export type AdviceOption = {
endColumn: number; // starts from 1
};
+export type LineHighlightOverviewRulerPosition =
+ | "FULL"
+ | "CENTER"
+ | "LEFT"
+ | "RIGHT";
+export type LineHighlightOverviewRulerOption = {
+ color: string;
+ position: LineHighlightOverviewRulerPosition;
+};
+export type LineHighlightOption = {
+ className: string;
+ lineNumber: number; // starts from 1
+ overviewRuler?: LineHighlightOverviewRulerOption;
+};
+
export const SupportedLanguages: monaco.languages.ILanguageExtensionPoint[] = [
{
id: "sql",
diff --git a/frontend/src/components/SchemaEditorLite/Aside/BranchTree.vue b/frontend/src/components/SchemaEditorLite/Aside/BranchTree.vue
index 85cecd67fa..273f510089 100644
--- a/frontend/src/components/SchemaEditorLite/Aside/BranchTree.vue
+++ b/frontend/src/components/SchemaEditorLite/Aside/BranchTree.vue
@@ -78,13 +78,14 @@
<script lang="ts" setup>
import { useElementSize } from "@vueuse/core";
-import { cloneDeep, escape, head } from "lodash-es";
+import { cloneDeep, debounce, escape, head } from "lodash-es";
import { TreeOption, NEllipsis, NInput, NDropdown, NTree } from "naive-ui";
import { computed, watch, ref, h, reactive, nextTick, onMounted } from "vue";
import { useI18n } from "vue-i18n";
import DuplicateIcon from "~icons/heroicons-outline/document-duplicate";
import EllipsisIcon from "~icons/heroicons-solid/ellipsis-horizontal";
import { SchemaIcon, TableIcon } from "@/components/Icon";
+import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { ComposedDatabase } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import {
@@ -146,6 +147,7 @@ const state = reactive<LocalState>({
shouldRelocateTreeNode: false,
});
const {
+ events,
targets,
readonly,
currentTab,
@@ -270,10 +272,6 @@ const contextMenuOptions = computed(() => {
return [];
});
-onMounted(() => {
- buildBranchTreeData();
-});
-
const buildBranchTreeData = () => {
const db = database.value;
const treeNodeList: TreeNode[] = [];
@@ -314,6 +312,13 @@ const buildBranchTreeData = () => {
}
};
+onMounted(() => {
+ buildBranchTreeData();
+});
+
+const debouncedBuildBranchTreeData = debounce(buildBranchTreeData, 100);
+useEmitteryEventListener(events, "rebuild-tree", debouncedBuildBranchTreeData);
+
watch(
[() => schemaList.value.length, () => flattenTableList.value.length],
buildBranchTreeData,
diff --git a/frontend/src/components/SchemaEditorLite/Aside/DatabaseTree.vue b/frontend/src/components/SchemaEditorLite/Aside/DatabaseTree.vue
index 69b5b75576..1c7ad3c51d 100644
--- a/frontend/src/components/SchemaEditorLite/Aside/DatabaseTree.vue
+++ b/frontend/src/components/SchemaEditorLite/Aside/DatabaseTree.vue
@@ -70,7 +70,7 @@
<script lang="ts" setup>
import { useElementSize } from "@vueuse/core";
-import { escape, head } from "lodash-es";
+import { debounce, escape, head } from "lodash-es";
import {
TreeOption,
NEllipsis,
@@ -84,6 +84,7 @@ import { useI18n } from "vue-i18n";
import EllipsisIcon from "~icons/heroicons-solid/ellipsis-horizontal";
import { DatabaseIcon, SchemaIcon, TableIcon } from "@/components/Icon";
import { InstanceV1EngineIcon } from "@/components/v2";
+import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { ComposedDatabase, ComposedInstance } from "@/types";
import { Engine } from "@/types/proto/v1/common";
import {
@@ -177,6 +178,7 @@ interface LocalState {
const { t } = useI18n();
const {
+ events,
targets,
currentTab,
addTab,
@@ -400,13 +402,19 @@ const buildDatabaseTreeData = () => {
});
}
};
+const debouncedBuildDatabaseTreeData = debounce(buildDatabaseTreeData, 100);
+useEmitteryEventListener(
+ events,
+ "rebuild-tree",
+ debouncedBuildDatabaseTreeData
+);
watch(
[
() => databaseList.value.length,
() => flattenSchemaList.value.length,
() => flattenTableList.value.length,
],
- buildDatabaseTreeData,
+ debouncedBuildDatabaseTreeData,
{
deep: false,
}
@@ -488,7 +496,7 @@ const openTabForTreeNode = (node: TreeNode) => {
state.shouldRelocateTreeNode = true;
};
-onMounted(async () => {
+onMounted(() => {
buildDatabaseTreeData();
});
diff --git a/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue b/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
index c41a1f6301..306d7d58b5 100644
--- a/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
+++ b/frontend/src/components/SchemaEditorLite/Panels/TableEditor.vue
@@ -6,7 +6,7 @@
>
<div
v-if="!readonly"
- class="w-full flex justify-between items-center space-x-2"
+ class="w-full flex justify-start items-center space-x-2"
>
<NButton
size="small"
diff --git a/frontend/src/components/SchemaEditorLite/algorithm/rebuild.ts b/frontend/src/components/SchemaEditorLite/algorithm/rebuild.ts
index 8790e62dcb..ddee774f61 100644
--- a/frontend/src/components/SchemaEditorLite/algorithm/rebuild.ts
+++ b/frontend/src/components/SchemaEditorLite/algorithm/rebuild.ts
@@ -1,10 +1,11 @@
+import { nextTick } from "vue";
import { ComposedDatabase } from "@/types";
import { DatabaseMetadata } from "@/types/proto/v1/database_service";
import { SchemaEditorContext } from "../context";
import { DiffMerge } from "./diff-merge";
export const useRebuildMetadataEdit = (context: SchemaEditorContext) => {
- const { clearEditStatus } = context;
+ const { clearEditStatus, events } = context;
const rebuildMetadataEdit = (
database: ComposedDatabase,
@@ -15,6 +16,10 @@ export const useRebuildMetadataEdit = (context: SchemaEditorContext) => {
const dm = new DiffMerge(context, database, source, target);
dm.merge();
dm.timer.printAll();
+ nextTick(() => {
+ events.emit("clear-tabs");
+ events.emit("rebuild-tree");
+ });
};
return { rebuildMetadataEdit };
diff --git a/frontend/src/components/SchemaEditorLite/context/index.ts b/frontend/src/components/SchemaEditorLite/context/index.ts
index 96e56ac643..16499807fa 100644
--- a/frontend/src/components/SchemaEditorLite/context/index.ts
+++ b/frontend/src/components/SchemaEditorLite/context/index.ts
@@ -12,6 +12,8 @@ export const KEY = Symbol("bb.schema-editor");
export type SchemaEditorEvents = Emittery<{
["update:selected-rollout-objects"]: RolloutObject[];
+ ["rebuild-tree"]: undefined;
+ ["clear-tabs"]: undefined;
}>;
export const provideSchemaEditorContext = (params: {
@@ -25,7 +27,7 @@ export const provideSchemaEditorContext = (params: {
const context = {
events,
...params,
- ...useTabs(),
+ ...useTabs(events),
...useEditStatus(),
...useEditConfigs(params.targets),
...useScrollStatus(),
diff --git a/frontend/src/components/SchemaEditorLite/context/tabs.ts b/frontend/src/components/SchemaEditorLite/context/tabs.ts
index 1433ddbff6..613eadbc96 100644
--- a/frontend/src/components/SchemaEditorLite/context/tabs.ts
+++ b/frontend/src/components/SchemaEditorLite/context/tabs.ts
@@ -1,8 +1,10 @@
import { v1 as uuidv1 } from "uuid";
import { computed, ref } from "vue";
+import { useEmitteryEventListener } from "@/composables/useEmitteryEventListener";
import { CoreTabContext, TabContext } from "../types";
+import { SchemaEditorEvents } from "./index";
-export const useTabs = () => {
+export const useTabs = (events: SchemaEditorEvents) => {
const tabMap = ref(new Map<string, TabContext>());
const tabList = computed(() => {
return Array.from(tabMap.value.values());
@@ -82,6 +84,10 @@ export const useTabs = () => {
return false;
});
};
+ useEmitteryEventListener(events, "clear-tabs", () => {
+ tabMap.value.clear();
+ currentTabId.value = "";
+ });
return {
tabMap,
diff --git a/frontend/src/components/misc/MaskSpinner.vue b/frontend/src/components/misc/MaskSpinner.vue
index 2c93ad0b8a..cc145230aa 100644
--- a/frontend/src/components/misc/MaskSpinner.vue
+++ b/frontend/src/components/misc/MaskSpinner.vue
@@ -1,6 +1,6 @@
<template>
<div
- v-zindexable="{ enabled: true }"
+ v-zindexable="{ enabled: zindexable }"
class="absolute inset-0 bg-white/50 flex flex-col items-center justify-center gap-y-2"
>
<NSpin v-bind="spinProps" />
@@ -12,7 +12,11 @@
import { NSpin, SpinProps } from "naive-ui";
import { zindexable as vZindexable } from "vdirs";
-defineProps<{
- spinProps?: SpinProps;
-}>();
+withDefaults(
+ defineProps<{
+ spinProps?: SpinProps;
+ zindexable?: boolean;
+ }>(),
+ { spinProps: undefined, zindexable: true }
+);
</script>
diff --git a/frontend/src/components/v2/Form/StepTab.vue b/frontend/src/components/v2/Form/StepTab.vue
index f4afbb7144..83a4f579a9 100644
--- a/frontend/src/components/v2/Form/StepTab.vue
+++ b/frontend/src/components/v2/Form/StepTab.vue
@@ -27,7 +27,7 @@
<div
class="pt-4 border-t border-block-border flex items-center space-x-2 justify-between"
- :class="[sticky && 'pb-4 bg-white sticky bottom-0 z-10']"
+ :class="[sticky && 'pb-4 bg-white sticky bottom-0 z-10', footerClass]"
>
<div>
<NButton v-if="showCancel" @click.prevent="$emit('cancel')">
@@ -78,6 +78,7 @@ withDefaults(
sticky?: boolean;
finishTitle?: string;
paneClass?: VueClass;
+ footerClass?: VueClass;
stepList: { title: string; description?: string; hideNext?: boolean }[];
}>(),
{
@@ -86,6 +87,7 @@ withDefaults(
sticky: false,
finishTitle: "bbkit.common.finish",
paneClass: undefined,
+ footerClass: undefined,
}
);
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 856a0bcea8..ecc602fa02 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -3258,7 +3258,6 @@
"parent-branch": "Parent",
"save-draft": "Save draft",
"merge-branch": "Merge branch",
- "delete-branch-after-merged": "Delete branch after merged",
"raw-sql-preview": "Raw SQL Preview",
"diff-editor": {
"self": "Diff editor",
@@ -3361,6 +3360,25 @@
"branch-is-protected": "This branch is protected by branch protection rules.",
"default-branches": "Default",
"your-branches": "Your branches",
- "active-branches": "Active branches"
+ "active-branches": "Active branches",
+ "select-branch": "Select branch",
+ "merge-rebase": {
+ "select-branches-to-merge": "Select branches to merge",
+ "select-branches-to-rebase": "Select branches to rebase",
+ "validating-branch": "Validating branches",
+ "able-to-merge": "Able to merge",
+ "able-to-rebase": "Able to rebase",
+ "cannot-automatically-merge": "Can't automatically merge, please {rebase_branch} first.",
+ "cannot-automatically-rebase": "Can't rebase automatically. Please resolve the conflicts manually.",
+ "go-rebase": "rebase branch",
+ "changes-of-branch": "Changes of {branch}",
+ "merge-succeeded": "Merge succeeded",
+ "rebase-succeeded": "Rebase succeeded",
+ "delete-branch-after-merged": "Delete branch after merged",
+ "merge-branch": "Merge branch",
+ "rebase-branch": "Rebase branch",
+ "confirm-rebase": "Confirm rebase?",
+ "conflict-not-resolved": "It seems that some conflicts haven't been resolved yet."
+ }
}
}
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 3a20726c80..1b7232837a 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -3256,7 +3256,6 @@
"parent-branch": "Rama principal",
"save-draft": "Guardar borrador",
"merge-branch": "Fusionar rama",
- "delete-branch-after-merged": "Eliminar rama después de la fusión",
"raw-sql-preview": "vista previa de sql sin formato",
"diff-editor": {
"self": "Editor de diferencias",
@@ -3359,6 +3358,25 @@
"branch-is-protected": "La rama está protegida",
"default-branches": "Ramas por defecto",
"your-branches": "Tus ramas",
- "active-branches": "Ramas activas"
+ "active-branches": "Ramas activas",
+ "select-branch": "Seleccionar sucursal",
+ "merge-rebase": {
+ "select-branches-to-merge": "Seleccionar sucursales para fusionar",
+ "select-branches-to-rebase": "Seleccione sucursales para rebase",
+ "validating-branch": "Validando sucursales",
+ "able-to-merge": "Capaz de fusionarse",
+ "able-to-rebase": "Capaz de rebase",
+ "cannot-automatically-merge": "No se puede fusionar automáticamente, {rebase_branch} primero.",
+ "cannot-automatically-rebase": "No se puede cambiar la base automáticamente. \nResuelva los conflictos manualmente.",
+ "go-rebase": "rama de rebase",
+ "changes-of-branch": "Cambios de {branch}",
+ "merge-succeeded": "Fusión exitosa",
+ "rebase-succeeded": "Rebase exitoso",
+ "delete-branch-after-merged": "Eliminar rama después de la fusión",
+ "merge-branch": "Fusionar rama",
+ "rebase-branch": "rama de rebase",
+ "confirm-rebase": "¿Confirmar rebase?",
+ "conflict-not-resolved": "Parece que algunos conflictos aún no se han resuelto."
+ }
}
}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 6f64d2e3ee..07c489dc99 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -3251,7 +3251,6 @@
"parent-branch": "父分支",
"save-draft": "保存草稿",
"merge-branch": "合并分支",
- "delete-branch-after-merged": "合并后删除分支",
"raw-sql-preview": "原始 SQL 预览",
"diff-editor": {
"self": "Diff 编辑器",
@@ -3354,6 +3353,25 @@
"branch-is-protected": "该分支已被保护",
"default-branches": "默认分支",
"your-branches": "你的分支",
- "active-branches": "活跃的分支"
+ "active-branches": "活跃的分支",
+ "select-branch": "选择分支",
+ "merge-rebase": {
+ "select-branches-to-merge": "选择要合并的分支",
+ "select-branches-to-rebase": "选择要 rebase 的分支",
+ "validating-branch": "正在验证分支",
+ "able-to-merge": "可以合并",
+ "able-to-rebase": "可以 rebase",
+ "cannot-automatically-merge": "无法自动合并,请先 {rebase_branch}。",
+ "cannot-automatically-rebase": "无法自动 rebase,请手动解决冲突。",
+ "go-rebase": "rebase 分支",
+ "changes-of-branch": "{branch} 的变更",
+ "merge-succeeded": "合并成功",
+ "rebase-succeeded": "Rebase 成功",
+ "delete-branch-after-merged": "合并后删除分支",
+ "merge-branch": "合并分支",
+ "rebase-branch": "Rebase 分支",
+ "confirm-rebase": "确认 rebase?",
+ "conflict-not-resolved": "似乎还有尚未解决的冲突。"
+ }
}
}
diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts
index 0af51f5c42..2903a23ff7 100644
--- a/frontend/src/router/index.ts
+++ b/frontend/src/router/index.ts
@@ -706,6 +706,24 @@ const routes: Array<RouteRecordRaw> = [
component: () => import("../views/branch/BranchRollout.vue"),
props: true,
},
+ {
+ path: "branches/:branchName/merge",
+ name: "workspace.project.branch.merge",
+ meta: {
+ title: () => t("branch.merge-rebase.merge-branch"),
+ },
+ component: () => import("../views/branch/BranchMerge.vue"),
+ props: true,
+ },
+ {
+ path: "branches/:branchName/rebase",
+ name: "workspace.project.branch.rebase",
+ meta: {
+ title: () => t("branch.merge-rebase.rebase-branch"),
+ },
+ component: () => import("../views/branch/BranchRebase.vue"),
+ props: true,
+ },
{
path: "changelists/:changelistName",
name: "workspace.project.changelist.detail",
diff --git a/frontend/src/store/modules/branch.ts b/frontend/src/store/modules/branch.ts
index 63a10121d5..fc66f5a621 100644
--- a/frontend/src/store/modules/branch.ts
+++ b/frontend/src/store/modules/branch.ts
@@ -6,6 +6,7 @@ import {
MergeBranchRequest,
Branch,
BranchView,
+ RebaseBranchRequest,
} from "@/types/proto/v1/branch_service";
export const useBranchStore = defineStore("schema_design", () => {
@@ -48,12 +49,21 @@ export const useBranchStore = defineStore("schema_design", () => {
};
const mergeBranch = async (request: MergeBranchRequest) => {
- const resp = await branchServiceClient.mergeBranch(request, {
+ const branch = await branchServiceClient.mergeBranch(request, {
silent: true,
});
- if (resp.branch) {
- branchMapByName.set(resp.branch.name, resp.branch);
+ branchMapByName.set(branch.name, branch);
+ return branch;
+ };
+
+ const rebaseBranch = async (request: RebaseBranchRequest) => {
+ const response = await branchServiceClient.rebaseBranch(request, {
+ silent: true,
+ });
+ if (response.branch) {
+ branchMapByName.set(response.branch.name, response.branch);
}
+ return response;
};
const fetchBranchByName = async (
@@ -104,6 +114,7 @@ export const useBranchStore = defineStore("schema_design", () => {
createBranch,
updateBranch,
mergeBranch,
+ rebaseBranch,
fetchBranchByName,
getBranchByName,
deleteBranch,
diff --git a/frontend/src/views/branch/BranchMerge.vue b/frontend/src/views/branch/BranchMerge.vue
new file mode 100644
index 0000000000..a8389e0164
--- /dev/null
+++ b/frontend/src/views/branch/BranchMerge.vue
@@ -0,0 +1,71 @@
+<template>
+ <div class="w-full h-full relative">
+ <BranchMergeView
+ v-if="project"
+ :project="project"
+ :head-branch-name="branchFullName"
+ @update:head-branch-name="handleUpdateHeadBranchName"
+ @merged="handleMerged"
+ />
+ <MaskSpinner v-else />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { useRouter } from "vue-router";
+import BranchMergeView from "@/components/Branch/BranchMergeView";
+import { useProjectV1Store } from "@/store";
+import { getProjectAndBranchId } from "@/store/modules/v1/common";
+import { Branch } from "@/types/proto/v1/branch_service";
+import { idFromSlug } from "@/utils";
+
+const props = defineProps<{
+ projectSlug: string;
+ branchName: string;
+}>();
+
+const router = useRouter();
+
+const project = computed(() => {
+ if (props.projectSlug === "-") {
+ return;
+ }
+ return useProjectV1Store().getProjectByUID(
+ String(idFromSlug(props.projectSlug as string))
+ );
+});
+
+const branchFullName = computed(() => {
+ if (!project.value) return null;
+ if (props.branchName === "-") return null;
+ return `${project.value.name}/branches/${props.branchName}`;
+});
+
+const handleUpdateHeadBranchName = (branchName: string | null) => {
+ const branchId = branchName ? getProjectAndBranchId(branchName)[1] : "-";
+ router.replace({
+ name: "workspace.project.branch.merge",
+ params: {
+ projectSlug: props.projectSlug,
+ branchName: branchId,
+ },
+ query: router.currentRoute.value.query,
+ hash: router.currentRoute.value.hash,
+ });
+};
+
+const handleMerged = (
+ mergedBranch: Branch,
+ headBranchName: string,
+ headBranch: Branch | undefined
+) => {
+ router.replace({
+ name: "workspace.project.branch.detail",
+ params: {
+ projectSlug: props.projectSlug,
+ branchName: mergedBranch.branchId,
+ },
+ });
+};
+</script>
diff --git a/frontend/src/views/branch/BranchRebase.vue b/frontend/src/views/branch/BranchRebase.vue
new file mode 100644
index 0000000000..11746bca19
--- /dev/null
+++ b/frontend/src/views/branch/BranchRebase.vue
@@ -0,0 +1,71 @@
+<template>
+ <div class="w-full h-full relative">
+ <BranchRebaseView
+ v-if="project"
+ :project="project"
+ :head-branch-name="branchFullName"
+ @update:head-branch-name="handleUpdateHeadBranchName"
+ @rebased="handleRebased"
+ />
+ <MaskSpinner v-else />
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { computed } from "vue";
+import { useRouter } from "vue-router";
+import BranchRebaseView from "@/components/Branch/BranchRebaseView";
+import { useProjectV1Store } from "@/store";
+import { getProjectAndBranchId } from "@/store/modules/v1/common";
+import { Branch } from "@/types/proto/v1/branch_service";
+import { idFromSlug } from "@/utils";
+
+const props = defineProps<{
+ projectSlug: string;
+ branchName: string;
+}>();
+
+const router = useRouter();
+
+const project = computed(() => {
+ if (props.projectSlug === "-") {
+ return;
+ }
+ return useProjectV1Store().getProjectByUID(
+ String(idFromSlug(props.projectSlug as string))
+ );
+});
+
+const branchFullName = computed(() => {
+ if (!project.value) return null;
+ if (props.branchName === "-") return null;
+ return `${project.value.name}/branches/${props.branchName}`;
+});
+
+const handleUpdateHeadBranchName = (branchName: string | null) => {
+ const branchId = branchName ? getProjectAndBranchId(branchName)[1] : "-";
+ router.replace({
+ name: "workspace.project.branch.rebase",
+ params: {
+ projectSlug: props.projectSlug,
+ branchName: branchId,
+ },
+ query: router.currentRoute.value.query,
+ hash: router.currentRoute.value.hash,
+ });
+};
+
+const handleRebased = (
+ rebasedBranch: Branch,
+ headBranchName: string,
+ headBranch: Branch | undefined
+) => {
+ router.replace({
+ name: "workspace.project.branch.detail",
+ params: {
+ projectSlug: props.projectSlug,
+ branchName: rebasedBranch.branchId,
+ },
+ });
+};
+</script>