Skip to content

Commit 8552967

Browse files
kitlangtoncavaldos
authored andcommitted
fix(tui): only show org switch affordances when useful (anomalyco#21054)
1 parent 57c20e9 commit 8552967

5 files changed

Lines changed: 33 additions & 15 deletions

File tree

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -665,19 +665,23 @@ function App(props: { onSnapshot?: () => Promise<string[]> }) {
665665
},
666666
category: "Provider",
667667
},
668-
{
669-
title: "Switch org",
670-
value: "console.org.switch",
671-
suggested: Boolean(sync.data.console_state.activeOrgName),
672-
slash: {
673-
name: "org",
674-
aliases: ["orgs", "switch-org"],
675-
},
676-
onSelect: () => {
677-
dialog.replace(() => <DialogConsoleOrg />)
678-
},
679-
category: "Provider",
680-
},
668+
...(sync.data.console_state.switchableOrgCount > 1
669+
? [
670+
{
671+
title: "Switch org",
672+
value: "console.org.switch",
673+
suggested: Boolean(sync.data.console_state.activeOrgName),
674+
slash: {
675+
name: "org",
676+
aliases: ["orgs", "switch-org"],
677+
},
678+
onSelect: () => {
679+
dialog.replace(() => <DialogConsoleOrg />)
680+
},
681+
category: "Provider",
682+
},
683+
]
684+
: []),
681685
{
682686
title: "View status",
683687
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
@@ -108,6 +108,7 @@ export function Prompt(props: PromptProps) {
108108
const shell = createMemo(() => props.placeholders?.shell ?? [])
109109
const [auto, setAuto] = createSignal<AutocompleteRef>()
110110
const activeOrgName = createMemo(() => sync.data.console_state.activeOrgName)
111+
const canSwitchOrgs = createMemo(() => sync.data.console_state.switchableOrgCount > 1)
111112
const currentProviderLabel = createMemo(() => {
112113
const current = local.model.current()
113114
const provider = local.model.parsed().provider
@@ -1181,7 +1182,13 @@ export function Prompt(props: PromptProps) {
11811182
<box flexDirection="row" gap={1} alignItems="center">
11821183
{props.right}
11831184
<Show when={activeOrgName()}>
1184-
<text fg={theme.textMuted} onMouseUp={() => command.trigger("console.org.switch")}>
1185+
<text
1186+
fg={theme.textMuted}
1187+
onMouseUp={() => {
1188+
if (!canSwitchOrgs()) return
1189+
command.trigger("console.org.switch")
1190+
}}
1191+
>
11851192
{`${CONSOLE_MANAGED_ICON} ${activeOrgName()}`}
11861193
</text>
11871194
</Show>

packages/opencode/src/config/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,7 @@ export namespace Config {
14381438
consoleState: {
14391439
consoleManagedProviders: Array.from(consoleManagedProviders),
14401440
activeOrgName,
1441+
switchableOrgCount: 0,
14411442
},
14421443
}
14431444
})

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)