@perses-dev/dashboards 0.8.0 → 0.9.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.
Files changed (196) hide show
  1. package/dist/cjs/components/Dashboard.js +29 -14
  2. package/dist/cjs/components/DashboardToolbar.js +148 -20
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +24 -18
  4. package/dist/cjs/components/GridLayout/GridLayout.js +88 -26
  5. package/dist/cjs/components/GridLayout/GridTitle.js +69 -31
  6. package/dist/cjs/components/GridLayout/index.js +18 -19
  7. package/dist/cjs/components/Panel/Panel.js +145 -55
  8. package/dist/cjs/components/Panel/Panel.test.js +50 -41
  9. package/dist/cjs/components/Panel/PanelContent.js +40 -12
  10. package/dist/cjs/components/Panel/index.js +16 -17
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +82 -107
  12. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +91 -92
  13. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +152 -0
  14. package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +40 -0
  15. package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +38 -0
  16. package/dist/cjs/components/PanelDrawer/index.js +28 -0
  17. package/dist/cjs/components/PanelDrawer/panel-editor-model.js +140 -0
  18. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +120 -31
  19. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +90 -83
  20. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
  21. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
  22. package/dist/cjs/components/TimeRangeControls/index.js +16 -17
  23. package/dist/cjs/components/Variables/Variable.js +186 -35
  24. package/dist/cjs/components/Variables/VariableList.js +100 -13
  25. package/dist/cjs/components/Variables/index.js +17 -18
  26. package/dist/cjs/components/index.js +21 -21
  27. package/dist/cjs/context/DashboardAppSlice.js +43 -31
  28. package/dist/cjs/context/DashboardProvider.js +88 -58
  29. package/dist/cjs/context/DatasourceStoreProvider.js +68 -0
  30. package/dist/cjs/context/LayoutsSlice.js +40 -27
  31. package/dist/cjs/context/QueryStringProvider.js +69 -15
  32. package/dist/cjs/context/TemplateVariableProvider.js +128 -136
  33. package/dist/cjs/context/TimeRangeProvider.js +79 -30
  34. package/dist/cjs/context/index.js +22 -22
  35. package/dist/cjs/css/styles.js +43 -39
  36. package/dist/cjs/index.js +19 -20
  37. package/dist/cjs/test/dashboard-provider.js +51 -0
  38. package/dist/cjs/test/index.js +18 -18
  39. package/dist/cjs/test/plugin-registry.js +52 -25
  40. package/dist/cjs/test/render.js +25 -22
  41. package/dist/cjs/test/setup-tests.js +4 -2
  42. package/dist/cjs/test/testDashboard.js +193 -109
  43. package/dist/cjs/utils/functions.js +9 -5
  44. package/dist/cjs/views/ViewDashboard/DashboardApp.js +67 -0
  45. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +83 -0
  46. package/dist/cjs/views/ViewDashboard/index.js +28 -0
  47. package/dist/cjs/views/index.js +16 -17
  48. package/dist/components/Dashboard.js +38 -1
  49. package/dist/components/Dashboard.js.map +1 -0
  50. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  51. package/dist/components/DashboardToolbar.js +154 -1
  52. package/dist/components/DashboardToolbar.js.map +1 -0
  53. package/dist/components/GridLayout/GridItemContent.js +35 -1
  54. package/dist/components/GridLayout/GridItemContent.js.map +1 -0
  55. package/dist/components/GridLayout/GridLayout.js +99 -1
  56. package/dist/components/GridLayout/GridLayout.js.map +1 -0
  57. package/dist/components/GridLayout/GridTitle.js +77 -1
  58. package/dist/components/GridLayout/GridTitle.js.map +1 -0
  59. package/dist/components/GridLayout/index.js +16 -1
  60. package/dist/components/GridLayout/index.js.map +1 -0
  61. package/dist/components/Panel/Panel.d.ts.map +1 -1
  62. package/dist/components/Panel/Panel.js +170 -1
  63. package/dist/components/Panel/Panel.js.map +1 -0
  64. package/dist/components/Panel/Panel.test.js +71 -1
  65. package/dist/components/Panel/Panel.test.js.map +1 -0
  66. package/dist/components/Panel/PanelContent.d.ts +2 -4
  67. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  68. package/dist/components/Panel/PanelContent.js +40 -1
  69. package/dist/components/Panel/PanelContent.js.map +1 -0
  70. package/dist/components/Panel/index.js +15 -1
  71. package/dist/components/Panel/index.js.map +1 -0
  72. package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
  73. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  74. package/dist/components/PanelDrawer/PanelDrawer.js +95 -1
  75. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
  76. package/dist/components/PanelDrawer/PanelDrawer.test.js +103 -1
  77. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
  78. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
  79. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
  80. package/dist/components/PanelDrawer/PanelEditorForm.js +142 -0
  81. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
  82. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +7 -0
  83. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +1 -0
  84. package/dist/components/PanelDrawer/PanelSpecEditor.js +34 -0
  85. package/dist/components/PanelDrawer/PanelSpecEditor.js.map +1 -0
  86. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +8 -0
  87. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +1 -0
  88. package/dist/components/PanelDrawer/PanelTypeSelect.js +34 -0
  89. package/dist/components/PanelDrawer/PanelTypeSelect.js.map +1 -0
  90. package/dist/components/PanelDrawer/index.d.ts +2 -0
  91. package/dist/components/PanelDrawer/index.d.ts.map +1 -0
  92. package/dist/components/PanelDrawer/index.js +15 -0
  93. package/dist/components/PanelDrawer/index.js.map +1 -0
  94. package/dist/components/PanelDrawer/panel-editor-model.d.ts +27 -0
  95. package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +1 -0
  96. package/dist/components/PanelDrawer/panel-editor-model.js +133 -0
  97. package/dist/components/PanelDrawer/panel-editor-model.js.map +1 -0
  98. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  99. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +138 -1
  100. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
  101. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -1
  102. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
  103. package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
  104. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  105. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
  106. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
  107. package/dist/components/TimeRangeControls/index.js +15 -1
  108. package/dist/components/TimeRangeControls/index.js.map +1 -0
  109. package/dist/components/Variables/Variable.d.ts.map +1 -1
  110. package/dist/components/Variables/Variable.js +202 -1
  111. package/dist/components/Variables/Variable.js.map +1 -0
  112. package/dist/components/Variables/VariableList.js +108 -1
  113. package/dist/components/Variables/VariableList.js.map +1 -0
  114. package/dist/components/Variables/index.js +16 -1
  115. package/dist/components/Variables/index.js.map +1 -0
  116. package/dist/components/index.d.ts +1 -0
  117. package/dist/components/index.d.ts.map +1 -1
  118. package/dist/components/index.js +20 -1
  119. package/dist/components/index.js.map +1 -0
  120. package/dist/context/DashboardAppSlice.js +45 -1
  121. package/dist/context/DashboardAppSlice.js.map +1 -0
  122. package/dist/context/DashboardProvider.d.ts +4 -2
  123. package/dist/context/DashboardProvider.d.ts.map +1 -1
  124. package/dist/context/DashboardProvider.js +107 -1
  125. package/dist/context/DashboardProvider.js.map +1 -0
  126. package/dist/context/DatasourceStoreProvider.d.ts +16 -0
  127. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
  128. package/dist/context/DatasourceStoreProvider.js +64 -0
  129. package/dist/context/DatasourceStoreProvider.js.map +1 -0
  130. package/dist/context/LayoutsSlice.js +43 -1
  131. package/dist/context/LayoutsSlice.js.map +1 -0
  132. package/dist/context/QueryStringProvider.js +40 -1
  133. package/dist/context/QueryStringProvider.js.map +1 -0
  134. package/dist/context/TemplateVariableProvider.d.ts +6 -3
  135. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  136. package/dist/context/TemplateVariableProvider.js +192 -1
  137. package/dist/context/TemplateVariableProvider.js.map +1 -0
  138. package/dist/context/TimeRangeProvider.js +72 -1
  139. package/dist/context/TimeRangeProvider.js.map +1 -0
  140. package/dist/context/index.d.ts +3 -2
  141. package/dist/context/index.d.ts.map +1 -1
  142. package/dist/context/index.js +21 -1
  143. package/dist/context/index.js.map +1 -0
  144. package/dist/css/styles.js +186 -1
  145. package/dist/css/styles.js.map +1 -0
  146. package/dist/index.js +17 -1
  147. package/dist/index.js.map +1 -0
  148. package/dist/test/dashboard-provider.d.ts +19 -0
  149. package/dist/test/dashboard-provider.d.ts.map +1 -0
  150. package/dist/test/dashboard-provider.js +40 -0
  151. package/dist/test/dashboard-provider.js.map +1 -0
  152. package/dist/test/index.d.ts +1 -0
  153. package/dist/test/index.d.ts.map +1 -1
  154. package/dist/test/index.js +17 -1
  155. package/dist/test/index.js.map +1 -0
  156. package/dist/test/plugin-registry.d.ts +2 -3
  157. package/dist/test/plugin-registry.d.ts.map +1 -1
  158. package/dist/test/plugin-registry.js +74 -1
  159. package/dist/test/plugin-registry.js.map +1 -0
  160. package/dist/test/render.d.ts +1 -2
  161. package/dist/test/render.d.ts.map +1 -1
  162. package/dist/test/render.js +34 -1
  163. package/dist/test/render.js.map +1 -0
  164. package/dist/test/setup-tests.js +18 -1
  165. package/dist/test/setup-tests.js.map +1 -0
  166. package/dist/test/testDashboard.d.ts.map +1 -1
  167. package/dist/test/testDashboard.js +274 -1
  168. package/dist/test/testDashboard.js.map +1 -0
  169. package/dist/utils/functions.js +17 -1
  170. package/dist/utils/functions.js.map +1 -0
  171. package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
  172. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
  173. package/dist/views/ViewDashboard/DashboardApp.js +56 -0
  174. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
  175. package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +3 -1
  176. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
  177. package/dist/views/ViewDashboard/ViewDashboard.js +79 -0
  178. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
  179. package/dist/views/ViewDashboard/index.d.ts +2 -0
  180. package/dist/views/ViewDashboard/index.d.ts.map +1 -0
  181. package/dist/views/ViewDashboard/index.js +15 -0
  182. package/dist/views/ViewDashboard/index.js.map +1 -0
  183. package/dist/views/index.js +15 -1
  184. package/dist/views/index.js.map +1 -0
  185. package/package.json +13 -7
  186. package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
  187. package/dist/cjs/views/DashboardApp.js +0 -46
  188. package/dist/cjs/views/ViewDashboard.js +0 -43
  189. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
  190. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
  191. package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
  192. package/dist/views/DashboardApp.d.ts +0 -4
  193. package/dist/views/DashboardApp.d.ts.map +0 -1
  194. package/dist/views/DashboardApp.js +0 -1
  195. package/dist/views/ViewDashboard.d.ts.map +0 -1
  196. package/dist/views/ViewDashboard.js +0 -1
