-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix: improve save button activation in prompts settings (#5780) #8267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
f913f9c
7eae039
358a76b
61aed25
93ea9e0
bf3f2ff
cc26220
cae2337
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -223,12 +223,13 @@ describe("PromptsView", () => { | |
| const changeEvent = new Event("change", { bubbles: true }) | ||
| fireEvent(textarea, changeEvent) | ||
|
|
||
| // The component calls setCustomInstructions with value || undefined | ||
| // Since empty string is falsy, it should be undefined | ||
| expect(setCustomInstructions).toHaveBeenCalledWith(undefined) | ||
| // The component calls setCustomInstructions with value ?? undefined | ||
| // With nullish coalescing, empty string is preserved (not treated as nullish) | ||
| expect(setCustomInstructions).toHaveBeenCalledWith("") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test Coverage Gap: While the test correctly verifies the onChange behavior with nullish coalescing, it doesn't test the actual save functionality or the trimming that should happen on save. Consider adding tests for the complete save flow. |
||
| // The postMessage call will have multiple calls, we need to check the right one | ||
| expect(vscode.postMessage).toHaveBeenCalledWith({ | ||
| type: "customInstructions", | ||
| text: undefined, | ||
| text: "", // empty string is now preserved with ?? operator | ||
| }) | ||
| }) | ||
| }) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,14 +56,31 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom | |
| }, []) | ||
|
|
||
| const updateSupportPrompt = (type: SupportPromptType, value: string | undefined) => { | ||
| // Don't trim during editing to preserve intentional whitespace | ||
| // Use nullish coalescing to preserve empty strings | ||
| const finalValue = value ?? undefined | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Using |
||
|
|
||
| if (type === "CONDENSE") { | ||
| setCustomCondensingPrompt(value || supportPrompt.default.CONDENSE) | ||
| setCustomCondensingPrompt(finalValue ?? supportPrompt.default.CONDENSE) | ||
| vscode.postMessage({ | ||
| type: "updateCondensingPrompt", | ||
| text: value || supportPrompt.default.CONDENSE, | ||
| text: finalValue ?? supportPrompt.default.CONDENSE, | ||
| }) | ||
| // Also update the customSupportPrompts to trigger change detection | ||
| const updatedPrompts = { ...customSupportPrompts } | ||
| if (finalValue === undefined) { | ||
| delete updatedPrompts[type] | ||
| } else { | ||
| updatedPrompts[type] = finalValue | ||
| } | ||
| setCustomSupportPrompts(updatedPrompts) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical Issue: This state update for CONDENSE type is redundant. The parent component already manages Consider removing lines 69-76 since the state is already being updated properly through the parent's setter function. |
||
| } else { | ||
| const updatedPrompts = { ...customSupportPrompts, [type]: value } | ||
| const updatedPrompts = { ...customSupportPrompts } | ||
| if (finalValue === undefined) { | ||
| delete updatedPrompts[type] | ||
| } else { | ||
| updatedPrompts[type] = finalValue | ||
| } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: This pattern of updating const updatePromptsObject = (prompts: Record<string, string | undefined>, key: string, value: string | undefined) => {
const updated = { ...prompts };
if (value === undefined) {
delete updated[key];
} else {
updated[key] = value;
}
return updated;
} |
||
| setCustomSupportPrompts(updatedPrompts) | ||
| } | ||
| } | ||
|
|
@@ -75,6 +92,10 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom | |
| type: "updateCondensingPrompt", | ||
| text: supportPrompt.default.CONDENSE, | ||
| }) | ||
| // Also update the customSupportPrompts to trigger change detection | ||
| const updatedPrompts = { ...customSupportPrompts } | ||
| delete updatedPrompts[type] | ||
| setCustomSupportPrompts(updatedPrompts) | ||
| } else { | ||
| const updatedPrompts = { ...customSupportPrompts } | ||
| delete updatedPrompts[type] | ||
|
|
@@ -147,10 +168,9 @@ const PromptsSettings = ({ customSupportPrompts, setCustomSupportPrompts }: Prom | |
| value={getSupportPromptValue(activeSupportOption)} | ||
| onChange={(e) => { | ||
| const value = | ||
| (e as unknown as CustomEvent)?.detail?.target?.value || | ||
| (e as unknown as CustomEvent)?.detail?.target?.value ?? | ||
| ((e as any).target as HTMLTextAreaElement).value | ||
| const trimmedValue = value.trim() | ||
| updateSupportPrompt(activeSupportOption, trimmedValue || undefined) | ||
| updateSupportPrompt(activeSupportOption, value) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical Issue: The PR description mentions "Trimming only happens on save, not on every keystroke", but I don't see any trimming logic when the Save button is actually clicked. The values should be trimmed before being persisted to storage. Consider adding a save handler that trims values before persisting them. |
||
| }} | ||
| rows={6} | ||
| className="w-full" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: This still trims during onChange, which conflicts with preserving whitespace while editing. Recommend posting the raw value here and trimming only on save to avoid state/message mismatches.
P3: Minor:
?? undefinedaftertrim()is redundant sincetrim()always returns a string.