@perses-dev/dashboards 0.24.0 → 0.26.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 (161) hide show
  1. package/dist/cjs/components/AddPanelButton/AddPanelButton.js +9 -2
  2. package/dist/cjs/components/Dashboard/Dashboard.js +23 -6
  3. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +8 -17
  4. package/dist/cjs/components/EditButton/EditButton.js +41 -0
  5. package/dist/cjs/components/EditButton/index.js +28 -0
  6. package/dist/cjs/components/EditJsonButton/EditJsonButton.js +42 -0
  7. package/dist/cjs/components/EditJsonButton/index.js +28 -0
  8. package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +86 -0
  9. package/dist/cjs/components/EditJsonDialog/index.js +28 -0
  10. package/dist/cjs/components/EmptyDashboard/EmptyDashboard.js +128 -0
  11. package/dist/cjs/components/EmptyDashboard/index.js +28 -0
  12. package/dist/cjs/components/Panel/Panel.js +0 -4
  13. package/dist/cjs/components/Panel/PanelHeader.js +2 -2
  14. package/dist/cjs/components/QuerySummaryTable/QuerySummaryTable.js +185 -0
  15. package/dist/cjs/components/QuerySummaryTable/index.js +28 -0
  16. package/dist/cjs/components/ToolbarIconButton/ToolbarIconButton.js +6 -3
  17. package/dist/cjs/components/Variables/EditVariablesButton.js +9 -2
  18. package/dist/cjs/components/index.js +4 -0
  19. package/dist/cjs/constants/user-interface-text.js +1 -0
  20. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +12 -6
  21. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +10 -1
  22. package/dist/cjs/context/DashboardProvider/edit-json-dialog-slice.js +36 -0
  23. package/dist/cjs/context/DatasourceStoreProvider.js +9 -3
  24. package/dist/cjs/context/TemplateVariableProvider/TemplateVariableProvider.js +3 -41
  25. package/dist/cjs/context/TemplateVariableProvider/hydrationUtils.js +68 -0
  26. package/dist/cjs/stories/decorators/WithDashboard.js +39 -0
  27. package/dist/cjs/stories/decorators/WithDatasourceStore.js +82 -0
  28. package/dist/cjs/stories/decorators/WithPluginRegistry.js +91 -0
  29. package/dist/cjs/stories/decorators/WithQueryClient.js +29 -0
  30. package/dist/cjs/stories/decorators/WithQueryParams.js +29 -0
  31. package/dist/cjs/stories/decorators/WithTemplateVariables.js +35 -0
  32. package/dist/cjs/stories/decorators/WithTimeRange.js +38 -0
  33. package/dist/cjs/stories/decorators/constants.js +36 -0
  34. package/dist/cjs/stories/decorators/index.js +35 -0
  35. package/dist/cjs/views/ViewDashboard/DashboardApp.js +11 -4
  36. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +2 -1
  37. package/dist/components/AddPanelButton/AddPanelButton.d.ts +16 -1
  38. package/dist/components/AddPanelButton/AddPanelButton.d.ts.map +1 -1
  39. package/dist/components/AddPanelButton/AddPanelButton.js +9 -2
  40. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  41. package/dist/components/Dashboard/Dashboard.d.ts +10 -2
  42. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
  43. package/dist/components/Dashboard/Dashboard.js +24 -7
  44. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  45. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  46. package/dist/components/DashboardToolbar/DashboardToolbar.js +8 -12
  47. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  48. package/dist/components/EditButton/EditButton.d.ts +13 -0
  49. package/dist/components/EditButton/EditButton.d.ts.map +1 -0
  50. package/dist/components/EditButton/EditButton.js +30 -0
  51. package/dist/components/EditButton/EditButton.js.map +1 -0
  52. package/dist/components/EditButton/index.d.ts +2 -0
  53. package/dist/components/EditButton/index.d.ts.map +1 -0
  54. package/dist/components/EditButton/index.js +15 -0
  55. package/dist/components/EditButton/index.js.map +1 -0
  56. package/dist/components/EditJsonButton/EditJsonButton.d.ts +3 -0
  57. package/dist/components/EditJsonButton/EditJsonButton.d.ts.map +1 -0
  58. package/dist/components/EditJsonButton/EditJsonButton.js +31 -0
  59. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -0
  60. package/dist/components/EditJsonButton/index.d.ts +2 -0
  61. package/dist/components/EditJsonButton/index.d.ts.map +1 -0
  62. package/dist/components/EditJsonButton/index.js +15 -0
  63. package/dist/components/EditJsonButton/index.js.map +1 -0
  64. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts +3 -0
  65. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -0
  66. package/dist/components/EditJsonDialog/EditJsonDialog.js +80 -0
  67. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -0
  68. package/dist/components/EditJsonDialog/index.d.ts +2 -0
  69. package/dist/components/EditJsonDialog/index.d.ts.map +1 -0
  70. package/dist/components/EditJsonDialog/index.js +15 -0
  71. package/dist/components/EditJsonDialog/index.js.map +1 -0
  72. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts +37 -0
  73. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts.map +1 -0
  74. package/dist/components/EmptyDashboard/EmptyDashboard.js +124 -0
  75. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -0
  76. package/dist/components/EmptyDashboard/index.d.ts +2 -0
  77. package/dist/components/EmptyDashboard/index.d.ts.map +1 -0
  78. package/dist/components/EmptyDashboard/index.js +15 -0
  79. package/dist/components/EmptyDashboard/index.js.map +1 -0
  80. package/dist/components/Panel/Panel.d.ts.map +1 -1
  81. package/dist/components/Panel/Panel.js +0 -4
  82. package/dist/components/Panel/Panel.js.map +1 -1
  83. package/dist/components/Panel/PanelHeader.d.ts +1 -2
  84. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  85. package/dist/components/Panel/PanelHeader.js +2 -2
  86. package/dist/components/Panel/PanelHeader.js.map +1 -1
  87. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts +11 -0
  88. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts.map +1 -0
  89. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +179 -0
  90. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -0
  91. package/dist/components/QuerySummaryTable/index.d.ts +2 -0
  92. package/dist/components/QuerySummaryTable/index.d.ts.map +1 -0
  93. package/dist/components/QuerySummaryTable/index.js +15 -0
  94. package/dist/components/QuerySummaryTable/index.js.map +1 -0
  95. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts +1 -1
  96. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts.map +1 -1
  97. package/dist/components/ToolbarIconButton/ToolbarIconButton.js +6 -3
  98. package/dist/components/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
  99. package/dist/components/Variables/EditVariablesButton.d.ts +16 -1
  100. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  101. package/dist/components/Variables/EditVariablesButton.js +9 -2
  102. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  103. package/dist/components/index.d.ts +4 -0
  104. package/dist/components/index.d.ts.map +1 -1
  105. package/dist/components/index.js +4 -0
  106. package/dist/components/index.js.map +1 -1
  107. package/dist/constants/user-interface-text.d.ts +1 -0
  108. package/dist/constants/user-interface-text.d.ts.map +1 -1
  109. package/dist/constants/user-interface-text.js +1 -0
  110. package/dist/constants/user-interface-text.js.map +1 -1
  111. package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -1
  112. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  113. package/dist/context/DashboardProvider/DashboardProvider.js +12 -6
  114. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  115. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +8 -0
  116. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  117. package/dist/context/DashboardProvider/dashboard-provider-api.js +10 -0
  118. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  119. package/dist/context/DashboardProvider/edit-json-dialog-slice.d.ts +12 -0
  120. package/dist/context/DashboardProvider/edit-json-dialog-slice.d.ts.map +1 -0
  121. package/dist/context/DashboardProvider/edit-json-dialog-slice.js +30 -0
  122. package/dist/context/DashboardProvider/edit-json-dialog-slice.js.map +1 -0
  123. package/dist/context/DatasourceStoreProvider.d.ts +2 -0
  124. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  125. package/dist/context/DatasourceStoreProvider.js +9 -3
  126. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  127. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +3 -2
  128. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -1
  129. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js +1 -39
  130. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -1
  131. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts +4 -0
  132. package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +1 -0
  133. package/dist/context/TemplateVariableProvider/hydrationUtils.js +62 -0
  134. package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +1 -0
  135. package/dist/stories/decorators/WithDashboard.js +33 -0
  136. package/dist/stories/decorators/WithDashboard.js.map +1 -0
  137. package/dist/stories/decorators/WithDatasourceStore.js +76 -0
  138. package/dist/stories/decorators/WithDatasourceStore.js.map +1 -0
  139. package/dist/stories/decorators/WithPluginRegistry.js +46 -0
  140. package/dist/stories/decorators/WithPluginRegistry.js.map +1 -0
  141. package/dist/stories/decorators/WithQueryClient.js +23 -0
  142. package/dist/stories/decorators/WithQueryClient.js.map +1 -0
  143. package/dist/stories/decorators/WithQueryParams.js +23 -0
  144. package/dist/stories/decorators/WithQueryParams.js.map +1 -0
  145. package/dist/stories/decorators/WithTemplateVariables.js +29 -0
  146. package/dist/stories/decorators/WithTemplateVariables.js.map +1 -0
  147. package/dist/stories/decorators/WithTimeRange.js +32 -0
  148. package/dist/stories/decorators/WithTimeRange.js.map +1 -0
  149. package/dist/stories/decorators/constants.js +30 -0
  150. package/dist/stories/decorators/constants.js.map +1 -0
  151. package/dist/stories/decorators/index.js +22 -0
  152. package/dist/stories/decorators/index.js.map +1 -0
  153. package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -0
  154. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  155. package/dist/views/ViewDashboard/DashboardApp.js +12 -5
  156. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  157. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -8
  158. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  159. package/dist/views/ViewDashboard/ViewDashboard.js +2 -1
  160. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  161. package/package.json +4 -4
