Skip to content

perf: entity group items filter utility refactor#38108

Merged
alex-golovanov merged 3 commits intoreleasefrom
feat/37769-filter-list-util
Dec 12, 2024
Merged

perf: entity group items filter utility refactor#38108
alex-golovanov merged 3 commits intoreleasefrom
feat/37769-filter-list-util

Conversation

@alex-golovanov
Copy link
Contributor

@alex-golovanov alex-golovanov commented Dec 11, 2024

Description

This pull request introduces a new utility function filterEntityGroupsBySearchTerm to replace the existing fuzzySearchInObjectItems function. Type inference is significantly improved. Additionally, some renaming was done to convey true meaning and improve readability.

Fixes #37769

Automation

/ok-to-test tags="@tag.IDE"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12277260297
Commit: 153de75
Cypress dashboard.
Tags: @tag.IDE
Spec:


Wed, 11 Dec 2024 13:55:20 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new filtering functionality for entity groups based on search terms.
    • Added a test suite to validate the new filtering function across various scenarios.
  • Bug Fixes

    • Updated components to use the new filtering method, improving search result accuracy.
  • Chores

    • Removed obsolete fuzzy search functionality and associated tests to streamline the codebase.
  • Refactor

    • Renamed variables for clarity and consistency throughout the application.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 11, 2024

Walkthrough

This pull request introduces a new utility function, filterEntityGroupsBySearchTerm, designed to filter entity groups based on a search term using the Fuse.js library. It includes a comprehensive test suite for this function, validating its behavior across various scenarios. Additionally, the codebase has been updated to replace previous fuzzy search implementations with the new function, enhancing clarity and consistency in variable naming and logic across several components.

Changes

File Change Summary
app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.test.ts New test suite added for filterEntityGroupsBySearchTerm function.
app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.ts New utility function filterEntityGroupsBySearchTerm added for filtering groups by search term.
app/client/src/IDE/utils/index.ts Export statement added for filterEntityGroupsBySearchTerm.
app/client/src/pages/Editor/IDE/EditorPane/JS/Add.tsx Updated to use filterEntityGroupsBySearchTerm; variable names changed for clarity.
app/client/src/pages/Editor/IDE/EditorPane/JS/List.tsx Renamed variables and updated filtering logic to use filterEntityGroupsBySearchTerm.
app/client/src/pages/Editor/IDE/EditorPane/Query/Add.tsx Modified to replace fuzzySearchInObjectItems with filterEntityGroupsBySearchTerm.
app/client/src/pages/Editor/IDE/EditorPane/Query/List.tsx Updated to use filterEntityGroupsBySearchTerm and renamed variables for clarity.
app/client/src/pages/Editor/IDE/EditorPane/fuzzySearchInFiles.test.ts Deleted file containing tests for the removed fuzzy search function.
app/client/src/pages/Editor/IDE/EditorPane/utils.ts Removed fuzzySearchInObjectItems function and related constants.

Assessment against linked issues

Objective Addressed Explanation
Create a util function filterList (37769)

Possibly related PRs

Suggested labels

Enhancement, Task, Bug, IDE Pod, ok-to-test

Suggested reviewers

  • albinAppsmith
  • hetunandu
  • sagar-qa007

🎉 In the realm of code, a new function shines,
Filtering groups with search terms so fine.
With tests in place, its logic is clear,
A joyful update, let’s give a cheer!
From fuzzy to precise, the changes align,
In the world of IDE, everything’s divine! 🌟


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:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (5)
app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.test.ts (1)

15-31: Add test cases for edge scenarios

The current test suite covers basic scenarios well. Consider adding tests for:

  • Case sensitivity handling
  • Special characters in search terms
  • Empty groups array input
test.each([
  ["FILE1", [{ name: "Group 1", items: [{ title: "file1" }] }]], // case sensitivity
  ["file#1", []], // special characters
  ["file1", [], []], // empty groups array
])("%s -> %j", (searchTerm, output) => {
  expect(filterEntityGroupsBySearchTerm(searchTerm, [])).toEqual(output);
});
app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.ts (1)

15-19: Consider making FUSE_OPTIONS configurable

The current implementation hardcodes the Fuse.js options. Consider making these configurable for different use cases.