@@ -1 +1,202 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useEffect,useRef}from"react";import{Select,FormControl,InputLabel,MenuItem,Box,LinearProgress,IconButton,TextField}from"@mui/material";import{Reload}from"mdi-material-ui";import{useTemplateVariable,useTemplateVariableActions,useTemplateVariableStore}from"../../context";export function TemplateVariable({name:e}){var a;const l=null===(a=useTemplateVariable(e).definition)||void 0===a?void 0:a.kind;switch(l){case"TextVariable":return _jsx(TextVariable,{name:e});case"ListVariable":return _jsx(ListVariable,{name:e})}return _jsxs("div",{children:["Unsupported Variable Kind: $",l]})}function ListVariable({name:e}){var a,l,t,i;const r=useTemplateVariable(e),n=r.definition,{setVariableValue:o,loadTemplateVariable:s}=useTemplateVariableActions(),u=!0===(null==n?void 0:n.options.allowMultiple);useEffect((()=>{s(e)}),[e,s]);let d=null===(a=r.state)||void 0===a?void 0:a.value;return u&&!Array.isArray(d)&&(d=[]),_jsxs(Box,{display:"flex",children:[_jsxs(FormControl,{children:[_jsx(InputLabel,{id:e,children:e}),_jsx(Select,{id:e,label:e,value:d,onChange:a=>{o(e,a.target.value)},multiple:u,children:null===(t=null===(l=r.state)||void 0===l?void 0:l.options)||void 0===t?void 0:t.map((e=>_jsx(MenuItem,{value:e.value,children:e.label},e.value)))}),(null===(i=r.state)||void 0===i?void 0:i.loading)&&_jsx(LinearProgress,{})]}),_jsx(IconButton,{onClick:()=>s(e),children:_jsx(Reload,{})})]})}function TextVariable({name:e}){const{state:a}=useTemplateVariable(e),l=useTemplateVariableStore().setVariableValue,t=useRef(null);return _jsx(TextField,{ref:t,defaultValue:null==a?void 0:a.value,onBlur:a=>l(e,a.target.value),placeholder:e,label:e})}
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { useEffect, useMemo, useRef } from 'react';
15
+ import { Select, FormControl, InputLabel, MenuItem, Box, LinearProgress, TextField } from '@mui/material';
16
+ import { usePlugin, DEFAULT_ALL_VALUE, useTemplateVariableValues, useDatasourceStore } from '@perses-dev/plugin-system';
17
+ import { useQuery } from '@tanstack/react-query';
18
+ import { useTemplateVariable, useTemplateVariableActions, useTemplateVariableStore } from '../../context';
19
+ export function TemplateVariable({ name }) {
20
+ var ref;
21
+ const ctx = useTemplateVariable(name);
22
+ const kind = (ref = ctx.definition) === null || ref === void 0 ? void 0 : ref.kind;
23
+ switch(kind){
24
+ case 'TextVariable':
25
+ return /*#__PURE__*/ _jsx(TextVariable, {
26
+ name: name
27
+ });
28
+ case 'ListVariable':
29
+ return /*#__PURE__*/ _jsx(ListVariable, {
30
+ name: name
31
+ });
32
+ }
33
+ return /*#__PURE__*/ _jsxs("div", {
34
+ children: [
35
+ "Unsupported Variable Kind: $",
36
+ kind
37
+ ]
38
+ });
39
+ }
40
+ /**
41
+ * Returns a serialized string of the current state of variable values.
42
+ */ function getVariableValuesKey(v) {
43
+ return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
44
+ }
45
+ function ListVariable({ name }) {
46
+ var ref, ref1, ref2;
47
+ const ctx = useTemplateVariable(name);
48
+ const definition = ctx.definition;
49
+ const { data: variablePlugin } = usePlugin('Variable', definition.spec.plugin.kind);
50
+ const { setVariableValue , setVariableLoading , setVariableOptions } = useTemplateVariableActions();
51
+ const datasourceStore = useDatasourceStore();
52
+ const spec = definition.spec.plugin.spec;
53
+ let dependsOnVariables;
54
+ if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
55
+ dependsOnVariables = variablePlugin.dependsOn(spec);
56
+ }
57
+ const variables = useTemplateVariableValues(dependsOnVariables);
58
+ const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_multiple) === true;
59
+ const allowAllValue = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_all_value) === true;
60
+ let waitToLoad = false;
61
+ if (dependsOnVariables) {
62
+ waitToLoad = dependsOnVariables.some((v)=>{
63
+ var ref;
64
+ return (ref = variables[v]) === null || ref === void 0 ? void 0 : ref.loading;
65
+ });
66
+ }
67
+ const variablesValueKey = getVariableValuesKey(variables);
68
+ const variablesOptionsQuery = useQuery([
69
+ name,
70
+ definition,
71
+ variablesValueKey
72
+ ], async ()=>{
73
+ const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
74
+ datasourceStore,
75
+ variables
76
+ }));
77
+ var ref;
78
+ return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
79
+ }, {
80
+ enabled: !!variablePlugin || waitToLoad
81
+ });
82
+ useEffect(()=>{
83
+ setVariableLoading(name, variablesOptionsQuery.isFetching);
84
+ if (variablesOptionsQuery.data) {
85
+ setVariableOptions(name, variablesOptionsQuery.data);
86
+ }
87
+ }, [
88
+ variablesOptionsQuery,
89
+ name,
90
+ setVariableLoading,
91
+ setVariableOptions
92
+ ]);
93
+ let value = (ref = ctx.state) === null || ref === void 0 ? void 0 : ref.value;
94
+ const options = (ref1 = ctx.state) === null || ref1 === void 0 ? void 0 : ref1.options;
95
+ const loading = (ref2 = ctx.state) === null || ref2 === void 0 ? void 0 : ref2.loading;
96
+ // Make sure value is an array if allowMultiple is true
97
+ if (allowMultiple && !Array.isArray(value)) {
98
+ value = typeof value === 'string' ? [
99
+ value
100
+ ] : [];
101
+ }
102
+ const finalOptions = useMemo(()=>{
103
+ let computedOptions = options ? [
104
+ ...options
105
+ ] : [];
106
+ // Add the all value if it's allowed
107
+ if (allowAllValue) {
108
+ computedOptions = [
109
+ {
110
+ value: DEFAULT_ALL_VALUE,
111
+ label: 'All'
112
+ },
113
+ ...computedOptions
114
+ ];
115
+ }
116
+ return computedOptions;
117
+ }, [
118
+ options,
119
+ allowAllValue
120
+ ]);
121
+ useEffect(()=>{
122
+ const firstOption = finalOptions === null || finalOptions === void 0 ? void 0 : finalOptions[0];
123
+ const valueIsInOptions = Boolean(finalOptions.find((v)=>{
124
+ if (allowMultiple) {
125
+ return value.includes(v.value);
126
+ }
127
+ return value === v.value;
128
+ }));
129
+ // If there is no value but there are options, set the value to the first option.
130
+ if (!value && firstOption) {
131
+ setVariableValue(name, firstOption.value);
132
+ }
133
+ // If there is a value but it's not in the options, select the first value or set to null
134
+ if (value && !valueIsInOptions && !definition.spec.default_value) {
135
+ setVariableValue(name, (firstOption === null || firstOption === void 0 ? void 0 : firstOption.value) || null);
136
+ }
137
+ }, [
138
+ finalOptions,
139
+ setVariableValue,
140
+ value,
141
+ name,
142
+ allowMultiple
143
+ ]);
144
+ return /*#__PURE__*/ _jsx(Box, {
145
+ display: 'flex',
146
+ children: /*#__PURE__*/ _jsxs(FormControl, {
147
+ children: [
148
+ /*#__PURE__*/ _jsx(InputLabel, {
149
+ id: name,
150
+ children: name
151
+ }),
152
+ /*#__PURE__*/ _jsxs(Select, {
153
+ sx: {
154
+ minWidth: 100,
155
+ maxWidth: 250
156
+ },
157
+ id: name,
158
+ label: name,
159
+ value: value !== null && value !== void 0 ? value : '',
160
+ onChange: (e)=>{
161
+ // Must be selected
162
+ if (e.target.value === null || e.target.value.length === 0) {
163
+ if (allowAllValue) {
164
+ setVariableValue(name, DEFAULT_ALL_VALUE);
165
+ }
166
+ return;
167
+ }
168
+ setVariableValue(name, e.target.value);
169
+ },
170
+ multiple: allowMultiple,
171
+ children: [
172
+ loading && /*#__PURE__*/ _jsx(MenuItem, {
173
+ value: "loading",
174
+ disabled: true,
175
+ children: "Loading"
176
+ }),
177
+ finalOptions.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
178
+ value: option.value,
179
+ children: option.label
180
+ }, option.value))
181
+ ]
182
+ }),
183
+ loading && /*#__PURE__*/ _jsx(LinearProgress, {})
184
+ ]
185
+ })
186
+ });
187
+ }
188
+ function TextVariable({ name }) {
189
+ const { state } = useTemplateVariable(name);
190
+ const s = useTemplateVariableStore();
191
+ const setVariableValue = s.setVariableValue;
192
+ const ref = useRef(null);
193
+ return /*#__PURE__*/ _jsx(TextField, {
194
+ ref: ref,
195
+ defaultValue: state === null || state === void 0 ? void 0 : state.value,
196
+ onBlur: (e)=>setVariableValue(name, e.target.value),
197
+ placeholder: name,
198
+ label: name
199
+ });
200
+ }
201
+
202
+ //# sourceMappingURL=Variable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Variables/Variable.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useEffect, useMemo, useRef } from 'react';\nimport { Select, FormControl, InputLabel, MenuItem, Box, LinearProgress, TextField } from '@mui/material';\nimport { VariableName, ListVariableDefinition, VariableValue } from '@perses-dev/core';\nimport {\n usePlugin,\n DEFAULT_ALL_VALUE,\n useTemplateVariableValues,\n VariableStateMap,\n useDatasourceStore,\n} from '@perses-dev/plugin-system';\nimport { useQuery } from '@tanstack/react-query';\nimport { useTemplateVariable, useTemplateVariableActions, useTemplateVariableStore } from '../../context';\n\ntype TemplateVariableProps = {\n name: VariableName;\n};\n\nexport function TemplateVariable({ name }: TemplateVariableProps) {\n const ctx = useTemplateVariable(name);\n const kind = ctx.definition?.kind;\n switch (kind) {\n case 'TextVariable':\n return <TextVariable name={name} />;\n case 'ListVariable':\n return <ListVariable name={name} />;\n }\n\n return <div>Unsupported Variable Kind: ${kind}</div>;\n}\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction ListVariable({ name }: TemplateVariableProps) {\n const ctx = useTemplateVariable(name);\n const definition = ctx.definition as ListVariableDefinition;\n const { data: variablePlugin } = usePlugin('Variable', definition.spec.plugin.kind);\n const { setVariableValue, setVariableLoading, setVariableOptions } = useTemplateVariableActions();\n const datasourceStore = useDatasourceStore();\n\n const spec = definition.spec.plugin.spec;\n\n let dependsOnVariables: string[] | undefined;\n if (variablePlugin?.dependsOn) {\n dependsOnVariables = variablePlugin.dependsOn(spec);\n }\n\n const variables = useTemplateVariableValues(dependsOnVariables);\n const allowMultiple = definition?.spec.allow_multiple === true;\n const allowAllValue = definition?.spec.allow_all_value === true;\n\n let waitToLoad = false;\n if (dependsOnVariables) {\n waitToLoad = dependsOnVariables.some((v) => variables[v]?.loading);\n }\n\n const variablesValueKey = getVariableValuesKey(variables);\n\n const variablesOptionsQuery = useQuery(\n [name, definition, variablesValueKey],\n async () => {\n const resp = await variablePlugin?.getVariableOptions(spec, { datasourceStore, variables });\n return resp?.data ?? [];\n },\n { enabled: !!variablePlugin || waitToLoad }\n );\n\n useEffect(() => {\n setVariableLoading(name, variablesOptionsQuery.isFetching);\n if (variablesOptionsQuery.data) {\n setVariableOptions(name, variablesOptionsQuery.data);\n }\n }, [variablesOptionsQuery, name, setVariableLoading, setVariableOptions]);\n\n let value = ctx.state?.value;\n const options = ctx.state?.options;\n const loading = ctx.state?.loading;\n\n // Make sure value is an array if allowMultiple is true\n if (allowMultiple && !Array.isArray(value)) {\n value = typeof value === 'string' ? [value] : [];\n }\n\n const finalOptions = useMemo(() => {\n let computedOptions = options ? [...options] : [];\n\n // Add the all value if it's allowed\n if (allowAllValue) {\n computedOptions = [{ value: DEFAULT_ALL_VALUE, label: 'All' }, ...computedOptions];\n }\n return computedOptions;\n }, [options, allowAllValue]);\n\n useEffect(() => {\n const firstOption = finalOptions?.[0];\n const valueIsInOptions = Boolean(\n finalOptions.find((v) => {\n if (allowMultiple) {\n return (value as string[]).includes(v.value);\n }\n return value === v.value;\n })\n );\n\n // If there is no value but there are options, set the value to the first option.\n if (!value && firstOption) {\n setVariableValue(name, firstOption.value);\n }\n\n // If there is a value but it's not in the options, select the first value or set to null\n if (value && !valueIsInOptions && !definition.spec.default_value) {\n setVariableValue(name, firstOption?.value || null);\n }\n }, [finalOptions, setVariableValue, value, name, allowMultiple]);\n\n return (\n <Box display={'flex'}>\n <FormControl>\n <InputLabel id={name}>{name}</InputLabel>\n <Select\n sx={{ minWidth: 100, maxWidth: 250 }}\n id={name}\n label={name}\n value={value ?? ''}\n onChange={(e) => {\n // Must be selected\n if (e.target.value === null || e.target.value.length === 0) {\n if (allowAllValue) {\n setVariableValue(name, DEFAULT_ALL_VALUE);\n }\n return;\n }\n setVariableValue(name, e.target.value as VariableValue);\n }}\n multiple={allowMultiple}\n >\n {loading && (\n <MenuItem value=\"loading\" disabled>\n Loading\n </MenuItem>\n )}\n {finalOptions.map((option) => (\n <MenuItem key={option.value} value={option.value}>\n {option.label}\n </MenuItem>\n ))}\n </Select>\n {loading && <LinearProgress />}\n </FormControl>\n </Box>\n );\n}\n\nfunction TextVariable({ name }: TemplateVariableProps) {\n const { state } = useTemplateVariable(name);\n const s = useTemplateVariableStore();\n const setVariableValue = s.setVariableValue;\n const ref = useRef<HTMLInputElement>(null);\n return (\n <TextField\n ref={ref}\n defaultValue={state?.value}\n onBlur={(e) => setVariableValue(name, e.target.value)}\n placeholder={name}\n label={name}\n />\n );\n}\n"],"names":["useEffect","useMemo","useRef","Select","FormControl","InputLabel","MenuItem","Box","LinearProgress","TextField","usePlugin","DEFAULT_ALL_VALUE","useTemplateVariableValues","useDatasourceStore","useQuery","useTemplateVariable","useTemplateVariableActions","useTemplateVariableStore","TemplateVariable","name","ctx","kind","definition","TextVariable","ListVariable","div","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","data","variablePlugin","spec","plugin","setVariableValue","setVariableLoading","setVariableOptions","datasourceStore","dependsOnVariables","dependsOn","variables","allowMultiple","allow_multiple","allowAllValue","allow_all_value","waitToLoad","some","loading","variablesValueKey","variablesOptionsQuery","resp","getVariableOptions","enabled","isFetching","state","options","Array","isArray","finalOptions","computedOptions","label","firstOption","valueIsInOptions","Boolean","find","includes","default_value","display","id","sx","minWidth","maxWidth","onChange","e","target","length","multiple","disabled","option","s","ref","defaultValue","onBlur","placeholder"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO,CAAC;AACnD,SAASC,MAAM,EAAEC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,cAAc,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAE1G,SACEC,SAAS,EACTC,iBAAiB,EACjBC,yBAAyB,EAEzBC,kBAAkB,QACb,2BAA2B,CAAC;AACnC,SAASC,QAAQ,QAAQ,uBAAuB,CAAC;AACjD,SAASC,mBAAmB,EAAEC,0BAA0B,EAAEC,wBAAwB,QAAQ,eAAe,CAAC;AAM1G,OAAO,SAASC,gBAAgB,CAAC,EAAEC,IAAI,CAAA,EAAyB,EAAE;QAEnDC,GAAc;IAD3B,MAAMA,GAAG,GAAGL,mBAAmB,CAACI,IAAI,CAAC,AAAC;IACtC,MAAME,IAAI,GAAGD,CAAAA,GAAc,GAAdA,GAAG,CAACE,UAAU,cAAdF,GAAc,WAAM,GAApBA,KAAAA,CAAoB,GAApBA,GAAc,CAAEC,IAAI,AAAC;IAClC,OAAQA,IAAI;QACV,KAAK,cAAc;YACjB,qBAAO,KAACE,YAAY;gBAACJ,IAAI,EAAEA,IAAI;cAAI,CAAC;QACtC,KAAK,cAAc;YACjB,qBAAO,KAACK,YAAY;gBAACL,IAAI,EAAEA,IAAI;cAAI,CAAC;KACvC;IAED,qBAAO,MAACM,KAAG;;YAAC,8BAA4B;YAAC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G,EAAEA,GAAG;QACRC,YAAY,EAAE3B,KAAK,aAALA,KAAK,WAAO,GAAZA,KAAAA,CAAY,GAAZA,KAAK,CAAE1B,KAAK;QAC1BsD,MAAM,EAAE,CAACT,CAAC,GAAKvC,gBAAgB,CAACpB,IAAI,EAAE2D,CAAC,CAACC,MAAM,CAAC9C,KAAK,CAAC;QACrDuD,WAAW,EAAErE,IAAI;QACjB8C,KAAK,EAAE9C,IAAI;MACX,CACF;AACJ,CAAC"}
@@ -1 +1,108 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState}from"react";import{Button,Stack,Box,Drawer,TableContainer,TableBody,TableRow,TableCell,Table,Paper,TableHead}from"@mui/material";import{useTemplateVariableDefinitions,useEditMode}from"../../context";import{TemplateVariable}from"./Variable";export function TemplateVariableList(){const[e,a]=useState(!1),l=useTemplateVariableDefinitions(),{isEditMode:i}=useEditMode();return _jsxs(Box,{m:2,children:[_jsx(Drawer,{anchor:"right",open:e,onClose:()=>a(!1),children:_jsxs(Box,{width:900,p:4,children:[_jsx(TableContainer,{component:Paper,children:_jsxs(Table,{sx:{minWidth:650},"aria-label":"simple table",children:[_jsx(TableHead,{children:_jsxs(TableRow,{children:[_jsx(TableCell,{children:"Variable Name"}),_jsx(TableCell,{align:"right",children:"Type"})]})}),_jsx(TableBody,{children:l.map((e=>_jsxs(TableRow,{sx:{"&:last-child td, &:last-child th":{border:0}},children:[_jsx(TableCell,{component:"th",scope:"row",sx:{fontWeight:"bold"},children:e.name}),_jsx(TableCell,{align:"right",children:e.kind})]},e.name)))})]})}),_jsx("pre",{children:JSON.stringify(l,null,2)})]})}),_jsx(Box,{display:"flex",justifyContent:"space-between",children:_jsxs(Stack,{direction:"row",spacing:2,children:[l.map((e=>_jsx(Box,{children:_jsx(TemplateVariable,{name:e.name},e.name)},e.name))),i&&_jsx(Button,{onClick:()=>a(!0),children:"Modify Variables"})]})})]})}
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
+ import { useState } from 'react';
15
+ import { Button, Stack, Box, Drawer, TableContainer, TableBody, TableRow, TableCell, Table, Paper, TableHead } from '@mui/material';
16
+ import { useTemplateVariableDefinitions, useEditMode } from '../../context';
17
+ import { TemplateVariable } from './Variable';
18
+ export function TemplateVariableList() {
19
+ const [isEditing, setIsEditing] = useState(false);
20
+ const variableDefinitions = useTemplateVariableDefinitions();
21
+ const { isEditMode } = useEditMode();
22
+ return /*#__PURE__*/ _jsxs(_Fragment, {
23
+ children: [
24
+ /*#__PURE__*/ _jsx(Drawer, {
25
+ anchor: 'right',
26
+ open: isEditing,
27
+ onClose: ()=>setIsEditing(false),
28
+ children: /*#__PURE__*/ _jsxs(Box, {
29
+ width: 900,
30
+ p: 4,
31
+ children: [
32
+ /*#__PURE__*/ _jsx(TableContainer, {
33
+ component: Paper,
34
+ children: /*#__PURE__*/ _jsxs(Table, {
35
+ sx: {
36
+ minWidth: 650
37
+ },
38
+ "aria-label": "simple table",
39
+ children: [
40
+ /*#__PURE__*/ _jsx(TableHead, {
41
+ children: /*#__PURE__*/ _jsxs(TableRow, {
42
+ children: [
43
+ /*#__PURE__*/ _jsx(TableCell, {
44
+ children: "Variable Name"
45
+ }),
46
+ /*#__PURE__*/ _jsx(TableCell, {
47
+ align: "right",
48
+ children: "Type"
49
+ })
50
+ ]
51
+ })
52
+ }),
53
+ /*#__PURE__*/ _jsx(TableBody, {
54
+ children: variableDefinitions.map((v)=>/*#__PURE__*/ _jsxs(TableRow, {
55
+ sx: {
56
+ '&:last-child td, &:last-child th': {
57
+ border: 0
58
+ }
59
+ },
60
+ children: [
61
+ /*#__PURE__*/ _jsx(TableCell, {
62
+ component: "th",
63
+ scope: "row",
64
+ sx: {
65
+ fontWeight: 'bold'
66
+ },
67
+ children: v.spec.name
68
+ }),
69
+ /*#__PURE__*/ _jsx(TableCell, {
70
+ align: "right",
71
+ children: v.kind
72
+ })
73
+ ]
74
+ }, v.spec.name))
75
+ })
76
+ ]
77
+ })
78
+ }),
79
+ /*#__PURE__*/ _jsx("pre", {
80
+ children: JSON.stringify(variableDefinitions, null, 2)
81
+ })
82
+ ]
83
+ })
84
+ }),
85
+ /*#__PURE__*/ _jsx(Box, {
86
+ display: 'flex',
87
+ justifyContent: "space-between",
88
+ children: /*#__PURE__*/ _jsxs(Stack, {
89
+ direction: 'row',
90
+ spacing: 2,
91
+ children: [
92
+ variableDefinitions.map((v)=>/*#__PURE__*/ _jsx(Box, {
93
+ children: /*#__PURE__*/ _jsx(TemplateVariable, {
94
+ name: v.spec.name
95
+ }, v.spec.name)
96
+ }, v.spec.name)),
97
+ isEditMode && /*#__PURE__*/ _jsx(Button, {
98
+ onClick: ()=>setIsEditing(true),
99
+ children: "Modify Variables"
100
+ })
101
+ ]
102
+ })
103
+ })
104
+ ]
105
+ });
106
+ }
107
+
108
+ //# sourceMappingURL=VariableList.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Variables/VariableList.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport {\n Button,\n Stack,\n Box,\n Drawer,\n TableContainer,\n TableBody,\n TableRow,\n TableCell,\n Table,\n Paper,\n TableHead,\n} from '@mui/material';\nimport { useTemplateVariableDefinitions, useEditMode } from '../../context';\nimport { TemplateVariable } from './Variable';\n\nexport function TemplateVariableList() {\n const [isEditing, setIsEditing] = useState(false);\n const variableDefinitions = useTemplateVariableDefinitions();\n const { isEditMode } = useEditMode();\n return (\n <>\n <Drawer anchor={'right'} open={isEditing} onClose={() => setIsEditing(false)}>\n <Box width={900} p={4}>\n <TableContainer component={Paper}>\n <Table sx={{ minWidth: 650 }} aria-label=\"simple table\">\n <TableHead>\n <TableRow>\n <TableCell>Variable Name</TableCell>\n <TableCell align=\"right\">Type</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {variableDefinitions.map((v) => (\n <TableRow key={v.spec.name} sx={{ '&:last-child td, &:last-child th': { border: 0 } }}>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n {v.spec.name}\n </TableCell>\n <TableCell align=\"right\">{v.kind}</TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </TableContainer>\n <pre>{JSON.stringify(variableDefinitions, null, 2)}</pre>\n </Box>\n </Drawer>\n <Box display={'flex'} justifyContent=\"space-between\">\n <Stack direction={'row'} spacing={2}>\n {variableDefinitions.map((v) => (\n <Box key={v.spec.name}>\n <TemplateVariable key={v.spec.name} name={v.spec.name} />\n </Box>\n ))}\n {isEditMode && <Button onClick={() => setIsEditing(true)}>Modify Variables</Button>}\n </Stack>\n </Box>\n </>\n );\n}\n"],"names":["useState","Button","Stack","Box","Drawer","TableContainer","TableBody","TableRow","TableCell","Table","Paper","TableHead","useTemplateVariableDefinitions","useEditMode","TemplateVariable","TemplateVariableList","isEditing","setIsEditing","variableDefinitions","isEditMode","anchor","open","onClose","width","p","component","sx","minWidth","aria-label","align","map","v","border","scope","fontWeight","spec","name","kind","pre","JSON","stringify","display","justifyContent","direction","spacing","onClick"],"mapp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
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './Variable';
14
+ export * from './VariableList';
15
+
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Variables/index.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './Variable';\nexport * from './VariableList';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC"}
@@ -1,6 +1,7 @@
1
1
  export * from './Dashboard';
