utils.ts 977 B

12345678910111213141516171819202122232425262728293031
  1. import { getBackendSrv } from '@grafana/runtime';
  2. import { PipelineListOption, PipeLineEntitiesInfo } from './types';
  3. export async function getPipeLineEntities(): Promise<PipeLineEntitiesInfo> {
  4. return await getBackendSrv()
  5. .get(`api/live/pipeline-entities`)
  6. .then((data) => {
  7. return {
  8. converter: transformLabel(data, 'converters'),
  9. frameProcessors: transformLabel(data, 'frameProcessors'),
  10. frameOutputs: transformLabel(data, 'frameOutputs'),
  11. getExample: (ruleType, type) => {
  12. return data[`${ruleType}s`]?.filter((option: PipelineListOption) => option.type === type)?.[0]?.['example'];
  13. },
  14. };
  15. });
  16. }
  17. export function transformLabel(data: any, key: keyof typeof data) {
  18. if (Array.isArray(data)) {
  19. return data.map((d) => ({
  20. label: d[key],
  21. value: d[key],
  22. }));
  23. }
  24. return data[key].map((typeObj: PipelineListOption) => ({
  25. label: typeObj.type,
  26. value: typeObj.type,
  27. }));
  28. }