@perses-dev/dashboards 0.11.0 → 0.12.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 (108) hide show
  1. package/dist/cjs/components/DashboardToolbar.js +9 -2
  2. package/dist/cjs/components/GridLayout/GridLayout.js +14 -16
  3. package/dist/cjs/components/Panel/DeletePanelDialog.js +2 -4
  4. package/dist/cjs/components/Panel/Panel.js +8 -9
  5. package/dist/cjs/components/Panel/Panel.test.js +2 -1
  6. package/dist/cjs/components/Panel/index.js +1 -0
  7. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +12 -4
  8. package/dist/cjs/components/PanelDrawer/PanelPreview.js +2 -2
  9. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +15 -15
  10. package/dist/cjs/components/Variables/VariableEditor.js +7 -6
  11. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
  12. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +8 -2
  13. package/dist/cjs/context/DashboardProvider/common.js +10 -0
  14. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +12 -12
  15. package/dist/cjs/context/DashboardProvider/delete-panel-group-slice.js +70 -0
  16. package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +85 -0
  17. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +74 -67
  18. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +6 -19
  19. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +39 -144
  20. package/dist/cjs/context/DashboardProvider/panel-slice.js +36 -0
  21. package/dist/cjs/context/useDashboardSpec.js +37 -8
  22. package/dist/cjs/utils/time-range-params.js +14 -8
  23. package/dist/cjs/views/ViewDashboard/DashboardApp.js +0 -1
  24. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  25. package/dist/components/DashboardToolbar.js +10 -3
  26. package/dist/components/DashboardToolbar.js.map +1 -1
  27. package/dist/components/GridLayout/GridItemContent.d.ts +2 -2
  28. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  29. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  30. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  31. package/dist/components/GridLayout/GridLayout.js +16 -18
  32. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  33. package/dist/components/Panel/DeletePanelDialog.d.ts +0 -1
  34. package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -1
  35. package/dist/components/Panel/DeletePanelDialog.js +2 -4
  36. package/dist/components/Panel/DeletePanelDialog.js.map +1 -1
  37. package/dist/components/Panel/Panel.d.ts +2 -2
  38. package/dist/components/Panel/Panel.d.ts.map +1 -1
  39. package/dist/components/Panel/Panel.js +7 -8
  40. package/dist/components/Panel/Panel.js.map +1 -1
  41. package/dist/components/Panel/Panel.test.js +2 -1
  42. package/dist/components/Panel/Panel.test.js.map +1 -1
  43. package/dist/components/Panel/index.d.ts +1 -0
  44. package/dist/components/Panel/index.d.ts.map +1 -1
  45. package/dist/components/Panel/index.js +1 -0
  46. package/dist/components/Panel/index.js.map +1 -1
  47. package/dist/components/PanelDrawer/PanelDrawer.test.js +12 -4
  48. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  49. package/dist/components/PanelDrawer/PanelPreview.js +2 -2
  50. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  51. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +15 -15
  52. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  53. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  54. package/dist/components/Variables/VariableEditor.js +7 -6
  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 +9 -5
  58. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  59. package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -1
  60. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  61. package/dist/context/DashboardProvider/DashboardProvider.js +8 -2
  62. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  63. package/dist/context/DashboardProvider/common.d.ts +7 -0
  64. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  65. package/dist/context/DashboardProvider/common.js +8 -1
  66. package/dist/context/DashboardProvider/common.js.map +1 -1
  67. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +5 -4
  68. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  69. package/dist/context/DashboardProvider/dashboard-provider-api.js +12 -12
  70. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  71. package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +23 -0
  72. package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -0
  73. package/dist/context/DashboardProvider/delete-panel-group-slice.js +64 -0
  74. package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -0
  75. package/dist/context/DashboardProvider/delete-panel-slice.d.ts +36 -0
  76. package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -0
  77. package/dist/context/DashboardProvider/delete-panel-slice.js +81 -0
  78. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -0
  79. package/dist/context/DashboardProvider/index.d.ts +2 -1
  80. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  81. package/dist/context/DashboardProvider/index.js.map +1 -1
  82. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +6 -35
  83. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  84. package/dist/context/DashboardProvider/panel-editor-slice.js +74 -67
  85. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  86. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -8
  87. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  88. package/dist/context/DashboardProvider/panel-group-editor-slice.js +6 -19
  89. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  90. package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -31
  91. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  92. package/dist/context/DashboardProvider/panel-group-slice.js +40 -145
  93. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  94. package/dist/context/DashboardProvider/panel-slice.d.ts +23 -0
  95. package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -0
  96. package/dist/context/DashboardProvider/panel-slice.js +32 -0
  97. package/dist/context/DashboardProvider/panel-slice.js.map +1 -0
  98. package/dist/context/useDashboardSpec.d.ts +10 -2
  99. package/dist/context/useDashboardSpec.d.ts.map +1 -1
  100. package/dist/context/useDashboardSpec.js +38 -9
  101. package/dist/context/useDashboardSpec.js.map +1 -1
  102. package/dist/utils/time-range-params.d.ts.map +1 -1
  103. package/dist/utils/time-range-params.js +15 -9
  104. package/dist/utils/time-range-params.js.map +1 -1
  105. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  106. package/dist/views/ViewDashboard/DashboardApp.js +0 -1
  107. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  108. package/package.json +4 -4
