[PR #6895] [MERGED] feat(hosts): add drag-and-drop and global subscription ordering #6502

Closed
opened 2026-11-02 04:09:14 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/MHSanaei/3x-ui/pull/6895
Author: @HamedSanaei
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/24/2026
Merged by: @MHSanaei

Base: main ← Head: feat/hosts-global-subscription-order-6894


📝 Commits (8)

  • a64e28c feat(hosts): support global subscription ordering and drag-and-drop
  • a6d3a42 refactor(frontend): unify pointer drag-and-drop handling
  • b4f6af9 Merge remote-tracking branch 'origin/main' into pr/6895
  • 0414026 Merge remote-tracking branch 'origin/main' into pr/6895
  • 38b0dc3 test(sub): pass the remote-DNS flag NewSubClashService now takes
  • edb5c86 Merge remote-tracking branch 'origin/main' into pr/6895
  • e92832f fix(hosts): hide the drag handle's decorative icon from screen readers
  • c195231 Merge remote-tracking branch 'origin/main' into pr/6895

📊 Changes

51 files changed (+1643 additions, -149 deletions)

View changed files

📝 .github/workflows/ci.yml (+10 -0)
📝 docs/content/docs/en/config/subscription.mdx (+37 -1)
📝 docs/content/docs/en/reference/api/hosts.mdx (+6 -2)
➕ docs/public/images/hosts-order-after.png (+0 -0)
➕ docs/public/images/hosts-order-before.png (+0 -0)
📝 docs/public/openapi.json (+11 -1)
📝 frontend/public/openapi.json (+11 -1)
📝 frontend/src/api/queries/useHostMutations.ts (+1 -1)
📝 frontend/src/generated/examples.ts (+2 -0)
📝 frontend/src/generated/schemas.ts (+10 -0)
📝 frontend/src/generated/types.ts (+2 -0)
📝 frontend/src/generated/zod.ts (+2 -0)
➕ frontend/src/hooks/usePointerRowReorder.ts (+109 -0)
📝 frontend/src/models/setting.ts (+2 -1)
📝 frontend/src/pages/api-docs/endpoints.ts (+2 -1)
📝 frontend/src/pages/hosts/HostList.css (+18 -0)
📝 frontend/src/pages/hosts/HostList.tsx (+51 -6)
📝 frontend/src/pages/hosts/HostsPage.tsx (+35 -4)
📝 frontend/src/pages/settings/SubscriptionGeneralTab.tsx (+17 -1)
📝 frontend/src/pages/xray/routing/RoutingTab.tsx (+51 -91)

...and 31 more files

📄 Description

Summary

  • Add pointer drag-and-drop to the Hosts table, retaining the existing Up/Down controls.
  • Share pointer gesture handling between Hosts and desktop/mobile Routing Rules through a typed React hook.
  • Add opt-in Hosts order subscription sorting across inbounds in Raw/Base64, Clash/Mihomo and JSON/Xray output.
  • Reuse persisted Host group order and the existing reorder endpoint. Existing installations keep Inbound order (default).

Motivation

Hosts were sorted only inside each inbound. An inbound with a lower subscription sort index or ID could therefore emit Host A before a globally higher-priority Host B, even though the Hosts page showed B first. The page also lacked a drag interaction for changing that global order.

Implementation

  • subHostSortMode is stored through the existing settings service: inbound-first (default) or hosts-first. The selector and help text are translated into all 13 locales; changing it takes effect on the next subscription request.
  • Load Host rows once per subscription request in bounded batches, carry typed group/inbound/Host ordering metadata, and stably sort render callbacks before generating output. Rendering in final order preserves first-link usage and remark behavior; identity is never inferred from generated URIs or names.
  • Host groups sort by persisted sort_order, then remark and group ID, matching the Hosts table. Inside a group, subscription sort index, inbound ID and Host row ID resolve ties; stable sorting preserves remaining emission ties.
  • Eligible entries without applicable Hosts, including legacy externalProxy fallbacks, follow Host-backed entries in their previous relative order. External client links retain their existing placement; the info node stays first. Standalone panel share/QR previews retain their existing order.
  • Keep the JSON numeric (sortIndex, kind, id) integration with balancers: retain its balancer slots and globally reorder only endpoint slots. Balancer tags and references remain valid. Clash naming/group processing still runs after ordered proxy generation.
  • Dragging uses a dedicated pointer grip, movement threshold, above/below target indicator, touch support, cancellation and listener cleanup. A drop sends one mutation; the page shows an optimistic order, blocks overlapping saves, refreshes the query and restores the prior order on failure.
  • Validate empty/duplicate/unknown reorder IDs atomically. Partial lists remain supported, with omitted groups following in their previous order. PostgreSQL row locks serialize competing reorders.
  • Regenerate frontend schemas, examples, OpenAPI and API reference docs. Document ordering and balancer behavior. Add PostgreSQL ordering coverage to the existing CI database job, including a guard against silently skipped coverage.

Validation

Shared pointer hook refactor

Both HostList and RoutingTab now consume usePointerRowReorder<TKey extends string | number>. Its inputs are containerRef, getRowKey, onDrop and optional disabled/isNoop; it returns drag state and onPointerDown. The hook owns the 5px activation threshold, active pointer validation, capture/release, bounded target detection, above/below position, cancellation, latest callback references and listener cleanup.

Hosts retain their string group IDs, before/after insertion algorithm, optimistic save/rollback, save guard and Up/Down controls. Routing retains numeric visible positions, originalRuleIndex mapping, splice algorithm and settings mutation. Its desktop DOM row keys are original rule indices while mobile cards expose visible positions; getRowKey handles that distinction before mapping a drop back to the full rule list.

The pre-refactor cancellation tests failed on both desktop and mobile because the old Routing handler committed on pointercancel. With the common hook, cancellation never commits, releasing outside the container cannot reuse a stale target, and unmount/lost capture clean up the gesture. No backend, subscription renderer, configuration format, dependencies or translations changed in this follow-up.

Focused hook/Hosts/Routing regression suite: 31 tests passed in four files. This includes the threshold, invalid/foreign pointers, cancellation, capture exceptions/release, no-op drops, outside targets, fresh callback references, listener cleanup, before/after insertion, one save, rollback, Up/Down, hidden-loopback mapping, and desktop/mobile/touch/RTL interactions.

Feature validation

  • Full shuffled Go suite: go test -p 2 -shuffle=on -count=1 ./... — passed, including subscription, service and route-contract tests on SQLite.
  • go test ./internal/sub -run '^TestSubHostOrder_Postgres$' -count=1 -v against disposable PostgreSQL 16 — all four scenarios passed (global order/reorder, filtering/fallbacks, Base64/info node, JSON balancers).
  • go test -race -shuffle=on -count=1 -timeout 15m ./internal/sub ./internal/web/service -run 'Test(Sub|ReorderHosts)' — passed.
  • golangci-lint run ./..., Go vet, go build ./..., workflow actionlint and git diff --check — passed.
  • Frontend on Node 26: clean npm ci, TypeScript, oxlint, format check, Vite production build and Storybook build — passed. Fresh npm run gen produces byte-identical generated artifacts.
  • Full frontend npm test after the shared-hook refactor — passed: 1,877 tests in 192 files, including Chromium Storybook tests. The focused hook/Hosts/Routing regression suite also passed separately (31 tests).
  • Docs typecheck and tests — passed (107 tests in 12 files).
  • Real Chromium drag of Host B (Inbound #20) above Host A (Inbound #5), using the production frontend and synthetic HTTP responses: exactly one reorder request with ["b","a","c"]; refresh retained the saved order.
  • Query-count regression: one Host query per actual Raw/Clash/JSON request in the representative fixture. No benchmark numbers are claimed.

The cross-inbound behavioral test was observed failing with inbound-first behavior forced while Hosts-first was selected, then passing with the implementation restored. The drag tests first failed on the missing drag controls, then passed with the implementation. The existing TestSub_HostSortComposesWithSubSortIndex remains unchanged.

Optional integration tests without their required environment remain skipped in the full Go suite; the dedicated PostgreSQL scenarios above were explicitly enabled. Full repository race, real master/node process E2E, fuzz smoke and vulnerability gates are left to upstream CI; the focused race command above was executed locally.

For refactor head a6d3a4263fd9c01b35a60cf1b1cb2443005ea2fc, CI and Docs CI are awaiting maintainer approval for this fork PR (action_required, no jobs started). Local passes above do not imply that upstream Actions have passed. The existing automated review covers the earlier a64e28c6 head and reported no blocking findings; the repository workflow does not automatically re-review pushes.

Screenshots

Actual Chromium captures of the built frontend, using synthetic example Host data and mocked API responses:

Before dragging:

Hosts before reordering

After dragging Host B above Host A:

Hosts after reordering

Compatibility

Inbound-first remains the default and can be restored through the same selector. No database migration, new table, new endpoint or dependency is added. Existing eligibility, exclusions, credentials and protocol renderers are reused. Client applications may still apply their own sorting after import.

Fixes #6894


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/MHSanaei/3x-ui/pull/6895 **Author:** [@HamedSanaei](https://github.com/HamedSanaei) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/24/2026 **Merged by:** [@MHSanaei](https://github.com/MHSanaei) **Base:** `main` ← **Head:** `feat/hosts-global-subscription-order-6894` --- ### 📝 Commits (8) - [`a64e28c`](https://github.com/MHSanaei/3x-ui/commit/a64e28c6cc0e3084fa0c3ac6553dc408a6f882fd) feat(hosts): support global subscription ordering and drag-and-drop - [`a6d3a42`](https://github.com/MHSanaei/3x-ui/commit/a6d3a4263fd9c01b35a60cf1b1cb2443005ea2fc) refactor(frontend): unify pointer drag-and-drop handling - [`b4f6af9`](https://github.com/MHSanaei/3x-ui/commit/b4f6af9e64a6f6018f313fd224050e148316f97e) Merge remote-tracking branch 'origin/main' into pr/6895 - [`0414026`](https://github.com/MHSanaei/3x-ui/commit/041402672ad1afd72af72ed48a7e08587a527a1c) Merge remote-tracking branch 'origin/main' into pr/6895 - [`38b0dc3`](https://github.com/MHSanaei/3x-ui/commit/38b0dc353a84e89495ca9330e4f1e18b2897db1d) test(sub): pass the remote-DNS flag NewSubClashService now takes - [`edb5c86`](https://github.com/MHSanaei/3x-ui/commit/edb5c86a9cab52c70a2c629689ce0acca66dbd52) Merge remote-tracking branch 'origin/main' into pr/6895 - [`e92832f`](https://github.com/MHSanaei/3x-ui/commit/e92832fd6e97f80400ce8395fcf05e658b2c3ccf) fix(hosts): hide the drag handle's decorative icon from screen readers - [`c195231`](https://github.com/MHSanaei/3x-ui/commit/c195231829d0fad289820eb57054e0bf1f4a3dbd) Merge remote-tracking branch 'origin/main' into pr/6895 ### 📊 Changes **51 files changed** (+1643 additions, -149 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+10 -0) 📝 `docs/content/docs/en/config/subscription.mdx` (+37 -1) 📝 `docs/content/docs/en/reference/api/hosts.mdx` (+6 -2) ➕ `docs/public/images/hosts-order-after.png` (+0 -0) ➕ `docs/public/images/hosts-order-before.png` (+0 -0) 📝 `docs/public/openapi.json` (+11 -1) 📝 `frontend/public/openapi.json` (+11 -1) 📝 `frontend/src/api/queries/useHostMutations.ts` (+1 -1) 📝 `frontend/src/generated/examples.ts` (+2 -0) 📝 `frontend/src/generated/schemas.ts` (+10 -0) 📝 `frontend/src/generated/types.ts` (+2 -0) 📝 `frontend/src/generated/zod.ts` (+2 -0) ➕ `frontend/src/hooks/usePointerRowReorder.ts` (+109 -0) 📝 `frontend/src/models/setting.ts` (+2 -1) 📝 `frontend/src/pages/api-docs/endpoints.ts` (+2 -1) 📝 `frontend/src/pages/hosts/HostList.css` (+18 -0) 📝 `frontend/src/pages/hosts/HostList.tsx` (+51 -6) 📝 `frontend/src/pages/hosts/HostsPage.tsx` (+35 -4) 📝 `frontend/src/pages/settings/SubscriptionGeneralTab.tsx` (+17 -1) 📝 `frontend/src/pages/xray/routing/RoutingTab.tsx` (+51 -91) _...and 31 more files_ </details> ### 📄 Description ## Summary - Add pointer drag-and-drop to the Hosts table, retaining the existing Up/Down controls. - Share pointer gesture handling between Hosts and desktop/mobile Routing Rules through a typed React hook. - Add opt-in **Hosts order** subscription sorting across inbounds in Raw/Base64, Clash/Mihomo and JSON/Xray output. - Reuse persisted Host group order and the existing reorder endpoint. Existing installations keep **Inbound order (default)**. ## Motivation Hosts were sorted only inside each inbound. An inbound with a lower subscription sort index or ID could therefore emit Host A before a globally higher-priority Host B, even though the Hosts page showed B first. The page also lacked a drag interaction for changing that global order. ## Implementation - `subHostSortMode` is stored through the existing settings service: `inbound-first` (default) or `hosts-first`. The selector and help text are translated into all 13 locales; changing it takes effect on the next subscription request. - Load Host rows once per subscription request in bounded batches, carry typed group/inbound/Host ordering metadata, and stably sort render callbacks before generating output. Rendering in final order preserves first-link usage and remark behavior; identity is never inferred from generated URIs or names. - Host groups sort by persisted `sort_order`, then remark and group ID, matching the Hosts table. Inside a group, subscription sort index, inbound ID and Host row ID resolve ties; stable sorting preserves remaining emission ties. - Eligible entries without applicable Hosts, including legacy `externalProxy` fallbacks, follow Host-backed entries in their previous relative order. External client links retain their existing placement; the info node stays first. Standalone panel share/QR previews retain their existing order. - Keep the JSON numeric `(sortIndex, kind, id)` integration with balancers: retain its balancer slots and globally reorder only endpoint slots. Balancer tags and references remain valid. Clash naming/group processing still runs after ordered proxy generation. - Dragging uses a dedicated pointer grip, movement threshold, above/below target indicator, touch support, cancellation and listener cleanup. A drop sends one mutation; the page shows an optimistic order, blocks overlapping saves, refreshes the query and restores the prior order on failure. - Validate empty/duplicate/unknown reorder IDs atomically. Partial lists remain supported, with omitted groups following in their previous order. PostgreSQL row locks serialize competing reorders. - Regenerate frontend schemas, examples, OpenAPI and API reference docs. Document ordering and balancer behavior. Add PostgreSQL ordering coverage to the existing CI database job, including a guard against silently skipped coverage. ## Validation ### Shared pointer hook refactor Both `HostList` and `RoutingTab` now consume `usePointerRowReorder<TKey extends string | number>`. Its inputs are `containerRef`, `getRowKey`, `onDrop` and optional `disabled`/`isNoop`; it returns `drag` state and `onPointerDown`. The hook owns the 5px activation threshold, active pointer validation, capture/release, bounded target detection, above/below position, cancellation, latest callback references and listener cleanup. Hosts retain their string group IDs, before/after insertion algorithm, optimistic save/rollback, save guard and Up/Down controls. Routing retains numeric visible positions, `originalRuleIndex` mapping, splice algorithm and settings mutation. Its desktop DOM row keys are original rule indices while mobile cards expose visible positions; `getRowKey` handles that distinction before mapping a drop back to the full rule list. The pre-refactor cancellation tests failed on both desktop and mobile because the old Routing handler committed on `pointercancel`. With the common hook, cancellation never commits, releasing outside the container cannot reuse a stale target, and unmount/lost capture clean up the gesture. No backend, subscription renderer, configuration format, dependencies or translations changed in this follow-up. Focused hook/Hosts/Routing regression suite: 31 tests passed in four files. This includes the threshold, invalid/foreign pointers, cancellation, capture exceptions/release, no-op drops, outside targets, fresh callback references, listener cleanup, before/after insertion, one save, rollback, Up/Down, hidden-loopback mapping, and desktop/mobile/touch/RTL interactions. ### Feature validation - Full shuffled Go suite: `go test -p 2 -shuffle=on -count=1 ./...` — passed, including subscription, service and route-contract tests on SQLite. - `go test ./internal/sub -run '^TestSubHostOrder_Postgres$' -count=1 -v` against disposable PostgreSQL 16 — all four scenarios passed (global order/reorder, filtering/fallbacks, Base64/info node, JSON balancers). - `go test -race -shuffle=on -count=1 -timeout 15m ./internal/sub ./internal/web/service -run 'Test(Sub|ReorderHosts)'` — passed. - `golangci-lint run ./...`, Go vet, `go build ./...`, workflow actionlint and `git diff --check` — passed. - Frontend on Node 26: clean `npm ci`, TypeScript, oxlint, format check, Vite production build and Storybook build — passed. Fresh `npm run gen` produces byte-identical generated artifacts. - Full frontend `npm test` after the shared-hook refactor — passed: 1,877 tests in 192 files, including Chromium Storybook tests. The focused hook/Hosts/Routing regression suite also passed separately (31 tests). - Docs typecheck and tests — passed (107 tests in 12 files). - Real Chromium drag of Host B (Inbound #20) above Host A (Inbound #5), using the production frontend and synthetic HTTP responses: exactly one reorder request with `["b","a","c"]`; refresh retained the saved order. - Query-count regression: one Host query per actual Raw/Clash/JSON request in the representative fixture. No benchmark numbers are claimed. The cross-inbound behavioral test was observed failing with inbound-first behavior forced while Hosts-first was selected, then passing with the implementation restored. The drag tests first failed on the missing drag controls, then passed with the implementation. The existing `TestSub_HostSortComposesWithSubSortIndex` remains unchanged. Optional integration tests without their required environment remain skipped in the full Go suite; the dedicated PostgreSQL scenarios above were explicitly enabled. Full repository race, real master/node process E2E, fuzz smoke and vulnerability gates are left to upstream CI; the focused race command above was executed locally. For refactor head `a6d3a4263fd9c01b35a60cf1b1cb2443005ea2fc`, [CI](https://github.com/MHSanaei/3x-ui/actions/runs/39736157841) and [Docs CI](https://github.com/MHSanaei/3x-ui/actions/runs/39736157840) are awaiting maintainer approval for this fork PR (`action_required`, no jobs started). Local passes above do not imply that upstream Actions have passed. The existing automated review covers the earlier `a64e28c6` head and reported no blocking findings; the repository workflow does not automatically re-review pushes. ## Screenshots Actual Chromium captures of the built frontend, using synthetic example Host data and mocked API responses: Before dragging: ![Hosts before reordering](https://raw.githubusercontent.com/HamedSanaei/3x-ui/feat/hosts-global-subscription-order-6894/docs/public/images/hosts-order-before.png) After dragging Host B above Host A: ![Hosts after reordering](https://raw.githubusercontent.com/HamedSanaei/3x-ui/feat/hosts-global-subscription-order-6894/docs/public/images/hosts-order-after.png) ## Compatibility Inbound-first remains the default and can be restored through the same selector. No database migration, new table, new endpoint or dependency is added. Existing eligibility, exclusions, credentials and protocol renderers are reused. Client applications may still apply their own sorting after import. Fixes #6894 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 04:09:14 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
MHSanaei/3x-ui#6502
No description provided.