mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 21:15:57 +03:00
feat(tui): restore sidebar onboarding (#50475)
This commit is contained in:
committed by
GitHub
Unverified
parent
643c4c3500
commit
532f25d0d4
@@ -1,12 +1,83 @@
|
||||
import { Plugin } from "@opencode/plugin/tui"
|
||||
import { createMemo, Show } from "solid-js"
|
||||
import { useTerminalDimensions } from "@opentui/solid"
|
||||
import { FilePath } from "../../ui/file-path"
|
||||
import { useWorkingDirectoryActions } from "../../ui/working-directory-actions"
|
||||
import { usePromptMove } from "../../component/prompt/move"
|
||||
import { hasConnectedProvider } from "../../util/connected-provider"
|
||||
|
||||
function View(props: { context: Plugin.Context; sessionID: string }) {
|
||||
export function SidebarOnboarding(props: { context: Plugin.Context; sessionID: string }) {
|
||||
const dimensions = useTerminalDimensions()
|
||||
const [onboarding, updateOnboarding] = props.context.storage.store("getting-started", {
|
||||
initial: { dismissed: false },
|
||||
})
|
||||
const session = createMemo(() => props.context.data.session.get(props.sessionID))
|
||||
const integrations = createMemo(() =>
|
||||
props.context.data.location.integration.list(session()?.location ?? props.context.location),
|
||||
)
|
||||
const showOnboarding = createMemo(() => {
|
||||
if (dimensions().height < 22) return false
|
||||
const list = integrations()
|
||||
if (!list) return false
|
||||
return !onboarding.dismissed && !hasConnectedProvider(list)
|
||||
})
|
||||
|
||||
return (
|
||||
<Show when={showOnboarding()}>
|
||||
<box
|
||||
id="sidebar.footer.getting-started"
|
||||
backgroundColor={props.context.theme.background.raised.high}
|
||||
paddingTop={1}
|
||||
paddingBottom={1}
|
||||
paddingLeft={2}
|
||||
paddingRight={2}
|
||||
flexDirection="row"
|
||||
gap={1}
|
||||
>
|
||||
<text flexShrink={0} fg={props.context.theme.text.base}>
|
||||
⬖
|
||||
</text>
|
||||
<box flexGrow={1} gap={1}>
|
||||
<box flexDirection="row" justifyContent="space-between">
|
||||
<text fg={props.context.theme.text.base}>
|
||||
<b>Getting started</b>
|
||||
</text>
|
||||
<text
|
||||
id="sidebar.footer.getting-started.dismiss"
|
||||
fg={props.context.theme.text.muted}
|
||||
onMouseUp={() => {
|
||||
void updateOnboarding((draft) => {
|
||||
draft.dismissed = true
|
||||
}).catch((error) => console.error("Failed to dismiss sidebar onboarding", error))
|
||||
}}
|
||||
>
|
||||
✕
|
||||
</text>
|
||||
</box>
|
||||
<text fg={props.context.theme.text.muted}>OpenCode includes free models so you can start immediately.</text>
|
||||
<text fg={props.context.theme.text.muted}>
|
||||
Connect from 75+ providers to use other models, including Claude, GPT, Gemini etc
|
||||
</text>
|
||||
<box
|
||||
id="sidebar.footer.getting-started.connect"
|
||||
flexDirection="row"
|
||||
gap={1}
|
||||
justifyContent="space-between"
|
||||
onMouseUp={() => props.context.keymap.dispatch("provider.connect")}
|
||||
>
|
||||
<text fg={props.context.theme.text.base}>Connect provider</text>
|
||||
<text fg={props.context.theme.text.muted}>/connect</text>
|
||||
</box>
|
||||
</box>
|
||||
</box>
|
||||
</Show>
|
||||
)
|
||||
}
|
||||
|
||||
function SidebarFooter(props: { context: Plugin.Context; sessionID: string }) {
|
||||
const session = createMemo(() => props.context.data.session.get(props.sessionID))
|
||||
const move = usePromptMove({
|
||||
projectID: () => props.context.data.session.get(props.sessionID)?.projectID,
|
||||
projectID: () => session()?.projectID,
|
||||
sessionID: () => props.sessionID,
|
||||
})
|
||||
const actions = useWorkingDirectoryActions({
|
||||
@@ -20,22 +91,25 @@ function View(props: { context: Plugin.Context; sessionID: string }) {
|
||||
return branch ? `${value}:${branch}` : value
|
||||
})
|
||||
return (
|
||||
<Show when={directory()}>
|
||||
{(value) => (
|
||||
<box
|
||||
id="sidebar.footer.location"
|
||||
onMouseOver={actions.onMouseOver}
|
||||
onMouseOut={actions.onMouseOut}
|
||||
onMouseUp={actions.onMouseUp}
|
||||
>
|
||||
<FilePath
|
||||
value={value()}
|
||||
maxWidth={38}
|
||||
fg={actions.hovered() ? props.context.theme.text.base : props.context.theme.text.muted}
|
||||
/>
|
||||
</box>
|
||||
)}
|
||||
</Show>
|
||||
<box gap={1}>
|
||||
<SidebarOnboarding context={props.context} sessionID={props.sessionID} />
|
||||
<Show when={directory()}>
|
||||
{(value) => (
|
||||
<box
|
||||
id="sidebar.footer.location"
|
||||
onMouseOver={actions.onMouseOver}
|
||||
onMouseOut={actions.onMouseOut}
|
||||
onMouseUp={actions.onMouseUp}
|
||||
>
|
||||
<FilePath
|
||||
value={value()}
|
||||
maxWidth={38}
|
||||
fg={actions.hovered() ? props.context.theme.text.base : props.context.theme.text.muted}
|
||||
/>
|
||||
</box>
|
||||
)}
|
||||
</Show>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -46,7 +120,7 @@ export default Plugin.define({
|
||||
// replace still takes the boundary over.
|
||||
context.ui.slot({
|
||||
append: "sidebar.footer",
|
||||
render: (props) => <View context={context} sessionID={props.sessionID} />,
|
||||
render: (props) => <SidebarFooter context={context} sessionID={props.sessionID} />,
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
@@ -0,0 +1,126 @@
|
||||
/** @jsxImportSource @opentui/solid */
|
||||
import { expect, test } from "bun:test"
|
||||
import { RGBA } from "@opentui/core"
|
||||
import { testRender } from "@opentui/solid"
|
||||
import type { Context } from "@opencode/plugin/tui/context"
|
||||
import { createStore, produce } from "solid-js/store"
|
||||
import { SidebarOnboarding } from "../../src/feature-plugins/sidebar/footer"
|
||||
|
||||
function context(options?: {
|
||||
dismissed?: boolean
|
||||
integrations?: Array<{ connections: unknown[] }>
|
||||
dispatched?: string[]
|
||||
}) {
|
||||
const color = RGBA.fromInts(200, 200, 200)
|
||||
const [onboarding, setOnboarding] = createStore({ dismissed: options?.dismissed ?? false })
|
||||
const location = { directory: "/workspace" }
|
||||
return {
|
||||
location,
|
||||
theme: {
|
||||
background: { raised: { high: color } },
|
||||
text: { base: color, muted: color },
|
||||
},
|
||||
storage: {
|
||||
store: () => [
|
||||
onboarding,
|
||||
(mutation: (draft: { dismissed: boolean }) => void) => {
|
||||
setOnboarding(produce(mutation))
|
||||
return Promise.resolve()
|
||||
},
|
||||
],
|
||||
},
|
||||
keymap: {
|
||||
dispatch: (id: string) => options?.dispatched?.push(id),
|
||||
},
|
||||
ui: {
|
||||
format: { path: (value: string) => value },
|
||||
},
|
||||
data: {
|
||||
session: {
|
||||
get: () => ({ location }),
|
||||
},
|
||||
location: {
|
||||
integration: { list: () => options?.integrations },
|
||||
vcs: { info: () => undefined },
|
||||
},
|
||||
},
|
||||
} as unknown as Context
|
||||
}
|
||||
|
||||
async function render(input: Context, height = 22) {
|
||||
const app = await testRender(
|
||||
() => (
|
||||
<box width={38}>
|
||||
<SidebarOnboarding context={input} sessionID="session" />
|
||||
</box>
|
||||
),
|
||||
{ width: 38, height },
|
||||
)
|
||||
await app.renderOnce()
|
||||
return app
|
||||
}
|
||||
|
||||
test("sidebar waits for integrations before showing onboarding", async () => {
|
||||
const app = await render(context())
|
||||
|
||||
try {
|
||||
expect(app.captureCharFrame()).not.toContain("Getting started")
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("sidebar preserves the compact layout when the onboarding card cannot fit", async () => {
|
||||
const app = await render(context({ integrations: [] }), 21)
|
||||
|
||||
try {
|
||||
expect(app.captureCharFrame()).not.toContain("Getting started")
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("sidebar shows onboarding without a connected integration", async () => {
|
||||
const app = await render(context({ integrations: [] }))
|
||||
|
||||
try {
|
||||
const frame = app.captureCharFrame()
|
||||
expect(frame).toContain("Getting started")
|
||||
expect(frame).toContain("OpenCode includes free models")
|
||||
expect(frame).toContain("Connect provider")
|
||||
expect(frame).toContain("/connect")
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("sidebar hides onboarding after an integration is connected or the card is dismissed", async () => {
|
||||
const connected = await render(context({ integrations: [{ connections: [{}] }] }))
|
||||
const dismissed = await render(context({ integrations: [], dismissed: true }))
|
||||
|
||||
try {
|
||||
expect(connected.captureCharFrame()).not.toContain("Getting started")
|
||||
expect(dismissed.captureCharFrame()).not.toContain("Getting started")
|
||||
} finally {
|
||||
connected.renderer.destroy()
|
||||
dismissed.renderer.destroy()
|
||||
}
|
||||
})
|
||||
|
||||
test("sidebar onboarding opens integrations and can be dismissed", async () => {
|
||||
const dispatched: string[] = []
|
||||
const app = await render(context({ integrations: [], dispatched }))
|
||||
|
||||
try {
|
||||
const connect = app.renderer.root.findDescendantById("sidebar.footer.getting-started.connect")!
|
||||
await app.mockMouse.click(connect.x, connect.y)
|
||||
expect(dispatched).toEqual(["provider.connect"])
|
||||
|
||||
const dismiss = app.renderer.root.findDescendantById("sidebar.footer.getting-started.dismiss")!
|
||||
await app.mockMouse.click(dismiss.x, dismiss.y)
|
||||
await app.renderOnce()
|
||||
expect(app.captureCharFrame()).not.toContain("Getting started")
|
||||
} finally {
|
||||
app.renderer.destroy()
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user