-
Notifications
You must be signed in to change notification settings - Fork 116
fix(ui): show avatar initials for single-segment usernames; tooltip truncated chart names #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eliran-ops
wants to merge
5
commits into
main
Choose a base branch
from
feat/fix-cosmetic-batch-avatar-stop-claude-truncation-tooltips
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7641738
fix(ui): show avatar initials for single-segment usernames; tooltip t…
eliran-mic 179d70c
fix(ui): make Tooltip wrapperClassName actually win over default display
eliran-mic a760e41
fix(user-initials): drop non-letters; honour single-segment fallback
eliran-mic 6bbaf88
test(ui): pin Tooltip twMerge override + whitespace user-initials
eliran-mic 7175703
chore(k8s-ui): mirror tailwind-merge in devDependencies
eliran-ops File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { renderToString } from 'react-dom/server' | ||
| import { Tooltip } from './Tooltip' | ||
|
|
||
| // Pins the wrapper-className merge contract: a caller passing | ||
| // `wrapperClassName="block"` MUST override the default `inline-flex` | ||
| // on the trigger span. Without `twMerge`, plain `clsx` concatenation | ||
| // emits both `inline-flex` and `block`, and stylesheet ordering picks | ||
| // the wrong one — breaks ChartBrowser's truncation flow because the | ||
| // wrapper stays `inline-flex` and the child `truncate` never engages. | ||
| describe('Tooltip wrapper className', () => { | ||
| it('lets the caller override the default display utility via twMerge', () => { | ||
| const html = renderToString( | ||
| <Tooltip content="hi" wrapperClassName="block"> | ||
| <span>child</span> | ||
| </Tooltip>, | ||
| ) | ||
| // Caller wins on the display group — twMerge drops the conflicting | ||
| // default. Assert each class independently; emit order is a | ||
| // twMerge implementation detail and varies across versions. | ||
| expect(html).toContain('block') | ||
| expect(html).toContain('max-w-full') | ||
| expect(html).not.toContain('inline-flex') | ||
| }) | ||
|
|
||
| it('keeps the default display utility when no caller override is supplied', () => { | ||
| const html = renderToString( | ||
| <Tooltip content="hi"> | ||
| <span>child</span> | ||
| </Tooltip>, | ||
| ) | ||
| expect(html).toContain('inline-flex max-w-full') | ||
| }) | ||
|
|
||
| it('merges arbitrary non-conflicting utilities from the caller alongside the defaults', () => { | ||
| const html = renderToString( | ||
| <Tooltip content="hi" wrapperClassName="min-w-0 flex-1"> | ||
| <span>child</span> | ||
| </Tooltip>, | ||
| ) | ||
| expect(html).toContain('inline-flex') | ||
| expect(html).toContain('max-w-full') | ||
| expect(html).toContain('min-w-0') | ||
| expect(html).toContain('flex-1') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import { describe, it, expect } from 'vitest' | ||
| import { computeUserInitials } from './user-initials' | ||
|
|
||
| // Pin the contract that the avatar circle never tries to render a | ||
| // non-letter glyph: previous implementations either produced | ||
| // silhouettes for separator-free usernames OR leaked separator | ||
| // characters into the result (e.g. ".U" for ".user"). | ||
|
|
||
| describe('computeUserInitials', () => { | ||
| it('uses segment initials when separators are present', () => { | ||
| expect(computeUserInitials('mary.kohli')).toBe('MK') | ||
| expect(computeUserInitials('mary_kohli')).toBe('MK') | ||
| expect(computeUserInitials('mary-kohli')).toBe('MK') | ||
| }) | ||
|
|
||
| it('caps segment initials at 2 even with many separators', () => { | ||
| expect(computeUserInitials('a.b.c.d')).toBe('AB') | ||
| }) | ||
|
|
||
| it('falls back to leading letters when no separators', () => { | ||
| expect(computeUserInitials('mkohli')).toBe('MK') | ||
| expect(computeUserInitials('alice')).toBe('AL') | ||
| }) | ||
|
|
||
| it('returns a single letter for single-character usernames', () => { | ||
| expect(computeUserInitials('a')).toBe('A') | ||
| }) | ||
|
|
||
| it('strips the @-domain before computing', () => { | ||
| expect(computeUserInitials('[email protected]')).toBe('MK') | ||
| expect(computeUserInitials('[email protected]')).toBe('MK') | ||
| }) | ||
|
|
||
| it('uppercases the result', () => { | ||
| expect(computeUserInitials('alice')).toBe('AL') | ||
| expect(computeUserInitials('ALICE')).toBe('AL') | ||
| expect(computeUserInitials('aLiCe')).toBe('AL') | ||
| }) | ||
|
|
||
| it('returns empty string for null/undefined/empty inputs', () => { | ||
| expect(computeUserInitials(null)).toBe('') | ||
| expect(computeUserInitials(undefined)).toBe('') | ||
| expect(computeUserInitials('')).toBe('') | ||
| }) | ||
|
|
||
| it('handles consecutive separators without producing empty segments', () => { | ||
| expect(computeUserInitials('mary..kohli')).toBe('MK') | ||
| expect(computeUserInitials('mary__kohli')).toBe('MK') | ||
| }) | ||
|
|
||
| it('handles email-only usernames with @ as the first character', () => { | ||
| expect(computeUserInitials('@example.com')).toBe('') | ||
| }) | ||
|
|
||
| it('does not include separator characters in the fallback', () => { | ||
| // Leading/trailing separators must not leak into the avatar | ||
| // circle as ".U", "-A", "_O" — non-letters get filtered before | ||
| // the slice, not after. | ||
| expect(computeUserInitials('.user')).toBe('US') | ||
| expect(computeUserInitials('-admin')).toBe('AD') | ||
| expect(computeUserInitials('_ops')).toBe('OP') | ||
| }) | ||
|
|
||
| it('takes leading letters of the segment, not the whole localPart, for trailing/leading separator inputs', () => { | ||
| // Single-segment inputs must fall back to leading letters of | ||
| // the SEGMENT, not the raw localPart — otherwise `'mary.'` | ||
| // returns `'MA'` from the wrong slice and inconsistency with | ||
| // `'mary.kohli'` shows up only on partial inputs. | ||
| expect(computeUserInitials('mary.')).toBe('MA') | ||
| expect(computeUserInitials('.mary')).toBe('MA') | ||
| }) | ||
|
|
||
| it('returns empty for inputs with no letters', () => { | ||
| // The avatar circle has no glyph to render for separator-only, | ||
| // digit-only, or punctuation-only inputs — return `''` so the | ||
| // caller can fall back to a silhouette. | ||
| expect(computeUserInitials('..')).toBe('') | ||
| expect(computeUserInitials('123')).toBe('') | ||
| expect(computeUserInitials('_')).toBe('') | ||
| expect(computeUserInitials('---')).toBe('') | ||
| }) | ||
|
|
||
| it('drops leading whitespace before computing initials', () => { | ||
| // Leading whitespace must not leak into the avatar circle as | ||
| // a pair of blank glyphs — the truthy `' '` would defeat the | ||
| // caller's `{initials || <silhouette>}` fallback. | ||
| expect(computeUserInitials(' alice')).toBe('AL') | ||
| expect(computeUserInitials('\talice')).toBe('AL') | ||
| }) | ||
|
|
||
| it('skips digits and punctuation interleaved with letters', () => { | ||
| expect(computeUserInitials('m1k')).toBe('MK') | ||
| expect(computeUserInitials('a$b$c')).toBe('AB') | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * Computes a 1- or 2-character avatar label for a username. | ||
| * | ||
| * Rules (in order): | ||
| * 1. Strip the @-domain from the local-part — domains never carry | ||
| * useful identity for an in-app avatar. | ||
| * 2. Drop everything that isn't a letter (separators like `.`, | ||
| * `_`, `-`, digits, punctuation). The avatar circle can only | ||
| * render a meaningful glyph for letters; rendering `.U` or | ||
| * `12` looks broken. | ||
| * 3. If the cleaned local-part contains separator-bounded | ||
| * segments (`.`, `_`, `-`), use the first letter of each | ||
| * segment (max 2). e.g. `"mary.kohli"` → `"MK"`. | ||
| * 4. Otherwise use the first 1-2 letters of the cleaned | ||
| * local-part. e.g. `"mkohli"` → `"MK"`. | ||
| * 5. Always uppercase. | ||
| * 6. Returns `''` when no letters survive — the caller falls back | ||
| * to a silhouette / `?` icon. | ||
| */ | ||
| export function computeUserInitials(username: string | null | undefined): string { | ||
| if (!username) return '' | ||
| const localPart = username.split('@')[0] | ||
| if (!localPart) return '' | ||
| // Split on the canonical separators first so segment-based | ||
| // initials still work, then drop any non-letter characters per | ||
| // segment so leading punctuation can't leak into the result. | ||
| const segments = localPart | ||
| .split(/[._-]/) | ||
| .map(s => s.replace(/[^a-zA-Z]/g, '')) | ||
| .filter(Boolean) | ||
| if (segments.length === 0) return '' | ||
| if (segments.length >= 2) { | ||
| return segments | ||
| .slice(0, 2) | ||
| .map(s => s[0].toUpperCase()) | ||
| .join('') | ||
| } | ||
| // Single segment (no usable separators) — surface up to two | ||
| // leading letters so e.g. `mkohli` produces `MK` instead of `M`. | ||
| return segments[0].slice(0, 2).toUpperCase() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.