|
|
|
@ -6,7 +6,6 @@ import { |
|
|
|
|
VizPanel, |
|
|
|
|
SceneObjectBase, |
|
|
|
|
VariableDependencyConfig, |
|
|
|
|
SceneVariable, |
|
|
|
|
SceneGridLayout, |
|
|
|
|
SceneVariableSet, |
|
|
|
|
SceneComponentProps, |
|
|
|
@ -36,11 +35,9 @@ export type RepeatDirection = 'v' | 'h'; |
|
|
|
|
export class PanelRepeaterGridItem extends SceneObjectBase<PanelRepeaterGridItemState> implements SceneGridItemLike { |
|
|
|
|
protected _variableDependency = new VariableDependencyConfig(this, { |
|
|
|
|
variableNames: [this.state.variableName], |
|
|
|
|
onVariableUpdatesCompleted: this._onVariableChanged.bind(this), |
|
|
|
|
onVariableUpdateCompleted: this._onVariableUpdateCompleted.bind(this), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
private _isWaitingForVariables = false; |
|
|
|
|
|
|
|
|
|
public constructor(state: PanelRepeaterGridItemState) { |
|
|
|
|
super(state); |
|
|
|
|
|
|
|
|
@ -49,26 +46,11 @@ export class PanelRepeaterGridItem extends SceneObjectBase<PanelRepeaterGridItem |
|
|
|
|
|
|
|
|
|
private _activationHandler() { |
|
|
|
|
this._subs.add(this.subscribeToState((newState, prevState) => this._handleGridResize(newState, prevState))); |
|
|
|
|
|
|
|
|
|
// If we our variable is ready we can process repeats on activation
|
|
|
|
|
if (sceneGraph.hasVariableDependencyInLoadingState(this)) { |
|
|
|
|
this._isWaitingForVariables = true; |
|
|
|
|
} else { |
|
|
|
|
this._performRepeat(); |
|
|
|
|
} |
|
|
|
|
this._performRepeat(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private _onVariableChanged(changedVariables: Set<SceneVariable>, dependencyChanged: boolean): void { |
|
|
|
|
if (dependencyChanged) { |
|
|
|
|
this._performRepeat(); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// If we are waiting for variables and the variable is no longer loading then we are ready to repeat as well
|
|
|
|
|
if (this._isWaitingForVariables && !sceneGraph.hasVariableDependencyInLoadingState(this)) { |
|
|
|
|
this._isWaitingForVariables = false; |
|
|
|
|
this._performRepeat(); |
|
|
|
|
} |
|
|
|
|
private _onVariableUpdateCompleted(): void { |
|
|
|
|
this._performRepeat(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -97,6 +79,10 @@ export class PanelRepeaterGridItem extends SceneObjectBase<PanelRepeaterGridItem |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private _performRepeat() { |
|
|
|
|
if (this._variableDependency.hasDependencyInLoadingState()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const variable = sceneGraph.lookupVariable(this.state.variableName, this); |
|
|
|
|
if (!variable) { |
|
|
|
|
console.error('SceneGridItemRepeater: Variable not found'); |
|
|
|
|