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


##########
superset-frontend/src/components/ListView/useListViewPersistence.ts:
##########
@@ -0,0 +1,171 @@
+/**
+ * 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 { useCallback, useEffect, useLayoutEffect, useState } from 'react';
+import { useHistory, useLocation } from 'react-router-dom';
+import rison from 'rison';
+
+const RESOURCES = ['dashboard', 'chart', 'dataset'] as const;
+const QUERY_KEYS = [
+  'filters',
+  'pageIndex',
+  'sortColumn',
+  'sortOrder',
+  'viewMode',
+] as const;
+
+export interface ListViewPersistenceConfig {
+  userId: number;
+  resource: (typeof RESOURCES)[number];
+}
+
+type SavedViews = Partial<
+  Record<ListViewPersistenceConfig['resource'], string>
+>;
+
+/** Pick only list settings; unrelated URL parameters belong to their links. */
+function listQuery(search: string) {
+  const source = new URLSearchParams(search);
+  const query = new URLSearchParams();
+  QUERY_KEYS.forEach(key => {
+    const value = source.get(key);
+    if (value !== null) query.set(key, value);
+  });
+  return query;
+}
+
+/** Ignore damaged or obsolete saved state instead of breaking a list page. */
+function readViews(userId: number): SavedViews {
+  try {
+    const stored: unknown = JSON.parse(
+      sessionStorage.getItem(`listview__state:${userId}`) || '{}',
+    );
+    if (!stored || typeof stored !== 'object' || Array.isArray(stored))
+      return {};
+    const views: SavedViews = {};
+    RESOURCES.forEach(resource => {
+      const value = (stored as Record<string, unknown>)[resource];
+      if (typeof value !== 'string') return;
+      const query = listQuery(value);
+      const page = query.get('pageIndex');
+      if (
+        page !== null &&
+        (!/^\d+$/.test(page) || !Number.isSafeInteger(Number(page)))
+      )
+        return;
+      const mode = query.get('viewMode');
+      if (mode !== null && mode !== 'card' && mode !== 'table') return;
+      const order = query.get('sortOrder');
+      if (order !== null && order !== 'asc' && order !== 'desc') return;
+      if (query.has('filters')) {
+        try {
+          const filters: unknown = rison.decode(query.get('filters') || '()');
+          if (!filters || typeof filters !== 'object' || 
Array.isArray(filters))
+            return;

Review Comment:
   **Suggestion:** If a saved filter's control is removed or disabled, this 
accepts its key and `convertFiltersRison` forwards it to `fetchData`, so the 
list keeps applying an invisible filter.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Rarely` ยท ๐Ÿท๏ธ `Api mismatch`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![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=9bb243df117d462fb864a5cc03dad68c&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=9bb243df117d462fb864a5cc03dad68c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/components/ListView/useListViewPersistence.ts
   **Line:** 77:79
   **Comment:**
        *Api Mismatch: If a saved filter's control is removed or disabled, this 
accepts its key and `convertFiltersRison` forwards it to `fetchData`, so the 
list keeps applying an invisible filter.
   
   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%2F45335&comment_hash=b82742e9813848e98ca034fb7ed8d8b20020a83b61b689bc331a28a1adf5e344&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45335&comment_hash=b82742e9813848e98ca034fb7ed8d8b20020a83b61b689bc331a28a1adf5e344&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset-frontend/src/components/ListView/utils.ts:
##########
@@ -351,7 +351,12 @@ export function useListViewState<D extends object = any>({
         : 'replace';
 
     setQuery(queryParams, method);
+    // URL navigation updates the table below. Do not write the old table
+    // page back into history before that synchronization has run.
+    // eslint-disable-next-line react-hooks/exhaustive-deps
+  }, [internalFilters, pageIndex, renderCard, setQuery, sortBy, viewMode]);

Review Comment:
   **Suggestion:** `query` changes from Back or Forward no longer rerun this 
effect, so filters, sort, and view mode stay stale; the later effect 
synchronizes only `pageIndex`.
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes` ยท ๐Ÿท๏ธ `Stale reference`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![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=ce4e5f6b5f474accb38b9b8a78bff702&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=ce4e5f6b5f474accb38b9b8a78bff702&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset-frontend/src/components/ListView/utils.ts
   **Line:** 357:357
   **Comment:**
        *Stale Reference: `query` changes from Back or Forward no longer rerun 
this effect, so filters, sort, and view mode stay stale; the later effect 
synchronizes only `pageIndex`.
   
   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%2F45335&comment_hash=885063f84a1b3a339ebb8933af70ed0cdfd0bed6e73dacff3c423199e7c1fcb8&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F45335&comment_hash=885063f84a1b3a339ebb8933af70ed0cdfd0bed6e73dacff3c423199e7c1fcb8&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