-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Introduce <FilterLiveForm>
#10344
Merged
Merged
Introduce <FilterLiveForm>
#10344
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
55555fd
wip: first working version
slax57 8c3bec7
wip: own story and defaultValues
slax57 8acaf9e
wip: more stories and fix per input validation
slax57 612ebc1
wip: story with ReferenceInput
slax57 c68e047
wip: add resettable everywhere
slax57 8c8d011
wip: add AsListActions story
slax57 ae9faa0
introduce FilterListWrapper and make stories more beautiful
slax57 af34890
move AutoSubmitFilterForm to ra-core
slax57 41780ed
trigger debounce bug in stories
slax57 e1342d4
fix and debug code
slax57 159cfd8
fix fix
slax57 3b0cb94
remove useless useListParams stories
slax57 8164dfb
apply fix to AutoSubmitFilterForm and remove tech debt from FilterForm
slax57 1512a1d
fix unit test
slax57 0c136e3
add missing FormGroupsProvider
slax57 719fc75
refactor FilterLiveSearch to use AutoSubmitFilterForm + fix AutoSubmi…
slax57 762b687
add FilterLiveSearch FullApp story
slax57 5362261
add filterlivesearch reapply old value bug unit test
slax57 47384c8
use AutoSubmitFilterForm in FilterForm
slax57 5b58e7e
improve AutoSubmitFilterForm component prop default value
slax57 b6b8eaf
add tests for AutoSubmitFilterForm
slax57 01c5429
add test for race condition bug
slax57 e8005b1
remove debug code
slax57 fbb3837
add docs for AutoSubmitFilterForm
slax57 482e83d
improve discoverability
slax57 0946f6e
fix Liquid syntax error
slax57 e34fa24
code review
slax57 36d5a45
move AutoSubmitFilterForm in form folder
slax57 eeee44f
reintroduce unset
slax57 fc30c5a
rename component to formComponent
slax57 9f0ef08
rename FilterListWrapper to FilterListSection
slax57 05e926f
rename AutoSubmitFilterForm to FilterLiveForm
slax57 7fd23c6
rename assets
slax57 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
35 changes: 35 additions & 0 deletions
35
packages/ra-core/src/controller/list/filter/AutoSubmitFilterForm.spec.tsx
This file contains 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,35 @@ | ||
import { getFilterFormValues } from './AutoSubmitFilterForm'; | ||
|
||
describe('<AutoSubmitFilterForm />', () => { | ||
describe('getFilterFormValues', () => { | ||
it('should correctly get the filter form values from the new filterValues', () => { | ||
const currentFormValues = { | ||
classicToClear: 'abc', | ||
nestedToClear: { nestedValue: 'def' }, | ||
classicUpdated: 'ghi', | ||
nestedUpdated: { nestedValue: 'jkl' }, | ||
nestedToSet: { nestedValue: undefined }, | ||
published_at: new Date('2022-01-01T03:00:00.000Z'), | ||
clearedDateValue: null, | ||
}; | ||
const newFilterValues = { | ||
classicUpdated: 'ghi2', | ||
nestedUpdated: { nestedValue: 'jkl2' }, | ||
nestedToSet: { nestedValue: 'mno2' }, | ||
published_at: '2022-01-01T03:00:00.000Z', | ||
}; | ||
|
||
expect( | ||
getFilterFormValues(currentFormValues, newFilterValues) | ||
).toEqual({ | ||
classicToClear: '', | ||
nestedToClear: { nestedValue: '' }, | ||
classicUpdated: 'ghi2', | ||
nestedUpdated: { nestedValue: 'jkl2' }, | ||
nestedToSet: { nestedValue: 'mno2' }, | ||
published_at: '2022-01-01T03:00:00.000Z', | ||
clearedDateValue: '', | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains 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 |
---|---|---|
|
@@ -15,30 +15,37 @@ import { | |
ValidateForm, | ||
} from '../../../form'; | ||
import { useDebouncedEvent, useEvent } from '../../../util'; | ||
import { useListFilterContext } from '../useListFilterContext'; | ||
import { useListContext } from '../useListContext'; | ||
|
||
/** | ||
* TODO | ||
*/ | ||
export const AutoSubmitFilterForm = (props: AutoSubmitFilterFormProps) => { | ||
const { filterValues, setFilters } = useListFilterContext(); | ||
const { filterValues, setFilters } = useListContext(); | ||
const resource = useResourceContext(props); | ||
|
||
const { debounce = 500, resolver, validate, children, ...rest } = props; | ||
const { | ||
debounce = 500, | ||
resolver, | ||
validate, | ||
children, | ||
component: Component, | ||
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. Why don't you provide a default value here and avoid the ternary at L124? 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. I didn't know how to do it, but now I know! Thanks! |
||
...rest | ||
} = props; | ||
|
||
const finalResolver = resolver | ||
? resolver | ||
: validate | ||
? getSimpleValidationResolver(validate) | ||
: undefined; | ||
|
||
const form = useForm({ | ||
const formContext = useForm({ | ||
mode: 'onChange', | ||
defaultValues: filterValues, | ||
resolver: finalResolver, | ||
...rest, | ||
}); | ||
const { handleSubmit, getValues, reset, watch, formState } = form; | ||
const { handleSubmit, getValues, reset, watch, formState } = formContext; | ||
const { isValid } = formState; | ||
|
||
// Ref tracking if there are internal changes pending, i.e. changes that | ||
|
@@ -111,10 +118,18 @@ export const AutoSubmitFilterForm = (props: AutoSubmitFilterFormProps) => { | |
); | ||
|
||
return ( | ||
<FormProvider {...form}> | ||
<FormProvider {...formContext}> | ||
<FormGroupsProvider> | ||
<SourceContextProvider value={sourceContext}> | ||
<form onSubmit={handleSubmit(onSubmit)}>{children}</form> | ||
{Component ? ( | ||
<Component onSubmit={handleSubmit(onSubmit)}> | ||
{children} | ||
</Component> | ||
) : ( | ||
<form onSubmit={handleSubmit(onSubmit)}> | ||
{children} | ||
</form> | ||
)} | ||
</SourceContextProvider> | ||
</FormGroupsProvider> | ||
</FormProvider> | ||
|
@@ -127,6 +142,7 @@ export interface AutoSubmitFilterFormProps | |
validate?: ValidateForm; | ||
debounce?: number | false; | ||
resource?: string; | ||
component?: React.ComponentType<any>; | ||
fzaninotto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
|
@@ -136,7 +152,7 @@ export interface AutoSubmitFilterFormProps | |
* and due to the dynamic nature of the filter form, we rebuild the filter form values from its current | ||
* values and make sure to pass at least an empty string for each input. | ||
*/ | ||
const getFilterFormValues = ( | ||
export const getFilterFormValues = ( | ||
formValues: Record<string, any>, | ||
filterValues: Record<string, any> | ||
) => { | ||
|
This file contains 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.
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.
When you have a non validated input you can't submit. But if you submit your
FilterList
in a same time, it will reset yourAutoSubmitForm
to the last validated state.Do we need to consider it as an issue or as a normal way of work @fzaninotto @djhi ?
Capture.video.2024-11-18.11.19.16.mp4
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.
IMO this isn't a bug