TryingtoLiveInTech commented on code in PR #44991:
URL: https://github.com/apache/superset/pull/44991#discussion_r4236829923


##########
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:
   Good catch, thanks. Fixed in f96a984ed8: the comparator now compares the six 
criteria one at a time, in the same order as `rankedSearchCompare`, and only 
falls back to natural ordering when all of them tie. I added your `CAN` example 
as a test (`can write CANReport` now ranks above `can read Dashboard`).
   



-- 
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