korbit-ai[bot] commented on code in PR #34323:
URL: https://github.com/apache/superset/pull/34323#discussion_r2231972032


##########
superset-frontend/plugins/plugin-chart-echarts/src/Pie/transformProps.ts:
##########
@@ -435,7 +436,16 @@ export default function transformProps(
     },
     legend: {
       ...getLegendProps(legendType, legendOrientation, showLegend, theme),
-      data: transformedData.map(datum => datum.name),
+      data: transformedData
+        .map(datum => datum.name)
+        .sort((a: string, b: string) => {
+          if (!legendSort) return 0;
+          if (legendSort === 'asc') {
+            return a.localeCompare(b);
+          } else {
+            return b.localeCompare(a);
+          }
+        }),

Review Comment:
   ### Overly complex legend sorting logic <sub>![category 
Readability](https://img.shields.io/badge/Readability-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The sorting logic uses nested if statements and implicit 'desc' handling, 
making it less readable than a more direct approach.
   
   
   ###### Why this matters
   Complex branching in sort functions can make the code harder to maintain and 
understand the sorting behavior at a glance.
   
   ###### Suggested change ∙ *Feature Preview*
   ```typescript
           .sort((a: string, b: string) => {
             if (!legendSort) return 0;
             return legendSort === 'asc' ? a.localeCompare(b) : 
b.localeCompare(a);
           })
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/215f040f-3dd6-4a47-b39e-47b876777db6/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/215f040f-3dd6-4a47-b39e-47b876777db6?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/215f040f-3dd6-4a47-b39e-47b876777db6?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/215f040f-3dd6-4a47-b39e-47b876777db6?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/215f040f-3dd6-4a47-b39e-47b876777db6)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:608781d0-077d-4719-bf8f-77c9c440a460 -->
   
   
   [](608781d0-077d-4719-bf8f-77c9c440a460)



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