-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix requestId race condition and actually dispatch bool columnMeta #211
fix requestId race condition and actually dispatch bool columnMeta #211
Conversation
dispatch( | ||
setColumnMeta([ | ||
collectionId, | ||
context, | ||
column.col_id, | ||
{ | ||
type: 'bool', | ||
key: column.col_id, | ||
max_value: undefined, | ||
min_value: undefined, | ||
category: category.category, | ||
description: column.description, | ||
display_name: column.name, | ||
filter_strategy: undefined, | ||
enum_values: undefined, | ||
}, | ||
]) | ||
); |
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 filters were not showing up because I forgot the dispatch...
? typeof current.value !== 'undefined' | ||
? Boolean(current.value) | ||
: undefined |
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.
Fixes accidentally setting all filters to false
if they were undefined
// In order not to create a dependency loop when filter changes within the below effect, | ||
// use a filter ref | ||
const filterRef = useRef(filter); | ||
filterRef.current = filter; | ||
|
||
useEffect(() => { | ||
let value; | ||
if (selectValue === 'true') { | ||
value = 1; | ||
} else if (selectValue === 'false') { | ||
value = 0; | ||
} | ||
dispatch(setFilter([collectionId, context, column, { ...filter, value }])); | ||
}, [selectValue, collectionId, context, column, filter, dispatch]); | ||
dispatch( | ||
setFilter([ | ||
collectionId, | ||
context, | ||
column, | ||
{ ...filterRef.current, value }, | ||
]) | ||
); | ||
}, [selectValue, collectionId, context, column, dispatch]); |
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.
fixes infinite render loop
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.
Oh very nice thank you for catching that
const context = result.requestId | ||
? requestContext.current[result.requestId] | ||
: undefined; | ||
if (!collectionId || !result?.data || !context || result.isError) | ||
return {}; | ||
return { filterData: result.data, context }; |
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.
Removed unnescary hacky context state (requestContext) that was causing issues, prefer just canceling the requests when the context changes (line 317)
No description provided.