-const FUSE_OPTIONS: FuseOptions<BaseItem> = {
+const DEFAULT_FUSE_OPTIONS: FuseOptions<BaseItem> = {
   shouldSort: true,
   threshold: 0.1,
   keys,
 };
+export const filterEntityGroupsBySearchTerm = <G extends BaseGroup, T extends BaseItem>(
+  searchTerm: string,
+  groups: Array<Group<G, T>>,
+  options: FuseOptions<BaseItem> = DEFAULT_FUSE_OPTIONS,
app/client/src/pages/Editor/IDE/EditorPane/Query/Add.tsx (2)

65-69: Simplify conditional rendering logic

The current implementation uses multiple conditions that could be simplified.

-{filteredItemGroups.length > 0 ? (
-  <GroupedList groups={filteredItemGroups} />
-) : null}
-{filteredItemGroups.length === 0 && searchTerm !== "" ? (
-  <EmptySearchResult
-    type={createMessage(EDITOR_PANE_TEXTS.search_objects.datasources)}
-  />
-) : null}
+{filteredItemGroups.length > 0 ? (
+  <GroupedList groups={filteredItemGroups} />
+) : searchTerm && (
+  <EmptySearchResult
+    type={createMessage(EDITOR_PANE_TEXTS.search_objects.datasources)}
+  />
+)}

32-34: Consider trimming search term for better UX

Trim the search term to handle whitespace consistently.

-const filteredItemGroups = filterEntityGroupsBySearchTerm(
-  searchTerm,
-  itemGroups,
-);
+const filteredItemGroups = filterEntityGroupsBySearchTerm(
+  searchTerm.trim(),
+  itemGroups,
+);
app/client/src/pages/Editor/IDE/EditorPane/JS/List.tsx (1)

Line range hint 85-113: Consider extracting common group rendering logic

The group rendering pattern is repeated across files. Consider extracting it into a shared component to improve maintainability.

Example structure:

interface EntityGroup {
  group: string;
  items: Array<any>;  // Type can be made more specific
}

interface EntityGroupListProps {
  groups: EntityGroup[];
  renderItem: (item: any) => React.ReactNode;
}

const EntityGroupList: React.FC<EntityGroupListProps> = ({ groups, renderItem }) => {
  // Common group rendering logic
};
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 0a046ed and 153de75.

📒 Files selected for processing (9)
  • app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.test.ts (1 hunks)
  • app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.ts (1 hunks)
  • app/client/src/IDE/utils/index.ts (1 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/JS/Add.tsx (3 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/JS/List.tsx (5 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/Query/Add.tsx (3 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/Query/List.tsx (3 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/fuzzySearchInFiles.test.ts (0 hunks)
  • app/client/src/pages/Editor/IDE/EditorPane/utils.ts (0 hunks)
💤 Files with no reviewable changes (2)
  • app/client/src/pages/Editor/IDE/EditorPane/utils.ts
  • app/client/src/pages/Editor/IDE/EditorPane/fuzzySearchInFiles.test.ts
✅ Files skipped from review due to trivial changes (1)
  • app/client/src/IDE/utils/index.ts
🔇 Additional comments (4)
app/client/src/pages/Editor/IDE/EditorPane/JS/Add.tsx (2)

56-61: LGTM! Clear and descriptive variable naming

The rename from groups to itemGroups better reflects the data structure and improves code readability.


64-67: Verify filter function behavior matches previous implementation

The implementation looks correct, but we should ensure the new filter maintains the same search experience.

Also applies to: 97-103

✅ Verification successful

Implementation verified with comprehensive test coverage

The new filterEntityGroupsBySearchTerm implementation is well-tested and maintains expected search behavior:

  • Uses Fuse.js for fuzzy searching with appropriate threshold (0.1)
  • Preserves empty search behavior (returns all groups)
  • Handles exact matches and non-matches correctly
  • Test cases cover empty search, exact match, no match, and partial match scenarios
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any tests comparing old vs new filter behavior
rg -l "fuzzySearchInObjectItems.*filterEntityGroupsBySearchTerm" -g "*.test.*"

Length of output: 80


Script:

#!/bin/bash
# Let's search for the old and new filter functions to understand the changes
rg -A 5 "fuzzySearchInObjectItems|filterEntityGroupsBySearchTerm" --type typescript

# Also search for test files related to these functions
fd -e test.ts -e test.tsx -e spec.ts -e spec.tsx -x rg -l "fuzzySearchInObjectItems|filterEntityGroupsBySearchTerm" {}

Length of output: 309


Script:

#!/bin/bash
# Let's examine the test file content to understand the test coverage
cat "./app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.test.ts"

# Let's also look for the implementation of both functions
rg -A 10 "fuzzySearchInObjectItems|filterEntityGroupsBySearchTerm" --type ts

Length of output: 11370


Script:

#!/bin/bash
# Let's look at the implementation of filterEntityGroupsBySearchTerm
cat "./app/client/src/IDE/utils/filterEntityGroupsBySearchTerm.ts"

# Also check if there's any trace of the old fuzzySearchInObjectItems implementation
rg "fuzzySearchInObjectItems" -B 5 -A 5

Length of output: 1322

app/client/src/pages/Editor/IDE/EditorPane/Query/List.tsx (1)

105-105: ⚠️ Potential issue

Fix object length check

The length check Object.keys(itemGroups).length === 0 seems incorrect since itemGroups is an array (based on its usage in the map function above).

-{Object.keys(itemGroups).length === 0 && <BlankState />}
+{(!itemGroups || itemGroups.length === 0) && <BlankState />}

Likely invalid or redundant comment.

app/client/src/pages/Editor/IDE/EditorPane/JS/List.tsx (1)

Line range hint 66-72: LGTM! Robust null checking

The implementation includes proper null checks and maintains consistency with the other files. The BlankState rendering condition is particularly well-handled.

Also applies to: 122-122

@github-actions github-actions bot added IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Task A simple Todo labels Dec 11, 2024
@alex-golovanov alex-golovanov added the ok-to-test Required label for CI label Dec 11, 2024
@alex-golovanov alex-golovanov merged commit 8a142c4 into release Dec 12, 2024
@alex-golovanov alex-golovanov deleted the feat/37769-filter-list-util branch December 12, 2024 07:06
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Dec 12, 2024
## Description
This pull request introduces a new utility function
`filterEntityGroupsBySearchTerm` to replace the existing
`fuzzySearchInObjectItems` function. Type inference is significantly
improved. Additionally, some renaming was done to convey true meaning
and improve readability.

Fixes [appsmithorg#37769](appsmithorg#37769)

## Automation

/ok-to-test tags="@tag.IDE"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/12277260297>
> Commit: 153de75
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12277260297&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.IDE`
> Spec:
> <hr>Wed, 11 Dec 2024 13:55:20 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced a new filtering functionality for entity groups based on
search terms.
- Added a test suite to validate the new filtering function across
various scenarios.

- **Bug Fixes**
- Updated components to use the new filtering method, improving search
result accuracy.

- **Chores**
- Removed obsolete fuzzy search functionality and associated tests to
streamline the codebase.

- **Refactor**
- Renamed variables for clarity and consistency throughout the
application.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product ok-to-test Required label for CI Task A simple Todo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create filterList util

2 participants