Drag-to-reorder organizations in the org list and switcher #627
Closed
bdunncompany
started this conversation in
Ideas
Replies: 1 comment
|
Shipped in #681 — thanks for the well-scoped POC and the partner-settings-jsonb decision write-up, that made review easy. Closing as resolved. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Drag-to-reorder organizations in the org list and switcher
Why
On
/settings/organizationsand the top-bar org switcher, organizations come back in an implicit order (creation timestamp). For an MSP, that order doesn't match how often you actually touch each customer. The customers you work with most often are the ones you most want at the top of the dropdown, but they're often the ones who were onboarded recently — so they end up at the bottom.Drag-to-reorder, persisted partner-wide, fixes that with no other configuration burden.
What I built
A working POC running on a real MSP install. Behavior:
createdAt, can't change/settings/organizations, order persists, top-bar switcher (Cmd+O) reflects it on next reloadImplementation summary:
partners.settings.organizationOrder?: string[]. No schema change — just a new key in the existingpartners.settingsjsonb. Mirrors the existing inheritable-settings pattern.PATCH /orgs/organizations/reorder(partner scope, audited aspartner.organizationOrder.update), body{ orderedIds: string[] }. Idempotent; the request fully replaces the order. Server-side sanitization drops any IDs that aren't in the caller'saccessibleOrgIdsso cross-partner mischief isn't possible.GET /orgs/organizationsappliesapplyOrganizationOrder()after the existingcreatedAtSQL sort, only forpartnerscope (andsystemscope when apartnerIdfilter is set). Unknown / newly-created orgs append at the end. If the partner-settings lookup throws for any reason, the response soft-falls-back to thecreatedAtorder.OrganizationsPage.tsxwith optimistic update, revert-on-PATCH-failure via re-fetch. 6-dot grip handle visible on row hover. Drag is disabled while a search filter is active so users can't reorder a hidden subset.OrgSwitcherboth consumeGET /orgs/organizations, so server-side ordering is enough.Why schema-free instead of an
organizations.sort_order INTEGERcolumnI considered both. The settings-jsonb approach won for this POC because:
partners.settingsshape, so reviewers don't have to learn a new pattern.users.settings.organizationOrderlater (per-user override) is a one-line change.A
sort_order INTEGERcolumn has real merits — index-friendly, lets the DB do the sort, conceptually cleaner. Happy to switch to that approach before any PR if you'd prefer it.Tests
applyOrganizationOrder/sanitizeOrganizationOrder(empty/null/duplicate/stale/single-org/no-mutation).PATCH /orgs/organizations/reorder(happy path, drops unknown IDs, preserves unrelated settings keys, scope rejection, zod validation).Known gaps / open questions
Worth flagging up front:
react-dnd-touch-backendswap) would be a nice follow-up.requireScope('partner')only. System-scoped admins reordering on a partner's behalf would need an additional code path; happy to add if it's wanted.users.settings.organizationOrder) is the obvious follow-up if multiple staff want different orderings.Patches
Two patches against latest main:
Drag-to-reorder organizations on the settings page— types + API + helper + UItest(api): cover PATCH /orgs/organizations/reorder endpoint— route testsHappy to open a PR if there's interest, or to first switch to the column-based persistence path if you'd rather have that.
All reactions