fix(tui): render console org load errors inline (#33040)
This commit is contained in:
parent
f092bafe88
commit
e6cdc543f3
1 changed files with 38 additions and 6 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
import { createResource, createMemo } from "solid-js"
|
import { createResource, createMemo, createSignal } from "solid-js"
|
||||||
|
import { TextAttributes } from "@opentui/core"
|
||||||
import { DialogSelect } from "../ui/dialog-select"
|
import { DialogSelect } from "../ui/dialog-select"
|
||||||
import { useSDK } from "../context/sdk"
|
import { useSDK } from "../context/sdk"
|
||||||
import { useDialog } from "../ui/dialog"
|
import { useDialog } from "../ui/dialog"
|
||||||
import { useToast } from "../ui/toast"
|
import { useToast } from "../ui/toast"
|
||||||
import { useTheme } from "../context/theme"
|
import { useTheme } from "../context/theme"
|
||||||
|
import { errorMessage } from "../util/error"
|
||||||
import type { ExperimentalConsoleListOrgsResponse } from "@opencode-ai/sdk/v2"
|
import type { ExperimentalConsoleListOrgsResponse } from "@opencode-ai/sdk/v2"
|
||||||
|
|
||||||
type OrgOption = ExperimentalConsoleListOrgsResponse["orgs"][number]
|
type OrgOption = ExperimentalConsoleListOrgsResponse["orgs"][number]
|
||||||
|
|
@ -25,14 +27,26 @@ export function DialogConsoleOrg() {
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { theme } = useTheme()
|
const { theme } = useTheme()
|
||||||
|
|
||||||
const [orgs] = createResource(async () => {
|
const [loadError, setLoadError] = createSignal<unknown>()
|
||||||
const result = await sdk.client.experimental.console.listOrgs({}, { throwOnError: true })
|
|
||||||
return result.data?.orgs ?? []
|
const [orgs] = createResource(() =>
|
||||||
})
|
sdk.client.experimental.console
|
||||||
|
.listOrgs({}, { throwOnError: true })
|
||||||
|
.then((result) => result.data?.orgs ?? [])
|
||||||
|
// Catch so the rejected resource never reaches the memos below: reading
|
||||||
|
// orgs() in an errored state re-throws and tears down the dialog.
|
||||||
|
.catch((error) => {
|
||||||
|
setLoadError(error)
|
||||||
|
return undefined
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
|
const showError = createMemo(() => Boolean(loadError()))
|
||||||
|
|
||||||
const current = createMemo(() => orgs()?.find((item) => item.active))
|
const current = createMemo(() => orgs()?.find((item) => item.active))
|
||||||
|
|
||||||
const options = createMemo(() => {
|
const options = createMemo(() => {
|
||||||
|
if (showError()) return []
|
||||||
const listed = orgs()
|
const listed = orgs()
|
||||||
if (listed === undefined) {
|
if (listed === undefined) {
|
||||||
return [
|
return [
|
||||||
|
|
@ -99,5 +113,23 @@ export function DialogConsoleOrg() {
|
||||||
}))
|
}))
|
||||||
})
|
})
|
||||||
|
|
||||||
return <DialogSelect<string | OrgOption> title="Switch org" options={options()} current={current()} />
|
return (
|
||||||
|
<DialogSelect<string | OrgOption>
|
||||||
|
title="Switch org"
|
||||||
|
options={options()}
|
||||||
|
current={current()}
|
||||||
|
renderFilter={!showError()}
|
||||||
|
locked={showError()}
|
||||||
|
emptyView={
|
||||||
|
showError() ? (
|
||||||
|
<box paddingLeft={4} paddingRight={4}>
|
||||||
|
<text fg={theme.error} attributes={TextAttributes.BOLD}>
|
||||||
|
Could not load orgs
|
||||||
|
</text>
|
||||||
|
<text fg={theme.textMuted}>{errorMessage(loadError())}</text>
|
||||||
|
</box>
|
||||||
|
) : undefined
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue