Skip to content

Commit c6ebc7f

Browse files
authored
fix(tui): only show org switch affordances when useful (anomalyco#21054)
1 parent 9856636 commit c6ebc7f

File tree

5 files changed

+33
-15
lines changed

5 files changed

+33
-15
lines changed

packages/opencode/src/cli/cmd/tui/app.tsx

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -630,19 +630,23 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
630630
},
631631
category: "Provider",
632632
},
633-
{
634-
title: "Switch org",
635-
value: "console.org.switch",
636-
suggested: Boolean(sync.data.console_state.activeOrgName),
637-
slash: {
638-
name: "org",
639-
aliases: ["orgs", "switch-org"],
640-
},
641-
onSelect: () => {
642-
dialog.replace(() => <DialogConsoleOrg />)
643-
},
644-
category: "Provider",
645-
},
633+
...(sync.data.console_state.switchableOrgCount > 1
634+
? [
635+
{
636+
title: "Switch org",
637+
value: "console.org.switch",
638+
suggested: Boolean(sync.data.console_state.activeOrgName),
639+
slash: {
640+
name: "org",
641+
aliases: ["orgs", "switch-org"],
642+
},
643+
onSelect: () => {
644+
dialog.replace(() => <DialogConsoleOrg />)
645+
},
646+
category: "Provider",
647+
},
648+
]
649+
: []),
646650
{
647651
title: "View status",
648652
keybind: "status_view",

packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ export function Prompt(props: PromptProps) {
9696
const shell = createMemo(() => props.placeholders?.shell ?? [])
9797
const [auto, setAuto] = createSignal<AutocompleteRef>()
9898
const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
99+
const canSwitchOrgs = createMemo(() => sync.data.console_state.switchableOrgCount > 1)
99100
const currentProviderLabel = createMemo(() => {
100101
const current = local.model.current()
101102
const provider = local.model.parsed().provider
@@ -1118,7 +1119,13 @@ export function Prompt(props: PromptProps) {
11181119
<box flexDirection="row" gap={1} alignItems="center">
11191120
{props.right}
11201121
<Show when={activeOrgName()}>
1121-
<text fg={theme.textMuted} onMouseUp={() => command.trigger("console.org.switch")}>
1122+
<text
1123+
fg={theme.textMuted}
1124+
onMouseUp={() => {
1125+
if (!canSwitchOrgs()) return
1126+
command.trigger("console.org.switch")
1127+
}}
1128+
>
11221129
{`${CONSOLE_MANAGED_ICON} ${activeOrgName()}`}
11231130
</text>
11241131
</Show>

packages/opencode/src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,6 +1469,7 @@ export namespace Config {
14691469
consoleState: {
14701470
consoleManagedProviders: Array.from(consoleManagedProviders),
14711471
activeOrgName,
1472+
switchableOrgCount: 0,
14721473
},
14731474
}
14741475
})

packages/opencode/src/config/console-state.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ import z from "zod"
33
export const ConsoleState = z.object({
44
consoleManagedProviders: z.array(z.string()),
55
activeOrgName: z.string().optional(),
6+
switchableOrgCount: z.number().int().nonnegative(),
67
})
78

89
export type ConsoleState = z.infer<typeof ConsoleState>
910

1011
export const emptyConsoleState: ConsoleState = {
1112
consoleManagedProviders: [],
1213
activeOrgName: undefined,
14+
switchableOrgCount: 0,
1315
}

packages/opencode/src/server/routes/experimental.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export const ExperimentalRoutes = lazy(() =>
5454
},
5555
}),
5656
async (c) => {
57-
return c.json(await Config.getConsoleState())
57+
const [consoleState, groups] = await Promise.all([Config.getConsoleState(), Account.orgsByAccount()])
58+
return c.json({
59+
...consoleState,
60+
switchableOrgCount: groups.reduce((count, group) => count + group.orgs.length, 0),
61+
})
5862
},
5963
)
6064
.get(

0 commit comments

Comments
 (0)