@perses-dev/dashboards 0.15.0 → 0.17.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 (86) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +8 -12
  2. package/dist/cjs/components/DownloadButton/DownloadButton.js +109 -0
  3. package/dist/cjs/{utils/component-ids.js → components/DownloadButton/index.js} +11 -14
  4. package/dist/cjs/components/GridLayout/GridLayout.js +13 -2
  5. package/dist/cjs/components/GridLayout/GridTitle.js +11 -17
  6. package/dist/cjs/components/Panel/Panel.js +4 -2
  7. package/dist/cjs/components/Panel/PanelHeader.js +54 -50
  8. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -3
  9. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +23 -0
  10. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +3 -1
  11. package/dist/cjs/components/Variables/Variable.js +7 -46
  12. package/dist/cjs/components/Variables/VariableEditor.js +157 -126
  13. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +353 -161
  14. package/dist/cjs/components/Variables/VariableList.js +15 -8
  15. package/dist/cjs/components/Variables/variable-model.js +74 -0
  16. package/dist/cjs/components/index.js +1 -0
  17. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +40 -15
  18. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  19. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +16 -1
  20. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +15 -21
  21. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  22. package/dist/components/DashboardToolbar/DashboardToolbar.js +8 -12
  23. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  24. package/dist/components/DownloadButton/DownloadButton.d.ts +3 -0
  25. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -0
  26. package/dist/components/DownloadButton/DownloadButton.js +60 -0
  27. package/dist/components/DownloadButton/DownloadButton.js.map +1 -0
  28. package/dist/components/DownloadButton/index.d.ts +2 -0
  29. package/dist/components/DownloadButton/index.d.ts.map +1 -0
  30. package/dist/{utils/component-ids.js → components/DownloadButton/index.js} +2 -14
  31. package/dist/components/DownloadButton/index.js.map +1 -0
  32. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  33. package/dist/components/GridLayout/GridLayout.js +13 -2
  34. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  35. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  36. package/dist/components/GridLayout/GridTitle.js +11 -17
  37. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  38. package/dist/components/Panel/Panel.d.ts.map +1 -1
  39. package/dist/components/Panel/Panel.js +4 -2
  40. package/dist/components/Panel/Panel.js.map +1 -1
  41. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  42. package/dist/components/Panel/PanelHeader.js +54 -50
  43. package/dist/components/Panel/PanelHeader.js.map +1 -1
  44. package/dist/components/PanelDrawer/PanelDrawer.js +1 -3
  45. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  46. package/dist/components/PanelDrawer/PanelDrawer.test.js +23 -0
  47. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  48. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +4 -2
  49. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  50. package/dist/components/Variables/Variable.d.ts.map +1 -1
  51. package/dist/components/Variables/Variable.js +8 -47
  52. package/dist/components/Variables/Variable.js.map +1 -1
  53. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  54. package/dist/components/Variables/VariableEditor.js +159 -128
  55. package/dist/components/Variables/VariableEditor.js.map +1 -1
  56. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  57. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +315 -162
  58. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  59. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  60. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  61. package/dist/components/Variables/VariableList.js +15 -8
  62. package/dist/components/Variables/VariableList.js.map +1 -1
  63. package/dist/components/Variables/variable-model.d.ts +8 -0
  64. package/dist/components/Variables/variable-model.d.ts.map +1 -0
  65. package/dist/components/Variables/variable-model.js +64 -0
  66. package/dist/components/Variables/variable-model.js.map +1 -0
  67. package/dist/components/index.d.ts +1 -0
  68. package/dist/components/index.d.ts.map +1 -1
  69. package/dist/components/index.js +1 -0
  70. package/dist/components/index.js.map +1 -1
  71. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  72. package/dist/context/DashboardProvider/panel-editor-slice.js +40 -15
  73. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  74. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  75. package/dist/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  76. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  77. package/dist/context/DashboardProvider/panel-group-slice.d.ts +9 -0
  78. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  79. package/dist/context/DashboardProvider/panel-group-slice.js +17 -0
  80. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  81. package/dist/views/ViewDashboard/tests/panelGroups.test.js +15 -21
  82. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  83. package/package.json +4 -4
  84. package/dist/utils/component-ids.d.ts +0 -8
  85. package/dist/utils/component-ids.d.ts.map +0 -1
  86. package/dist/utils/component-ids.js.map +0 -1
@@ -0,0 +1,74 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name1 in all)Object.defineProperty(target, name1, {
19
+ enumerable: true,
20
+ get: all[name1]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ useListVariablePluginValues: ()=>useListVariablePluginValues,
25
+ getVariableValuesKey: ()=>getVariableValuesKey
26
+ });
27
+ const _pluginSystem = require("@perses-dev/plugin-system");
28
+ const _reactQuery = require("@tanstack/react-query");
29
+ function useListVariablePluginValues(definition) {
30
+ const { data: variablePlugin } = (0, _pluginSystem.usePlugin)('Variable', definition.spec.plugin.kind);
31
+ const datasourceStore = (0, _pluginSystem.useDatasourceStore)();
32
+ const allVariables = (0, _pluginSystem.useTemplateVariableValues)();
33
+ const { timeRange } = (0, _pluginSystem.useTimeRange)();
34
+ const variablePluginCtx = {
35
+ timeRange,
36
+ datasourceStore,
37
+ variables: allVariables
38
+ };
39
+ const spec = definition.spec.plugin.spec;
40
+ let dependsOnVariables;
41
+ if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
42
+ const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
43
+ dependsOnVariables = dependencies.variables;
44
+ }
45
+ const variables = (0, _pluginSystem.useTemplateVariableValues)(dependsOnVariables);
46
+ let waitToLoad = false;
47
+ if (dependsOnVariables) {
48
+ waitToLoad = dependsOnVariables.some((v)=>{
49
+ var ref;
50
+ return (ref = variables[v]) === null || ref === void 0 ? void 0 : ref.loading;
51
+ });
52
+ }
53
+ const variablesValueKey = getVariableValuesKey(variables);
54
+ const variablesOptionsQuery = (0, _reactQuery.useQuery)([
55
+ name,
56
+ definition,
57
+ variablesValueKey,
58
+ timeRange
59
+ ], async ()=>{
60
+ const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
61
+ datasourceStore,
62
+ variables,
63
+ timeRange
64
+ }));
65
+ var ref;
66
+ return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
67
+ }, {
68
+ enabled: !!variablePlugin || waitToLoad
69
+ });
70
+ return variablesOptionsQuery;
71
+ }
72
+ function getVariableValuesKey(v) {
73
+ return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
74
+ }
@@ -18,6 +18,7 @@ _exportStar(require("./Dashboard"), exports);
18
18
  _exportStar(require("./DashboardToolbar"), exports);
