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(dialogs): skills, custom-section, and interests dialogs support draggable tags. #2244

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

m4dd0c
Copy link

@m4dd0c m4dd0c commented Mar 19, 2025

closes #2243

Summary by CodeRabbit

  • New Features
    • Enabled drag-and-drop reordering for keywords in multiple dialogs, including Custom Section, Interests, and Skills. Users can now rearrange keywords intuitively, improving the organization and usability of these sections.

Copy link

coderabbitai bot commented Mar 19, 2025

📝 Walkthrough

Walkthrough

The changes add drag-and-drop functionality for managing keyword lists in three dialog components: CustomSectionDialog, InterestsDialog, and SkillsDialog. Each component now tracks the index of a dragged item with a new state variable and implements dedicated event handlers (handleDragOver and handleDrop). These modifications allow users to reposition keywords dynamically, with the UI elements updated to support draggable interactions.

Changes

Files Change Summary
apps/client/src/.../dialogs/{custom-section, interests, skills}.tsx Added drag-and-drop functionality: introduced a draggedIndex state variable, implemented handleDragOver to prevent default behavior, and added handleDrop to reorder keywords. UI elements (motion.div) now include draggable attributes and relevant event handlers.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Component
    participant KeywordsList

    User->>Component: Initiates drag (onDragStart)
    Component->>Component: Set draggedIndex state
    User->>Component: Drags over keyword (onDragOver)
    Component->>Component: Prevents default behavior
    User->>Component: Drops keyword (onDrop)
    Component->>KeywordsList: Reorders keywords based on draggedIndex and drop target
    Component->>Component: Resets draggedIndex state
Loading

Assessment against linked issues

