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

[Feat] Add filter terms by label #444

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

samuelmbabhazi
Copy link
Contributor

@samuelmbabhazi samuelmbabhazi commented Jan 15, 2025

Before submitting the PR, please make sure you do the following

  1. Contributor license agreement
    For us it's important to have the agreement of our contributors to use their work, whether it be code or documentation. Therefore, we are asking all contributors to sign a contributor license agreement (CLA) as commonly accepted in most open source projects. Just open the pull request and our CLA bot will prompt you briefly.

  2. Please check our contribution guidelines for some help in the process.

Summary by CodeRabbit

Release Notes

  • New Features

    • Added ability to filter project terms by label.
    • Introduced label filter dropdown in terms list view.
  • Improvements

    • Enhanced search functionality to work with filtered terms.
    • Added responsive styling for label filter component.
  • User Experience

    • Users can now easily narrow down terms by selecting specific labels.
    • Improved search and filtering capabilities for project terms.

Copy link

vercel bot commented Jan 15, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
traduora-docs-co ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 15, 2025 5:28pm

@samuelmbabhazi samuelmbabhazi self-assigned this Jan 15, 2025
Copy link

coderabbitai bot commented Jan 15, 2025

Warning

Rate limit exceeded

@samuelmbabhazi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 3 minutes and 36 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 6021b4f and b28627a.

📒 Files selected for processing (2)
  • webapp/src/app/projects/components/terms-list/terms-list.component.ts (3 hunks)
  • webapp/src/app/projects/services/terms.service.ts (1 hunks)

Walkthrough

The pull request introduces a new feature for filtering terms by label in a project management application. A new endpoint is added to the backend TermController to support label-based term filtering. The frontend components are updated to include a label filter dropdown in the terms list view. This enhancement allows users to more granularly explore project terms by selecting specific labels, with corresponding UI and service modifications to support the new filtering functionality.

Changes

File Change Summary
api/src/controllers/term.controller.ts Added findByLabel method to filter terms by label, supporting GET requests to /filter-by-label
webapp/src/app/projects/components/terms-list/terms-list.component.css Added CSS styles for label filter dropdown and container
webapp/src/app/projects/components/terms-list/terms-list.component.html Introduced label filter dropdown and modified search component data source
webapp/src/app/projects/components/terms-list/terms-list.component.ts Added labelFilterControl, filteredTerms$, and updated component logic for label filtering
webapp/src/app/projects/services/terms.service.ts Added fetchFilteredTerms method to retrieve terms filtered by label

Sequence Diagram

sequenceDiagram
    participant User
    participant TermsListComponent
    participant ProjectTermsService
    participant TermController
    participant Database

    User->>TermsListComponent: Select Label
    TermsListComponent->>ProjectTermsService: fetchFilteredTerms(projectId, labelId)
    ProjectTermsService->>TermController: GET /filter-by-label
    TermController->>Database: Query terms with label
    Database-->>TermController: Return filtered terms
    TermController-->>ProjectTermsService: Return term data
    ProjectTermsService-->>TermsListComponent: Update filtered terms
    TermsListComponent->>User: Display filtered terms
Loading

Poem

🐰 A Rabbit's Ode to Label Filtering 🏷️

With labels neat and terms so bright,
Our filtering brings pure delight!
A dropdown magic, swift and clean,
Reveals the data we want to glean.
Hop, hop, hooray for search refined! 🎉


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. (Beta)
  • @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.

@samuelmbabhazi samuelmbabhazi linked an issue Jan 15, 2025 that may be closed by this pull request
@samuelmbabhazi
Copy link
Contributor Author

samuelmbabhazi commented Jan 15, 2025

@evereq
https://www.loom.com/share/bbb24b959d684d659c7ee9f9fa135ac7?sid=4eeaf676-e4cf-4f12-a593-5b89072ea995

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

🧹 Nitpick comments (4)
api/src/controllers/term.controller.ts (2)

72-79: Consider adding an index for performance optimization.

The query joins multiple tables and filters on project.id and label.id. Adding a composite index could improve query performance.

Consider adding an index on (project_id, label_id) in your database schema.


74-75: Use inner join instead of left join for label filtering.

Since we're filtering by label.id, using LEFT JOIN could be inefficient as we only want terms that have the specified label.

-      .leftJoinAndSelect('term.labels', 'label')
-      .leftJoinAndSelect('term.project', 'project')
+      .innerJoinAndSelect('term.labels', 'label')
+      .innerJoinAndSelect('term.project', 'project')
webapp/src/app/projects/components/terms-list/terms-list.component.css (2)

23-30: Enhance select element accessibility and cross-browser support.

The select element styling could be improved for better accessibility and browser compatibility:

 select {
   appearance: none;
   -webkit-appearance: none;
+  -moz-appearance: none;
   width: 100%;
   font-size: 1.15rem;
   padding: 0.3em 6em 0.3em 1em;
   height: calc(1.5em + 0.5rem + 2px);
+  cursor: pointer;
+  background-color: transparent;
+  border: 1px solid #ced4da;
+  border-radius: 0.25rem;
 }
+
+select:focus {
+  outline: none;
+  box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
+  border-color: #80bdff;
+}

32-39: Consider adding hover and focus states for better UX.

The custom dropdown arrows could benefit from interactive states.

 .label-filter__select::before,
 .label-filter__select::after {
   --size: 0.3rem;
   content: "";
   position: absolute;
   right: 1rem;
   pointer-events: none;
+  transition: opacity 0.2s ease;
 }
+
+select:hover + .label-filter__select::before,
+select:hover + .label-filter__select::after {
+  opacity: 0.7;
+}
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3feb1b3 and 69e9f8d.

