Copilot commented on code in PR #24444:
URL: https://github.com/apache/superset/pull/24444#discussion_r2955047708


##########
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;
+}) {

Review Comment:
   `createLengthFormatter` requires a `config` argument, unlike the other 
formatter factories in this folder which default `config` to `{}`. Since this 
is exported as a public factory, consider giving `config` a default value and 
typing `convertType` as a string union/enum instead of a free-form string to 
prevent typos (e.g. mismatched keys between call sites).
   



##########
superset-frontend/packages/superset-ui-chart-controls/src/utils/D3Formatting.ts:
##########
@@ -68,6 +68,9 @@ export const D3_FORMAT_OPTIONS: [string, string][] = [
     'MEMORY_TRANSFER_RATE_BINARY',
     t('Memory transfer rate in bytes - binary (1024B => 1KiB/s)'),
   ],
+  ['LENGTH', t('Length in m (12345m => 12.34km)')],
+  ['LENGTH_CM_KM', t('Length in cm (12345678cm => 123.45km)')],

Review Comment:
   The example conversions in these option labels don't match the formatter's 
`toFixed(2)` rounding behavior (e.g. 12345m => 12.345km rounds to 12.35, not 
12.34; similarly 12345678cm rounds to 123.46km). Please adjust the example 
input values (or the formatter rounding logic) so the text accurately reflects 
what users will see.
   



##########
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:
   The formatted unit suffixes are returned as `KM`/`M`, but the UI option text 
describes `km`/`m` and SI unit symbols are conventionally lowercase (except 
where applicable). This will produce user-visible output that doesn't match the 
option description; please align the formatter output (and consider avoiding 
the redundant `.toString()` after `toFixed()`).
   



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