-
Notifications
You must be signed in to change notification settings - Fork 7.4k
feat(settings): add save feedback for preferences changes #2261
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
Open
lspassos1
wants to merge
3
commits into
koala73:main
Choose a base branch
from
lspassos1:feat/settings-save-feedback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export function showToast(message: string, durationMs = 3000): void { | ||
| document.querySelector('.toast-notification')?.remove(); | ||
|
|
||
| const toast = document.createElement('div'); | ||
| toast.className = 'toast-notification'; | ||
| toast.setAttribute('role', 'status'); | ||
| toast.textContent = message; | ||
|
|
||
| document.body.appendChild(toast); | ||
| requestAnimationFrame(() => toast.classList.add('visible')); | ||
| setTimeout(() => { | ||
| toast.classList.remove('visible'); | ||
| setTimeout(() => toast.remove(), 300); | ||
| }, durationMs); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { describe, it } from 'node:test'; | ||
| import assert from 'node:assert/strict'; | ||
| import { readFileSync } from 'node:fs'; | ||
| import { dirname, join, resolve } from 'node:path'; | ||
| import { fileURLToPath } from 'node:url'; | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
| const root = resolve(__dirname, '..'); | ||
|
|
||
| function src(path) { | ||
| return readFileSync(join(root, path), 'utf-8'); | ||
| } | ||
|
|
||
| function extractMethodBody(source, methodName) { | ||
| const signature = `${methodName}(): void {`; | ||
| const start = source.indexOf(signature); | ||
| assert.notEqual(start, -1, `${methodName}() not found`); | ||
|
|
||
| let depth = 1; | ||
| let i = start + signature.length; | ||
| while (i < source.length && depth > 0) { | ||
| const char = source[i]; | ||
| if (char === '{') depth += 1; | ||
| if (char === '}') depth -= 1; | ||
| i += 1; | ||
| } | ||
|
|
||
| assert.equal(depth, 0, `${methodName}() body did not terminate`); | ||
| return source.slice(start + signature.length, i - 1); | ||
| } | ||
|
|
||
| describe('settings save feedback guardrails', () => { | ||
| const toastSrc = src('src/utils/toast.ts'); | ||
| const settingsSrc = src('src/components/UnifiedSettings.ts'); | ||
| const prefsSrc = src('src/services/preferences-content.ts'); | ||
| const handlersSrc = src('src/app/event-handlers.ts'); | ||
| const countryIntelSrc = src('src/app/country-intel.ts'); | ||
|
|
||
| it('uses a shared body-level toast utility with role=status', () => { | ||
| assert.match(toastSrc, /export function showToast\(message: string, durationMs = 3000\): void/); | ||
| assert.match(toastSrc, /toast\.setAttribute\('role', 'status'\)/); | ||
| assert.match(toastSrc, /document\.querySelector\('\.toast-notification'\)\?\.remove\(\)/); | ||
| assert.match(toastSrc, /}, durationMs\);/); | ||
| }); | ||
|
|
||
| it('shows saved feedback for Preferences through renderPreferences callback', () => { | ||
| assert.match(settingsSrc, /onSettingSaved:\s*\(\)\s*=>\s*showToast\(t\('modals\.settingsWindow\.saved'\), 4000\)/); | ||
| assert.match(prefsSrc, /onSettingSaved\?: \(\) => void;/); | ||
| assert.match(prefsSrc, /host\.onSettingSaved\?\.\(\);/); | ||
| }); | ||
|
|
||
| it('keeps Panels save on inline status only', () => { | ||
| const saveBody = extractMethodBody(settingsSrc, 'savePanelChanges'); | ||
| assert.doesNotMatch(saveBody, /showToast\(/); | ||
| }); | ||
|
|
||
| it('removes duplicate global toast implementations from event handlers and country intel', () => { | ||
| assert.match(handlersSrc, /import \{ showToast \} from '@\/utils\/toast';/); | ||
| assert.match(countryIntelSrc, /import \{ showToast \} from '@\/utils\/toast';/); | ||
| assert.doesNotMatch(handlersSrc, /\n\s*showToast\(msg: string\): void \{/); | ||
| assert.doesNotMatch(countryIntelSrc, /\n\s*showToast\(msg: string\): void \{/); | ||
| }); | ||
|
|
||
| it('preserves UnifiedSettings toast duration for modal-originated feedback', () => { | ||
| assert.match(settingsSrc, /showToast\(t\('modals\.settingsWindow\.freePanelLimit', \{ max: String\(FREE_MAX_PANELS\) \}\), 4000\)/); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The pattern
/private savePanelChanges\(\): void \{([\s\S]*?)\n {2}\}/assumes the closing}ofsavePanelChangesis indented with exactly 2 spaces. Any formatting change (e.g., reformatter runs, indentation style shift) will silently break the assertion —saveMatchwill benull, theassert.okwill fail with a confusing message, and the real assertion aboutshowToastwill never be reached.Consider anchoring on the method name itself rather than its closing brace, or reading the entire file and checking the region between known method boundaries:
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.
Addressed in the latest push. The guardrail no longer depends on the closing-brace indentation; it now locates
savePanelChanges()by signature and extracts the body by walking brace depth before asserting thatshowToast(is absent.