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

JNG-3980 filter empty values #449

Merged
merged 3 commits into from
Aug 22, 2024
Merged

Conversation

noherczeg
Copy link
Contributor

@noherczeg noherczeg commented Aug 15, 2024

StoryJNG-3980 Filter for empty values on tables

Copy link

coderabbitai bot commented Aug 15, 2024

Walkthrough

In this update, several components of the Judo UI framework have undergone significant improvements in filter handling. The logic for filtering operations in components like EagerTable and LazyTable has been streamlined by removing unnecessary checks, enhancing clarity and maintainability. Localization strings have been updated for better readability, and new functionalities have been introduced to support expanded filtering capabilities. These changes collectively aim to improve the user experience and the framework's responsiveness to filter updates.

Changes

Files Change Summary
.../table/EagerTable.tsx, .../table/LazyTable.tsx Simplified filter handling by removing checks for defined values in newModel.items.
.../i18n/system_default.json.hbs, .../i18n/system_en-US.json.hbs, .../i18n/system_hu-HU.json.hbs Updated localization strings for filters to improve readability; added new entries for is defined and is undefined.
.../dialog/FilterDialog.tsx.hbs Removed several utility functions and updated filter logic for improved responsiveness and clarity.
.../utilities/filter-helper.ts.hbs Introduced new functions for enhanced filter operations and checks for filters without values.
pom.xml Updated version of judo-ui-typescript-rest dependency, reflecting new features related to filtering.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant EagerTable
    participant LazyTable
    participant FilterHelper

    User->>EagerTable: Update filters
    EagerTable->>FilterHelper: Map filters
    FilterHelper-->>EagerTable: Return newFilters
    EagerTable->>User: Display updated table

    User->>LazyTable: Update filters
    LazyTable->>FilterHelper: Map filters
    FilterHelper-->>LazyTable: Return newFilters
    LazyTable->>User: Display updated table
Loading

🐰 In the thicket where code takes flight,
Changes hop in, oh what a sight!
Filters now dance without a care,
User-friendly strings fill the air.
With each update, we celebrate,
A UI bright—oh, isn’t it great! 🌟


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f812018 and 4398924.

Files selected for processing (11)
  • judo-ui-react-itest/ActionGroupTestPro/action_group_test_pro__god/src/test/resources/snapshots/frontend-react/src/components/table/EagerTable.tsx.snapshot (1 hunks)
  • judo-ui-react-itest/ActionGroupTestPro/action_group_test_pro__god/src/test/resources/snapshots/frontend-react/src/components/table/LazyTable.tsx.snapshot (1 hunks)
  • judo-ui-react/src/main/resources/actor/public/i18n/system_default.json.hbs (1 hunks)
  • judo-ui-react/src/main/resources/actor/public/i18n/system_en-US.json.hbs (1 hunks)
  • judo-ui-react/src/main/resources/actor/public/i18n/system_hu-HU.json.hbs (1 hunks)
  • judo-ui-react/src/main/resources/actor/src/components/dialog/FilterDialog.tsx.hbs (3 hunks)
  • judo-ui-react/src/main/resources/actor/src/components/table/EagerTable.tsx.hbs (1 hunks)
  • judo-ui-react/src/main/resources/actor/src/components/table/LazyTable.tsx.hbs (1 hunks)
  • judo-ui-react/src/main/resources/actor/src/components/table/table-column-operators.tsx.hbs (1 hunks)
  • judo-ui-react/src/main/resources/actor/src/utilities/filter-helper.ts.hbs (11 hunks)
  • pom.xml (1 hunks)
Files skipped from review due to trivial changes (2)
  • judo-ui-react/src/main/resources/actor/public/i18n/system_en-US.json.hbs
  • judo-ui-react/src/main/resources/actor/public/i18n/system_hu-HU.json.hbs
Additional comments not posted (20)
judo-ui-react/src/main/resources/actor/src/components/table/table-column-operators.tsx.hbs (3)

29-30: Verify the decision to allow all operators.

Allowing all operators for date-time columns could lead to unexpected behavior. Ensure this change is intentional and consider documenting the rationale.


34-35: LGTM!

The logic for boolean column operators is clear and aligns with the source reference.


24-25: Verify the decision to allow all operators.

Allowing all operators for date columns could lead to unexpected behavior. Ensure this change is intentional and consider documenting the rationale.