@@ -19,6 +19,7 @@ Object.defineProperty(exports, "DashboardToolbar", {
19
19
  get: ()=>DashboardToolbar
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
22
23
  const _material = require("@mui/material");
23
24
  const _pencilOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PencilOutline"));
24
25
  const _plusBoxOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PlusBoxOutline"));
@@ -34,13 +35,19 @@ function _interopRequireDefault(obj) {
34
35
  const DashboardToolbar = (props)=>{
35
36
  const { dashboardName } = props;
36
37
  const { isEditMode , setEditMode } = (0, _context.useEditMode)();
37
- const { openAddPanelGroup , openAddPanel , reset , save } = (0, _context.useDashboardActions)();
38
+ const { openAddPanelGroup , openAddPanel , save } = (0, _context.useDashboardActions)();
38
39
  const isLaptopSize = (0, _material.useMediaQuery)((0, _material.useTheme)().breakpoints.up('sm'));
40
+ const [originalSpec, setOriginalSpec] = (0, _react.useState)(undefined);
41
+ const { spec , resetSpec } = (0, _context.useDashboardSpec)();
39
42
  const onEditButtonClick = ()=>{
43
+ setOriginalSpec(spec);
40
44
  setEditMode(true);
41
45
  };
42
46
  const onCancelButtonClick = ()=>{
43
- reset();
47
+ // Reset to the original spec and exit edit mode
48
+ if (originalSpec) {
49
+ resetSpec(originalSpec);
50
+ }
44
51
  setEditMode(false);
45
52
  };
46
53
  const onSave = ()=>{
@@ -30,7 +30,9 @@ const _gridItemContent = require("./GridItemContent");
30
30
  const ResponsiveGridLayout = (0, _reactGridLayout.WidthProvider)(_reactGridLayout.Responsive);
31
31
  function GridLayout(props) {
32
32
  const { panelGroupId , ...others } = props;
33
+ const theme = (0, _material.useTheme)();
33
34
  const groupDefinition = (0, _context.usePanelGroup)(panelGroupId);
35
+ const { updatePanelGroupLayouts } = (0, _context.usePanelGroupActions)(panelGroupId);
34
36
  var ref;
35
37
  const [isOpen, setIsOpen] = (0, _react.useState)((ref = !groupDefinition.isCollapsed) !== null && ref !== void 0 ? ref : true);
36
38
  const { isEditMode } = (0, _context.useEditMode)();
@@ -62,17 +64,11 @@ function GridLayout(props) {
62
64
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(ResponsiveGridLayout, {
63
65
  className: "layout",
64
66
  breakpoints: {
65
- lg: 1200,
66
- md: 996,
67
- sm: 768,
68
- xs: 480,
67
+ sm: theme.breakpoints.values.sm,
69
68
  xxs: 0
70
69
  },
71
70
  cols: {
72
- lg: 24,
73
- md: 24,
74
71
  sm: 24,
75
- xs: 24,
76
72
  xxs: 2
77
73
  },
78
74
  rowHeight: 30,
@@ -82,23 +78,25 @@ function GridLayout(props) {
82
78
  ],
83
79
  isDraggable: isEditMode,
84
80
  isResizable: isEditMode,
85
- children: groupDefinition.items.map(({ x , y , width , height }, itemIndex)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
86
- "data-grid": {
87
- x,
88
- y,
89
- w: width,
90
- h: height
91
- },
81
+ containerPadding: [
82
+ 0,
83
+ 10
84
+ ],
85
+ layouts: {
86
+ sm: groupDefinition.itemLayouts
87
+ },
88
+ onLayoutChange: updatePanelGroupLayouts,
89
+ children: groupDefinition.itemLayouts.map(({ i })=>/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
92
90
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
93
91
  FallbackComponent: _components.ErrorAlert,
94
92
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_gridItemContent.GridItemContent, {
95
93
  panelGroupItemId: {
96
94
  panelGroupId,
97
- itemIndex
95
+ panelGroupItemLayoutId: i
98
96
  }
99
97
  })
100
98
  })
101
- }, itemIndex))
99
+ }, i))
102
100
  })
