feat(sidebar): drag-and-drop connection reordering (#748) - #817
Conversation
Connections render in a persisted custom order rather than storage's natural array order. A new connection_order collection (flat id list) is stored via the existing write-through storage facade, and ConnectionsList gains native HTML5 drag-and-drop to reorder its rows, persisting the new order on drop.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
cevheri
left a comment
There was a problem hiding this comment.
Good work, @Asgabani. I ran it in the app in Chromium and in Firefox: the handle on hover, dragging up and down, the order surviving a reload, a connection created afterwards appending last, and a drag never selecting the row. onDragStart does not call dataTransfer.setData, which used to stop Firefox starting a drag at all, and Firefox 155 is fine without it. Two things before I merge.
-
storage.deleteConnectiondoes not pruneconnection_order. I deleted a connection through the UI and its id was still in the stored order afterwards, and it keeps being pushed to server storage.deleteConnectionis already where a sibling id list is maintained on delete:dismissed_seedsis recorded there. Same place, with a test. -
docs/STORAGE.mdis the collection inventory and it still describes ten: the collection column enumeration, the "10 collections" line and the table under it, the localStorage key map, the facade API row for Connections (it already listsgetDismissedSeeds()), and the second "10 collections" in the migration walkthrough. Two code comments count them too:encrypting-provider.tssays "the remaining six hold metadata", which is the written justification for encrypting onlyconnections, andconnection-secrets.tssays "all ten collections". #812 adds a collection as well, so whichever of the two lands second has to re-derive that number rather than write 11.
One note, no change needed: the mobile list gets the props, but HTML5 drag is pointer-only, so nothing there can fire on a phone. The handle needs hover, so nothing looks broken either.
- deleteConnection now prunes the deleted id out of connection_order too, mirroring the existing dismissed_seeds handling. - docs/STORAGE.md's collection inventory (schema table, collection reference table, localStorage key map, facade API row, and both "10 collections" call-outs) now accounts for connection_order, along with the two code comments in encrypting-provider.ts and connection-secrets.ts that counted collections. - Updated tests/components/studio/source-tab.test.tsx's storage mock, which predates this branch's reorder work and was missing the two methods useConnectionOrder calls.
|
Addressed both:
Rebased onto latest `main` — that pulled in a new `tests/components/studio/source-tab.test.tsx` whose storage mock predates this branch and was missing the two methods `useConnectionOrder` calls, so I added those too (unrelated to your feedback, just needed to keep tests green post-merge). Ran the full local suite again: format/lint/typecheck/knip clean, all four drift guards pass, `test:components` 46/46 groups, core suite at the same pre-existing 13 environment-gap failures (Helm/standalone-zip) as a clean checkout, 100.00% coverage, build green. |
…ns sections With libredb#812 merged the list renders a Favorites section above Connections, and both are now cut from the one saved order, so each keeps the user's order within itself. A drop onto a row in the other section is ignored and that row is not highlighted: the dragged row would stay in its own section, so accepting it would only change the saved order in a way nothing on screen shows. A row alone in its section gets no drag handle.
cevheri
left a comment
There was a problem hiding this comment.
merging shortly, fixed conflicts
|
Thanks @Asgabani. #812 landed first, so I merged The merge keeps both sides. The collection inventory is now 12 in The follow-up commit is where the two features meet. Favorites and Connections are both cut from the one saved order, so each section keeps your order within itself. A drop onto a row in the other section is ignored and that row is not highlighted, because the dragged row would stay in its own section and the only effect would be an invisible change to the saved order. A row alone in its section gets no handle. Tests are in |
542 files and 17,477 tests, 100% of 56,883 lines. #817's test files were also run 24 times at once each, under the per-file runner they have not met before: 24/24.
Closes #748.
What changed
StorageData.connection_order(new collection): a flat list of connection ids in the user's preferred order, mirroring the existingdismissed_seeds-style separate-list pattern rather than a field onDatabaseConnection— amanaged:trueconnection is replaced wholesale on every load (seemergeManagedConnections), so a field on the connection object itself would be silently discarded on reload.storage.getConnectionOrder()/storage.setConnectionOrder()on the storage facade, wired intouseStorageSync's migrate/pull paths like every other collection.applyConnectionOrder()(src/lib/connection-order.ts): sorts a connections array by the persisted order; a connection absent from the order (never dragged, or created after the user last reordered) sorts after every connection the order does know about, in its original relative position (Array.prototype.sortis spec-stable, so that fallback needs no code of its own).useConnectionOrder()hook:useSyncExternalStoreover the facade, same shape as the repo's other storage-backed hooks.ConnectionsList/ConnectionItem: native HTML5 drag-and-drop (no new dependency) — a drag handle appears on hover onceonReorderConnectionsis passed and the list has more than one connection; dropping persists the new order via the facade.Note on #694
#748's "Done when" mentions #694 (favorites): if that lands first, a favorited group should keep its own drag order rather than the two features competing for one order field. Since #694 hasn't merged yet, this PR reorders the flat
connectionslist only.connectionOrder/onReorderConnectionsare threaded through as plain optional props (not baked into any favorites-aware grouping), so whichever PR lands second can partition the already-ordered list into favorite/non-favorite groups without this one needing to change.Testing
Ran locally (
bun run format && bun run lint && bun run typecheck && bun run knip && bun run chart:check && bun run channels:showcase:check && bun run readme:check && bun run security:check && bun run test && bun run build, plusbun run build:lib && bun run attw):git stash).bun run test:components: 39/39 groups pass.bun run test: same 13 pre-existing failures as a clean checkout (Helm binary not installed, missing built standalone zip) — verified identical viagit stashbefore/after. No live Postgres/MySQL in this sandbox, so DB-integration tests weren't exercised beyond what's already mocked.bun run test:coverage && bun run coverage:check: 100.00% line coverage on the merged lcov.bun run build,bun run build:lib,bun run attw: all succeed (ConnectionsList/Sidebarare reachable from the embeddable workspace export surface).If CI surfaces something this sandbox couldn't (Helm chart tests, live DB integration tests), happy to fix it up.