judo-ui-react/src/main/resources/actor/public/i18n/system_default.json.hbs (1)

116-127: LGTM!

The capitalization of filter descriptions improves readability, and the addition of "Is defined" and "Is undefined" enhances filtering capabilities.

judo-ui-react/src/main/resources/actor/src/components/dialog/FilterDialog.tsx.hbs (3)

Line range hint 268-268: LGTM!

The logic in FilterDialog for managing filters is streamlined and efficient.


33-33: Verify the usage of new imports.

Ensure that the newly imported utility functions are used correctly throughout the file.

Verification successful

New imports are correctly used in FilterDialog.tsx.hbs.

The newly imported functions are utilized appropriately throughout the file to handle filter operations. No issues found with their usage.

  • getOperationEnumValue is used for setting filter operators.
  • getOperatorsByFilter is used for mapping filter operators.
  • isFilterWithoutValue is used in conditional logic.
  • getDefaultOperator is used to determine default operators.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify usage of new imports in `FilterDialog.tsx.hbs`.

# Test: Search for the usage of each newly imported function. Expect: Correct usage throughout the file.
rg --type tsx 'getOperationEnumValue|getOperatorsByFilter|getDefaultOperator|isFilterWithoutValue' judo-ui-react/src/main/resources/actor/src/components/dialog/FilterDialog.tsx.hbs

Length of output: 210


Script:

#!/bin/bash
# Description: Verify usage of new imports in `FilterDialog.tsx.hbs`.

# Test: Search for the usage of each newly imported function. Expect: Correct usage throughout the file.
rg 'getOperationEnumValue|getOperatorsByFilter|getDefaultOperator|isFilterWithoutValue' judo-ui-react/src/main/resources/actor/src/components/dialog/FilterDialog.tsx.hbs

Length of output: 690


217-217: LGTM! But verify the conditional logic.

The conditional rendering of FilterInput based on isFilterWithoutValue likely improves responsiveness. Ensure the logic aligns with expected behavior.

Verification successful

Conditional Logic Verified: isFilterWithoutValue Functionality

The isFilterWithoutValue function correctly determines if a filter does not require a value, and the conditional rendering of FilterInput in FilterDialog.tsx.hbs aligns with this logic. The changes enhance responsiveness by ensuring FilterInput is only rendered when necessary.

  • Definition found in judo-ui-react/src/main/resources/actor/src/utilities/filter-helper.ts.hbs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the logic of `isFilterWithoutValue` in conditional rendering.

# Test: Search for the definition and usage of `isFilterWithoutValue`. Expect: Logic aligns with expected behavior.
rg --type tsx 'isFilterWithoutValue' judo-ui-react/src/main/resources/actor/src/components/dialog/FilterDialog.tsx.hbs

Length of output: 146


Script:

#!/bin/bash
# Description: Verify the logic of `isFilterWithoutValue` in conditional rendering.

# Test: Search for the definition and usage of `isFilterWithoutValue` without specifying file type.
rg 'isFilterWithoutValue' judo-ui-react/src/main/resources/actor/src/components/dialog/FilterDialog.tsx.hbs -A 5

Length of output: 803


Script:

#!/bin/bash
# Description: Search for the definition of `isFilterWithoutValue` in the `utilities` directory.

# Test: Locate the definition of `isFilterWithoutValue` to verify its logic.
rg 'function isFilterWithoutValue' judo-ui-react/src/main/resources/actor/src/utilities -A 5

Length of output: 94


Script:

#!/bin/bash
# Description: Search for any occurrence of `isFilterWithoutValue` in the `utilities` directory.

# Test: Locate any reference to `isFilterWithoutValue` to verify its logic.
rg 'isFilterWithoutValue' judo-ui-react/src/main/resources/actor/src/utilities -A 5

Length of output: 1851

judo-ui-react/src/main/resources/actor/src/utilities/filter-helper.ts.hbs (9)

195-198: Enhance filterByStringOperation with isDefined and isUndefined.

The function now supports isDefined and isUndefined operations. Ensure these operations are correctly implemented and tested.


219-222: Enhance filterByNumericOperation with isDefined and isUndefined.

The function now supports isDefined and isUndefined operations. Ensure these operations are correctly implemented and tested.


243-246: Enhance filterByDateOperation with isDefined and isUndefined.

The function now supports isDefined and isUndefined operations. Ensure these operations are correctly implemented and tested.


262-265: Enhance filterByBooleanOperation with isDefined and isUndefined.

The function now supports isDefined and isUndefined operations. Ensure these operations are correctly implemented and tested.


278-281: Enhance filterByEnumerationOperation with isDefined and isUndefined.

The function now supports isDefined and isUndefined operations. Ensure these operations are correctly implemented and tested.


353-358: Ensure correct operator mapping in mapDateOperator.

The function maps isEmpty and isNotEmpty to isUndefined and isDefined. Verify that these mappings align with the intended operations.

Verification successful

Operator mappings in mapDateOperator are consistent.

The mapDateOperator function correctly maps isEmpty to _NumericOperation.isUndefined and isNotEmpty to _NumericOperation.isDefined, aligning with the intended operations. No changes are needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct mapping of date operators in mapDateOperator.

# Test: Search for the mapDateOperator function definition and ensure correct operator mapping.
ast-grep --lang typescript --pattern $'function mapDateOperator($_) {
  $$$
}'

Length of output: 79


Script:

#!/bin/bash
# Search for the term 'mapDateOperator' across the codebase to locate its definition and understand its context.
rg 'mapDateOperator' -A 5

Length of output: 1875


373-378: Ensure correct operator mapping in mapSingleSelectOperator.

The function maps isEmpty and isNotEmpty to isUndefined and isDefined. Verify that these mappings align with the intended operations.

Verification successful

Operator Mapping Verified in mapSingleSelectOperator.

The isEmpty and isNotEmpty operators are correctly mapped to _EnumerationOperation.isUndefined and _EnumerationOperation.isDefined, respectively, in the mapSingleSelectOperator function.

  • judo-ui-react/src/main/resources/actor/src/utilities/filter-helper.ts.hbs
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct mapping of single select operators in mapSingleSelectOperator.

# Test: Search for the mapSingleSelectOperator function definition and ensure correct operator mapping.
ast-grep --lang typescript --pattern $'function mapSingleSelectOperator($_) {
  $$$
}'

Length of output: 87


Script:

#!/bin/bash
# Search for the mapSingleSelectOperator function definition and any references to it in the codebase.
rg 'mapSingleSelectOperator' -A 5

Length of output: 1354


296-301: Ensure correct operator mapping in mapStringOperator.

The function maps isEmpty and isNotEmpty to isUndefined and isDefined. Verify that these mappings align with the intended operations.

Verification successful

Verify intended logic for operator mapping in mapStringOperator.

The function mapStringOperator correctly maps isEmpty to _StringOperation.isUndefined and isNotEmpty to _StringOperation.isDefined. Ensure these mappings align with the intended operations or specifications.

  • File: judo-ui-react/src/main/resources/actor/src/utilities/filter-helper.ts.hbs
  • Lines: 296-301
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the correct mapping of string operators in mapStringOperator.

# Test: Search for the mapStringOperator function definition and ensure correct operator mapping.
ast-grep --lang typescript --pattern $'function mapStringOperator($_) {
  $$$
}'

Length of output: 81


Script:

#!/bin/bash
# Description: Search for the mapStringOperator function in the codebase using ripgrep to understand its context.
rg 'mapStringOperator' -A 10 --type=typescript

Length of output: 81


Script:

#!/bin/bash
# Description: Search for the mapStringOperator function in the codebase without specifying a file type.
rg 'mapStringOperator' -A 10

Length of output: 2270


323-328: Ensure correct operator mapping in mapNumericOperator.

The function maps isEmpty and isNotEmpty to isUndefined and isDefined. Verify that these mappings align with the intended operations.

judo-ui-react/src/main/resources/actor/src/components/table/EagerTable.tsx.hbs (1)

257-260: Ensure handling of undefined values.

The check for defined values in newModel.items has been removed. Ensure that mapFilterModelToFilters can handle undefined values appropriately to avoid potential runtime errors.

pom.xml (1)

60-60: Dependency Version Update Acknowledged.

The version update for judo-ui-typescript-rest reflects the new feature JNG_3980_filter_empty_values. Ensure compatibility with other components relying on this dependency.

judo-ui-react-itest/ActionGroupTestPro/action_group_test_pro__god/src/test/resources/snapshots/frontend-react/src/components/table/LazyTable.tsx.snapshot (1)

302-305: Refactoring Acknowledged: Simplified Filter Handling.