@@ -0,0 +1,185 @@
1
+ // Copyright 2023 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "QuerySummaryTable", {
18
+ enumerable: true,
19
+ get: ()=>QuerySummaryTable
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _reactQuery = require("@tanstack/react-query");
24
+ const _pluginSystem = require("@perses-dev/plugin-system");
25
+ const TABLE_MAX_WIDTH = 1000;
26
+ function QuerySummaryTable(props) {
27
+ const { showTotalQueries =true } = props;
28
+ const datasourcClient = (0, _pluginSystem.useDatasourceClient)({
29
+ kind: 'PrometheusDatasource'
30
+ });
31
+ const { absoluteTimeRange } = (0, _pluginSystem.useTimeRange)();
32
+ // for displaying a summary of recent query results
33
+ const queryClient = (0, _reactQuery.useQueryClient)();
34
+ const queries = queryClient.getQueryCache().findAll();
35
+ const activeQueries = queries.filter((query)=>query.state.status === 'loading');
36
+ const completedQueries = queries.filter((query)=>query.state.status === 'success');
37
+ const querySummary = (0, _pluginSystem.useActiveTimeSeriesQueries)();
38
+ if (datasourcClient.isLoading === true) {
39
+ return null;
40
+ }
41
+ const warnings = [];
42
+ querySummary.forEach((query)=>{
43
+ var ref;
44
+ const queryData = query.state.data;
45
+ if (queryData && ((ref = queryData.metadata) === null || ref === void 0 ? void 0 : ref.notices)) {
46
+ var ref1;
47
+ const queryKey = query.queryKey;
48
+ const warningMessage = (ref1 = queryData.metadata.notices[0]) === null || ref1 === void 0 ? void 0 : ref1.message;
49
+ if (warningMessage) {
50
+ warnings.push({
51
+ query: String(queryKey[0].spec.plugin.spec.query),
52
+ summary: warningMessage
53
+ });
54
+ }
55
+ }
56
+ });
57
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
58
+ spacing: 1,
59
+ mb: 2,
60
+ sx: {
61
+ maxWidth: TABLE_MAX_WIDTH
62
+ },
63
+ children: [
64
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
65
+ sx: {
66
+ p: 1
67
+ },
68
+ children: [
69
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
70
+ variant: "h2",
71
+ mb: 1,
72
+ children: "Query Summary"
73
+ }),
74
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableContainer, {
75
+ component: _material.Paper,
76
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Table, {
77
+ size: "small",
78
+ "aria-label": "query summary table",
79
+ children: [
80
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableHead, {
81
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.TableRow, {
82
+ children: [
83
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
84
+ children: "Queries Loading"
85
+ }),
86
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
87
+ children: "Recent Time Series Queries"
88
+ }),
89
+ showTotalQueries && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
90
+ children: "Total Queries"
91
+ }),
92
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
93
+ children: "Start Time"
94
+ }),
95
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
96
+ children: "End Time"
97
+ })
98
+ ]
99
+ })
100
+ }),
101
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableBody, {
102
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.TableRow, {
103
+ children: [
104
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
105
+ children: activeQueries.length
106
+ }),
107
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
108
+ children: querySummary.length
109
+ }),
110
+ showTotalQueries && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
111
+ children: completedQueries.length
112
+ }),
113
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
114
+ children: absoluteTimeRange.start.toString()
115
+ }),
116
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
117
+ children: absoluteTimeRange.end.toString()
118
+ })
119
+ ]
120
+ })
121
+ })
122
+ ]
123
+ })
124
+ })
125
+ ]
126
+ }),
127
+ warnings.length > 0 && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
128
+ sx: {
129
+ p: 1,
130
+ m: 0
131
+ },
132
+ children: [
133
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
134
+ variant: "h3",
135
+ mb: 1,
136
+ children: "Warnings"
137
+ }),
138
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableContainer, {
139
+ component: _material.Paper,
140
+ sx: {
141
+ mb: 2
142
+ },
143
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Table, {
144
+ size: "small",
145
+ "aria-label": "query warnings table",
146
+ children: [
147
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableHead, {
148
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.TableRow, {
149
+ children: [
150
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
151
+ children: "Query"
152
+ }),
153
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
154
+ children: "Summary"
155
+ })
156
+ ]
157
+ })
158
+ }),
159
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableBody, {
160
+ children: warnings.map((details, idx)=>{
161
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.TableRow, {
162
+ children: [
163
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
164
+ children: details.query
165
+ }),
166
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
167
+ children: details.summary
168
+ })
169
+ ]
170
+ }, idx);
171
+ })
172
+ })
173
+ ]
174
+ })
175
+ }),
176
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
177
+ disabled: true,
178
+ variant: "outlined",
179
+ children: "TODO: Action Button"
180
+ })
181
+ ]
182
+ })
183
+ ]
184
+ });
185
+ }
@@ -0,0 +1,28 @@
1
+ // Copyright 2023 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./QuerySummaryTable"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -19,17 +19,20 @@ Object.defineProperty(exports, "ToolbarIconButton", {
19
19
  get: ()=>ToolbarIconButton
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
22
23
  const _material = require("@mui/material");