2
2
  export * from './GridLayout';
3
3
  export * from './Panel';
4
+ export * from './PanelDrawer';
4
5
  export * from './TimeRangeControls';
5
6
  export * from './Variables';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC"}
@@ -1 +1,20 @@
1
- export*from"./Dashboard";export*from"./GridLayout";export*from"./Panel";export*from"./TimeRangeControls";export*from"./Variables";
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './Dashboard';
14
+ export * from './GridLayout';
15
+ export * from './Panel';
16
+ export * from './PanelDrawer';
17
+ export * from './TimeRangeControls';
18
+ export * from './Variables';
19
+
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './Dashboard';\nexport * from './GridLayout';\nexport * from './Panel';\nexport * from './PanelDrawer';\nexport * from './TimeRangeControls';\nexport * from './Variables';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC"}
@@ -1 +1,45 @@
1
- import{immer}from"zustand/middleware/immer";import{useDashboardStore}from"./DashboardProvider";export const createDashboardAppSlice=immer((e=>({openPanelDrawer:({groupIndex:a,panelKey:r})=>e((e=>{e.panelDrawer={groupIndex:a,panelKey:r}})),closePanelDrawer:()=>e((e=>{e.panelDrawer=void 0})),openPanelGroupDialog:a=>e((e=>{e.panelGroupDialog={groupIndex:a}})),closePanelGroupDialog:()=>e((e=>{e.panelGroupDialog=void 0}))})));export function useDashboardApp(){return useDashboardStore((({panelDrawer:e,openPanelDrawer:a,closePanelDrawer:r,panelGroupDialog:o,openPanelGroupDialog:l,closePanelGroupDialog:p})=>({panelDrawer:e,openPanelDrawer:a,closePanelDrawer:r,panelGroupDialog:o,openPanelGroupDialog:l,closePanelGroupDialog:p})))}
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { immer } from 'zustand/middleware/immer';
14
+ import { useDashboardStore } from './DashboardProvider';
15
+ export const createDashboardAppSlice = immer((set)=>({
16
+ openPanelDrawer: ({ groupIndex , panelKey })=>set((state)=>{
17
+ state.panelDrawer = {
18
+ groupIndex,
19
+ panelKey
20
+ };
21
+ }),
22
+ closePanelDrawer: ()=>set((state)=>{
23
+ state.panelDrawer = undefined;
24
+ }),
25
+ openPanelGroupDialog: (groupIndex)=>set((state)=>{
26
+ state.panelGroupDialog = {
27
+ groupIndex
28
+ };
29
+ }),
30
+ closePanelGroupDialog: ()=>set((state)=>{
31
+ state.panelGroupDialog = undefined;
32
+ })
33
+ }));
34
+ export function useDashboardApp() {
35
+ return useDashboardStore(({ panelDrawer , openPanelDrawer , closePanelDrawer , panelGroupDialog , openPanelGroupDialog , closePanelGroupDialog , })=>({
36
+ panelDrawer,
37
+ openPanelDrawer,
38
+ closePanelDrawer,
39
+ panelGroupDialog,
40
+ openPanelGroupDialog,
41
+ closePanelGroupDialog
42
+ }));
43
+ }
44
+
45
+ //# sourceMappingURL=DashboardAppSlice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/context/DashboardAppSlice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { immer } from 'zustand/middleware/immer';\nimport { useDashboardStore } from './DashboardProvider';\n\ninterface PanelDrawer {\n groupIndex?: number;\n panelKey?: string;\n}\ninterface PanelGroupDialog {\n groupIndex?: number;\n}\n\nexport interface DashboardAppSlice {\n panelDrawer?: PanelDrawer;\n openPanelDrawer: (panelDrawer: PanelDrawer) => void;\n closePanelDrawer: () => void;\n panelGroupDialog?: PanelGroupDialog;\n openPanelGroupDialog: (groupIndex?: number) => void;\n closePanelGroupDialog: () => void;\n}\n\nexport const createDashboardAppSlice = immer<DashboardAppSlice>((set) => ({\n openPanelDrawer: ({ groupIndex, panelKey }: PanelDrawer) =>\n set((state) => {\n state.panelDrawer = {\n groupIndex,\n panelKey,\n };\n }),\n closePanelDrawer: () =>\n set((state) => {\n state.panelDrawer = undefined;\n }),\n openPanelGroupDialog: (groupIndex?: number) =>\n set((state) => {\n state.panelGroupDialog = { groupIndex };\n }),\n closePanelGroupDialog: () =>\n set((state) => {\n state.panelGroupDialog = undefined;\n }),\n}));\n\nexport function useDashboardApp() {\n return useDashboardStore(\n ({\n panelDrawer,\n openPanelDrawer,\n closePanelDrawer,\n panelGroupDialog,\n openPanelGroupDialog,\n closePanelGroupDialog,\n }) => ({\n panelDrawer,\n openPanelDrawer,\n closePanelDrawer,\n panelGroupDialog,\n openPanelGroupDialog,\n closePanelGroupDialog,\n })\n );\n}\n"],"names":["immer","useDashboardStore","createDashboardAppSlice","set","openPanelDrawer","groupIndex","panelKey","state","panelDrawer","closePanelDrawer","undefined","openPanelGroupDialog","panelGroupDialog","closePanelGroupDialog","useDashboardApp"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,KAAK,QAAQ,0BAA0B,CAAC;AACjD,SAASC,iBAAiB,QAAQ,qBAAqB,CAAC;AAmBxD,OAAO,MAAMC,uBAAuB,GAAGF,KAAK,CAAoB,CAACG,GAAG,GAAM,CAAA;QACxEC,eAAe,EAAE,CAAC,EAAEC,UAAU,CAAA,EAAEC,QAAQ,CAAA,EAAe,GACrDH,GAAG,CAAC,CAACI,KAAK,GAAK;gBACbA,KAAK,CAACC,WAAW,GAAG;oBAClBH,UAAU;oBACVC,QAAQ;iBACT,CAAC;YACJ,CAAC,CAAC;QACJG,gBAAgB,EAAE,IAChBN,GAAG,CAAC,CAACI,KAAK,GAAK;gBACbA,KAAK,CAACC,WAAW,GAAGE,SAAS,CAAC;YAChC,CAAC,CAAC;QACJC,oBAAoB,EAAE,CAACN,UAAmB,GACxCF,GAAG,CAAC,CAACI,KAAK,GAAK;gBACbA,KAAK,CAACK,gBAAgB,GAAG;oBAAEP,UAAU;iBAAE,CAAC;YAC1C,CAAC,CAAC;QACJQ,qBAAqB,EAAE,IACrBV,GAAG,CAAC,CAACI,KAAK,GAAK;gBACbA,KAAK,CAACK,gBAAgB,GAAGF,SAAS,CAAC;YACrC,CAAC,CAAC;KACL,CAAA,AAAC,CAAC,CAAC;AAEJ,OAAO,SAASI,eAAe,GAAG;IAChC,OAAOb,iBAAiB,CACtB,CAAC,EACCO,WAAW,CAAA,EACXJ,eAAe,CAAA,EACfK,gBAAgB,CAAA,EAChBG,gBAAgB,CAAA,EAChBD,oBAAoB,CAAA,EACpBE,qBAAqB,CAAA,IACtB,GAAM,CAAA;YACLL,WAAW;YACXJ,eAAe;YACfK,gBAAgB;YAChBG,gBAAgB;YAChBD,oBAAoB;YACpBE,qBAAqB;SACtB,CAAA,AAAC,CACH,CAAC;AACJ,CAAC"}
@@ -1,4 +1,5 @@
1
1
  /// <reference types="react" />
