Skip to content

Conversation

@rahulramesha
Copy link
Contributor

@rahulramesha rahulramesha commented Dec 2, 2024

This PR fixes half block dragging to have better UX and only update the incomplete block when required.

Screen.Recording.2024-12-02.at.7.03.57.PM.mov

Summary by CodeRabbit

  • New Features

    • Enhanced block resizing logic in the Gantt chart, allowing blocks to revert to a default size when necessary.
    • Improved date positioning calculations in the timeline chart for better accuracy.
  • Bug Fixes

    • Corrected error handling for undefined dates in various functions, ensuring proper behavior when dates are missing.
  • Documentation

    • Updated comments and descriptions to reflect changes in logic and functionality.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The changes in this pull request involve updates to the IBaseTimelineStore interface and the BaseTimeLineStore class, specifically modifying the getUpdatedPositionAfterDrag method to include a new boolean parameter, shouldUpdateHalfBlock. Additionally, the useGanttResizable hook has been enhanced to manage block resizing more effectively by incorporating conditions based on start_date and target_date. The getItemPositionWidth function has also been adjusted to refine date positioning calculations. Overall, these changes focus on improving the functionality and logic related to timeline and Gantt chart interactions.

Changes

File Path Change Summary
web/ce/store/timeline/base-timeline.store.ts Updated getUpdatedPositionAfterDrag method in IBaseTimelineStore and BaseTimeLineStore to include shouldUpdateHalfBlock parameter.
web/core/components/gantt-chart/helpers/blockResizables/use-gantt-resizable.ts Modified useGanttResizable hook to revert block width to DEFAULT_BLOCK_WIDTH based on start_date and target_date, and updated handleMouseUp and handleMouseMove logic.
web/core/components/gantt-chart/views/helpers.ts Adjusted getItemPositionWidth to modify scrollPosition calculation when dates are undefined, and updated error handling in getDateFromPositionOnGantt.

Possibly related PRs

Suggested labels

🌟enhancement

Suggested reviewers

  • SatishGandham
  • sriramveeraghanta

🐰 In the timeline's dance, we hop and we play,
With blocks that resize in a clever new way.
Dates guide our path, as we leap and we bound,
In the Gantt chart's realm, new logic is found.
So let’s celebrate changes, both big and small,
For a timeline that's better, we’ll cheer for them all! 🎉


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

🧹 Outside diff range and nitpick comments (1)
web/ce/store/timeline/base-timeline.store.ts (1)

278-301: LGTM: Enhanced half-block update logic with improved control

The changes effectively handle half-block updates by conditionally updating dates based on the shouldUpdateHalfBlock parameter. The single updatePayload object approach improves code maintainability.

Minor documentation improvement suggested:

Apply this diff to enhance the method documentation:

   /**
    * returns updates dates of blocks post drag.
    * @param id
-   * @param shouldUpdateHalfBlock if is a half block then update the incomplete block only if this is true
+   * @param shouldUpdateHalfBlock When true, allows updating the missing date (start_date or target_date) during half-block drag
    * @returns
    */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3c6006d and 936a26b.

📒 Files selected for processing (3)
  • web/ce/store/timeline/base-timeline.store.ts (2 hunks)
  • web/core/components/gantt-chart/helpers/blockResizables/use-gantt-resizable.ts (3 hunks)
  • web/core/components/gantt-chart/views/helpers.ts (1 hunks)
🔇 Additional comments (3)
web/core/components/gantt-chart/views/helpers.ts (1)

102-102: LGTM: Improved scroll position calculation for half blocks

The adjustment to include chartData.data.dayWidth in the scroll position calculation when itemStartDate is not available ensures accurate positioning during half-block dragging.

web/core/components/gantt-chart/helpers/blockResizables/use-gantt-resizable.ts (2)

78-79: LGTM: Improved half-block resizing logic

The changes correctly handle half-block resizing by:

  • Reverting to default width when target_date is missing during left-handle drag
  • Reverting to default width and adjusting marginLeft when start_date is missing during right-handle drag

Also applies to: 83-90


124-124: ⚠️ Potential issue

Fix incomplete error handling

The setToast function is referenced but not invoked, which means errors during block updates won't be displayed to the user.

Apply this diff to fix the error handling:

-        setToast;
+        setToast({
+          message: "Error updating block position",
+          type: "error",
+        });

Likely invalid or redundant comment.

getUpdatedPositionAfterDrag: (id: string, ignoreDependencies?: boolean) => IBlockUpdateDependencyData[];
getUpdatedPositionAfterDrag: (
id: string,
shouldUpdateHalfBlock: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this flag?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, to make sure we only update the block's missing date, when the missing side is dragged. Either i pass down the side that is being dragged or the flag.

@pushya22 pushya22 merged commit da00712 into preview Dec 2, 2024
13 of 14 checks passed
@pushya22 pushya22 deleted the fix-half-block-dragging branch December 2, 2024 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛bug Something isn't working 🌐frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants