refactor(tui): group console orgs by account
parent
e972353d59
commit
8922a77e93
|
|
@ -13,6 +13,17 @@ type OrgOption = {
|
||||||
active: boolean
|
active: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const accountHost = (url: string) => {
|
||||||
|
try {
|
||||||
|
return new URL(url).host
|
||||||
|
} catch {
|
||||||
|
return url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const accountLabel = (item: Pick<OrgOption, "accountEmail" | "accountUrl">) =>
|
||||||
|
`${item.accountEmail} ${accountHost(item.accountUrl)}`
|
||||||
|
|
||||||
export function DialogConsoleOrg() {
|
export function DialogConsoleOrg() {
|
||||||
const sdk = useSDK()
|
const sdk = useSDK()
|
||||||
const dialog = useDialog()
|
const dialog = useDialog()
|
||||||
|
|
@ -49,19 +60,19 @@ export function DialogConsoleOrg() {
|
||||||
|
|
||||||
return listed
|
return listed
|
||||||
.toSorted((a, b) => {
|
.toSorted((a, b) => {
|
||||||
if (a.active !== b.active) return a.active ? -1 : 1
|
const activeAccountA = a.active ? 0 : 1
|
||||||
|
const activeAccountB = b.active ? 0 : 1
|
||||||
|
if (activeAccountA !== activeAccountB) return activeAccountA - activeAccountB
|
||||||
|
|
||||||
|
const accountCompare = accountLabel(a).localeCompare(accountLabel(b))
|
||||||
|
if (accountCompare !== 0) return accountCompare
|
||||||
|
|
||||||
return a.orgName.localeCompare(b.orgName)
|
return a.orgName.localeCompare(b.orgName)
|
||||||
})
|
})
|
||||||
.map((item) => ({
|
.map((item) => ({
|
||||||
title: item.orgName,
|
title: item.orgName,
|
||||||
value: item,
|
value: item,
|
||||||
description: `${item.accountEmail} · ${(() => {
|
category: accountLabel(item),
|
||||||
try {
|
|
||||||
return new URL(item.accountUrl).host
|
|
||||||
} catch {
|
|
||||||
return item.accountUrl
|
|
||||||
}
|
|
||||||
})()}`,
|
|
||||||
onSelect: async () => {
|
onSelect: async () => {
|
||||||
if (item.active) {
|
if (item.active) {
|
||||||
dialog.clear()
|
dialog.clear()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue