mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AdHocFilters: Clean-up unused prop from type (#74960)
* AdHocFilters: Clean-up unused prop from type * Fix test
This commit is contained in:
parent
1386725251
commit
6a37a56d68
@ -48,7 +48,8 @@ export interface AdHocVariableFilter {
|
|||||||
key: string;
|
key: string;
|
||||||
operator: string;
|
operator: string;
|
||||||
value: string;
|
value: string;
|
||||||
condition: string;
|
/** @deprecated */
|
||||||
|
condition?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AdHocVariableModel extends BaseVariableModel {
|
export interface AdHocVariableModel extends BaseVariableModel {
|
||||||
|
@ -59,7 +59,6 @@ describe('adhoc actions', () => {
|
|||||||
key: 'filter-key',
|
key: 'filter-key',
|
||||||
value: 'filter-existing',
|
value: 'filter-existing',
|
||||||
operator: '!=',
|
operator: '!=',
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const variable = adHocBuilder()
|
const variable = adHocBuilder()
|
||||||
@ -76,7 +75,7 @@ describe('adhoc actions', () => {
|
|||||||
.whenAsyncActionIsDispatched(applyFilterFromTable(options), true);
|
.whenAsyncActionIsDispatched(applyFilterFromTable(options), true);
|
||||||
|
|
||||||
const expectedQuery = { 'var-Filters': ['filter-key|!=|filter-existing', 'filter-key|=|filter-value'] };
|
const expectedQuery = { 'var-Filters': ['filter-key|!=|filter-existing', 'filter-key|=|filter-value'] };
|
||||||
const expectedFilter = { key: 'filter-key', value: 'filter-value', operator: '=', condition: '' };
|
const expectedFilter = { key: 'filter-key', value: 'filter-value', operator: '=' };
|
||||||
|
|
||||||
tester.thenDispatchedActionsShouldEqual(
|
tester.thenDispatchedActionsShouldEqual(
|
||||||
toKeyedAction(key, filterAdded(toVariablePayload(variable, expectedFilter)))
|
toKeyedAction(key, filterAdded(toVariablePayload(variable, expectedFilter)))
|
||||||
@ -108,7 +107,7 @@ describe('adhoc actions', () => {
|
|||||||
.build();
|
.build();
|
||||||
|
|
||||||
const expectedQuery = { 'var-Filters': ['filter-key|=|filter-value'] };
|
const expectedQuery = { 'var-Filters': ['filter-key|=|filter-value'] };
|
||||||
const expectedFilter = { key: 'filter-key', value: 'filter-value', operator: '=', condition: '' };
|
const expectedFilter = { key: 'filter-key', value: 'filter-value', operator: '=' };
|
||||||
|
|
||||||
tester.thenDispatchedActionsShouldEqual(
|
tester.thenDispatchedActionsShouldEqual(
|
||||||
createAddVariableAction(variable),
|
createAddVariableAction(variable),
|
||||||
@ -142,7 +141,7 @@ describe('adhoc actions', () => {
|
|||||||
.whenActionIsDispatched(createAddVariableAction(variable))
|
.whenActionIsDispatched(createAddVariableAction(variable))
|
||||||
.whenAsyncActionIsDispatched(applyFilterFromTable(options), true);
|
.whenAsyncActionIsDispatched(applyFilterFromTable(options), true);
|
||||||
|
|
||||||
const expectedFilter = { key: 'filter-key', value: 'filter-value', operator: '=', condition: '' };
|
const expectedFilter = { key: 'filter-key', value: 'filter-value', operator: '=' };
|
||||||
const expectedQuery = { 'var-Filters': ['filter-key|=|filter-value'] };
|
const expectedQuery = { 'var-Filters': ['filter-key|=|filter-value'] };
|
||||||
|
|
||||||
tester.thenDispatchedActionsShouldEqual(
|
tester.thenDispatchedActionsShouldEqual(
|
||||||
@ -181,7 +180,7 @@ describe('adhoc actions', () => {
|
|||||||
.whenActionIsDispatched(createAddVariableAction(existing))
|
.whenActionIsDispatched(createAddVariableAction(existing))
|
||||||
.whenAsyncActionIsDispatched(applyFilterFromTable(options), true);
|
.whenAsyncActionIsDispatched(applyFilterFromTable(options), true);
|
||||||
|
|
||||||
const expectedFilter = { key: 'filter-key', value: 'filter-value', operator: '=', condition: '' };
|
const expectedFilter = { key: 'filter-key', value: 'filter-value', operator: '=' };
|
||||||
const expectedQuery = { 'var-elastic-filter': [] as string[], 'var-Filters': ['filter-key|=|filter-value'] };
|
const expectedQuery = { 'var-elastic-filter': [] as string[], 'var-Filters': ['filter-key|=|filter-value'] };
|
||||||
|
|
||||||
tester.thenDispatchedActionsShouldEqual(
|
tester.thenDispatchedActionsShouldEqual(
|
||||||
@ -200,7 +199,6 @@ describe('adhoc actions', () => {
|
|||||||
key: 'key',
|
key: 'key',
|
||||||
value: 'value',
|
value: 'value',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updated = {
|
const updated = {
|
||||||
@ -241,7 +239,6 @@ describe('adhoc actions', () => {
|
|||||||
key: 'key',
|
key: 'key',
|
||||||
value: 'value',
|
value: 'value',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const adding = {
|
const adding = {
|
||||||
@ -263,7 +260,7 @@ describe('adhoc actions', () => {
|
|||||||
.whenAsyncActionIsDispatched(addFilter(toKeyedVariableIdentifier(variable), adding), true);
|
.whenAsyncActionIsDispatched(addFilter(toKeyedVariableIdentifier(variable), adding), true);
|
||||||
|
|
||||||
const expectedQuery = { 'var-elastic-filter': ['key|=|value', 'key|!=|value'] };
|
const expectedQuery = { 'var-elastic-filter': ['key|=|value', 'key|!=|value'] };
|
||||||
const expectedFilter = { key: 'key', value: 'value', operator: '!=', condition: '' };
|
const expectedFilter = { key: 'key', value: 'value', operator: '!=' };
|
||||||
|
|
||||||
tester.thenDispatchedActionsShouldEqual(
|
tester.thenDispatchedActionsShouldEqual(
|
||||||
toKeyedAction(key, filterAdded(toVariablePayload(variable, expectedFilter)))
|
toKeyedAction(key, filterAdded(toVariablePayload(variable, expectedFilter)))
|
||||||
@ -279,7 +276,6 @@ describe('adhoc actions', () => {
|
|||||||
key: 'key',
|
key: 'key',
|
||||||
value: 'value',
|
value: 'value',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const variable = adHocBuilder()
|
const variable = adHocBuilder()
|
||||||
@ -332,7 +328,6 @@ describe('adhoc actions', () => {
|
|||||||
key: 'key',
|
key: 'key',
|
||||||
value: 'value',
|
value: 'value',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const variable = adHocBuilder()
|
const variable = adHocBuilder()
|
||||||
@ -362,7 +357,6 @@ describe('adhoc actions', () => {
|
|||||||
key: 'key',
|
key: 'key',
|
||||||
value: 'value',
|
value: 'value',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const variable = adHocBuilder()
|
const variable = adHocBuilder()
|
||||||
@ -373,21 +367,15 @@ describe('adhoc actions', () => {
|
|||||||
.withDatasource({ uid: 'elasticsearch' })
|
.withDatasource({ uid: 'elasticsearch' })
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
const fromUrl = [
|
const fromUrl = [{ ...existing, name: 'value-2' }];
|
||||||
{ ...existing, condition: '>' },
|
|
||||||
{ ...existing, name: 'value-2' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const tester = await reduxTester<RootReducerType>()
|
const tester = await reduxTester<RootReducerType>()
|
||||||
.givenRootReducer(getRootReducer())
|
.givenRootReducer(getRootReducer())
|
||||||
.whenActionIsDispatched(createAddVariableAction(variable))
|
.whenActionIsDispatched(createAddVariableAction(variable))
|
||||||
.whenAsyncActionIsDispatched(setFiltersFromUrl(toKeyedVariableIdentifier(variable), fromUrl), true);
|
.whenAsyncActionIsDispatched(setFiltersFromUrl(toKeyedVariableIdentifier(variable), fromUrl), true);
|
||||||
|
|
||||||
const expectedQuery = { 'var-elastic-filter': ['key|=|value', 'key|=|value'] };
|
const expectedQuery = { 'var-elastic-filter': ['key|=|value'] };
|
||||||
const expectedFilters = [
|
const expectedFilters = [{ key: 'key', value: 'value', operator: '=', name: 'value-2' }];
|
||||||
{ key: 'key', value: 'value', operator: '=', condition: '>' },
|
|
||||||
{ key: 'key', value: 'value', operator: '=', condition: '', name: 'value-2' },
|
|
||||||
];
|
|
||||||
|
|
||||||
tester.thenDispatchedActionsShouldEqual(
|
tester.thenDispatchedActionsShouldEqual(
|
||||||
toKeyedAction(key, filtersRestored(toVariablePayload(variable, expectedFilters)))
|
toKeyedAction(key, filtersRestored(toVariablePayload(variable, expectedFilters)))
|
||||||
|
@ -48,7 +48,7 @@ export const applyFilterFromTable = (options: AdHocTableOptions): ThunkResult<vo
|
|||||||
|
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
const { value, key, operator } = options;
|
const { value, key, operator } = options;
|
||||||
const filter = { value, key, operator, condition: '' };
|
const filter = { value, key, operator };
|
||||||
return await dispatch(addFilter(toKeyedVariableIdentifier(variable), filter));
|
return await dispatch(addFilter(toKeyedVariableIdentifier(variable), filter));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,13 +84,11 @@ function setup() {
|
|||||||
key: 'key1',
|
key: 'key1',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
value: 'val1',
|
value: 'val1',
|
||||||
condition: '',
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
key: 'key2',
|
key: 'key2',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
value: 'val2',
|
value: 'val2',
|
||||||
condition: '',
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const addFilter = jest.fn();
|
const addFilter = jest.fn();
|
||||||
|
@ -39,7 +39,6 @@ export const AdHocFilterBuilder = ({ datasource, appendBefore, onCompleted, allF
|
|||||||
onCompleted({
|
onCompleted({
|
||||||
value: item.value ?? '',
|
value: item.value ?? '',
|
||||||
operator: operator,
|
operator: operator,
|
||||||
condition: '',
|
|
||||||
key: key!,
|
key: key!,
|
||||||
});
|
});
|
||||||
setKey(null);
|
setKey(null);
|
||||||
@ -57,7 +56,7 @@ export const AdHocFilterBuilder = ({ datasource, appendBefore, onCompleted, allF
|
|||||||
{appendBefore}
|
{appendBefore}
|
||||||
<AdHocFilterRenderer
|
<AdHocFilterRenderer
|
||||||
datasource={datasource}
|
datasource={datasource}
|
||||||
filter={{ key, value: '', operator, condition: '' }}
|
filter={{ key, value: '', operator }}
|
||||||
placeHolder={t('variable.adhoc.placeholder', 'Select value')}
|
placeHolder={t('variable.adhoc.placeholder', 'Select value')}
|
||||||
onKeyChange={onKeyChanged}
|
onKeyChange={onKeyChanged}
|
||||||
onOperatorChange={onOperatorChanged}
|
onOperatorChange={onOperatorChanged}
|
||||||
|
@ -25,7 +25,7 @@ describe('adHocVariableReducer', () => {
|
|||||||
.thenStateShouldEqual({
|
.thenStateShouldEqual({
|
||||||
[id]: {
|
[id]: {
|
||||||
...initialState[id],
|
...initialState[id],
|
||||||
filters: [{ value: 'a', operator: '=', condition: '', key: 'a' }],
|
filters: [{ value: 'a', operator: '=', key: 'a' }],
|
||||||
} as AdHocVariableModel,
|
} as AdHocVariableModel,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -46,8 +46,8 @@ describe('adHocVariableReducer', () => {
|
|||||||
[id]: {
|
[id]: {
|
||||||
...initialState[id],
|
...initialState[id],
|
||||||
filters: [
|
filters: [
|
||||||
{ value: 'a', operator: '=', condition: '', key: 'a' },
|
{ value: 'a', operator: '=', key: 'a' },
|
||||||
{ value: 'b', operator: '=', condition: '', key: 'b' },
|
{ value: 'b', operator: '=', key: 'b' },
|
||||||
],
|
],
|
||||||
} as AdHocVariableModel,
|
} as AdHocVariableModel,
|
||||||
});
|
});
|
||||||
@ -69,7 +69,7 @@ describe('adHocVariableReducer', () => {
|
|||||||
.thenStateShouldEqual({
|
.thenStateShouldEqual({
|
||||||
[id]: {
|
[id]: {
|
||||||
...initialState[id],
|
...initialState[id],
|
||||||
filters: [{ value: 'a', operator: '=', condition: '', key: 'a' }],
|
filters: [{ value: 'a', operator: '=', key: 'a' }],
|
||||||
} as AdHocVariableModel,
|
} as AdHocVariableModel,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -90,7 +90,7 @@ describe('adHocVariableReducer', () => {
|
|||||||
.thenStateShouldEqual({
|
.thenStateShouldEqual({
|
||||||
[id]: {
|
[id]: {
|
||||||
...initialState[id],
|
...initialState[id],
|
||||||
filters: [{ value: 'b', operator: '=', condition: '', key: 'b' }],
|
filters: [{ value: 'b', operator: '=', key: 'b' }],
|
||||||
} as AdHocVariableModel,
|
} as AdHocVariableModel,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -133,8 +133,8 @@ describe('adHocVariableReducer', () => {
|
|||||||
[id]: {
|
[id]: {
|
||||||
...initialState[id],
|
...initialState[id],
|
||||||
filters: [
|
filters: [
|
||||||
{ value: 'b', operator: '=', condition: '', key: 'b' },
|
{ value: 'b', operator: '=', key: 'b' },
|
||||||
{ value: 'aa', operator: '=', condition: '', key: 'aa' },
|
{ value: 'aa', operator: '=', key: 'aa' },
|
||||||
],
|
],
|
||||||
} as AdHocVariableModel,
|
} as AdHocVariableModel,
|
||||||
});
|
});
|
||||||
@ -158,8 +158,8 @@ describe('adHocVariableReducer', () => {
|
|||||||
[id]: {
|
[id]: {
|
||||||
...initialState[id],
|
...initialState[id],
|
||||||
filters: [
|
filters: [
|
||||||
{ value: 'b', operator: '=', condition: '', key: 'b' },
|
{ value: 'b', operator: '=', key: 'b' },
|
||||||
{ value: 'aa', operator: '>', condition: '', key: 'aa' },
|
{ value: 'aa', operator: '>', key: 'aa' },
|
||||||
],
|
],
|
||||||
} as AdHocVariableModel,
|
} as AdHocVariableModel,
|
||||||
});
|
});
|
||||||
@ -181,8 +181,8 @@ describe('adHocVariableReducer', () => {
|
|||||||
[id]: {
|
[id]: {
|
||||||
...initialState[id],
|
...initialState[id],
|
||||||
filters: [
|
filters: [
|
||||||
{ value: 'aa', operator: '=', condition: '', key: 'aa' },
|
{ value: 'aa', operator: '=', key: 'aa' },
|
||||||
{ value: 'bb', operator: '=', condition: '', key: 'bb' },
|
{ value: 'bb', operator: '=', key: 'bb' },
|
||||||
],
|
],
|
||||||
} as AdHocVariableModel,
|
} as AdHocVariableModel,
|
||||||
});
|
});
|
||||||
@ -203,8 +203,8 @@ describe('adHocVariableReducer', () => {
|
|||||||
[id]: {
|
[id]: {
|
||||||
...initialState[id],
|
...initialState[id],
|
||||||
filters: [
|
filters: [
|
||||||
{ value: 'aa', operator: '=', condition: '', key: 'aa' },
|
{ value: 'aa', operator: '=', key: 'aa' },
|
||||||
{ value: 'bb', operator: '=', condition: '', key: 'bb' },
|
{ value: 'bb', operator: '=', key: 'bb' },
|
||||||
],
|
],
|
||||||
} as AdHocVariableModel,
|
} as AdHocVariableModel,
|
||||||
});
|
});
|
||||||
@ -216,7 +216,7 @@ function createFilter(value: string, operator = '='): AdHocVariableFilter {
|
|||||||
return {
|
return {
|
||||||
value,
|
value,
|
||||||
operator,
|
operator,
|
||||||
condition: '',
|
|
||||||
key: value,
|
key: value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,6 @@ describe('urlParser', () => {
|
|||||||
value: '',
|
value: '',
|
||||||
key: 'key',
|
key: 'key',
|
||||||
operator: '',
|
operator: '',
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const filters: AdHocVariableFilter[] = [a];
|
const filters: AdHocVariableFilter[] = [a];
|
||||||
@ -67,7 +66,6 @@ describe('urlParser', () => {
|
|||||||
value: undefined,
|
value: undefined,
|
||||||
key: 'key',
|
key: 'key',
|
||||||
operator: undefined,
|
operator: undefined,
|
||||||
condition: '',
|
|
||||||
} as unknown as AdHocVariableFilter;
|
} as unknown as AdHocVariableFilter;
|
||||||
|
|
||||||
const filters: AdHocVariableFilter[] = [a];
|
const filters: AdHocVariableFilter[] = [a];
|
||||||
@ -85,7 +83,6 @@ describe('urlParser', () => {
|
|||||||
value: 1974,
|
value: 1974,
|
||||||
key: 'key',
|
key: 'key',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
condition: '',
|
|
||||||
} as unknown as AdHocVariableFilter;
|
} as unknown as AdHocVariableFilter;
|
||||||
|
|
||||||
const filters: AdHocVariableFilter[] = [a];
|
const filters: AdHocVariableFilter[] = [a];
|
||||||
@ -103,7 +100,6 @@ describe('urlParser', () => {
|
|||||||
value: false,
|
value: false,
|
||||||
key: 'key',
|
key: 'key',
|
||||||
operator: '=',
|
operator: '=',
|
||||||
condition: '',
|
|
||||||
} as unknown as AdHocVariableFilter;
|
} as unknown as AdHocVariableFilter;
|
||||||
|
|
||||||
const filters: AdHocVariableFilter[] = [a];
|
const filters: AdHocVariableFilter[] = [a];
|
||||||
@ -171,7 +167,6 @@ describe('urlParser', () => {
|
|||||||
value: '',
|
value: '',
|
||||||
key: 'key',
|
key: 'key',
|
||||||
operator: '',
|
operator: '',
|
||||||
condition: '',
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -193,6 +188,5 @@ function createFilter(value: string, operator = '='): AdHocVariableFilter {
|
|||||||
value: `${value}-value`,
|
value: `${value}-value`,
|
||||||
key: `${value}-key`,
|
key: `${value}-key`,
|
||||||
operator: operator,
|
operator: operator,
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@ function toFilter(value: string | number | boolean | undefined | null): AdHocVar
|
|||||||
key: parts[0],
|
key: parts[0],
|
||||||
operator: parts[1],
|
operator: parts[1],
|
||||||
value: parts[2],
|
value: parts[2],
|
||||||
condition: '',
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user