{ "version": 3, "sources": ["../../account/principal_info.tsx"], "sourcesContent": ["import * as React from \"react\"\nimport {classNames} from \"@cling/lib.web.utils\"\nimport {Avatar} from \"@cling/lib.web.mdc\"\nimport {AccountUID, is_AccountUID, is_TeamUID, PrincipalUID, Team} from \"@cling/lib.shared.model\"\nimport {observer} from \"mobx-react\"\nimport {assert_never, full_name} from \"@cling/lib.shared.utils\"\nimport {account_resource, team_resource, team_members_resource} from \"@cling/lib.web.resources\"\nimport {simple_tooltip_event_handlers} from \"@cling/lib.web.mdc/simple_tooltip\"\n\ninterface AccountModel {\n uid?: AccountUID\n given_name?: string\n family_name?: string\n profile_image_url?: string\n}\n\ninterface TeamModel {\n name?: string\n}\n\ntype Props = (\n | {uid: PrincipalUID; account?: never; teams_of_account?: never; team?: never}\n | {uid?: never; account: AccountModel; teams_of_account?: Team[]; team?: never}\n | {uid?: never; account?: never; teams_of_account?: never; team: TeamModel}\n) & {\n display:\n | \"avatar\"\n | \"avatar_small\"\n | \"avatar_large\"\n | \"avatar_very_large\"\n | \"full_name\"\n | \"full_name_no_teams\"\n | \"complete\"\n custom_details?: string\n className?: string\n tooltip?: \"full_name\"\n \"data-test-id\"?: string\n \"data-test-ignore\"?: boolean\n prefix?: string\n}\n\nexport const PrincipalInfo = observer(\n ({\n uid,\n display,\n className,\n prefix,\n custom_details,\n tooltip,\n \"data-test-id\": data_test_id,\n \"data-test-ignore\": data_test_ignore,\n teams_of_account,\n team,\n account,\n }: Props) => {\n if (!teams_of_account) {\n teams_of_account = []\n }\n if (uid) {\n if (is_AccountUID(uid)) {\n account = account_resource.read(uid)\n } else if (is_TeamUID(uid)) {\n team = team_resource.read(uid)\n } else {\n throw assert_never(uid)\n }\n }\n if (account?.uid) {\n const account_uid = account.uid\n // Go through all teams we have access to the members of.\n for (const team_candidate of team_resource.read_all()) {\n const members = team_members_resource.read(team_candidate.uid)\n if (members?.account_uids.includes(account_uid)) {\n teams_of_account.push(team_candidate)\n }\n }\n }\n const name = (prefix || \"\") + (team ? team.name : full_name(account))\n if ([\"full_name\", \"full_name_no_teams\"].includes(display)) {\n let details\n if (custom_details) {\n details = custom_details\n } else if (teams_of_account.length > 0) {\n details = teams_of_account\n .map((x) => (x ? x.name : \"...\"))\n .sort((a, b) => a.localeCompare(b))\n .join(\", \")\n }\n return (\n <span\n className={classNames(className, \"principal-info__full-name\")}\n data-test-id={data_test_id}\n data-test-ignore={data_test_ignore}\n >\n {name}\n {display === \"full_name\" && !!details && (\n <div className=\"principal-info__teams\">{details}</div>\n )}\n </span>\n )\n }\n let icon: string | undefined\n let letter: string | undefined\n if (!account) {\n if (team || is_TeamUID(uid)) {\n icon = \"group\"\n } else {\n letter = \"\\u2026\" // ... horizontal ellipsis\n }\n } else if (account.given_name) {\n letter = account.given_name.charAt(0)\n } else if (account.family_name) {\n letter = account.family_name.charAt(0)\n } else {\n letter = \"?\"\n }\n const tooltip_str = tooltip === \"full_name\" && (account || team) ? name : undefined\n return (\n <div\n aria-label={tooltip_str}\n data-test-id={data_test_id}\n data-test-ignore={data_test_ignore}\n className=\"principal-info\"\n {...(tooltip_str ? simple_tooltip_event_handlers : {})}\n >\n <div>\n <Avatar\n className={className}\n image_url={account && account.profile_image_url}\n icon={icon}\n letter={letter}\n large={display === \"avatar_large\"}\n very_large={display === \"avatar_very_large\"}\n small={display === \"avatar_small\"}\n />\n </div>\n {display === \"complete\" && (\n <div className=\"principal-info__complete-fullname\">\n {name}\n {teams_of_account.length > 0 && (\n <div className=\"principal-info__teams\">\n {teams_of_account.map((x) => (x ? x.name : \"...\")).join(\", \")}\n </div>\n )}\n </div>\n )}\n </div>\n )\n },\n)\n"], "mappings": "oWAAAA,IAyCO,IAAMC,EAAgBC,EACzB,CAAC,CACG,IAAAC,EACA,QAAAC,EACA,UAAAC,EACA,OAAAC,EACA,eAAAC,EACA,QAAAC,EACA,eAAgBC,EAChB,mBAAoBC,EACpB,iBAAAC,EACA,KAAAC,EACA,QAAAC,CACJ,IAAa,CAIT,GAHKF,I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WACGA,EAACM,EAAA,CACG,UAAW7B,EACX,UAAWQ,GAAWA,EAAQ,kBAC9B,KAAMiB,EACN,OAAQC,EACR,MAAO3B,IAAY,eACnB,WAAYA,IAAY,oBACxB,MAAOA,IAAY,eACvB,CACJ,EACCA,IAAY,YACTwB,EAAC,OAAI,UAAU,qCACVN,EACAX,EAAiB,OAAS,GACvBiB,EAAC,OAAI,UAAU,yBACVjB,EAAiB,IAAKc,GAAOA,EAAIA,EAAE,KAAO,KAAM,EAAE,KAAK,IAAI,CAChE,CAER,CAER,CAER,CACJ", "names": ["init_compat_module", "PrincipalInfo", "observer", "uid", "display", "className", "prefix", "custom_details", "tooltip", "data_test_id", "data_test_ignore", "teams_of_account", "team", "account", "is_AccountUID", "account_resource", "is_TeamUID", "team_resource", "assert_never", "account_uid", "team_candidate", "team_members_resource", "name", "full_name", "details", "x", "a", "b", "_", "classNames", "icon", "letter", "tooltip_str", "simple_tooltip_event_handlers", "Avatar"] }