2
+ import type { StoreApi } from 'zustand';
2
3
  import { DashboardSpec, LayoutDefinition, PanelDefinition } from '@perses-dev/core';
3
4
  import { DashboardAppSlice } from './DashboardAppSlice';
4
5
  import { LayoutsSlice } from './LayoutsSlice';
@@ -19,8 +20,8 @@ export interface DashboardProviderProps {
19
20
  children?: React.ReactNode;
20
21
  }
21
22
  export declare function usePanels(): {
22
- panels: Record<string, PanelDefinition<import("@perses-dev/core").JsonObject>>;
23
- updatePanel: (name: string, panel: PanelDefinition<import("@perses-dev/core").JsonObject>, groupIndex?: number | undefined) => void;
23
+ panels: Record<string, PanelDefinition<unknown>>;
24
+ updatePanel: (name: string, panel: PanelDefinition<unknown>, groupIndex?: number | undefined) => void;
24
25
  };
25
26
  export declare function useEditMode(): {
26
27
  isEditMode: boolean;
@@ -29,6 +30,7 @@ export declare function useEditMode(): {
29
30
  export declare function useDashboard(): {
30
31
  dashboard: DashboardSpec;
31
32
  };
33
+ export declare const DashboardContext: import("react").Context<StoreApi<DashboardStoreState> | undefined>;
32
34
  export declare function useDashboardStore<T>(selector: (state: DashboardStoreState) => T): T;
33
35
  export declare function DashboardProvider(props: DashboardProviderProps): JSX.Element;
34
36
  //# sourceMappingURL=DashboardProvider.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardProvider.d.ts","sourceRoot":"","sources":["../../src/context/DashboardProvider.tsx"],"names":[],"mappings":";AAmBA,OAAO,EAAE,aAAa,EAAsB,gBAAgB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxG,OAAO,EAAE,iBAAiB,EAA2B,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,YAAY,EAAsB,MAAM,gBAAgB,CAAC;AAElE,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB,EAAE,YAAY;IAC1E,SAAS,EAAE,aAAa,CAAC;IACzB,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACxC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACjF,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AACD,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,m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,CAAC;CAC5B;AAED,wBAAgB,SAAS;;;EAExB;AAED,wBAAgB,WAAW;;;EAE1B;AAED,wBAAgB,YAAY;;EAU3B;AAED,eAAO,MAAM,gBAAgB,oEAAsE,CAAC;AAEpG,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,CAAC,KAM/E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eAsD9D"}
@@ -1 +1,107 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{createStore,useStore}from"zustand";import{immer}from"zustand/middleware/immer";import shallow from"zustand/shallow";import{createContext,useContext}from"react";import produce from"immer";import{createDashboardAppSlice}from"./DashboardAppSlice";import{createLayoutsSlice}from"./LayoutsSlice";export function usePanels(){return useDashboardStore((({panels:e,updatePanel:o})=>({panels:e,updatePanel:o})))}export function useEditMode(){return useDashboardStore((({isEditMode:e,setEditMode:o})=>({isEditMode:e,setEditMode:o})))}export function useDashboard(){return{dashboard:useDashboardStore((e=>produce(e.dashboard,(o=>{o.panels=e.panels,o.layouts=e.layouts}))))}}const DashboardContext=createContext(void 0);export function useDashboardStore(e){const o=useContext(DashboardContext);if(void 0===o)throw new Error("No DashboardContext found. Did you forget a Provider?");return useStore(o,e,shallow)}export function DashboardProvider(e){const{children:o,initialState:{dashboardSpec:t,isEditMode:r}}=e,{layouts:a,panels:s}=t,d=createStore()(immer(((e,o,d)=>({...createDashboardAppSlice(e,o,d,[]),...createLayoutsSlice(e,o,d,[]),layouts:a,panels:s,dashboard:t,updatePanel:(o,t,r=0)=>e((e=>{var a,s;if(void 0===e.panels[o]){let t=0;null===(a=e.layouts[r])||void 0===a||a.spec.items.forEach((e=>{e.y>t&&(t=e.y)}));const d={x:0,y:t+1,width:12,height:6,content:{$ref:`#/spec/panels/${o}`}},i=e.layouts;i&&i[r]&&(null===(s=i[r])||void 0===s||s.spec.items.push(d))}e.panels[o]=t})),isEditMode:!!r,setEditMode:o=>e({isEditMode:o})}))));return _jsx(DashboardContext.Provider,{value:d,children:o})}
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { createStore, useStore } from 'zustand';
15
+ import { immer } from 'zustand/middleware/immer';
16
+ import shallow from 'zustand/shallow';
17
+ import { createContext, useContext } from 'react';
18
+ import produce from 'immer';
19
+ import { createDashboardAppSlice } from './DashboardAppSlice';
20
+ import { createLayoutsSlice } from './LayoutsSlice';
21
+ export function usePanels() {
22
+ return useDashboardStore(({ panels , updatePanel })=>({
23
+ panels,
24
+ updatePanel
25
+ }));
26
+ }
27
+ export function useEditMode() {
28
+ return useDashboardStore(({ isEditMode , setEditMode })=>({
29
+ isEditMode,
30
+ setEditMode
31
+ }));
32
+ }
33
+ export function useDashboard() {
34
+ const selectDashboardSpec = (state)=>{
35
+ return produce(state.dashboard, (draftState)=>{
36
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
37
+ draftState.panels = state.panels;
38
+ draftState.layouts = state.layouts;
39
+ });
40
+ };
41
+ const dashboard = useDashboardStore(selectDashboardSpec);
42
+ return {
43
+ dashboard
44
+ };
45
+ }
46
+ export const DashboardContext = /*#__PURE__*/ createContext(undefined);
47
+ export function useDashboardStore(selector) {
48
+ const store = useContext(DashboardContext);
49
+ if (store === undefined) {
50
+ throw new Error('No DashboardContext found. Did you forget a Provider?');
51
+ }
52
+ return useStore(store, selector, shallow);
53
+ }
54
+ export function DashboardProvider(props) {
55
+ const { children , initialState: { dashboardSpec , isEditMode } , } = props;
56
+ const { layouts , panels } = dashboardSpec;
57
+ const dashboardStore = createStore()(immer((set, get, api)=>{
58
+ return {
59
+ ...createDashboardAppSlice(set, get, api, []),
60
+ ...createLayoutsSlice(set, get, api, []),
61
+ layouts,
62
+ panels,
63
+ dashboard: dashboardSpec,
64
+ updatePanel: (name, panel, groupIndex = 0)=>{
65
+ return set((state)=>{
66
+ // add new panel to layouts if panels[name] is undefined
67
+ if (state.panels[name] === undefined) {
68
+ var ref;
69
+ // find maximum y so new panel is added to the end of the grid
70
+ let maxY = 0;
71
+ (ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.spec.items.forEach((layout)=>{
72
+ if (layout.y > maxY) {
73
+ maxY = layout.y;
74
+ }
75
+ });
76
+ const panelLayout = {
77
+ x: 0,
78
+ y: maxY + 1,
79
+ width: 12,
80
+ height: 6,
81
+ content: {
82
+ $ref: `#/spec/panels/${name}`
83
+ }
84
+ };
85
+ const layouts = state.layouts;
86
+ if (layouts && layouts[groupIndex]) {
87
+ var ref1;
88
+ (ref1 = layouts[groupIndex]) === null || ref1 === void 0 ? void 0 : ref1.spec.items.push(panelLayout);
89
+ }
90
+ }
91
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
92
+ state.panels[name] = panel;
93
+ });
94
+ },
95
+ isEditMode: !!isEditMode,
96
+ setEditMode: (isEditMode)=>set({
97
+ isEditMode
98
+ })
99
+ };
100
+ }));
101
+ return /*#__PURE__*/ _jsx(DashboardContext.Provider, {
102
+ value: dashboardStore,
103
+ children: children
104
+ });
105
+ }
106
+
107
+ //# sourceMappingURL=DashboardProvider.js.map