@perses-dev/dashboards 0.24.0 → 0.25.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 (133) 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 +127 -0
  11. package/dist/cjs/components/EmptyDashboard/index.js +28 -0
  12. package/dist/cjs/components/QuerySummaryTable/QuerySummaryTable.js +185 -0
  13. package/dist/cjs/components/QuerySummaryTable/index.js +28 -0
  14. package/dist/cjs/components/ToolbarIconButton/ToolbarIconButton.js +6 -3
  15. package/dist/cjs/components/Variables/EditVariablesButton.js +9 -2
  16. package/dist/cjs/components/index.js +4 -0
  17. package/dist/cjs/constants/user-interface-text.js +1 -0
  18. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +12 -6
  19. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +10 -1
  20. package/dist/cjs/context/DashboardProvider/edit-json-dialog-slice.js +36 -0
  21. package/dist/cjs/context/DatasourceStoreProvider.js +9 -3
  22. package/dist/cjs/stories/decorators/WithDashboard.js +60 -0
  23. package/dist/cjs/stories/decorators/WithPluginRegistry.js +91 -0
  24. package/dist/cjs/stories/decorators/WithQueryClient.js +29 -0
  25. package/dist/cjs/stories/decorators/WithQueryParams.js +29 -0
  26. package/dist/cjs/stories/decorators/WithTemplateVariables.js +27 -0
  27. package/dist/cjs/stories/decorators/index.js +32 -0
  28. package/dist/cjs/views/ViewDashboard/DashboardApp.js +11 -4
  29. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +2 -1
  30. package/dist/components/AddPanelButton/AddPanelButton.d.ts +16 -1
  31. package/dist/components/AddPanelButton/AddPanelButton.d.ts.map +1 -1
  32. package/dist/components/AddPanelButton/AddPanelButton.js +9 -2
  33. package/dist/components/AddPanelButton/AddPanelButton.js.map +1 -1
  34. package/dist/components/Dashboard/Dashboard.d.ts +10 -2
  35. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -1
  36. package/dist/components/Dashboard/Dashboard.js +24 -7
  37. package/dist/components/Dashboard/Dashboard.js.map +1 -1
  38. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  39. package/dist/components/DashboardToolbar/DashboardToolbar.js +8 -12
  40. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  41. package/dist/components/EditButton/EditButton.d.ts +13 -0
  42. package/dist/components/EditButton/EditButton.d.ts.map +1 -0
  43. package/dist/components/EditButton/EditButton.js +30 -0
  44. package/dist/components/EditButton/EditButton.js.map +1 -0
  45. package/dist/components/EditButton/index.d.ts +2 -0
  46. package/dist/components/EditButton/index.d.ts.map +1 -0
  47. package/dist/components/EditButton/index.js +15 -0
  48. package/dist/components/EditButton/index.js.map +1 -0
  49. package/dist/components/EditJsonButton/EditJsonButton.d.ts +3 -0
  50. package/dist/components/EditJsonButton/EditJsonButton.d.ts.map +1 -0
  51. package/dist/components/EditJsonButton/EditJsonButton.js +31 -0
  52. package/dist/components/EditJsonButton/EditJsonButton.js.map +1 -0
  53. package/dist/components/EditJsonButton/index.d.ts +2 -0
  54. package/dist/components/EditJsonButton/index.d.ts.map +1 -0
  55. package/dist/components/EditJsonButton/index.js +15 -0
  56. package/dist/components/EditJsonButton/index.js.map +1 -0
  57. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts +3 -0
  58. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -0
  59. package/dist/components/EditJsonDialog/EditJsonDialog.js +80 -0
  60. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -0
  61. package/dist/components/EditJsonDialog/index.d.ts +2 -0
  62. package/dist/components/EditJsonDialog/index.d.ts.map +1 -0
  63. package/dist/components/EditJsonDialog/index.js +15 -0
  64. package/dist/components/EditJsonDialog/index.js.map +1 -0
  65. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts +33 -0
  66. package/dist/components/EmptyDashboard/EmptyDashboard.d.ts.map +1 -0
  67. package/dist/components/EmptyDashboard/EmptyDashboard.js +123 -0
  68. package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -0
  69. package/dist/components/EmptyDashboard/index.d.ts +2 -0
  70. package/dist/components/EmptyDashboard/index.d.ts.map +1 -0
  71. package/dist/components/EmptyDashboard/index.js +15 -0
  72. package/dist/components/EmptyDashboard/index.js.map +1 -0
  73. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts +11 -0
  74. package/dist/components/QuerySummaryTable/QuerySummaryTable.d.ts.map +1 -0
  75. package/dist/components/QuerySummaryTable/QuerySummaryTable.js +179 -0
  76. package/dist/components/QuerySummaryTable/QuerySummaryTable.js.map +1 -0
  77. package/dist/components/QuerySummaryTable/index.d.ts +2 -0
  78. package/dist/components/QuerySummaryTable/index.d.ts.map +1 -0
  79. package/dist/components/QuerySummaryTable/index.js +15 -0
  80. package/dist/components/QuerySummaryTable/index.js.map +1 -0
  81. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts +1 -1
  82. package/dist/components/ToolbarIconButton/ToolbarIconButton.d.ts.map +1 -1
  83. package/dist/components/ToolbarIconButton/ToolbarIconButton.js +6 -3
  84. package/dist/components/ToolbarIconButton/ToolbarIconButton.js.map +1 -1
  85. package/dist/components/Variables/EditVariablesButton.d.ts +16 -1
  86. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  87. package/dist/components/Variables/EditVariablesButton.js +9 -2
  88. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  89. package/dist/components/index.d.ts +4 -0
  90. package/dist/components/index.d.ts.map +1 -1
  91. package/dist/components/index.js +4 -0
  92. package/dist/components/index.js.map +1 -1
  93. package/dist/constants/user-interface-text.d.ts +1 -0
  94. package/dist/constants/user-interface-text.d.ts.map +1 -1
  95. package/dist/constants/user-interface-text.js +1 -0
  96. package/dist/constants/user-interface-text.js.map +1 -1
  97. package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -1
  98. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  99. package/dist/context/DashboardProvider/DashboardProvider.js +12 -6
  100. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  101. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +8 -0
  102. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  103. package/dist/context/DashboardProvider/dashboard-provider-api.js +10 -0
  104. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  105. package/dist/context/DashboardProvider/edit-json-dialog-slice.d.ts +12 -0
  106. package/dist/context/DashboardProvider/edit-json-dialog-slice.d.ts.map +1 -0
  107. package/dist/context/DashboardProvider/edit-json-dialog-slice.js +30 -0
  108. package/dist/context/DashboardProvider/edit-json-dialog-slice.js.map +1 -0
  109. package/dist/context/DatasourceStoreProvider.d.ts +2 -0
  110. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  111. package/dist/context/DatasourceStoreProvider.js +9 -3
  112. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  113. package/dist/stories/decorators/WithDashboard.js +48 -0
  114. package/dist/stories/decorators/WithDashboard.js.map +1 -0
  115. package/dist/stories/decorators/WithPluginRegistry.js +46 -0
  116. package/dist/stories/decorators/WithPluginRegistry.js.map +1 -0
  117. package/dist/stories/decorators/WithQueryClient.js +23 -0
  118. package/dist/stories/decorators/WithQueryClient.js.map +1 -0
  119. package/dist/stories/decorators/WithQueryParams.js +23 -0
  120. package/dist/stories/decorators/WithQueryParams.js.map +1 -0
  121. package/dist/stories/decorators/WithTemplateVariables.js +21 -0
  122. package/dist/stories/decorators/WithTemplateVariables.js.map +1 -0
  123. package/dist/stories/decorators/index.js +19 -0
  124. package/dist/stories/decorators/index.js.map +1 -0
  125. package/dist/views/ViewDashboard/DashboardApp.d.ts +2 -0
  126. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  127. package/dist/views/ViewDashboard/DashboardApp.js +12 -5
  128. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  129. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -8
  130. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  131. package/dist/views/ViewDashboard/ViewDashboard.js +2 -1
  132. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  133. 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([
@@ -0,0 +1,60 @@
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
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ DEFAULT_DASHBOARD_INITIAL_STATE: ()=>DEFAULT_DASHBOARD_INITIAL_STATE,
25
+ WithDashboard: ()=>WithDashboard
26
+ });
27
+ const _jsxRuntime = require("react/jsx-runtime");
28
+ const _dashboards = require("@perses-dev/dashboards");
29
+ // Type guard because storybook types parameters as `any`
30
+ function isWithDashboardParameter(parameter) {
31
+ return !!parameter && typeof parameter === 'object' && 'props' in parameter;
32
+ }
33
+ const DEFAULT_DASHBOARD_INITIAL_STATE = {
34
+ dashboardResource: {
35
+ kind: 'Dashboard',
36
+ metadata: {
37
+ name: 'My Dashboard',
38
+ project: 'Storybook',
39
+ created_at: '2021-11-09T00:00:00Z',
40
+ updated_at: '2021-11-09T00:00:00Z',
41
+ version: 0
42
+ },
43
+ spec: {
44
+ duration: '1h',
45
+ variables: [],
46
+ layouts: [],
47
+ panels: {}
48
+ }
49
+ }
50
+ };
51
+ const WithDashboard = (Story, context)=>{
52
+ const initParameter = context.parameters.withDashboard;
53
+ const parameter = isWithDashboardParameter(initParameter) ? initParameter : undefined;
54
+ const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
55
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_dashboards.DashboardProvider, {
56
+ initialState: DEFAULT_DASHBOARD_INITIAL_STATE,
57
+ ...props,
58
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(Story, {})
59
+ });
60
+ };
@@ -0,0 +1,91 @@
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, "WithPluginRegistry", {
18
+ enumerable: true,
19
+ get: ()=>WithPluginRegistry
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _pluginSystem = require("@perses-dev/plugin-system");
23
+ function _getRequireWildcardCache(nodeInterop) {
24
+ if (typeof WeakMap !== "function") return null;
25
+ var cacheBabelInterop = new WeakMap();
26
+ var cacheNodeInterop = new WeakMap();
27
+ return (_getRequireWildcardCache = function(nodeInterop) {
28
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
29
+ })(nodeInterop);
30
+ }
31
+ function _interopRequireWildcard(obj, nodeInterop) {
32
+ if (!nodeInterop && obj && obj.__esModule) {
33
+ return obj;
34
+ }
35
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
36
+ return {
37
+ default: obj
38
+ };
39
+ }
40
+ var cache = _getRequireWildcardCache(nodeInterop);
41
+ if (cache && cache.has(obj)) {
42
+ return cache.get(obj);
43
+ }
44
+ var newObj = {};
45
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
46
+ for(var key in obj){
47
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
48
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
49
+ if (desc && (desc.get || desc.set)) {
50
+ Object.defineProperty(newObj, key, desc);
51
+ } else {
52
+ newObj[key] = obj[key];
53
+ }
54
+ }
55
+ }
56
+ newObj.default = obj;
57
+ if (cache) {
58
+ cache.set(obj, newObj);
59
+ }
60
+ return newObj;
61
+ }
62
+ // NOTE: the aliases we use for components break these top level imports, so we
63
+ // import relatively.
64
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
65
+ const prometheusResource = require('../../../../prometheus-plugin/plugin.json');
66
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
67
+ const panelsResource = require('../../../../panels-plugin/plugin.json');
68
+ const bundledPluginLoader = (0, _pluginSystem.dynamicImportPluginLoader)([
69
+ {
70
+ resource: prometheusResource,
71
+ // This throws an error in CI (but not locally for some reason), likely because
72
+ // this package isn't a dependency for dashboards. We probably do not want to
73
+ // make it one solely for type-checking in storybook.
74
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
75
+ // @ts-ignore
76
+ importPlugin: ()=>Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("@perses-dev/prometheus-plugin")))
77
+ },
78
+ {
79
+ resource: panelsResource,
80
+ // Same comment as above.
81
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
82
+ // @ts-ignore
83
+ importPlugin: ()=>Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("@perses-dev/panels-plugin")))
84
+ }
85
+ ]);
86
+ const WithPluginRegistry = (Story)=>{
87
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.PluginRegistry, {
88
+ pluginLoader: bundledPluginLoader,
89
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(Story, {})
90
+ });
91
+ };
@@ -0,0 +1,29 @@
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, "WithQueryClient", {
18
+ enumerable: true,
19
+ get: ()=>WithQueryClient
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _reactQuery = require("@tanstack/react-query");
23
+ const WithQueryClient = (Story)=>{
24
+ const queryClient = new _reactQuery.QueryClient({});
25
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
26
+ client: queryClient,
27
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(Story, {})
28
+ });
29
+ };
@@ -0,0 +1,29 @@
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, "WithQueryParams", {
18
+ enumerable: true,
19
+ get: ()=>WithQueryParams
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _window = require("use-query-params/adapters/window");
23
+ const _useQueryParams = require("use-query-params");
24
+ const WithQueryParams = (Story)=>{
25
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_useQueryParams.QueryParamProvider, {
26
+ adapter: _window.WindowHistoryAdapter,
27
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(Story, {})
28
+ });
29
+ };