Skip to content

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

chore: retire branch from changelist items (#11861)

Liu Jif9adf5c14fe3
diff --git a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/AddChangePanel.vue b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/AddChangePanel.vue
index 6bdb3b85a5..2514e43332 100644
--- a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/AddChangePanel.vue
+++ b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/AddChangePanel.vue
@@ -22,11 +22,6 @@
{{ $t("common.change-history") }}
</div>
</NRadio>
- <NRadio value="BRANCH">
- <div class="flex items-center">
- <GitBranch :size="16" class="mr-1" />{{ $t("common.branch") }}
- </div>
- </NRadio>
<NRadio value="RAW_SQL">
<div class="flex items-center">
<File :size="16" class="mr-1" />
@@ -37,7 +32,6 @@
</div>
<ChangeHistoryForm v-if="changeSource === 'CHANGE_HISTORY'" />
- <BranchForm v-if="changeSource === 'BRANCH'" />
<RawSQLForm v-if="changeSource === 'RAW_SQL'" />
</div>
@@ -80,7 +74,7 @@
<script setup lang="ts">
import { asyncComputed } from "@vueuse/core";
import dayjs from "dayjs";
-import { File, GitBranch, History } from "lucide-vue-next";
+import { File, History } from "lucide-vue-next";
import { NRadio, NRadioGroup } from "naive-ui";
import { zindexable as vZindexable } from "vdirs";
import { computed, ref, watch } from "vue";
@@ -104,7 +98,7 @@ import {
} from "@/utils";
import { useChangelistDetailContext } from "../context";
import { provideAddChangeContext } from "./context";
-import { BranchForm, ChangeHistoryForm, RawSQLForm } from "./form";
+import { ChangeHistoryForm, RawSQLForm } from "./form";
import { emptyRawSQLChange } from "./utils";
const { t } = useI18n();
diff --git a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchForm.vue b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchForm.vue
deleted file mode 100644
index fa99859b8f..0000000000
--- a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchForm.vue
+++ /dev/null
@@ -1,182 +0,0 @@
-<template>
- <div class="flex flex-col gap-y-4">
- <div class="flex flex-col gap-y-2 max-w-max">
- <div
- v-if="changes.length === 0"
- class="text-control-placeholder text-sm leading-[28px]"
- >
- {{
- $t("changelist.add-change.branch.select-at-least-one-branch-below")
- }}
- </div>
- <BranchChangeItem
- v-for="change in changes"
- :key="change.source"
- :change="change"
- :branch="branchForChange(change)"
- @click-item="handleClickChange($event)"
- @remove-item="handleRemoveChange($event)"
- />
- </div>
- <div class="flex flex-row items-center justify-between py-0.5">
- <div class="flex flex-row items-center justify-start gap-x-2">
- <DatabaseSelect
- v-model:database="state.databaseUID"
- :project="project.uid"
- />
- </div>
- <div class="flex flex-row items-center justify-end gap-x-2">
- <SearchBox
- v-model:value="state.keyword"
- :placeholder="$t('common.filter-by-name')"
- />
- </div>
- </div>
-
- <BranchTable
- v-model:selected="selectedBranchList"
- :branch-list="filteredBranchList"
- :is-fetching="!ready"
- :keyword="state.keyword"
- @click-item="state.detailBranchName = $event.name"
- />
- <BranchDetailPanel
- :branch-name="state.detailBranchName"
- @close="state.detailBranchName = undefined"
- />
- </div>
-</template>
-
-<script setup lang="ts">
-import { first, orderBy } from "lodash-es";
-import { computed, reactive, watch } from "vue";
-import { DatabaseSelect } from "@/components/v2";
-import { useDatabaseV1Store, useLocalSheetStore } from "@/store";
-import { useBranchListByProject, useBranchStore } from "@/store/modules/branch";
-import { UNKNOWN_ID } from "@/types";
-import type { Branch } from "@/types/proto/v1/branch_service";
-import { Changelist_Change as Change } from "@/types/proto/v1/changelist_service";
-import { keyBy } from "@/utils";
-import BranchDetailPanel from "../../BranchDetailPanel";
-import { useChangelistDetailContext } from "../../context";
-import { useAddChangeContext } from "../context";
-import BranchChangeItem from "./BranchChangeItem.vue";
-import BranchTable from "./BranchTable";
-
-type LocalState = {
- keyword: string;
- databaseUID: string | undefined;
- branchList: Branch[];
- detailBranchName: string | undefined;
-};
-
-const state = reactive<LocalState>({
- keyword: "",
- databaseUID: undefined,
- branchList: [],
- detailBranchName: undefined,
-});
-
-const { project } = useChangelistDetailContext();
-const { changesFromBranch: changes } = useAddChangeContext();
-const { branchList, ready } = useBranchListByProject(
- computed(() => project.value.name)
-);
-const localSheetStore = useLocalSheetStore();
-
-const database = computed(() => {
- const uid = state.databaseUID;
- if (!uid || uid === String(UNKNOWN_ID)) return undefined;
- return useDatabaseV1Store().getDatabaseByUID(uid);
-});
-
-const filteredBranchList = computed(() => {
- const db = database.value;
- if (!db) {
- return [];
- }
- const branchListFilterByDatabase = branchList.value.filter((branch) => {
- return branch.baselineDatabase === db.name;
- });
- let list = orderBy(
- branchListFilterByDatabase,
- (branch) => branch.updateTime,
- "desc"
- );
-
- const kw = state.keyword.trim().toLowerCase();
- if (kw) {
- list = list.filter((branch) => branch.branchId.toLowerCase().includes(kw));
- }
-
- return list;
-});
-
-const selectedBranchList = computed<string[]>({
- get() {
- return changes.value.map((change) => {
- return change.source;
- });
- },
- set(selected) {
- const existedChangesByBranchName = keyBy(
- changes.value,
- (change) => change.source
- );
- const updatedChanges: Change[] = [];
- for (let i = 0; i < selected.length; i++) {
- const name = selected[i];
- const existedChange = existedChangesByBranchName.get(name);
- if (existedChange) {
- updatedChanges.push(existedChange);
- } else {
- const uid = localSheetStore.nextUID();
- const sheet = localSheetStore.createLocalSheet(
- `${project.value.name}/sheets/${uid}`
- );
- updatedChanges.push(
- Change.fromPartial({
- sheet: sheet.name,
- source: name,
- })
- );
- }
- }
- changes.value = updatedChanges;
- },
-});
-
-const handleRemoveChange = (change: Change) => {
- const index = changes.value.findIndex((c) => c.source === change.source);
- if (index >= 0) {
- changes.value.splice(index, 1);
- }
-};
-
-const handleClickChange = async (change: Change) => {
- const branchName = change.source;
- const branch = await useBranchStore().fetchBranchByName(
- branchName,
- true /* useCache */
- );
- const database = useDatabaseV1Store().getDatabaseByName(
- branch.baselineDatabase
- );
- state.databaseUID = database.uid;
- state.detailBranchName = branchName;
-};
-
-const branchForChange = (change: Change) => {
- return branchList.value.find((br) => br.name === change.source);
-};
-
-// Select the first database automatically
-watch(
- () => project.value.name,
- (project) => {
- const databaseList = useDatabaseV1Store().databaseListByProject(project);
- state.databaseUID = first(databaseList)?.uid;
- },
- { immediate: true }
-);
-</script>
diff --git a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchTable/BranchTable.vue b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchTable/BranchTable.vue
deleted file mode 100644
index e4aed750d7..0000000000
--- a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchTable/BranchTable.vue
+++ /dev/null
@@ -1,163 +0,0 @@
-<template>
- <BBGrid
- :column-list="columns"
- :ready="!isFetching"
- :data-source="branchList"
- :show-placeholder="true"
- :custom-header="true"
- class="border"
- @click-row="handleClickRow"
- >
- <template #header>
- <div role="table-row" class="bb-grid-row bb-grid-header-row group">
- <div
- v-for="(column, index) in columns"
- :key="index"
- role="table-cell"
- class="bb-grid-header-cell capitalize"
- :class="[column.class]"
- >
- <template v-if="index === 0">
- <NCheckbox
- v-bind="allSelectionState"
- @update:checked="toggleSelectAll"
- />
- </template>
- <template v-else>{{ column.title }}</template>
- </div>
- </div>
- </template>
- <template #item="{ item: branch }: BBGridRow<Branch>">
- <div class="bb-grid-cell" @click.stop.prevent>
- <NCheckbox
- :checked="isSelected(branch)"
- @update:checked="toggleSelect(branch, $event)"
- />
- </div>
-
- <!-- eslint-disable-next-line vue/no-v-html -->
- <div class="bb-grid-cell" v-html="renderTitle(branch)"></div>
- <div class="bb-grid-cell">
- <BranchBaseline :branch="branch" />
- </div>
- <div class="bb-grid-cell">
- <i18n-t keypath="common.updated-at-by">
- <template #time>
- <HumanizeDate :date="branch.updateTime" />
- </template>
- <template #user>{{ getUser(branch.updater)?.title }}</template>
- </i18n-t>
- </div>
- </template>
- </BBGrid>
-</template>
-
-<script lang="ts" setup>
-import { escape } from "lodash-es";
-import { NCheckbox } from "naive-ui";
-import { computed } from "vue";
-import { useI18n } from "vue-i18n";
-import type { BBGridColumn, BBGridRow } from "@/bbkit";
-import { BBGrid } from "@/bbkit";
-import BranchBaseline from "@/components/Branch/BranchBaseline.vue";
-import HumanizeDate from "@/components/misc/HumanizeDate.vue";
-import { useUserStore } from "@/store";
-import type { Branch } from "@/types/proto/v1/branch_service";
-import { extractUserResourceName, getHighlightHTMLByRegExp } from "@/utils";
-
-const props = defineProps<{
- selected: string[];
- branchList: Branch[];
- isFetching: boolean;
- keyword: string;
-}>();
-
-const emit = defineEmits<{
- (event: "update:selected", selected: string[]): void;
- (event: "click-item", branch: Branch): void;
-}>();
-
-const { t } = useI18n();
-
-const columns = computed((): BBGridColumn[] => {
- return [
- { title: "", width: "auto" },
- { title: t("common.branch"), width: "1fr" },
- { title: t("schema-designer.baseline-version"), width: "2fr" },
- {
- title: t("common.updated-at"),
- width: "auto",
- },
- ];
-});
-
-const allSelectionState = computed(() => {
- const { branchList: list, selected } = props;
- const set = new Set(selected);
-
- const checked =
- selected.length > 0 && list.every((branch) => set.has(branch.name));
- const indeterminate = !checked && selected.some((name) => set.has(name));
-
- return {
- checked,
- indeterminate,
- };
-});
-
-const toggleSelectAll = (on: boolean) => {
- if (on) {
- emit(
- "update:selected",
- props.branchList.map((branch) => branch.name)
- );
- } else {
- emit("update:selected", []);
- }
-};
-
-const isSelected = (branch: Branch) => {
- return props.selected.includes(branch.name);
-};
-
-const toggleSelect = (branch: Branch, on: boolean) => {
- const set = new Set(props.selected);
- const key = branch.name;
- if (on) {
- if (!set.has(key)) {
- set.add(key);
- emit("update:selected", Array.from(set));
- }
- } else {
- if (set.has(key)) {
- set.delete(key);
- emit("update:selected", Array.from(set));
- }
- }
-};
-
-const renderTitle = (branch: Branch) => {
- const keyword = props.keyword.trim().toLowerCase();
-
- const { branchId } = branch;
-
- if (!keyword) {
- return escape(branchId);
- }
-
- return getHighlightHTMLByRegExp(
- escape(branchId),
- escape(keyword),
- false /* !caseSensitive */
- );
-};
-
-const getUser = (name: string) => {
- const email = extractUserResourceName(name);
- return useUserStore().getUserByEmail(email);
-};
-
-const handleClickRow = (item: Branch) => {
- emit("click-item", item);
-};
-</script>
diff --git a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchTable/index.ts b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchTable/index.ts
deleted file mode 100644
index 69b431139f..0000000000
--- a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/BranchTable/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-import BranchTable from "./BranchTable.vue";
-
-export default BranchTable;
diff --git a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/index.ts b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/index.ts
index 5e1a0eb400..6a384a1833 100644
--- a/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/index.ts
+++ b/frontend/src/components/Changelist/ChangelistDetail/AddChangePanel/form/index.ts
@@ -1,5 +1,4 @@
-import BranchForm from "./BranchForm.vue";
import ChangeHistoryForm from "./ChangeHistoryForm.vue";
import RawSQLForm from "./RawSQLForm.vue";
-export { ChangeHistoryForm, BranchForm, RawSQLForm };
+export { ChangeHistoryForm, RawSQLForm };