1- import { createResource , createMemo } from "solid-js"
1+ import { createResource , createMemo , createSignal } from "solid-js"
2+ import { TextAttributes } from "@opentui/core"
23import { DialogSelect } from "../ui/dialog-select"
34import { useSDK } from "../context/sdk"
45import { useDialog } from "../ui/dialog"
56import { useToast } from "../ui/toast"
67import { useTheme } from "../context/theme"
8+ import { errorMessage } from "../util/error"
79import type { ExperimentalConsoleListOrgsResponse } from "@opencode-ai/sdk/v2"
810
911type OrgOption = ExperimentalConsoleListOrgsResponse [ "orgs" ] [ number ]
@@ -25,14 +27,26 @@ export function DialogConsoleOrg() {
2527 const toast = useToast ( )
2628 const { theme } = useTheme ( )
2729
28- const [ orgs ] = createResource ( async ( ) => {
29- const result = await sdk . client . experimental . console . listOrgs ( { } , { throwOnError : true } )
30- return result . data ?. orgs ?? [ ]
31- } )
30+ const [ loadError , setLoadError ] = createSignal < unknown > ( )
31+
32+ const [ orgs ] = createResource ( ( ) =>
33+ sdk . client . experimental . console
34+ . listOrgs ( { } , { throwOnError : true } )
35+ . then ( ( result ) => result . data ?. orgs ?? [ ] )
36+ // Catch so the rejected resource never reaches the memos below: reading
37+ // orgs() in an errored state re-throws and tears down the dialog.
38+ . catch ( ( error ) => {
39+ setLoadError ( error )
40+ return undefined
41+ } ) ,
42+ )
43+
44+ const showError = createMemo ( ( ) => Boolean ( loadError ( ) ) )
3245
3346 const current = createMemo ( ( ) => orgs ( ) ?. find ( ( item ) => item . active ) )
3447
3548 const options = createMemo ( ( ) => {
49+ if ( showError ( ) ) return [ ]
3650 const listed = orgs ( )
3751 if ( listed === undefined ) {
3852 return [
@@ -99,5 +113,23 @@ export function DialogConsoleOrg() {
99113 } ) )
100114 } )
101115
102- return < DialogSelect < string | OrgOption > title = "Switch org" options = { options ( ) } current = { current ( ) } />
116+ return (
117+ < DialogSelect < string | OrgOption >
118+ title = "Switch org"
119+ options = { options ( ) }
120+ current = { current ( ) }
121+ renderFilter = { ! showError ( ) }
122+ locked = { showError ( ) }
123+ emptyView = {
124+ showError ( ) ? (
125+ < box paddingLeft = { 4 } paddingRight = { 4 } >
126+ < text fg = { theme . error } attributes = { TextAttributes . BOLD } >
127+ Could not load orgs
128+ </ text >
129+ < text fg = { theme . textMuted } > { errorMessage ( loadError ( ) ) } </ text >
130+ </ box >
131+ ) : undefined
132+ }
133+ />
134+ )
103135}
0 commit comments