Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(today): drop duplicate project emoji in the switcher (#124317)

Charles Vien9dcd5397cc98
diff --git a/frontend/src/layout/today/TodayLogo.tsx b/frontend/src/layout/today/TodayLogo.tsx
index 4e660eefd75d..f4c87cde924a 100644
--- a/frontend/src/layout/today/TodayLogo.tsx
+++ b/frontend/src/layout/today/TodayLogo.tsx
@@ -3,6 +3,8 @@ import { Avatar, AvatarFallback, AvatarImage } from '@posthog/quill'
import { lettermarkColorIndex } from 'lib/lemon-ui/Lettermark/Lettermark'
import { backendAssetUrl } from 'lib/utils/apiHost'
+import { leadingEmoji } from './leadingEmoji'
+
/** quill's smallest avatar is 20px, so the tile and the menu row sizes override it. */
const SIZE_CLASSES = {
tile: 'size-7 text-xs',
@@ -18,7 +20,6 @@ export interface TodayLogoProps {
size: keyof typeof SIZE_CLASSES
}
-/** An uploaded org or project logo, or its first letter. */
export function TodayLogo({ name, mediaId, colorSeed, size }: TodayLogoProps): JSX.Element {
const color = colorSeed !== null ? lettermarkColorIndex(colorSeed) : null
return (
@@ -33,7 +34,7 @@ export function TodayLogo({ name, mediaId, colorSeed, size }: TodayLogoProps): J
: undefined
}
>
- {name ? String.fromCodePoint(name.codePointAt(0)!).toLocaleUpperCase() : '?'}
+ {name ? (leadingEmoji(name) ?? String.fromCodePoint(name.codePointAt(0)!).toLocaleUpperCase()) : '?'}
</AvatarFallback>
</Avatar>
)
diff --git a/frontend/src/layout/today/TodayProjectMenu.tsx b/frontend/src/layout/today/TodayProjectMenu.tsx
index 0d54b7c856bd..58487214ee78 100644
--- a/frontend/src/layout/today/TodayProjectMenu.tsx
+++ b/frontend/src/layout/today/TodayProjectMenu.tsx
@@ -7,6 +7,7 @@ import { newAccountMenuLogic } from 'lib/components/Account/newAccountMenuLogic'
import { projectLogic } from 'scenes/projectLogic'
import { teamLogic } from 'scenes/teamLogic'
+import { withoutLeadingEmoji } from './leadingEmoji'
import { TodayLogo } from './TodayLogo'
import { ProjectMenuActionKey, todayProjectMenuLogic } from './todayProjectMenuLogic'
import { TodaySwitcherMenu, TodaySwitcherRow } from './TodaySwitcherMenu'
@@ -24,6 +25,10 @@ const ACTION_ROWS: Record<ProjectMenuActionKey, Pick<TodaySwitcherRow, 'label' |
// names differ only near the end, so a narrower menu truncates the part that tells them apart.
const MENU_DEFAULT_WIDTH = 335
+function nameBesideLogo(name: string, mediaId: string | null | undefined): string {
+ return mediaId ? name : withoutLeadingEmoji(name)
+}
+
/** The project switcher shortcut opens this menu too. */
export function TodayProjectMenu(): JSX.Element {
const { currentTeam } = useValues(teamLogic)
@@ -45,7 +50,11 @@ export function TodayProjectMenu(): JSX.Element {
size="trigger"
/>
)}
- <span className="max-w-48 min-w-0 truncate">{currentTeam?.name ?? 'Select project'}</span>
+ <span className="max-w-48 min-w-0 truncate">
+ {currentTeam
+ ? nameBesideLogo(currentTeam.name, currentProject?.logo_media_id)
+ : 'Select project'}
+ </span>
</Button>
}
open={isProjectSwitcherOpen}
@@ -56,21 +65,17 @@ export function TodayProjectMenu(): JSX.Element {
noMatchLabel="No projects match your search"
groups={projectGroups.map((group) => ({
label: group.name ?? 'Projects',
- rows: group.projects.map(({ team }) => ({
- value: String(team.id),
- label: team.name,
- leading: (
- <TodayLogo
- name={team.name}
- // The org's project list carries no logos, so only the current project shows its upload.
- mediaId={team.project_id === currentProject?.id ? currentProject.logo_media_id : null}
- colorSeed={null}
- size="row"
- />
- ),
- dataAttr: 'today-top-bar-project-item',
- onSelect: () => switchProject(team.id, team.project_id),
- })),
+ rows: group.projects.map(({ team }) => {
+ // The org's project list carries no logos, so only the current project shows its upload.
+ const mediaId = team.project_id === currentProject?.id ? currentProject.logo_media_id : null
+ return {
+ value: String(team.id),
+ label: nameBesideLogo(team.name, mediaId),
+ leading: <TodayLogo name={team.name} mediaId={mediaId} colorSeed={null} size="row" />,
+ dataAttr: 'today-top-bar-project-item',
+ onSelect: () => switchProject(team.id, team.project_id),
+ }
+ }),
}))}
actions={projectMenuActions.map(({ key, disabledReason }) => ({
value: key,
diff --git a/frontend/src/layout/today/leadingEmoji.test.ts b/frontend/src/layout/today/leadingEmoji.test.ts
new file mode 100644
index 000000000000..a11db4c134e8
--- /dev/null
+++ b/frontend/src/layout/today/leadingEmoji.test.ts
@@ -0,0 +1,18 @@
+import { leadingEmoji, withoutLeadingEmoji } from './leadingEmoji'
+
+describe('leadingEmoji', () => {
+ it.each([
+ ['🎉 PostHog App', '🎉', 'PostHog App'],
+ ['🎉PostHog App', '🎉', 'PostHog App'],
+ ['👩‍💻 Dev team', '👩‍💻', 'Dev team'],
+ ['❤️ Fans', '❤️', 'Fans'],
+ ['👍🏽 Thumbs', '👍🏽', 'Thumbs'],
+ ['🎉', '🎉', '🎉'],
+ ['PostHog 🎉', null, 'PostHog 🎉'],
+ ['PostHog', null, 'PostHog'],
+ ['', null, ''],
+ ])('splits %j into %j and %j', (name, emoji, rest) => {
+ expect(leadingEmoji(name)).toEqual(emoji)
+ expect(withoutLeadingEmoji(name)).toEqual(rest)
+ })
+})
diff --git a/frontend/src/layout/today/leadingEmoji.ts b/frontend/src/layout/today/leadingEmoji.ts
new file mode 100644
index 000000000000..8677601d1230
--- /dev/null
+++ b/frontend/src/layout/today/leadingEmoji.ts
@@ -0,0 +1,11 @@
+const graphemes = new Intl.Segmenter(undefined, { granularity: 'grapheme' })
+
+export function leadingEmoji(name: string): string | null {
+ const [first] = graphemes.segment(name)
+ return first && /\p{Extended_Pictographic}/u.test(first.segment) ? first.segment : null
+}
+
+export function withoutLeadingEmoji(name: string): string {
+ const emoji = leadingEmoji(name)
+ return (emoji && name.slice(emoji.length).trimStart()) || name
+}