mirror of https://github.com/apache/superset.git
chore(native-filters): remove instant filtering option (#15365)
* chore(native-filters): remove instant filtering option * fix test
This commit is contained in:
parent
e5d4765986
commit
f286647140
|
@ -45,7 +45,6 @@ export const nativeFilters: NativeFiltersState = {
|
|||
rootPath: ['ROOT_ID'],
|
||||
excluded: [],
|
||||
},
|
||||
isInstant: true,
|
||||
controlValues: {
|
||||
multiSelect: false,
|
||||
enableEmptyFilter: false,
|
||||
|
@ -79,7 +78,6 @@ export const nativeFilters: NativeFiltersState = {
|
|||
enableEmptyFilter: false,
|
||||
inverseSelection: false,
|
||||
},
|
||||
isInstant: true,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
@ -136,7 +134,6 @@ export const singleNativeFiltersState = {
|
|||
cascadeParentIds: [],
|
||||
scope: { rootPath: ['ROOT_ID'], excluded: [227, 229] },
|
||||
inverseSelection: false,
|
||||
isInstant: true,
|
||||
allowsMultipleValues: false,
|
||||
isRequired: false,
|
||||
},
|
||||
|
|
|
@ -62,7 +62,6 @@ export const nativeFiltersInfo: NativeFiltersState = {
|
|||
rootPath: [],
|
||||
excluded: [],
|
||||
},
|
||||
isInstant: true,
|
||||
controlValues: {
|
||||
allowsMultipleValues: true,
|
||||
isRequired: false,
|
||||
|
|
|
@ -53,7 +53,7 @@ class MainPreset extends Preset {
|
|||
}
|
||||
}
|
||||
|
||||
fetchMock.get(`glob:*/api/v1/dataset/1`, {
|
||||
fetchMock.get('glob:*/api/v1/dataset/7', {
|
||||
description_columns: {},
|
||||
id: 1,
|
||||
label_columns: {
|
||||
|
@ -156,8 +156,7 @@ describe('FilterBar', () => {
|
|||
"defaultDataMask":{"filterState":{"value":null}},
|
||||
"controlValues":{},
|
||||
"cascadeParentIds":[],
|
||||
"scope":{"rootPath":["ROOT_ID"],"excluded":[]},
|
||||
"isInstant":false
|
||||
"scope":{"rootPath":["ROOT_ID"],"excluded":[]}
|
||||
}],
|
||||
"filter_sets_configuration":[{
|
||||
"name":"${FILTER_SET_NAME}",
|
||||
|
@ -168,17 +167,16 @@ describe('FilterBar', () => {
|
|||
"name":"${FILTER_NAME}",
|
||||
"filterType":"filter_time",
|
||||
"targets":[{}],
|
||||
"defaultDataMask":{"filterState":{"value":"Last week"},"extraFormData":{"time_range":"Last week"}},
|
||||
"defaultDataMask":{"filterState":{},"extraFormData":{}},
|
||||
"controlValues":{},
|
||||
"cascadeParentIds":[],
|
||||
"scope":{"rootPath":["ROOT_ID"],"excluded":[]},
|
||||
"isInstant":false
|
||||
"scope":{"rootPath":["ROOT_ID"],"excluded":[]}
|
||||
}
|
||||
},
|
||||
"dataMask":{
|
||||
"${filterId}":{
|
||||
"extraFormData":{"time_range":"Last week"},
|
||||
"filterState":{"value":"Last week"},
|
||||
"extraFormData":{},
|
||||
"filterState":{},
|
||||
"ownState":{},
|
||||
"id":"${filterId}"
|
||||
}
|
||||
|
@ -192,7 +190,14 @@ describe('FilterBar', () => {
|
|||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
fetchMock.get(
|
||||
'http://localhost/api/v1/time_range/?q=%27Last%20day%27',
|
||||
'glob:*/api/v1/time_range/?q=%27No%20filter%27',
|
||||
{
|
||||
result: { since: '', until: '', timeRange: 'No filter' },
|
||||
},
|
||||
{ overwriteRoutes: true },
|
||||
);
|
||||
fetchMock.get(
|
||||
'glob:*/api/v1/time_range/?q=%27Last%20day%27',
|
||||
{
|
||||
result: {
|
||||
since: '2021-04-13T00:00:00',
|
||||
|
@ -203,7 +208,7 @@ describe('FilterBar', () => {
|
|||
{ overwriteRoutes: true },
|
||||
);
|
||||
fetchMock.get(
|
||||
'http://localhost/api/v1/time_range/?q=%27Last%20week%27',
|
||||
'glob:*/api/v1/time_range/?q=%27Last%20week%27',
|
||||
{
|
||||
result: {
|
||||
since: '2021-04-07T00:00:00',
|
||||
|
|
|
@ -216,11 +216,10 @@ const FilterBar: React.FC<FiltersBarProps> = ({
|
|||
}
|
||||
// force instant updating on initialization for filters with `requiredFirst` is true or instant filters
|
||||
else if (
|
||||
(dataMaskSelected[filter.id] && filter.isInstant) ||
|
||||
// filterState.value === undefined - means that value not initialized
|
||||
(dataMask.filterState?.value !== undefined &&
|
||||
dataMaskSelected[filter.id]?.filterState?.value === undefined &&
|
||||
filter.requiredFirst)
|
||||
dataMask.filterState?.value !== undefined &&
|
||||
dataMaskSelected[filter.id]?.filterState?.value === undefined &&
|
||||
filter.requiredFirst
|
||||
) {
|
||||
dispatch(updateDataMask(filter.id, dataMask));
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ import React, {
|
|||
} from 'react';
|
||||
import { useSelector } from 'react-redux';
|
||||
import { FormItem } from 'src/components/Form';
|
||||
import { Checkbox, Input } from 'src/common/components';
|
||||
import { Input } from 'src/common/components';
|
||||
import { Select } from 'src/components/Select';
|
||||
import SupersetResourceSelect, {
|
||||
cachedSupersetGet,
|
||||
|
@ -816,16 +816,6 @@ const FiltersConfigForm = (
|
|||
{Object.keys(controlItems)
|
||||
.filter(key => BASIC_CONTROL_ITEMS.includes(key))
|
||||
.map(key => controlItems[key].element)}
|
||||
<StyledRowFormItem
|
||||
name={['filters', filterId, 'isInstant']}
|
||||
initialValue={filterToEdit?.isInstant || false}
|
||||
valuePropName="checked"
|
||||
colon={false}
|
||||
>
|
||||
<Checkbox data-test="apply-changes-instantly-checkbox">
|
||||
{t('Apply changes instantly')}
|
||||
</Checkbox>
|
||||
</StyledRowFormItem>
|
||||
</Collapse.Panel>
|
||||
{((hasDataset && hasAdditionalFilters) || hasMetrics) && (
|
||||
<Collapse.Panel
|
||||
|
|
|
@ -51,7 +51,6 @@ const formMock: FormInstance = {
|
|||
const filterMock: Filter = {
|
||||
cascadeParentIds: [],
|
||||
defaultDataMask: {},
|
||||
isInstant: false,
|
||||
id: 'mock',
|
||||
name: 'mock',
|
||||
scope: {
|
||||
|
|
|
@ -112,7 +112,6 @@ const ADVANCED_REGEX = /^advanced$/i;
|
|||
const DEFAULT_VALUE_REGEX = /^filter has default value$/i;
|
||||
const MULTIPLE_REGEX = /^multiple select$/i;
|
||||
const REQUIRED_REGEX = /^required$/i;
|
||||
const APPLY_INSTANTLY_REGEX = /^apply changes instantly$/i;
|
||||
const HIERARCHICAL_REGEX = /^filter is hierarchical$/i;
|
||||
const FIRST_ITEM_REGEX = /^default to first item$/i;
|
||||
const INVERSE_SELECTION_REGEX = /^inverse selection$/i;
|
||||
|
@ -169,7 +168,6 @@ test('renders a value filter type', () => {
|
|||
|
||||
expect(getCheckbox(DEFAULT_VALUE_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(REQUIRED_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(APPLY_INSTANTLY_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(HIERARCHICAL_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(FIRST_ITEM_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(INVERSE_SELECTION_REGEX)).not.toBeChecked();
|
||||
|
@ -194,7 +192,6 @@ test('renders a numerical range filter type', () => {
|
|||
expect(screen.getByText(REQUIRED_REGEX)).toBeInTheDocument();
|
||||
|
||||
expect(getCheckbox(DEFAULT_VALUE_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(APPLY_INSTANTLY_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(PRE_FILTER_REGEX)).not.toBeChecked();
|
||||
|
||||
expect(queryCheckbox(MULTIPLE_REGEX)).not.toBeInTheDocument();
|
||||
|
@ -217,7 +214,6 @@ test('renders a time range filter type', () => {
|
|||
expect(screen.queryByText(COLUMN_REGEX)).not.toBeInTheDocument();
|
||||
|
||||
expect(getCheckbox(DEFAULT_VALUE_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(APPLY_INSTANTLY_REGEX)).not.toBeChecked();
|
||||
|
||||
expect(screen.queryByText(ADVANCED_REGEX)).not.toBeInTheDocument();
|
||||
});
|
||||
|
@ -234,7 +230,6 @@ test('renders a time column filter type', () => {
|
|||
expect(screen.queryByText(COLUMN_REGEX)).not.toBeInTheDocument();
|
||||
|
||||
expect(getCheckbox(DEFAULT_VALUE_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(APPLY_INSTANTLY_REGEX)).not.toBeChecked();
|
||||
|
||||
expect(screen.queryByText(ADVANCED_REGEX)).not.toBeInTheDocument();
|
||||
});
|
||||
|
@ -251,7 +246,6 @@ test('renders a time grain filter type', () => {
|
|||
expect(screen.queryByText(COLUMN_REGEX)).not.toBeInTheDocument();
|
||||
|
||||
expect(getCheckbox(DEFAULT_VALUE_REGEX)).not.toBeChecked();
|
||||
expect(getCheckbox(APPLY_INSTANTLY_REGEX)).not.toBeChecked();
|
||||
|
||||
expect(screen.queryByText(ADVANCED_REGEX)).not.toBeInTheDocument();
|
||||
});
|
||||
|
|
|
@ -41,7 +41,6 @@ export interface NativeFiltersFormItem {
|
|||
label: string;
|
||||
};
|
||||
sortMetric: string | null;
|
||||
isInstant: boolean;
|
||||
adhoc_filters?: AdhocFilter[];
|
||||
time_range?: string;
|
||||
granularity_sqla?: string;
|
||||
|
|
|
@ -56,18 +56,6 @@ export const validateForm = async (
|
|||
throw error;
|
||||
}
|
||||
}
|
||||
const validateInstant = (filterId: string) => {
|
||||
const isInstant = formValues.filters[filterId]
|
||||
? formValues.filters[filterId].isInstant
|
||||
: filterConfigMap[filterId]?.isInstant;
|
||||
if (!isInstant) {
|
||||
addValidationError(
|
||||
filterId,
|
||||
'isInstant',
|
||||
'For hierarchical filters changes must be applied instantly',
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
const validateCycles = (filterId: string, trace: string[] = []) => {
|
||||
if (trace.includes(filterId)) {
|
||||
|
@ -81,7 +69,6 @@ export const validateForm = async (
|
|||
? formValues.filters[filterId].parentFilter?.value
|
||||
: filterConfigMap[filterId]?.cascadeParentIds?.[0];
|
||||
if (parentId) {
|
||||
validateInstant(parentId);
|
||||
validateCycles(parentId, [...trace, filterId]);
|
||||
}
|
||||
};
|
||||
|
@ -153,7 +140,6 @@ export const createHandleSave = (
|
|||
? [formInputs.parentFilter.value]
|
||||
: [],
|
||||
scope: formInputs.scope,
|
||||
isInstant: formInputs.isInstant,
|
||||
sortMetric: formInputs.sortMetric,
|
||||
};
|
||||
});
|
||||
|
|
|
@ -42,7 +42,6 @@ export interface Target {
|
|||
export interface Filter {
|
||||
cascadeParentIds: string[];
|
||||
defaultDataMask: DataMask;
|
||||
isInstant: boolean;
|
||||
id: string; // randomly generated at filter creation
|
||||
name: string;
|
||||
scope: Scope;
|
||||
|
|
Loading…
Reference in New Issue