-
Notifications
You must be signed in to change notification settings - Fork 227
PMM-14848: import useTableUrlState #5537
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
Merged
+294
−59
Merged
Changes from 14 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
bdbe8d1
feat: import useTableUrlState
fabio-silva 0fe7a2e
chore: lint
fabio-silva fa98e11
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 83984a6
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 25d8204
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva e4eeb57
chore: simplify code
fabio-silva 1dd909e
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva a5ef9be
chore: update @percona/percona-ui
fabio-silva 1736744
Merge branch 'PMM-14848-table-url-params' of https://github.com/perco…
fabio-silva 5e5650b
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 1c25d84
chore: remove duplicate const
fabio-silva 5169316
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 7aa1020
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 1dc9fdc
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva c4a58e1
PMM-14848 move sessions URL state constant
cursoragent 0b3e2b0
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva c119f22
chore: format
fabio-silva c773985
Merge branch 'main' into PMM-14848-table-url-params
mattiasimonato 0e2e8ae
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva a2e1edf
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 16355b0
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 7e08bec
fix: allow search on QAN while typing
fabio-silva c2ed921
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 963024c
Merge branch 'main' into PMM-14848-table-url-params
fabio-silva 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import { renderHook } from '@testing-library/react'; | ||
| import { describe, expect, it, vi } from 'vitest'; | ||
| import reactRouter from 'react-router-dom'; | ||
| import { useTableUrlState } from './useTableUrlState'; | ||
|
|
||
| const { usePerconaTableUrlState } = vi.hoisted(() => ({ | ||
| usePerconaTableUrlState: vi.fn(), | ||
| })); | ||
|
|
||
| vi.mock('@percona/percona-ui', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('@percona/percona-ui')>(); | ||
| return { | ||
| ...actual, | ||
| usePerconaTableUrlState, | ||
| }; | ||
| }); | ||
|
|
||
| const setup = (params: string) => { | ||
| const searchParams = new URLSearchParams(params); | ||
| const setSearchParams = vi.fn(); | ||
|
|
||
| vi.spyOn(reactRouter, 'useSearchParams').mockReturnValue([searchParams, setSearchParams]); | ||
| vi.mocked(usePerconaTableUrlState).mockReturnValue({ | ||
| tableState: { | ||
| state: { | ||
| columnFilters: [], | ||
| globalFilter: '', | ||
| sorting: [], | ||
| pagination: { pageIndex: 0, pageSize: 10 }, | ||
| }, | ||
| onColumnFiltersChange: vi.fn(), | ||
| onGlobalFilterChange: vi.fn(), | ||
| onSortingChange: vi.fn(), | ||
| onPaginationChange: vi.fn(), | ||
| }, | ||
| tableProps: { | ||
| state: { | ||
| columnFilters: [], | ||
| globalFilter: '', | ||
| sorting: [], | ||
| pagination: { pageIndex: 0, pageSize: 10 }, | ||
| showColumnFilters: false, | ||
| showGlobalFilter: false, | ||
| }, | ||
| onColumnFiltersChange: vi.fn(), | ||
| onGlobalFilterChange: vi.fn(), | ||
| onSortingChange: vi.fn(), | ||
| onPaginationChange: vi.fn(), | ||
| onShowColumnFiltersChange: vi.fn(), | ||
| onShowGlobalFilterChange: vi.fn(), | ||
| }, | ||
| }); | ||
|
|
||
| return { searchParams, setSearchParams }; | ||
| }; | ||
|
|
||
| describe('useTableUrlState', () => { | ||
| it('passes react-router search params to percona useTableUrlState', () => { | ||
| const { searchParams, setSearchParams } = setup( | ||
| 'serviceIds=123&overview.sort=queryText:desc' | ||
| ); | ||
|
|
||
| renderHook(() => | ||
| useTableUrlState({ | ||
| paramPrefix: 'overview', | ||
| }) | ||
| ); | ||
|
|
||
| expect(usePerconaTableUrlState).toHaveBeenCalledWith({ | ||
| searchParams, | ||
| setSearchParams, | ||
| paramPrefix: 'overview', | ||
| }); | ||
| }); | ||
|
|
||
| it('forwards optional hook configuration', () => { | ||
| const { searchParams, setSearchParams } = setup(''); | ||
|
|
||
| renderHook(() => | ||
| useTableUrlState({ | ||
| paramPrefix: 'sessions', | ||
| debounceMs: 500, | ||
| replace: false, | ||
| sync: { pagination: false }, | ||
| }) | ||
| ); | ||
|
|
||
| expect(usePerconaTableUrlState).toHaveBeenCalledWith({ | ||
| searchParams, | ||
| setSearchParams, | ||
| paramPrefix: 'sessions', | ||
| debounceMs: 500, | ||
| replace: false, | ||
| sync: { pagination: false }, | ||
| }); | ||
| }); | ||
| }); |
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,25 @@ | ||
| import { useSearchParams } from 'react-router-dom'; | ||
| import { | ||
| usePerconaTableUrlState, | ||
| type UsePerconaTableUrlStateOptions, | ||
| type UsePerconaTableUrlStateResult, | ||
| } from '@percona/percona-ui'; | ||
|
|
||
| export type UseTableUrlStateOptions = Omit< | ||
| UsePerconaTableUrlStateOptions, | ||
| 'searchParams' | 'setSearchParams' | ||
| >; | ||
|
|
||
| export type UseTableUrlStateResult = UsePerconaTableUrlStateResult; | ||
|
|
||
| export const useTableUrlState = ( | ||
| options: UseTableUrlStateOptions = {} | ||
| ): UseTableUrlStateResult => { | ||
| const [searchParams, setSearchParams] = useSearchParams(); | ||
|
|
||
| return usePerconaTableUrlState({ | ||
| searchParams, | ||
| setSearchParams, | ||
| ...options, | ||
| }); | ||
| }; |
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
Oops, something went wrong.
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.