grafana/public/app/features/live/pages/utils.ts

32 lines
977 B
TypeScript
Raw Normal View History

2021-09-30 15:37:31 -05:00
import { getBackendSrv } from '@grafana/runtime';
2021-10-19 02:50:17 -05:00
import { PipelineListOption, PipeLineEntitiesInfo } from './types';
2021-09-30 15:37:31 -05:00
export async function getPipeLineEntities(): Promise<PipeLineEntitiesInfo> {
return await getBackendSrv()
.get(`api/live/pipeline-entities`)
.then((data) => {
return {
converter: transformLabel(data, 'converters'),
2021-10-06 14:55:54 -05:00
frameProcessors: transformLabel(data, 'frameProcessors'),
frameOutputs: transformLabel(data, 'frameOutputs'),
2021-09-30 15:37:31 -05:00
getExample: (ruleType, type) => {
return data[`${ruleType}s`]?.filter((option: PipelineListOption) => option.type === type)?.[0]?.['example'];
},
};
});
}
2021-10-19 02:50:17 -05:00
export function transformLabel(data: any, key: keyof typeof data) {
if (Array.isArray(data)) {
return data.map((d) => ({
label: d[key],
value: d[key],
}));
}
2021-09-30 15:37:31 -05:00
return data[key].map((typeObj: PipelineListOption) => ({
label: typeObj.type,
value: typeObj.type,
}));
}