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

change: [M3-8533, M3-8761] - Fix firewall rules table and Replace react-beautiful-dnd with dnd-kit lib #11127

Conversation

pmakode-akamai
Copy link
Contributor

@pmakode-akamai pmakode-akamai commented Oct 21, 2024

Description 📝

While working on ticket M3-8533 & PR #11109, we decided to implement/use semantic markup for the Firewall rules table to improve consistency and accessibility, rather than applying a styling band-aid to div grids to make it look like our normal tables. The react-beautiful-dnd library has made us rely on div(Box) grids instead of our normal tables, which complicates using semantic tables/grid layouts because of the draggable elements. Plus, this library has been deprecated (announcement: atlassian/react-beautiful-dnd#2672).

To solve these problems and make better use of our normal tables, switching to dnd-kit(https://dndkit.com/) would be the great idea, which is more popular, supports grid layouts better, and can replace react-beautiful-dnd. This will help us use our semantic tables properly and fix the issues with the Firewall rules table in both dark and light modes.

Changes 🔄

List any change relevant to the reviewer.

  • Used Normal tables instead of Div Box grids
  • Updated PolicyRow
    • Changed it to have borders on all sides.
    • Changed the alignment of the Select and helper text to be aligned with the Action column for screens < 'md', and with the last column for screens >= 'md'.
  • Replaced react-beautiful-dnd with dnd-kit lib
  • Fix <Table /> styling for noOverflow property

Target release date 🗓️

N/A

Preview 📷

Before After
Screenshot 2024-10-21 at 6 21 23 PM Screenshot 2024-10-21 at 6 20 12 PM
Screenshot 2024-10-21 at 6 22 28 PM Screenshot 2024-10-21 at 6 23 24 PM

How to test 🧪

Prerequisites

  • Clear cache or test in Incognito.

Reproduction steps

Verification steps

  • Ensure the table is not broken in both dark and light modes.
  • Verify table across different screen sizes and ensure it matches our normal table colors.
  • Ensure the drag and drop functionality work as expected in different screen sizes.
  • Verify all firewall rule actions work as expected.

As an Author I have considered 🤔

Check all that apply

  • 👀 Doing a self review
  • ❔ Our contribution guidelines
  • 🤏 Splitting feature into small PRs
  • ➕ Adding a changeset
  • 🧪 Providing/Improving test coverage
  • 🔐 Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • 👣 Providing comprehensive reproduction steps
  • 📑 Providing or updating our documentation
  • 🕛 Scheduling a pair reviewing session
  • 📱 Providing mobile support
  • ♿ Providing accessibility support

@pmakode-akamai pmakode-akamai self-assigned this Oct 21, 2024
@pmakode-akamai pmakode-akamai marked this pull request as ready for review October 21, 2024 12:56
@pmakode-akamai pmakode-akamai requested a review from a team as a code owner October 21, 2024 12:56
@pmakode-akamai pmakode-akamai requested review from cpathipa and hkhalil-akamai and removed request for a team October 21, 2024 12:56
Copy link

github-actions bot commented Oct 21, 2024

Coverage Report:
Base Coverage: 87.32%
Current Coverage: 86.95%

@pmakode-akamai pmakode-akamai force-pushed the M3-8533-fix-firewall-rules-table-and-replace-react-beautiful-dnd-with-dnd-kit branch from c42e8b1 to 33ded4a Compare October 21, 2024 14:14
Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

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

Fantastic work @pmakode-akamai, and really appreciate considering going with a more holistic refactor, including replacing a non-supported library.

Implementation, markup and styling looks great (in both modes) for the most part, leaving some comments that shouldn't take too much extra work to implement.

Screenshot 2024-10-21 at 10 57 48

Screenshot 2024-10-21 at 11 03 49

packages/manager/package.json Show resolved Hide resolved
@pmakode-akamai pmakode-akamai force-pushed the M3-8533-fix-firewall-rules-table-and-replace-react-beautiful-dnd-with-dnd-kit branch from 33ded4a to e425c84 Compare October 22, 2024 05:51
@abailly-akamai
Copy link
Contributor

@pmakode-akamai I believe the e2e failure is relevant here - you may want to take a look at firewalls/update-firewall.spec.ts

@pmakode-akamai pmakode-akamai requested a review from a team as a code owner October 22, 2024 13:44
@pmakode-akamai pmakode-akamai requested review from cliu-akamai and removed request for a team October 22, 2024 13:44
Copy link
Member

@bnussman-akamai bnussman-akamai left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

For whatever reason, the dragging is not nearly as smooth as the previous implementation for me. I did try the dndkit examples and they were much smoother. Could this be something wrong on our end?

develop This PR
Screen.Recording.2024-10-22.at.10.44.04.AM.mov
Screen.Recording.2024-10-22.at.10.38.40.AM.mov

I'm also noticing that the table row is can't overflow outside of the table like it did previously when dragging. Not a blocker, but I liked how previously the row was "on top" of everything when dragging.

@pmakode-akamai
Copy link
Contributor Author

pmakode-akamai commented Oct 22, 2024

For whatever reason, the dragging is not nearly as smooth as the previous implementation for me. I did try the dndkit examples and they were much smoother. Could this be something wrong on our end?

Hi @bnussman-akamai, I think we can definitely add a transition (something like in this) to make the drag animation smoother. However, I'm having some difficulty figuring out how the dnd-kit is handling onDragEnd in our case.

I'm encountering a similar issue to what was mentioned here when I try to add the transition. Looks like dnd-kit works fine with local state but not so much with async state (as per this comment). In our case, the way we are reordering onDragEnd is not straight forward.

I will check how we can add a transition in our case somehow.

I'm also noticing that the table row is can't overflow outside of the table like it did previously when dragging. Not a blocker, but I liked how previously the row was "on top" of everything when dragging.

I agree, the DndContext is currently applied to the table, which is why the table row can’t overflow outside of it like it did previously. We can explore adjustments to allow the row to appear 'on top' during dragging.

@pmakode-akamai
Copy link
Contributor Author

pmakode-akamai commented Oct 23, 2024

@abailly-akamai @bnussman-akamai

For whatever reason, the dragging is not nearly as smooth as the previous implementation for me. I did try the dndkit examples and they were much smoother. Could this be something wrong on our end?

update: The smoothness while dragging rows has been improved! ✅

I'm also noticing that the table row is can't overflow outside of the table like it did previously when dragging. Not a blocker, but I liked how previously the row was "on top" of everything when dragging.

To allow dragging over the top of current page / overflow outside of the table, we can simply add a noOverflow={true} prop to the <Table /> component (as overflow is not allowing us to drag over the top). However, this changes the styling of the header due to how noOverflow is implemented in our <Table /> component.

  • With noOverflow={true}
    Screenshot 2024-10-23 at 9 30 57 PM
Screen.Recording.2024-10-23.at.10.37.43.PM.mov

I’d like to confirm if we want to apply this header styling with noOverflow={true} for the FirewallRulesTable. Additionally, should we maintain the overflow settings for Firewall Rules Table, considering that the version in production does not have overflow?

@abailly-akamai
Copy link
Contributor

@pmakode-akamai @bnussman-akamai

It struck me that adding noOverflow to allow overflow was smelly 😄

I pushed a commit to:

  • Make sure the table header styling isn't dependent on the noOverflow property (this was clearly a bug)
  • Reverted the styling so noOverflow actually implements the proper CSS
    I looked at a couple components that had this property declared and did not see any regression. Not sure what the intent was when adding it, but since it did the opposite it's worth checking

@abailly-akamai abailly-akamai self-requested a review October 23, 2024 19:27
Copy link
Contributor

@abailly-akamai abailly-akamai left a comment

Choose a reason for hiding this comment

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

Great work - thanks for the contribution 👍

@bnussman-akamai
Copy link
Member

In production I'm able to re-order rules with the keyboard (using space then up and down arrow keys). In this PR I don't think I can do that, but I may be missing something. Is this something we can accomplish with dndkit?

@abailly-akamai
Copy link
Contributor

@bnussman-akamai

The team seems to have put great care into accessibility for this component, which is great - https://docs.dndkit.com/guides/accessibility#keyboard-support

This implementation was missing the keyboard sensors, which surprise me isn't a default. Anyway, added them. You experience may differ slightly from the previous plugin tho

},
}),
useSensor(TouchSensor),
useSensor(KeyboardSensor)
Copy link
Contributor

