Skip to content
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

Merged
merged 3 commits into from
May 15, 2024

Conversation

dauglyon
Copy link
Collaborator

No description provided.

@dauglyon dauglyon requested a review from codytodonnell May 14, 2024 22:06
Comment on lines +228 to +245
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,
},
])
);
Copy link
Collaborator Author

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...

Comment on lines +255 to +257
? typeof current.value !== 'undefined'
? Boolean(current.value)
: undefined
Copy link
Collaborator Author

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

Comment on lines +1018 to +1038
// 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]);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixes infinite render loop

Copy link
Collaborator

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

Comment on lines -157 to -162
const context = result.requestId
? requestContext.current[result.requestId]
: undefined;
if (!collectionId || !result?.data || !context || result.isError)
return {};
return { filterData: result.data, context };
Copy link
Collaborator Author

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)

@codytodonnell codytodonnell merged commit e407210 into feature/boolean-filter May 15, 2024
@codytodonnell codytodonnell deleted the feature/boolean-filter-fixes branch May 15, 2024 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants