Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: initial the branding in frontend (#927)
ecmadao4ddd314d19da
diff --git a/frontend/src/components/EnvironmentForm.vue b/frontend/src/components/EnvironmentForm.vueindex 190154a4e0..0dc95e7f1f 100644--- a/frontend/src/components/EnvironmentForm.vue+++ b/frontend/src/components/EnvironmentForm.vue@@ -49,7 +49,7 @@<div class="-mt-0.5"><div class="textlabel flex">{{ $t("policy.approval.auto") }}- <FeatureBadge feature="bb.feature.approval-policy" />+ <FeatureBadge feature="bb.feature.approval-policy" class="text-accent" /></div><div class="mt-1 textinfolabel">{{ $t("policy.approval.auto-info") }}@@ -91,7 +91,7 @@<div class="-mt-0.5"><div class="textlabel flex">{{ $t("policy.backup.daily") }}- <FeatureBadge feature="bb.feature.backup-policy" />+ <FeatureBadge feature="bb.feature.backup-policy" class="text-accent" /></div><div class="mt-1 textinfolabel">{{ $t("policy.backup.daily-info") }}@@ -110,7 +110,7 @@<div class="-mt-0.5"><div class="textlabel flex">{{ $t("policy.backup.weekly") }}- <FeatureBadge feature="bb.feature.backup-policy" />+ <FeatureBadge feature="bb.feature.backup-policy" class="text-accent" /></div><div class="mt-1 textinfolabel">{{ $t("policy.backup.weekly-info") }}diff --git a/frontend/src/components/FeatureBadge.vue b/frontend/src/components/FeatureBadge.vueindex 247a0fd546..75fb506a22 100644--- a/frontend/src/components/FeatureBadge.vue+++ b/frontend/src/components/FeatureBadge.vue@@ -1,6 +1,6 @@<template><router-link v-if="!hasFeature" to="/setting/subscription" exact-active-class>- <heroicons-solid:sparkles class="w-5 h-5 text-accent" />+ <heroicons-solid:sparkles class="w-5 h-5"/></router-link></template>diff --git a/frontend/src/components/FeatureModal.vue b/frontend/src/components/FeatureModal.vueindex 402dd8f240..2d4f86fd1f 100644--- a/frontend/src/components/FeatureModal.vue+++ b/frontend/src/components/FeatureModal.vue@@ -3,7 +3,7 @@:title="$t('subscription.disabled-feature')"@close="$emit('cancel')">- <div>+ <div class="min-w-0 md:min-w-400"><div class="flex items-start space-x-2"><div class="flex items-center"><!-- Heroicons name: outline/exclamation -->@@ -76,3 +76,11 @@ export default {},};</script>++<style scoped>+@media (min-width: 768px) {+ .md\:min-w-400 {+ min-width: 400px;+ }+}+</style>\ No newline at end of filediff --git a/frontend/src/components/SingleFileSelector.vue b/frontend/src/components/SingleFileSelector.vuenew file mode 100644index 0000000000..69fc3bedb5--- /dev/null+++ b/frontend/src/components/SingleFileSelector.vue@@ -0,0 +1,110 @@+<template>+ <div+ class="cursor-pointer transition-all hover:bg-gray-100"+ :class="[state.dropAreaActive ? 'bg-gray-300 opacity-100' : '']"+ @click="onUploaderClick"+ @drop="onFileDrop"+ @dragover.prevent+ @dragenter="state.dropAreaActive = true"+ @dragleave="state.dropAreaActive = false"+ >+ <input+ ref="uploader"+ name="uploader"+ type="file"+ :accept="supportFileExtensions.join(',')"+ class="sr-only hidden"+ @input="onFileChange"+ />+ <slot></slot>+ </div>+</template>+++<script lang="ts" setup>+import { ref, reactive, PropType } from "vue";+import { useStore } from "vuex";+import { useI18n } from "vue-i18n";++interface LocalState {+ dropAreaActive: boolean;+}++const props = defineProps({+ maxFileSizeInMiB: {+ required: true,+ type: Number,+ },+ supportFileExtensions: {+ required: true,+ type: Object as PropType<string[]>,+ },+});++const emit = defineEmits(["on-select"]);++const store = useStore();+const { t } = useI18n();++const state = reactive<LocalState>({+ dropAreaActive: false,+});++const uploader = ref<HTMLInputElement | null>(null);++const onUploaderClick = () => {+ uploader.value?.click();+}++const onFileChange = () => {+ const files: File[] = (uploader.value as any).files;+ selectFile(files);+};++const onFileDrop = (e: any) => {+ e.preventDefault();++ state.dropAreaActive = false;+ const files: File[] = e.dataTransfer.files;+ selectFile(files);+};++const selectFile = (files: File[]) => {+ if (!files.length) {+ return;+ }++ const file = files[0];+ if (!validFile(file)) {+ return;+ }+ emit("on-select", file);+};++const validFile = (file: File): boolean => {+ const extension = file.name.toLowerCase().split(".").slice(-1)[0];+ if (!props.supportFileExtensions.includes(`.${extension}`)) {+ store.dispatch("notification/pushNotification", {+ module: "bytebase",+ style: "CRITICAL",+ title: t("common.file-selector.type-limit", {+ extension: props.supportFileExtensions.join(", "),+ }),+ });+ return false;+ }++ if (file.size > props.maxFileSizeInMiB * 1024 * 1024) {+ store.dispatch("notification/pushNotification", {+ module: "bytebase",+ style: "CRITICAL",+ title: t("common.file-selector.size-limit", {+ size: props.maxFileSizeInMiB,+ })+ });+ return false;+ }++ return true;+};+</script>diff --git a/frontend/src/locales/en.yml b/frontend/src/locales/en.ymlindex 0842d3510c..dbef3f29f2 100644--- a/frontend/src/locales/en.yml+++ b/frontend/src/locales/en.yml@@ -177,6 +177,9 @@ common:warning: Warningedited: editedpreview: Preview+ file-selector:+ type-limit: Only support {extension} file+ size-limit: File size should less than {size} MiBerror-page:go-back-home: Go back homeanomaly-center: Anomaly Center@@ -311,6 +314,15 @@ settings:content: >-You are about to restore the following members. All existing memberssynced from VCS will be removed.+ general:+ workspace:+ branding: Branding+ only-owner-can-edit: Only workspace owner can update the branding.+ logo: Logo+ logo-aspect: The suggested logo size should be in 5:2 aspect ratio (e.g 100 x 40).+ select-logo: Upload a file+ drag-logo: or drag here+ logo-upload-tip: "{extension} up to {size} MiB"activity:name: Namecomment: Comment@@ -1287,6 +1299,9 @@ subscription:Bytebase supports 3rd-party authentication & authorization based on your VCS configuration.@:{'subscription.upgrade'} to unlock this feature.login: "@:{'subscription.upgrade'} to unlock this feature"+ bb-feature-branding:+ title: Branding+ desc: Customize the logo.feature-sections:database-management:title: Database Developmentdiff --git a/frontend/src/locales/zh-CN.yml b/frontend/src/locales/zh-CN.ymlindex e4377a6cd8..6a6e55ac5a 100644--- a/frontend/src/locales/zh-CN.yml+++ b/frontend/src/locales/zh-CN.yml@@ -177,6 +177,9 @@ common:warning: 警告edited: 编辑于preview: 预览+ file-selector:+ type-limit: 仅支持 {extension} 类型的文件+ size-limit: 文件大小需小于 {size} MiBerror-page:go-back-home: 回到主页anomaly-center: 异常中心@@ -300,6 +303,15 @@ settings:emphasize: 请注意,该功能需要 VCS 仓库内所有成员均设置了公开邮箱。change-role-provider-to-bytebase:content: 将会恢复成以下成员的权限。所有由 VCS 提供的成员将会被移除。+ general:+ workspace:+ branding: 品牌+ only-owner-can-edit: 仅管理员可以更新品牌信息+ logo: Logo+ logo-aspect: Logo 建议为 5:2 的宽:高比例(例如 100 x 40 像素)+ select-logo: 选择+ drag-logo: 或拖拽文件+ logo-upload-tip: 支持 {extension} 类型文件,不能大于 {size} MiBactivity:name: 名称comment: 评论@@ -1126,6 +1138,9 @@ subscription:desc: >-Bytebase 可根据您配置的 VCS 来支持相应的第三方认证 & 授权。请通过@:{'subscription.upgrade'}来开启该功能。login: 请@:{'subscription.upgrade'}来开启该功能+ bb-feature-branding:+ title: 自定义品牌信息+ desc: 定制 Logofeature-sections:database-management:title: 数据库管理diff --git a/frontend/src/types/plan.ts b/frontend/src/types/plan.tsindex 1032c21a62..e852b611b5 100644--- a/frontend/src/types/plan.ts+++ b/frontend/src/types/plan.ts@@ -12,7 +12,9 @@ export type FeatureType =| "bb.feature.backup-policy"// Admin & Security| "bb.feature.rbac"- | "bb.feature.3rd-party-auth";+ | "bb.feature.3rd-party-auth"+ // Branding+ | "bb.feature.branding";export enum PlanType {FREE = 0,@@ -56,6 +58,8 @@ export const FEATURE_MATRIX: Map<FeatureType, boolean[]> = new Map([// Admin & Security["bb.feature.rbac", [false, true, true]],["bb.feature.3rd-party-auth", [false, true, true]],+ // Branding+ ["bb.feature.branding", [false, true, true]],]);export const FEATURE_SECTIONS = [diff --git a/frontend/src/views/SettingSidebar.vue b/frontend/src/views/SettingSidebar.vueindex 4c939ab588..5e8d818811 100644--- a/frontend/src/views/SettingSidebar.vue+++ b/frontend/src/views/SettingSidebar.vue@@ -35,12 +35,13 @@{{ $t("settings.sidebar.workspace") }}</div><div class="space-y-1">- <!-- <router-link+ <router-link+ v-if="isDev()"to="/setting/general"class="outline-item group w-full flex items-center pl-11 pr-2 py-2">{{ $t("settings.sidebar.general") }}- </router-link>-->+ </router-link><!-- <router-linkto="/setting/agent"class="outline-item group w-full flex items-center pl-11 pr-2 py-2"diff --git a/frontend/src/views/SettingWorkspaceGeneral.vue b/frontend/src/views/SettingWorkspaceGeneral.vueindex bf8b2bf5e3..8915f4717e 100644--- a/frontend/src/views/SettingWorkspaceGeneral.vue+++ b/frontend/src/views/SettingWorkspaceGeneral.vue@@ -1,56 +1,175 @@<template><div class="mt-2 space-y-6 divide-y divide-block-border">- <div v-if="allowEdit" class="pt-5 flex justify-end">- <button- type="button"- class="btn-primary"- :disabled="!allowSave"- @click.prevent="doSave"- >- {{ $t("common.update") }}- </button>+ <div class="px-4 py-6 lg:flex">+ <div class="text-left lg:w-1/4">+ <h1 class="text-2xl font-bold">+ {{ $t("settings.general.workspace.branding") }}+ </h1>+ <span v-if="!allowEdit" class="text-sm text-gray-400">+ {{ $t("settings.general.workspace.only-owner-can-edit") }}+ </span>+ </div>+ <div class="flex-1 lg:px-5">+ <div class="mb-5 mt-5 lg:mt-0">+ <p>+ {{ $t("settings.general.workspace.logo") }}+ </p>+ <p class="mb-3 text-sm text-gray-400">+ {{ $t("settings.general.workspace.logo-aspect") }}+ </p>+ <div+ class="flex justify-center border-2 border-gray-300 border-dashed rounded-md relative h-48"+ >+ <div+ class="w-full bg-no-repeat bg-contain bg-center rounded-md pointer-events-none m-5"+ :style="`background-image: url(${state.logoUrl});`"+ ></div>+ <SingleFileSelector+ class="space-y-1 text-center flex flex-col justify-center items-center absolute top-0 bottom-0 left-0 right-0"+ :class="[state.logoUrl ? 'opacity-0 hover:opacity-90' : '']"+ :max-file-size-in-mi-b="maxFileSizeInMiB"+ :support-file-extensions="supportImageExtensions"+ @on-select="onLogoSelect"+ >+ <svg+ class="mx-auto h-12 w-12 text-gray-400 pointer-events-none"+ stroke="currentColor"+ fill="none"+ viewBox="0 0 48 48"+ aria-hidden="true"+ >+ <path+ d="M28 8H12a4 4 0 00-4 4v20m32-12v8m0 0v8a4 4 0 01-4 4H12a4 4 0 01-4-4v-4m32-4l-3.172-3.172a4 4 0 00-5.656 0L28 28M8 32l9.172-9.172a4 4 0 015.656 0L28 28m0 0l4 4m4-24h8m-4-4v8m-12 4h.02"+ stroke-width="2"+ stroke-linecap="round"+ stroke-linejoin="round"+ />+ </svg>+ <div class="text-sm text-gray-600 inline-flex pointer-events-none">+ <span+ class="relative cursor-pointer rounded-md font-medium text-indigo-600 hover:text-indigo-500 focus-within:outline-none focus-within:ring-2 focus-within:ring-offset-2 focus-within:ring-indigo-500"+ >+ {{ $t("settings.general.workspace.select-logo") }}+ </span>+ <p class="pl-1">+ {{ $t("settings.general.workspace.drag-logo") }}+ </p>+ </div>+ <p class="text-xs text-gray-500 pointer-events-none">+ {{+ $t("settings.general.workspace.logo-upload-tip", {+ extension: supportImageExtensions.join(", "),+ size: maxFileSizeInMiB+ })+ }}+ </p>+ </SingleFileSelector>+ </div>+ </div>+ <div class="flex">+ <button+ type="button"+ class="btn-primary ml-auto"+ :disabled="!allowSave"+ @click.prevent="uploadLogo"+ >+ <FeatureBadge feature="bb.feature.branding" class="text-white pointer-events-none" />+ {{ $t("common.update") }}+ </button>+ </div>+ </div></div></div>+ <FeatureModal+ v-if="state.showFeatureModal"+ feature="bb.feature.branding"+ @cancel="state.showFeatureModal = false"+ /></template>-<script lang="ts">-import { computed, defineComponent, reactive } from "vue";+<script lang="ts" setup>+import { computed, reactive } from "vue";import { useStore } from "vuex";import { isOwner } from "../utils";-// eslint-disable-next-line @typescript-eslint/no-empty-interface-interface LocalState {}+interface LocalState {+ displayName?: string;+ logoUrl?: string;+ logoFile: File | null;+ loading: boolean;+ showFeatureModal: boolean;+}-export default defineComponent({- name: "SettingWorkspaceGeneral",- setup() {- const store = useStore();+const maxFileSizeInMiB = 2;- const state = reactive<LocalState>({});+// getImageUrlFromBase64String will convert the image base64 string to the HTML image url.+const getImageUrlFromBase64String = (+ base64String: string | undefined+): string => {+ if (!base64String) return "";- const currentUser = computed(() => store.getters["auth/currentUser"]());+ const decodedData = window.atob(base64String);+ const uInt8Array = new Uint8Array(decodedData.length);- const allowEdit = computed((): boolean => {- return isOwner(currentUser.value.role);- });+ // Insert all character code into uInt8Array+ for (let i = 0; i < decodedData.length; ++i) {+ uInt8Array[i] = decodedData.charCodeAt(i);+ }- const allowSave = computed((): boolean => {- return false;- });+ const blob = new Blob([uInt8Array]);+ return URL.createObjectURL(blob);+};- const doSave = () => {- // do nothing- };+const store = useStore();- return {- state,- allowEdit,- allowSave,- doSave,- };- },- data() {- return { placeholder: "{{ DB_NAME_PLACEHOLDER }}" };- },+const state = reactive<LocalState>({+ displayName: "",+ logoUrl: "",+ logoFile: null,+ loading: false,+ showFeatureModal: false,});++const currentUser = computed(() => store.getters["auth/currentUser"]());++const allowEdit = computed((): boolean => {+ return isOwner(currentUser.value.role);+});++const valid = computed((): boolean => {+ return !!state.displayName || !!state.logoFile+});++const changed = computed((): boolean => {+ return false;+});++const allowSave = computed((): boolean => {+ return allowEdit.value && changed.value && valid.value;+});++const hasBrandingFeature = computed((): boolean => {+ return store.getters["subscription/feature"]("bb.feature.branding");+});++const uploadLogo = () => {+ if (!hasBrandingFeature.value) {+ state.showFeatureModal = true;+ return;+ }+ // TODO: upload logo+};++const onLogoSelect = (file: File) => {+ state.logoFile = file;+ state.logoUrl = URL.createObjectURL(file);+};++const supportImageExtensions = [+ ".jpg",+ ".jpeg",+ ".png",+ ".webp",+ ".svg",+];</script>