grafana/public/app/features/variables/guard.ts
Marcus Andersson ac7af7d4c3
TemplateVariables: make sure we handle multi/single value with correct data type (#23208)
* Fixed issue with multi value.

* Made some refactorings after feedback from Torkel and Hugo.

* minor refactorings.

* changed so we don't make the current value to array if multi is false.

* added snapshot to contain v23.

* Fixed so we always use the correct type when setting value for multi/non-multi.

* added some more tests.

* added tests.

* some small adjustments after feedback
2020-04-01 18:13:38 +02:00

15 lines
582 B
TypeScript

import { QueryVariableModel, VariableModel, AdHocVariableModel, VariableWithMultiSupport } from '../templating/types';
export const isQuery = (model: VariableModel): model is QueryVariableModel => {
return model.type === 'query';
};
export const isAdHoc = (model: VariableModel): model is AdHocVariableModel => {
return model.type === 'adhoc';
};
export const isMulti = (model: VariableModel): model is VariableWithMultiSupport => {
const withMulti = model as VariableWithMultiSupport;
return withMulti.hasOwnProperty('multi') && typeof withMulti.multi === 'boolean';
};