@grafana/scenes 6.13.0--canary.1122.15186594626.0 → 6.14.0--canary.1130.15248914373.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
@@ -1,3 +1,15 @@
|
|
1
|
+
# v6.13.0 (Thu May 22 2025)
|
2
|
+
|
3
|
+
#### 🚀 Enhancement
|
4
|
+
|
5
|
+
- GroupByVariable: Add support for default values [#1122](https://github.com/grafana/scenes/pull/1122) ([@mdvictor](https://github.com/mdvictor))
|
6
|
+
|
7
|
+
#### Authors: 1
|
8
|
+
|
9
|
+
- Victor Marin ([@mdvictor](https://github.com/mdvictor))
|
10
|
+
|
11
|
+
---
|
12
|
+
|
1
13
|
# v6.12.0 (Fri May 16 2025)
|
2
14
|
|
3
15
|
### Release Notes
|
@@ -4,6 +4,7 @@ import { ScopesContext } from '@grafana/runtime';
|
|
4
4
|
import { useContext, useEffect } from 'react';
|
5
5
|
import { VariableHide, VariableFormatID } from '@grafana/schema';
|
6
6
|
import { SCOPES_VARIABLE_NAME } from '../constants.js';
|
7
|
+
import { isEqual } from 'lodash';
|
7
8
|
|
8
9
|
class ScopesVariable extends SceneObjectBase {
|
9
10
|
constructor(state) {
|
@@ -57,8 +58,9 @@ class ScopesVariable extends SceneObjectBase {
|
|
57
58
|
}
|
58
59
|
updateStateFromContext(state) {
|
59
60
|
const loading = state.value.length === 0 ? false : state.loading;
|
61
|
+
const oldValue = this.state.scopes;
|
60
62
|
this.setState({ scopes: state.value, loading });
|
61
|
-
if (!loading) {
|
63
|
+
if (!loading && !isEqual(oldValue, state.value)) {
|
62
64
|
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
63
65
|
}
|
64
66
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"ScopesVariable.js","sources":["../../../../src/variables/variants/ScopesVariable.tsx"],"sourcesContent":["import { SceneObjectBase } from '../../core/SceneObjectBase';\nimport {\n CustomVariableValue,\n SceneVariable,\n SceneVariableState,\n SceneVariableValueChangedEvent,\n VariableValue,\n} from '../types';\nimport { Scope } from '@grafana/data';\nimport { SceneComponentProps } from '../../core/types';\nimport { ScopesContext, ScopesContextValue } from '@grafana/runtime';\nimport { useContext, useEffect } from 'react';\nimport { VariableFormatID, VariableHide } from '@grafana/schema';\nimport { SCOPES_VARIABLE_NAME } from '../constants';\n\nexport interface ScopesVariableState extends SceneVariableState {\n /**\n * Last captured state from ScopesContext\n */\n scopes: Scope[];\n /**\n * Set to true if you want to the variable to enable / disable scopes when activated / deactivated\n */\n enable?: boolean;\n}\n\nexport class ScopesVariable extends SceneObjectBase<ScopesVariableState> implements SceneVariable<ScopesVariableState> {\n protected _renderBeforeActivation = true;\n protected _context: ScopesContextValue | undefined;\n\n // Special options that enables variables to be hidden but still render to access react contexts\n public UNSAFE_renderAsHidden = true;\n public static Component = ScopesVariableRenderer;\n\n public constructor(state: Partial<ScopesVariableState>) {\n super({\n skipUrlSync: true,\n loading: true,\n scopes: [],\n ...state,\n type: 'system',\n name: SCOPES_VARIABLE_NAME,\n hide: VariableHide.hideVariable,\n });\n }\n\n /**\n * Temporary simple implementation to stringify the scopes.\n */\n public getValue(): VariableValue {\n const scopes = this.state.scopes ?? [];\n return new ScopesVariableFormatter(scopes.map((scope) => scope.metadata.name));\n }\n\n public getScopes(): Scope[] | undefined {\n return this.state.scopes;\n }\n\n /**\n * This method is used to keep the context up to date with the scopes context received from React\n * 1) Subscribes to ScopesContext state changes and synchronizes it with the variable state\n * 2) Handles enable / disabling of scopes based on variable enable option.\n */\n public setContext(context: ScopesContextValue | undefined) {\n if (!context) {\n return;\n }\n\n this._context = context;\n\n const oldState = context.state;\n\n // Update scopes enable state if state.enable is defined\n if (this.state.enable != null) {\n context.setEnabled(this.state.enable);\n }\n\n // Subscribe to context state changes\n const sub = context.stateObservable.subscribe((state) => {\n this.updateStateFromContext(state);\n });\n\n return () => {\n sub.unsubscribe();\n\n if (this.state.enable != null) {\n context.setEnabled(oldState.enabled);\n }\n };\n }\n\n public updateStateFromContext(state: { loading: boolean; value: Scope[] }) {\n // There was logic in SceneQueryRunner that said if there are no scopes then loading state should not block query execution\n const loading = state.value.length === 0 ? false : state.loading;\n this.setState({ scopes: state.value, loading });\n\n if (!loading) {\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n }\n}\n\nfunction ScopesVariableRenderer({ model }: SceneComponentProps<ScopesVariable>) {\n const context = useContext(ScopesContext);\n\n useEffect(() => {\n return model.setContext(context);\n }, [context, model]);\n\n return null;\n}\n\nexport class ScopesVariableFormatter implements CustomVariableValue {\n public constructor(private _value: string[]) {}\n\n public formatter(formatNameOrFn?: string): string {\n if (formatNameOrFn === VariableFormatID.QueryParam) {\n return this._value.map((scope) => `scope=${encodeURIComponent(scope)}`).join('&');\n }\n\n return this._value.join(', ');\n }\n}\n"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"ScopesVariable.js","sources":["../../../../src/variables/variants/ScopesVariable.tsx"],"sourcesContent":["import { SceneObjectBase } from '../../core/SceneObjectBase';\nimport {\n CustomVariableValue,\n SceneVariable,\n SceneVariableState,\n SceneVariableValueChangedEvent,\n VariableValue,\n} from '../types';\nimport { Scope } from '@grafana/data';\nimport { SceneComponentProps } from '../../core/types';\nimport { ScopesContext, ScopesContextValue } from '@grafana/runtime';\nimport { useContext, useEffect } from 'react';\nimport { VariableFormatID, VariableHide } from '@grafana/schema';\nimport { SCOPES_VARIABLE_NAME } from '../constants';\nimport { isEqual } from 'lodash';\n\nexport interface ScopesVariableState extends SceneVariableState {\n /**\n * Last captured state from ScopesContext\n */\n scopes: Scope[];\n /**\n * Set to true if you want to the variable to enable / disable scopes when activated / deactivated\n */\n enable?: boolean;\n}\n\nexport class ScopesVariable extends SceneObjectBase<ScopesVariableState> implements SceneVariable<ScopesVariableState> {\n protected _renderBeforeActivation = true;\n protected _context: ScopesContextValue | undefined;\n\n // Special options that enables variables to be hidden but still render to access react contexts\n public UNSAFE_renderAsHidden = true;\n public static Component = ScopesVariableRenderer;\n\n public constructor(state: Partial<ScopesVariableState>) {\n super({\n skipUrlSync: true,\n loading: true,\n scopes: [],\n ...state,\n type: 'system',\n name: SCOPES_VARIABLE_NAME,\n hide: VariableHide.hideVariable,\n });\n }\n\n /**\n * Temporary simple implementation to stringify the scopes.\n */\n public getValue(): VariableValue {\n const scopes = this.state.scopes ?? [];\n return new ScopesVariableFormatter(scopes.map((scope) => scope.metadata.name));\n }\n\n public getScopes(): Scope[] | undefined {\n return this.state.scopes;\n }\n\n /**\n * This method is used to keep the context up to date with the scopes context received from React\n * 1) Subscribes to ScopesContext state changes and synchronizes it with the variable state\n * 2) Handles enable / disabling of scopes based on variable enable option.\n */\n public setContext(context: ScopesContextValue | undefined) {\n if (!context) {\n return;\n }\n\n this._context = context;\n\n const oldState = context.state;\n\n // Update scopes enable state if state.enable is defined\n if (this.state.enable != null) {\n context.setEnabled(this.state.enable);\n }\n\n // Subscribe to context state changes\n const sub = context.stateObservable.subscribe((state) => {\n this.updateStateFromContext(state);\n });\n\n return () => {\n sub.unsubscribe();\n\n if (this.state.enable != null) {\n context.setEnabled(oldState.enabled);\n }\n };\n }\n\n public updateStateFromContext(state: { loading: boolean; value: Scope[] }) {\n // There was logic in SceneQueryRunner that said if there are no scopes then loading state should not block query execution\n const loading = state.value.length === 0 ? false : state.loading;\n const oldValue = this.state.scopes;\n\n this.setState({ scopes: state.value, loading });\n\n if (!loading && !isEqual(oldValue, state.value)) {\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n }\n}\n\nfunction ScopesVariableRenderer({ model }: SceneComponentProps<ScopesVariable>) {\n const context = useContext(ScopesContext);\n\n useEffect(() => {\n return model.setContext(context);\n }, [context, model]);\n\n return null;\n}\n\nexport class ScopesVariableFormatter implements CustomVariableValue {\n public constructor(private _value: string[]) {}\n\n public formatter(formatNameOrFn?: string): string {\n if (formatNameOrFn === VariableFormatID.QueryParam) {\n return this._value.map((scope) => `scope=${encode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A;AAChD,IAAI,IAAA,cAAA,KAAmB,iBAAiB,UAAY,EAAA;AAClD,MAAA,OAAO,IAAK,CAAA,MAAA,CAAO,GAAI,CAAA,CAAC,KAAU,KAAA,CAAA,MAAA,EAAS,kBAAmB,CAAA,KAAK,CAAC,CAAA,CAAE,CAAE,CAAA,IAAA,CAAK,GAAG,CAAA;AAAA;AAGlF,IAAO,OAAA,IAAA,CAAK,MAAO,CAAA,IAAA,CAAK,IAAI,CAAA;AAAA;AAEhC;;;;"}
|
package/dist/index.js
CHANGED
@@ -7289,8 +7289,9 @@ class ScopesVariable extends SceneObjectBase {
|
|
7289
7289
|
}
|
7290
7290
|
updateStateFromContext(state) {
|
7291
7291
|
const loading = state.value.length === 0 ? false : state.loading;
|
7292
|
+
const oldValue = this.state.scopes;
|
7292
7293
|
this.setState({ scopes: state.value, loading });
|
7293
|
-
if (!loading) {
|
7294
|
+
if (!loading && !lodash.isEqual(oldValue, state.value)) {
|
7294
7295
|
this.publishEvent(new SceneVariableValueChangedEvent(this), true);
|
7295
7296
|
}
|
7296
7297
|
}
|