Skip to content

refactor: issue list modal refactor#6702

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
refactor-work_item_search_modal
Mar 6, 2025
Merged

refactor: issue list modal refactor#6702
sriramveeraghanta merged 1 commit intopreviewfrom
refactor-work_item_search_modal

Conversation

@vamsikrishnamathala
Copy link
Member

@vamsikrishnamathala vamsikrishnamathala commented Mar 5, 2025

Description

This update refactors the work items search modal, enabling it to be used with any search function.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

References

Summary by CodeRabbit

  • New Features
    • Enhanced the issue modal with flexible configuration options, allowing it to operate without a mandatory project identifier.
    • Added support for custom search behavior and dynamic updates of selected issues when the modal is activated.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 5, 2025

Walkthrough

The changes update the ExistingIssuesListModal component by modifying its Props type. The projectId is now optional, and two additional optional properties are introduced: one for preselected work items and another for a custom search service callback. The handleSearch function now conditionally uses the custom callback if provided, falling back to a standard search when a valid project ID is available. Additionally, a useEffect hook is added to update the selected issues based on the modal’s open state and the provided preselected work items.

Changes

File Path Change Summary
web/core/components/.../existing-issues-list-modal.tsx - Made projectId optional in Props.
- Added optional properties: selectedWorkItems and workItemSearchServiceCallback.
- Updated handleSearch to prefer workItemSearchServiceCallback and conditional fallback logic.
- Modified useEffect to set selected issues based on changes in isOpen and selectedWorkItems.

Sequence Diagram(s)

sequenceDiagram
    participant U as User
    participant M as ExistingIssuesListModal
    participant C as Custom Search Service Callback
    participant P as projectService.projectIssuesSearch

    U->>M: Trigger search
    M->>M: Check if workItemSearchServiceCallback is provided
    alt Custom Callback Provided
        M->>C: Invoke custom search with parameters
    else Fallback Search
        M->>M: Check if projectId is defined
        alt projectId exists
            M->>P: Call projectIssuesSearch with parameters
        else
            M-->>U: No search action executed
        end
    end
    Note over M,U: Update modal with search results
Loading

Possibly related PRs

Suggested labels

🧹chore

Suggested reviewers

  • sriramveeraghanta
  • anmolsinghbhatia
  • prateekshourya29

Poem

Oh, how the code does hop and bound,
A rabbit's tail in changes found.
Project IDs now optional, so light,
Custom searches make our modal bright.
With bugs chased off in a clever sprint,
We celebrate with a nibble and a wink!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
  • @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.

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
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: 0

🧹 Nitpick comments (3)
web/core/components/core/modals/existing-issues-list-modal.tsx (3)

92-111: Simplify conditional search service logic

The current approach works but can be made clearer by using early returns or conditional assignment patterns.

-  const handleSearch = () => {
-    if (!isOpen || !workspaceSlug) return;
-    setIsLoading(true);
-    const searchService =
-      workItemSearchServiceCallback ??
-      (projectId
-        ? projectService.projectIssuesSearch.bind(projectService, workspaceSlug?.toString(), projectId?.toString())
-        : undefined);
-    if (!searchService) return;
-    searchService({
-      search: debouncedSearchTerm,
-      ...searchParams,
-      workspace_search: isWorkspaceLevel,
-    })
+  const handleSearch = () => {
+    if (!isOpen || !workspaceSlug) return;
+    
+    // Return early if no search method is available
+    if (!workItemSearchServiceCallback && !projectId) return;
+    
+    setIsLoading(true);
+    
+    // Determine which search service to use
+    const searchService = workItemSearchServiceCallback ?? 
+      projectService.projectIssuesSearch.bind(projectService, workspaceSlug, projectId);
+    
+    searchService({
+      search: debouncedSearchTerm,
+      ...searchParams,
+      workspace_search: isWorkspaceLevel,
+    })

Also note that the .toString() calls are unnecessary as TypeScript will handle the string conversion automatically when needed.


119-121: Consider search behavior on modal close

The dependency array includes isOpen, which means handleSearch() will be called both when the modal opens and closes. When the modal is closing, the search is still triggered but has no visible effect since the modal is disappearing.

Consider adding a condition to skip the search operation when the modal is closing:

  useEffect(() => {
+   if (!isOpen) return;
    handleSearch();
  }, [debouncedSearchTerm, isOpen, isWorkspaceLevel, projectId, workspaceSlug]);

232-242: Translatable search text still pending

There's a TODO comment about translating the search results text that isn't addressed in this PR.

Consider updating this section to use the translation framework:

  {searchTerm !== "" && (
    <h5 className="mx-2 text-[0.825rem] text-custom-text-200">
-     Search results for{" "}
-     <span className="text-custom-text-100">
-       {'"'}
-       {searchTerm}
-       {'"'}
-     </span>{" "}
-     in project:
+     {t("search.results_for", { searchTerm })}{" "}
+     {isWorkspaceLevel ? t("search.in_workspace") : t("search.in_project")}
    </h5>
  )}

This assumes you add the appropriate translation keys to your i18n files.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac6fef3 and 9fc26ca.

📒 Files selected for processing (1)
  • web/core/components/core/modals/existing-issues-list-modal.tsx (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (4)
web/core/components/core/modals/existing-issues-list-modal.tsx (4)

27-27: Good enhancement of component flexibility!

Making projectId optional allows the component to be used in more contexts. This change aligns well with the added workItemSearchServiceCallback prop that can be used when projectId is unavailable.


34-35: Well-designed extension of the component API

The added props enhance the component's reusability by:

  1. Supporting pre-selected work items with selectedWorkItems
  2. Allowing custom search functionality with workItemSearchServiceCallback

This matches the PR objectives of making the modal reusable with any search function.


113-117: Correctly handles pre-selected work items

Good implementation of useEffect to update the selected issues based on external pre-selections when the modal opens or when the pre-selections change.


67-72: Consider persistence of selected issues

When the modal closes, handleClose() resets selectedIssues. With the new selectedWorkItems prop, you may want to reconsider this behavior.

If users frequently reopen the modal expecting their previous selections to persist, the current implementation would lose those selections. Consider whether:

  1. Selected issues should persist between modal openings
  2. Selected issues should reset only when explicitly requested
  3. The current behavior is in fact correct according to your requirements

The answer depends on the expected UX flow of your application.

@sriramveeraghanta sriramveeraghanta merged commit a40e44c into preview Mar 6, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the refactor-work_item_search_modal branch March 6, 2025 08:15
@sriramveeraghanta sriramveeraghanta added this to the v0.25.2 milestone Mar 9, 2025
aaryan610 pushed a commit that referenced this pull request Apr 9, 2025
* fix: issue stats refactor (#6705)

* fix: issue stats refactor

* fix: refactor

* fix: ui color

* fix: translation key

* refactor: issue list modal refactor (#6702)

---------

Co-authored-by: Akshita Goyal <36129505+gakshita@users.noreply.github.com>
Co-authored-by: Vamsi Krishna <46787868+vamsikrishnamathala@users.noreply.github.com>
Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
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