@perses-dev/dashboards 0.22.0 → 0.23.1

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 (126) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +3 -0
  2. package/dist/cjs/components/DeletePanelDialog/DeletePanelDialog.js +8 -30
  3. package/dist/cjs/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +1 -0
  4. package/dist/cjs/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -0
  5. package/dist/cjs/components/GridLayout/GridItemContent.js +2 -1
  6. package/dist/cjs/components/GridLayout/GridLayout.js +4 -7
  7. package/dist/cjs/components/Panel/Panel.js +4 -5
  8. package/dist/cjs/components/Panel/Panel.test.js +10 -2
  9. package/dist/cjs/components/Panel/PanelContent.js +2 -1
  10. package/dist/cjs/components/Panel/PanelHeader.js +17 -0
  11. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +1 -0
  12. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +2 -2
  13. package/dist/cjs/components/Variables/EditVariablesButton.js +1 -0
  14. package/dist/cjs/components/Variables/VariableEditor.js +1 -1
  15. package/dist/cjs/components/Variables/VariableList.js +8 -2
  16. package/dist/cjs/{utils/functions.js → constants/grid-layout-config.js} +13 -5
  17. package/dist/cjs/constants/index.js +1 -0
  18. package/dist/cjs/constants/user-interface-text.js +2 -0
  19. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +29 -9
  20. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +6 -4
  21. package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +62 -0
  22. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +8 -37
  23. package/dist/cjs/context/useDashboard.js +4 -2
  24. package/dist/cjs/utils/index.js +1 -1
  25. package/dist/cjs/utils/panelUtils.js +168 -0
  26. package/dist/cjs/utils/panelUtils.test.js +195 -0
  27. package/dist/cjs/views/ViewDashboard/DashboardApp.js +4 -1
  28. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +4 -2
  29. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  30. package/dist/components/DashboardToolbar/DashboardToolbar.js +3 -0
  31. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  32. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -1
  33. package/dist/components/DeletePanelDialog/DeletePanelDialog.js +7 -24
  34. package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -1
  35. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +1 -0
  36. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
  37. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +1 -0
  38. package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
  39. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  40. package/dist/components/GridLayout/GridItemContent.js +2 -1
  41. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  42. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  43. package/dist/components/GridLayout/GridLayout.js +4 -7
  44. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  45. package/dist/components/Panel/Panel.d.ts.map +1 -1
  46. package/dist/components/Panel/Panel.js +5 -6
  47. package/dist/components/Panel/Panel.js.map +1 -1
  48. package/dist/components/Panel/Panel.test.js +10 -2
  49. package/dist/components/Panel/Panel.test.js.map +1 -1
  50. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  51. package/dist/components/Panel/PanelContent.js +2 -1
  52. package/dist/components/Panel/PanelContent.js.map +1 -1
  53. package/dist/components/Panel/PanelHeader.d.ts +1 -0
  54. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  55. package/dist/components/Panel/PanelHeader.js +17 -0
  56. package/dist/components/Panel/PanelHeader.js.map +1 -1
  57. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +1 -0
  58. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  59. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +2 -2
  60. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  61. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  62. package/dist/components/Variables/EditVariablesButton.js +1 -0
  63. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  64. package/dist/components/Variables/VariableEditor.js +1 -1
  65. package/dist/components/Variables/VariableEditor.js.map +1 -1
  66. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  67. package/dist/components/Variables/VariableList.js +8 -2
  68. package/dist/components/Variables/VariableList.js.map +1 -1
  69. package/dist/constants/grid-layout-config.d.ts +6 -0
  70. package/dist/constants/grid-layout-config.d.ts.map +1 -0
  71. package/dist/{utils/functions.js → constants/grid-layout-config.js} +5 -3
  72. package/dist/constants/grid-layout-config.js.map +1 -0
  73. package/dist/constants/index.d.ts +1 -0
  74. package/dist/constants/index.d.ts.map +1 -1
  75. package/dist/constants/index.js +1 -0
  76. package/dist/constants/index.js.map +1 -1
  77. package/dist/constants/user-interface-text.d.ts +2 -0
  78. package/dist/constants/user-interface-text.d.ts.map +1 -1
  79. package/dist/constants/user-interface-text.js +2 -0
  80. package/dist/constants/user-interface-text.js.map +1 -1
  81. package/dist/context/DashboardProvider/DashboardProvider.d.ts +6 -4
  82. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  83. package/dist/context/DashboardProvider/DashboardProvider.js +29 -4
  84. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  85. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -0
  86. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  87. package/dist/context/DashboardProvider/dashboard-provider-api.js +6 -4
  88. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  89. package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts +19 -0
  90. package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts.map +1 -0
  91. package/dist/context/DashboardProvider/duplicate-panel-slice.js +58 -0
  92. package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -0
  93. package/dist/context/DashboardProvider/index.d.ts +1 -1
  94. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  95. package/dist/context/DashboardProvider/index.js.map +1 -1
  96. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +4 -0
  97. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  98. package/dist/context/DashboardProvider/panel-editor-slice.js +6 -35
  99. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  100. package/dist/context/useDashboard.d.ts.map +1 -1
  101. package/dist/context/useDashboard.js +4 -2
  102. package/dist/context/useDashboard.js.map +1 -1
  103. package/dist/utils/index.d.ts +1 -1
  104. package/dist/utils/index.d.ts.map +1 -1
  105. package/dist/utils/index.js +1 -1
  106. package/dist/utils/index.js.map +1 -1
  107. package/dist/utils/panelUtils.d.ts +27 -0
  108. package/dist/utils/panelUtils.d.ts.map +1 -0
  109. package/dist/utils/panelUtils.js +174 -0
  110. package/dist/utils/panelUtils.js.map +1 -0
  111. package/dist/utils/panelUtils.test.d.ts +2 -0
  112. package/dist/utils/panelUtils.test.d.ts.map +1 -0
  113. package/dist/utils/panelUtils.test.js +193 -0
  114. package/dist/utils/panelUtils.test.js.map +1 -0
  115. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
  116. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  117. package/dist/views/ViewDashboard/DashboardApp.js +4 -1
  118. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  119. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -0
  120. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  121. package/dist/views/ViewDashboard/ViewDashboard.js +4 -2
  122. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  123. package/package.json +5 -5
  124. package/dist/utils/functions.d.ts +0 -2
  125. package/dist/utils/functions.d.ts.map +0 -1
  126. package/dist/utils/functions.js.map +0 -1
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "createPanelEditorSlice", {
18
18
  enumerable: true,
19
19
  get: ()=>createPanelEditorSlice
20
20
  });
