@perses-dev/dashboards 0.14.0 → 0.15.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 (105) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +7 -3
  2. package/dist/cjs/{css/styles.js → components/GridLayout/GridContainer.js} +66 -39
  3. package/dist/cjs/components/GridLayout/GridLayout.js +51 -64
  4. package/dist/cjs/components/GridLayout/GridTitle.js +3 -2
  5. package/dist/cjs/components/Panel/PanelHeader.js +6 -6
  6. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +15 -54
  7. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +25 -11
  8. package/dist/cjs/components/Variables/Variable.js +11 -4
  9. package/dist/cjs/components/Variables/VariableEditor.js +1 -0
  10. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -2
  11. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +3 -3
  12. package/dist/cjs/components/Variables/VariableList.js +76 -17
  13. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +2 -1
  14. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +68 -39
  15. package/dist/cjs/context/{TimeRangeProvider.js → TimeRangeProvider/TimeRangeProvider.js} +4 -4
  16. package/dist/cjs/{utils → context/TimeRangeProvider}/index.js +2 -1
  17. package/dist/cjs/{utils/time-range-params.js → context/TimeRangeProvider/query-params.js} +11 -5
  18. package/dist/cjs/index.js +0 -1
  19. package/dist/cjs/test/testDashboard.js +1 -1
  20. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  21. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +6 -7
  22. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  23. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
  24. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  25. package/dist/components/DashboardToolbar/DashboardToolbar.js +7 -3
  26. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  27. package/dist/components/GridLayout/GridContainer.d.ts +6 -0
  28. package/dist/components/GridLayout/GridContainer.d.ts.map +1 -0
  29. package/dist/{css/styles.js → components/GridLayout/GridContainer.js} +65 -38
  30. package/dist/components/GridLayout/GridContainer.js.map +1 -0
  31. package/dist/components/GridLayout/GridLayout.d.ts +1 -2
  32. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  33. package/dist/components/GridLayout/GridLayout.js +53 -66
  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 +4 -3
  37. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  38. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  39. package/dist/components/Panel/PanelHeader.js +6 -6
  40. package/dist/components/Panel/PanelHeader.js.map +1 -1
  41. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  42. package/dist/components/TimeRangeControls/TimeRangeControls.js +19 -58
  43. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  44. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +25 -11
  45. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  46. package/dist/components/Variables/Variable.js +11 -4
  47. package/dist/components/Variables/Variable.js.map +1 -1
  48. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  49. package/dist/components/Variables/VariableEditor.js +1 -0
  50. package/dist/components/Variables/VariableEditor.js.map +1 -1
  51. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +2 -2
  52. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  53. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +1 -1
  54. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  55. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +3 -3
  56. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  57. package/dist/components/Variables/VariableList.d.ts +5 -1
  58. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  59. package/dist/components/Variables/VariableList.js +38 -18
  60. package/dist/components/Variables/VariableList.js.map +1 -1
  61. package/dist/context/DashboardProvider/DashboardProvider.js +2 -1
  62. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  63. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -1
  64. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  65. package/dist/context/DashboardProvider/dashboard-provider-api.js +70 -41
  66. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  67. package/dist/context/{TimeRangeProvider.d.ts → TimeRangeProvider/TimeRangeProvider.d.ts} +2 -2
  68. package/dist/context/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -0
  69. package/dist/context/{TimeRangeProvider.js → TimeRangeProvider/TimeRangeProvider.js} +4 -4
  70. package/dist/context/TimeRangeProvider/TimeRangeProvider.js.map +1 -0
  71. package/dist/context/TimeRangeProvider/index.d.ts +3 -0
  72. package/dist/context/TimeRangeProvider/index.d.ts.map +1 -0
  73. package/dist/{utils → context/TimeRangeProvider}/index.js +2 -1
  74. package/dist/context/TimeRangeProvider/index.js.map +1 -0
  75. package/dist/{utils/time-range-params.d.ts → context/TimeRangeProvider/query-params.d.ts} +3 -3
  76. package/dist/context/TimeRangeProvider/query-params.d.ts.map +1 -0
  77. package/dist/{utils/time-range-params.js → context/TimeRangeProvider/query-params.js} +13 -7
  78. package/dist/context/TimeRangeProvider/query-params.js.map +1 -0
  79. package/dist/index.d.ts +0 -1
  80. package/dist/index.d.ts.map +1 -1
  81. package/dist/index.js +0 -1
  82. package/dist/index.js.map +1 -1
  83. package/dist/test/testDashboard.js +1 -1
  84. package/dist/test/testDashboard.js.map +1 -1
  85. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
  86. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  87. package/dist/views/ViewDashboard/DashboardApp.js +2 -1
  88. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  89. package/dist/views/ViewDashboard/ViewDashboard.d.ts +1 -0
  90. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  91. package/dist/views/ViewDashboard/ViewDashboard.js +6 -7
  92. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  93. package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  94. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  95. package/package.json +4 -4
  96. package/dist/context/TimeRangeProvider.d.ts.map +0 -1
  97. package/dist/context/TimeRangeProvider.js.map +0 -1
  98. package/dist/css/styles.d.ts +0 -172
  99. package/dist/css/styles.d.ts.map +0 -1
  100. package/dist/css/styles.js.map +0 -1
  101. package/dist/utils/index.d.ts +0 -2
  102. package/dist/utils/index.d.ts.map +0 -1
  103. package/dist/utils/index.js.map +0 -1
  104. package/dist/utils/time-range-params.d.ts.map +0 -1
  105. package/dist/utils/time-range-params.js.map +0 -1
