Files
grafana/public/app/features/variables/shared/testing/optionsVariableBuilder.ts
kay delaney cadc551a3c Chore: Remove deprecated re-exported template variable types (#87459)
Chore: Remove deprecated re-exported template varible types
2024-05-10 12:00:41 +01:00

43 lines
1.1 KiB
TypeScript

import { VariableOption, VariableWithOptions } from '@grafana/data';
import { VariableBuilder } from './variableBuilder';
export class OptionsVariableBuilder<T extends VariableWithOptions> extends VariableBuilder<T> {
withOptions(...options: Array<string | { text: string; value: string }>) {
this.variable.options = [];
for (let index = 0; index < options.length; index++) {
const option = options[index];
if (typeof option === 'string') {
this.variable.options.push({
text: option,
value: option,
selected: false,
});
} else {
this.variable.options.push({ ...option, selected: false });
}
}
return this;
}
withoutOptions() {
this.variable.options = undefined as unknown as VariableOption[];
return this;
}
withCurrent(text: string | string[], value?: string | string[]) {
this.variable.current = {
text,
value: value ?? text,
selected: true,
};
return this;
}
withQuery(query: string) {
this.variable.query = query;
return this;
}
}