Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(native-filters): Caching scope #23314

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously it expected two calls to getDataset.

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 || '',
);