Copilot commented on code in PR #44991:
URL: https://github.com/apache/superset/pull/44991#discussion_r4198332359
##########
superset-frontend/src/features/roles/utils.ts:
##########
@@ -60,6 +61,51 @@ export const formatPermissionLabel = (
viewMenuName: string,
) => `${permissionName.replace(/_/g, ' ')} ${viewMenuName.replace(/_/g, ' ')}`;
+// Numeric-aware collation so "[yyy2]" sorts before "[yyy10]" instead of the
+// plain string order produced by localeCompare ("[yyy10]" before "[yyy2]").
+const naturalCollator = new Intl.Collator(undefined, { numeric: true });
+
+/**
+ * Ranks how closely a label matches a search term, mirroring the tiers of
+ * rankedSearchCompare (exact, prefix, substring; case-sensitive first).
+ * Lower is a better match.
+ */
+const getSearchMatchRank = (label: string, search: string) => {
+ const labelLower = label.toLowerCase();
+ const searchLower = search.toLowerCase();
+ const tiers = [
+ label === search,
+ label.startsWith(search),
+ labelLower === searchLower,
+ labelLower.startsWith(searchLower),
+ label.includes(search),
+ labelLower.includes(searchLower),
+ ];
+ const rank = tiers.indexOf(true);
+ return rank === -1 ? tiers.length : rank;
Review Comment:
This first-match index does not fully mirror `rankedSearchCompare`: once
both labels hit the same earliest tier, it discards differences in the
remaining case-sensitive tiers. For example, searching `CAN` ranks both `can
read Dashboard` and `can write CANReport` as case-insensitive prefixes, so
natural order puts the former first, whereas the default comparator puts the
latter first because it also contains the exact-case search text. Preserve the
complete ordered boolean vector and use natural collation only when every
relevance criterion ties.
--
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]