grafana/public/app/features/trails/ActionTabs/utils.ts
Darren Janeczek 810c224039
datatrails: synchronize the range of the y axis for all breakdown panels (#84781)
feat: sync the yaxis of breakdown panels
2024-03-22 16:19:11 -04:00

47 lines
1.4 KiB
TypeScript

import { SelectableValue } from '@grafana/data';
import { AdHocFiltersVariable, QueryVariable, sceneGraph, SceneObject } from '@grafana/scenes';
import { VAR_FILTERS } from '../shared';
export function getLabelOptions(scenObject: SceneObject, variable: QueryVariable) {
const labelFilters = sceneGraph.lookupVariable(VAR_FILTERS, scenObject);
const labelOptions: Array<SelectableValue<string>> = [];
if (!(labelFilters instanceof AdHocFiltersVariable)) {
return [];
}
const filters = labelFilters.state.filters;
for (const option of variable.getOptionsForSelect()) {
const filterExists = filters.find((f) => f.key === option.value);
if (!filterExists) {
labelOptions.push({ label: option.label, value: String(option.value) });
}
}
return labelOptions;
}
interface Type<T> extends Function {
new (...args: any[]): T;
}
export function findSceneObjectByType<T extends SceneObject>(scene: SceneObject, sceneType: Type<T>) {
const targetScene = sceneGraph.findObject(scene, (obj) => obj instanceof sceneType);
if (targetScene instanceof sceneType) {
return targetScene;
}
return null;
}
export function findSceneObjectsByType<T extends SceneObject>(scene: SceneObject, sceneType: Type<T>) {
function isSceneType(scene: SceneObject): scene is T {
return scene instanceof sceneType;
}
const targetScenes = sceneGraph.findAllObjects(scene, isSceneType);
return targetScenes.filter(isSceneType);
}