mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 19:11:53 +07:00
[PR #6895] [MERGED] feat(hosts): add drag-and-drop and global subscription ordering #6502
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6502
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 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)
a64e28cfeat(hosts): support global subscription ordering and drag-and-dropa6d3a42refactor(frontend): unify pointer drag-and-drop handlingb4f6af9Merge remote-tracking branch 'origin/main' into pr/68950414026Merge remote-tracking branch 'origin/main' into pr/689538b0dc3test(sub): pass the remote-DNS flag NewSubClashService now takesedb5c86Merge remote-tracking branch 'origin/main' into pr/6895e92832ffix(hosts): hide the drag handle's decorative icon from screen readersc195231Merge 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
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
subHostSortModeis stored through the existing settings service:inbound-first(default) orhosts-first. The selector and help text are translated into all 13 locales; changing it takes effect on the next subscription request.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.externalProxyfallbacks, 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.(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.Validation
Shared pointer hook refactor
Both
HostListandRoutingTabnow consumeusePointerRowReorder<TKey extends string | number>. Its inputs arecontainerRef,getRowKey,onDropand optionaldisabled/isNoop; it returnsdragstate andonPointerDown. 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,
originalRuleIndexmapping, splice algorithm and settings mutation. Its desktop DOM row keys are original rule indices while mobile cards expose visible positions;getRowKeyhandles 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
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 -vagainst 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 andgit diff --check— passed.npm ci, TypeScript, oxlint, format check, Vite production build and Storybook build — passed. Freshnpm run genproduces byte-identical generated artifacts.npm testafter 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).["b","a","c"]; refresh retained the saved order.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_HostSortComposesWithSubSortIndexremains 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 earliera64e28c6head 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:
After dragging Host B above Host A:
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.