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

Added easy label creation to multiselect #425

Merged
merged 2 commits into from
Jan 3, 2025

Conversation

tonyaellie
Copy link
Collaborator

@tonyaellie tonyaellie commented Jan 2, 2025

What type of PR is this?

  • feature

What this PR does / why we need it:

Adds easy label creation to the label mutliselect component.
Also fixes the websocket connection in dev mode as this is needed for the easy label creation to work fully.

Which issue(s) this PR fixes:

Fixes #187

Summary by CodeRabbit

  • New Features

    • Enhanced Multiselect component with ability to create and add new items directly from search input
    • Improved WebSocket connection logic for different development environments
  • Refactor

    • Simplified Multiselect component props and rendering logic
    • Updated WebSocket host configuration for development mode

Copy link
Contributor

coderabbitai bot commented Jan 2, 2025

Walkthrough

The pull request introduces enhancements to the Multiselect component, focusing on improving label creation and management. The changes primarily involve modifying the dropdown rendering logic, simplifying prop management, and adding a new feature that allows users to create labels dynamically during item creation. Additionally, a WebSocket connection configuration update has been made to support different development environments.

Changes

File Change Summary
frontend/components/Form/Multiselect.vue - Removed name and uniqueField props
- Updated item rendering with itm.id and itm.name
- Added dynamic label creation functionality
- Simplified filtering and selection logic
frontend/composables/use-server-events.ts - Added environment-specific WebSocket host configuration
- Modified connection logic for development environment

Assessment against linked issues

Objective Addressed Explanation
Easy Label Creation [#187]

Possibly related PRs

Suggested reviewers

  • tankerkiller125

Security Recommendations

  1. Validate and sanitize user input when creating new labels to prevent potential injection attacks.
  2. Implement rate limiting on the label creation API endpoint to prevent abuse.
  3. Ensure proper error handling and validation in the createAndAdd function to prevent unexpected behavior.
  4. Add authentication checks to confirm user permissions before allowing label creation.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1638e35 and d0a0cbd.

📒 Files selected for processing (2)
  • frontend/components/Form/Multiselect.vue (5 hunks)
  • frontend/composables/use-server-events.ts (1 hunks)
🔇 Additional comments (7)
frontend/components/Form/Multiselect.vue (7)

8-9: Keying by itm.id for each item
Using itm.id as a key is appropriate for stable rendering. Ensure each itm.id is truly unique and non-sensitive so that IDs are not accidentally exposed.


33-33: Highlight selected items
Conditionally adding the bordered class to selected items is clear and self-documenting. This maintains good UX for distinguishing selected vs. non-selected items.


36-37: Click handler references ID
Referencing obj.id for toggling selection is consistent with the rest of the code. This is a neat improvement over referencing a more generic unique field.


40-42: Conditional new item creation
Displaying a button to create new items only if no exact match is found is a great UX enhancement. Just confirm that partial but not exact matches behave as intended.


91-91: Selected items array
Extracting item IDs into a separate computed property is a good approach for clarity.


95-97: toggle function logic
The toggling approach is well-structured, removing or adding items based on whether they're already selected. Good job keeping the logic short and clear.


103-104: API & notifier references
Defining api and toast at the top keeps the necessary dependencies together and well-organized.


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.

@tonyaellie
Copy link
Collaborator Author

Currently creating a label closes the multiselect dropdown, in theory there is also a race condition if the user creates a label and then quickly submits it, its also not especially clear that a label is being created not sure how much we care about these issues though? @tankerkiller125 @katosdev

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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments.

Actionable comments posted: 1

🧹 Nitpick comments (3)
frontend/composables/use-server-events.ts (1)

21-23: Use environment-based configuration for clarity and security
Having the dynamic replacement for the port in development mode is good for local testing. However, consider reading the environment configuration (e.g., from environment variables or a separate config file) so as to avoid potential confusion and to ensure the port isn't inadvertently exposed or changed in production.

frontend/components/Form/Multiselect.vue (2)

23-23: Dropdown styling
The z-[9999] ensures the dropdown stays above other elements. Just confirm that this high z-index won't introduce weird stacking issues in complex UIs.


82-82: Search filtering
Filtering by item.name.toLowerCase() is straightforward. Be mindful of items that may have additional relevant fields (e.g., synonyms) in the future.

🛑 Comments failed to post (1)
frontend/components/Form/Multiselect.vue (1)

106-119: ⚠️ Potential issue

Item creation with user-specified name
The asynchronous call to api.labels.create followed by updating the local array is correct. Validate user input to avoid any potential injection or unwanted characters, particularly if these labels appear in any shared or public context.

[security_recommendation]

+ // Example code snippet
+ function sanitizeName(name: string): string {
+   return name.replace(/[^\w\s-]/g, "");
+ }
+ 
async function createAndAdd(name: string) {
  // ...
}

Committable suggestion skipped: line range outside the PR's diff.

@tonyaellie
Copy link
Collaborator Author

I also removed the generalisation and made it specific to labels, this makes it a lot more readable and if we want to have a multi select for something else we can always copy it.

@tankerkiller125
Copy link
Contributor

I'm perfectly fine with a race condition as long as it's not something drastic that happens basically every time unless you wait 3 minutes or something stupid.

Generally I like to avoid them, but if it's something that should happen basically instantly, I'm not too worried about it.

@tankerkiller125 tankerkiller125 merged commit 2b4ad93 into main Jan 3, 2025
12 checks passed
@tonyaellie tonyaellie deleted the tonya/easy-label-creation branch January 3, 2025 21:00
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.

Easy Label Creation
2 participants