4RH1T3CT0R7 opened a new pull request, #37980:
URL: https://github.com/apache/superset/pull/37980

   ### SUMMARY
   
   When a user sets a percentage format (e.g. `,.1%` or `.8%`) on a Table chart 
column, small numbers (`|value| < 1`) display as raw unformatted values instead 
of formatted percentages.
   
   **Root cause:** In `formatColumnValue()`, the check 
`config.d3SmallNumberFormat === undefined` is too strict. The column config is 
serialized as JSON in the database, which converts `undefined` → `null`. When 
loaded back, `null === undefined` evaluates to `false`, so the code falls 
through to `getNumberFormatter(null)` which returns the `SMART_NUMBER` 
formatter instead of the user's percentage formatter. The same issue occurs 
with empty string `""` from a cleared Select control.
   
   **Fix:** Extract a shared `getSmallNumberFormatter()` utility into 
`@superset-ui/core` that uses `== null` (catches both `undefined` and `null`) 
and `.trim() === ''` (catches empty/whitespace strings) to properly fall back 
to the default formatter. Both `plugin-chart-table` and 
`plugin-chart-ag-grid-table` now call this shared utility, eliminating the 
duplicated logic.
   
   **Changes:**
   - 
**`packages/superset-ui-core/src/number-format/getSmallNumberFormatter.ts`** — 
New shared utility with a generic type parameter to accept any formatter type 
without circular dependency on `@superset-ui/chart-controls`
   - **`packages/superset-ui-core/src/number-format/index.ts`** — Export the 
new utility
   - **`plugins/plugin-chart-table/src/utils/formatValue.ts`** — Replace inline 
buggy logic with shared utility call
   - **`plugins/plugin-chart-ag-grid-table/src/utils/formatValue.ts`** — Same 
change
   - 
**`packages/superset-ui-core/test/number-format/getSmallNumberFormatter.test.ts`**
 — 8 unit tests covering `undefined`, `null`, `""`, whitespace, valid format, 
currency format, percentage regression, and `undefined` default formatter
   - **`plugins/plugin-chart-table/test/utils/formatValue.test.ts`** — 6 
regression tests for `formatColumnValue` with `null`/`""`/missing 
`d3SmallNumberFormat`, plus boundary tests for values `0`, `1`, `-1`
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A — formatting logic fix, no visual component changes.
   
   ### TESTING INSTRUCTIONS
   1. Apply the patch and run the unit tests:
      ```
      cd superset-frontend
      npx jest --testRegex ".*getSmallNumberFormatter\.test\.[jt]sx?$" 
--no-coverage
      npx jest --testRegex 
".*plugin-chart-table.test.utils.formatValue\.test\.[jt]sx?$" --no-coverage
      ```
   2. To verify manually:
      - Create a Table chart with a numeric column
      - Set the column's D3 format to a percentage format like `.8%`
      - Leave the "Small Number Format" field empty
      - Add data with small values (e.g. `-0.00001229`)
      - Verify the value displays as `-0.00122900%` instead of the raw number
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: Fixes #36189
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API


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