-
Couldn't load subscription status.
- Fork 74
Fix(firestore): Respect data type when applying filter #1097
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?
Conversation
The firestore filter view was incorrectly setting the data type to string if the value was entered before the data type was selected. This was because the data type was being inferred from the value itself. This change lifts the state of the `fieldType` to the parent component, `CollectionFilter.tsx`, and passes it down as a prop. The `onSubmit` function in `CollectionFilter.tsx` now parses the value based on the `fieldType` before dispatching the action. This ensures that the selected data type is always respected, regardless of the order of operations.
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.
Summary of Changes
Hello @joehan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request addresses an issue in the Firestore filter view where the data type of a filter value was incorrectly inferred as a string if the value was entered before the data type was explicitly selected. The fix involves centralizing the fieldType state in the parent CollectionFilter component and ensuring that the value is correctly parsed to its intended type (number, boolean, or string) before the filter action is dispatched.
Highlights
- Centralized Type State: The fieldType state, which determines the data type of the filter value, has been moved from the ConditionEntry component to its parent, CollectionFilter.tsx.
- Explicit Value Parsing: The CollectionFilter component now explicitly parses the filter value based on the selected fieldType (e.g., converting to a number or boolean) before dispatching the filter action, ensuring type integrity.
- Simplified ConditionEntry: The ConditionEntry component no longer manages its own fieldType state or infers the type from the input value, receiving it as a prop instead.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request effectively refactors the component to fix an issue with data type handling in Firestore filters by lifting the fieldType state. The approach is sound, centralizing type control in the CollectionFilter component. I've identified one critical issue in the submission logic that incorrectly processes boolean values, which would prevent boolean filters from working as expected. Please see the detailed comment for a fix.
| } else if (fieldType === 'boolean') { | ||
| data.value = data.value === 'true'; | ||
| } |
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.
This logic for handling boolean values is incorrect. The BooleanCondition component ensures that the form value is already a boolean when this onSubmit handler is called. This code will incorrectly convert a true boolean value to false (because true === 'true' is false), and a false boolean value will also become false (false === 'true' is false). Since BooleanCondition resets the value to a boolean when the type is switched, there's no scenario where data.value would be a string like 'true' when fieldType is 'boolean'. This else if block should be removed to fix boolean filtering.
This change fixes a regression where the filter data type would always default to "string" when the filter view was closed and reopened. The `fieldType` state is now initialized in the `CollectionFilter` component based on the type of the existing filter value. This ensures that the dropdown correctly reflects the type of the currently applied filter when the view is reopened.
Courtesy of Jules:
The firestore filter view was incorrectly setting the data type to string if the value was entered before the data type was selected. This was because the data type was being inferred from the value itself.
This change lifts the state of the
fieldTypeto the parent component,CollectionFilter.tsx, and passes it down as a prop. TheonSubmitfunction inCollectionFilter.tsxnow parses the value based on thefieldTypebefore dispatching the action. This ensures that the selected data type is always respected, regardless of the order of operations.