Skip to content

Replace react-sortable-hoc with dnd-kit - #7860

Open
arikfr wants to merge 1 commit into
fe/09-react-testing-libraryfrom
fe/10-dnd-kit
Open

arikfr wants to merge 1 commit into
fe/09-react-testing-libraryfrom
fe/10-dnd-kit

Conversation

@arikfr

@arikfr arikfr commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

What type of PR is this?

  • Other (dependencies)

Description

Part 10 of the frontend dependency upgrade stack tracked in #7848. Stacked on #7859.

react-sortable-hoc hasn't had a release since 2022. It only allows React 16/17 and uses findDOMNode, which React 19 removes. This reimplements viz-lib's components/sortable on dnd-kit (@dnd-kit/core, sortable, modifiers, utilities; all support React 16.8–19).

The API stays the same (SortableContainer, SortableElement, DragHandle, plus a local sortableElement() HOC instead of react-sortable-hoc's). Items are identified by index, and the container reports onSortEnd({ oldIndex, newIndex }). It's used in three places: query/dashboard parameters, the chart editor's series order, and the table/details editors' column order.

What's different

  • Dragging: items move in place (CSS transform) instead of react-sortable-hoc's floating clone, and helperClass goes on the dragged item. Parameters' appendSortableToParent prop only chose where that clone was attached, so it's gone. So is the onBeforeSortStart handler, which didn't exist on the component.
  • Finding the DOM node: dnd-kit needs each item's DOM node. DragHandle finds it with closest(), which works for components that don't expose a DOM ref, like antd's Collapse.Panel (react-sortable-hoc used findDOMNode).
  • Sensors: mouse and touch sensors rather than the pointer sensor, so the Cypress parameter test, which drags by triggering mouse events, keeps working.
  • New: keyboard sorting (focus a handle, Space, arrows, Space). The handles get role="button" and screen reader instructions.
  • New prop: the container takes an itemCount prop, since dnd-kit needs the list of item ids up front.

How is this tested?

  • Unit tests (pytest, jest)

  • Manually

  • Lint, type-check, jest and the production build pass locally.

  • New unit tests for the sortable components: mouse drag (with a mocked layout, since jsdom doesn't lay anything out), the sortableElement HOC, the dragging classes, keyboard sorting and the disabled state.

  • In Chromium (Playwright, real mouse), against a local backend, I reordered:

    • query parameters: the new order is saved and survives a reload
    • chart series in the chart editor
    • table columns in the table editor (Collapse panels)

    No console errors.

  • The Cypress "rearrange parameters" test runs on the canary ([Do not merge] CI for the frontend dependency upgrade stack (#7848) #7852).

🤖 Generated with Claude Code

Review in cubic

@greptile-apps

greptile-apps Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Replaces drag-and-drop library across sortable components.

The PR appears safe to merge based on the changes reviewed.

Summary

This PR replaces react-sortable-hoc with dnd-kit while retaining index-based sort callbacks for parameters, chart series, and visualization columns.

  • Adds mouse, touch, and keyboard sorting through the shared sortable components.
  • Updates callers to supply item counts and adds sortable-component tests.
Diagram
%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[DragHandle] --> B[SortableElement]
  B --> C[SortableContainer / DndContext]
  C --> D[onSortEnd: oldIndex, newIndex]
  D --> E[Caller updates item order]
Loading

Reviews (6) · Last reviewed commit: "Replace react-sortable-hoc with dnd-kit" · Reviewed by Greptile

Comment thread viz-lib/src/components/sortable/index.tsx
Comment thread viz-lib/src/components/sortable/sortable.test.tsx

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

All reported issues were addressed across 8 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread viz-lib/src/components/sortable/index.tsx
Comment thread viz-lib/src/components/sortable/index.tsx
Comment thread viz-lib/src/components/sortable/index.tsx
Comment thread viz-lib/src/components/sortable/sortable.test.tsx
@arikfr arikfr mentioned this pull request Sep 27, 2026
3 tasks done
@arikfr
arikfr force-pushed the fe/09-react-testing-library branch 2 times, most recently from 04c02f3 to d69ade9 Compare September 28, 2026 14:57
@arikfr
arikfr force-pushed the fe/10-dnd-kit branch 2 times, most recently from e283e33 to c172e43 Compare October 3, 2026 21:06
@arikfr
arikfr force-pushed the fe/09-react-testing-library branch from d69ade9 to 2b063e4 Compare October 3, 2026 21:06
@arikfr
arikfr force-pushed the fe/09-react-testing-library branch from 2b063e4 to 9997fa9 Compare October 4, 2026 13:56
react-sortable-hoc is unmaintained, only allows React 16/17, and relies
on findDOMNode, which React 19 removes. Reimplement viz-lib's sortable
components (SortableContainer, SortableElement, sortableElement,
DragHandle) on @dnd-kit, keeping their API: items are identified by
index and the container reports `onSortEnd({ oldIndex, newIndex })`.

- Items move in place instead of being cloned into a floating "helper";
  `helperClass` is applied to the dragged item.
- The drag handle finds its item's DOM node with closest(), which works
  for components that don't expose a DOM ref (antd's Collapse.Panel).
- Mouse and touch sensors (the e2e tests drag with mouse events), plus
  keyboard sorting.
- The container takes an `itemCount`. Parameters' `appendSortableToParent`
  (where to attach the helper) and the undefined `onBeforeSortStart`
  handler are gone.

Part of #7848.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@arikfr
arikfr force-pushed the fe/09-react-testing-library branch from 9997fa9 to 4a85a9d Compare October 8, 2026 12:36

This branch has not been deployed

No deployments
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.

1 participant