TryingtoLiveInTech opened a new pull request, #44991:
URL: https://github.com/apache/superset/pull/44991

   ### SUMMARY
   
   In **List Roles → Edit → Permissions**, permissions whose names embed 
numbers were ordered as plain strings, which is confusing for roles with many 
similar permissions such as per-dataset `datasource_access`:
   
   ```
   datasource access [xxx].[yyy1](id:1)
   datasource access [xxx].[yyy10](id:10)
   datasource access [xxx].[yyy100](id:100)
   datasource access [xxx].[yyy101](id:101)
   ...
   datasource access [xxx].[yyy11](id:11)
   ...
   datasource access [xxx].[yyy2](id:2)
   ```
   
   There were two separate causes:
   
   1. **Dropdown options**: `AsyncSelect`'s default comparator sorts labels 
with `localeCompare`, which compares digits character by character.
   2. **Selected tags**: the edit modal hydrates the selected values in the 
order returned by `GET /api/v1/security/roles/<id>/permissions/`. That FAB 
endpoint reads the `role.permissions` relationship without an `ORDER BY`, so 
the tags follow whatever order the database returns.
   
   Changes (scoped to `src/features/roles`):
   
   - Add `comparePermissionOptions`, a numeric-aware comparator 
(`Intl.Collator` with `numeric: true`). When a search term is present it keeps 
the same relevance tiers as the default Select comparator (exact → prefix → 
substring, case-sensitive first) and only uses natural ordering to break ties. 
It's passed as the `sortComparator` of `PermissionsField`; selected-first 
ordering is unchanged.
   - Add `sortPermissionOptions` and apply it to the role's fetched permissions 
before hydrating the form, so the selected tags read in natural order too.
   - `RoleListEditModal.test.tsx` auto-mocked `./utils`, which would turn the 
new sort helper into a stub returning `undefined`; the mock now keeps the pure 
`formatPermissionLabel` / `sortPermissionOptions` helpers real.
   
   I kept this local to the roles feature rather than changing the shared 
`rankedSearchCompare` / `DEFAULT_SORT_COMPARATOR`, since that would change 
ordering for every Select in the app. Happy to follow up with that if 
maintainers prefer.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Before: `yyy1, yyy10, yyy100, yyy101 … yyy109, yyy11, yyy110, yyy111, yyy12 
… yyy2, yyy20 …`
   
   After: `yyy1, yyy2, yyy3 … yyy10, yyy11 … yyy100, yyy101 … yyy111`
   
   ### TESTING INSTRUCTIONS
   
   Unit tests:
   
   ```bash
   cd superset-frontend
   npm run test -- src/features/roles
   ```
   
   New tests in `src/features/roles/utils.test.ts` cover natural ordering, 
non-mutation of the input, plain label ordering, search-relevance ranking, and 
natural tie-breaking among equal search matches.
   
   Manual:
   
   1. Create a role and give it several numbered permissions, e.g. `datasource 
access` on datasets named `t1`, `t2`, `t10`, `t100`.
   2. Go to **Settings → List Roles**, edit the role, and open the 
**Permissions** field.
   3. Verify the selected tags read `t1, t2, t10, t100`.
   4. Open the dropdown and verify options are listed in natural order 
(selected first), including after typing a search term such as `t`.
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to