This is an automated email from the ASF dual-hosted git repository.

kgabryje pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 605cfa045a perf: Prevent rerendering and re-querying metadata of 
filters in horizontal bar (#22389)
605cfa045a is described below

commit 605cfa045a8b774713f8ddf57abb1f2825c645cf
Author: Kamil Gabryjelski <[email protected]>
AuthorDate: Mon Dec 12 16:07:38 2022 +0100

    perf: Prevent rerendering and re-querying metadata of filters in horizontal 
bar (#22389)
---
 .../FilterBar/FilterControls/FilterControl.tsx     | 77 ++++++++++++----------
 .../FilterBar/FilterControls/FilterValue.tsx       |  2 +-
 2 files changed, 45 insertions(+), 34 deletions(-)

diff --git 
a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControl.tsx
 
b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControl.tsx
index 535e2e0bd9..7d335e553d 100644
--- 
a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControl.tsx
+++ 
b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterControl.tsx
@@ -17,6 +17,11 @@
  * under the License.
  */
 import React, { useContext, useMemo, useState } from 'react';
+import {
+  createHtmlPortalNode,
+  InPortal,
+  OutPortal,
+} from 'react-reverse-portal';
 import { styled, SupersetTheme } from '@superset-ui/core';
 import { FormItem as StyledFormItem, Form } from 'src/components/Form';
 import { Tooltip } from 'src/components/Tooltip';
@@ -224,6 +229,7 @@ const FilterControl = ({
   orientation = FilterBarOrientation.VERTICAL,
   overflow = false,
 }: FilterControlProps) => {
+  const portalNode = useMemo(() => createHtmlPortalNode(), []);
   const [isFilterActive, setIsFilterActive] = useState(false);
 
   const { name = '<undefined>' } = filter;
@@ -276,40 +282,45 @@ const FilterControl = ({
   }, [orientation, overflow]);
 
   return (
-    <FilterControlContainer
-      layout={
-        orientation === FilterBarOrientation.HORIZONTAL && !overflow
-          ? 'horizontal'
-          : 'vertical'
-      }
-    >
-      <FilterCard
-        filter={filter}
-        isVisible={!isFilterActive && !isScrolling}
-        placement={filterCardPlacement}
+    <>
+      <InPortal node={portalNode}>
+        <FilterValue
+          dataMaskSelected={dataMaskSelected}
+          filter={filter}
+          showOverflow={showOverflow}
+          focusedFilterId={focusedFilterId}
+          onFilterSelectionChange={onFilterSelectionChange}
+          inView={inView}
+          parentRef={parentRef}
+          setFilterActive={setIsFilterActive}
+          orientation={orientation}
+          overflow={overflow}
+        />
+      </InPortal>
+      <FilterControlContainer
+        layout={
+          orientation === FilterBarOrientation.HORIZONTAL && !overflow
+            ? 'horizontal'
+            : 'vertical'
+        }
       >
-        <div>
-          <FormItem
-            label={label}
-            required={filter?.controlValues?.enableEmptyFilter}
-            validateStatus={isMissingRequiredValue ? 'error' : undefined}
-          >
-            <FilterValue
-              dataMaskSelected={dataMaskSelected}
-              filter={filter}
-              showOverflow={showOverflow}
-              focusedFilterId={focusedFilterId}
-              onFilterSelectionChange={onFilterSelectionChange}
-              inView={inView}
-              parentRef={parentRef}
-              setFilterActive={setIsFilterActive}
-              orientation={orientation}
-              overflow={overflow}
-            />
-          </FormItem>
-        </div>
-      </FilterCard>
-    </FilterControlContainer>
+        <FilterCard
+          filter={filter}
+          isVisible={!isFilterActive && !isScrolling}
+          placement={filterCardPlacement}
+        >
+          <div>
+            <FormItem
+              label={label}
+              required={filter?.controlValues?.enableEmptyFilter}
+              validateStatus={isMissingRequiredValue ? 'error' : undefined}
+            >
+              <OutPortal node={portalNode} />
+            </FormItem>
+          </div>
+        </FilterCard>
+      </FilterControlContainer>
+    </>
   );
 };
 
diff --git 
a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
 
b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
index 213329c4b3..308361622e 100644
--- 
a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
+++ 
b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
@@ -319,4 +319,4 @@ const FilterValue: React.FC<FilterControlProps> = ({
     </StyledDiv>
   );
 };
-export default FilterValue;
+export default React.memo(FilterValue);

Reply via email to