optionsVariableBuilder.ts 899 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { VariableOption, VariableWithOptions } from 'app/features/variables/types';
  2. import { VariableBuilder } from './variableBuilder';
  3. export class OptionsVariableBuilder<T extends VariableWithOptions> extends VariableBuilder<T> {
  4. withOptions(...texts: string[]) {
  5. this.variable.options = [];
  6. for (let index = 0; index < texts.length; index++) {
  7. this.variable.options.push({
  8. text: texts[index],
  9. value: texts[index],
  10. selected: false,
  11. });
  12. }
  13. return this;
  14. }
  15. withoutOptions() {
  16. this.variable.options = undefined as unknown as VariableOption[];
  17. return this;
  18. }
  19. withCurrent(text: string | string[], value?: string | string[]) {
  20. this.variable.current = {
  21. text,
  22. value: value ?? text,
  23. selected: true,
  24. };
  25. return this;
  26. }
  27. withQuery(query: any) {
  28. this.variable.query = query;
  29. return this;
  30. }
  31. }