🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
💄 style(workspace): draw bauhaus avatars for workspaces without a logo (#21786)
Lobehub Coder22b78eff6175
diff --git a/src/business/client/hooks/useWorkspaceOptionLabel.tsx b/src/business/client/hooks/useWorkspaceOptionLabel.tsxindex 87747273079..5c0f32f828b 100644--- a/src/business/client/hooks/useWorkspaceOptionLabel.tsx+++ b/src/business/client/hooks/useWorkspaceOptionLabel.tsx@@ -1,9 +1,10 @@'use client';-import { DEFAULT_AVATAR } from '@lobechat/const';-import { Avatar, Flexbox, Text } from '@lobehub/ui';+import { Flexbox, Text } from '@lobehub/ui';import { type ReactNode, useCallback } from 'react';+import WorkspaceAvatar from '@/components/WorkspaceAvatar';+import type { WorkspaceListItem } from './useActiveWorkspace';/**@@ -15,7 +16,7 @@ export const useWorkspaceOptionLabel = (): ((workspace: WorkspaceListItem) => ReuseCallback((workspace: WorkspaceListItem) => (<Flexbox horizontal align={'center'} gap={10} style={{ flex: 1, minWidth: 0 }}>- <Avatar avatar={workspace.avatar || DEFAULT_AVATAR} shape={'square'} size={24} />+ <WorkspaceAvatar avatar={workspace.avatar} name={workspace.name} size={24} /><Text ellipsis style={{ flex: '0 1 auto', minWidth: 0 }}>{workspace.name}</Text>diff --git a/src/components/WorkspaceAvatar/index.test.tsx b/src/components/WorkspaceAvatar/index.test.tsxnew file mode 100644index 00000000000..224992e30ee--- /dev/null+++ b/src/components/WorkspaceAvatar/index.test.tsx@@ -0,0 +1,49 @@+/**+ * @vitest-environment happy-dom+ */+import { render, screen } from '@testing-library/react';+import { describe, expect, it } from 'vitest';++import WorkspaceAvatar from './index';++// boring-avatars' bauhaus draws a circle and a line over two rects; the other+// variants never combine both, so this pair identifies the workspace look.+const isBauhaus = (svg: Element) => !!svg.querySelector('circle') && !!svg.querySelector('line');++// Mask ids differ per instance, so compare what is drawn rather than the markup.+const drawing = (svg: Element | null) =>+ [...(svg?.querySelectorAll('rect, circle, line') ?? [])].map((node) =>+ ['fill', 'stroke', 'transform', 'x', 'y', 'cx', 'cy', 'x1', 'x2', 'y1', 'y2']+ .map((attr) => node.getAttribute(attr))+ .join('|'),+ );++describe('WorkspaceAvatar', () => {+ it('draws the bauhaus fallback from the name when there is no logo', () => {+ render(<WorkspaceAvatar name={'Foundry'} size={24} />);++ const fallback = screen.getByRole('img', { name: 'Foundry' });+ expect(fallback.tagName.toLowerCase()).toBe('svg');+ expect(isBauhaus(fallback)).toBe(true);+ });++ it('draws the same mark for the same name', () => {+ const { container: first } = render(<WorkspaceAvatar name={'Foundry'} />);+ const { container: second } = render(<WorkspaceAvatar avatar={''} name={'Foundry'} />);+ const { container: other } = render(<WorkspaceAvatar name={'Lighthouse'} />);++ expect(drawing(first.querySelector('svg'))).toEqual(drawing(second.querySelector('svg')));+ expect(drawing(first.querySelector('svg'))).not.toEqual(drawing(other.querySelector('svg')));+ });++ it('shows the custom logo when the workspace has one', () => {+ const { container } = render(+ <WorkspaceAvatar avatar={'https://example.com/logo.png'} name={'Foundry'} />,+ );++ expect(container.querySelector('img')?.getAttribute('src')).toBe(+ 'https://example.com/logo.png',+ );+ expect(container.querySelector('svg')).toBeNull();+ });+});diff --git a/src/components/WorkspaceAvatar/index.tsx b/src/components/WorkspaceAvatar/index.tsxnew file mode 100644index 00000000000..8fb83106735--- /dev/null+++ b/src/components/WorkspaceAvatar/index.tsx@@ -0,0 +1,35 @@+'use client';++import { memo } from 'react';++import Avatar, { type AvatarProps } from '@/components/Avatar';++export interface WorkspaceAvatarProps extends Omit<AvatarProps, 'avatar' | 'name'> {+ /** The workspace's own logo (image URL or emoji). Empty draws the generated fallback. */+ avatar?: string | null;+ /** Workspace name: seeds the generated fallback and labels the image. */+ name?: string | null;+}++/**+ * An organization's avatar. Without a logo it draws the bauhaus-style avatar+ * `@lobehub/ui` generates from the name, so workspaces read apart from people+ * (pixel) and from agents and projects (gradient), and the same name always+ * draws the same mark.+ */+const WorkspaceAvatar = memo<WorkspaceAvatarProps>(+ ({ avatar, fallbackVariant = 'bauhaus', name, shape = 'square', title, ...rest }) => (+ <Avatar+ {...rest}+ avatar={avatar || undefined}+ fallbackVariant={fallbackVariant}+ name={name || undefined}+ shape={shape}+ title={title ?? (name || undefined)}+ />+ ),+);++WorkspaceAvatar.displayName = 'WorkspaceAvatar';++export default WorkspaceAvatar;diff --git a/src/features/Acceptance/Workspace/AcceptanceScopeSwitcher.tsx b/src/features/Acceptance/Workspace/AcceptanceScopeSwitcher.tsxindex 55c4477a43e..6dca48f0e31 100644--- a/src/features/Acceptance/Workspace/AcceptanceScopeSwitcher.tsx+++ b/src/features/Acceptance/Workspace/AcceptanceScopeSwitcher.tsx@@ -1,8 +1,7 @@'use client';-import { DEFAULT_AVATAR } from '@lobechat/const';import type { DropdownItem } from '@lobehub/ui';-import { Avatar, Button, DropdownMenu, Icon } from '@lobehub/ui';+import { Button, DropdownMenu, Icon } from '@lobehub/ui';import { Check, ChevronsUpDown } from 'lucide-react';import { memo, useMemo } from 'react';import { useTranslation } from 'react-i18next';@@ -10,6 +9,7 @@ import { useNavigate } from 'react-router';import { useActiveWorkspace } from '@/business/client/hooks/useActiveWorkspace';import { useWorkspaces } from '@/business/client/hooks/useWorkspaces';+import WorkspaceAvatar from '@/components/WorkspaceAvatar';import { acceptanceListPath } from '../Viewer/routes';@@ -37,7 +37,7 @@ const AcceptanceScopeSwitcher = memo(() => {},...workspaces.map((workspace) => ({extra: check(active?.id === workspace.id),- icon: <Avatar avatar={workspace.avatar || DEFAULT_AVATAR} shape={'square'} size={18} />,+ icon: <WorkspaceAvatar avatar={workspace.avatar} name={workspace.name} size={18} />,key: workspace.id,label: workspace.name,onClick: () => navigate(`/${workspace.slug}${acceptanceListPath()}`),diff --git a/src/features/Electron/titlebar/TabBar/TabItem.tsx b/src/features/Electron/titlebar/TabBar/TabItem.tsxindex 48dc185a1b2..22a1a0f458f 100644--- a/src/features/Electron/titlebar/TabBar/TabItem.tsx+++ b/src/features/Electron/titlebar/TabBar/TabItem.tsx@@ -9,6 +9,7 @@ import { memo, useCallback, useEffect, useState } from 'react';import { useTranslation } from 'react-i18next';import Avatar from '@/components/Avatar';+import WorkspaceAvatar from '@/components/WorkspaceAvatar';import ProjectAvatar from '@/features/Projects/ProjectAvatar';import { electronStylish } from '@/styles/electron';@@ -262,6 +263,8 @@ const TabItem = memo<TabItemProps>(<span className={styles.avatarWrapper}>{meta.avatarSeed ? (<ProjectAvatar avatar={meta.avatar} name={meta.avatarSeed} size={16} />+ ) : meta.avatarKind === 'workspace' ? (+ <WorkspaceAvatar avatar={meta.avatar} name={meta.title} size={16} />) : meta.avatar ? (<AvataremojiScaleWithBackgrounddiff --git a/src/features/Electron/titlebar/TabBar/hooks/useResolvedTabs.ts b/src/features/Electron/titlebar/TabBar/hooks/useResolvedTabs.tsindex bd3300df1ae..9efd0aab0a9 100644--- a/src/features/Electron/titlebar/TabBar/hooks/useResolvedTabs.ts+++ b/src/features/Electron/titlebar/TabBar/hooks/useResolvedTabs.ts@@ -53,6 +53,7 @@ export const resolveTab = (? undefined: (pickMeaningful(live?.avatar) ?? pickMeaningful(tab.cached?.avatar));const avatarSeed = pickMeaningful(live?.avatarSeed) ?? pickMeaningful(tab.cached?.avatarSeed);+ const avatarKind = live?.avatarKind ?? tab.cached?.avatarKind;const backgroundColor =pickMeaningful(live?.backgroundColor) ?? pickMeaningful(tab.cached?.backgroundColor);@@ -60,6 +61,7 @@ export const resolveTab = (isActive,meta: {avatar,+ avatarKind,avatarSeed,backgroundColor,icon: staticMeta.icon ?? FALLBACK_ICON,diff --git a/src/features/Electron/titlebar/TabBar/resolveRouteMeta.test.ts b/src/features/Electron/titlebar/TabBar/resolveRouteMeta.test.tsindex fbcb87d3bcd..ff76f524cf2 100644--- a/src/features/Electron/titlebar/TabBar/resolveRouteMeta.test.ts+++ b/src/features/Electron/titlebar/TabBar/resolveRouteMeta.test.ts@@ -82,6 +82,14 @@ describe('guardedMergeCache', () => {expect(merged).toEqual({ avatarSeed: 'Alpha', title: 'Fix login · Alpha' });});+ it('keeps the avatar kind so a cold tab still draws the workspace mark', () => {+ const merged = guardedMergeCache(+ { avatar: 'logo.png', title: 'Acme' },+ { avatar: null, avatarKind: 'workspace', title: 'Acme' },+ );+ expect(merged).toEqual({ avatarKind: 'workspace', title: 'Acme' });+ });+it('drops a cached avatar the entity has confirmed it no longer has', () => {const merged = guardedMergeCache({ avatar: 'logo.png', avatarSeed: 'Alpha', title: 'Alpha' },diff --git a/src/features/Electron/titlebar/TabBar/resolveRouteMeta.ts b/src/features/Electron/titlebar/TabBar/resolveRouteMeta.tsindex 315026352b0..b1d15bf2621 100644--- a/src/features/Electron/titlebar/TabBar/resolveRouteMeta.ts+++ b/src/features/Electron/titlebar/TabBar/resolveRouteMeta.ts@@ -48,6 +48,7 @@ export const guardedMergeCache = (if (isMeaningful(next.avatar)) merged.avatar = next.avatar;else if (next.avatar === null) delete merged.avatar;if (isMeaningful(next.avatarSeed)) merged.avatarSeed = next.avatarSeed;+ if (isMeaningful(next.avatarKind)) merged.avatarKind = next.avatarKind;if (isMeaningful(next.backgroundColor)) merged.backgroundColor = next.backgroundColor;return Object.keys(merged).length > 0 ? merged : undefined;diff --git a/src/features/Electron/titlebar/TabBar/resolveTab.test.ts b/src/features/Electron/titlebar/TabBar/resolveTab.test.tsindex 9ecaba373b1..17f5aa5c352 100644--- a/src/features/Electron/titlebar/TabBar/resolveTab.test.ts+++ b/src/features/Electron/titlebar/TabBar/resolveTab.test.ts@@ -62,6 +62,17 @@ describe('resolveTab', () => {expect(live.meta.avatarSeed).toBe('Alpha');});+ it('carries the workspace avatar kind from the snapshot', () => {+ const cold = resolveTab(+ fixtureRoutes,+ tab('/agent/abc', { avatarKind: 'workspace', title: 'Acme' }),+ false,+ t,+ );+ expect(cold.meta.avatarKind).toBe('workspace');+ expect(cold.meta.avatar).toBeUndefined();+ });+it('active tab: a live null avatar hides the cached one', () => {const resolved = resolveTab(fixtureRoutes,diff --git a/src/features/Messenger/scopeOptions.tsx b/src/features/Messenger/scopeOptions.tsxindex 2859ad5bff4..9b1e8d6beff 100644--- a/src/features/Messenger/scopeOptions.tsx+++ b/src/features/Messenger/scopeOptions.tsx@@ -1,5 +1,7 @@import { Avatar, createStaticStyles, Flexbox, Tag, Text } from '@lobehub/ui';+import WorkspaceAvatar from '@/components/WorkspaceAvatar';+export const PERSONAL_SCOPE = 'personal';const styles = createStaticStyles(({ css }) => ({@@ -68,7 +70,11 @@ const renderScopeOption = ({personalTagLabel?: string;}) => (<Flexbox horizontal align="center" className={styles.scopeOption} gap={8}>- <Avatar avatar={avatar || label} shape="square" size={20} />+ {isPersonal ? (+ <Avatar avatar={avatar || label} shape="square" size={20} />+ ) : (+ <WorkspaceAvatar avatar={avatar} name={label} size={20} />+ )}<Flexbox horizontal align="center" className={styles.scopeTitle} gap={6}><Text ellipsis className={styles.scopeName}>{label}diff --git a/src/features/PageShell/ShellTopBar.tsx b/src/features/PageShell/ShellTopBar.tsxindex 4b1f04a562a..a8205ce8e1f 100644--- a/src/features/PageShell/ShellTopBar.tsx+++ b/src/features/PageShell/ShellTopBar.tsx@@ -6,8 +6,8 @@ import type { ReactNode } from 'react';import { useActiveWorkspace } from '@/business/client/hooks/useActiveWorkspace';import { useWorkspaces } from '@/business/client/hooks/useWorkspaces';-import Avatar from '@/components/Avatar';import { ProductLogo } from '@/components/Branding';+import WorkspaceAvatar from '@/components/WorkspaceAvatar';import UserAvatar from '@/features/User/UserAvatar';/**@@ -104,7 +104,6 @@ const ShellTopBar = ({ actions, onBack, scope, title, titleExtra }: ShellTopBarP// scope to switch to, so the bar is the product, the collection, and you.const switchable = workspaces.length > 1;const scopeName = workspace?.name;- const scopeAvatar = workspace?.avatar || scopeName;return (<Flexbox horizontal align={'center'} className={styles.root} gap={8}>@@ -132,7 +131,7 @@ const ShellTopBar = ({ actions, onBack, scope, title, titleExtra }: ShellTopBarP{scope ??(scopeName && (<Flexbox horizontal align={'center'} className={styles.scopePill} gap={6}>- <Avatar avatar={scopeAvatar} shape={'square'} size={20} />+ <WorkspaceAvatar avatar={workspace?.avatar} name={scopeName} size={20} /><Text fontSize={13} weight={600}>{scopeName}</Text>diff --git a/src/features/RouteMeta/usePublishDynamicRouteMeta.ts b/src/features/RouteMeta/usePublishDynamicRouteMeta.tsindex 5fccab84ba1..e0836e9574c 100644--- a/src/features/RouteMeta/usePublishDynamicRouteMeta.ts+++ b/src/features/RouteMeta/usePublishDynamicRouteMeta.ts@@ -3,10 +3,10 @@ import { useEffect } from 'react';import type { DynamicRouteMeta } from '@/spa/router/routeMeta';export const usePublishDynamicRouteMeta = (- { avatar, avatarSeed, backgroundColor, title }: DynamicRouteMeta,+ { avatar, avatarKind, avatarSeed, backgroundColor, title }: DynamicRouteMeta,onResolve: (meta: DynamicRouteMeta) => void,) => {useEffect(() => {- onResolve({ avatar, avatarSeed, backgroundColor, title });- }, [avatar, avatarSeed, backgroundColor, onResolve, title]);+ onResolve({ avatar, avatarKind, avatarSeed, backgroundColor, title });+ }, [avatar, avatarKind, avatarSeed, backgroundColor, onResolve, title]);};diff --git a/src/features/User/UserAvatar.tsx b/src/features/User/UserAvatar.tsxindex 9c1be4d8a5a..4e74792e122 100644--- a/src/features/User/UserAvatar.tsx+++ b/src/features/User/UserAvatar.tsx@@ -105,8 +105,8 @@ const UserAvatar = ({avatar={avatarValue}background={background}className={clickable ? styles.clickable : className}- // A workspace identity is not a person, so it keeps the gradient fallback.- fallbackVariant={nameOverride ? 'marble' : 'pixel'}+ // A workspace identity is not a person, so it draws the workspace mark.+ fallbackVariant={nameOverride ? 'bauhaus' : 'pixel'}name={name}ref={ref}shape={'square'}diff --git a/src/features/Workspace/routeMeta.test.tsx b/src/features/Workspace/routeMeta.test.tsxindex 59e97910e5d..1dfec62ef87 100644--- a/src/features/Workspace/routeMeta.test.tsx+++ b/src/features/Workspace/routeMeta.test.tsx@@ -36,20 +36,24 @@ describe('workspaceHomeRouteMeta', () => {await waitFor(() => {expect(onResolve).toHaveBeenLastCalledWith({avatar: 'https://example.com/avatar.png',+ avatarKind: 'workspace',backgroundColor: undefined,title: 'Acme',});});});- it('uses the workspace name as the avatar placeholder source when no avatar is set', async () => {+ // The tab draws the workspace mark seeded from the title, so no name string+ // poses as the avatar.+ it('marks the tab as a workspace without an avatar when no avatar is set', async () => {mocks.workspaces = [{ avatar: null, id: 'ws-1', name: 'Acme', slug: 'acme' }];const onResolve = renderDynamicMeta('acme');await waitFor(() => {expect(onResolve).toHaveBeenLastCalledWith({- avatar: 'Acme',+ avatar: null,+ avatarKind: 'workspace',backgroundColor: undefined,title: 'Acme',});diff --git a/src/features/Workspace/routeMeta.ts b/src/features/Workspace/routeMeta.tsindex 22ea6fb72be..0061384dcb9 100644--- a/src/features/Workspace/routeMeta.ts+++ b/src/features/Workspace/routeMeta.ts@@ -12,7 +12,10 @@ const WorkspaceHomeDynamicMeta = ({ onResolve, params }: DynamicRouteMetaProps)usePublishDynamicRouteMeta(workspace? {- avatar: workspace.avatar || workspace.name,+ // `null` clears a cached logo once it is removed; the tab then draws+ // the workspace's generated mark from its name.+ avatar: workspace.avatar || null,+ avatarKind: 'workspace',title: workspace.name,}: {},diff --git a/src/spa/router/routeMeta.ts b/src/spa/router/routeMeta.tsindex 9df3fa34913..7b785c47c1f 100644--- a/src/spa/router/routeMeta.ts+++ b/src/spa/router/routeMeta.ts@@ -8,12 +8,19 @@ export interface StaticRouteMeta {titleKey?: string;}+export type RouteAvatarKind = 'workspace';+export interface DynamicRouteMeta {/*** `null` means the entity loaded and has no avatar, which clears a cached* one; `undefined` means it is not known yet, which keeps the cache.*/avatar?: string | null;+ /**+ * The entity whose avatar this is, when its fallback differs from the+ * initials one. A workspace draws the bauhaus mark seeded from its title.+ */+ avatarKind?: RouteAvatarKind;/*** Name a generated avatar is seeded from, for an entity that draws one when it* has no image of its own (a project). Unset keeps the initials fallback.@@ -47,6 +54,7 @@ export interface RouteHandle {export interface ResolvedRouteMeta {avatar?: string;+ avatarKind?: RouteAvatarKind;avatarSeed?: string;backgroundColor?: string;icon?: LucideIcon;diff --git a/src/store/electron/actions/currentRouteMeta.ts b/src/store/electron/actions/currentRouteMeta.tsindex 9319e967ee7..49aa457404f 100644--- a/src/store/electron/actions/currentRouteMeta.ts+++ b/src/store/electron/actions/currentRouteMeta.ts@@ -44,6 +44,7 @@ export class CurrentRouteMetaActionImpl {currentRouteMetaUrl === url &&(currentRouteMeta === null) === (meta === null) &¤tRouteMeta?.avatar === meta?.avatar &&+ currentRouteMeta?.avatarKind === meta?.avatarKind &¤tRouteMeta?.avatarSeed === meta?.avatarSeed &¤tRouteMeta?.backgroundColor === meta?.backgroundColor &¤tRouteMeta?.title === meta?.title