Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: simplify and fix allow edit (#13307)
Danny Xu6acc6aadf0da
diff --git a/frontend/src/components/Branch/BranchDetailView.vue b/frontend/src/components/Branch/BranchDetailView.vueindex 7817b796df..7c921db0e6 100644--- a/frontend/src/components/Branch/BranchDetailView.vue+++ b/frontend/src/components/Branch/BranchDetailView.vue@@ -13,18 +13,7 @@<div class="w-full flex flex-row justify-between items-center"><div class="w-full flex flex-row justify-start items-center gap-x-2">- <NInput- v-if="allowEdit"- v-model:value="state.branchId"- class="!w-auto"- :passively-activated="true"- :style="branchIdInputStyle"- :readonly="!allowEdit || !state.isEditingBranchId"- :placeholder="'feature/add-billing'"- @focus="state.isEditingBranchId = true"- @blur="handleBranchIdInputBlur"- />- <span v-else class="text-xl leading-[34px]">{{+ <span class="text-xl leading-[34px]">{{cleanBranch.branchId}}</span><span@@ -42,43 +31,38 @@</div><div><div class="w-full flex flex-row justify-between items-center">- <div- v-if="allowEdit"- class="flex flex-row justify-end items-center space-x-2"- >- <template v-if="!state.isEditing">- <NButton @click="handleEdit">{{ $t("common.edit") }}</NButton>- <NButton- v-if="showMergeBranchButton"- @click="handleGotoMergeBranch"- >- {{ $t("branch.merge-rebase.merge-branch") }}- </NButton>- <NButton- v-if="showRebaseBranchButton"- @click="handleGotoRebaseBranch"- >- {{ $t("branch.merge-rebase.rebase-branch") }}- </NButton>- <NButton- v-if="showApplyBranchButton"- type="primary"- @click="handleApplyBranchToDatabase"- >{{ $t("schema-designer.apply-to-database") }}</NButton- >- </template>- <template v-else>- <NButton :loading="state.isReverting" @click="handleCancelEdit">{{- $t("common.cancel")- }}</NButton>- <NButton- type="primary"- :loading="!!state.savingStatus"- @click="handleSaveBranch"- >{{ $t("common.save") }}</NButton- >- </template>- </div>+ <template v-if="!state.isEditing">+ <NButton v-if="showEditButton" @click="handleEdit">{{ $t("common.edit") }}</NButton>+ <NButton+ v-if="showMergeBranchButton"+ @click="handleGotoMergeBranch"+ >+ {{ $t("branch.merge-rebase.merge-branch") }}+ </NButton>+ <NButton+ v-if="showRebaseBranchButton"+ @click="handleGotoRebaseBranch"+ >+ {{ $t("branch.merge-rebase.rebase-branch") }}+ </NButton>+ <NButton+ v-if="showApplyBranchButton"+ type="primary"+ @click="handleApplyBranchToDatabase"+ >{{ $t("schema-designer.apply-to-database") }}</NButton+ >+ </template>+ <template v-else>+ <NButton :loading="state.isReverting" @click="handleCancelEdit">{{+ $t("common.cancel")+ }}</NButton>+ <NButton+ type="primary"+ :loading="!!state.savingStatus"+ @click="handleSaveBranch"+ >{{ $t("common.save") }}</NButton+ >+ </template></div></div></div>@@ -139,9 +123,8 @@import { asyncComputed, computedAsync } from "@vueuse/core";import dayjs from "dayjs";import { cloneDeep } from "lodash-es";-import { NButton, NCheckbox, NDivider, NInput, useDialog } from "naive-ui";+import { NButton, NCheckbox, NDivider, useDialog } from "naive-ui";import { Status } from "nice-grpc-common";-import type { CSSProperties } from "vue";import { computed, nextTick, reactive, ref, watch } from "vue";import { useI18n } from "vue-i18n";import { useRouter } from "vue-router";@@ -182,7 +165,6 @@ import { provideSQLCheckContext } from "../SQLCheck";import { generateDiffDDL } from "../SchemaEditorLite";import MaskSpinner from "../misc/MaskSpinner.vue";import SchemaDesignEditorLite from "./SchemaDesignEditorLite.vue";-import { validateBranchName } from "./utils";interface LocalState {branchId: string;@@ -199,9 +181,6 @@ const props = defineProps<{cleanBranch: Branch;dirtyBranch: Branch;}>();-const emit = defineEmits<{- (event: "update:branch-id", id: string): void;-}>();const { t } = useI18n();const router = useRouter();@@ -235,16 +214,6 @@ const checkPermission = (permission: Permission): boolean => {);};-const allowEdit = computed(() => {- if (!checkPermission("bb.branches.update")) {- return false;- }- if (props.dirtyBranch.parentBranch === "") {- return checkPermission("bb.branches.admin");- }- return true;-});-const allowDelete = computed(() => {if (props.dirtyBranch.parentBranch === "") {return checkPermission("bb.branches.admin");@@ -270,13 +239,24 @@ const database = computedAsync(() => {);}, unknownDatabase());++const showEditButton = computed(() => {+ if (checkPermission("bb.branches.admin")) {+ return true;+ }+ // main branches (parent-less branches) cannot be updated.+ if (!parentBranch.value) {+ return false;+ }+ return true;+});+const showMergeBranchButton = computed(() => {// main branches (parent-less branches) cannot be merged.if (!parentBranch.value) {return false;}- // The branch's creator and project owners can merge feature branches into main branches.- return allowEdit.value;+ return checkPermission("bb.branches.update");});const showRebaseBranchButton = computed(() => {@@ -289,8 +269,7 @@ const showRebaseBranchButton = computed(() => {);}- // For feature branches: project owners and branch creator- return allowEdit.value;+ return checkPermission("bb.branches.update");});const showApplyBranchButton = computed(() => {@@ -312,22 +291,6 @@ const rebuildMetadataEdit = () => {);};-const branchIdInputStyle = computed(() => {- const style: CSSProperties = {- cursor: "default",- minWidth: "10rem",- "--n-color-disabled": "transparent",- "--n-font-size": "20px",- };- const border = state.isEditingBranchId- ? "1px solid rgb(var(--color-control-border))"- : "none";- style["--n-border"] = border;- style["--n-border-disabled"] = border;-- return style;-});-watch(() => props.dirtyBranch.branchId,(title) => {@@ -338,48 +301,6 @@ watch(});-const handleBranchIdInputBlur = async () => {- if (state.branchId === "") {- pushNotification({- module: "bytebase",- style: "WARN",- title: "Branch name cannot be empty.",- });- return;- }- if (!validateBranchName(state.branchId)) {- pushNotification({- module: "bytebase",- style: "CRITICAL",- title: "Branch name valid characters: /^[a-zA-Z][a-zA-Z0-9-_/]+$/",- });- return;- }-- const branch = props.dirtyBranch;- const updateMask = [];- if (branch.branchId !== state.branchId) {- updateMask.push("branch_id");- }- if (updateMask.length !== 0) {- await branchStore.updateBranch(- Branch.fromPartial({- name: branch.name,- branchId: state.branchId,- baselineDatabase: branch.baselineDatabase,- }),- updateMask- );- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: t("schema-designer.message.updated-succeed"),- });- }- emit("update:branch-id", state.branchId);- state.isEditingBranchId = false;-};-const handleParentBranchClick = async () => {if (!parentBranch.value) {return;