Objective Addressed Explanation
Add draggable functionality for tags in skills, interests, and custom-section dialogs (#2243)

Possibly related PRs

Poem

I'm a rabbit on a code-filled quest,
Hopping through keywords with my best zest.
Dragging and dropping with style so bright,
Rearranging tags to set things right.
Code and carrots, a delightful sight!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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

@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 (2)
apps/client/src/pages/builder/sidebars/left/dialogs/interests.tsx (2)

34-37: Move handleDragOver outside the component function.

The ESLint error correctly identifies that the handleDragOver function doesn't use any component state or props, so it can be moved outside the component for better performance.

 type FormValues = z.infer<typeof formSchema>;
 
+const handleDragOver = (e: React.DragEvent) => {
+  e.preventDefault();
+};
+
 export const InterestsDialog = () => {
   const form = useForm<FormValues>({
     defaultValues: defaultInterest,
     resolver: zodResolver(formSchema),
   });
 
   const [pendingKeyword, setPendingKeyword] = useState("");
   const [draggedIndex, setDraggedIndex] = useState<number | null>(null);
-  const handleDragOver = (e: React.DragEvent) => {
-    e.preventDefault();
-  };
🧰 Tools
🪛 ESLint

[error] 35-35: Move arrow function 'handleDragOver' to the outer scope.

(unicorn/consistent-function-scoping)


1-130: Consider applying consistent code structure across dialog components.

For better maintainability, you should apply the same code structure improvement suggested for this file to the other dialog components (SkillsDialog and CustomSectionDialog) - moving the handleDragOver function outside of the component definition since it doesn't use any component state.

🧰 Tools
🪛 ESLint

[error] 35-35: Move arrow function 'handleDragOver' to the outer scope.

(unicorn/consistent-function-scoping)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between cd21860 and a8626e4.

📒 Files selected for processing (3)
  • apps/client/src/pages/builder/sidebars/left/dialogs/custom-section.tsx (3 hunks)
  • apps/client/src/pages/builder/sidebars/left/dialogs/interests.tsx (2 hunks)
  • apps/client/src/pages/builder/sidebars/left/dialogs/skills.tsx (2 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
apps/client/src/pages/builder/sidebars/left/dialogs/skills.tsx (1)
libs/schema/src/sections/skill.ts (1) (1)
  • defaultSkill (17-23)
🪛 ESLint
apps/client/src/pages/builder/sidebars/left/dialogs/interests.tsx

[error] 35-35: Move arrow function 'handleDragOver' to the outer scope.

(unicorn/consistent-function-scoping)

🔇 Additional comments (11)
apps/client/src/pages/builder/sidebars/left/dialogs/skills.tsx (4)

28-30: Well-implemented drag handler function.

The handleDragOver function correctly prevents the default behavior, which is necessary for proper drag-and-drop functionality to work.


39-39: Good state implementation for drag tracking.

Using a nullable number for tracking the dragged item's index is appropriate for this use case.


41-55: Well-structured drop handler with proper safeguards.

The handleDrop function:

  • Prevents default behavior
  • Handles the null case safely
  • Creates a new array to maintain immutability
  • Correctly performs the array manipulation for reordering
  • Resets the drag state after completion

This implementation follows React best practices for state updates.


146-156: Properly implemented drag event handlers.

The drag-and-drop event handlers are correctly implemented on the motion.div component, enabling the reordering functionality while maintaining the component's animation capabilities.

apps/client/src/pages/builder/sidebars/left/dialogs/custom-section.tsx (4)

33-35: Well-implemented drag handler function.

The handleDragOver function correctly prevents the default behavior, which is necessary for proper drag-and-drop functionality to work.


47-47: Good state implementation for drag tracking.

Using a nullable number for tracking the dragged item's index is appropriate for this use case.


49-63: Well-structured drop handler with proper safeguards.

The handleDrop function:

  • Prevents default behavior
  • Handles the null case safely
  • Creates a new array to maintain immutability
  • Correctly performs the array manipulation for reordering
  • Resets the drag state after completion

This implementation follows React best practices for state updates.


197-207: Properly implemented drag event handlers.

The drag-and-drop event handlers are correctly implemented on the motion.div component, enabling the reordering functionality while maintaining the component's animation capabilities.

apps/client/src/pages/builder/sidebars/left/dialogs/interests.tsx (3)

34-34: Good state implementation for drag tracking.

Using a nullable number for tracking the dragged item's index is appropriate for this use case.


39-53: Well-structured drop handler with proper safeguards.

The handleDrop function:

  • Prevents default behavior
  • Handles the null case safely
  • Creates a new array to maintain immutability
  • Correctly performs the array manipulation for reordering
  • Resets the drag state after completion

This implementation follows React best practices for state updates.


99-109: Properly implemented drag event handlers.

The drag-and-drop event handlers are correctly implemented on the motion.div component, enabling the reordering functionality while maintaining the component's animation capabilities.

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

🧹 Nitpick comments (1)
apps/client/src/pages/builder/sidebars/left/dialogs/interests.tsx (1)

100-110: Consider enhancing drag-and-drop accessibility

While the draggable implementation works well, consider adding:

  1. Visual feedback during drag operations (e.g., opacity changes or shadows)
  2. Keyboard navigation alternatives for users who cannot use drag-and-drop
  3. ARIA attributes for screen reader support

Example enhancement for visual feedback:

 <motion.div
   key={item}
   layout
   draggable
+  className={draggedIndex === index ? "opacity-50" : ""}
   initial={{ opacity: 0, y: -50 }}
   animate={{ opacity: 1, y: 0, transition: { delay: index * 0.1 } }}
   exit={{ opacity: 0, x: -50 }}
   onDragStart={() => {
     setDraggedIndex(index);
   }}
   onDragOver={handleDragOver}
   onDrop={(e) => {
     handleDrop(e, index, field);
   }}
+  aria-grabbed={draggedIndex === index}
+  aria-dropeffect="move"
 >
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a8626e4 and 1994dde.

📒 Files selected for processing (1)
  • apps/client/src/pages/builder/sidebars/left/dialogs/interests.tsx (2 hunks)
🔇 Additional comments (3)
apps/client/src/pages/builder/sidebars/left/dialogs/interests.tsx (3)

27-29: Clean implementation of handleDragOver function

The function properly prevents the default dragover behavior, which is necessary to enable dropping elements.


38-38: Good state management for drag tracking

The draggedIndex state variable is appropriately implemented to track which item is currently being dragged.


40-54: Well-structured handleDrop implementation

The drop handler logic correctly:

  1. Creates a new array to maintain immutability
  2. Removes the item from its original position
  3. Inserts it at the new position
  4. Updates the field value
  5. Resets the drag state

This implementation follows React best practices for state updates.

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.

[Feature] Add functionality to make tags draggable.
1 participant