The removal of the conditional check for defined values in newModel.items simplifies the logic. Ensure that this change doesn't affect the functionality negatively, especially in cases where undefined values might have been handled differently.

judo-ui-react/src/main/resources/actor/src/components/table/LazyTable.tsx.hbs (1)

304-307: Refactoring Acknowledged: Simplified Filter Handling.

The removal of the conditional check for defined values in newModel.items simplifies the logic. Ensure that this change doesn't affect the functionality negatively, especially in cases where undefined values might have been handled differently.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Outside diff range, codebase verification and nitpick comments (6)
judo-ui-react/src/main/resources/actor/src/components/table/table-column-operators.tsx.hbs (3)

13-15: Expand the comment for clarity.

The comment explains why 'startsWith' and 'endsWith' are excluded but does not mention 'isAnyOf'. Consider expanding the comment to explain this exclusion as well.

  // startsWith and endsWith is filtered out because they'd need complex value mapping...
+ // isAnyOf is excluded to prevent multiple selections in a single filter.

19-20: Add a comment to explain exclusion.

Consider adding a comment explaining why 'isAnyOf' is excluded for numeric columns.

  // Exclude 'isAnyOf' to limit filtering to single numeric values.

Line range hint 38-39: Add a comment to explain exclusion.

Consider adding a comment explaining why 'isAnyOf' is excluded for single select columns.

  // Exclude 'isAnyOf' to ensure only one selection is possible.
judo-ui-react-itest/ActionGroupTestPro/action_group_test_pro__god/src/test/resources/snapshots/frontend-react/src/components/table/EagerTable.tsx.snapshot (1)

238-241: Add Check for Undefined filterModel.items in mapFilterModelToFilters

The mapFilterModelToFilters function does not handle the case where filterModel.items might be undefined, which could lead to runtime errors. Consider adding a check to ensure filterModel.items is defined before iterating over it.

  • File: judo-ui-react/src/main/resources/actor/src/utilities/filter-helper.ts.hbs
  • Relevant Code Snippet:
    export function mapFilterModelToFilters(filterModel: GridFilterModel, filterOptions: FilterOption[]): Filter[] {
      const filters: Filter[] = [];
    
      for (const item of filterModel.items) {
        const filterOption = filterOptions.find((o) => o.attributeName === item.field);
    
        if (!filterOption) {
          console.warn(`Could not map filter option for filter item: ${JSON.stringify(item, null, 4)}`);
          continue;
        }
        // ...
      }
      // ...
    }
Analysis chain

Ensure handling of undefined values.

The check for defined values in newModel.items has been removed. Ensure that mapFilterModelToFilters can handle undefined values appropriately to avoid potential runtime errors.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that mapFilterModelToFilters can handle undefined values in newModel.items.

# Test: Search for the mapFilterModelToFilters function definition and ensure it handles undefined values.
ast-grep --lang typescript --pattern $'function mapFilterModelToFilters($_, $_) {
  $$$
}'

Length of output: 91


Script:

#!/bin/bash
# Search for the mapFilterModelToFilters function in the codebase to find its definition or usage.
rg 'mapFilterModelToFilters' -A 5

Length of output: 11942


Script:

#!/bin/bash
# Extract the full implementation of the mapFilterModelToFilters function to verify handling of undefined values.
rg 'export function mapFilterModelToFilters' -A 20 judo-ui-react/src/main/resources/actor/src/utilities/filter-helper.ts.hbs

Length of output: 811

judo-ui-react/src/main/resources/actor/src/utilities/filter-helper.ts.hbs (2)

100-102: Clarify logic in isFilterWithoutValue.

The function checks for isDefined and isUndefined operations. Ensure this logic aligns with the intended use of filters without values.

-  return ['isDefined', 'isUndefined'].includes(getOperationEnumValue(filter, filter.filterBy.operator))
+  return ['isDefined', 'isUndefined'].includes(filter.filterBy.operator)

104-107: Document the purpose of ucFirst.

The function capitalizes the first letter of a string. Consider adding a comment to clarify its purpose for future maintainers.

+// Capitalizes the first letter of a string
export const ucFirst = (str: string): string => {

@noherczeg noherczeg merged commit bb8390d into develop Aug 22, 2024
3 checks passed
@noherczeg noherczeg deleted the feature/JNG-3980-filter-empty-values branch August 22, 2024 13:48
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.

3 participants