Skip to content

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

chore: avatar component updates (#7823)

Liu Ji60282bd3925a
diff --git a/frontend/package.json b/frontend/package.json
index b441db442a..4d0eea81ae 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -38,6 +38,7 @@
"highlight.js": "11.6.0",
"html-to-image": "^1.11.4",
"inter-ui": "3.19.3",
+ "is-chinese": "^2.0.0",
"js-base64": "^3.7.5",
"js-yaml": "4.1.0",
"jszip": "^3.10.1",
diff --git a/frontend/pnpm-lock.yaml b/frontend/pnpm-lock.yaml
index d3e587d19a..c3b010910b 100644
--- a/frontend/pnpm-lock.yaml
+++ b/frontend/pnpm-lock.yaml
@@ -77,6 +77,9 @@ dependencies:
inter-ui:
specifier: 3.19.3
version: 3.19.3
+ is-chinese:
+ specifier: ^2.0.0
+ version: 2.0.0
js-base64:
specifier: ^3.7.5
version: 3.7.5
@@ -3563,6 +3566,10 @@ packages:
dependencies:
binary-extensions: 2.2.0
+ resolution: {integrity: sha512-1BTwHrs0wHnNZTyMWM8MPpVEs8u4uvLnUA2QZGt6cFjqY82DZV3lKH6hBGHqu8eJxkAIYcelm1kBR8v8URS4yA==}
+ dev: false
+
resolution: {integrity: sha512-RRjxlvLDkD1YJwDbroBHMb+cukurkDWNyHx7D3oNB5x9rb5ogcksMC5wHCadcXoo67gVr/+3GFySh3134zi6rw==}
dependencies:
diff --git a/frontend/src/bbkit/BBAvatar.vue b/frontend/src/bbkit/BBAvatar.vue
index ac8490aaea..27cc8821b7 100644
--- a/frontend/src/bbkit/BBAvatar.vue
+++ b/frontend/src/bbkit/BBAvatar.vue
@@ -12,11 +12,15 @@
</template>
<script lang="ts" setup>
+import isChinese from "is-chinese";
import { computed, withDefaults } from "vue";
+import { SYSTEM_BOT_EMAIL } from "@/types";
import { VueClass } from "@/utils";
import { hashCode } from "./BBUtil";
import { BBAvatarSizeType } from "./types";
+const DEFAULT_BRANDING_COLOR = "#4f46e5";
+
const BACKGROUND_COLOR_LIST: string[] = [
"#64748B",
"#EF4444",
@@ -55,6 +59,7 @@ const fontStyleClassMap: Map<BBAvatarSizeType, string> = new Map([
const props = withDefaults(
defineProps<{
username?: string;
+ email?: string;
size: BBAvatarSizeType;
rounded?: boolean;
backgroundColor?: string;
@@ -63,6 +68,7 @@ const props = withDefaults(
}>(),
{
username: "",
+ email: "",
size: "NORMAL",
rounded: true,
backgroundColor: "",
@@ -76,6 +82,35 @@ const initials = computed(() => {
return "?";
}
+ if (props.email === SYSTEM_BOT_EMAIL) {
+ return "BB";
+ }
+
+ // Priority
+ // 1. First Chinese character
+ // 2. At most the first 2 letters in email
+ // Fallback if email is invalid
+ // 1. The first and the last initial letter in title
+ // 2. The first initial letter in title
+
+ const chars = props.username.split("");
+ for (let i = 0; i < chars.length; i++) {
+ const ch = chars[i];
+ if (isChinese(ch)) {
+ return ch;
+ }
+ }
+
+ if (props.email) {
+ const nameInEmail = props.email.split("@")[0] ?? "";
+ if (nameInEmail.length >= 2) {
+ return nameInEmail.substring(0, 2).toUpperCase();
+ }
+ if (nameInEmail.length === 1) {
+ return nameInEmail.charAt(0).toUpperCase();
+ }
+ }
+
const parts = props.username.split(/[ -]/);
let initials = "";
for (let i = 0; i < parts.length; i++) {
@@ -96,6 +131,13 @@ const initials = computed(() => {
});
const backgroundColor = computed(() => {
+ if (props.email === SYSTEM_BOT_EMAIL) {
+ return (
+ getComputedStyle(document.documentElement)
+ .getPropertyValue("--color-accent")
+ .trim() || DEFAULT_BRANDING_COLOR
+ );
+ }
return (
props.backgroundColor ||
BACKGROUND_COLOR_LIST[
diff --git a/frontend/src/components/ActivityTable/ActivityTable.vue b/frontend/src/components/ActivityTable/ActivityTable.vue
index 8a35a7ae30..7b0120a20d 100644
--- a/frontend/src/components/ActivityTable/ActivityTable.vue
+++ b/frontend/src/components/ActivityTable/ActivityTable.vue
@@ -38,7 +38,11 @@
</BBTableCell>
<BBTableCell class="w-[12%]">
<div class="flex flex-row items-center">
- <BBAvatar :size="'SMALL'" :username="getUser(activity)?.title" />
+ <BBAvatar
+ :size="'SMALL'"
+ :username="getUser(activity)?.title"
+ :email="getUser(activity)?.email"
+ />
<span class="ml-2">{{ getUser(activity)?.title }}</span>
</div>
</BBTableCell>
diff --git a/frontend/src/components/Issue/review/CurrentApprover.vue b/frontend/src/components/Issue/review/CurrentApprover.vue
index bee64bd89d..0f7116ec96 100644
--- a/frontend/src/components/Issue/review/CurrentApprover.vue
+++ b/frontend/src/components/Issue/review/CurrentApprover.vue
@@ -7,7 +7,11 @@
<BBSpin />
</template>
<template v-else-if="currentApprover">
- <BBAvatar :size="'SMALL'" :username="currentApprover.title" />
+ <BBAvatar
+ :size="'SMALL'"
+ :username="currentApprover.title"
+ :email="currentApprover.email"
+ />
<span class="ml-2">
{{ currentApprover.title }}
</span>
diff --git a/frontend/src/components/Issue/table/IssueTable.vue b/frontend/src/components/Issue/table/IssueTable.vue
index 7ca5a17ed8..ece9e05e10 100644
--- a/frontend/src/components/Issue/table/IssueTable.vue
+++ b/frontend/src/components/Issue/table/IssueTable.vue
@@ -119,6 +119,7 @@
:username="
issue.assignee ? issue.assignee.name : $t('common.unassigned')
"
+ :email="issue.assignee?.email"
/>
<span class="ml-2">
{{ issue.assignee ? issue.assignee.name : $t("common.unassigned") }}
@@ -127,7 +128,11 @@
</BBTableCell>
<BBTableCell class="hidden sm:table-cell w-36">
<div class="flex flex-row items-center">
- <BBAvatar :size="'SMALL'" :username="issue.creator.name" />
+ <BBAvatar
+ :size="'SMALL'"
+ :username="issue.creator.name"
+ :email="issue.creator.email"
+ />
<span class="ml-2">
{{ issue.creator.name }}
</span>
diff --git a/frontend/src/components/PrincipalAvatar.vue b/frontend/src/components/PrincipalAvatar.vue
index b5e651878b..aed711737d 100644
--- a/frontend/src/components/PrincipalAvatar.vue
+++ b/frontend/src/components/PrincipalAvatar.vue
@@ -1,6 +1,7 @@
<template>
<BBAvatar
:username="name"
+ :email="email"
:size="size"
:override-class="overrideClass"
:override-text-size="overrideTextSize"
@@ -46,7 +47,13 @@ export default defineComponent({
}
return props.principal.name;
});
- return { name };
+ const email = computed((): string => {
+ if (props.principal.id === UNKNOWN_ID) {
+ return "";
+ }
+ return props.principal.email;
+ });
+ return { name, email };
},
});
</script>
diff --git a/frontend/src/components/User/UserAvatar.vue b/frontend/src/components/User/UserAvatar.vue
index b9cb39149f..00db719992 100644
--- a/frontend/src/components/User/UserAvatar.vue
+++ b/frontend/src/components/User/UserAvatar.vue
@@ -1,6 +1,7 @@
<template>
<BBAvatar
:username="username"
+ :email="email"
:size="size"
:override-class="overrideClass"
:override-text-size="overrideTextSize"
@@ -40,4 +41,10 @@ const username = computed((): string => {
}
return props.user.title;
});
+const email = computed(() => {
+ if (props.user.name === `users/${UNKNOWN_ID}`) {
+ return undefined;
+ }
+ return props.user.email;
+});
</script>