Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SceneVariableSet: Allow propagation of variable changes through local variable #1030

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading