fix(tui): only show org switch affordances when useful (#21054)
This commit is contained in:
@@ -630,19 +630,23 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
|
|||||||
},
|
},
|
||||||
category: "Provider",
|
category: "Provider",
|
||||||
},
|
},
|
||||||
{
|
...(sync.data.console_state.switchableOrgCount > 1
|
||||||
title: "Switch org",
|
? [
|
||||||
value: "console.org.switch",
|
{
|
||||||
suggested: Boolean(sync.data.console_state.activeOrgName),
|
title: "Switch org",
|
||||||
slash: {
|
value: "console.org.switch",
|
||||||
name: "org",
|
suggested: Boolean(sync.data.console_state.activeOrgName),
|
||||||
aliases: ["orgs", "switch-org"],
|
slash: {
|
||||||
},
|
name: "org",
|
||||||
onSelect: () => {
|
aliases: ["orgs", "switch-org"],
|
||||||
dialog.replace(() => <DialogConsoleOrg />)
|
},
|
||||||
},
|
onSelect: () => {
|
||||||
category: "Provider",
|
dialog.replace(() => <DialogConsoleOrg />)
|
||||||
},
|
},
|
||||||
|
category: "Provider",
|
||||||
|
},
|
||||||
|
]
|
||||||
|
: []),
|
||||||
{
|
{
|
||||||
title: "View status",
|
title: "View status",
|
||||||
keybind: "status_view",
|
keybind: "status_view",
|
||||||
|
|||||||
@@ -96,6 +96,7 @@ export function Prompt(props: PromptProps) {
|
|||||||
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
const shell = createMemo(() => props.placeholders?.shell ?? [])
|
||||||
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
const [auto, setAuto] = createSignal<AutocompleteRef>()
|
||||||
const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
|
const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
|
||||||
|
const canSwitchOrgs = createMemo(() => sync.data.console_state.switchableOrgCount > 1)
|
||||||
const currentProviderLabel = createMemo(() => {
|
const currentProviderLabel = createMemo(() => {
|
||||||
const current = local.model.current()
|
const current = local.model.current()
|
||||||
const provider = local.model.parsed().provider
|
const provider = local.model.parsed().provider
|
||||||
@@ -1118,7 +1119,13 @@ export function Prompt(props: PromptProps) {
|
|||||||
<box flexDirection="row" gap={1} alignItems="center">
|
<box flexDirection="row" gap={1} alignItems="center">
|
||||||
{props.right}
|
{props.right}
|
||||||
<Show when={activeOrgName()}>
|
<Show when={activeOrgName()}>
|
||||||
<text fg={theme.textMuted} onMouseUp={() => command.trigger("console.org.switch")}>
|
<text
|
||||||
|
fg={theme.textMuted}
|
||||||
|
onMouseUp={() => {
|
||||||
|
if (!canSwitchOrgs()) return
|
||||||
|
command.trigger("console.org.switch")
|
||||||
|
}}
|
||||||
|
>
|
||||||
{`${CONSOLE_MANAGED_ICON} ${activeOrgName()}`}
|
{`${CONSOLE_MANAGED_ICON} ${activeOrgName()}`}
|
||||||
</text>
|
</text>
|
||||||
</Show>
|
</Show>
|
||||||
|
|||||||
@@ -1469,6 +1469,7 @@ export namespace Config {
|
|||||||
consoleState: {
|
consoleState: {
|
||||||
consoleManagedProviders: Array.from(consoleManagedProviders),
|
consoleManagedProviders: Array.from(consoleManagedProviders),
|
||||||
activeOrgName,
|
activeOrgName,
|
||||||
|
switchableOrgCount: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import z from "zod"
|
|||||||
export const ConsoleState = z.object({
|
export const ConsoleState = z.object({
|
||||||
consoleManagedProviders: z.array(z.string()),
|
consoleManagedProviders: z.array(z.string()),
|
||||||
activeOrgName: z.string().optional(),
|
activeOrgName: z.string().optional(),
|
||||||
|
switchableOrgCount: z.number().int().nonnegative(),
|
||||||
})
|
})
|
||||||
|
|
||||||
export type ConsoleState = z.infer<typeof ConsoleState>
|
export type ConsoleState = z.infer<typeof ConsoleState>
|
||||||
@@ -10,4 +11,5 @@ export type ConsoleState = z.infer<typeof ConsoleState>
|
|||||||
export const emptyConsoleState: ConsoleState = {
|
export const emptyConsoleState: ConsoleState = {
|
||||||
consoleManagedProviders: [],
|
consoleManagedProviders: [],
|
||||||
activeOrgName: undefined,
|
activeOrgName: undefined,
|
||||||
|
switchableOrgCount: 0,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,11 @@ export const ExperimentalRoutes = lazy(() =>
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
async (c) => {
|
async (c) => {
|
||||||
return c.json(await Config.getConsoleState())
|
const [consoleState, groups] = await Promise.all([Config.getConsoleState(), Account.orgsByAccount()])
|
||||||
|
return c.json({
|
||||||
|
...consoleState,
|
||||||
|
switchableOrgCount: groups.reduce((count, group) => count + group.orgs.length, 0),
|
||||||
|
})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.get(
|
.get(
|
||||||
|
|||||||
Reference in New Issue
Block a user