Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit d2c1fb9

Browse files
authored
fix(native-filters): Caching scope (apache#23314)
1 parent df9a5bb commit d2c1fb9

File tree

5 files changed

+23
-35
lines changed

5 files changed

+23
-35
lines changed

superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ describe('Native filters', () => {
576576
},
577577
);
578578
saveNativeFilterSettings([SAMPLE_CHART]);
579-
enterNativeFilterEditModal();
579+
enterNativeFilterEditModal(false);
580580
cy.get(nativeFilters.modal.tabsList.removeTab)
581581
.should('be.visible')
582582
.first()
@@ -812,7 +812,7 @@ describe('Native filters', () => {
812812
force: true,
813813
});
814814
cancelNativeFilterSettings();
815-
enterNativeFilterEditModal();
815+
enterNativeFilterEditModal(false);
816816
cy.get(nativeFilters.filtersList.removeIcon).first().click();
817817
cy.contains('You have removed this filter.').should('be.visible');
818818
});
@@ -855,7 +855,7 @@ describe('Native filters', () => {
855855
.contains(testItems.filterDefaultValue)
856856
.should('be.visible');
857857
validateFilterNameOnDashboard(testItems.topTenChart.filterColumn);
858-
enterNativeFilterEditModal();
858+
enterNativeFilterEditModal(false);
859859
deleteNativeFilter();
860860
saveNativeFilterSettings([SAMPLE_CHART]);
861861
cy.get(dataTestChartName(testItems.topTenChart.name)).within(() => {

superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/ColumnSelect.tsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
* under the License.
1818
*/
1919
import React, { useCallback, useState, useMemo, useEffect } from 'react';
20-
import { Column, ensureIsArray, SupersetClient, t } from '@superset-ui/core';
20+
import { Column, ensureIsArray, t } from '@superset-ui/core';
2121
import { useChangeEffect } from 'src/hooks/useChangeEffect';
2222
import { Select, FormInstance } from 'src/components';
2323
import { useToasts } from 'src/components/MessageToasts/withToasts';
2424
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
25-
import { cacheWrapper } from 'src/utils/cacheWrapper';
2625
import { NativeFiltersForm } from '../types';
26+
import { cachedSupersetGet } from './utils';
2727

2828
interface ColumnSelectProps {
2929
allowClear?: boolean;
@@ -37,14 +37,6 @@ interface ColumnSelectProps {
3737
mode?: 'multiple';
3838
}
3939

40-
const localCache = new Map<string, any>();
41-
42-
const cachedSupersetGet = cacheWrapper(
43-
SupersetClient.get,
44-
localCache,
45-
({ endpoint }) => endpoint || '',
46-
);
47-
4840
/** Special purpose AsyncSelect that selects a column from a dataset */
4941
// eslint-disable-next-line import/prefer-default-export
5042
export function ColumnSelect({

superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/DatasetSelect.tsx

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,13 @@
1818
*/
1919
import React, { useCallback, useMemo } from 'react';
2020
import rison from 'rison';
21-
import { t, SupersetClient } from '@superset-ui/core';
21+
import { t } from '@superset-ui/core';
2222
import { AsyncSelect } from 'src/components';
23-
import { cacheWrapper } from 'src/utils/cacheWrapper';
2423
import {
2524
ClientErrorObject,
2625
getClientErrorObject,
2726
} from 'src/utils/getClientErrorObject';
28-
import { datasetToSelectOption } from './utils';
29-
30-
const localCache = new Map<string, any>();
31-
32-
const cachedSupersetGet = cacheWrapper(
33-
SupersetClient.get,
34-
localCache,
35-
({ endpoint }) => endpoint || '',
36-
);
27+
import { cachedSupersetGet, datasetToSelectOption } from './utils';
3728

3829
interface DatasetSelectProps {
3930
onChange: (value: { label: string; value: number }) => void;

superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
NativeFilterType,
3535
styled,
3636
SupersetApiError,
37-
SupersetClient,
3837
t,
3938
} from '@superset-ui/core';
4039
import { isEqual } from 'lodash';
@@ -70,7 +69,6 @@ import DateFilterControl from 'src/explore/components/controls/DateFilterControl
7069
import AdhocFilterControl from 'src/explore/components/controls/FilterControl/AdhocFilterControl';
7170
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
7271
import { waitForAsyncData } from 'src/middleware/asyncEvent';
73-
import { cacheWrapper } from 'src/utils/cacheWrapper';
7472
import { ClientErrorObject } from 'src/utils/getClientErrorObject';
7573
import { SingleValueType } from 'src/filters/components/Range/SingleValueType';
7674
import {
@@ -91,6 +89,7 @@ import getControlItemsMap from './getControlItemsMap';
9189
import RemovedFilter from './RemovedFilter';
9290
import { useBackendFormUpdate, useDefaultValue } from './state';
9391
import {
92+
cachedSupersetGet,
9493
FILTER_SUPPORTED_TYPES,
9594
hasTemporalColumns,
9695
mostUsedDataset,
@@ -322,14 +321,6 @@ const FILTER_TYPE_NAME_MAPPING = {
322321
[t('Group By')]: t('Group by'),
323322
};
324323

325-
const localCache = new Map<string, any>();
326-
327-
const cachedSupersetGet = cacheWrapper(
328-
SupersetClient.get,
329-
localCache,
330-
({ endpoint }) => endpoint || '',
331-
);
332-
333324
/**
334325
* The configuration form for a specific filter.
335326
* Assigns field values to `filters[filterId]` in the form.

superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/utils.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@ import { flatMapDeep } from 'lodash';
2020
import { FormInstance } from 'src/components';
2121
import React from 'react';
2222
import { CustomControlItem, Dataset } from '@superset-ui/chart-controls';
23-
import { Column, ensureIsArray, GenericDataType } from '@superset-ui/core';
23+
import {
24+
Column,
25+
ensureIsArray,
26+
GenericDataType,
27+
SupersetClient,
28+
} from '@superset-ui/core';
2429
import { DatasourcesState, ChartsState } from 'src/dashboard/types';
30+
import { cacheWrapper } from 'src/utils/cacheWrapper';
2531

2632
const FILTERS_FIELD_NAME = 'filters';
2733

@@ -130,3 +136,11 @@ export const mostUsedDataset = (
130136

131137
return datasets[mostUsedDataset]?.id;
132138
};
139+
140+
const localCache = new Map<string, any>();
141+
142+
export const cachedSupersetGet = cacheWrapper(
143+
SupersetClient.get,
144+
localCache,
145+
({ endpoint }) => endpoint || '',
146+
);

0 commit comments

Comments
 (0)