mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Scenes: Add support for viewing variable dependency graph in settings * Fix failing e2e test * Add test for createDependencyNodes/Edges * Refactor for better separation between old architecture and scenes * Add internationalization * run maker --------- Co-authored-by: Ivan Ortega <ivanortegaalba@gmail.com>
29 lines
1.0 KiB
TypeScript
29 lines
1.0 KiB
TypeScript
import { SceneVariable, SceneVariableState } from '@grafana/scenes';
|
|
import { GraphEdge, GraphNode } from 'app/features/variables/inspect/utils';
|
|
|
|
export function createDependencyNodes(variables: Array<SceneVariable<SceneVariableState>>): GraphNode[] {
|
|
return variables.map((variable) => ({ id: variable.state.name, label: `${variable.state.name}` }));
|
|
}
|
|
|
|
export function filterNodesWithDependencies(nodes: GraphNode[], edges: GraphEdge[]): GraphNode[] {
|
|
return nodes.filter((node) => edges.some((edge) => edge.from === node.id || edge.to === node.id));
|
|
}
|
|
|
|
export const createDependencyEdges = (variables: Array<SceneVariable<SceneVariableState>>): GraphEdge[] => {
|
|
const edges: GraphEdge[] = [];
|
|
for (const variable of variables) {
|
|
for (const other of variables) {
|
|
if (variable === other) {
|
|
continue;
|
|
}
|
|
|
|
const dependsOn = variable.variableDependency?.hasDependencyOn(other.state.name);
|
|
if (dependsOn) {
|
|
edges.push({ from: variable.state.name, to: other.state.name });
|
|
}
|
|
}
|
|
}
|
|
|
|
return edges;
|
|
};
|