@grafana/scenes 6.39.2--canary.1258.18314715919.0 → 6.39.2--canary.1264.18315947032.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/scenes",
3
- "version": "6.39.2--canary.1258.18314715919.0",
3
+ "version": "6.39.2--canary.1264.18315947032.0",
4
4
  "description": "Grafana framework for building dynamic dashboards",
5
5
  "author": "Grafana Labs",
6
6
  "license": "Apache-2.0",
@@ -125,5 +125,5 @@
125
125
  "prettier --write"
126
126
  ]
127
127
  },
128
- "gitHead": "83e7917d91c5433dcf86ab3701d0b2fbcc394f34"
128
+ "gitHead": "dde9ef453c7f6ea0c1717f0fc932861f35eadd89"
129
129
  }
@@ -1,108 +0,0 @@
1
- import React from 'react';
2
- import { of } from 'rxjs';
3
- import { useStyles2, Switch } from '@grafana/ui';
4
- import { css } from '@emotion/css';
5
- import { SceneObjectBase } from '../../core/SceneObjectBase.js';
6
- import { SceneObjectUrlSyncConfig } from '../../services/SceneObjectUrlSyncConfig.js';
7
- import { SceneVariableValueChangedEvent } from '../types.js';
8
-
9
- class SwitchVariable extends SceneObjectBase {
10
- constructor(initialState) {
11
- super({
12
- // TODO: remove this once switch is in the schema @leventebalogh
13
- // @ts-expect-error - switch is a valid variable type, but not in the schema yet
14
- type: "switch",
15
- value: "false",
16
- enabledValue: "true",
17
- disabledValue: "false",
18
- name: "",
19
- ...initialState
20
- });
21
- this._prevValue = "";
22
- this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: () => this.getKeys() });
23
- }
24
- /**
25
- * This function is called on when SceneVariableSet is activated or when a dependency changes.
26
- */
27
- validateAndUpdate() {
28
- const newValue = this.getValue();
29
- if (this._prevValue !== newValue) {
30
- this._prevValue = newValue;
31
- this.publishEvent(new SceneVariableValueChangedEvent(this), true);
32
- }
33
- return of({});
34
- }
35
- setValue(newValue) {
36
- if (this.getValue() === newValue) {
37
- return;
38
- }
39
- if ([this.state.enabledValue, this.state.disabledValue].includes(newValue)) {
40
- this.setState({ value: newValue });
41
- this.publishEvent(new SceneVariableValueChangedEvent(this), true);
42
- } else {
43
- console.error(
44
- `Invalid value for switch variable: "${newValue}". Valid values are: "${this.state.enabledValue}" and "${this.state.disabledValue}".`
45
- );
46
- }
47
- }
48
- getValue() {
49
- return this.state.value;
50
- }
51
- isEnabled() {
52
- return this.state.value === this.state.enabledValue;
53
- }
54
- isDisabled() {
55
- return this.state.value === this.state.disabledValue;
56
- }
57
- getKey() {
58
- return `var-${this.state.name}`;
59
- }
60
- getKeys() {
61
- if (this.state.skipUrlSync) {
62
- return [];
63
- }
64
- return [this.getKey()];
65
- }
66
- getUrlState() {
67
- if (this.state.skipUrlSync) {
68
- return {};
69
- }
70
- return { [this.getKey()]: this.state.value };
71
- }
72
- updateFromUrl(values) {
73
- const val = values[this.getKey()];
74
- if (typeof val === "string") {
75
- this.setValue(val);
76
- }
77
- }
78
- }
79
- SwitchVariable.Component = SwitchVariableRenderer;
80
- function SwitchVariableRenderer({ model }) {
81
- const state = model.useState();
82
- const styles = useStyles2(getStyles);
83
- return /* @__PURE__ */ React.createElement("div", { className: styles.container }, /* @__PURE__ */ React.createElement(
84
- Switch,
85
- {
86
- value: state.value === state.enabledValue,
87
- onChange: (event) => {
88
- model.setValue(event.currentTarget.checked ? state.enabledValue : state.disabledValue);
89
- }
90
- }
91
- ));
92
- }
93
- function getStyles(theme) {
94
- return {
95
- container: css({
96
- display: "flex",
97
- alignItems: "center",
98
- padding: theme.spacing(0, 1),
99
- height: theme.spacing(theme.components.height.md),
100
- borderRadius: theme.shape.radius.default,
101
- border: `1px solid ${theme.components.input.borderColor}`,
102
- background: theme.colors.background.primary
103
- })
104
- };
105
- }
106
-
107
- export { SwitchVariable };
108
- //# sourceMappingURL=SwitchVariable.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SwitchVariable.js","sources":["../../../../src/variables/variants/SwitchVariable.tsx"],"sourcesContent":["import React from 'react';\nimport { Observable, of } from 'rxjs';\nimport { Switch, useStyles2 } from '@grafana/ui';\nimport { GrafanaTheme2 } from '@grafana/data';\nimport { css } from '@emotion/css';\nimport { SceneObjectBase } from '../../core/SceneObjectBase';\nimport { SceneComponentProps, SceneObjectUrlValues } from '../../core/types';\nimport { SceneObjectUrlSyncConfig } from '../../services/SceneObjectUrlSyncConfig';\nimport {\n SceneVariable,\n SceneVariableState,\n SceneVariableValueChangedEvent,\n ValidateAndUpdateResult,\n VariableValue,\n} from '../types';\n\nexport interface SwitchVariableState extends SceneVariableState {\n value: string;\n enabledValue: string;\n disabledValue: string;\n}\n\nexport class SwitchVariable extends SceneObjectBase<SwitchVariableState> implements SceneVariable<SwitchVariableState> {\n public static Component = SwitchVariableRenderer;\n private _prevValue: VariableValue = '';\n\n public constructor(initialState: Partial<SwitchVariableState>) {\n super({\n // TODO: remove this once switch is in the schema @leventebalogh\n // @ts-expect-error - switch is a valid variable type, but not in the schema yet\n type: 'switch',\n value: 'false',\n enabledValue: 'true',\n disabledValue: 'false',\n name: '',\n ...initialState,\n });\n\n this._urlSync = new SceneObjectUrlSyncConfig(this, { keys: () => this.getKeys() });\n }\n\n /**\n * This function is called on when SceneVariableSet is activated or when a dependency changes.\n */\n public validateAndUpdate(): Observable<ValidateAndUpdateResult> {\n const newValue = this.getValue();\n\n if (this._prevValue !== newValue) {\n this._prevValue = newValue;\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n }\n\n return of({});\n }\n\n public setValue(newValue: string): void {\n // Ignore if there's no change\n if (this.getValue() === newValue) {\n return;\n }\n\n if ([this.state.enabledValue, this.state.disabledValue].includes(newValue)) {\n this.setState({ value: newValue });\n this.publishEvent(new SceneVariableValueChangedEvent(this), true);\n } else {\n console.error(\n `Invalid value for switch variable: \"${newValue}\". Valid values are: \"${this.state.enabledValue}\" and \"${this.state.disabledValue}\".`\n );\n }\n }\n\n public getValue(): VariableValue {\n return this.state.value;\n }\n\n public isEnabled(): boolean {\n return this.state.value === this.state.enabledValue;\n }\n\n public isDisabled(): boolean {\n return this.state.value === this.state.disabledValue;\n }\n\n private getKey(): string {\n return `var-${this.state.name}`;\n }\n\n public getKeys(): string[] {\n if (this.state.skipUrlSync) {\n return [];\n }\n\n return [this.getKey()];\n }\n\n public getUrlState(): SceneObjectUrlValues {\n if (this.state.skipUrlSync) {\n return {};\n }\n\n return { [this.getKey()]: this.state.value };\n }\n\n public updateFromUrl(values: SceneObjectUrlValues): void {\n const val = values[this.getKey()];\n\n if (typeof val === 'string') {\n this.setValue(val);\n }\n }\n}\n\nfunction SwitchVariableRenderer({ model }: SceneComponentProps<SwitchVariable>) {\n const state = model.useState();\n const styles = useStyles2(getStyles);\n\n return (\n <div className={styles.container}>\n <Switch\n value={state.value === state.enabledValue}\n onChange={(event) => {\n model.setValue(event!.currentTarget.checked ? state.enabledValue : state.disabledValue);\n }}\n />\n </div>\n );\n}\n\nfunction getStyles(theme: GrafanaTheme2) {\n return {\n container: css({\n display: 'flex',\n alignItems: 'center',\n padding: theme.spacing(0, 1),\n height: theme.spacing(theme.components.height.md),\n borderRadius: theme.shape.radius.default,\n border: `1px solid ${theme.components.input.borderColor}`,\n background: theme.colors.background.primary,\n }),\n };\n}\n"],"names":[],"mappings":";;;;;;;;AAsBO,MAAM,uBAAuB,eAAmF,CAAA;AAAA,EAI9G,YAAY,YAA4C,EAAA;AAC7D,IAAM,KAAA,CAAA;AAAA;AAAA;AAAA,MAGJ,IAAM,EAAA,QAAA;AAAA,MACN,KAAO,EAAA,OAAA;AAAA,MACP,YAAc,EAAA,MAAA;AAAA,MACd,aAAe,EAAA,OAAA;AAAA,MACf,IAAM,EAAA,EAAA;AAAA,MACN,GAAG;AAAA,KACJ,CAAA;AAZH,IAAA,IAAA,CAAQ,UAA4B,GAAA,EAAA;AAclC,IAAK,IAAA,CAAA,QAAA,GAAW,IAAI,wBAAA,CAAyB,IAAM,EAAA,EAAE,MAAM,MAAM,IAAA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