-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Avatars] Split out Agent Avatars from User Avatars #92002
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
grgia
wants to merge
2
commits into
main
Choose a base branch
from
georgia-remove-bots
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.
+290
−217
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
| @@ -1,23 +1,8 @@ | ||
| import type {TupleToUnion} from 'type-fest'; | ||
| import BotAvatarBlue from '@assets/images/avatars/bots/bot-avatar--blue.svg'; | ||
| import BotAvatarGreen from '@assets/images/avatars/bots/bot-avatar--green.svg'; | ||
| import BotAvatarIce from '@assets/images/avatars/bots/bot-avatar--ice.svg'; | ||
| import BotAvatarPink from '@assets/images/avatars/bots/bot-avatar--pink.svg'; | ||
| import BotAvatarTangerine from '@assets/images/avatars/bots/bot-avatar--tangerine.svg'; | ||
| import BotAvatarYellow from '@assets/images/avatars/bots/bot-avatar--yellow.svg'; | ||
|
|
||
| const botAvatars = [BotAvatarBlue, BotAvatarGreen, BotAvatarIce, BotAvatarPink, BotAvatarTangerine, BotAvatarYellow] as const; | ||
|
|
||
| type BotAvatar = TupleToUnion<typeof botAvatars>; | ||
|
|
||
| const botAvatarIDs = new Map<BotAvatar, string>([ | ||
| [BotAvatarBlue, 'bot-avatar--blue'], | ||
| [BotAvatarGreen, 'bot-avatar--green'], | ||
| [BotAvatarIce, 'bot-avatar--ice'], | ||
| [BotAvatarPink, 'bot-avatar--pink'], | ||
| [BotAvatarTangerine, 'bot-avatar--tangerine'], | ||
| [BotAvatarYellow, 'bot-avatar--yellow'], | ||
| ]); | ||
|
|
||
| export {botAvatars, botAvatarIDs, BotAvatarBlue, BotAvatarGreen, BotAvatarIce, BotAvatarPink, BotAvatarTangerine, BotAvatarYellow}; | ||
| export type {BotAvatar}; | ||
| export {BotAvatarBlue, BotAvatarGreen, BotAvatarIce, BotAvatarPink, BotAvatarTangerine, BotAvatarYellow}; |
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,26 @@ | ||
| /* eslint-disable @typescript-eslint/naming-convention */ | ||
| import {BotAvatarBlue, BotAvatarGreen, BotAvatarIce, BotAvatarPink, BotAvatarTangerine, BotAvatarYellow} from '@components/Icon/DefaultBotAvatars'; | ||
| import CONST from '@src/CONST'; | ||
| import {createAvatarCatalog} from './AvatarCatalog'; | ||
| import type {AvatarEntry} from './AvatarCatalog'; | ||
|
|
||
| type AgentAvatarID = 'bot-avatar--blue' | 'bot-avatar--green' | 'bot-avatar--ice' | 'bot-avatar--pink' | 'bot-avatar--tangerine' | 'bot-avatar--yellow'; | ||
|
|
||
| const CDN_BOT_AVATARS = `${CONST.CLOUDFRONT_URL}/images/avatars/bots`; | ||
|
|
||
| const AGENT_AVATAR_ENTRIES: Record<AgentAvatarID, AvatarEntry> = { | ||
| 'bot-avatar--blue': {local: BotAvatarBlue, url: `${CDN_BOT_AVATARS}/bot-avatar--blue.png`}, | ||
| 'bot-avatar--green': {local: BotAvatarGreen, url: `${CDN_BOT_AVATARS}/bot-avatar--green.png`}, | ||
| 'bot-avatar--ice': {local: BotAvatarIce, url: `${CDN_BOT_AVATARS}/bot-avatar--ice.png`}, | ||
| 'bot-avatar--pink': {local: BotAvatarPink, url: `${CDN_BOT_AVATARS}/bot-avatar--pink.png`}, | ||
| 'bot-avatar--tangerine': {local: BotAvatarTangerine, url: `${CDN_BOT_AVATARS}/bot-avatar--tangerine.png`}, | ||
| 'bot-avatar--yellow': {local: BotAvatarYellow, url: `${CDN_BOT_AVATARS}/bot-avatar--yellow.png`}, | ||
| }; | ||
|
|
||
| const AGENT_AVATARS = createAvatarCatalog<AgentAvatarID>( | ||
| AGENT_AVATAR_ENTRIES, | ||
| (Object.keys(AGENT_AVATAR_ENTRIES) as AgentAvatarID[]).map((id) => ({id, ...AGENT_AVATAR_ENTRIES[id]})), | ||
| ); | ||
|
|
||
| export {AGENT_AVATARS}; | ||
| export type {AgentAvatarID}; | ||
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,45 @@ | ||
| import type {SvgProps} from 'react-native-svg'; | ||
|
|
||
| type AvatarEntry = {local: React.FC<SvgProps>; url: string}; | ||
|
|
||
| // Base shape for cross-catalog iteration. Specific catalogs widen `string` to their own ID literal union. | ||
| type AvatarCatalogBase = { | ||
| entries: Record<string, AvatarEntry>; | ||
| ordered: ReadonlyArray<{id: string} & AvatarEntry>; | ||
| getLocal: (id: string) => React.FC<SvgProps> | undefined; | ||
| getURL: (id: string) => string | undefined; | ||
| isAvatarID: (value: unknown) => boolean; | ||
| resolveURI: (id: string) => string; | ||
| getNameFromURL: (url: string | undefined) => string | undefined; | ||
| }; | ||
|
|
||
| type AvatarCatalog<ID extends string> = { | ||
| entries: Record<ID, AvatarEntry>; | ||
| ordered: Array<{id: ID} & AvatarEntry>; | ||
| getLocal: (id: ID) => React.FC<SvgProps> | undefined; | ||
| getURL: (id: ID) => string | undefined; | ||
| isAvatarID: (value: unknown) => value is ID; | ||
| resolveURI: (id: string) => string; | ||
| getNameFromURL: (url: string | undefined) => ID | undefined; | ||
| }; | ||
|
|
||
| function createAvatarCatalog<ID extends string>(entries: Record<ID, AvatarEntry>, ordered: Array<{id: ID} & AvatarEntry>): AvatarCatalog<ID> { | ||
| return { | ||
| entries, | ||
| ordered, | ||
| getLocal: (id) => entries[id]?.local, | ||
| getURL: (id) => entries[id]?.url, | ||
| isAvatarID: (value): value is ID => typeof value === 'string' && value in entries, | ||
| resolveURI: (id) => (id in entries ? entries[id as ID].url : id), | ||
| getNameFromURL: (url) => { | ||
| if (!url || typeof url !== 'string') { | ||
| return undefined; | ||
| } | ||
| const name = (url.split('/').at(-1)?.split('.').at(0) ?? '') as ID; | ||
| return name in entries ? name : undefined; | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export {createAvatarCatalog}; | ||
| export type {AvatarEntry, AvatarCatalog, AvatarCatalogBase}; |
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 type {SvgProps} from 'react-native-svg'; | ||
| import {AGENT_AVATARS} from './AgentAvatarCatalog'; | ||
| import type {AvatarCatalogBase} from './AvatarCatalog'; | ||
| import {USER_AVATARS} from './UserAvatarCatalog'; | ||
|
|
||
| // Catalogs whose entries have CDN-backed URLs (i.e. not letter avatars). | ||
| // Keep this list in sync when adding a new catalog with `url` entries. | ||
| // Narrow catalogs are widened to AvatarCatalogBase for cross-catalog iteration. | ||
| const CATALOGS_WITH_CDN_URLS = [USER_AVATARS, AGENT_AVATARS] as unknown as AvatarCatalogBase[]; | ||
|
|
||
| function findLocalAvatarForURL(source: unknown): React.FC<SvgProps> | undefined { | ||
| if (typeof source !== 'string') { | ||
| return undefined; | ||
| } | ||
| for (const catalog of CATALOGS_WITH_CDN_URLS) { | ||
| const name = catalog.getNameFromURL(source); | ||
| if (name) { | ||
| return catalog.getLocal(name); | ||
| } | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| function findAvatarIDFromURL(source: unknown): string | undefined { | ||
| if (typeof source !== 'string') { | ||
| return undefined; | ||
| } | ||
| for (const catalog of CATALOGS_WITH_CDN_URLS) { | ||
| const name = catalog.getNameFromURL(source); | ||
| if (name) { | ||
| return name; | ||
| } | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| function findCatalogURLForID(id: string): string | undefined { | ||
| for (const catalog of CATALOGS_WITH_CDN_URLS) { | ||
| if (catalog.isAvatarID(id)) { | ||
| return catalog.getURL(id); | ||
| } | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| export {findLocalAvatarForURL, findAvatarIDFromURL, findCatalogURLForID}; |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ CONSISTENCY-5 (docs)
The
/* eslint-disable @typescript-eslint/naming-convention */directive at the top of this new file lacks a justification comment explaining why the naming convention rule needs to be disabled. The keys inAGENT_AVATAR_ENTRIESuse kebab-case (e.g.,'bot-avatar--blue') which conflicts with the naming convention rule, but this reason should be documented.Add a justification comment explaining why the rule is disabled, for example:
/* eslint-disable @typescript-eslint/naming-convention -- Avatar IDs use kebab-case to match CDN filenames */Reviewed at: 95f3f70 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.