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


##########
superset-frontend/src/features/versionHistory/canRestoreDashboard.ts:
##########
@@ -0,0 +1,41 @@
+/**
+ * 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 { RootState } from 'src/dashboard/types';
+
+/**
+ * Whether the current user may restore a version of this dashboard.
+ *
+ * The dashboard counterpart of `canOverwriteSlice`, and it excludes
+ * externally managed dashboards for the same reason: their source of truth
+ * lives outside Superset, so a restore would be overwritten again by the next
+ * sync.
+ *
+ * Exported as one selector because the gate has more than one consumer — the
+ * history panel and the preview banner — and the header menu's own
+ * `is_managed_externally` check already showed how easily those drift apart.
+ * The panel is reachable directly via `?version_history=true`, so a gate
+ * applied only where the menu entry renders is not applied at all. The restore
+ * endpoint checks editorship but not external management, which leaves this as
+ * the only guard.
+ */
+export const selectCanRestoreDashboard = (state: RootState): boolean =>
+  (state.dashboardInfo?.dash_edit_perm ?? false) &&
+  !state.dashboardInfo?.is_managed_externally;

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag the restore gate for omitting extra-editor support until the 
dashboard payload exposes extra_editors; keep it aligned with the existing 
editors-only canUserEditDashboard behavior in the meantime.
   
   **Applied to:**
     - `superset-frontend/src/features/versionHistory/canRestoreDashboard.ts`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
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:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag the entity_name fallback in relatedEntryKey while the API 
omits stable identities for tombstoned entities; defer this issue until the 
backend exposes the natural record identity.
   
   **Applied to:**
     - `superset-frontend/src/features/versionHistory/grouping.ts`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



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