21
- const _functions = require("../../utils/functions");
21
+ const _panelUtils = require("../../utils/panelUtils");
22
22
  const _common = require("./common");
23
23
  const _panelGroupSlice = require("./panel-group-slice");
24
24
  function createPanelEditorSlice() {
@@ -80,7 +80,7 @@ function createPanelEditorSlice() {
80
80
  newGroup.itemLayouts.push({
81
81
  i: existingLayout.i,
82
82
  x: 0,
83
- y: getYForNewRow(newGroup),
83
+ y: (0, _panelUtils.getYForNewRow)(newGroup),
84
84
  w: existingLayout.w,
85
85
  h: existingLayout.h
86
86
  });
@@ -99,6 +99,7 @@ function createPanelEditorSlice() {
99
99
  });
100
100
  },
101
101
  openAddPanel (panelGroupId) {
102
+ var ref, ref1;
102
103
  // If a panel group isn't supplied, add to the first group or create a group if there aren't any
103
104
  let newGroup = undefined;
104
105
  panelGroupId !== null && panelGroupId !== void 0 ? panelGroupId : panelGroupId = get().panelGroupOrder[0];
@@ -107,23 +108,19 @@ function createPanelEditorSlice() {
107
108
  newGroup.title = 'Panel Group';
108
109
  panelGroupId = newGroup.id;
109
110
  }
111
+ var ref2, ref3;
110
112
  const editorState = {
111
113
  mode: 'Add',
112
114
  initialValues: {
113
115
  name: '',
114
116
  description: '',
115
117
  groupId: panelGroupId,
116
- kind: '',
117
- spec: {}
118
+ kind: (ref2 = (ref = get().initialValues) === null || ref === void 0 ? void 0 : ref.kind) !== null && ref2 !== void 0 ? ref2 : '',
119
+ spec: (ref3 = (ref1 = get().initialValues) === null || ref1 === void 0 ? void 0 : ref1.spec) !== null && ref3 !== void 0 ? ref3 : {}
118
120
  },
119
121
  applyChanges: (next)=>{
120
122
  const panelDef = createPanelDefinitionFromEditorValues(next);
121
- const uniquePanelKeys = getUniquePanelKeys(get().panels);
122
- let panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(next.name);
123
- // append count if panel key already exists
124
- if (uniquePanelKeys[panelKey]) {
125
- panelKey += `-${uniquePanelKeys[panelKey]}`;
126
- }
123
+ const panelKey = (0, _panelUtils.getValidPanelKey)(next.name, get().panels);
127
124
  set((state)=>{
128
125
  // Add a panel
129
126
  state.panels[panelKey] = panelDef;
@@ -135,7 +132,7 @@ function createPanelEditorSlice() {
135
132
  const layout = {
136
133
  i: (0, _common.generateId)().toString(),
137
134
  x: 0,
138
- y: getYForNewRow(group),
135
+ y: (0, _panelUtils.getYForNewRow)(group),
139
136
  w: 12,
140
137
  h: 6
141
138
  };
@@ -177,29 +174,3 @@ function createPanelDefinitionFromEditorValues(editorValues) {
177
174
  }
178
175
  };
179
176
  }
180
- // Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present
181
- function getYForNewRow(group) {
182
- let newRowY = 0;
183
- for (const layout of group.itemLayouts){
184
- const itemMaxY = layout.y + layout.h;
185
- if (itemMaxY > newRowY) {
186
- newRowY = itemMaxY;
187
- }
188
- }
189
- return newRowY;
190
- }
191
- // Find all the unique panel keys
192
- // ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name
193
- function getUniquePanelKeys(panels) {
194
- const uniquePanelKeys = {};
195
- Object.keys(panels).forEach((panelKey)=>{
196
- const key = panelKey.replace(/-([0-9]+)/, '');
197
- const count = uniquePanelKeys[key];
198
- if (count) {
199
- uniquePanelKeys[key] = count + 1;
200
- } else {
201
- uniquePanelKeys[key] = 1;
202
- }
203
- });
204
- return uniquePanelKeys;
205
- }
@@ -22,13 +22,14 @@ const _core = require("@perses-dev/core");
22
22
  const _dashboardProvider = require("./DashboardProvider");
23
23
  const _templateVariableProvider = require("./TemplateVariableProvider");
24
24
  function useDashboard() {
25
- const { panels , panelGroups , panelGroupOrder , defaultTimeRange , metadata , setDashboard: setDashboardResource , } = (0, _dashboardProvider.useDashboardStore)(({ panels , panelGroups , panelGroupOrder , defaultTimeRange , setDashboard , metadata })=>({
25
+ const { panels , panelGroups , panelGroupOrder , defaultTimeRange , setDashboard: setDashboardResource , metadata , display , } = (0, _dashboardProvider.useDashboardStore)(({ panels , panelGroups , panelGroupOrder , defaultTimeRange , setDashboard , metadata , display })=>({
26
26
  panels,
27
27
  panelGroups,
28
28
  panelGroupOrder,
29
29
  defaultTimeRange,
30
30
  setDashboard,
31
- metadata
31
+ metadata,
32
+ display
32
33
  }));
33
34
  const { setVariableDefinitions } = (0, _templateVariableProvider.useTemplateVariableActions)();
34
35
  const variables = (0, _templateVariableProvider.useTemplateVariableDefinitions)();
@@ -37,6 +38,7 @@ function useDashboard() {
37
38
  kind: 'Dashboard',
38
39
  metadata,
39
40
  spec: {
41
+ display,
40
42
  panels,
41
43
  layouts,
42
44
  variables,
@@ -14,7 +14,7 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _exportStar(require("./functions"), exports);
17
+ _exportStar(require("./panelUtils"), exports);
18
18
  function _exportStar(from, to) {
19
19
  Object.keys(from).forEach(function(k) {
20
20
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -0,0 +1,168 @@
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
+ getYForNewRow: ()=>getYForNewRow,
25
+ insertPanelInLayout: ()=>insertPanelInLayout,
26
+ getValidPanelKey: ()=>getValidPanelKey
27
+ });
28
+ const _constants = require("../constants");
29
+ function getYForNewRow(group) {
30
+ let newRowY = 0;
31
+ for (const layout of group.itemLayouts){
32
+ const itemMaxY = layout.y + layout.h;
33
+ if (itemMaxY > newRowY) {
34
+ newRowY = itemMaxY;
35
+ }
36
+ }
37
+ return newRowY;
38
+ }
39
+ function getPanelBounds({ x , y , w , h }) {
40
+ return {
41
+ x1: x,
42
+ x2: x + w,
43
+ y1: y,
44
+ y2: y + h
45
+ };
46
+ }
47
+ function insertPanelInLayout(newLayout, referenceLayout, itemLayouts) {
48
+ const MAX_LAYOUT_WIDTH = _constants.GRID_LAYOUT_COLS[_constants.GRID_LAYOUT_SMALL_BREAKPOINT];
49
+ const referenceBounds = getPanelBounds(referenceLayout);
50
+ // Organize layouts based on vertical relation to the item being inserted
51
+ // after.
52
+ const aboveInsertRow = [];
53
+ const insertRow = [];
54
+ const belowInsertRow = [];
55
+ itemLayouts.forEach((itemLayout)=>{
56
+ const itemBounds = getPanelBounds(itemLayout);
57
+ if (itemBounds.y2 <= referenceBounds.y1) {
58
+ aboveInsertRow.push(itemLayout);
59
+ } else if (itemBounds.y1 >= referenceBounds.y2) {
60
+ belowInsertRow.push(itemLayout);
61
+ } else {
62
+ insertRow.push(itemLayout);
63
+ }
64
+ });
65
+ // Cannot safely assume that the order of item layouts array is strictly
66
+ // left to right. Sorting the row by horizontal position to more easily find
67
+ // gaps.
68
+ insertRow.sort((a, b)=>a.x - b.x);
69
+ const insertAfterIndex = insertRow.findIndex((item)=>item.i === referenceLayout.i);
70
+ if (insertAfterIndex === insertRow.length - 1) {
71
+ // Insert to the right when space is available and the reference is the last
72
+ // item in the row.
73
+ if (referenceBounds.x2 + newLayout.w <= MAX_LAYOUT_WIDTH) {
74
+ return [
75
+ ...aboveInsertRow,
76
+ ...insertRow,
77
+ {
78
+ ...newLayout,
79
+ x: referenceBounds.x2,
80
+ y: referenceBounds.y1
81
+ },
82
+ ...belowInsertRow
83
+ ];
84
+ }
85
+ } else if (insertAfterIndex >= 0) {
86
+ const nextItem = insertRow[insertAfterIndex + 1];
87
+ if (nextItem && getPanelBounds(nextItem).x1 - referenceBounds.x2 >= newLayout.w) {
88
+ // Insert to the right when space is available between the reference and
89
+ // the next item in the row.
90
+ insertRow.splice(insertAfterIndex + 1, 0, {
91
+ ...newLayout,
92
+ x: referenceBounds.x2,
93
+ y: referenceBounds.y1
94
+ });
95
+ return [
96
+ ...aboveInsertRow,
97
+ ...insertRow,
98
+ ...belowInsertRow
99
+ ];
100
+ }
101
+ }
102
+ // Insert the new item below the original and shift the items below the
103
+ // row where the reference is located.
104
+ return [
105
+ ...aboveInsertRow,
106
+ ...insertRow,
107
+ {
108
+ x: referenceBounds.x1,
109
+ y: referenceBounds.y2,
110
+ ...newLayout
111
+ },
112
+ ...belowInsertRow.map((itemLayout)=>{
113
+ // Note: the grid will not necessarily display all of these items shifted
114
+ // all the way down because of vertical compacting, but shifing their
115
+ // y position ensures the new item gets vertical precedence over items
116
+ // below it in that compacting.
117
+ return {
118
+ ...itemLayout,
119
+ y: itemLayout.y + newLayout.h
120
+ };
121
+ })
122
+ ];
123
+ }
124
+ function getValidPanelKey(panelKey, panels) {
125
+ const uniquePanelKeys = getUniquePanelKeys(panels);
126
+ let normalizedPanelKey = getPanelKeyParts(removeWhiteSpaces(panelKey)).name;
127
+ const matchingKey = uniquePanelKeys[normalizedPanelKey];
128
+ if (typeof matchingKey === 'number') {
129
+ normalizedPanelKey += `-${matchingKey + 1}`;
130
+ }
131
+ return normalizedPanelKey;
132
+ }
133
+ const removeWhiteSpaces = (str)=>{
134
+ return str.replace(/\s+/g, '');
135
+ };
136
+ /**
137
+ * Breaks the specified panel key into the name and the optional `-number` used
138
+ * for deduping panels with the same name.
139
+ */ function getPanelKeyParts(panelKey) {
140
+ const parts = panelKey.match(/(.+)-([0-9]+)/);
141
+ if (parts && parts[1] && parts[2]) {
142
+ return {
143
+ name: parts[1],
144
+ number: parseInt(parts[2], 10)
145
+ };
146
+ }
147
+ return {
148
+ name: panelKey
149
+ };
150
+ }
151
+ // Find all the unique panel keys and the largest number used for each.
152
+ // ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name
153
+ function getUniquePanelKeys(panels) {
154
+ const uniquePanelKeys = {};
155
+ Object.keys(panels).forEach((panelKey)=>{
156
+ const { name , number } = getPanelKeyParts(panelKey);
157
+ if (uniquePanelKeys[name] === undefined) {
158
+ uniquePanelKeys[name] = 0;
159
+ }
160
+ const currentValue = uniquePanelKeys[name];
161
+ if (typeof currentValue === 'number' && number) {
162
+ // Check for the maximum value because we cannot rely on a sequential
163
+ // set of numbers when panels are modified.
164
+ uniquePanelKeys[name] = Math.max(currentValue, number);
165
+ }
166
+ });
167
+ return uniquePanelKeys;
168
+ }
@@ -0,0 +1,195 @@
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
+ const _panelUtils = require("./panelUtils");
18
+ describe('insertPanelInLayout', ()=>{
19
+ describe('inserts the panel to the right when space is available', ()=>{
20
+ test('with a single panel in that row', ()=>{
21
+ const newLayout = {
22
+ i: 'abc',
23
+ w: 10,
24
+ h: 8
25
+ };
26
+ const referenceLayout = {
27
+ i: 'one',
28
+ x: 0,
29
+ y: 0,
30
+ w: 6,
31
+ h: 6
32
+ };
33
+ const layouts = [
34
+ referenceLayout
35
+ ];
36
+ expect((0, _panelUtils.insertPanelInLayout)(newLayout, referenceLayout, layouts)).toEqual([
37
+ referenceLayout,
38
+ {
39
+ x: 6,
40
+ y: 0,
41
+ ...newLayout
42
+ }
43
+ ]);
44
+ });
45
+ test('with multiple panels in that row with space between them', ()=>{
46
+ const newLayout = {
47
+ i: 'abc',
48
+ w: 10,
49
+ h: 8
50
+ };
51
+ const referenceLayout = {
52
+ i: 'one',
53
+ x: 0,
54
+ y: 0,
55
+ w: 3,
56
+ h: 4
57
+ };
58
+ const otherPanelInRow = {
59
+ i: 'two',
60
+ x: 20,
61
+ y: 0,
62
+ w: 4,
63
+ h: 4
64
+ };
65
+ const layouts = [
66
+ referenceLayout,
67
+ otherPanelInRow
68
+ ];
69
+ expect((0, _panelUtils.insertPanelInLayout)(newLayout, referenceLayout, layouts)).toEqual([
70
+ referenceLayout,
71
+ {
72
+ x: 3,
73
+ y: 0,
74
+ ...newLayout
75
+ },
76
+ otherPanelInRow
77
+ ]);
78
+ });
79
+ });
80
+ describe('inserts the panel below when space is not available to the right', ()=>{
81
+ test('with a single panel in the initial layout', ()=>{
82
+ const newLayout = {
83
+ i: 'abc',
84
+ w: 10,
85
+ h: 8
86
+ };
87
+ const referenceLayout = {
88
+ i: 'one',
89
+ x: 1,
90
+ y: 0,
91
+ w: 18,
92
+ h: 4
93
+ };
94
+ const layouts = [
95
+ referenceLayout
96
+ ];
97
+ expect((0, _panelUtils.insertPanelInLayout)(newLayout, referenceLayout, layouts)).toEqual([
98
+ referenceLayout,
99
+ {
100
+ x: 1,
101
+ y: 4,
102
+ ...newLayout
103
+ }
104
+ ]);
105
+ });
106
+ test('with a single panel in the same row and additional panels below', ()=>{
107
+ const newLayout = {
108
+ i: 'abc',
109
+ w: 10,
110
+ h: 8
111
+ };
112
+ const referenceLayout = {
113
+ i: 'one',
114
+ x: 0,
115
+ y: 0,
116
+ w: 18,
117
+ h: 4
118
+ };
119
+ const nextRowItem = {
120
+ i: 'two',
121
+ x: 0,
122
+ y: 4,
123
+ w: 6,
124
+ h: 6
125
+ };
126
+ const layouts = [
127
+ referenceLayout,
128
+ nextRowItem
129
+ ];
130
+ expect((0, _panelUtils.insertPanelInLayout)(newLayout, referenceLayout, layouts)).toEqual([
131
+ referenceLayout,
132
+ {
133
+ x: 0,
134
+ y: 4,
135
+ ...newLayout
136
+ },
137
+ {
138
+ ...nextRowItem,
139
+ y: nextRowItem.y + newLayout.h
140
+ }
141
+ ]);
142
+ });
143
+ });
144
+ });
145
+ describe('getValidPanelKey', ()=>{
146
+ test('removes whitespace', ()=>{
147
+ expect((0, _panelUtils.getValidPanelKey)('my panel name', {})).toBe('mypanelname');
148
+ });
149
+ test('does not include a counter if the key is not in use', ()=>{
150
+ const mockPanelDefs = {
151
+ alreadyInUse: {
152
+ kind: 'Panel',
153
+ spec: {}
154
+ }
155
+ };
156
+ expect((0, _panelUtils.getValidPanelKey)('newPanelName', mockPanelDefs)).toBe('newPanelName');
157
+ });
158
+ test('includes a counter if the key is already in use', ()=>{
159
+ const mockPanelDefs = {
160
+ alreadyInUse: {
161
+ kind: 'Panel',
162
+ spec: {}
163
+ }
164
+ };
165
+ expect((0, _panelUtils.getValidPanelKey)('alreadyInUse', mockPanelDefs)).toBe('alreadyInUse-1');
166
+ });
167
+ test('includes an incremented counter if the key is already in use multiple times', ()=>{
168
+ const mockPanelDefs = {
169
+ popularKey: {
170
+ kind: 'Panel',
171
+ spec: {}
172
+ },
173
+ 'popularKey-1': {
174
+ kind: 'Panel',
175
+ spec: {}
176
+ }
177
+ };
178
+ expect((0, _panelUtils.getValidPanelKey)('popularKey', mockPanelDefs)).toBe('popularKey-2');
179
+ expect((0, _panelUtils.getValidPanelKey)('popularKey-1', mockPanelDefs)).toBe('popularKey-2');
180
+ });
181
+ test('does not duplicate counters when they are out of order', ()=>{
182
+ const mockPanelDefs = {
183
+ outoforder: {
184
+ kind: 'Panel',
185
+ spec: {}
186
+ },
187
+ 'outoforder-2': {
188
+ kind: 'Panel',
189
+ spec: {}
190
+ }
191
+ };
192
+ expect((0, _panelUtils.getValidPanelKey)('outoforder', mockPanelDefs)).toBe('outoforder-3');
193
+ expect((0, _panelUtils.getValidPanelKey)('outoforder-2', mockPanelDefs)).toBe('outoforder-3');
194
+ });
195
+ });
@@ -25,7 +25,7 @@ const _components = require("@perses-dev/components");
25
25
  const _components1 = require("../../components");
26
26
  const _context = require("../../context");
27
27
  const DashboardApp = (props)=>{
28
- const { dashboardResource , dashboardTitleComponent , onSave , initialVariableIsSticky , isReadonly } = props;
28
+ const { dashboardResource , dashboardTitleComponent , onSave , onDiscard , initialVariableIsSticky , isReadonly } = props;
29
29
  const { setEditMode } = (0, _context.useEditMode)();
30
30
  const { dashboard , setDashboard } = (0, _context.useDashboard)();
31
31
  const [originalDashboard, setOriginalDashboard] = (0, _react.useState)(undefined);
@@ -37,6 +37,9 @@ const DashboardApp = (props)=>{
37
37
  }
38
38
  setEditMode(false);
39
39
  closeDiscardChangesConfirmationDialog();
40
+ if (onDiscard) {
41
+ onDiscard(dashboard);
42
+ }
40
43
  };
41
44
  const onEditButtonClick = ()=>{
42
45
  setEditMode(true);
@@ -25,7 +25,7 @@ const _pluginSystem = require("@perses-dev/plugin-system");
25
25
  const _context = require("../../context");
26
26
  const _dashboardApp = require("./DashboardApp");
27
27
  function ViewDashboard(props) {
28
- const { dashboardResource , datasourceApi , dashboardTitleComponent , onSave , initialVariableIsSticky , isReadonly , sx , ...others } = props;
28
+ const { dashboardResource , datasourceApi , dashboardTitleComponent , onSave , onDiscard , initialVariableIsSticky , isReadonly , isEditing , sx , ...others } = props;
29
29
  const { spec } = dashboardResource;
30
30
  var _duration;
31
31
  const dashboardDuration = (_duration = spec.duration) !== null && _duration !== void 0 ? _duration : '1h';
@@ -35,7 +35,8 @@ function ViewDashboard(props) {
35
35
  datasourceApi: datasourceApi,
36
36
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DashboardProvider, {
37
37
  initialState: {
38
- dashboardResource
38
+ dashboardResource,
39
+ isEditMode: !!isEditing
39
40
  },
40
41
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.TimeRangeProvider, {
41
42
  initialTimeRange: initialTimeRange,
@@ -57,6 +58,7 @@ function ViewDashboard(props) {
57
58
  dashboardResource: dashboardResource,
58
59
  dashboardTitleComponent: dashboardTitleComponent,
59
60
  onSave: onSave,
61
+ onDiscard: onDiscard,
60
62
  initialVariableIsSticky: initialVariableIsSticky,
61
63
  isReadonly: isReadonly
62
64
  })
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAQrD,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBA0I5D,CAAC"}
1
+ {"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAQrD,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBA4I5D,CAAC"}
@@ -45,9 +45,11 @@ export const DashboardToolbar = (props)=>{
45
45
  setEditMode(false);
46
46
  }
47
47
  };
48
+ const testId = 'dashboard-toolbar';
48
49
  return /*#__PURE__*/ _jsx(_Fragment, {
49
50
  children: isEditMode ? /*#__PURE__*/ _jsxs(Stack, {
50
51
  spacing: 1,
52
+ "data-testid": testId,
51
53
  children: [
52
54
  /*#__PURE__*/ _jsxs(Box, {
53
55
  p: 2,
@@ -154,6 +156,7 @@ export const DashboardToolbar = (props)=>{
154
156
  }) : /*#__PURE__*/ _jsxs(Stack, {
155
157
  spacing: 1,
156
158
  padding: 2,
159
+ "data-testid": testId,
157
160
  children: [
158
161
  /*#__PURE__*/ _jsxs(Box, {
159
162
  sx: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"sourcesContent":["// Copyright 2023 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 { Typography, Stack, Button, Box, useTheme, useMediaQuery, Alert } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport { ErrorBoundary, ErrorAlert } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport { useDashboard, useEditMode } from '../../context';\nimport { AddPanelButton } from '../AddPanelButton';\nimport { AddGroupButton } from '../AddGroupButton';\nimport { DownloadButton } from '../DownloadButton';\nimport { TimeRangeControls } from '../TimeRangeControls';\nimport { TemplateVariableList, EditVariablesButton } from '../Variables';\n\nexport interface DashboardToolbarProps {\n dashboardName: string;\n dashboardTitleComponent?: JSX.Element;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n onEditButtonClick: () => void;\n onCancelButtonClick: () => void;\n onSave?: (entity: DashboardResource) => Promise<DashboardResource>;\n}\n\nexport const DashboardToolbar = (props: DashboardToolbarProps) => {\n const {\n dashboardName,\n dashboardTitleComponent,\n initialVariableIsSticky,\n isReadonly,\n onEditButtonClick,\n onCancelButtonClick,\n onSave,\n } = props;\n\n const dashboard = useDashboard();\n const { isEditMode, setEditMode } = useEditMode();\n\n const isBiggerThanMd = useMediaQuery(useTheme().breakpoints.up('md'));\n const isBiggerThanSm = useMediaQuery(useTheme().breakpoints.up('sm'));\n\n const [isSavingDashboard, setSavingDashboard] = useState<boolean>(false);\n\n const dashboardTitle = dashboardTitleComponent ? (\n dashboardTitleComponent\n ) : (\n <Typography variant=\"h2\">{dashboardName}</Typography>\n );\n\n const onSaveButtonClick = () => {\n if (onSave !== undefined) {\n setSavingDashboard(true);\n onSave(dashboard.dashboard)\n .then(() => {\n setSavingDashboard(false);\n setEditMode(false);\n })\n .catch(() => {\n setSavingDashboard(false);\n });\n } else {\n setEditMode(false);\n }\n };\n\n return (\n <>\n {isEditMode ? (\n <Stack spacing={1}>\n <Box p={2} display=\"flex\" sx={{ backgroundColor: (theme) => theme.palette.primary.main + '30' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n {isReadonly && (\n <Alert severity={'warning'} sx={{ backgroundColor: 'transparent', padding: 0 }}>\n Dashboard managed via code only. Download JSON and commit changes to save.\n </Alert>\n )}\n <Button variant=\"contained\" onClick={onSaveButtonClick} disabled={isReadonly || isSavingDashboard}>\n Save\n </Button>\n <Button variant=\"outlined\" onClick={onCancelButtonClick}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box\n sx={{\n display: 'flex',\n width: '100%',\n alignItems: 'start',\n padding: (theme) => theme.spacing(1, 2, 2, 2),\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList\n initialVariableIsSticky={initialVariableIsSticky}\n sx={{\n backgroundColor: ({ palette }) =>\n palette.mode === 'dark' ? palette.background.default : palette.background.paper,\n }}\n />\n </ErrorBoundary>\n {isBiggerThanMd ? (\n // On bigger screens, make it one row\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\" sx={{ whiteSpace: 'nowrap' }}>\n <EditVariablesButton />\n <AddPanelButton />\n <AddGroupButton />\n <TimeRangeControls />\n <DownloadButton />\n </Stack>\n ) : (\n // On smaller screens, make it two rows\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\" sx={{ whiteSpace: 'nowrap' }}>\n <TimeRangeControls />\n <DownloadButton />\n </Stack>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\" sx={{ whiteSpace: 'nowrap' }}>\n <EditVariablesButton />\n <AddPanelButton />\n <AddGroupButton />\n </Stack>\n </Stack>\n )}\n </Box>\n </Stack>\n ) : (\n <Stack spacing={1} padding={2}>\n <Box sx={{ display: 'flex', width: '100%' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <TimeRangeControls />\n <DownloadButton />\n {isBiggerThanSm && (\n <Button\n variant=\"outlined\"\n color=\"secondary\"\n startIcon={<PencilIcon />}\n onClick={onEditButtonClick}\n sx={{ marginLeft: 'auto' }}\n >\n Edit\n </Button>\n )}\n </Stack>\n </Box>\n <Box paddingY={2}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList\n initialVariableIsSticky={initialVariableIsSticky}\n sx={{\n backgroundColor: ({ palette }) =>\n palette.mode === 'dark' ? palette.background.default : palette.background.paper,\n }}\n />\n </ErrorBoundary>\n </Box>\n </Stack>\n )}\n </>\n );\n};\n"],"names":["useState","Typography","Stack","Button","Box","useTheme","useMediaQuery","Alert","PencilIcon","ErrorBoundary","ErrorAlert","useDashboard","useEditMode","AddPanelButton","AddGroupButton","DownloadButton","TimeRangeControls","TemplateVariableList","EditVariablesButton","DashboardToolbar","props","dashboardName","dashboardTitleComponent","initialVariableIsSticky","isReadonly","onEditButtonClick","onCancelButtonClick","onSave","dashboard","isEditMode","setEditMode","isBiggerThanMd","breakpoints","up","isBiggerThanSm","isSavingDashboard","setSavingDashboard","dashboardTitle","variant","onSaveButtonClick","undefined","then","catch","spacing","p","display","sx","backgroundColor","theme","palette","primary","main","direction","marginLeft","severity","padding","onClick","disabled","width","alignItems","FallbackComponent","mode","background","default","paper","whiteSpace","color","startIcon","paddingY"],"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,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,KAAK,QAAQ,eAAe,CAAC;AAC/F,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,SAASC,aAAa,EAAEC,UAAU,QAAQ,wBAAwB,CAAC;AAEnE,SAASC,YAAY,EAAEC,WAAW,QAAQ,eAAe,CAAC;AAC1D,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AACnD,SAASC,iBAAiB,QAAQ,sBAAsB,CAAC;AACzD,SAASC,oBAAoB,EAAEC,mBAAmB,QA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,cAAc;sCACf,MAACnC,KAAK;4BAACkD,SAAS,EAAC,KAAK;4BAACT,OAAO,EAAE,CAAC;4BAAEU,UAAU,EAAC,MAAM;;8CAClD,KAACrC,iBAAiB,KAAG;8CACrB,KAACD,cAAc,KAAG;gCACjBmB,cAAc,kBACb,KAAC/B,MAAM;oCACLmC,OAAO,EAAC,UAAU;oCAClB4B,KAAK,EAAC,WAAW;oCACjBC,SAAS,gBAAE,KAAC3D,UAAU,KAAG;oCACzBgD,OAAO,EAAE/B,iBAAiB;oCAC1BqB,EAAE,EAAE;wCAAEO,UAAU,EAAE,MAAM;qCAAE;8CAC3B,MAED;kCAAS,AACV;;0BACK;;kBACJ;8BACN,KAACjD,GAAG;oBAACgE,QAAQ,EAAE,CAAC;8BACd,cAAA,KAAC3D,aAAa;wBAACmD,iBAAiB,EAAElD,UAAU;kCAC1C,cAAA,KAACO,oBAAoB;4BACnBM,uBAAuB,EAAEA,uBAAuB;4BAChDuB,EAAE,EAAE;gCACFC,eAAe,EAAE,CAAC,EAAEE,OAAO,CAAA,EAAE,GAC3BA,OAAO,CAACY,IAAI,KAAK,MAAM,GAAGZ,OAAO,CAACa,UAAU,CAACC,OAAO,GAAGd,OAAO,CAACa,UAAU,CAACE,KAAK;6BAClF;0BACD;sBACY;kBACZ;;UACA,AACT;MACA,CACH;AACJ,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"sourcesContent":["// Copyright 2023 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 { Typography, Stack, Button, Box, useTheme, useMediaQuery, Alert } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport { ErrorBoundary, ErrorAlert } from '@perses-dev/components';\nimport { DashboardResource } from '@perses-dev/core';\nimport { useDashboard, useEditMode } from '../../context';\nimport { AddPanelButton } from '../AddPanelButton';\nimport { AddGroupButton } from '../AddGroupButton';\nimport { DownloadButton } from '../DownloadButton';\nimport { TimeRangeControls } from '../TimeRangeControls';\nimport { TemplateVariableList, EditVariablesButton } from '../Variables';\n\nexport interface DashboardToolbarProps {\n dashboardName: string;\n dashboardTitleComponent?: JSX.Element;\n initialVariableIsSticky?: boolean;\n isReadonly: boolean;\n onEditButtonClick: () => void;\n onCancelButtonClick: () => void;\n onSave?: (entity: DashboardResource) => Promise<DashboardResource>;\n}\n\nexport const DashboardToolbar = (props: DashboardToolbarProps) => {\n const {\n dashboardName,\n dashboardTitleComponent,\n initialVariableIsSticky,\n isReadonly,\n onEditButtonClick,\n onCancelButtonClick,\n onSave,\n } = props;\n\n const dashboard = useDashboard();\n const { isEditMode, setEditMode } = useEditMode();\n\n const isBiggerThanMd = useMediaQuery(useTheme().breakpoints.up('md'));\n const isBiggerThanSm = useMediaQuery(useTheme().breakpoints.up('sm'));\n\n const [isSavingDashboard, setSavingDashboard] = useState<boolean>(false);\n\n const dashboardTitle = dashboardTitleComponent ? (\n dashboardTitleComponent\n ) : (\n <Typography variant=\"h2\">{dashboardName}</Typography>\n );\n\n const onSaveButtonClick = () => {\n if (onSave !== undefined) {\n setSavingDashboard(true);\n onSave(dashboard.dashboard)\n .then(() => {\n setSavingDashboard(false);\n setEditMode(false);\n })\n .catch(() => {\n setSavingDashboard(false);\n });\n } else {\n setEditMode(false);\n }\n };\n\n const testId = 'dashboard-toolbar';\n\n return (\n <>\n {isEditMode ? (\n <Stack spacing={1} data-testid={testId}>\n <Box p={2} display=\"flex\" sx={{ backgroundColor: (theme) => theme.palette.primary.main + '30' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n {isReadonly && (\n <Alert severity={'warning'} sx={{ backgroundColor: 'transparent', padding: 0 }}>\n Dashboard managed via code only. Download JSON and commit changes to save.\n </Alert>\n )}\n <Button variant=\"contained\" onClick={onSaveButtonClick} disabled={isReadonly || isSavingDashboard}>\n Save\n </Button>\n <Button variant=\"outlined\" onClick={onCancelButtonClick}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box\n sx={{\n display: 'flex',\n width: '100%',\n alignItems: 'start',\n padding: (theme) => theme.spacing(1, 2, 2, 2),\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList\n initialVariableIsSticky={initialVariableIsSticky}\n sx={{\n backgroundColor: ({ palette }) =>\n palette.mode === 'dark' ? palette.background.default : palette.background.paper,\n }}\n />\n </ErrorBoundary>\n {isBiggerThanMd ? (\n // On bigger screens, make it one row\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\" sx={{ whiteSpace: 'nowrap' }}>\n <EditVariablesButton />\n <AddPanelButton />\n <AddGroupButton />\n <TimeRangeControls />\n <DownloadButton />\n </Stack>\n ) : (\n // On smaller screens, make it two rows\n <Stack spacing={1}>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\" sx={{ whiteSpace: 'nowrap' }}>\n <TimeRangeControls />\n <DownloadButton />\n </Stack>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\" sx={{ whiteSpace: 'nowrap' }}>\n <EditVariablesButton />\n <AddPanelButton />\n <AddGroupButton />\n </Stack>\n </Stack>\n )}\n </Box>\n </Stack>\n ) : (\n <Stack spacing={1} padding={2} data-testid={testId}>\n <Box sx={{ display: 'flex', width: '100%' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <TimeRangeControls />\n <DownloadButton />\n {isBiggerThanSm && (\n <Button\n variant=\"outlined\"\n color=\"secondary\"\n startIcon={<PencilIcon />}\n onClick={onEditButtonClick}\n sx={{ marginLeft: 'auto' }}\n >\n Edit\n </Button>\n )}\n </Stack>\n </Box>\n <Box paddingY={2}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList\n initialVariableIsSticky={initialVariableIsSticky}\n sx={{\n backgroundColor: ({ palette }) =>\n palette.mode === 'dark' ? palette.background.default : palette.background.paper,\n }}\n />\n </ErrorBoundary>\n </Box>\n </Stack>\n )}\n </>\n );\n};\n"],"names":["useState","Typography","Stack","Button","Box","useTheme","useMediaQuery","Alert","PencilIcon","ErrorBoundary","ErrorAlert","useDashboard","useEditMode","AddPanelButton","AddGroupButton","DownloadButton","TimeRangeControls","TemplateVariableList","EditVariablesButton","DashboardToolbar","props","dashboardName","dashboardTitleComponent","initialVariableIsSticky","isReadonly","onEditButtonClick","onCancelButtonClick","onSave","dashboard","isEditMode","setEditMode","isBiggerThanMd","breakpoints","up","isBiggerThanSm","isSavingDashboard","setSavingDashboard","dashboardTitle","variant","onSaveButtonClick","undefined","then","catch","testId","spacing","data-testid","p","display","sx","backgroundColor","theme","palette","primary","main","direction","marginLeft","severity","padding","onClick","disabled","width","alignItems","FallbackComponent","mode","background","default","paper","whiteSpace","color","startIcon","paddingY"],"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,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,aAAa,EAAEC,KAAK,QAAQ,eAAe,CAAC;AAC/F,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,SAASC,aAAa,EAAEC,UAAU,QAAQ,wBAAwB,CAAC;AAEnE,SAASC,YAAY,EAAEC,WAAW,QAAQ,eAAe,CAAC;AAC1D,SAASC,cAAc,QAAQ,mBAAmB,CA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KAACC,cAAc,KAAG;;kCACZ;;0BACF,AACT;;kBACG;;UACA,iBAER,MAACZ,KAAK;YAAC0C,OAAO,EAAE,CAAC;YAAEa,OAAO,EAAE,CAAC;YAAEZ,aAAW,EAAEF,MAAM;;8BAChD,MAACvC,GAAG;oBAAC4C,EAAE,EAAE;wBAAED,OAAO,EAAE,MAAM;wBAAEa,KAAK,EAAE,MAAM;qBAAE;;wBACxCvB,cAAc;sCACf,MAACnC,KAAK;4BAACoD,SAAS,EAAC,KAAK;4BAACV,OAAO,EAAE,CAAC;4BAAEW,UAAU,EAAC,MAAM;;8CAClD,KAACvC,iBAAiB,KAAG;8CACrB,KAACD,cAAc,KAAG;gCACjBmB,cAAc,kBACb,KAAC/B,MAAM;oCACLmC,OAAO,EAAC,UAAU;oCAClB8B,KAAK,EAAC,WAAW;oCACjBC,SAAS,gBAAE,KAAC7D,UAAU,KAAG;oCACzBkD,OAAO,EAAEjC,iBAAiB;oCAC1BuB,EAAE,EAAE;wCAAEO,UAAU,EAAE,MAAM;qCAAE;8CAC3B,MAED;kCAAS,AACV;;0BACK;;kBACJ;8BACN,KAACnD,GAAG;oBAACkE,QAAQ,EAAE,CAAC;8BACd,cAAA,KAAC7D,aAAa;wBAACqD,iBAAiB,EAAEpD,UAAU;kCAC1C,cAAA,KAACO,oBAAoB;4BACnBM,uBAAuB,EAAEA,uBAAuB;4BAChDyB,EAAE,EAAE;gCACFC,eAAe,EAAE,CAAC,EAAEE,OAAO,CAAA,EAAE,GAC3BA,OAAO,CAACY,IAAI,KAAK,MAAM,GAAGZ,OAAO,CAACa,UAAU,CAACC,OAAO,GAAGd,OAAO,CAACa,UAAU,CAACE,KAAK;6BAClF;0BACD;sBACY;kBACZ;;UACA,AACT;MACA,CACH;AACJ,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"DeletePanelDialog.d.ts","sourceRoot":"","sources":["../../../src/components/DeletePanelDialog/DeletePanelDialog.tsx"],"names":[],"mappings":";AAkBA,eAAO,MAAM,iBAAiB,mBAoB7B,CAAC"}
1
+ {"version":3,"file":"DeletePanelDialog.d.ts","sourceRoot":"","sources":["../../../src/components/DeletePanelDialog/DeletePanelDialog.tsx"],"names":[],"mappings":";AAiBA,eAAO,MAAM,iBAAiB,mBAS7B,CAAC"}