[GH-ISSUE #4835] [Feature]: Allow to reorder attached inbounds in client edit window #3364

Closed
opened 2026-10-31 20:31:56 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @maxbranson64-eng on GitHub (Jun 2, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4835

Currently you cannot change how Attached inbounds are sorted for each client. So if you create new inbound it will be added to subscription page as last one. For example if you create local inbound then connect node (that has inbounds) and then create new local inbound. On subsciprion page and in client app inbounds from node will be between local inbounds but I expect local inbounds to be grouped on top of the list.

Describe the solution you'd like

Make it possible to drag and drop inbounds in Attached inbounds section of Client edit window. Order inbounds on subscription page according to the position of inbounds in Attached inbounds section.

Alternatives you've considered

No response

Concrete use case

No response

Mockups, screenshots, or examples

No response

Which parts of the panel would this affect?

No response

Are you willing to help?

  • I'd like to implement this feature myself and open a PR.
  • I can help test once a PR is open.

Before submitting

  • I searched existing issues and this feature has not been requested.
  • This feature request is written in English.
Originally created by @maxbranson64-eng on GitHub (Jun 2, 2026). Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/4835 ### Is your feature request related to a problem? Currently you cannot change how Attached inbounds are sorted for each client. So if you create new inbound it will be added to subscription page as last one. For example if you create local inbound then connect node (that has inbounds) and then create new local inbound. On subsciprion page and in client app inbounds from node will be between local inbounds but I expect local inbounds to be grouped on top of the list. ### Describe the solution you'd like Make it possible to drag and drop inbounds in Attached inbounds section of Client edit window. Order inbounds on subscription page according to the position of inbounds in Attached inbounds section. ### Alternatives you've considered _No response_ ### Concrete use case _No response_ ### Mockups, screenshots, or examples _No response_ ### Which parts of the panel would this affect? _No response_ ### Are you willing to help? - [ ] I'd like to implement this feature myself and open a PR. - [ ] I can help test once a PR is open. ### Before submitting - [x] I searched [existing issues](../issues?q=is%3Aissue) and this feature has not been requested. - [x] This feature request is written in English.
bsakaguchi 2026-10-31 20:31:56 +07:00
Author
Owner

@github-actions[bot] commented on GitHub (Jun 2, 2026):

Thanks for the detailed request. This is a genuine gap — per-client ordering of attached inbounds is not currently implemented, and the subscription output order is effectively undefined (the query in sub/subService.go:getInboundsBySubId() has no ORDER BY clause on attached inbounds).

Current state (confirmed in source)

Layer File Status
DB model database/model/model.go — ClientInbound struct No sort_order field; only client_id, inbound_id, flow_override, created_at
Subscription query sub/subService.go:235–251 SELECT DISTINCT inbounds.id … JOIN client_inbounds — no ORDER BY
Frontend edit modal frontend/src/pages/clients/ClientFormModal.tsx:574–588 Ant Design <Select mode="multiple"> — no drag/reorder

A precedent already exists in the codebase. InboundFallback (same file, model.go:528) already has a sort_order integer column, and the fallbacks section of the inbound form uses up/down arrow buttons (frontend/src/pages/inbounds/form/FallbacksCard.tsx + useInboundFallbacks.ts) to reorder entries and persist the index as sortOrder.

What a PR would need to touch

  1. Database migration — add a sort_order INT DEFAULT 0 column to the client_inbounds table.
  2. Backend queries — update GetInboundIdsForRecord() / GetInboundIdsForEmail() in the client service to ORDER BY sort_order, and update Attach()/Create() to accept and store sort_order values.
  3. Subscription service — update getInboundsBySubId() (sub/subService.go:235) to JOIN and ORDER BY client_inbounds.sort_order so the output respects the custom order.
  4. Frontend — replace the multi-select in ClientFormModal.tsx with a reorderable list (drag-and-drop or up/down arrows matching the fallbacks pattern), and send sort_order values on save.

If you'd like to implement this, the fallbacks code (FallbacksCard.tsx, useInboundFallbacks.ts, InboundFallback model) is the closest existing example to follow.

<!-- gh-comment-id:4607407553 --> @github-actions[bot] commented on GitHub (Jun 2, 2026): Thanks for the detailed request. This is a genuine gap — per-client ordering of attached inbounds is not currently implemented, and the subscription output order is effectively undefined (the query in `sub/subService.go:getInboundsBySubId()` has no ORDER BY clause on attached inbounds). **Current state (confirmed in source)** | Layer | File | Status | |---|---|---| | DB model | `database/model/model.go` — `ClientInbound` struct | No `sort_order` field; only `client_id`, `inbound_id`, `flow_override`, `created_at` | | Subscription query | `sub/subService.go:235–251` | `SELECT DISTINCT inbounds.id … JOIN client_inbounds` — no ORDER BY | | Frontend edit modal | `frontend/src/pages/clients/ClientFormModal.tsx:574–588` | Ant Design `<Select mode="multiple">` — no drag/reorder | **A precedent already exists in the codebase.** `InboundFallback` (same file, `model.go:528`) already has a `sort_order` integer column, and the fallbacks section of the inbound form uses up/down arrow buttons (`frontend/src/pages/inbounds/form/FallbacksCard.tsx` + `useInboundFallbacks.ts`) to reorder entries and persist the index as `sortOrder`. **What a PR would need to touch** 1. **Database migration** — add a `sort_order INT DEFAULT 0` column to the `client_inbounds` table. 2. **Backend queries** — update `GetInboundIdsForRecord()` / `GetInboundIdsForEmail()` in the client service to ORDER BY `sort_order`, and update `Attach()`/`Create()` to accept and store `sort_order` values. 3. **Subscription service** — update `getInboundsBySubId()` (`sub/subService.go:235`) to JOIN and ORDER BY `client_inbounds.sort_order` so the output respects the custom order. 4. **Frontend** — replace the multi-select in `ClientFormModal.tsx` with a reorderable list (drag-and-drop or up/down arrows matching the fallbacks pattern), and send `sort_order` values on save. If you'd like to implement this, the fallbacks code (`FallbacksCard.tsx`, `useInboundFallbacks.ts`, `InboundFallback` model) is the closest existing example to follow.
Author
Owner

@psyhotm commented on GitHub (Jun 4, 2026):

I can confirm this issue with PostgreSQL backend.

In my setup the inbounds are displayed in the panel in the expected order:

  1. Russia
  2. Russia (HY2)
  3. Netherlands
  4. Netherlands (HY2)
  5. France
  6. France (HY2)

But the generated subscription returns them in a different order, for example:

  1. Netherlands
  2. France
  3. Russia (HY2)
  4. Russia
  5. Netherlands (HY2)
  6. France (HY2)

I checked the PostgreSQL data directly. The inbounds table ordered by id is correct, and client_inbounds also has the expected assignment order. However, a query using WHERE id IN (...) without an explicit ORDER BY returns rows in a different order.

So this is not only a feature request for manual drag-and-drop sorting. There is also a backend correctness issue: subscription output should be deterministic.

A minimal fix would be to add an explicit order in sub/subService.go:getInboundsBySubId(), for example:

ORDER BY inbounds.id ASC

A better long-term fix would be to add `client_inbounds.sort_order` and order by that, as already suggested above.
This is especially visible with PostgreSQL because row order is not guaranteed unless `ORDER BY` is specified.
<!-- gh-comment-id:4626701395 --> @psyhotm commented on GitHub (Jun 4, 2026): I can confirm this issue with PostgreSQL backend. In my setup the inbounds are displayed in the panel in the expected order: 1. Russia 2. Russia (HY2) 3. Netherlands 4. Netherlands (HY2) 5. France 6. France (HY2) But the generated subscription returns them in a different order, for example: 1. Netherlands 2. France 3. Russia (HY2) 4. Russia 5. Netherlands (HY2) 6. France (HY2) I checked the PostgreSQL data directly. The `inbounds` table ordered by `id` is correct, and `client_inbounds` also has the expected assignment order. However, a query using `WHERE id IN (...)` without an explicit `ORDER BY` returns rows in a different order. So this is not only a feature request for manual drag-and-drop sorting. There is also a backend correctness issue: subscription output should be deterministic. A minimal fix would be to add an explicit order in `sub/subService.go:getInboundsBySubId()`, for example: ```sql ORDER BY inbounds.id ASC A better long-term fix would be to add `client_inbounds.sort_order` and order by that, as already suggested above. This is especially visible with PostgreSQL because row order is not guaranteed unless `ORDER BY` is specified.
Author
Owner

@psyhotm commented on GitHub (Jun 10, 2026):

Fixes #4835.

3x-ui-issue-4835-inbound-order.patch

I prepared a patch for this issue.

What it does:

  • Adds a persistent sort_order field to the client_inbounds relation table.
  • Preserves the selected inbound order when creating, editing, or attaching inbounds to a client.
  • Uses client_inbounds.sort_order when generating subscription links, so VPN clients receive nodes in the same order as configured for that client.
  • Adds a drag-and-drop reorder list in the client edit modal under “Attached inbounds”.
  • Keeps backward compatibility by falling back to inbound_id when no explicit order exists.
  • Updates generated OpenAPI / TypeScript schemas.
  • Adds a backend test to verify that subscription inbounds are returned according to the saved attachment order.

This fixes the issue where subscription node order may change unpredictably, especially with PostgreSQL, because the old query used WHERE id IN (...) without an explicit ORDER BY.

Patch file is available and can be turned into a PR if this approach looks acceptable.

Механика такая:
под полем выбора появится отдельный список выбранных inbound’ов с drag-handle слева.
Перетаскиваешь строки в нужный порядок, жмешь Сохранить, и именно этот порядок уйдет в подписку клиента.

[ 🇷🇺 Россия ] [ 🇳🇱 Нидерланды ] [ 🇫🇷 Франция ]
⠿ 🇷🇺 Россия
⠿ 🇳🇱 Нидерланды
⠿ 🇫🇷 Франция

Можно будет поменять, например, на:
⠿ 🇷🇺 Россия
⠿ 🇫🇷 Франция
⠿ 🇳🇱 Нидерланды

Image
<!-- gh-comment-id:4671472529 --> @psyhotm commented on GitHub (Jun 10, 2026): Fixes #4835. [3x-ui-issue-4835-inbound-order.patch](https://github.com/user-attachments/files/28799844/3x-ui-issue-4835-inbound-order.patch) I prepared a patch for this issue. What it does: - Adds a persistent `sort_order` field to the `client_inbounds` relation table. - Preserves the selected inbound order when creating, editing, or attaching inbounds to a client. - Uses `client_inbounds.sort_order` when generating subscription links, so VPN clients receive nodes in the same order as configured for that client. - Adds a drag-and-drop reorder list in the client edit modal under “Attached inbounds”. - Keeps backward compatibility by falling back to `inbound_id` when no explicit order exists. - Updates generated OpenAPI / TypeScript schemas. - Adds a backend test to verify that subscription inbounds are returned according to the saved attachment order. This fixes the issue where subscription node order may change unpredictably, especially with PostgreSQL, because the old query used `WHERE id IN (...)` without an explicit `ORDER BY`. Patch file is available and can be turned into a PR if this approach looks acceptable. **Механика такая:** под полем выбора появится отдельный список выбранных inbound’ов с drag-handle слева. Перетаскиваешь строки в нужный порядок, жмешь Сохранить, и именно этот порядок уйдет в подписку клиента. [ 🇷🇺 Россия ] [ 🇳🇱 Нидерланды ] [ 🇫🇷 Франция ] ⠿ 🇷🇺 Россия ⠿ 🇳🇱 Нидерланды ⠿ 🇫🇷 Франция **Можно будет поменять, например, на:** ⠿ 🇷🇺 Россия ⠿ 🇫🇷 Франция ⠿ 🇳🇱 Нидерланды <img width="1614" height="975" alt="Image" src="https://github.com/user-attachments/assets/878be7ee-ee21-49f3-a21d-4fbaec645b85" />
Author
Owner

@MHSanaei commented on GitHub (Jul 3, 2026):

This is now supported: each inbound has a Subscription sort index field (in the inbound create/edit form, also shown as a column in the inbound list), and subscription output — raw, HTML page, JSON, and Clash — is ordered by that index with ID as tiebreaker. That also fixes the non-deterministic ordering you observed on PostgreSQL, since the query now has an explicit ORDER BY.

For your example, give your local inbounds lower sort indexes than the node inbounds and they'll be grouped on top for every client.

Per-client ordering (a different order for each client) is intentionally not part of this mechanism — if you specifically need that, please open a focused follow-up issue; @psyhotm's patch would be a natural starting point there.

<!-- gh-comment-id:4873801461 --> @MHSanaei commented on GitHub (Jul 3, 2026): This is now supported: each inbound has a **Subscription sort index** field (in the inbound create/edit form, also shown as a column in the inbound list), and subscription output — raw, HTML page, JSON, and Clash — is ordered by that index with ID as tiebreaker. That also fixes the non-deterministic ordering you observed on PostgreSQL, since the query now has an explicit ORDER BY. For your example, give your local inbounds lower sort indexes than the node inbounds and they'll be grouped on top for every client. Per-client ordering (a different order for each client) is intentionally not part of this mechanism — if you specifically need that, please open a focused follow-up issue; @psyhotm's patch would be a natural starting point there.
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#3364
No description provided.