Skip to content

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

chore: update project branch tables (#9995)

boojack008e0bc1f493
diff --git a/frontend/src/components/Branch/BranchDataTable.vue b/frontend/src/components/Branch/BranchDataTable.vue
deleted file mode 100644
index 50348aa88a..0000000000
--- a/frontend/src/components/Branch/BranchDataTable.vue
+++ /dev/null
@@ -1,152 +0,0 @@
-<template>
- <NDataTable
- v-bind="$attrs"
- :bordered="false"
- :columns="dataTableColumns"
- :data="dataTableRows"
- :row-key="rowKey"
- :row-props="rowProps"
- :loading="!ready"
- class="bb-branch-data-table"
- />
-</template>
-
-<script lang="ts" setup>
-import dayjs from "dayjs";
-import { NDataTable } from "naive-ui";
-import { computed, h } from "vue";
-import { useI18n } from "vue-i18n";
-import BranchBaseline from "@/components/Branch/BranchBaseline.vue";
-import { useDatabaseV1Store, useUserStore } from "@/store";
-import { Branch } from "@/types/proto/v1/branch_service";
-
-type BranchRowData = {
- branch: Branch;
- name: string;
- branchName: string;
- baselineVersion: string;
- updatedTimeStr: string;
- children?: BranchRowData[];
-};
-
-const props = defineProps<{
- branches: Branch[];
- ready?: boolean;
-}>();
-
-const emit = defineEmits<{
- (event: "click", branch: Branch): void;
-}>();
-
-const { t } = useI18n();
-const userV1Store = useUserStore();
-const databaseStore = useDatabaseV1Store();
-
-const dataTableRows = computed(() => {
- const parentBranches = props.branches.filter((branch) => {
- return branch.parentBranch === "";
- });
- const parentRows: BranchRowData[] = parentBranches.map((branch) => {
- const database = databaseStore.getDatabaseByName(branch.baselineDatabase);
- const baselineVersion = `(${database.effectiveEnvironmentEntity.title}) ${database.databaseName}`;
-
- return {
- branch: branch,
- name: branch.branchId,
- branchName: branch.branchId,
- baselineVersion: baselineVersion,
- updatedTimeStr: getUpdatedTimeStr(branch),
- children: [],
- };
- });
- const childBranches = props.branches.filter((branch) => {
- return branch.parentBranch !== "";
- });
- for (const childBranch of childBranches) {
- const parentRow = parentRows.find(
- (row) => row.branch.name === childBranch.parentBranch
- );
- if (parentRow) {
- parentRow.children?.push({
- branch: childBranch,
- name: childBranch.branchId,
- branchName: `${childBranch.branchId}`,
- baselineVersion: "",
- updatedTimeStr: getUpdatedTimeStr(childBranch),
- });
- }
- }
-
- return parentRows;
-});
-
-const dataTableColumns = computed(() => {
- const BRANCH_NAME_COLUMN = {
- title: t("common.branch"),
- key: "branchName",
- };
- const BASELINE_VERSION_COLUMN = {
- title: t("schema-designer.baseline-version"),
- key: "baselineVersion",
- render: (row: BranchRowData) => {
- return h(BranchBaseline, {
- branch: row.branch,
- showInstanceIcon: true,
- });
- },
- };
- const UPDATED_TIME_COLUMN = {
- title: t("common.updated"),
- key: "updatedTimeStr",
- };
-
- return [
- BRANCH_NAME_COLUMN,
- BASELINE_VERSION_COLUMN,
- UPDATED_TIME_COLUMN,
- ].filter((column) => column);
-});
-
-const rowKey = (row: BranchRowData) => {
- return row.branch.name;
-};
-
-const rowProps = (row: BranchRowData) => {
- return {
- class: "cursor-pointer hover:bg-gray-100",
- onClick: (event: MouseEvent) => {
- const targetElement = event.target as HTMLElement;
- const triggerElement = targetElement.closest(
- "div.n-data-table-expand-trigger"
- );
- // Only emit click event when user clicks on the row but not the expand trigger.
- if (!triggerElement) {
- emit("click", row.branch);
- }
- },
- };
-};
-
-const getUpdatedTimeStr = (branch: Branch) => {
- const updater = userV1Store.getUserByEmail(branch.updater.split("/")[1]);
- const updatedTimeStr = t("schema-designer.message.updated-time-by-user", {
- time: dayjs
- .duration((branch.updateTime ?? new Date()).getTime() - Date.now())
- .humanize(true),
- user: updater?.title,
- });
- return updatedTimeStr;
-};
-</script>
-
-<style lang="postcss" scoped>
-.bb-branch-data-table :deep(.n-data-table-expand-trigger) {
- @apply !w-5 !h-5 inline-flex justify-center items-center translate-y-0.5 rounded hover:bg-white hover:shadow;
-}
-.bb-branch-data-table :deep(.n-data-table-expand-trigger > .n-base-icon) {
- @apply !w-5 !h-5 flex flex-row justify-center items-center;
-}
-.bb-branch-data-table :deep(.n-data-table-td) {
- background-color: transparent !important;
-}
-</style>
diff --git a/frontend/src/components/Branch/BranchDataTable/cells/BranchNameCell.vue b/frontend/src/components/Branch/BranchDataTable/cells/BranchNameCell.vue
new file mode 100644
index 0000000000..8eb5e2f536
--- /dev/null
+++ b/frontend/src/components/Branch/BranchDataTable/cells/BranchNameCell.vue
@@ -0,0 +1,70 @@
+<template>
+ <div class="flex flex-row justify-start items-center gap-1">
+ <span
+ class="cursor-pointer hover:underline hover:text-blue-600"
+ @click.stop="handleBranchClick"
+ >{{ branchName }}</span
+ >
+ <span v-if="isProtected">
+ <NTooltip trigger="hover">
+ <template #trigger>
+ <ShieldAlertIcon class="w-4 h-auto text-gray-500" />
+ </template>
+ {{ $t("branch.branch-is-protected") }}
+ </NTooltip>
+ </span>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import { ShieldAlertIcon } from "lucide-vue-next";
+import { NTooltip } from "naive-ui";
+import { computed } from "vue";
+import { useRouter } from "vue-router";
+import { useProjectV1Store } from "@/store";
+import {
+ getProjectAndBranchId,
+ projectNamePrefix,
+} from "@/store/modules/v1/common";
+import { useProjectBranchProtectionRules } from "@/store/modules/v1/projectProtectionRoles";
+import { Branch } from "@/types/proto/v1/branch_service";
+import { projectV1Slug } from "@/utils";
+import { wildcardToRegex } from "../../utils";
+
+const props = defineProps<{
+ branch: Branch;
+}>();
+
+const router = useRouter();
+const projectStore = useProjectV1Store();
+
+const project = computed(() => {
+ const [projectId] = getProjectAndBranchId(props.branch.name);
+ return projectStore.getProjectByName(`${projectNamePrefix}${projectId}`);
+});
+
+const branchProtectionRules = useProjectBranchProtectionRules(
+ project.value.name
+);
+
+const branchName = computed(() => {
+ return props.branch.branchId;
+});
+
+const isProtected = computed(() => {
+ return branchProtectionRules.value.some((rule) => {
+ return wildcardToRegex(rule.nameFilter).test(props.branch.branchId);
+ });
+});
+
+const handleBranchClick = async () => {
+ const [_, branchId] = getProjectAndBranchId(props.branch.name);
+ router.push({
+ name: "workspace.project.branch.detail",
+ params: {
+ projectSlug: projectV1Slug(project.value),
+ branchName: `${branchId}`,
+ },
+ });
+};
+</script>
diff --git a/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue b/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue
new file mode 100644
index 0000000000..e40fb725a7
--- /dev/null
+++ b/frontend/src/components/Branch/BranchDataTable/cells/BranchUpdatedCell.vue
@@ -0,0 +1,37 @@
+<template>
+ <div class="flex flex-row justify-start items-center gap-1">
+ <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"
+ >
+ <UserAvatar size="TINY" :user="updater" />
+ <span>{{ updater.title }}</span>
+ </div>
+ <span>{{ updateTimeStr }}</span>
+ </div>
+</template>
+
+<script lang="ts" setup>
+import dayjs from "dayjs";
+import { computed } from "vue";
+import { useUserStore } from "@/store";
+import { getUserEmailFromIdentifier } from "@/store/modules/v1/common";
+import { User } from "@/types/proto/v1/auth_service";
+import { Branch } from "@/types/proto/v1/branch_service";
+
+const props = defineProps<{
+ branch: Branch;
+}>();
+
+const userStore = useUserStore();
+
+const updater = computed(() => {
+ const email = getUserEmailFromIdentifier(props.branch.updater);
+ return userStore.getUserByEmail(email) as User;
+});
+
+const updateTimeStr = computed(() => {
+ return dayjs
+ .duration((props.branch.updateTime ?? new Date()).getTime() - Date.now())
+ .humanize(true);
+});
+</script>
diff --git a/frontend/src/components/Branch/BranchDataTable/index.vue b/frontend/src/components/Branch/BranchDataTable/index.vue
new file mode 100644
index 0000000000..2110213575
--- /dev/null
+++ b/frontend/src/components/Branch/BranchDataTable/index.vue
@@ -0,0 +1,91 @@
+<template>
+ <NDataTable
+ v-bind="$attrs"
+ :loading="!ready"
+ :columns="columns"
+ :data="branches"
+ :row-key="rowKey"
+ :pagination="pagination"
+ :paginate-single-page="false"
+ />
+</template>
+
+<script lang="ts" setup>
+import { NDataTable, DataTableColumn, PaginationProps } from "naive-ui";
+import { computed, h, ref } from "vue";
+import { useI18n } from "vue-i18n";
+import BranchBaseline from "@/components/Branch/BranchBaseline.vue";
+import { useBranchStore } from "@/store";
+import { Branch } from "@/types/proto/v1/branch_service";
+import BranchNameCell from "./cells/BranchNameCell.vue";
+import BranchUpdatedCell from "./cells/BranchUpdatedCell.vue";
+
+const props = defineProps<{
+ branches: Branch[];
+ ready?: boolean;
+ showParentBranchColumn?: boolean;
+}>();
+
+const { t } = useI18n();
+const branchStore = useBranchStore();
+
+const pagination = ref<PaginationProps>({
+ pageSize: 5,
+});
+
+const columns = computed(() => {
+ const columns: (DataTableColumn<Branch> & { hide?: boolean })[] = [
+ {
+ title: t("common.branch"),
+ key: "branchName",
+ render: (row: Branch) => {
+ return h(BranchNameCell, {
+ branch: row,
+ });
+ },
+ },
+ {
+ title: t("schema-designer.parent-branch"),
+ key: "branchName",
+ width: 256,
+ hide: !props.showParentBranchColumn,
+ render: (row: Branch) => {
+ const parentBranch = branchStore.getBranchByName(row.parentBranch);
+ if (!parentBranch) {
+ return "";
+ }
+ return h(BranchNameCell, {
+ branch: parentBranch,
+ });
+ },
+ },
+ {
+ title: t("schema-designer.baseline-version"),
+ key: "baselineVersion",
+ width: 256,
+ render: (row: Branch) => {
+ return h(BranchBaseline, {
+ branch: row,
+ showInstanceIcon: true,
+ });
+ },
+ },
+ {
+ title: t("common.updated"),
+ key: "updated",
+ width: 256,
+ render: (row: Branch) => {
+ return h(BranchUpdatedCell, {
+ branch: row,
+ });
+ },
+ },
+ ];
+
+ return columns.filter((column) => !column.hide);
+});
+
+const rowKey = (row: Branch) => {
+ return row.name;
+};
+</script>
diff --git a/frontend/src/components/ProjectBranchesPanel.vue b/frontend/src/components/ProjectBranchesPanel.vue
index a900cfd34f..6e071d4ee0 100644
--- a/frontend/src/components/ProjectBranchesPanel.vue
+++ b/frontend/src/components/ProjectBranchesPanel.vue
@@ -1,5 +1,5 @@
<template>
- <div class="space-y-4 w-full overflow-x-auto">
+ <div class="space-y-6 w-full overflow-x-auto">
<div class="flex flex-row justify-end items-center gap-x-2 pt-0.5">
<SearchBox
v-model:value="state.searchKeyword"
@@ -7,30 +7,44 @@
:placeholder="$t('common.filter-by-name')"
/>
<NButton type="primary" @click="handleCreateBranch">
- <heroicons-solid:plus class="w-4 h-auto mr-0.5" />
+ <PlusIcon class="w-4 h-auto mr-0.5" />
<span>{{ $t("database.new-branch") }}</span>
</NButton>
</div>
-
- <BranchDataTable
- class="border"
- :branches="filteredBranches"
- :ready="ready"
- @click="handleBranchClick"
- />
+ <div class="w-full space-y-2">
+ <p class="textlabel">{{ $t("branch.default-branches") }}</p>
+ <BranchDataTable :branches="defaultBranches" :ready="ready" />
+ </div>
+ <div class="w-full space-y-2">
+ <p class="textlabel">{{ $t("branch.your-branches") }}</p>
+ <BranchDataTable
+ :branches="currentUserBranches"
+ :ready="ready"
+ :show-parent-branch-column="true"
+ />
+ </div>
+ <div class="w-full space-y-2">
+ <p class="textlabel">{{ $t("branch.active-branches") }}</p>
+ <BranchDataTable
+ :branches="activeBranches"
+ :ready="ready"
+ :show-parent-branch-column="true"
+ />
+ </div>
</div>
</template>
<script lang="ts" setup>
import { orderBy } from "lodash-es";
+import { PlusIcon } from "lucide-vue-next";
import { NButton } from "naive-ui";
import { computed, reactive } from "vue";
import { useRouter } from "vue-router";
-import BranchDataTable from "@/components/Branch/BranchDataTable.vue";
+import BranchDataTable from "@/components/Branch/BranchDataTable/index.vue";
+import { useCurrentUserV1 } from "@/store";
import { useBranchListByProject } from "@/store/modules/branch";
-import { getProjectAndBranchId } from "@/store/modules/v1/common";
+import { userNamePrefix } from "@/store/modules/v1/common";
import { ComposedProject } from "@/types";
-import { Branch } from "@/types/proto/v1/branch_service";
import { projectV1Slug } from "@/utils";
const props = defineProps<{
@@ -41,7 +55,12 @@ interface LocalState {
searchKeyword: string;
}
+// BRANCH_DEFAULT_ACTIVE_DURATION is the duration that a branch is considered as active.
+// Currently, it is set to 2 months.
+const BRANCH_DEFAULT_ACTIVE_DURATION = 1000 * 60 * 60 * 24 * 30 * 2;
+
const router = useRouter();
+const currentUser = useCurrentUserV1();
const { branchList, ready } = useBranchListByProject(
computed(() => props.project.name)
);
@@ -57,23 +76,38 @@ const filteredBranches = computed(() => {
});
});
-const handleCreateBranch = () => {
- router.push({
- name: "workspace.project.branch.detail",
- params: {
- projectSlug: projectV1Slug(props.project),
- branchName: "new",
- },
+// defaultBranches are those branches that are parent branches.
+const defaultBranches = computed(() => {
+ return filteredBranches.value.filter((branch) => {
+ return branch.parentBranch === "";
});
-};
+});
+
+// currentUserBranches are those branches that are created by the current user and are not parent branches.
+const currentUserBranches = computed(() => {
+ return filteredBranches.value.filter((branch) => {
+ return (
+ branch.parentBranch !== "" &&
+ branch.creator === `${userNamePrefix}${currentUser.value.email}`
+ );
+ });
+});
+
+// activeBranches are those branches that are active in the last 2 months.
+const activeBranches = computed(() => {
+ return filteredBranches.value.filter((branch) => {
+ return (
+ branch.updateTime!.getTime() > Date.now() - BRANCH_DEFAULT_ACTIVE_DURATION
+ );
+ });
+});
-const handleBranchClick = async (branch: Branch) => {
- const [_, branchId] = getProjectAndBranchId(branch.name);
+const handleCreateBranch = () => {
router.push({
name: "workspace.project.branch.detail",
params: {
projectSlug: projectV1Slug(props.project),
- branchName: `${branchId}`,
+ branchName: "new",
},
});
};
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 378163cf67..38828fba83 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -3356,6 +3356,10 @@
"rollout": {
"select-target-database": "Select target database"
},
- "select-tables-to-rollout": "Select tables to rollout"
+ "select-tables-to-rollout": "Select tables to rollout",
+ "branch-is-protected": "This branch is protected by branch protection rules.",
+ "default-branches": "Default",
+ "your-branches": "Your branches",
+ "active-branches": "Active branches"
}
}
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index 09b29b1e86..aa6b117432 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -3354,6 +3354,10 @@
"rollout": {
"select-target-database": "Seleccionar base de datos de destino"
},
- "select-tables-to-rollout": "Seleccionar tablas para implementar"
+ "select-tables-to-rollout": "Seleccionar tablas para implementar",
+ "branch-is-protected": "La rama está protegida",
+ "default-branches": "Ramas por defecto",
+ "your-branches": "Tus ramas",
+ "active-branches": "Ramas activas"
}
}
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 73c185face..b12e323617 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -3349,6 +3349,10 @@
"rollout": {
"select-target-database": "选择目标数据库"
},
- "select-tables-to-rollout": "选择要发布的表"
+ "select-tables-to-rollout": "选择要发布的表",
+ "branch-is-protected": "该分支已被保护",
+ "default-branches": "默认分支",
+ "your-branches": "你的分支",
+ "active-branches": "活跃的分支"
}
}
diff --git a/frontend/src/store/modules/branch.ts b/frontend/src/store/modules/branch.ts
index f4f0fc93cc..63a10121d5 100644
--- a/frontend/src/store/modules/branch.ts
+++ b/frontend/src/store/modules/branch.ts
@@ -18,6 +18,9 @@ export const useBranchStore = defineStore("schema_design", () => {
parent: projectName,
view: BranchView.BRANCH_VIEW_BASIC,
});
+ for (const branch of branches) {
+ branchMapByName.set(branch.name, branch);
+ }
return branches;
};
@@ -31,7 +34,6 @@ export const useBranchStore = defineStore("schema_design", () => {
branchId: branchId,
branch,
});
- // console.debug("got schema", createdBranch.schema);
branchMapByName.set(createdBranch.name, createdBranch);
return createdBranch;
};