@@ -33,7 +33,7 @@ function _interopRequireDefault(obj) {
33
33
  };
34
34
  }
35
35
  const DashboardToolbar = (props)=>{
36
- const { dashboardName , dashboardTitleComponent , onEditButtonClick , onCancelButtonClick } = props;
36
+ const { dashboardName , dashboardTitleComponent , initialVariableIsSticky , onEditButtonClick , onCancelButtonClick } = props;
37
37
  const { isEditMode , setEditMode } = (0, _context.useEditMode)();
38
38
  const { openAddPanelGroup , openAddPanel } = (0, _context.useDashboardActions)();
39
39
  const isLaptopSize = (0, _material.useMediaQuery)((0, _material.useTheme)().breakpoints.up('sm'));
@@ -89,7 +89,9 @@ const DashboardToolbar = (props)=>{
89
89
  children: [
90
90
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
91
91
  FallbackComponent: _components.ErrorAlert,
92
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {})
92
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {
93
+ initialVariableIsSticky: initialVariableIsSticky
94
+ })
93
95
  }),
94
96
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
95
97
  direction: 'row',
@@ -150,7 +152,9 @@ const DashboardToolbar = (props)=>{
150
152
  paddingY: 2,
151
153
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
152
154
  FallbackComponent: _components.ErrorAlert,
153
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {})
155
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {
156
+ initialVariableIsSticky: initialVariableIsSticky
157
+ })
154
158
  })
155
159
  })
156
160
  ]