103
101
  })
104
102
  ]
@@ -52,13 +52,11 @@ const DeletePanelDialog = ()=>{
52
52
  });
53
53
  };
54
54
  const DeletePanelForm = ({ deletePanelDialog })=>{
55
- const { deletePanels , closeDeletePanelDialog } = (0, _context.useDeletePanelDialog)();
55
+ const { deletePanel , closeDeletePanelDialog } = (0, _context.useDeletePanelDialog)();
56
56
  const handleDelete = (e)=>{
57
57
  e.preventDefault();
58
58
  const { panelGroupItemId } = deletePanelDialog;
59
- deletePanels([
60
- panelGroupItemId
61
- ]);
59
+ deletePanel(panelGroupItemId);
62
60
  closeDeletePanelDialog();
63
61
  };
64
62
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("form", {
@@ -25,7 +25,7 @@ const _reactIntersectionObserver = require("react-intersection-observer");
25
25
  const _components = require("@perses-dev/components");
26
26
  const _material = require("@mui/material");
27
27
  const _informationOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/InformationOutline"));
28
- const _pencil = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pencil"));
28
+ const _pencilOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PencilOutline"));
29
29
  const _deleteOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/DeleteOutline"));
30
30
  const _dragVertical = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/DragVertical"));
31
31
  const _context = require("../../context");
@@ -80,13 +80,11 @@ function Panel(props) {
80
80
  sx: {
81
81
  display: 'flex',
82
82
  alignItems: 'center',
83
- minHeight: '24px'
83
+ minHeight: '32px'
84
84
  },
85
85
  children: [
86
86
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
87
- component: "h2",
88
- variant: "body2",
89
- fontWeight: (theme)=>theme.typography.fontWeightMedium,
87
+ variant: "subtitle1",
90
88
  whiteSpace: "nowrap",
91
89
  overflow: "hidden",
92
90
  textOverflow: "ellipsis",
@@ -106,9 +104,9 @@ function Panel(props) {
106
104
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_informationOutline.default, {
107
105
  "aria-describedby": "info-tooltip",
108
106
  "aria-hidden": false,
109
- fontSize: "small",
110
107
  sx: {
111
- cursor: 'pointer'
108
+ cursor: 'pointer',
109
+ color: (theme)=>theme.palette.grey[700]
112
110
  }
113
111
  })
114
112
  }),
@@ -121,7 +119,7 @@ function Panel(props) {
121
119
  "aria-label": "edit panel",
122
120
  size: "small",
123
121
  onClick: openEditPanel,
124
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencil.default, {})
122
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencilOutline.default, {})
125
123
  }),
