mapledan opened a new pull request, #38949:
URL: https://github.com/apache/superset/pull/38949

   ### SUMMARY
   
   #37625  converted `PivotData` from JavaScript to TypeScript and typed 
`colKey`/`rowKey` as `string[][]`. To satisfy this type constraint, 
`processRecord` was updated to wrap all record values with `String()` before 
storing them as keys.
   
   This introduced a regression: temporal columns containing **numeric 
timestamps** (e.g. `1704067200000`) are now stringified to `"1704067200000"`. 
When `TableRenderers` passes this string to `TimeFormatter`, the underlying 
`stringifyTimeInput` calls `new Date("1704067200000")`, which returns `Invalid 
Date` in all browsers — numeric strings are not a valid `Date` constructor 
input. D3 time formatters then output `"NaN"` for each date component, causing 
pivot table column/row headers to display `NaN`.
   
   **Root cause chain:**
   processRecord: String(1704067200000) → "1704067200000"
   → TableRenderers: dateFormatterscol
   → stringifyTimeInput: new Date("1704067200000") = Invalid Date
   → D3 formatter: "NaN"
   
   **Fix:**
   
   Extend `stringifyTimeInput` to handle `string` inputs, completing the 
TypeScript migration that `fc5506e466` started at the data layer but did not 
propagate to the formatting layer:
   
   - **Numeric-only strings** (e.g. `"1704067200000"`) are converted back to 
`number`
     via `Number()` before `Date` construction, restoring pre-`fc5506e466` 
behavior.
   - **All other strings** (e.g. ISO date strings `"2024-01-01T00:00:00Z"`) are 
passed
     directly to `new Date()`, which handles them correctly in all browsers.
   
   Also update `TimeFormatter`'s type signature (callable interface, 
constructor, and `format()` method) to include `string`, making the type system 
consistent with the actual inputs the formatter receives at runtime.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   | Before | After |
   |--------|-------|
   | Pivot table date headers show `NaN` for temporal columns with numeric 
timestamps | Dates display correctly |
   
   ### TESTING INSTRUCTIONS
   
   1. Create a chart using the **Pivot Table** visualization
   2. Add a temporal column (e.g. `__timestamp`) as a **Row** or **Column**
   3. Use a data source that returns dates as numeric timestamps
   4. Observe that date headers previously showed `NaN` and now display 
formatted dates correctly
   
   Unit test added to `TimeFormatter.test.ts`:
   handles numeric string, treating it as a timestamp
   
   
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] 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