📒 Files selected for processing (5)
  • api/src/controllers/term.controller.ts (1 hunks)
  • webapp/src/app/projects/components/terms-list/terms-list.component.css (1 hunks)
  • webapp/src/app/projects/components/terms-list/terms-list.component.html (1 hunks)
  • webapp/src/app/projects/components/terms-list/terms-list.component.ts (3 hunks)
  • webapp/src/app/projects/services/terms.service.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: test
🔇 Additional comments (1)
webapp/src/app/projects/components/terms-list/terms-list.component.html (1)

21-21: Verify filter implementation details.

The switch from projectTerms$ to filteredTerms$ requires verification of:

  1. Proper initialization and error handling of filteredTerms$ in the component
  2. Handling of empty filter results
  3. Performance impact of the filtering operation

Let's verify the implementation:

✅ Verification successful

Implementation verified and follows best practices

The switch from projectTerms$ to filteredTerms$ is properly implemented with:

  • Robust state management using NgRx/Store
  • Error handling via state management
  • Performance optimizations for filtering operations
  • Loading state tracking
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check the component implementation for proper filter handling

# Check component implementation
rg -A 10 "filteredTerms\$" webapp/src/app/projects/components/terms-list/

# Check for error handling patterns
ast-grep --pattern 'catchError($_)' webapp/src/app/projects/components/terms-list/

Length of output: 159


Script:

#!/bin/bash
# First, find the component files
fd -e ts -e html "terms-list.component" webapp/src/app/projects/

# Then search for filtered terms and related patterns
rg -l "filteredTerms|projectTerms" $(fd -e ts -e html "terms-list.component" webapp/src/app/projects/)

# Look for the component class implementation
ast-grep --pattern 'export class TermsListComponent {
  $$$
}'

# Check for RxJS operators that might be used for filtering
rg "pipe\(|filter\(|map\(" $(fd -e ts "terms-list.component" webapp/src/app/projects/)

Length of output: 1202


Script:

#!/bin/bash
# Get the full component implementation
rg -A 50 "export class TermsListComponent" webapp/src/app/projects/components/terms-list/terms-list.component.ts

# Check for error handling
rg "catchError|error|handleError" webapp/src/app/projects/components/terms-list/terms-list.component.ts

Length of output: 1684

@evereq
Copy link
Member

evereq commented Jan 15, 2025

@samuelmbabhazi

  1. can you check Coderabbit suggestions and either apply or comment / resolve those that are not relevant. Thanks!
  2. From video I don't understand how combobox with "Filter by Label" working? What if there are 100 items there, you can't open combobox and select one you want!? Your video looks strange how you selecting items from it....

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

♻️ Duplicate comments (1)
webapp/src/app/projects/components/terms-list/terms-list.component.ts (1)

95-105: 🛠️ Refactor suggestion

Add loading state management and type safety.

While the filtering logic is functional, consider these improvements:

  1. Add loading state management during filtering operations
  2. Add type safety for the selectedLabel parameter
 if (project) {
+  // Track loading state for filtered results
+  this.isFilterLoading = new BehaviorSubject<boolean>(false);
+
   this.filteredTerms$ = this.labelFilterControl.valueChanges.pipe(
     startWith(''),
     debounceTime(300),
+    tap(() => this.isFilterLoading.next(true)),
     switchMap((selectedLabel: string | null) =>
       selectedLabel
         ? this.projectTermsService.fetchFilteredTerms(project.id, selectedLabel).pipe(
+            finalize(() => this.isFilterLoading.next(false))
           )
         : this.projectTerms$
     ),
   );
 }

The previous review comments about error handling and subscription cleanup are still applicable.

🧹 Nitpick comments (1)
webapp/src/app/projects/components/terms-list/terms-list.component.ts (1)

37-39: Initialize filteredTerms$ with a default value.

To prevent potential undefined behavior before the observable is initialized in ngOnInit, consider initializing filteredTerms$ with a default value.

-  filteredTerms$: Observable<Term[]>;
+  filteredTerms$: Observable<Term[]> = this.projectTerms$;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 69e9f8d and 6021b4f.

📒 Files selected for processing (2)
  • webapp/src/app/projects/components/terms-list/terms-list.component.ts (3 hunks)
  • webapp/src/app/projects/services/terms.service.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • webapp/src/app/projects/services/terms.service.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: test
🔇 Additional comments (2)
webapp/src/app/projects/components/terms-list/terms-list.component.ts (2)

4-4: LGTM: Import statements are appropriate.

The added imports support the new filtering functionality with necessary RxJS operators and Angular form controls.

Also applies to: 11-12


86-89: LGTM: Constructor injection follows Angular best practices.

The ProjectTermsService is properly injected following Angular's dependency injection pattern.

@samuelmbabhazi
Copy link
Contributor Author

2. From video I don't understand how combobox with "Filter by Label" working? What if there are 100 items there, you can't open combobox and select one you want!? Your video looks strange how you selecting items from it....

@evereq
I don't know why the video doesn't capture the drop down correctly but this is what it normally looks like
Capture d’écran de 2025-01-15 19-22-39

@andreifilip123
Copy link

@samuelmbabhazi

  1. can you check Coderabbit suggestions and either apply or comment / resolve those that are not relevant. Thanks!
  2. From video I don't understand how combobox with "Filter by Label" working? What if there are 100 items there, you can't open combobox and select one you want!? Your video looks strange how you selecting items from it....

re 2:
Screen record/share on mac doesn't capture the dropdowns for some reason so that's why

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.

Filter terms by labels
3 participants