-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Fixing issue when cookie and filter control are enabled #8354
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
djhvscf
wants to merge
8
commits into
develop
Choose a base branch
from
issue-8246
base: develop
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.
+368
−11
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8e006e5
Fixing issue when cookie and filter control are enabled
djhvscf f93e577
Add missing file
djhvscf fba6fa9
Fix comments from AI
djhvscf 23f6157
Potential fix for pull request finding
djhvscf dc250e3
Potential fix for pull request finding
djhvscf cae4f37
Fix lint
djhvscf 4827766
Fix copilot comments
djhvscf 534ebc4
Merge remote-tracking branch 'origin/develop' into issue-8246
djhvscf 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,184 @@ | ||
| import fs from 'node:fs' | ||
| import path from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
| import { beforeAll, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)) | ||
| const FILTER_CONTROL_PATH = path.resolve( | ||
| __dirname, | ||
| '../../src/extensions/filter-control/bootstrap-table-filter-control.js' | ||
| ) | ||
| const FILTER_CONTROL_UTILS_PATH = path.resolve( | ||
| __dirname, | ||
| '../../src/extensions/filter-control/utils.js' | ||
| ) | ||
|
|
||
| describe('filter-control issue #8246', () => { | ||
| describe('source regression guards', () => { | ||
| let mainSource | ||
| let utilsSource | ||
|
|
||
| beforeAll(() => { | ||
| mainSource = fs.readFileSync(FILTER_CONTROL_PATH, 'utf-8') | ||
| utilsSource = fs.readFileSync(FILTER_CONTROL_UTILS_PATH, 'utf-8') | ||
| }) | ||
|
|
||
| it('triggerSearch() accepts an isInitial parameter and forwards it via trigger data', () => { | ||
| const match = mainSource.match(/triggerSearch\s*\([^)]*\)\s*\{[\s\S]*?\n {2}\}/) | ||
|
|
||
| expect(match, 'triggerSearch block must be present').not.toBeNull() | ||
| const body = match[0] | ||
|
|
||
| expect(body).toMatch(/triggerSearch\s*\(\s*isInitial\s*=\s*false\s*\)/) | ||
| expect(body).toMatch(/\.trigger\('change',\s*\{\s*isInitial\s*\}\)/) | ||
| expect(body).toMatch(/\.trigger\('keyup',\s*\{\s*isInitial\s*\}\)/) | ||
| }) | ||
|
djhvscf marked this conversation as resolved.
Outdated
|
||
|
|
||
| it('createControls calls triggerSearch(true) for the initial render', () => { | ||
| expect(utilsSource).toMatch(/that\.triggerSearch\s*\(\s*true\s*\)/) | ||
| }) | ||
|
|
||
| it('keyup handler reads isInitial from event data and forwards to onColumnSearch', () => { | ||
| // capture from the keyup binding up to (but not including) the next binding | ||
| const m = utilsSource.match(/header\.off\('keyup',\s*'input'\)[\s\S]*?(?=header\.off\(|$)/) | ||
|
|
||
| expect(m, 'keyup handler must be present').not.toBeNull() | ||
| const body = m[0] | ||
|
|
||
| expect(body).toMatch(/const isInitial\s*=\s*!!\(obj && obj\.isInitial\)/) | ||
| expect(body).toMatch(/onColumnSearch\(\{[^}]*isInitial[^}]*\}\)/) | ||
| }) | ||
|
|
||
| it('change handler on select reads isInitial from event data and forwards to onColumnSearch', () => { | ||
| const m = utilsSource.match(/header\.off\('change',\s*'select'\)[\s\S]*?(?=header\.off\(|$)/) | ||
|
|
||
| expect(m, 'select change handler must be present').not.toBeNull() | ||
| const body = m[0] | ||
|
|
||
| expect(body).toMatch(/const isInitial\s*=\s*!!\(obj && obj\.isInitial\)/) | ||
| expect(body).toMatch(/onColumnSearch\(\{[^}]*isInitial[^}]*\}\)/) | ||
| }) | ||
|
|
||
| it('onColumnSearch derives isInitialRender from _initialized OR the per-call isInitial flag', () => { | ||
| expect(mainSource).toMatch( | ||
| /onColumnSearch\s*\(\{[^}]*\bisInitial\b[^}]*\}\)/ | ||
| ) | ||
| expect(mainSource).toMatch( | ||
| /const isInitialRender = !this\._initialized \|\| isInitial === true/ | ||
| ) | ||
| }) | ||
| }) | ||
|
|
||
| describe('isInitialRender truth table', () => { | ||
| const computeIsInitialRender = (initialized, isInitial) => | ||
| !initialized || isInitial === true | ||
|
|
||
| it('treats pre-initialization as initial render', () => { | ||
| expect(computeIsInitialRender(false, false)).toBe(true) | ||
| expect(computeIsInitialRender(false, undefined)).toBe(true) | ||
| }) | ||
|
|
||
| it('treats the post-init triggerSearch(true) deferred call as initial render (the #8246 fix)', () => { | ||
| expect(computeIsInitialRender(true, true)).toBe(true) | ||
| }) | ||
|
|
||
| it('treats user-initiated searches as not initial', () => { | ||
| expect(computeIsInitialRender(true, false)).toBe(false) | ||
| expect(computeIsInitialRender(true, undefined)).toBe(false) | ||
| }) | ||
|
|
||
| it('only treats explicit isInitial === true as initial (defensive)', () => { | ||
| expect(computeIsInitialRender(true, 'yes')).toBe(false) | ||
| expect(computeIsInitialRender(true, 1)).toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| describe('onColumnSearch effect simulation', () => { | ||
| function simulateOnColumnSearch (state) { | ||
| const ctx = { | ||
| _initialized: state._initialized, | ||
| _filterControlValuesLoaded: state._filterControlValuesLoaded ?? false, | ||
| options: { | ||
| cookie: state.cookie, | ||
| pageNumber: state.pageNumber | ||
| }, | ||
| onSearch: vi.fn() | ||
| } | ||
|
|
||
| const isInitialRender = !ctx._initialized || state.isInitial === true | ||
|
|
||
| if (!ctx.options.cookie) { | ||
| if (!isInitialRender) { | ||
| ctx.options.pageNumber = 1 | ||
| } | ||
| } else { | ||
| ctx._filterControlValuesLoaded = true | ||
| } | ||
|
|
||
| ctx.onSearch({ currentTarget: null, firedByInitSearchText: isInitialRender }, false) | ||
| return ctx | ||
| } | ||
|
|
||
| it('issue #8246: cookie-restored pageNumber survives the deferred initial-render call', () => { | ||
| const ctx = simulateOnColumnSearch({ | ||
| _initialized: true, | ||
| isInitial: true, | ||
| cookie: true, | ||
| pageNumber: 5 | ||
| }) | ||
|
|
||
| expect(ctx.options.pageNumber).toBe(5) | ||
| expect(ctx._filterControlValuesLoaded).toBe(true) | ||
| expect(ctx.onSearch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ firedByInitSearchText: true }), | ||
| false | ||
| ) | ||
| }) | ||
|
|
||
| it('user-initiated cookie+filter search does NOT reset pageNumber inside filter-control, but signals core onSearch to reset', () => { | ||
| const ctx = simulateOnColumnSearch({ | ||
| _initialized: true, | ||
| isInitial: false, | ||
| cookie: true, | ||
| pageNumber: 5 | ||
| }) | ||
|
|
||
| expect(ctx.options.pageNumber).toBe(5) | ||
| expect(ctx._filterControlValuesLoaded).toBe(true) | ||
| expect(ctx.onSearch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ firedByInitSearchText: false }), | ||
| false | ||
| ) | ||
| }) | ||
|
|
||
| it('non-cookie user search resets pageNumber to 1', () => { | ||
| const ctx = simulateOnColumnSearch({ | ||
| _initialized: true, | ||
| isInitial: false, | ||
| cookie: false, | ||
| pageNumber: 5 | ||
| }) | ||
|
|
||
| expect(ctx.options.pageNumber).toBe(1) | ||
| expect(ctx.onSearch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ firedByInitSearchText: false }), | ||
| false | ||
| ) | ||
| }) | ||
|
|
||
| it('non-cookie initial render does not reset pageNumber', () => { | ||
| const ctx = simulateOnColumnSearch({ | ||
| _initialized: false, | ||
| isInitial: false, | ||
| cookie: false, | ||
| pageNumber: 5 | ||
| }) | ||
|
|
||
| expect(ctx.options.pageNumber).toBe(5) | ||
| expect(ctx.onSearch).toHaveBeenCalledWith( | ||
| expect.objectContaining({ firedByInitSearchText: true }), | ||
| false | ||
| ) | ||
| }) | ||
| }) | ||
| }) | ||
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.
Uh oh!
There was an error while loading. Please reload this page.