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


##########
superset-frontend/src/features/versionHistory/grouping.ts:
##########
@@ -0,0 +1,276 @@
+/**
+ * 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 type {
+  ActivityRecord,
+  RelatedEntry,
+  SaveGroup,
+  TimelineEntry,
+} from './types';
+
+/**
+ * Stable identity for one activity record, used to deduplicate rows
+ * when merging pages (offset pagination can re-serve rows if a new
+ * save lands between page fetches).
+ */
+export function recordKey(record: ActivityRecord): string {
+  return [
+    record.transaction_id,
+    record.entity_kind,
+    record.entity_uuid ?? record.entity_name,
+    record.source,
+    record.kind,
+    record.operation,
+    JSON.stringify(record.path),
+    // kind/operation/path can repeat within one transaction — the same field
+    // touched twice, or two entries under one collection path. Without the
+    // values, the second record is taken for a re-served copy of the first and
+    // dropped on page merge, so the timeline silently under-reports the save.
+    JSON.stringify(record.from_value ?? null),
+    JSON.stringify(record.to_value ?? null),
+  ].join('|');
+}
+
+/** Merge a newly fetched page into already loaded records, deduplicated. */
+export function mergeActivityPages(
+  existing: ActivityRecord[],
+  incoming: ActivityRecord[],
+): ActivityRecord[] {
+  const seen = new Set(existing.map(recordKey));
+  const merged = [...existing];
+  incoming.forEach(record => {
+    const key = recordKey(record);
+    if (!seen.has(key)) {
+      seen.add(key);
+      merged.push(record);
+    }
+  });
+  return merged;
+}
+
+/** One related row per save of a related entity, regardless of how many
+ * change records that save produced. */
+export function relatedEntryKey(record: ActivityRecord): string {
+  return [
+    record.transaction_id,
+    record.entity_kind,
+    record.entity_uuid ?? record.entity_name,
+  ].join('|');

Review Comment:
   **Suggestion:** Using `entity_name` as the identity fallback when 
`entity_uuid` is null can merge unrelated related-entity records that share a 
name, which is possible for deleted entities or entities whose UUID is absent. 
Those distinct changes will collapse into one timeline row and some history 
will be lost. Use a stable unique identifier or retain such records separately 
when no UUID is available. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ Distinct deleted-entity history rows can collapse together.
   ```
   </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=5449ccf27c184d93ad5cf96314ab2aeb&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=5449ccf27c184d93ad5cf96314ab2aeb&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/src/features/versionHistory/grouping.ts
   **Line:** 68:73
   **Comment:**
        *Logic Error: Using `entity_name` as the identity fallback when 
`entity_uuid` is null can merge unrelated related-entity records that share a 
name, which is possible for deleted entities or entities whose UUID is absent. 
Those distinct changes will collapse into one timeline row and some history 
will be lost. Use a stable unique identifier or retain such records separately 
when no UUID is available.
   
   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%2F41551&comment_hash=a039c73244dfd48f7fa52795f86e6f0f000fcb69d5b13f13e309a71b2d5d2294&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41551&comment_hash=a039c73244dfd48f7fa52795f86e6f0f000fcb69d5b13f13e309a71b2d5d2294&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