You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/10/24 07:39:48 UTC

[GitHub] [superset] zhaoyongjie commented on a diff in pull request #21821: perf(native-filters): improve native filter modal form performance

zhaoyongjie commented on code in PR #21821:
URL: https://github.com/apache/superset/pull/21821#discussion_r1002929562


##########
superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigModal.tsx:
##########
@@ -153,19 +153,27 @@ export function FiltersConfigModal({
 
   const unsavedFiltersIds = newFilterIds.filter(id => !removedFilters[id]);
   // brings back a filter that was previously removed ("Undo")
-  const restoreFilter = (id: string) => {
-    const removal = removedFilters[id];
-    // gotta clear the removal timeout to prevent the filter from getting deleted
-    if (removal?.isPending) clearTimeout(removal.timerId);
-    setRemovedFilters(current => ({ ...current, [id]: null }));
-  };
+  const restoreFilter = useCallback(
+    (id: string) => {
+      const removal = removedFilters[id];
+      // gotta clear the removal timeout to prevent the filter from getting deleted
+      if (removal?.isPending) clearTimeout(removal.timerId);
+      setRemovedFilters(current => ({ ...current, [id]: null }));
+    },
+    [removedFilters],
+  );
   const getInitialFilterOrder = () => Object.keys(filterConfigMap);
 
   // State for tracking the re-ordering of filters
   const [orderedFilters, setOrderedFilters] = useState<string[]>(
     getInitialFilterOrder(),
   );
 
+  // State for rendered filter to improve performance
+  const [renderedFilters, setRenderedFilters] = useState<string[]>([

Review Comment:
   nits: use Set for this case.
   
   ```typescript
   const [renderedFilters, setRenderedFilters] = useState<Set[]>([
   ```



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org