Skip to content

Commit 393688c

Browse files
authored
Add deep links to settings sections (#2355)
1 parent 57d9731 commit 393688c

File tree

21 files changed

+74
-16
lines changed

21 files changed

+74
-16
lines changed

webview-ui/src/App.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,28 @@ const App = () => {
4646
const settingsRef = useRef<SettingsViewRef>(null)
4747

4848
const switchTab = useCallback((newTab: Tab) => {
49+
setCurrentSection(undefined)
50+
4951
if (settingsRef.current?.checkUnsaveChanges) {
5052
settingsRef.current.checkUnsaveChanges(() => setTab(newTab))
5153
} else {
5254
setTab(newTab)
5355
}
5456
}, [])
5557

58+
const [currentSection, setCurrentSection] = useState<string | undefined>(undefined)
59+
5660
const onMessage = useCallback(
5761
(e: MessageEvent) => {
5862
const message: ExtensionMessage = e.data
5963

6064
if (message.type === "action" && message.action) {
6165
const newTab = tabsByMessageAction[message.action]
66+
const section = message.values?.section as string | undefined
6267

6368
if (newTab) {
6469
switchTab(newTab)
70+
setCurrentSection(section)
6571
}
6672
}
6773

@@ -104,7 +110,9 @@ const App = () => {
104110
{tab === "prompts" && <PromptsView onDone={() => switchTab("chat")} />}
105111
{tab === "mcp" && <McpView onDone={() => switchTab("chat")} />}
106112
{tab === "history" && <HistoryView onDone={() => switchTab("chat")} />}
107-
{tab === "settings" && <SettingsView ref={settingsRef} onDone={() => setTab("chat")} />}
113+
{tab === "settings" && (
114+
<SettingsView ref={settingsRef} onDone={() => switchTab("chat")} targetSection={currentSection} />
115+
)}
108116
<ChatView
109117
isHidden={tab !== "chat"}
110118
showAnnouncement={showAnnouncement}

webview-ui/src/components/chat/AutoApproveMenu.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,11 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => {
161161
}, [alwaysApproveResubmit, setAlwaysApproveResubmit])
162162

163163
const handleOpenSettings = useCallback(() => {
164-
window.postMessage({ type: "action", action: "settingsButtonClicked" })
164+
window.postMessage({
165+
type: "action",
166+
action: "settingsButtonClicked",
167+
values: { section: "autoApprove" },
168+
})
165169
}, [])
166170

167171
// Map action IDs to their specific handlers

webview-ui/src/components/chat/ChatTextArea.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,11 @@ const ChatTextArea = forwardRef<HTMLTextAreaElement, ChatTextAreaProps>(
10281028
]}
10291029
onChange={(value) => {
10301030
if (value === "settingsButtonClicked") {
1031-
vscode.postMessage({ type: "loadApiConfiguration", text: value })
1031+
vscode.postMessage({
1032+
type: "loadApiConfiguration",
1033+
text: value,
1034+
values: { section: "providers" },
1035+
})
10321036
} else {
10331037
vscode.postMessage({ type: "loadApiConfigurationById", text: value })
10341038
}

webview-ui/src/components/chat/ChatView.tsx

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import { getAllModes } from "../../../../src/shared/modes"
3232
import TelemetryBanner from "../common/TelemetryBanner"
3333
import { useAppTranslation } from "@/i18n/TranslationContext"
3434
import removeMd from "remove-markdown"
35-
35+
import { Trans } from "react-i18next"
3636
interface ChatViewProps {
3737
isHidden: boolean
3838
showAnnouncement: boolean
@@ -1006,17 +1006,28 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
10061006
<div className="flex items-center p-3 my-3 bg-vscode-inputValidation-warningBackground border border-vscode-inputValidation-warningBorder rounded">
10071007
<span className="codicon codicon-loading codicon-modifier-spin mr-2" />
10081008
<span className="text-vscode-foreground">
1009-
Still initializing checkpoint... If this takes too long, you can{" "}
1010-
<VSCodeLink
1011-
href="#"
1012-
onClick={(e) => {
1013-
e.preventDefault()
1014-
window.postMessage({ type: "action", action: "settingsButtonClicked" }, "*")
1009+
<Trans
1010+
i18nKey="chat:checkpoint.initializingWarning"
1011+
components={{
1012+
settingsLink: (
1013+
<VSCodeLink
1014+
href="#"
1015+
onClick={(e) => {
1016+
e.preventDefault()
1017+
window.postMessage(
1018+
{
1019+
type: "action",
1020+
action: "settingsButtonClicked",
1021+
values: { section: "checkpoints" },
1022+
},
1023+
"*",
1024+
)
1025+
}}
1026+
className="inline px-0.5"
1027+
/>
1028+
),
10151029
}}
1016-
className="inline px-0.5">
1017-
disable checkpoints in settings
1018-
</VSCodeLink>{" "}
1019-
and restart your task.
1030+
/>
10201031
</span>
10211032
</div>
10221033
),

webview-ui/src/components/common/TelemetryBanner.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ const TelemetryBanner = () => {
4040
}
4141

4242
const handleOpenSettings = () => {
43-
window.postMessage({ type: "action", action: "settingsButtonClicked" })
43+
window.postMessage({
44+
type: "action",
45+
action: "settingsButtonClicked",
46+
values: { section: "advanced" }, // Link directly to advanced settings with telemetry controls
47+
})
4448
}
4549

4650
return (

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ type SectionName = (typeof sectionNames)[number]
7878

7979
type SettingsViewProps = {
8080
onDone: () => void
81+
targetSection?: string
8182
}
8283

83-
const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone }, ref) => {
84+
const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone, targetSection }, ref) => {
8485
const { t } = useAppTranslation()
8586

8687
const extensionState = useExtensionState()
@@ -316,6 +317,17 @@ const SettingsView = forwardRef<SettingsViewRef, SettingsViewProps>(({ onDone },
316317

317318
const scrollToSection = (ref: React.RefObject<HTMLDivElement>) => ref.current?.scrollIntoView()
318319

320+
// Scroll to target section when specified
321+
useEffect(() => {
322+
if (targetSection) {
323+
const sectionObj = sections.find((section) => section.id === targetSection)
324+
if (sectionObj && sectionObj.ref.current) {
325+
// Use setTimeout to ensure the scroll happens after render
326+
setTimeout(() => scrollToSection(sectionObj.ref), 500)
327+
}
328+
}
329+
}, [targetSection, sections])
330+
319331
return (
320332
<Tab>
321333
<TabHeader className="flex justify-between items-center gap-2">

webview-ui/src/i18n/locales/ca/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"checkpoint": {
9595
"initial": "Punt de control inicial",
9696
"regular": "Punt de control",
97+
"initializingWarning": "Encara s'està inicialitzant el punt de control... Si això triga massa, pots desactivar els punts de control a la <settingsLink>configuració</settingsLink> i reiniciar la teva tasca.",
9798
"menu": {
9899
"viewDiff": "Veure diferències",
99100
"restore": "Restaurar punt de control",

webview-ui/src/i18n/locales/de/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"checkpoint": {
9595
"initial": "Initialer Checkpoint",
9696
"regular": "Checkpoint",
97+
"initializingWarning": "Checkpoint wird noch initialisiert... Falls dies zu lange dauert, kannst du Checkpoints in den <settingsLink>Einstellungen</settingsLink> deaktivieren und deine Aufgabe neu starten.",
9798
"menu": {
9899
"viewDiff": "Unterschiede anzeigen",
99100
"restore": "Checkpoint wiederherstellen",

webview-ui/src/i18n/locales/en/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"checkpoint": {
9393
"initial": "Initial Checkpoint",
9494
"regular": "Checkpoint",
95+
"initializingWarning": "Still initializing checkpoint... If this takes too long, you can disable checkpoints in <settingsLink>settings</settingsLink> and restart your task.",
9596
"menu": {
9697
"viewDiff": "View Diff",
9798
"restore": "Restore Checkpoint",

webview-ui/src/i18n/locales/es/chat.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
"checkpoint": {
9595
"initial": "Punto de control inicial",
9696
"regular": "Punto de control",
97+
"initializingWarning": "Todavía inicializando el punto de control... Si esto tarda demasiado, puedes desactivar los puntos de control en la <settingsLink>configuración</settingsLink> y reiniciar tu tarea.",
9798
"menu": {
9899
"viewDiff": "Ver diferencias",
99100
"restore": "Restaurar punto de control",

0 commit comments

Comments
 (0)