19
19
  _exportStar(require("./DeletePanelDialog"), exports);
20
20
  _exportStar(require("./DeletePanelGroupDialog"), exports);
21
+ _exportStar(require("./DownloadButton"), exports);
21
22
  _exportStar(require("./GridLayout"), exports);
22
23
  _exportStar(require("./Panel"), exports);
23
24
  _exportStar(require("./PanelDrawer"), exports);
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "createPanelEditorSlice", {
20
20
  });
21
21
  const _functions = require("../../utils/functions");
22
22
  const _common = require("./common");
23
+ const _panelGroupSlice = require("./panel-group-slice");
23
24
  function createPanelEditorSlice() {
24
25
  // Return the state creator function for Zustand that uses the panels provided as intitial state
25
26
  return (set, get)=>{
@@ -51,14 +52,14 @@ function createPanelEditorSlice() {
51
52
  },
52
53
  applyChanges: (next)=>{
53
54
  const panelDefinititon = createPanelDefinitionFromEditorValues(next);
54
- set((draft)=>{
55
- draft.panels[panelKey] = panelDefinititon;
55
+ set((state)=>{
56
+ state.panels[panelKey] = panelDefinititon;
56
57
  // If the panel didn't change groups, nothing else to do
57
58
  if (next.groupId === panelGroupId) {
58
59
  return;
59
60
  }
60
61
  // Move panel to the new group
61
- const existingGroup = draft.panelGroups[panelGroupId];
62
+ const existingGroup = state.panelGroups[panelGroupId];
62
63
  if (existingGroup === undefined) {
63
64
  throw new Error(`Missing panel group ${panelGroupId}`);
64
65
  }
@@ -72,7 +73,7 @@ function createPanelEditorSlice() {
72
73
  existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
73
74
  delete existingGroup.itemPanelKeys[panelGroupLayoutId];
74
75
  // Add item to the end of the new group
75
- const newGroup = draft.panelGroups[next.groupId];
76
+ const newGroup = state.panelGroups[next.groupId];
76
77
  if (newGroup === undefined) {
77
78
  throw new Error(`Could not find new group ${next.groupId}`);
78
79
  }
@@ -98,13 +99,13 @@ function createPanelEditorSlice() {
98
99
  });
99
100
  },
100
101
  openAddPanel (panelGroupId) {
101
- // If a panel group isn't supplied, add to the first group
102
+ // If a panel group isn't supplied, add to the first group or create a group if there aren't any
103
+ let newGroup = undefined;
104
+ panelGroupId !== null && panelGroupId !== void 0 ? panelGroupId : panelGroupId = get().panelGroupOrder[0];
102
105
  if (panelGroupId === undefined) {
103
- const firstGroupId = get().panelGroupOrder[0];
104
- if (firstGroupId === undefined) {
105
- throw new Error('No panel groups to add a panel to');
106
- }
107
- panelGroupId = firstGroupId;
106
+ newGroup = (0, _panelGroupSlice.createEmptyPanelGroup)();
107
+ newGroup.title = 'Panel Group';
108
+ panelGroupId = newGroup.id;
108
109
  }
109
110
  const editorState = {
110
111
  mode: 'Add',
@@ -119,12 +120,17 @@ function createPanelEditorSlice() {
119
120
  },
120
121
  applyChanges: (next)=>{
121
122
  const panelDef = createPanelDefinitionFromEditorValues(next);
122
- const panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(next.name);
123
- set((draft)=>{
123
+ const uniquePanelKeys = getUniquePanelKeys(get().panels);
124
+ let panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(next.name);
125
+ // append count if panel key already exists
126
+ if (uniquePanelKeys[panelKey]) {
127
+ panelKey += `-${uniquePanelKeys[panelKey]}`;
128
+ }
129
+ set((state)=>{
124
130
  // Add a panel
125
- draft.panels[panelKey] = panelDef;
131
+ state.panels[panelKey] = panelDef;
126
132
  // Also add a panel group item referencing the panel
127
- const group = draft.panelGroups[next.groupId];
133
+ const group = state.panelGroups[next.groupId];
128
134
  if (group === undefined) {
129
135
  throw new Error(`Missing panel group ${next.groupId}`);
130
136
  }
@@ -145,8 +151,12 @@ function createPanelEditorSlice() {
145
151
  });
146
152
  }
147
153
  };
148
- // Open the editor with the new state
149
154
  set((state)=>{
155
+ // Add the new panel group if one was created for the panel
156
+ if (newGroup !== undefined) {
157
+ (0, _panelGroupSlice.addPanelGroup)(state, newGroup);
158
+ }
159
+ // Open the editor with the new state
150
160
  state.panelEditor = editorState;
151
161
  });
152
162
  }
@@ -180,3 +190,18 @@ function getYForNewRow(group) {
180
190
  }
181
191
  return newRowY;
182
192
  }
193
+ // Find all the unique panel keys
194
+ // ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name
195
+ function getUniquePanelKeys(panels) {
196
+ const uniquePanelKeys = {};
197
+ Object.keys(panels).forEach((panelKey)=>{
198
+ const key = panelKey.replace(/-([0-9]+)/, '');
199
+ const count = uniquePanelKeys[key];
200
+ if (count) {
201
+ uniquePanelKeys[key] = count + 1;
202
+ } else {
203
+ uniquePanelKeys[key] = 1;
204
+ }
205
+ });
206
+ return uniquePanelKeys;
207
+ }
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "createPanelGroupEditorSlice", {
18
18
  enumerable: true,
19
19
  get: ()=>createPanelGroupEditorSlice
20
20
  });
21
- const _common = require("./common");
21
+ const _panelGroupSlice = require("./panel-group-slice");
22
22
  const createPanelGroupEditorSlice = (set, get)=>({
23
23
  panelGroupEditor: undefined,
24
24
  openAddPanelGroup: ()=>{
@@ -30,15 +30,11 @@ const createPanelGroupEditorSlice = (set, get)=>({
30
30
  isCollapsed: false
31
31
  },
32
32
  applyChanges (next) {
33
- const newGroup = {
34
- id: (0, _common.generateId)(),
35
- itemLayouts: [],
36
- itemPanelKeys: {},
37
- ...next
38
- };
33
+ const newGroup = (0, _panelGroupSlice.createEmptyPanelGroup)();
34
+ newGroup.title = next.title;
35
+ newGroup.isCollapsed = next.isCollapsed;
39
36
  set((draft)=>{
40
- draft.panelGroups[newGroup.id] = newGroup;
41
- draft.panelGroupOrder.unshift(newGroup.id);
37
+ (0, _panelGroupSlice.addPanelGroup)(draft, newGroup);
42
38
  });
43
39
  },
44
40
  close () {
@@ -22,7 +22,9 @@ function _export(target, all) {
22
22
  }
23
23
  _export(exports, {
24
24
  createPanelGroupSlice: ()=>createPanelGroupSlice,
25
- convertLayoutsToPanelGroups: ()=>convertLayoutsToPanelGroups
25
+ convertLayoutsToPanelGroups: ()=>convertLayoutsToPanelGroups,
26
+ createEmptyPanelGroup: ()=>createEmptyPanelGroup,
27
+ addPanelGroup: ()=>addPanelGroup
26
28
  });
27
29
  const _core = require("@perses-dev/core");
28
30
  const _common = require("./common");
@@ -96,3 +98,16 @@ function convertLayoutsToPanelGroups(layouts) {
96
98
  panelGroupOrder: panelGroupIdOrder
97
99
  };
98
100
  }
101
+ function createEmptyPanelGroup() {
102
+ return {
103
+ id: (0, _common.generateId)(),
104
+ title: undefined,
105
+ isCollapsed: false,
106
+ itemLayouts: [],
107
+ itemPanelKeys: {}
108
+ };
109
+ }
110
+ function addPanelGroup(draft, newGroup) {
111
+ draft.panelGroups[newGroup.id] = newGroup;
112
+ draft.panelGroupOrder.unshift(newGroup.id);
113
+ }
@@ -46,45 +46,40 @@ describe('Panel Groups', ()=>{
46
46
  };
47
47
  it('should delete panel', ()=>{
48
48
  renderDashboard();
49
- const panel = _react.screen.getByText('CPU');
50
- _userEvent.default.hover(panel);
51
- const deletePanelButton = _react.screen.getByLabelText('delete panel');
49
+ const panelTitle = 'CPU';
50
+ const deletePanelButton = _react.screen.getByLabelText(`delete panel ${panelTitle}`);
52
51
  _userEvent.default.click(deletePanelButton);
53
52
  _react.screen.getByText('Delete Panel');
54
53
  const deleteButton = _react.screen.getByText('Delete');
55
54
  _userEvent.default.click(deleteButton);
56
55
  // The panel should disappear
57
- const deletedPanel = _react.screen.queryByText('CPU');
56
+ const deletedPanel = _react.screen.queryByText(panelTitle);
58
57
  expect(deletedPanel).not.toBeInTheDocument();
59
58
  });
60
59
  it('should only delete panel from panel group if panel is not referenced more than once', ()=>{
61
60
  renderDashboard();
62
- const panels = _react.screen.getAllByText('Disk I/O Utilization');
61
+ const panelTitle = 'Disk I/O Utilization';
62
+ const panels = _react.screen.getAllByText(panelTitle);
63
63
  expect(panels).toHaveLength(2);
64
- const panel = panels[0];
65
- if (panel === undefined) throw new Error('Missing panel');
66
- _userEvent.default.hover(panel);
67
- const deletePanelButton = _react.screen.getByLabelText('delete panel');
64
+ const deletePanelButton = _react.screen.getAllByLabelText(`delete panel ${panelTitle}`)[0];
65
+ if (deletePanelButton === undefined) throw new Error('Missing delete button');
68
66
  _userEvent.default.click(deletePanelButton);
69
67
  _react.screen.getByText('Delete Panel');
70
68
  const deleteButton = _react.screen.getByText('Delete');
71
69
  _userEvent.default.click(deleteButton);
72
70
  // The deleted panel should still be on screen in the other group
73
- const deletedPanel = _react.screen.queryByText('Disk I/O Utilization');
71
+ const deletedPanel = _react.screen.queryByText(panelTitle);
74
72
  expect(deletedPanel).toBeInTheDocument();
75
73
  });
76
74
  it('should swap panels', ()=>{
77
75
  renderDashboard();
78
76
  // should move panel down
79
- const group1 = _react.screen.getByText('CPU Stats');
80
- _userEvent.default.hover(group1);
81
- const moveGroupDownBtn = _react.screen.getByLabelText('move group down');
77
+ const groupTitle1 = 'CPU Stats';
78
+ const moveGroupDownBtn = _react.screen.getByLabelText(`move group ${groupTitle1} down`);
82
79
  _userEvent.default.click(moveGroupDownBtn);
83
- _userEvent.default.unhover(moveGroupDownBtn);
84
80
  // should move panel up
85
- const group2 = _react.screen.getByText('Disk Stats');
86
- _userEvent.default.hover(group2);
87
- const moveGroupUpBtn = _react.screen.getByLabelText('move group up');
81
+ const groupTitle2 = 'Disk Stats';
82
+ const moveGroupUpBtn = _react.screen.getByLabelText(`move group ${groupTitle2} up`);
88
83
  _userEvent.default.click(moveGroupUpBtn);
89
84
  /* TODO: Figure out how to test this visually without coupling to the store
90
85
  const layouts = storeApi.getState().layouts;
@@ -94,15 +89,14 @@ describe('Panel Groups', ()=>{
94
89
  */ });
95
90
  it('should delete a panel group', ()=>{
96
91
  renderDashboard();
97
- const group = _react.screen.getByText('CPU Stats');
98
- _userEvent.default.hover(group);
99
- const deleteGroupIcon = _react.screen.getByLabelText('delete group');
92
+ const groupTitle = 'CPU Stats';
93
+ const deleteGroupIcon = _react.screen.getByLabelText(`delete group ${groupTitle}`);
100
94
  _userEvent.default.click(deleteGroupIcon);
101
95
  _react.screen.getByText('Delete Panel Group');
102
96
  const deleteButton = _react.screen.getByText('Delete');
103
97
  _userEvent.default.click(deleteButton);
104
98
  // should remove group
105
- const deletedGroup = _react.screen.queryByText('CPU Stats');
99
+ const deletedGroup = _react.screen.queryByText(groupTitle);
106
100
  expect(deletedGroup).not.toBeInTheDocument();
107
101
  // CPU panel should be completely gone since it wasn't in any other group
108
102
  let panel = _react.screen.queryByText('CPU');
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"names":[],"mappings":";AAsBA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBAmF5D,CAAC"}
1
+ {"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"names":[],"mappings":";AAuBA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;CACjC;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBAoF5D,CAAC"}
@@ -19,6 +19,7 @@ import { ErrorBoundary, ErrorAlert } from '@perses-dev/components';
19
19
  import { useDashboardActions, useEditMode } from '../../context';
20
20
  import { TemplateVariableList } from '../Variables';
21
21
  import { TimeRangeControls } from '../TimeRangeControls';
22
+ import { DownloadButton } from '../DownloadButton';
22
23
  export const DashboardToolbar = (props)=>{
23
24
  const { dashboardName , dashboardTitleComponent , initialVariableIsSticky , onEditButtonClick , onCancelButtonClick } = props;
24
25
  const { isEditMode , setEditMode } = useEditMode();
@@ -47,9 +48,7 @@ export const DashboardToolbar = (props)=>{
47
48
  /*#__PURE__*/ _jsxs(Stack, {
48
49
  direction: "row",
49
50
  spacing: 1,
50
- sx: {
51
- marginLeft: 'auto'
52
- },
51
+ marginLeft: "auto",
53
52
  children: [
54
53
  /*#__PURE__*/ _jsx(Button, {
55
54
  variant: "contained",
@@ -81,11 +80,9 @@ export const DashboardToolbar = (props)=>{
81
80
  })
82
81
  }),
83
82
  /*#__PURE__*/ _jsxs(Stack, {
84
- direction: 'row',
83
+ direction: "row",
85
84
  spacing: 1,
86
- sx: {
87
- marginLeft: 'auto'
88
- },
85
+ marginLeft: "auto",
89
86
  children: [
90
87
  /*#__PURE__*/ _jsx(Button, {
91
88
  startIcon: /*#__PURE__*/ _jsx(AddPanelGroupIcon, {}),
@@ -104,7 +101,7 @@ export const DashboardToolbar = (props)=>{
104
101
  })
105
102
  ]
106
103
  }) : /*#__PURE__*/ _jsxs(Stack, {
107
- spacing: 2,
104
+ spacing: 1,
108
105
  padding: 2,
109
106
  children: [
110
107
  /*#__PURE__*/ _jsxs(Box, {
@@ -116,12 +113,11 @@ export const DashboardToolbar = (props)=>{
116
113
  dashboardTitle,
117
114
  /*#__PURE__*/ _jsxs(Stack, {
118
115
  direction: "row",
119
- spacing: 2,
120
- sx: {
121
- marginLeft: 'auto'
122
- },
116
+ spacing: 1,
117
+ marginLeft: "auto",
123
118
  children: [
124
119
  /*#__PURE__*/ _jsx(TimeRangeControls, {}),
120
+ /*#__PURE__*/ _jsx(DownloadButton, {}),
125
121
  isLaptopSize && /*#__PURE__*/ _jsx(Button, {
126
122
  variant: "outlined",
127
123
  startIcon: /*#__PURE__*/ _jsx(PencilIcon, {}),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Typography, Stack, Button, Box, useTheme, useMediaQuery } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport AddPanelGroupIcon from 'mdi-material-ui/PlusBoxOutline';\nimport AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';\nimport { ErrorBoundary, ErrorAlert } from '@perses-dev/components';\nimport { useDashboardActions, useEditMode } from '../../context';\nimport { TemplateVariableList } from '../Variables';\nimport { TimeRangeControls } from '../TimeRangeControls';\n\nexport interface DashboardToolbarProps {\n dashboardName: string;\n dashboardTitleComponent?: JSX.Element;\n initialVariableIsSticky?: boolean;\n onEditButtonClick: () => void;\n onCancelButtonClick: () => void;\n}\n\nexport const DashboardToolbar = (props: DashboardToolbarProps) => {\n const { dashboardName, dashboardTitleComponent, initialVariableIsSticky, onEditButtonClick, onCancelButtonClick } =\n props;\n\n const { isEditMode, setEditMode } = useEditMode();\n const { openAddPanelGroup, openAddPanel } = useDashboardActions();\n const isLaptopSize = useMediaQuery(useTheme().breakpoints.up('sm'));\n const dashboardTitle = dashboardTitleComponent ? (\n dashboardTitleComponent\n ) : (\n <Typography variant=\"h2\">{dashboardName}</Typography>\n );\n\n const onSave = () => {\n setEditMode(false);\n };\n\n return (\n <>\n {isEditMode ? (\n <Stack spacing={2}>\n <Box sx={{ backgroundColor: (theme) => theme.palette.primary.light + '20' }}>\n <Box padding={2} display=\"flex\">\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} sx={{ marginLeft: 'auto' }}>\n <Button variant=\"contained\" onClick={onSave}>\n Save\n </Button>\n <Button variant=\"outlined\" onClick={onCancelButtonClick}>\n Cancel\n </Button>\n </Stack>\n </Box>\n </Box>\n <Box\n sx={{\n display: 'flex',\n width: '100%',\n alignItems: 'flex-start',\n padding: (theme) => theme.spacing(2),\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList initialVariableIsSticky={initialVariableIsSticky} />\n </ErrorBoundary>\n <Stack direction={'row'} spacing={1} sx={{ marginLeft: 'auto' }}>\n <Button startIcon={<AddPanelGroupIcon />} onClick={openAddPanelGroup}>\n Add Panel Group\n </Button>\n <Button startIcon={<AddPanelIcon />} onClick={openAddPanel}>\n Add Panel\n </Button>\n <TimeRangeControls />\n </Stack>\n </Box>\n </Stack>\n ) : (\n <Stack spacing={2} padding={2}>\n <Box sx={{ display: 'flex', width: '100%' }}>\n {dashboardTitle}\n <Stack direction=\"row\" spacing={2} sx={{ marginLeft: 'auto' }}>\n <TimeRangeControls />\n {isLaptopSize && (\n <Button\n variant=\"outlined\"\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 initialVariableIsSticky={initialVariableIsSticky} />\n </ErrorBoundary>\n </Box>\n </Stack>\n )}\n </>\n );\n};\n"],"names":["Typography","Stack","Button","Box","useTheme","useMediaQuery","PencilIcon","AddPanelGroupIcon","AddPanelIcon","ErrorBoundary","ErrorAlert","useDashboardActions","useEditMode","TemplateVariableList","TimeRangeControls","DashboardToolbar","props","dashboardName","dashboardTitleComponent","initialVariableIsSticky","onEditButtonClick","onCancelButtonClick","isEditMode","setEditMode","openAddPanelGroup","openAddPanel","isLaptopSize","breakpoints","up","dashboardTitle","variant","onSave","spacing","sx","backgroundColor","theme","palette","primary","light","padding","display","direction","marginLeft","onClick","width","alignItems","FallbackComponent","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,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,eAAe,CAAC;AACxF,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,OAAOC,iBAAiB,MAAM,gCAAgC,CAAC;AAC/D,OAAOC,YAAY,MAAM,qCAAqC,CAAC;AAC/D,SAASC,aAAa,EAAEC,UAAU,QAAQ,wBAAwB,CAAC;AACnE,SAASC,mBAAmB,EAAEC,WAAW,QAAQ,eAAe,CAAC;AACjE,SAASC,oBAAoB,QAAQ,cAAc,CAAC;AACpD,SAASC,iBAAiB,QAAQ,sBAAsB,CAAC;AAUzD,OAAO,MAAMC,gBAAgB,GAAG,CAACC,KAA4B,GAAK;IAChE,MAAM,EAAEC,aAAa,CAAA,EAAEC,uBAAuB,CAAA,EAAEC,uBAAuB,CAAA,EAAEC,iBAAiB,CAAA,EAAEC,mBAAmB,CAAA,EAAE,GAC/GL,KAAK,AAAC;IAER,MAAM,EAAEM,UAAU,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAGX,WAAW,EAAE,AAAC;IAClD,MAAM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,EAAEpC,UAAU;kCAC1C,cAAA,KAACG,oBAAoB;4BAACM,uBAAuB,EAAEA,uBAAuB;0BAAI;sBAC5D;kBACZ;;UACA,AACT;MACA,CACH;AACJ,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Typography, Stack, Button, Box, useTheme, useMediaQuery } from '@mui/material';\nimport PencilIcon from 'mdi-material-ui/PencilOutline';\nimport AddPanelGroupIcon from 'mdi-material-ui/PlusBoxOutline';\nimport AddPanelIcon from 'mdi-material-ui/ChartBoxPlusOutline';\nimport { ErrorBoundary, ErrorAlert } from '@perses-dev/components';\nimport { useDashboardActions, useEditMode } from '../../context';\nimport { TemplateVariableList } from '../Variables';\nimport { TimeRangeControls } from '../TimeRangeControls';\nimport { DownloadButton } from '../DownloadButton';\n\nexport interface DashboardToolbarProps {\n dashboardName: string;\n dashboardTitleComponent?: JSX.Element;\n initialVariableIsSticky?: boolean;\n onEditButtonClick: () => void;\n onCancelButtonClick: () => void;\n}\n\nexport const DashboardToolbar = (props: DashboardToolbarProps) => {\n const { dashboardName, dashboardTitleComponent, initialVariableIsSticky, onEditButtonClick, onCancelButtonClick } =\n props;\n\n const { isEditMode, setEditMode } = useEditMode();\n const { openAddPanelGroup, openAddPanel } = useDashboardActions();\n const isLaptopSize = useMediaQuery(useTheme().breakpoints.up('sm'));\n const dashboardTitle = dashboardTitleComponent ? (\n dashboardTitleComponent\n ) : (\n <Typography variant=\"h2\">{dashboardName}</Typography>\n );\n\n const onSave = () => {\n setEditMode(false);\n };\n\n return (\n <>\n {isEditMode ? (\n <Stack spacing={2}>\n <Box sx={{ backgroundColor: (theme) => theme.palette.primary.light + '20' }}>\n <Box padding={2} display=\"flex\">\n {dashboardTitle}\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button variant=\"contained\" onClick={onSave}>\n Save\n </Button>\n <Button variant=\"outlined\" onClick={onCancelButtonClick}>\n Cancel\n </Button>\n </Stack>\n </Box>\n </Box>\n <Box\n sx={{\n display: 'flex',\n width: '100%',\n alignItems: 'flex-start',\n padding: (theme) => theme.spacing(2),\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <TemplateVariableList initialVariableIsSticky={initialVariableIsSticky} />\n </ErrorBoundary>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button startIcon={<AddPanelGroupIcon />} onClick={openAddPanelGroup}>\n Add Panel Group\n </Button>\n <Button startIcon={<AddPanelIcon />} onClick={openAddPanel}>\n Add Panel\n </Button>\n <TimeRangeControls />\n </Stack>\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 {isLaptopSize && (\n <Button\n variant=\"outlined\"\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 initialVariableIsSticky={initialVariableIsSticky} />\n </ErrorBoundary>\n </Box>\n </Stack>\n )}\n </>\n );\n};\n"],"names":["Typography","Stack","Button","Box","useTheme","useMediaQuery","PencilIcon","AddPanelGroupIcon","AddPanelIcon","ErrorBoundary","ErrorAlert","useDashboardActions","useEditMode","TemplateVariableList","TimeRangeControls","DownloadButton","DashboardToolbar","props","dashboardName","dashboardTitleComponent","initialVariableIsSticky","onEditButtonClick","onCancelButtonClick","isEditMode","setEditMode","openAddPanelGroup","openAddPanel","isLaptopSize","breakpoints","up","dashboardTitle","variant","onSave","spacing","sx","backgroundColor","theme","palette","primary","light","padding","display","direction","marginLeft","onClick","width","alignItems","FallbackComponent","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,UAAU,EAAEC,KAAK,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,aAAa,QAAQ,eAAe,CAAC;AACxF,OAAOC,UAAU,MAAM,+BAA+B,CAAC;AACvD,OAAOC,iBAAiB,MAAM,gCAAgC,CAAC;AAC/D,OAAOC,YAAY,MAAM,qCAAqC,CAAC;AAC/D,SAASC,aAAa,EAAEC,UAAU,QAAQ,wBAAwB,CAAC;AACnE,SAASC,mBAAmB,EAAEC,WAAW,QAAQ,eAAe,CAAC;AACjE,SAASC,oBAAoB,QAAQ,cAAc,CAAC;AACpD,SAASC,iBAAiB,QAAQ,sBAAsB,CAAC;AACzD,SAASC,cAAc,QAAQ,mBAAmB,CAAC;AAUnD,OAAO,MAAMC,gBAAgB,GAAG,CAACC,KAA4B,GAAK;IAChE,MAAM,EAAEC,aAAa,CAAA,EAAEC,uBAAuB,CAAA,EAAEC,uBAAuB,CAAA,EAAEC,iBAAiB,CAAA,EAAEC,mBAAmB,CAAA,EAAE,GAC/GL,KAAK,AAAC;IAER,MAAM,EAAEM,UAAU,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAGZ,WAAW,EAAE,AAAC;IAClD,MAAM,EAAEa,iBAAiB,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGf,mBAAmB,EAAE,AAAC;IAClE,MAAMg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0 +1,3 @@
1
+ /// <reference types="react" />
2
+ export declare function DownloadButton(): JSX.Element;
3
+ //# sourceMappingURL=DownloadButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DownloadButton.d.ts","sourceRoot":"","sources":["../../../src/components/DownloadButton/DownloadButton.tsx"],"names":[],"mappings":";AAmBA,wBAAgB,cAAc,gBA8B7B"}
@@ -0,0 +1,60 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
+ import React, { useRef } from 'react';
15
+ import DownloadIcon from 'mdi-material-ui/DownloadOutline';
16
+ import { IconButton, styled } from '@mui/material';
17
+ import { useDashboard } from '../../context';
18
+ // Button to download the dashboard as a JSON file.
19
+ export function DownloadButton() {
20
+ const { dashboard } = useDashboard();
21
+ const hiddenLinkRef = useRef(null);
22
+ const onDownloadButtonClick = ()=>{
23
+ if (!hiddenLinkRef || !hiddenLinkRef.current) return;
24
+ // Create blob URL
25
+ const hiddenLinkUrl = URL.createObjectURL(new Blob([
26
+ JSON.stringify(dashboard)
27
+ ], {
28
+ type: 'application/json'
29
+ }));
30
+ // Simulate click
31
+ hiddenLinkRef.current.href = hiddenLinkUrl;
32
+ hiddenLinkRef.current.click();
33
+ // Remove blob URL (for memory management)
34
+ URL.revokeObjectURL(hiddenLinkUrl);
35
+ };
36
+ return /*#__PURE__*/ _jsxs(_Fragment, {
37
+ children: [
38
+ /*#__PURE__*/ _jsx(DownloadIconButton, {
39
+ title: "Download JSON",
40
+ onClick: onDownloadButtonClick,
41
+ children: /*#__PURE__*/ _jsx(DownloadIcon, {})
42
+ }),
43
+ /*#__PURE__*/ _jsx("a", {
44
+ ref: hiddenLinkRef,
45
+ style: {
46
+ display: 'none'
47
+ },
48
+ download: `${dashboard.metadata.name}.json`
49
+ })
50
+ ]
51
+ });
52
+ }
53
+ const DownloadIconButton = styled(IconButton)(({ theme })=>({
54
+ border: `1px solid ${theme.palette.grey[300]}`,
55
+ borderRadius: theme.shape.borderRadius,
56
+ padding: '4px',
57
+ color: theme.palette.grey[900]
58
+ }));
59
+
60
+ //# sourceMappingURL=DownloadButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/DownloadButton/DownloadButton.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { useRef } from 'react';\nimport DownloadIcon from 'mdi-material-ui/DownloadOutline';\nimport { IconButton, styled } from '@mui/material';\nimport { useDashboard } from '../../context';\n\n// Button to download the dashboard as a JSON file.\nexport function DownloadButton() {\n const { dashboard } = useDashboard();\n const hiddenLinkRef = useRef<HTMLAnchorElement>(null);\n\n const onDownloadButtonClick = () => {\n if (!hiddenLinkRef || !hiddenLinkRef.current) return;\n // Create blob URL\n const hiddenLinkUrl = URL.createObjectURL(\n new Blob([JSON.stringify(dashboard)], {\n type: 'application/json',\n })\n );\n // Simulate click\n hiddenLinkRef.current.href = hiddenLinkUrl;\n hiddenLinkRef.current.click();\n // Remove blob URL (for memory management)\n URL.revokeObjectURL(hiddenLinkUrl);\n };\n\n return (\n <>\n <DownloadIconButton title=\"Download JSON\" onClick={onDownloadButtonClick}>\n <DownloadIcon />\n </DownloadIconButton>\n {/* Hidden link to download the dashboard as a JSON file */}\n {/* eslint-disable jsx-a11y/anchor-has-content */}\n {/* eslint-disable jsx-a11y/anchor-is-valid */}\n <a ref={hiddenLinkRef} style={{ display: 'none' }} download={`${dashboard.metadata.name}.json`} />\n </>\n );\n}\n\nconst DownloadIconButton = styled(IconButton)(({ theme }) => ({\n border: `1px solid ${theme.palette.grey[300]}`,\n borderRadius: theme.shape.borderRadius,\n padding: '4px',\n color: theme.palette.grey[900],\n}));\n"],"names":["React","useRef","DownloadIcon","IconButton","styled","useDashboard","DownloadButton","dashboard","hiddenLinkRef","onDownloadButtonClick","current","hiddenLinkUrl","URL","createObjectURL","Blob","JSON","stringify","type","href","click","revokeObjectURL","DownloadIconButton","title","onClick","a","ref","style","display","download","metadata","name","theme","border","palette","grey","borderRadius","shape","padding","color"],"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,OAAOA,KAAK,IAAIC,MAAM,QAAQ,OAAO,CAAC;AACtC,OAAOC,YAAY,MAAM,iCAAiC,CAAC;AAC3D,SAASC,UAAU,EAAEC,MAAM,QAAQ,eAAe,CAAC;AACnD,SAASC,YAAY,QAAQ,eAAe,CAAC;AAE7C,mDAAmD;AACnD,OAAO,SAASC,cAAc,GAAG;IAC/B,MAAM,EAAEC,SAAS,CAAA,EAAE,GAAGF,YAAY,EAAE,AAAC;IACrC,MAAMG,aAAa,GAAGP,MAAM,CAAoB,IAAI,CAAC,AAAC;IAEtD,MAAMQ,qBAAqB,GAAG,IAAM;QAClC,IAAI,CAACD,aAAa,IAAI,CAACA,aAAa,CAACE,OAAO,EAAE,OAAO;QACrD,kBAAkB;QAClB,MAAMC,aAAa,GAAGC,GAAG,CAACC,eAAe,CACvC,IAAIC,IAAI,CAAC;YAACC,IAAI,CAACC,SAAS,CAACT,SAAS,CAAC;SAAC,EAAE;YACpCU,IAAI,EAAE,kBAAkB;SACzB,CAAC,CACH,AAAC;QACF,iBAAiB;QACjBT,aAAa,CAACE,OAAO,CAACQ,IAAI,GAAGP,aAAa,CAAC;QAC3CH,aAAa,CAACE,OAAO,CAACS,KAAK,EAAE,CAAC;QAC9B,0CAA0C;QAC1CP,GAAG,CAACQ,eAAe,CAACT,aAAa,CAAC,CAAC;IACrC,CAAC,AAAC;IAEF,qBACE;;0BACE,KAACU,kBAAkB;gBAACC,KAAK,EAAC,eAAe;gBAACC,OAAO,EAAEd,qBAAqB;0BACtE,cAAA,KAACP,YAAY,KAAG;cACG;0BAIrB,KAACsB,GAAC;gBAACC,GAAG,EAAEjB,aAAa;gBAAEkB,KAAK,EAAE;oBAAEC,OAAO,EAAE,MAAM;iBAAE;gBAAEC,QAAQ,EAAE,CAAC,EAAErB,SAAS,CAACsB,QAAQ,CAACC,IAAI,CAAC,KAAK,CAAC;cAAI;;MACjG,CACH;AACJ,CAAC;AAED,MAAMT,kBAAkB,GAAGjB,MAAM,CAACD,UAAU,CAAC,CAAC,CAAC,EAAE4B,KAAK,CAAA,EAAE,GAAM,CAAA;QAC5DC,MAAM,EAAE,CAAC,UAAU,EAAED,KAAK,CAACE,OAAO,CAACC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9CC,YAAY,EAAEJ,KAAK,CAACK,KAAK,CAACD,YAAY;QACtCE,OAAO,EAAE,KAAK;QACdC,KAAK,EAAEP,KAAK,CAACE,OAAO,CAACC,IAAI,CAAC,GAAG,CAAC;KAC/B,CAAA,AAAC,CAAC,AAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './DownloadButton';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DownloadButton/index.ts"],"names":[],"mappings":"AAaA,cAAc,kBAAkB,CAAC"}
@@ -10,18 +10,6 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { useRef } from 'react';
14
- /**
15
- * Generates a unique (stable) ID for a component. Should be replaced with React.useId once we support only React 18.
16
- */ export function useId(prefix) {
17
- if (globalThis.useIdValue === undefined) {
18
- globalThis.useIdValue = 0;
19
- }
20
- const id = useRef(undefined);
21
- if (id.current === undefined) {
22
- id.current = `${prefix}-${globalThis.useIdValue++}`;
23
- }
24
- return id.current;
25
- }
13
+ export * from './DownloadButton';
26
14
 
27
- //# sourceMappingURL=component-ids.js.map
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/DownloadButton/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DownloadButton';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,kBAAkB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAoD,YAAY,EAAE,MAAM,eAAe,CAAC;AAO/F,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,YAAY,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eA+ChD"}
1
+ {"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAoD,YAAY,EAAE,MAAM,eAAe,CAAC;AAO/F,MAAM,WAAW,eAAe;IAC9B,YAAY,EAAE,YAAY,CAAC;CAC5B;AAID;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eA0DhD"}
@@ -20,6 +20,7 @@ import { GridTitle } from './GridTitle';
20
20
  import { GridItemContent } from './GridItemContent';
21
21
  import { GridContainer } from './GridContainer';
22
22
  const ResponsiveGridLayout = WidthProvider(Responsive);
23
+ const SMALL_LAYOUT_BREAKPOINT = 'sm';
23
24
  /**
24
25
  * Layout component that arranges children in a Grid based on the definition.
25
26
  */ export function GridLayout(props) {
@@ -30,6 +31,16 @@ const ResponsiveGridLayout = WidthProvider(Responsive);
30
31
  var ref;
31
32
  const [isOpen, setIsOpen] = useState((ref = !groupDefinition.isCollapsed) !== null && ref !== void 0 ? ref : true);
32
33
  const { isEditMode } = useEditMode();
34
+ const handleLayoutChange = (currentLayout, allLayouts)=>{
35
+ // Using the value from `allLayouts` instead of `currentLayout` because of
36
+ // a bug in react-layout-grid where `currentLayout` does not adjust properly
37
+ // when going to a smaller breakpoint and then back to a larger breakpoint.
38
+ // https://github.com/react-grid-layout/react-grid-layout/issues/1663
39
+ const smallLayout = allLayouts[SMALL_LAYOUT_BREAKPOINT];
40
+ if (smallLayout) {
41
+ updatePanelGroupLayouts(smallLayout);
42
+ }
43
+ };
33
44
  return /*#__PURE__*/ _jsxs(GridContainer, {
34
45
  children: [
35
46
  groupDefinition.title !== undefined && /*#__PURE__*/ _jsx(GridTitle, {
@@ -66,9 +77,9 @@ const ResponsiveGridLayout = WidthProvider(Responsive);
66
77
  10
67
78
  ],
68
79
  layouts: {
69
- sm: groupDefinition.itemLayouts
80
+ [SMALL_LAYOUT_BREAKPOINT]: groupDefinition.itemLayouts
70
81
  },
71
- onLayoutChange: updatePanelGroupLayouts,
82
+ onLayoutChange: handleLayoutChange,
72
83
  children: groupDefinition.itemLayouts.map(({ i })=>/*#__PURE__*/ _jsx("div", {
73
84
  children: /*#__PURE__*/ _jsx(ErrorBoundary, {
74
85
  FallbackComponent: ErrorAlert,