-
-
Notifications
You must be signed in to change notification settings - Fork 530
Feature: useListValuesAutoComplate filter does not refresh when left side changes in panel. #1253
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -14,8 +14,8 @@ const useListValuesAutocomplete = ({ | |||||
| asyncFetch, useLoadMore, useAsyncSearch, forceAsyncSearch, | ||||||
| asyncListValues: selectedAsyncListValues, | ||||||
| listValues: staticListValues, allowCustomValues, | ||||||
| value: selectedValue, setValue, placeholder, | ||||||
| config | ||||||
| value: selectedValue, setValue, placeholder, | ||||||
| config,field | ||||||
| }, { | ||||||
| debounceTimeout, | ||||||
| multiple, | ||||||
|
|
@@ -41,9 +41,21 @@ const useListValuesAutocomplete = ({ | |||||
|
|
||||||
| // compute | ||||||
| const nSelectedAsyncListValues = listValuesToArray(selectedAsyncListValues); | ||||||
| const listValues = asyncFetch | ||||||
| ? (selectedAsyncListValues ? mergeListValues(asyncListValues, nSelectedAsyncListValues, true) : asyncListValues) | ||||||
| : staticListValues; | ||||||
| // const listValues = asyncFetch | ||||||
| // ? (selectedAsyncListValues ? mergeListValues(asyncListValues, nSelectedAsyncListValues, true) : asyncListValues) | ||||||
| // : staticListValues; | ||||||
| const listValues = React.useMemo(() => { | ||||||
| return asyncFetch | ||||||
| ? (selectedAsyncListValues | ||||||
| ? mergeListValues(asyncListValues || [], nSelectedAsyncListValues, true) | ||||||
| : asyncListValues || []) | ||||||
| : listValuesToArray(staticListValues); | ||||||
| }, [asyncFetch, selectedAsyncListValues, asyncListValues, staticListValues, nSelectedAsyncListValues]); | ||||||
|
|
||||||
| React.useEffect(() => { | ||||||
| setAsyncListValues(undefined); | ||||||
| }, [field]); | ||||||
|
||||||
|
|
||||||
| let listValuesToDisplay = asyncFetch | ||||||
| ? asyncListValues | ||||||
| : staticListValues; | ||||||
|
|
@@ -95,7 +107,7 @@ const useListValuesAutocomplete = ({ | |||||
| const { values, hasMore, meta: newMeta } = res?.values | ||||||
| ? res | ||||||
| : { values: res } // fallback, if response contains just array, not object | ||||||
| ; | ||||||
| ; | ||||||
| const nValues = listValuesToArray(values); | ||||||
| let assumeHasMore; | ||||||
| let newValues; | ||||||
|
|
@@ -123,21 +135,42 @@ const useListValuesAutocomplete = ({ | |||||
| return newValues; | ||||||
| }; | ||||||
|
|
||||||
| // const loadListValues = async (filter = null, isLoadMore = false) => { | ||||||
| // setLoadingCnt(x => (x + 1)); | ||||||
| // setIsLoadingMore(isLoadMore); | ||||||
| // const list = await fetchListValues(filter, isLoadMore); | ||||||
| // if (!componentIsMounted.current) { | ||||||
| // return; | ||||||
| // } | ||||||
| // if (list != null) { | ||||||
| // // tip: null can be used for reject (eg, if user don't want to filter by input) | ||||||
| // setAsyncListValues(list); | ||||||
| // } | ||||||
| // setLoadingCnt(x => (x - 1)); | ||||||
| // setIsLoadingMore(false); | ||||||
| // }; | ||||||
| const loadListValues = async (filter = null, isLoadMore = false) => { | ||||||
| if (!isLoadMore) { | ||||||
| setAsyncListValues(undefined); | ||||||
| } | ||||||
|
|
||||||
| setLoadingCnt(x => (x + 1)); | ||||||
| setIsLoadingMore(isLoadMore); | ||||||
| const list = await fetchListValues(filter, isLoadMore); | ||||||
| if (!componentIsMounted.current) { | ||||||
| return; | ||||||
| } | ||||||
| if (list != null) { | ||||||
| // tip: null can be used for reject (eg, if user don't want to filter by input) | ||||||
| setAsyncListValues(list); | ||||||
| } | ||||||
| setLoadingCnt(x => (x - 1)); | ||||||
| setIsLoadingMore(false); | ||||||
| }; | ||||||
|
||||||
| }; | |
| }, [fetchListValues, setAsyncListValues, setLoadingCnt, setIsLoadingMore, componentIsMounted]); |
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.
Ensure both async and static list values are consistently converted to arrays. Consider clarifying in an inline comment why an empty array is used as a fallback in the memoized computation.