Skip to content

Commit

Permalink
fix(nativeFilters): Speed up native filters by removing unnecessary r…
Browse files Browse the repository at this point in the history
…erenders (apache#25282)

Co-authored-by: JUST.in DO IT <justin.park@airbnb.com>
  • Loading branch information
Always-prog and justinpark committed Sep 28, 2023
1 parent ba5e2f6 commit a0eeb4d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export enum AppSection {
export type FilterState = { value?: any; [key: string]: any };

export type DataMask = {
__cache?: FilterState;
extraFormData?: ExtraFormData;
filterState?: FilterState;
ownState?: JsonObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import { useMemo } from 'react';
import { useSelector } from 'react-redux';
import { shallowEqual, useSelector } from 'react-redux';
import {
DataMaskStateWithId,
ensureIsArray,
Expand All @@ -32,6 +32,7 @@ export function useFilterDependencies(
): ExtraFormData {
const dependencyIds = useSelector<any, string[] | undefined>(
state => state.nativeFilters.filters[id]?.cascadeParentIds,
shallowEqual,
);
return useMemo(() => {
let dependencies = {};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@
*/

/* eslint-disable no-param-reassign */
import React, { useEffect, useState, useCallback, createContext } from 'react';
import React, {
useEffect,
useState,
useCallback,
createContext,
useRef,
} from 'react';
import { useDispatch, useSelector } from 'react-redux';
import {
DataMaskStateWithId,
Expand Down Expand Up @@ -144,6 +150,8 @@ const FilterBar: React.FC<FiltersBarProps> = ({

const [filtersInScope] = useSelectFiltersInScope(nativeFilterValues);

const dataMaskSelectedRef = useRef(dataMaskSelected);
dataMaskSelectedRef.current = dataMaskSelected;
const handleFilterSelectionChange = useCallback(
(
filter: Pick<Filter, 'id'> & Partial<Filter>,
Expand All @@ -154,19 +162,19 @@ const FilterBar: React.FC<FiltersBarProps> = ({
if (
// filterState.value === undefined - means that value not initialized
dataMask.filterState?.value !== undefined &&
dataMaskSelected[filter.id]?.filterState?.value === undefined &&
dataMaskSelectedRef.current[filter.id]?.filterState?.value ===
undefined &&
filter.requiredFirst
) {
dispatch(updateDataMask(filter.id, dataMask));
}

draft[filter.id] = {
...(getInitialDataMask(filter.id) as DataMaskWithId),
...dataMask,
};
});
},
[dataMaskSelected, dispatch, setDataMaskSelected],
[dispatch, setDataMaskSelected],
);

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/dataMask/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function getInitialDataMask(
}
return {
...otherProps,
__cache: {},
extraFormData: {},
filterState: {},
ownState: {},
Expand Down

0 comments on commit a0eeb4d

Please sign in to comment.