@hkhalil-akamai hkhalil-akamai Oct 23, 2024

Choose a reason for hiding this comment

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

I don't think the KeyboardSensor achieves the effect we're looking for. It moves items in the keyed direction by 25px, which can make it difficult to precisely change the place of the item. It allows moving the item left and right and also scrolls the page.

Screen.Recording.2024-10-23.at.6.47.21.PM.mov

I can't find an option within dnd-kit that accomplishes the prior behavior. My recommendation is to setup a custom key handler that calls triggerReorder as well as e.preventDefault() to prevent the scrolling issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's fair!

I can't find an option within dnd-kit that accomplishes the prior behavior.

I believe the commit underneath achieves parity with the previous behavior, while still using the kit and avoiding a custom key handler. Can you confirm?

680049a

Copy link
Contributor

Choose a reason for hiding this comment

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

This gets closer but I'm still seeing some weird behavior when the page has vertical scrolling enabled. It's hard to describe but you can see it for yourself by Ctrl-+'ing in until the page overflows.

Copy link
Contributor Author

@pmakode-akamai pmakode-akamai Oct 29, 2024

Choose a reason for hiding this comment

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

@abailly-akamai @hkhalil-akamai I tried different ways and even used e.preventDefault() to prevent window scrolling (when the browser has vertical scroll enabled) while the KeyboardSensor is active. However, this didn't work due to how the dnd-kit KeyboardSensor is implemented, as it adds default scrolling behavior. After extensive digging 🥲, I found that the handleKeyDown method from the KeyboardSensor does not allow us to override the scrolling behavior when using keyboard keys. As a result, I customized the dnd-kit library code itself to meet our requirements 😅, and some how I was able to prevent the scroll behavior when using keyboard keys ✅

