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

Commit

Permalink
fix(native-filters): Caching scope (apache#23314)
Browse files Browse the repository at this point in the history
  • Loading branch information
john-bodley committed Mar 14, 2023
1 parent df9a5bb commit d2c1fb9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ describe('Native filters', () => {
},
);
saveNativeFilterSettings([SAMPLE_CHART]);
enterNativeFilterEditModal();
enterNativeFilterEditModal(false);
cy.get(nativeFilters.modal.tabsList.removeTab)
.should('be.visible')
.first()
Expand Down Expand Up @@ -812,7 +812,7 @@ describe('Native filters', () => {
force: true,
});
cancelNativeFilterSettings();
enterNativeFilterEditModal();
enterNativeFilterEditModal(false);
cy.get(nativeFilters.filtersList.removeIcon).first().click();
cy.contains('You have removed this filter.').should('be.visible');
});
Expand Down Expand Up @@ -855,7 +855,7 @@ describe('Native filters', () => {
.contains(testItems.filterDefaultValue)
.should('be.visible');
validateFilterNameOnDashboard(testItems.topTenChart.filterColumn);
enterNativeFilterEditModal();
enterNativeFilterEditModal(false);
deleteNativeFilter();
saveNativeFilterSettings([SAMPLE_CHART]);
cy.get(dataTestChartName(testItems.topTenChart.name)).within(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* under the License.
*/
import React, { useCallback, useState, useMemo, useEffect } from 'react';
import { Column, ensureIsArray, SupersetClient, t } from '@superset-ui/core';
import { Column, ensureIsArray, t } from '@superset-ui/core';
import { useChangeEffect } from 'src/hooks/useChangeEffect';
import { Select, FormInstance } from 'src/components';
import { useToasts } from 'src/components/MessageToasts/withToasts';
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
import { cacheWrapper } from 'src/utils/cacheWrapper';
import { NativeFiltersForm } from '../types';
import { cachedSupersetGet } from './utils';

interface ColumnSelectProps {
allowClear?: boolean;
Expand All @@ -37,14 +37,6 @@ interface ColumnSelectProps {
mode?: 'multiple';
}

const localCache = new Map<string, any>();

const cachedSupersetGet = cacheWrapper(
SupersetClient.get,
localCache,
({ endpoint }) => endpoint || '',
);

/** Special purpose AsyncSelect that selects a column from a dataset */
// eslint-disable-next-line import/prefer-default-export
export function ColumnSelect({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,13 @@
*/
import React, { useCallback, useMemo } from 'react';
import rison from 'rison';
import { t, SupersetClient } from '@superset-ui/core';
import { t } from '@superset-ui/core';
import { AsyncSelect } from 'src/components';
import { cacheWrapper } from 'src/utils/cacheWrapper';
import {
ClientErrorObject,
getClientErrorObject,
} from 'src/utils/getClientErrorObject';
import { datasetToSelectOption } from './utils';

const localCache = new Map<string, any>();

const cachedSupersetGet = cacheWrapper(
SupersetClient.get,
localCache,
({ endpoint }) => endpoint || '',
);
import { cachedSupersetGet, datasetToSelectOption } from './utils';

interface DatasetSelectProps {
onChange: (value: { label: string; value: number }) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import {
NativeFilterType,
styled,
SupersetApiError,
SupersetClient,
t,
} from '@superset-ui/core';
import { isEqual } from 'lodash';
Expand Down Expand Up @@ -70,7 +69,6 @@ import DateFilterControl from 'src/explore/components/controls/DateFilterControl
import AdhocFilterControl from 'src/explore/components/controls/FilterControl/AdhocFilterControl';
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
import { waitForAsyncData } from 'src/middleware/asyncEvent';
import { cacheWrapper } from 'src/utils/cacheWrapper';
import { ClientErrorObject } from 'src/utils/getClientErrorObject';
import { SingleValueType } from 'src/filters/components/Range/SingleValueType';
import {
Expand All @@ -91,6 +89,7 @@ import getControlItemsMap from './getControlItemsMap';
import RemovedFilter from './RemovedFilter';
import { useBackendFormUpdate, useDefaultValue } from './state';
import {
cachedSupersetGet,
FILTER_SUPPORTED_TYPES,
hasTemporalColumns,
mostUsedDataset,
Expand Down Expand Up @@ -322,14 +321,6 @@ const FILTER_TYPE_NAME_MAPPING = {
[t('Group By')]: t('Group by'),
};

const localCache = new Map<string, any>();

const cachedSupersetGet = cacheWrapper(
SupersetClient.get,
localCache,
({ endpoint }) => endpoint || '',
);

/**
* The configuration form for a specific filter.
* Assigns field values to `filters[filterId]` in the form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ import { flatMapDeep } from 'lodash';
import { FormInstance } from 'src/components';
import React from 'react';
import { CustomControlItem, Dataset } from '@superset-ui/chart-controls';
import { Column, ensureIsArray, GenericDataType } from '@superset-ui/core';
import {
Column,
ensureIsArray,
GenericDataType,
SupersetClient,
} from '@superset-ui/core';
import { DatasourcesState, ChartsState } from 'src/dashboard/types';
import { cacheWrapper } from 'src/utils/cacheWrapper';

const FILTERS_FIELD_NAME = 'filters';

Expand Down Expand Up @@ -130,3 +136,11 @@ export const mostUsedDataset = (

return datasets[mostUsedDataset]?.id;
};

const localCache = new Map<string, any>();

export const cachedSupersetGet = cacheWrapper(
SupersetClient.get,
localCache,
({ endpoint }) => endpoint || '',
);

0 comments on commit d2c1fb9

Please sign in to comment.