126
124
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(IconButton, {
127
125
  "aria-label": "delete panel",
@@ -147,7 +145,8 @@ function Panel(props) {
147
145
  }),
148
146
  sx: {
149
147
  display: 'block',
150
- padding: (theme)=>theme.spacing(1, panelPadding),
148
+ paddingX: (theme)=>theme.spacing(panelPadding),
149
+ paddingY: '4px',
151
150
  borderBottom: (theme)=>`solid 1px ${theme.palette.divider}`
152
151
  }
153
152
  }),
@@ -43,9 +43,10 @@ describe('Panel', ()=>{
43
43
  }
44
44
  }
45
45
  },
46
+ // TODO: This is coupled to ID generation which is not good and the tests will probably fail
46
47
  panelGroupItemId: {
47
48
  panelGroupId: 0,
48
- itemIndex: 0
49
+ panelGroupItemLayoutId: ''
49
50
  }
50
51
  };
51
52
  };
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _exportStar(require("./Panel"), exports);
18
+ _exportStar(require("./DeletePanelDialog"), exports);
18
19
  function _exportStar(from, to) {
19
20
  Object.keys(from).forEach(function(k) {
20
21
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -53,8 +53,8 @@ describe('Panel Drawer', ()=>{
53
53
  };
54
54
  it('should add new panel', async ()=>{
55
55
  const storeApi = renderPanelDrawer();
56
- // Open the drawer for a new panel (i.e. no panel key)
57
- (0, _testUtils.act)(()=>storeApi.getState().openAddPanel(0));
56
+ // Open the drawer for a new panel
57
+ (0, _testUtils.act)(()=>storeApi.getState().openAddPanel());
58
58
  const nameInput = await _react.screen.findByLabelText(/Name/);
59
59
  _userEvent.default.type(nameInput, 'New Panel');
60
60
  _userEvent.default.click(_react.screen.getByText('Add'));
@@ -79,9 +79,17 @@ describe('Panel Drawer', ()=>{
79
79
  it('should edit an existing panel', async ()=>{
80
80
  const storeApi = renderPanelDrawer();
81
81
  // Open the drawer for an existing panel
82
+ const group = Object.values(storeApi.getState().panelGroups).find((group)=>group.title === 'CPU Stats');
83
+ if (group === undefined) {
84
+ throw new Error('Test group not found');
85
+ }
86
+ const layout = Object.entries(group.itemPanelKeys).find(([, panelKey])=>panelKey === 'cpu');
87
+ if (layout === undefined) {
88
+ throw new Error('Test panel not found');
89
+ }
82
90
  (0, _testUtils.act)(()=>storeApi.getState().openEditPanel({
83
- panelGroupId: 0,
84
- itemIndex: 0
91
+ panelGroupId: group.id,
92
+ panelGroupItemLayoutId: layout[0]
85
93
  }));
86
94
  const nameInput = await _react.screen.findByLabelText(/Name/);
87
95
  _userEvent.default.clear(nameInput);
@@ -36,10 +36,10 @@ function PanelPreview({ name , description , kind , spec , groupId }) {
36
36
  }
37
37
  }
38
38
  },
39
- // TODO: what should itemIndex be?
39
+ // TODO: this shouldn't be necessary for preview
40
40
  panelGroupItemId: {
41
41
  panelGroupId: groupId,
42
- itemIndex: 0
42
+ panelGroupItemLayoutId: ''
43
43
  }
44
44
  };
45
45
  if (!kind) {
@@ -20,7 +20,6 @@ const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-librar
20
20
  const _testUtils = require("react-dom/test-utils");
21
21
  const _context = require("../../context");
22
22
  const _test = require("../../test");
23
- const _testDashboard = /*#__PURE__*/ _interopRequireDefault(require("../../test/testDashboard"));
24
23
  const _panelGroupDialog = require("./PanelGroupDialog");
25
24
  function _interopRequireDefault(obj) {
26
25
  return obj && obj.__esModule ? obj : {
@@ -54,21 +53,23 @@ describe('Add Panel Group', ()=>{
54
53
  _userEvent.default.type(nameInput, 'New Panel Group');
55
54
  _userEvent.default.click(_react.screen.getByText('Add'));
56
55
  // TODO: Figure out how to test this without coupling to the store state
57
- const panelGroups = storeApi.getState().panelGroups;
58
- expect(panelGroups).toMatchObject({
59
- '3': {
60
- id: 3,
61
- title: 'New Panel Group',
62
- isCollapsed: false,
63
- items: []
64
- }
56
+ const panelGroups = Object.values(storeApi.getState().panelGroups);
57
+ expect(panelGroups).toContainEqual({
58
+ id: expect.any(Number),
59
+ title: 'New Panel Group',
60
+ isCollapsed: false,
61
+ itemLayouts: expect.any(Array),
62
+ itemPanelKeys: expect.any(Object)
65
63
  });
66
64
  });
67
65
  it('should edit existing panel group', async ()=>{
68
- var ref;
69
66
  const storeApi = renderDialog();
70
67
  // Open the dialog for an existing panel group
71
- (0, _testUtils.act)(()=>storeApi.getState().openEditPanelGroup(0));
68
+ const group = Object.values(storeApi.getState().panelGroups).find((group)=>group.title === 'CPU Stats');
69
+ if (group === undefined) {
70
+ throw new Error('Missing test group');
71
+ }
72
+ (0, _testUtils.act)(()=>storeApi.getState().openEditPanelGroup(group.id));
72
73
  const nameInput = await _react.screen.findByLabelText(/Name/);
73
74
  _userEvent.default.clear(nameInput);
74
75
  _userEvent.default.type(nameInput, 'New Name');
@@ -76,11 +77,10 @@ describe('Add Panel Group', ()=>{
76
77
  // TODO: Figure out how to test this without coupling to the store state
77
78
  const panelGroups = storeApi.getState().panelGroups;
78
79
  expect(panelGroups).toMatchObject({
79
- '0': {
80
- id: 0,
80
+ [group.id]: {
81
+ id: group.id,
81
82
  title: 'New Name',
82
- isCollapsed: false,
83
- items: (ref = _testDashboard.default.spec.layouts[0]) === null || ref === void 0 ? void 0 : ref.spec.items
83
+ isCollapsed: false
84
84
  }
85
85
  });
86
86
  });
@@ -117,18 +117,19 @@ function VariableEditor(props) {
117
117
  justifyContent: "end",
118
118
  children: [
119
119
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
120
+ disabled: props.variableDefinitions === variableDefinitions,
121
+ variant: "contained",
120
122
  onClick: ()=>{
121
- props.onCancel();
123
+ props.onChange(variableDefinitions);
122
124
  },
123
- children: "Cancel"
125
+ children: "Apply"
124
126
  }),
125
127
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
126
- disabled: props.variableDefinitions === variableDefinitions,
127
- variant: "contained",
128
+ variant: "outlined",
128
129
  onClick: ()=>{
129
- props.onChange(variableDefinitions);
130
+ props.onCancel();
130
131
  },
131
- children: "Apply Changes"
132
+ children: "Cancel"
132
133
  })
133
134
  ]
134
135
  }),
@@ -54,6 +54,7 @@ function VariableEditForm({ initialVariableDefinition , onChange , onCancel })
54
54
  item: true,
55
55
  xs: 6,
56
56
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
57
+ fullWidth: true,
57
58
  label: "Name",
58
59
  value: state.name,
59
60
  onChange: (v)=>{
@@ -95,6 +96,7 @@ function VariableEditForm({ initialVariableDefinition , onChange , onCancel })
95
96
  item: true,
96
97
  xs: 6,
97
98
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
99
+ fullWidth: true,
98
100
  label: "Label",
99
101
  value: state.label,
100
102
  onChange: (v)=>{
@@ -108,6 +110,7 @@ function VariableEditForm({ initialVariableDefinition , onChange , onCancel })
108
110
  item: true,
109
111
  xs: 12,
110
112
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
113
+ fullWidth: true,
111
114
  label: "Description",
112
115
  value: state.description,
113
116
  onChange: (v)=>{
@@ -217,17 +220,18 @@ function VariableEditForm({ initialVariableDefinition , onChange , onCancel })
217
220
  justifyContent: "end",
218
221
  children: [
219
222
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
223
+ variant: "contained",
220
224
  onClick: ()=>{
221
- onCancel();
225
+ onChange((0, _variableEditorFormModel.getVariableDefinitionFromState)(state));
222
226
  },
223
- children: "Cancel"
227
+ children: "Update"
224
228
  }),
225
229
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
226
- variant: "contained",
230
+ variant: "outlined",
227
231
  onClick: ()=>{
228
- onChange((0, _variableEditorFormModel.getVariableDefinitionFromState)(state));
232
+ onCancel();
229
233
  },
230
- children: "Update Variable"
234
+ children: "Cancel"
231
235
  })
232
236
  ]
233
237
  })
@@ -34,6 +34,9 @@ const _react = require("react");
34
34
  const _panelGroupEditorSlice = require("./panel-group-editor-slice");
35
35
  const _panelGroupSlice = require("./panel-group-slice");
36
36
  const _panelEditorSlice = require("./panel-editor-slice");
37
+ const _panelSlice = require("./panel-slice");
38
+ const _deletePanelGroupSlice = require("./delete-panel-group-slice");
39
+ const _deletePanelSlice = require("./delete-panel-slice");
37
40
  function _interopRequireDefault(obj) {
38
41
  return obj && obj.__esModule ? obj : {
39
42
  default: obj
@@ -53,9 +56,12 @@ function DashboardProvider(props) {
53
56
  const dashboardStore = (0, _zustand.createStore)()((0, _immer.immer)((0, _middleware.devtools)((...args)=>{
54
57
  const [set, get] = args;
55
58
  return {
56
- ...(0, _panelGroupEditorSlice.createPanelGroupEditorSlice)(...args),
57
59
  ...(0, _panelGroupSlice.createPanelGroupSlice)(layouts)(...args),
58
- ...(0, _panelEditorSlice.createPanelEditorSlice)(panels)(...args),
60
+ ...(0, _panelSlice.createPanelSlice)(panels)(...args),
61
+ ...(0, _panelGroupEditorSlice.createPanelGroupEditorSlice)(...args),
62
+ ...(0, _deletePanelGroupSlice.createDeletePanelGroupSlice)(...args),
63
+ ...(0, _panelEditorSlice.createPanelEditorSlice)()(...args),
64
+ ...(0, _deletePanelSlice.createDeletePanelSlice)()(...args),
59
65
  defaultTimeRange: {
60
66
  pastDuration: dashboardSpec.duration
61
67
  },
@@ -16,3 +16,13 @@
16
16
  Object.defineProperty(exports, "__esModule", {
17
17
  value: true
18
18
  });
19
+ Object.defineProperty(exports, "generateId", {
20
+ enumerable: true,
21
+ get: ()=>generateId
22
+ });
23
+ function generateId() {
24
+ if (globalThis.dashboardStoreId === undefined) {
25
+ globalThis.dashboardStoreId = -1;
26
+ }
27
+ return globalThis.dashboardStoreId++;
28
+ }
@@ -35,7 +35,6 @@ _export(exports, {
35
35
  useDeletePanelDialog: ()=>useDeletePanelDialog,
36
36
  useDefaultTimeRange: ()=>useDefaultTimeRange
37
37
  });
38
- const _core = require("@perses-dev/core");
39
38
  const _react = require("react");
40
39
  const _dashboardProvider = require("./DashboardProvider");
41
40
  function useEditMode() {
@@ -57,7 +56,7 @@ function useDashboardActions() {
57
56
  };
58
57
  }
59
58
  function usePanelGroupIds() {
60
- return (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder);
59
+ return (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupOrder);
61
60
  }
62
61
  function useListPanelGroups() {
63
62
  const panelGroupIds = usePanelGroupIds();
@@ -87,20 +86,22 @@ function usePanelGroupActions(panelGroupId) {
87
86
  const openEditPanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openEditPanelGroup);
88
87
  const deletePanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openDeletePanelGroupDialog);
89
88
  const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
89
+ const updatePanelGroupLayouts = (0, _dashboardProvider.useDashboardStore)((store)=>store.updatePanelGroupLayouts);
90
90
  return {
91
91
  openEditPanelGroup: ()=>openEditPanelGroup(panelGroupId),
92
92
  deletePanelGroup: ()=>deletePanelGroup(panelGroupId),
93
93
  openAddPanel: ()=>openAddPanel(panelGroupId),
94
94
  moveUp,
95
- moveDown
95
+ moveDown,
96
+ updatePanelGroupLayouts: (itemLayouts)=>updatePanelGroupLayouts(panelGroupId, itemLayouts)
96
97
  };
97
98
  }
98
99
  /**
99
100
  * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be
100
101
  * moved in that direction.
101
102
  */ function useMovePanelGroup(panelGroupId) {
102
- const currentIndex = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder.findIndex((id)=>id === panelGroupId));
103
- const panelGroupsLength = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder.length);
103
+ const currentIndex = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupOrder.findIndex((id)=>id === panelGroupId));
104
+ const panelGroupsLength = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupOrder.length);
104
105
  const swapPanelGroups = (0, _dashboardProvider.useDashboardStore)((store)=>store.swapPanelGroups);
105
106
  if (currentIndex < 0) {
106
107
  throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);
@@ -124,12 +125,11 @@ function useDeletePanelGroupDialog() {
124
125
  }));
125
126
  }
126
127
  function usePanel(panelGroupItemId) {
127
- const { panelGroupId , itemIndex } = panelGroupItemId;
128
+ const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
128
129
  const panel = (0, _dashboardProvider.useDashboardStore)((store)=>{
129
- var ref, ref1;
130
- const panelRef = (ref1 = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items[itemIndex]) === null || ref1 === void 0 ? void 0 : ref1.content;
131
- if (panelRef === undefined) return;
132
- const panelKey = (0, _core.getPanelKeyFromRef)(panelRef);
130
+ var ref;
131
+ const panelKey = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.itemPanelKeys[panelGroupLayoutId];
132
+ if (panelKey === undefined) return;
133
133
  return store.panels[panelKey];
134
134
  });
135
135
  if (panel === undefined) {
@@ -151,11 +151,11 @@ function usePanelEditor() {
151
151
  function useDeletePanelDialog() {
152
152
  const deletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanelDialog);
153
153
  // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
154
- const deletePanels = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanels);
154
+ const deletePanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanel);
155
155
  const closeDeletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.closeDeletePanelDialog);
156
156
  return {
157
157
  deletePanelDialog,
158
- deletePanels,
158
+ deletePanel,
159
159
  closeDeletePanelDialog
160
160
  };
161
161
  }
@@ -0,0 +1,70 @@
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
+ Object.defineProperty(exports, "createDeletePanelGroupSlice", {
18
+ enumerable: true,
19
+ get: ()=>createDeletePanelGroupSlice
20
+ });
21
+ const createDeletePanelGroupSlice = (set, get)=>({
22
+ deletePanelGroup (panelGroupId) {
23
+ const { panelGroups , panelGroupOrder } = get();
24
+ const group = panelGroups[panelGroupId];
25
+ const idIndex = panelGroupOrder.findIndex((id)=>id === panelGroupId);
26
+ if (group === undefined || idIndex === -1) {
27
+ throw new Error(`Panel group ${panelGroupId} not found`);
28
+ }
29
+ // Get the panel keys for all the panel items in the group we're going to delete
30
+ const panelKeys = Object.values(group.itemPanelKeys);
31
+ set((draft)=>{
32
+ // Delete the panel group which also deletes all its items
33
+ delete draft.panelGroups[panelGroupId];
34
+ draft.panelGroupOrder.splice(idIndex, 1);
35
+ // Get all remaining panel keys in use
36
+ const usedPanelKeys = getUsedPanelKeys(draft.panelGroups);
37
+ // For the panel keys of the items that were just deleted, see if they're still used and if not, also delete the
38
+ // panel definition
39
+ for (const panelKey of panelKeys){
40
+ if (usedPanelKeys.has(panelKey)) continue;
41
+ delete draft.panels[panelKey];
42
+ }
43
+ });
44
+ },
45
+ openDeletePanelGroupDialog: (panelGroupId)=>{
46
+ const panelGroup = get().panelGroups[panelGroupId];
47
+ if (panelGroup === undefined) {
48
+ throw new Error(`Panel group with Id ${panelGroupId} not found`);
49
+ }
50
+ set((state)=>{
51
+ state.deletePanelGroupDialog = {
52
+ panelGroupId,
53
+ panelGroupName: panelGroup.title
54
+ };
55
+ });
56
+ },
57
+ closeDeletePanelGroupDialog: ()=>set((state)=>{
58
+ state.deletePanelGroupDialog = undefined;
59
+ })
60
+ });
61
+ // Helper to get the panel keys of all groups, returning a set to eliminate duplicates
62
+ function getUsedPanelKeys(panelGroups) {
63
+ const usedPanelKeys = new Set();
64
+ for (const group of Object.values(panelGroups)){
65
+ for (const panelKey of Object.values(group.itemPanelKeys)){
66
+ usedPanelKeys.add(panelKey);
67
+ }
68
+ }
69
+ return usedPanelKeys;
70
+ }
@@ -0,0 +1,85 @@
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
+ Object.defineProperty(exports, "createDeletePanelSlice", {
18
+ enumerable: true,
19
+ get: ()=>createDeletePanelSlice
20
+ });
21
+ function createDeletePanelSlice() {
22
+ // Return the state creator function for Zustand that uses the panels provided as intitial state
23
+ return (set, get)=>({
24
+ deletePanel (panelGroupItemId) {
25
+ set((draft)=>{
26
+ const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
27
+ const existingGroup = draft.panelGroups[panelGroupId];
28
+ if (existingGroup === undefined) {
29
+ throw new Error(`Missing panel group ${panelGroupId}`);
30
+ }
31
+ const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout)=>layout.i === panelGroupLayoutId);
32
+ const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];
33
+ if (existingLayoutIdx === -1 || existingPanelKey === undefined) {
34
+ throw new Error(`Missing panel group item ${panelGroupLayoutId}`);
35
+ }
36
+ // remove panel from panel group
37
+ existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
38
+ delete existingGroup.itemPanelKeys[panelGroupLayoutId];
39
+ // See if panel key is still used and if not, delete it
40
+ if (isPanelKeyStillUsed(draft.panelGroups, existingPanelKey) === false) {
41
+ delete draft.panels[existingPanelKey];
42
+ }
43
+ });
44
+ },
45
+ openDeletePanelDialog (panelGroupItemId) {
46
+ const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
47
+ const { panels , panelGroups } = get();
48
+ const panelGroup = panelGroups[panelGroupId];
49
+ if (panelGroup === undefined) {
50
+ throw new Error(`Panel group not found ${panelGroupId}`);
51
+ }
52
+ const panelKey = panelGroup.itemPanelKeys[panelGroupLayoutId];
53
+ if (panelKey === undefined) {
54
+ throw new Error(`Could not find Panel Group item ${panelGroupLayoutId}`);
55
+ }
56
+ const panel = panels[panelKey];
57
+ if (panel === undefined) {
58
+ throw new Error(`Could not find panel ${panelKey}`);
59
+ }
60
+ set((state)=>{
61
+ var _title;
62
+ state.deletePanelDialog = {
63
+ panelGroupItemId: panelGroupItemId,
64
+ panelName: panel.spec.display.name,
65
+ panelGroupName: (_title = panelGroup.title) !== null && _title !== void 0 ? _title : ''
66
+ };
67
+ });
68
+ },
69
+ closeDeletePanelDialog () {
70
+ set((state)=>{
71
+ state.deletePanelDialog = undefined;
72
+ });
73
+ }
74
+ });
75
+ }
76
+ // Helper function to determine if a panel key is still being used somewhere in Panel Groups
77
+ function isPanelKeyStillUsed(panelGroups, panelKey) {
78
+ for (const group of Object.values(panelGroups)){
79
+ const found = Object.values(group.itemPanelKeys).find((key)=>key === panelKey);
80
+ if (found !== undefined) {
81
+ return true;
82
+ }
83
+ }
84
+ return false;
85
+ }