@@ -14,40 +14,68 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "styles", {
17
+ Object.defineProperty(exports, "GridContainer", {
18
18
  enumerable: true,
19
- get: ()=>styles
19
+ get: ()=>GridContainer
20
20
  });
21
- const styles = (theme)=>{
22
- return {
23
- '&.react-grid-layout': {
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ function GridContainer(props) {
25
+ const [isFirstRender, setIsFirstRender] = (0, _react.useState)(true);
26
+ (0, _react.useEffect)(()=>{
27
+ if (isFirstRender) {
28
+ setIsFirstRender(false);
29
+ }
30
+ }, [
31
+ isFirstRender
32
+ ]);
33
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(ReactGridLayoutContainer, {
34
+ sx: {
35
+ // This adds spcing between grids (rows) in the overall dashboard
36
+ '& + &': {
37
+ marginTop: (theme)=>theme.spacing(1)
38
+ },
39
+ // This disables the animation of grid items when a grid is first rendered
40
+ // (see https://github.com/react-grid-layout/react-grid-layout/issues/103)
41
+ '& .react-grid-item.cssTransforms': {
42
+ transitionProperty: isFirstRender ? 'none' : 'transform'
43
+ }
44
+ },
45
+ children: props.children
46
+ });
47
+ }
48
+ /**
49
+ * These are the classes needed by react-grid-layout from their CSS stylesheet.
50
+ */ const ReactGridLayoutContainer = (0, _material.styled)('section')(({ theme })=>({
51
+ '& .react-grid-layout': {
24
52
  position: 'relative',
25
53
  transition: 'height 200ms ease'
26
54
  },
27
- '&.react-grid-item': {
55
+ '& .react-grid-item': {
28
56
  transition: 'all 200ms ease',
29
57
  transitionProperty: 'left, top'
30
58
  },
31
- '&.react-grid-item img': {
59
+ '& .react-grid-item img': {
32
60
  pointerEvents: 'none',
33
61
  userSelect: 'none'
34
62
  },
35
- '&.react-grid-item.cssTransforms': {
63
+ '& .react-grid-item.cssTransforms': {
36
64
  transitionProperty: 'transform'
37
65
  },
38
- '&.react-grid-item.resizing': {
66
+ '& .react-grid-item.resizing': {
39
67
  zIndex: 1,
40
68
  willChange: 'width, height'
41
69
  },
42
- '&.react-grid-item.react-draggable-dragging': {
70
+ '& .react-grid-item.react-draggable-dragging': {
43
71
  transition: 'none',
44
72
  zIndex: 3,
45
73
  willChange: 'transform'
46
74
  },
47
- '&.react-grid-item.dropping': {
75
+ '& .react-grid-item.dropping': {
48
76
  visibility: 'hidden'
49
77
  },
50
- '&.react-grid-item.react-grid-placeholder': {
78
+ '& .react-grid-item.react-grid-placeholder': {
51
79
  background: theme.palette.primary.main,
52
80
  opacity: 0.2,
53
81
  transitionDuration: '100ms',
@@ -58,12 +86,12 @@ const styles = (theme)=>{
58
86
  msUserSelect: 'none',
59
87
  OUserSelect: 'none'
60
88
  },
61
- '&.react-grid-item > .react-resizable-handle': {
89
+ '& .react-grid-item > .react-resizable-handle': {
62
90
  position: 'absolute',
63
91
  width: '20px',
64
92
  height: '20px'
65
93
  },
66
- '&.react-grid-item > .react-resizable-handle::after': {
94
+ '& .react-grid-item > .react-resizable-handle::after': {
67
95
  content: '""',
68
96
  position: 'absolute',
69
97
  right: '3px',
@@ -73,62 +101,62 @@ const styles = (theme)=>{
73
101
  borderRight: '2px solid rgba(0, 0, 0, 0.4)',
74
102
  borderBottom: '2px solid rgba(0, 0, 0, 0.4)'
75
103
  },
76
- '&.react-resizable-hide > .react-resizable-handle': {
104
+ '& .react-resizable-hide > .react-resizable-handle': {
77
105
  display: 'none'
78
106
  },
79
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-sw': {
107
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-sw': {
80
108
  bottom: '0',
81
109
  left: '0',
82
110
  cursor: 'sw-resize',
83
111
  transform: 'rotate(90deg)'
84
112
  },
85
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-se': {
113
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-se': {
86
114
  bottom: '0',
87
115
  right: '0',
88
116
  cursor: 'se-resize'
89
117
  },
90
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-nw': {
118
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-nw': {
91
119
  top: '0',
92
120
  left: '0',
93
121
  cursor: 'nw-resize',
94
122
  transform: 'rotate(180deg)'
95
123
  },
96
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-ne': {
124
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-ne': {
97
125
  top: '0',
98
126
  right: '0',
99
127
  cursor: 'ne-resize',
100
128
  transform: 'rotate(270deg)'
101
129
  },
102
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-w, &.react-grid-item > .react-resizable-handle.react-resizable-handle-e': {
130
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-w, &.react-grid-item > .react-resizable-handle.react-resizable-handle-e': {
103
131
  top: '50%',
104
132
  marginTop: '-10px',
105
133
  cursor: 'ew-resize'
106
134
  },
107
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-w': {
135
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-w': {
108
136
  left: '0',
109
137
  transform: 'rotate(135deg)'
110
138
  },
111
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-e': {
139
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-e': {
112
140
  right: '0',
113
141
  transform: 'rotate(315deg)'
114
142
  },
115
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-n, &.react-grid-item > .react-resizable-handle.react-resizable-handle-s': {
143
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-n, &.react-grid-item > .react-resizable-handle.react-resizable-handle-s': {
116
144
  left: '50%',
117
145
  marginLeft: '-10px',
118
146
  cursor: 'ns-resize'
119
147
  },
120
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-n': {
148
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-n': {
121
149
  top: '0',
122
150
  transform: 'rotate(225deg)'
123
151
  },
124
- '&.react-grid-item > .react-resizable-handle.react-resizable-handle-s': {
152
+ '& .react-grid-item > .react-resizable-handle.react-resizable-handle-s': {
125
153
  bottom: '0',
126
154
  transform: 'rotate(45deg)'
127
155
  },
128
- '&.react-resizable': {
156
+ '& .react-resizable': {
129
157
  position: 'relative'
130
158
  },
131
- '&.react-resizable-handle': {
159
+ '& .react-resizable-handle': {
132
160
  position: 'absolute',
133
161
  width: '20px',
134
162
  height: '20px',
@@ -139,54 +167,53 @@ const styles = (theme)=>{
139
167
  backgroundPosition: 'bottom right',
140
168
  padding: '0 3px 3px 0'
141
169
  },
142
- '&.react-resizable-handle-sw': {
170
+ '& .react-resizable-handle-sw': {
143
171
  bottom: '0',
144
172
  left: '0',
145
173
  cursor: 'sw-resize',
146
174
  transform: 'rotate(90deg)'
147
175
  },
148
- '&.react-resizable-handle-se': {
176
+ '& .react-resizable-handle-se': {
149
177
  bottom: '0',
150
178
  right: '0',
151
179
  cursor: 'se-resize'
152
180
  },
153
- '&.react-resizable-handle-nw': {
181
+ '& .react-resizable-handle-nw': {
154
182
  top: '0',
155
183
  left: '0',
156
184
  cursor: 'nw-resize',
157
185
  transform: 'rotate(180deg)'
158
186
  },
159
- '&.react-resizable-handle-ne': {
187
+ '& .react-resizable-handle-ne': {
160
188
  top: '0',
161
189
  right: '0',
162
190
  cursor: 'ne-resize',
163
191
  transform: 'rotate(270deg)'
164
192
  },
165
- '&.react-resizable-handle-w, .react-resizable-handle-e': {
193
+ '& .react-resizable-handle-w, .react-resizable-handle-e': {
166
194
  top: '50%',
167
195
  marginTop: '-10px',
168
196
  cursor: 'ew-resize'
169
197
  },
170
- '&.react-resizable-handle-w': {
198
+ '& .react-resizable-handle-w': {
171
199
  left: '0',
172
200
  transform: 'rotate(135deg)'
173
201
  },
174
- '&.react-resizable-handle-e': {
202
+ '& .react-resizable-handle-e': {
175
203
  right: '0',
176
204
  transform: 'rotate(315deg)'
177
205
  },
178
- '&.react-resizable-handle-n, .react-resizable-handle-s': {
206
+ '& .react-resizable-handle-n, .react-resizable-handle-s': {
179
207
  left: '50%',
180
208
  marginLeft: '-10px',
181
209
  cursor: 'ns-resize'
182
210
  },
183
- '&.react-resizable-handle-n': {
211
+ '& .react-resizable-handle-n': {
184
212
  top: '0',
185
213
  transform: 'rotate(225deg)'
186
214
  },
187
- '&.react-resizable-handle-s': {
215
+ '& .react-resizable-handle-s': {
188
216
  bottom: '0',
189
217
  transform: 'rotate(45deg)'
190
218
  }
191
- };
192
- };
219
+ }));
@@ -23,83 +23,70 @@ const _react = require("react");
23
23
  const _reactGridLayout = require("react-grid-layout");
24
24
  const _material = require("@mui/material");
25
25
  const _components = require("@perses-dev/components");
26
- const _styles = require("../../css/styles");
27
26
  const _context = require("../../context");
28
27
  const _gridTitle = require("./GridTitle");
29
28
  const _gridItemContent = require("./GridItemContent");
29
+ const _gridContainer = require("./GridContainer");
30
30
  const ResponsiveGridLayout = (0, _reactGridLayout.WidthProvider)(_reactGridLayout.Responsive);
31
31
  function GridLayout(props) {
32
- const { panelGroupId , ...others } = props;
32
+ const { panelGroupId /*...others */ } = props;
33
33
  const theme = (0, _material.useTheme)();
34
34
  const groupDefinition = (0, _context.usePanelGroup)(panelGroupId);
35
35
  const { updatePanelGroupLayouts } = (0, _context.usePanelGroupActions)(panelGroupId);
36
36
  var ref;
37
37
  const [isOpen, setIsOpen] = (0, _react.useState)((ref = !groupDefinition.isCollapsed) !== null && ref !== void 0 ? ref : true);
38
38
  const { isEditMode } = (0, _context.useEditMode)();
39
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
39
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_gridContainer.GridContainer, {
40
40
  children: [
41
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.GlobalStyles, {
42
- styles: _styles.styles
41
+ groupDefinition.title !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_gridTitle.GridTitle, {
42
+ panelGroupId: panelGroupId,
43
+ title: groupDefinition.title,
44
+ collapse: groupDefinition.isCollapsed === undefined ? undefined : {
45
+ isOpen,
46
+ onToggleOpen: ()=>setIsOpen((current)=>!current)
47
+ }
43
48
  }),
44
- /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
45
- ...others,
46
- component: "section",
47
- sx: {
48
- '& + &': {
49
- marginTop: (theme)=>theme.spacing(1)
50
- }
51
- },
52
- children: [
53
- groupDefinition.title !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_gridTitle.GridTitle, {
54
- panelGroupId: panelGroupId,
55
- title: groupDefinition.title,
56
- collapse: groupDefinition.isCollapsed === undefined ? undefined : {
57
- isOpen,
58
- onToggleOpen: ()=>setIsOpen((current)=>!current)
59
- }
60
- }),
61
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Collapse, {
62
- in: isOpen,
63
- unmountOnExit: true,
64
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(ResponsiveGridLayout, {
65
- className: "layout",
66
- breakpoints: {
67
- sm: theme.breakpoints.values.sm,
68
- xxs: 0
69
- },
70
- cols: {
71
- sm: 24,
72
- xxs: 2
73
- },
74
- rowHeight: 30,
75
- draggableHandle: '.drag-handle',
76
- resizeHandles: [
77
- 'se'
78
- ],
79
- isDraggable: isEditMode,
80
- isResizable: isEditMode,
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", {
90
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
91
- FallbackComponent: _components.ErrorAlert,
92
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_gridItemContent.GridItemContent, {
93
- panelGroupItemId: {
94
- panelGroupId,
95
- panelGroupItemLayoutId: i
96
- }
97
- })
98
- })
99
- }, i))
100
- })
101
- })
102
- ]
49
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Collapse, {
50
+ in: isOpen,
51
+ unmountOnExit: true,
52
+ appear: false,
53
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(ResponsiveGridLayout, {
54
+ className: "layout",
55
+ breakpoints: {
56
+ sm: theme.breakpoints.values.sm,
57
+ xxs: 0
58
+ },
59
+ cols: {
60
+ sm: 24,
61
+ xxs: 2
62
+ },
63
+ rowHeight: 30,
64
+ draggableHandle: '.drag-handle',
65
+ resizeHandles: [
66
+ 'se'
67
+ ],
68
+ isDraggable: isEditMode,
69
+ isResizable: isEditMode,
70
+ containerPadding: [
71
+ 0,
72
+ 10
73
+ ],
74
+ layouts: {
75
+ sm: groupDefinition.itemLayouts
76
+ },
77
+ onLayoutChange: updatePanelGroupLayouts,
78
+ children: groupDefinition.itemLayouts.map(({ i })=>/*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
79
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
80
+ FallbackComponent: _components.ErrorAlert,
81
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_gridItemContent.GridItemContent, {
82
+ panelGroupItemId: {
83
+ panelGroupId,
84
+ panelGroupItemLayoutId: i
85
+ }
86
+ })
87
+ })
88
+ }, i))
89
+ })
103
90
  })
104
91
  ]
105
92
  });
@@ -37,7 +37,8 @@ function _interopRequireDefault(obj) {
37
37
  function GridTitle(props) {
38
38
  const { panelGroupId , title , collapse } = props;
39
39
  const [isHovered, setIsHovered] = (0, _react.useState)(false);
40
- const { openAddPanel , openEditPanelGroup , deletePanelGroup , moveUp , moveDown } = (0, _context.usePanelGroupActions)(panelGroupId);
40
+ const { openAddPanel , openEditPanelGroup , moveUp , moveDown } = (0, _context.usePanelGroupActions)(panelGroupId);
41
+ const { openDeletePanelGroupDialog } = (0, _context.useDeletePanelGroupDialog)();
41
42
  const { isEditMode } = (0, _context.useEditMode)();
42
43
  const text = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
43
44
  variant: "h2",
@@ -81,7 +82,7 @@ function GridTitle(props) {
81
82
  }),
82
83
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
83
84
  "aria-label": "delete group",
84
- onClick: deletePanelGroup,
85
+ onClick: ()=>openDeletePanelGroupDialog(panelGroupId),
85
86
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_deleteOutline.default, {})
86
87
  }),
87
88
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
@@ -95,17 +95,17 @@ function PanelHeader({ id , title , description , editHandlers , isHovered , sx
95
95
  title: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
96
96
  id: titleElementId,
97
97
  variant: "subtitle1",
98
- sx: {
99
- whiteSpace: 'nowrap',
100
- overflow: 'hidden',
101
- textOverflow: 'ellipsis'
102
- },
103
98
  children: title
104
99
  }),
105
100
  action: action,
106
101
  sx: (0, _components.combineSx)((theme)=>({
107
102
  padding: theme.spacing(1),
108
- borderBottom: `solid 1px ${theme.palette.divider}`
103
+ borderBottom: `solid 1px ${theme.palette.divider}`,
104
+ '.MuiCardHeader-content': {
105
+ whiteSpace: 'nowrap',
106
+ overflow: 'hidden',
107
+ textOverflow: 'ellipsis'
108
+ }
109
109
  }), sx),
110
110
  ...rest
111
111
  });
@@ -25,8 +25,6 @@ _export(exports, {
25
25
  TimeRangeControls: ()=>TimeRangeControls
26
26
  });
27
27
  const _jsxRuntime = require("react/jsx-runtime");
28
- const _react = require("react");
29
- const _material = require("@mui/material");
30
28
  const _components = require("@perses-dev/components");
31
29
  const _core = require("@perses-dev/core");
32
30
  const _context = require("../../context");
@@ -88,58 +86,21 @@ const TIME_OPTIONS = [
88
86
  ];
89
87
  function TimeRangeControls() {
90
88
  const { timeRange , setTimeRange } = (0, _context.useDashboardTimeRange)();
91
- const [showCustomDateSelector, setShowCustomDateSelector] = (0, _react.useState)(false);
92
- const anchorEl = (0, _react.useRef)();
93
- const convertedTimeRange = (0, _react.useMemo)(()=>{
94
- return (0, _core.isRelativeTimeRange)(timeRange) ? (0, _core.toAbsoluteTimeRange)(timeRange) : timeRange;
95
- }, [
96
- timeRange
97
- ]);
98
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
99
- direction: "row",
100
- spacing: 1,
101
- children: [
102
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Popover, {
103
- anchorEl: anchorEl.current,
104
- anchorOrigin: {
105
- vertical: 'bottom',
106
- horizontal: 'center'
89
+ const defaultTimeRange = (0, _context.useDefaultTimeRange)();
90
+ // add time shortcut if one does not match duration from dashboard JSON
91
+ if (!TIME_OPTIONS.some((option)=>option.value.pastDuration === defaultTimeRange.pastDuration)) {
92
+ if ((0, _core.isDurationString)(defaultTimeRange.pastDuration)) {
93
+ TIME_OPTIONS.push({
94
+ value: {
95
+ pastDuration: defaultTimeRange.pastDuration
107
96
  },
108
- open: showCustomDateSelector,
109
- onClose: ()=>setShowCustomDateSelector(false),
110
- sx: (theme)=>({
111
- padding: theme.spacing(2)
112
- }),
113
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.AbsoluteTimePicker, {
114
- initialTimeRange: convertedTimeRange,
115
- onChange: (timeRange)=>{
116
- setTimeRange(timeRange);
117
- setShowCustomDateSelector(false);
118
- }
119
- })
120
- }),
121
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControl, {
122
- fullWidth: true,
123
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
124
- ref: anchorEl,
125
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.TimeRangeSelector, {
126
- timeOptions: TIME_OPTIONS,
127
- value: timeRange,
128
- onSelectChange: (event)=>{
129
- const duration = event.target.value;
130
- const relativeTimeInput = {
131
- pastDuration: duration,
132
- end: new Date()
133
- };
134
- setTimeRange(relativeTimeInput);
135
- setShowCustomDateSelector(false);
136
- },
137
- onCustomClick: ()=>{
138
- setShowCustomDateSelector(true);
139
- }
140
- })
141
- })
142
- })
143
- ]
97
+ display: `Last ${defaultTimeRange.pastDuration}`
98
+ });
99
+ }
100
+ }
101
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.DateTimeRangePicker, {
102
+ timeOptions: TIME_OPTIONS,
103
+ value: timeRange,
104
+ onChange: setTimeRange
144
105
  });
145
106
  }
@@ -45,29 +45,43 @@ describe('TimeRangeControls', ()=>{
45
45
  dashboardResource: _testDashboard.default
46
46
  };
47
47
  });
48
- const renderTimeRangeControls = ()=>{
48
+ const renderTimeRangeControls = (testURLParams)=>{
49
49
  (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DashboardProvider, {
50
50
  initialState: initialState,
51
51
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TimeRangeProvider, {
52
- timeRange: testDefaultTimeRange,
52
+ initialTimeRange: testDefaultTimeRange,
53
+ enabledURLParams: testURLParams,
53
54
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {})
54
55
  })
55
56
  }), undefined, history);
56
57
  };
57
- it('should render correct initial relative time shortcut', async ()=>{
58
- renderTimeRangeControls();
59
- expect(_react.screen.getByText('Last 5 minutes')).toBeInTheDocument();
60
- });
61
- // TODO: fix setTimeRange no-op, test query params
62
- it('should be able to select the first option', ()=>{
63
- renderTimeRangeControls();
58
+ it('should default to dashboard duration and update selected time option when clicked', async ()=>{
59
+ renderTimeRangeControls(false);
60
+ expect(_react.screen.getByText('Last 30 minutes')).toBeInTheDocument();
64
61
  const dateButton = _react.screen.getByRole('button');
65
62
  _userEvent.default.click(dateButton);
66
- const firstOption = _react.screen.getByRole('option', {
63
+ const firstSelected = _react.screen.getByRole('option', {
67
64
  name: 'Last 5 minutes'
68
65
  });
69
- _userEvent.default.click(firstOption);
66
+ _userEvent.default.click(firstSelected);
70
67
  expect(dateButton).toHaveTextContent(/5 minutes/i);
71
68
  });
69
+ it('should update URL params with correct time range values', ()=>{
70
+ renderTimeRangeControls(true);
71
+ const dateButton = _react.screen.getByRole('button');
72
+ _userEvent.default.click(dateButton);
73
+ const firstSelected = _react.screen.getByRole('option', {
74
+ name: 'Last 5 minutes'
75
+ });
76
+ _userEvent.default.click(firstSelected);
77
+ expect(history.location.search).toEqual('?start=5m');
78
+ // pick another option from TimeRangeSelector dropdown
79
+ const secondSelected = _react.screen.getByText('Last 12 hours');
80
+ _userEvent.default.click(secondSelected);
81
+ expect(history.location.search).toEqual('?start=12h');
82
+ // back button should return to first option selected
83
+ history.back();
84
+ expect(history.location.search).toEqual('?start=5m');
85
+ });
72
86
  // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
73
87
  });
@@ -57,16 +57,24 @@ function ListVariable({ name }) {
57
57
  const { data: variablePlugin } = (0, _pluginSystem.usePlugin)('Variable', definition.spec.plugin.kind);
58
58
  const { setVariableValue , setVariableLoading , setVariableOptions } = (0, _context.useTemplateVariableActions)();
59
59
  const datasourceStore = (0, _pluginSystem.useDatasourceStore)();
60
+ const allVariables = (0, _pluginSystem.useTemplateVariableValues)();
61
+ const { timeRange } = (0, _pluginSystem.useTimeRange)();
62
+ const variablePluginCtx = {
63
+ timeRange,
64
+ datasourceStore,
65
+ variables: allVariables
66
+ };
60
67
  const spec = definition.spec.plugin.spec;
61
68
  let dependsOnVariables;
62
69
  if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
63
- dependsOnVariables = variablePlugin.dependsOn(spec);
70
+ const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
71
+ dependsOnVariables = dependencies.variables;
64
72
  }
65
73
  const variables = (0, _pluginSystem.useTemplateVariableValues)(dependsOnVariables);
66
74
  const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_multiple) === true;
67
75
  const allowAllValue = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_all_value) === true;
68
76
  var ref4;
69
- const label = (ref4 = (ref = definition === null || definition === void 0 ? void 0 : definition.spec.display) === null || ref === void 0 ? void 0 : ref.label) !== null && ref4 !== void 0 ? ref4 : name;
77
+ const title = (ref4 = (ref = definition === null || definition === void 0 ? void 0 : definition.spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref4 !== void 0 ? ref4 : name;
70
78
  let waitToLoad = false;
71
79
  if (dependsOnVariables) {
72
80
  waitToLoad = dependsOnVariables.some((v)=>{
@@ -75,7 +83,6 @@ function ListVariable({ name }) {
75
83
  });
76
84
  }
77
85
  const variablesValueKey = getVariableValuesKey(variables);
78
- const { timeRange } = (0, _pluginSystem.useTimeRange)();
79
86
  const variablesOptionsQuery = (0, _reactQuery.useQuery)([
80
87
  name,
81
88
  definition,
@@ -165,7 +172,7 @@ function ListVariable({ name }) {
165
172
  children: [
166
173
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
167
174
  id: name,
168
- children: label
175
+ children: title
169
176
  }),
170
177
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Select, {
171
178
  sx: {
@@ -60,6 +60,7 @@ function VariableEditor(props) {
60
60
  }
61
61
  if (!v.spec.display) {
62
62
  v.spec.display = {
63
+ name: v.spec.name,
63
64
  hidden: false
64
65
  };
65
66
  }