Skip to content

Commit 1f07a77

Browse files
authored
Merge pull request RooCodeInc#921 from RooVetGit/welcome_screen_tweaks
Hide custom temp on welcome view and make submit button more intuitive
2 parents b194408 + 439c46c commit 1f07a77

File tree

3 files changed

+97
-24
lines changed

3 files changed

+97
-24
lines changed

webview-ui/src/components/settings/ApiOptions.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ import { RequestyModelPicker } from "./RequestyModelPicker"
4848
interface ApiOptionsProps {
4949
apiErrorMessage?: string
5050
modelIdErrorMessage?: string
51+
fromWelcomeView?: boolean
5152
}
5253

53-
const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) => {
54+
const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage, fromWelcomeView }: ApiOptionsProps) => {
5455
const { apiConfiguration, uriScheme, handleInputChange } = useExtensionState()
5556
const [ollamaModels, setOllamaModels] = useState<string[]>([])
5657
const [lmStudioModels, setLmStudioModels] = useState<string[]>([])
@@ -1391,17 +1392,19 @@ const ApiOptions = ({ apiErrorMessage, modelIdErrorMessage }: ApiOptionsProps) =
13911392
</>
13921393
)}
13931394

1394-
<div style={{ marginTop: "10px" }}>
1395-
<TemperatureControl
1396-
value={apiConfiguration?.modelTemperature}
1397-
onChange={(value) => {
1398-
handleInputChange("modelTemperature")({
1399-
target: { value },
1400-
})
1401-
}}
1402-
maxValue={2}
1403-
/>
1404-
</div>
1395+
{!fromWelcomeView && (
1396+
<div style={{ marginTop: "10px" }}>
1397+
<TemperatureControl
1398+
value={apiConfiguration?.modelTemperature}
1399+
onChange={(value) => {
1400+
handleInputChange("modelTemperature")({
1401+
target: { value },
1402+
})
1403+
}}
1404+
maxValue={2}
1405+
/>
1406+
</div>
1407+
)}
14051408

14061409
{modelIdErrorMessage && (
14071410
<p
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { render, screen } from "@testing-library/react"
2+
import ApiOptions from "../ApiOptions"
3+
import { ExtensionStateContextProvider } from "../../../context/ExtensionStateContext"
4+
5+
// Mock VSCode components
6+
jest.mock("@vscode/webview-ui-toolkit/react", () => ({
7+
VSCodeTextField: ({ children, value, onBlur }: any) => (
8+
<div>
9+
{children}
10+
<input type="text" value={value} onChange={onBlur} />
11+
</div>
12+
),
13+
VSCodeLink: ({ children, href }: any) => <a href={href}>{children}</a>,
14+
VSCodeRadio: ({ children, value, checked }: any) => <input type="radio" value={value} checked={checked} />,
15+
VSCodeRadioGroup: ({ children }: any) => <div>{children}</div>,
16+
}))
17+
18+
// Mock other components
19+
jest.mock("vscrui", () => ({
20+
Dropdown: ({ children, value, onChange }: any) => (
21+
<select value={value} onChange={onChange}>
22+
{children}
23+
</select>
24+
),
25+
Checkbox: ({ children, checked, onChange }: any) => (
26+
<label>
27+
<input type="checkbox" checked={checked} onChange={(e) => onChange(e.target.checked)} />
28+
{children}
29+
</label>
30+
),
31+
Pane: ({ children }: any) => <div>{children}</div>,
32+
}))
33+
34+
jest.mock("../TemperatureControl", () => ({
35+
TemperatureControl: ({ value, onChange }: any) => (
36+
<div data-testid="temperature-control">
37+
<input
38+
type="range"
39+
value={value || 0}
40+
onChange={(e) => onChange(parseFloat(e.target.value))}
41+
min={0}
42+
max={2}
43+
step={0.1}
44+
/>
45+
</div>
46+
),
47+
}))
48+
49+
describe("ApiOptions", () => {
50+
const renderApiOptions = (props = {}) => {
51+
render(
52+
<ExtensionStateContextProvider>
53+
<ApiOptions {...props} />
54+
</ExtensionStateContextProvider>,
55+
)
56+
}
57+
58+
it("shows temperature control by default", () => {
59+
renderApiOptions()
60+
expect(screen.getByTestId("temperature-control")).toBeInTheDocument()
61+
})
62+
63+
it("hides temperature control when fromWelcomeView is true", () => {
64+
renderApiOptions({ fromWelcomeView: true })
65+
expect(screen.queryByTestId("temperature-control")).not.toBeInTheDocument()
66+
})
67+
})

webview-ui/src/components/welcome/WelcomeView.tsx

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { VSCodeButton } from "@vscode/webview-ui-toolkit/react"
2-
import { useEffect, useState } from "react"
2+
import { useState } from "react"
33
import { useExtensionState } from "../../context/ExtensionStateContext"
44
import { validateApiConfiguration } from "../../utils/validate"
55
import { vscode } from "../../utils/vscode"
@@ -8,18 +8,18 @@ import ApiOptions from "../settings/ApiOptions"
88
const WelcomeView = () => {
99
const { apiConfiguration } = useExtensionState()
1010

11-
const [apiErrorMessage, setApiErrorMessage] = useState<string | undefined>(undefined)
12-
13-
const disableLetsGoButton = apiErrorMessage !== null && apiErrorMessage !== undefined
11+
const [errorMessage, setErrorMessage] = useState<string | undefined>(undefined)
1412

1513
const handleSubmit = () => {
14+
const error = validateApiConfiguration(apiConfiguration)
15+
if (error) {
16+
setErrorMessage(error)
17+
return
18+
}
19+
setErrorMessage(undefined)
1620
vscode.postMessage({ type: "apiConfiguration", apiConfiguration })
1721
}
1822

19-
useEffect(() => {
20-
setApiErrorMessage(validateApiConfiguration(apiConfiguration))
21-
}, [apiConfiguration])
22-
2323
return (
2424
<div style={{ position: "fixed", top: 0, left: 0, right: 0, bottom: 0, padding: "0 20px" }}>
2525
<h2>Hi, I'm Roo!</h2>
@@ -33,10 +33,13 @@ const WelcomeView = () => {
3333
<b>To get started, this extension needs an API provider.</b>
3434

3535
<div style={{ marginTop: "10px" }}>
36-
<ApiOptions />
37-
<VSCodeButton onClick={handleSubmit} disabled={disableLetsGoButton} style={{ marginTop: "3px" }}>
38-
Let's go!
39-
</VSCodeButton>
36+
<ApiOptions fromWelcomeView />
37+
<div style={{ display: "flex", flexDirection: "column", gap: "5px" }}>
38+
<VSCodeButton onClick={handleSubmit} style={{ marginTop: "3px" }}>
39+
Let's go!
40+
</VSCodeButton>
41+
{errorMessage && <span className="text-destructive">{errorMessage}</span>}
42+
</div>
4043
</div>
4144
</div>
4245
)

0 commit comments

Comments
 (0)