codeant-ai-for-open-source[bot] commented on code in PR #24444:
URL: https://github.com/apache/superset/pull/24444#discussion_r2955059073


##########
superset-frontend/packages/superset-ui-core/src/number-format/factories/createLengthFormatter.ts:
##########
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import NumberFormatter from '../NumberFormatter';
+
+export default function createLengthFormatter(config: {
+  description?: string;
+  id?: string;
+  label?: string;
+  convertType?: string;
+}) {
+  const { description, id, label, convertType } = config;
+
+  return new NumberFormatter({
+    description,
+    formatFunc: value => {
+      if (convertType === 'm => km') {
+        return `${(value / 1000).toFixed(2).toString()}KM`;
+      }
+      if (convertType === 'cm => km') {
+        return `${(value / 100_000).toFixed(2).toString()}KM`;
+      }
+      if (convertType === 'cm => m') {
+        return `${(value / 100).toFixed(2).toString()}M`;
+      }

Review Comment:
   **Suggestion:** The formatter appends `KM`/`M`, but the feature text and 
registered option descriptions use SI unit symbols `km`/`m`; returning 
uppercase units produces incorrect user-facing unit labels. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Y-axis and tooltip units display incorrect SI casing.
   - ⚠️ Dropdown examples and rendered labels become inconsistent.
   ```
   </details>
   
   ```suggestion
         if (convertType === 'm => km') {
           return `${(value / 1000).toFixed(2).toString()}km`;
         }
         if (convertType === 'cm => km') {
           return `${(value / 100_000).toFixed(2).toString()}km`;
         }
         if (convertType === 'cm => m') {
           return `${(value / 100).toFixed(2).toString()}m`;
         }
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. App initialization runs `setupFormatters()` from
   `superset-frontend/src/preamble.ts:57-60`, registering `LENGTH`, 
`LENGTH_CM_KM`, and
   `LENGTH_CM_M` with `createLengthFormatter(...)` at
   `superset-frontend/src/setup/setupFormatters.ts:96-103`.
   
   2. Explore control dropdown exposes these options through `D3_FORMAT_OPTIONS`
   
(`superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts:71-73`),
   and `y_axis_format` uses those choices in `sharedControls.tsx:301-309`.
   
   3. After selecting one of these formats, chart rendering obtains the 
formatter via
   `getTimeOrNumberFormatter()` 
(`plugins/legacy-preset-chart-nvd3/src/utils.ts:49-52`) and
   applies it to axis ticks/labels/tooltips in `NVD3Vis.ts:41`, 
`NVD3Vis.ts:56`, and
   `NVD3Vis.ts:199-214`.
   
   4. The formatter output comes from `createLengthFormatter.ts:34`, `:37`, 
`:40`, returning
   `KM`/`M`, which conflicts with option text/examples using `km`/`m` in
   `D3Formatting.ts:71-73`.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/packages/superset-ui-core/src/number-format/factories/createLengthFormatter.ts
   **Line:** 33:41
   **Comment:**
        *Logic Error: The formatter appends `KM`/`M`, but the feature text and 
registered option descriptions use SI unit symbols `km`/`m`; returning 
uppercase units produces incorrect user-facing unit labels.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F24444&comment_hash=4e0bd99beca83cc3ca37c18e5651541c3153e0d94e2d102f286441e171d00c1e&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F24444&comment_hash=4e0bd99beca83cc3ca37c18e5651541c3153e0d94e2d102f286441e171d00c1e&reaction=dislike'>👎</a>



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