23
- function ToolbarIconButton(props) {
24
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(IconButton, {
24
+ function IconButton(props, ref) {
25
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledIconButton, {
26
+ ref: ref,
25
27
  variant: "outlined",
26
28
  color: "secondary",
27
29
  ...props
28
30
  });
29
31
  }
30
- const IconButton = (0, _material.styled)(_material.Button)(({ theme })=>({
32
+ const StyledIconButton = (0, _material.styled)(_material.Button)(({ theme })=>({
31
33
  // Using a button with some adjusted styles because it is easier to inherit
32
34
  // styling and variants from themes than with an IconButton.
33
35
  padding: theme.spacing(0.5),
34
36
  minWidth: 'auto'
35
37
  }));
38
+ const ToolbarIconButton = /*#__PURE__*/ (0, _react.forwardRef)(IconButton);
@@ -31,7 +31,7 @@ function _interopRequireDefault(obj) {
31
31
  default: obj
32
32
  };
33
33
  }
34
- function EditVariablesButton() {
34
+ function EditVariablesButton({ variant ='text' , label ='Variables' , color ='primary' , fullWidth }) {
35
35
  const [isVariableEditorOpen, setIsVariableEditorOpen] = (0, _react.useState)(false);
36
36
  const variableDefinitions = (0, _context.useTemplateVariableDefinitions)();
37
37
  const { setVariableDefinitions } = (0, _context.useTemplateVariableActions)();
@@ -49,7 +49,14 @@ function EditVariablesButton() {
49
49
  startIcon: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencilOutline.default, {}),
50
50
  onClick: openVariableEditor,
51
51
  "aria-label": _constants.TOOLTIP_TEXT.editVariables,
52
- children: "Variables"
52
+ variant: variant,
53
+ color: color,
54
+ fullWidth: fullWidth,
55
+ sx: {
56
+ whiteSpace: 'nowrap',
57
+ minWidth: 'auto'
58
+ },
59
+ children: label
53
60
  })
54
61
  }),
55
62
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Drawer, {
@@ -22,10 +22,14 @@ _exportStar(require("./DeletePanelDialog"), exports);
22
22
  _exportStar(require("./DeletePanelGroupDialog"), exports);
23
23
  _exportStar(require("./DiscardChangesConfirmationDialog"), exports);
24
24
  _exportStar(require("./DownloadButton"), exports);
25
+ _exportStar(require("./EditJsonButton"), exports);
26
+ _exportStar(require("./EditJsonDialog"), exports);
27
+ _exportStar(require("./EmptyDashboard"), exports);
25
28
  _exportStar(require("./GridLayout"), exports);
26
29
  _exportStar(require("./Panel"), exports);
27
30
  _exportStar(require("./PanelDrawer"), exports);
28
31
  _exportStar(require("./PanelGroupDialog"), exports);
32
+ _exportStar(require("./QuerySummaryTable"), exports);
29
33
  _exportStar(require("./TimeRangeControls"), exports);
30
34
  _exportStar(require("./ToolbarIconButton"), exports);
31
35
  _exportStar(require("./Variables"), exports);
@@ -29,6 +29,7 @@ const TOOLTIP_TEXT = {
29
29
  addPanel: 'Add panel',
30
30
  addGroup: 'Add panel group',
31
31
  downloadDashboard: 'Download JSON',
32
+ editJson: 'Edit JSON',
32
33
  editVariables: 'Edit variables',
33
34
  refreshDashboard: 'Refresh dashboard',
34
35
  // Group buttons
@@ -40,6 +40,7 @@ const _deletePanelGroupSlice = require("./delete-panel-group-slice");
40
40
  const _deletePanelSlice = require("./delete-panel-slice");
41
41
  const _discardChangesDialogSlice = require("./discard-changes-dialog-slice");
42
42
  const _duplicatePanelSlice = require("./duplicate-panel-slice");
43
+ const _editJsonDialogSlice = require("./edit-json-dialog-slice");
43
44
  const DashboardContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
44
45
  function useDashboardStore(selector) {
45
46
  const store = (0, _react.useContext)(DashboardContext);
@@ -80,18 +81,23 @@ function DashboardProvider(props) {
80
81
  }
81
82
  function initStore(props) {
82
83
  const { initialState: { dashboardResource , isEditMode } , } = props;
83
- const { spec: { display , layouts , panels , duration } , metadata , } = dashboardResource;
84
+ const { spec: { display , duration } , metadata , } = dashboardResource;
85
+ let { spec: { layouts , panels } , } = dashboardResource;
86
+ // Set fallbacks in case the frontend is used with a non-Perses backend
87
+ layouts = layouts !== null && layouts !== void 0 ? layouts : [];
88
+ panels = panels !== null && panels !== void 0 ? panels : {};
84
89
  const store = (0, _zustand.createStore)()((0, _immer.immer)((0, _middleware.devtools)((...args)=>{
85
90
  const [set] = args;
86
91
  return {
87
- ...(0, _panelGroupSlice.createPanelGroupSlice)(layouts)(...args),
88
- ...(0, _panelSlice.createPanelSlice)(panels)(...args),
92
+ /* Groups */ ...(0, _panelGroupSlice.createPanelGroupSlice)(layouts)(...args),
89
93
  ...(0, _panelGroupEditorSlice.createPanelGroupEditorSlice)(...args),
90
94
  ...(0, _deletePanelGroupSlice.createDeletePanelGroupSlice)(...args),
95
+ /* Panels */ ...(0, _panelSlice.createPanelSlice)(panels)(...args),
91
96
  ...(0, _panelEditorSlice.createPanelEditorSlice)()(...args),
92
97
  ...(0, _deletePanelSlice.createDeletePanelSlice)()(...args),
93
- ...(0, _discardChangesDialogSlice.createDiscardChangesDialogSlice)(...args),
94
98
  ...(0, _duplicatePanelSlice.createDuplicatePanelSlice)()(...args),
99
+ /* General */ ...(0, _discardChangesDialogSlice.createDiscardChangesDialogSlice)(...args),
100
+ ...(0, _editJsonDialogSlice.createEditJsonDialogSlice)(...args),
95
101
  metadata,
96
102
  display,
97
103
  defaultTimeRange: {
@@ -101,12 +107,12 @@ function initStore(props) {
101
107
  setEditMode: (isEditMode)=>set({
102
108
  isEditMode
103
109
  }),
104
- setDashboard: ({ metadata , spec: { display , panels , layouts } })=>{
110
+ setDashboard: ({ metadata , spec: { display , panels ={} , layouts =[] } })=>{
105
111
  set((state)=>{
106
112
  state.metadata = metadata;
107
113
  state.display = display;
108
- const { panelGroups , panelGroupOrder } = (0, _panelGroupSlice.convertLayoutsToPanelGroups)(layouts);
109
114
  state.panels = panels;
115
+ const { panelGroups , panelGroupOrder } = (0, _panelGroupSlice.convertLayoutsToPanelGroups)(layouts);
110
116
  state.panelGroups = panelGroups;
111
117
  state.panelGroupOrder = panelGroupOrder;
112
118
  });
@@ -34,7 +34,8 @@ _export(exports, {
34
34
  usePanelEditor: ()=>usePanelEditor,
35
35
  useDeletePanelDialog: ()=>useDeletePanelDialog,
36
36
  useDefaultTimeRange: ()=>useDefaultTimeRange,
37
- useDiscardChangesConfirmationDialog: ()=>useDiscardChangesConfirmationDialog
37
+ useDiscardChangesConfirmationDialog: ()=>useDiscardChangesConfirmationDialog,
38
+ useEditJsonDialog: ()=>useEditJsonDialog
38
39
  });
39
40
  const _react = require("react");
40
41
  const _dashboardProvider = require("./DashboardProvider");
@@ -200,3 +201,11 @@ const selectDiscardChangesConfirmationDialog = ({ discardChangesConfirmationDial
200
201
  function useDiscardChangesConfirmationDialog() {
201
202
  return (0, _dashboardProvider.useDashboardStore)(selectDiscardChangesConfirmationDialog);
202
203
  }
204
+ const selectEditJsonDialog = ({ editJsonDialog , openEditJsonDialog , closeEditJsonDialog })=>({
205
+ editJsonDialog,
206
+ openEditJsonDialog,
207
+ closeEditJsonDialog
208
+ });
209
+ function useEditJsonDialog() {
210
+ return (0, _dashboardProvider.useDashboardStore)(selectEditJsonDialog);
211
+ }
@@ -0,0 +1,36 @@
1
+ // Copyright 2023 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "createEditJsonDialogSlice", {
18
+ enumerable: true,
19
+ get: ()=>createEditJsonDialogSlice
20
+ });
21
+ const createEditJsonDialogSlice = (set)=>({
22
+ openEditJsonDialog () {
23
+ set((state)=>{
24
+ state.editJsonDialog = {
25
+ isOpen: true
26
+ };
27
+ });
28
+ },
29
+ closeEditJsonDialog () {
30
+ set((state)=>{
31
+ state.editJsonDialog = {
32
+ isOpen: false
33
+ };
34
+ });
35
+ }
36
+ });
@@ -23,7 +23,7 @@ const _react = require("react");
23
23
  const _core = require("@perses-dev/core");
24
24
  const _pluginSystem = require("@perses-dev/plugin-system");
25
25
  function DatasourceStoreProvider(props) {
26
- const { dashboardResource , datasourceApi , children } = props;
26
+ const { dashboardResource , datasourceApi , onCreate , children } = props;
27
27
  const { project } = dashboardResource.metadata;
28
28
  const { getPlugin , listPluginMetadata } = (0, _pluginSystem.usePluginRegistry)();
29
29
  const findDatasource = (0, _core.useEvent)(async (selector)=>{
@@ -68,12 +68,18 @@ function DatasourceStoreProvider(props) {
68
68
  findDatasource(selector),
69
69
  getPlugin('Datasource', kind)
70
70
  ]);
71
- return plugin.createClient(spec.plugin.spec, {
71
+ // allows extending client
72
+ const client = plugin.createClient(spec.plugin.spec, {
72
73
  proxyUrl
73
74
  });
75
+ if (onCreate !== undefined) {
76
+ return onCreate(client);
77
+ }
78
+ return client;
74
79
  }, [
75
80
  findDatasource,
76
- getPlugin
81
+ getPlugin,
82
+ onCreate
77
83
  ]);
78
84
  const listDatasourceMetadata = (0, _core.useEvent)(async (datasourcePluginKind)=>{
79
85
  const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
@@ -34,6 +34,7 @@ const _zustand = require("zustand");
34
34
  const _immer = require("zustand/middleware/immer");
35
35
  const _middleware = require("zustand/middleware");
36
36
  const _pluginSystem = require("@perses-dev/plugin-system");
37
+ const _hydrationUtils = require("./hydrationUtils");
37
38
  const _queryParams = require("./query-params");
38
39
  const TemplateVariableStoreContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
39
40
  function useTemplateVariableStoreCtx() {
@@ -123,12 +124,12 @@ function PluginProvider({ children }) {
123
124
  function createTemplateVariableSrvStore({ initialVariableDefinitions =[] , queryParams }) {
124
125
  const initialParams = (0, _queryParams.getInitalValuesFromQueryParameters)(queryParams ? queryParams[0] : {});
125
126
  const store = (0, _zustand.createStore)()((0, _middleware.devtools)((0, _immer.immer)((set)=>({
126
- variableState: hydrateTemplateVariableStates(initialVariableDefinitions, initialParams),
127
+ variableState: (0, _hydrationUtils.hydrateTemplateVariableStates)(initialVariableDefinitions, initialParams),
127
128
  variableDefinitions: initialVariableDefinitions,
128
129
  setVariableDefinitions (definitions) {
129
130
  set((state)=>{
130
131
  state.variableDefinitions = definitions;
131
- state.variableState = hydrateTemplateVariableStates(definitions, initialParams);
132
+ state.variableState = (0, _hydrationUtils.hydrateTemplateVariableStates)(definitions, initialParams);
132
133
  });
133
134
  },
134
135
  setVariableOptions (name, options) {
@@ -187,42 +188,3 @@ function TemplateVariableProvider({ children , initialVariableDefinitions =[] }
187
188
  })
188
189
  });
189
190
  }
190
- /** Helpers */ function hydrateTemplateVariableState(variable, initialValue) {
191
- const varState = {
192
- value: null,
193
- loading: false
194
- };
195
- switch(variable.kind){
196
- case 'TextVariable':
197
- varState.value = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.value;
198
- break;
199
- case 'ListVariable':
200
- varState.options = [];
201
- var ref;
202
- varState.value = (ref = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.default_value) !== null && ref !== void 0 ? ref : null;
203
- if (varState.options.length > 0 && !varState.value) {
204
- var ref1;
205
- var ref2;
206
- const firstOptionValue = (ref2 = (ref1 = varState.options[0]) === null || ref1 === void 0 ? void 0 : ref1.value) !== null && ref2 !== void 0 ? ref2 : null;
207
- if (firstOptionValue !== null) {
208
- varState.value = variable.spec.allow_multiple ? [
209
- firstOptionValue
210
- ] : firstOptionValue;
211
- }
212
- }
213
- break;
214
- default:
215
- break;
216
- }
217
- return varState;
218
- }
219
- function hydrateTemplateVariableStates(definitions, initialValues) {
220
- const state = {};
221
- definitions.forEach((v)=>{
222
- const name = v.spec.name;
223
- const param = initialValues[name];
224
- const initialValue = param ? param : null;
225
- state[name] = hydrateTemplateVariableState(v, initialValue);
226
- });
227
- return state;
228
- }
@@ -0,0 +1,68 @@
1
+ // Copyright 2023 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "hydrateTemplateVariableStates", {
18
+ enumerable: true,
19
+ get: ()=>hydrateTemplateVariableStates
20
+ });
21
+ const _pluginSystem = require("@perses-dev/plugin-system");
22
+ function hydrateTemplateVariableState(variable, initialValue) {
23
+ const varState = {
24
+ value: null,
25
+ loading: false
26
+ };
27
+ switch(variable.kind){
28
+ case 'TextVariable':
29
+ varState.value = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.value;
30
+ break;
31
+ case 'ListVariable':
32
+ varState.options = [];
33
+ var ref;
34
+ varState.value = (ref = initialValue !== null && initialValue !== void 0 ? initialValue : variable.spec.default_value) !== null && ref !== void 0 ? ref : null;
35
+ if (varState.options.length > 0 && !varState.value) {
36
+ var ref1;
37
+ var ref2;
38
+ const firstOptionValue = (ref2 = (ref1 = varState.options[0]) === null || ref1 === void 0 ? void 0 : ref1.value) !== null && ref2 !== void 0 ? ref2 : null;
39
+ if (firstOptionValue !== null) {
40
+ varState.value = variable.spec.allow_multiple ? [
41
+ firstOptionValue
42
+ ] : firstOptionValue;
43
+ }
44
+ }
45
+ // "all" variable handling assumes the value is not in an array. This is
46
+ // handled properly during internal variable interactions, but it is possible
47
+ // to end up in a buggy state if the variables are initialized with an "all"
48
+ // value inside an array. When hydrating variables, normalize this to minimize
49
+ // bugs.
50
+ if (Array.isArray(varState.value) && varState.value.length === 1 && varState.value[0] === _pluginSystem.DEFAULT_ALL_VALUE) {
51
+ varState.value = _pluginSystem.DEFAULT_ALL_VALUE;
52
+ }
53
+ break;
54
+ default:
55
+ break;
56
+ }
57
+ return varState;
58
+ }
59
+ function hydrateTemplateVariableStates(definitions, initialValues) {
60
+ const state = {};
61
+ definitions.forEach((v)=>{
62
+ const name = v.spec.name;
63
+ const param = initialValues[name];
64
+ const initialValue = param ? param : null;
65
+ state[name] = hydrateTemplateVariableState(v, initialValue);
66
+ });
67
+ return state;
68
+ }
@@ -0,0 +1,39 @@
1
+ // Copyright 2023 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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "WithDashboard", {
18
+ enumerable: true,
19
+ get: ()=>WithDashboard
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _dashboards = require("@perses-dev/dashboards");
23
+ const _constants = require("./constants");
24
+ // Type guard because storybook types parameters as `any`
25
+ function isWithDashboardParameter(parameter) {
26
+ return !!parameter && typeof parameter === 'object' && 'props' in parameter;
27
+ }
28
+ const WithDashboard = (Story, context)=>{
29
+ const initParameter = context.parameters.withDashboard;
30
+ const parameter = isWithDashboardParameter(initParameter) ? initParameter : undefined;
31
+ const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
32
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_dashboards.DashboardProvider, {
33
+ initialState: {
34
+ dashboardResource: _constants.EMPTY_DASHBOARD_RESOURCE
35
+ },
36
+ ...props,
37
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(Story, {})
38
+ });
39
+ };