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


##########
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts:
##########
@@ -685,14 +710,27 @@ export function transformTimeseriesAnnotation(
 ): SeriesOption[] {
   const series: SeriesOption[] = [];
   const { hideLine, name, opacity, showMarkers, style, width, color } = layer;
+
+  const shiftMs = parseTimeShiftToMs((layer as any)?.overrides?.time_shift);
+
   const result = annotationData[name];
   const isHorizontal = orientation === OrientationType.Horizontal;
   const { records } = result;
   if (records) {
     const data = records.map(record => {
       const keys = Object.keys(record);
-      const x = keys.length > 0 ? record[keys[0]] : 0;
+
+      let x = keys.length > 0 ? record[keys[0]] : 0;
       const y = keys.length > 1 ? record[keys[1]] : 0;
+
+      if (shiftMs !== 0 && x != null) {
+        const xMs = typeof x === 'string' ? new Date(x).getTime() : Number(x);

Review Comment:
   **Suggestion:** When an annotation timestamp is supplied as a numeric epoch 
string, `new Date(x)` does not reliably interpret it as an epoch timestamp and 
commonly produces an invalid date, so the shift is silently skipped. Normalize 
numeric strings as numbers before date parsing, otherwise annotations 
represented by stringified epoch values remain unshifted while equivalent 
numeric values are shifted. [possible bug]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Stringified epoch annotations remain unshifted.
   - ⚠️ Annotation alignment depends on timestamp representation.
   - ⚠️ Numeric and string records render inconsistently.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Render a Timeseries annotation whose first record field is a stringified 
epoch
   timestamp, such as `"1704067200000"`; `transformTimeseriesAnnotation()` 
obtains that value
   as `x` at
   
`superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts:723`.
   
   2. Apply a nonzero annotation time shift through 
`layer.overrides.time_shift`, which is
   parsed at line 714.
   
   3. At line 727, the string value is passed to `new Date(x)` instead of being 
converted
   with `Number(x)` first; JavaScript does not reliably parse a millisecond 
epoch string as a
   valid date, so `getTime()` can return `NaN`.
   
   4. Because line 729 rejects `NaN`, the code skips the addition at line 730 
and returns the
   original timestamp at lines 734-736; equivalent numeric epoch values are 
shifted,
   producing inconsistent annotation alignment.
   ```
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a9c6dc288f344ac7b0d06dd2c24190b9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a9c6dc288f344ac7b0d06dd2c24190b9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/plugin-chart-echarts/src/Timeseries/transformers.ts
   **Line:** 727:727
   **Comment:**
        *Possible Bug: When an annotation timestamp is supplied as a numeric 
epoch string, `new Date(x)` does not reliably interpret it as an epoch 
timestamp and commonly produces an invalid date, so the shift is silently 
skipped. Normalize numeric strings as numbers before date parsing, otherwise 
annotations represented by stringified epoch values remain unshifted while 
equivalent numeric values are shifted.
   
   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.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38126&comment_hash=37bae9e945d77513eaa0640b13129bbd0972814e24bedd75f45b3473a264f06c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F38126&comment_hash=37bae9e945d77513eaa0640b13129bbd0972814e24bedd75f45b3473a264f06c&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