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