Skip to content

Commit

Permalink
SceneVariableSet: Allow propagation of variable changes through local…
Browse files Browse the repository at this point in the history
… variable (#1030)
  • Loading branch information
torkelo authored Jan 28, 2025
1 parent f5d08aa commit 9e55654
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 4 additions & 3 deletions packages/scenes/src/variables/sets/SceneVariableSet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ describe('SceneVariableList', () => {
expect(B.state.loading).toBe(true);
});

describe('When local value overrides parent variable changes on top level should not propagate', () => {
it('When local value overrides parent variable changes on top level should propagate', () => {
const topLevelVar = new TestVariable({
name: 'test',
options: [],
Expand All @@ -832,10 +832,11 @@ describe('SceneVariableList', () => {

activateFullSceneTree(scene);

nestedScene.doSomethingThatRequiresVariables();
topLevelVar.changeValueTo('E');

expect(nestedScene.state.didSomethingCount).toBe(0);
expect(nestedScene.state.variableValueChanged).toBe(0);
expect(nestedScene.state.didSomethingCount).toBe(2);
expect(nestedScene.state.variableValueChanged).toBe(1);
});
});

Expand Down
5 changes: 4 additions & 1 deletion packages/scenes/src/variables/sets/SceneVariableSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ export class SceneVariableSet extends SceneObjectBase<SceneVariableSetState> imp
// If we find a nested SceneVariableSet that has a variable with the same name we stop the traversal
if (sceneObject.state.$variables && sceneObject.state.$variables !== this) {
const localVar = sceneObject.state.$variables.getByName(variable.state.name);
if (localVar) {
// If local variable is viewed as loading when ancestor is loading we propagate a change
if (localVar?.isAncestorLoading) {
variable = localVar;
} else if (localVar) {
return;
}
}
Expand Down

0 comments on commit 9e55654

Please sign in to comment.