Could you take a look?

a839fef

Copy link
Contributor

Choose a reason for hiding this comment

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

Great digging, this works exactly like I would expect it to! 👏🏽🎉

overflowX: 'auto',
overflowY: 'hidden',
Copy link
Contributor Author

@pmakode-akamai pmakode-akamai Oct 24, 2024

Choose a reason for hiding this comment

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

@abailly-akamai

  • I looked at a couple components that had this property declared and did not see any regression. Not sure what the intent was when adding it, but since it did the opposite it's worth checking

Thank you for the changes, but I wonder if the intent was to enable a horizontal scrollbar for all tables by default, without the noOverflow property (for smaller screens or at time when the table content tend to overflow)?

Browser window adjusted / or on smaller screens:

On Prod On this Branch with these changes
Screenshot 2024-10-24 at 4 25 16 PM Screenshot 2024-10-24 at 4 51 33 PM

If the plan is to apply overflowX: auto to all our normal tables by default (incase), we need to ensure this doesn't affect the Firewall Rules Table. As, we want to allow row dragging over the top in this case, which won’t be possible if overflowX: auto is enabled. With some changes here; we may need to add noOverflow property specific to the Firewalls Rules table.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah sorry I am working too fast on this one - I'll revert that part but keep the styling fix

Copy link
Contributor

@hkhalil-akamai hkhalil-akamai left a comment

Choose a reason for hiding this comment

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

Great work @pmakode-akamai @abailly-akamai! 🎉

@pmakode-akamai pmakode-akamai force-pushed the M3-8533-fix-firewall-rules-table-and-replace-react-beautiful-dnd-with-dnd-kit branch from f8160db to 275706b Compare November 15, 2024 15:15
@pmakode-akamai
Copy link
Contributor Author

@bnussman-akamai Are we good to merge this PR? thanks!!

@abailly-akamai
Copy link
Contributor

@pmakode-akamai have you confirmed the failing tests are unrelated?

@pmakode-akamai
Copy link
Contributor Author

@pmakode-akamai have you confirmed the failing tests are unrelated?

@abailly-akamai yea, this should be unrelated

confirming all checks for these 2 specs pass locally. I think all checks should pass on re-run.

Screenshot 2024-11-15 at 11 23 00 PM

Screenshot 2024-11-15 at 11 24 59 PM

@linode-gh-bot
Copy link
Collaborator

Cloud Manager UI test results

🎉 445 passing tests on test run #32 ↗︎

❌ Failing✅ Passing↪️ Skipped🕐 Duration
0 Failing445 Passing2 Skipped81m 30s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved Multiple approvals and ready to merge!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants