@perses-dev/dashboards 0.29.0 → 0.30.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 (69) hide show
  1. package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +79 -0
  2. package/dist/cjs/{stories/decorators/WithQueryClient.js → components/DashboardStickyToolbar/index.js} +11 -12
  3. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +3 -2
  4. package/dist/cjs/components/EditJsonDialog/EditJsonDialog.js +5 -0
  5. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +5 -5
  6. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -1
  7. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +7 -8
  8. package/dist/cjs/components/Variables/VariableList.js +16 -55
  9. package/dist/cjs/components/index.js +1 -0
  10. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +3 -4
  11. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +4 -4
  12. package/dist/cjs/context/useDashboard.js +4 -4
  13. package/dist/cjs/stories/decorators/index.js +0 -5
  14. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts +9 -0
  15. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts.map +1 -0
  16. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +68 -0
  17. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -0
  18. package/dist/components/DashboardStickyToolbar/index.d.ts +2 -0
  19. package/dist/components/DashboardStickyToolbar/index.d.ts.map +1 -0
  20. package/dist/{stories/decorators/WithQueryClient.js → components/DashboardStickyToolbar/index.js} +2 -10
  21. package/dist/components/DashboardStickyToolbar/index.js.map +1 -0
  22. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  23. package/dist/components/DashboardToolbar/DashboardToolbar.js +4 -3
  24. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  25. package/dist/components/EditJsonDialog/EditJsonDialog.d.ts.map +1 -1
  26. package/dist/components/EditJsonDialog/EditJsonDialog.js +5 -0
  27. package/dist/components/EditJsonDialog/EditJsonDialog.js.map +1 -1
  28. package/dist/components/TimeRangeControls/TimeRangeControls.js +6 -6
  29. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  30. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -1
  31. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  32. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  33. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +7 -8
  34. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  35. package/dist/components/Variables/VariableList.d.ts +1 -7
  36. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  37. package/dist/components/Variables/VariableList.js +18 -52
  38. package/dist/components/Variables/VariableList.js.map +1 -1
  39. package/dist/components/index.d.ts +1 -0
  40. package/dist/components/index.d.ts.map +1 -1
  41. package/dist/components/index.js +1 -0
  42. package/dist/components/index.js.map +1 -1
  43. package/dist/context/DashboardProvider/DashboardProvider.d.ts +2 -2
  44. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  45. package/dist/context/DashboardProvider/DashboardProvider.js +3 -4
  46. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  47. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -1
  48. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  49. package/dist/context/DashboardProvider/dashboard-provider-api.js +3 -3
  50. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  51. package/dist/context/useDashboard.d.ts.map +1 -1
  52. package/dist/context/useDashboard.js +4 -4
  53. package/dist/context/useDashboard.js.map +1 -1
  54. package/dist/stories/decorators/index.js +0 -5
  55. package/dist/stories/decorators/index.js.map +1 -1
  56. package/package.json +6 -6
  57. package/dist/cjs/stories/decorators/WithDataQueriesProvider.js +0 -39
  58. package/dist/cjs/stories/decorators/WithPluginRegistry.js +0 -94
  59. package/dist/cjs/stories/decorators/WithQueryParams.js +0 -29
  60. package/dist/cjs/stories/decorators/WithTimeRange.js +0 -38
  61. package/dist/stories/decorators/WithDataQueriesProvider.js +0 -33
  62. package/dist/stories/decorators/WithDataQueriesProvider.js.map +0 -1
  63. package/dist/stories/decorators/WithPluginRegistry.js +0 -49
  64. package/dist/stories/decorators/WithPluginRegistry.js.map +0 -1
  65. package/dist/stories/decorators/WithQueryClient.js.map +0 -1
  66. package/dist/stories/decorators/WithQueryParams.js +0 -23
  67. package/dist/stories/decorators/WithQueryParams.js.map +0 -1
  68. package/dist/stories/decorators/WithTimeRange.js +0 -32
  69. package/dist/stories/decorators/WithTimeRange.js.map +0 -1
@@ -0,0 +1,79 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "DashboardStickyToolbar", {
18
+ enumerable: true,
19
+ get: ()=>DashboardStickyToolbar
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ const _pinOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOutline"));
25
+ const _pinOffOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOffOutline"));
26
+ const _variables = require("../Variables");
27
+ const _timeRangeControls = require("../TimeRangeControls");
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ function DashboardStickyToolbar(props) {
34
+ const [isPin, setIsPin] = (0, _react.useState)(props.initialVariableIsSticky);
35
+ const scrollTrigger = (0, _material.useScrollTrigger)({
36
+ disableHysteresis: true
37
+ });
38
+ const isSticky = scrollTrigger && props.initialVariableIsSticky && isPin;
39
+ return(// marginBottom={-1} counteracts the marginBottom={1} on every variable input.
40
+ // The margin on the inputs is for spacing between inputs, but is not meant to add space to bottom of the container.
41
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
42
+ marginBottom: -1,
43
+ "data-testid": "variable-list",
44
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.AppBar, {
45
+ color: "inherit",
46
+ position: isSticky ? 'fixed' : 'static',
47
+ elevation: isSticky ? 4 : 0,
48
+ sx: {
49
+ backgroundColor: 'inherit',
50
+ ...props.sx
51
+ },
52
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
53
+ display: "flex",
54
+ justifyContent: "space-between",
55
+ children: [
56
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
57
+ display: "flex",
58
+ flexWrap: "wrap",
59
+ alignItems: "start",
60
+ my: isSticky ? 2 : 0,
61
+ ml: isSticky ? 2 : 0,
62
+ children: [
63
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {}),
64
+ props.initialVariableIsSticky && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
65
+ onClick: ()=>setIsPin(!isPin),
66
+ children: isPin ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOutline.default, {}) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOffOutline.default, {})
67
+ })
68
+ ]
69
+ }),
70
+ isSticky && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
71
+ my: 2,
72
+ mr: 2,
73
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {})
74
+ })
75
+ ]
76
+ })
77
+ })
78
+ }));
79
+ }
@@ -14,16 +14,15 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "WithQueryClient", {
18
- enumerable: true,
19
- get: ()=>WithQueryClient
20
- });
21
- const _jsxRuntime = require("react/jsx-runtime");
22
- const _reactQuery = require("@tanstack/react-query");
23
- const WithQueryClient = (Story)=>{
24
- const queryClient = new _reactQuery.QueryClient({});
25
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
26
- client: queryClient,
27
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(Story, {})
17
+ _exportStar(require("./DashboardStickyToolbar"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
28
26
  });
29
- };
27
+ return from;
28
+ }
@@ -30,6 +30,7 @@ const _timeRangeControls = require("../TimeRangeControls");
30
30
  const _variables = require("../Variables");
31
31
  const _editButton = require("../EditButton");
32
32
  const _editJsonButton = require("../EditJsonButton");
33
+ const _dashboardStickyToolbar = require("../DashboardStickyToolbar");
33
34
  const DashboardToolbar = (props)=>{
34
35
  const { dashboardName , dashboardTitleComponent , initialVariableIsSticky , isReadonly , onEditButtonClick , onCancelButtonClick , onSave , } = props;
35
36
  const dashboard = (0, _context.useDashboard)();
@@ -106,7 +107,7 @@ const DashboardToolbar = (props)=>{
106
107
  children: [
107
108
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
108
109
  FallbackComponent: _components.ErrorAlert,
109
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {
110
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_dashboardStickyToolbar.DashboardStickyToolbar, {
110
111
  initialVariableIsSticky: initialVariableIsSticky,
111
112
  sx: {
112
113
  backgroundColor: ({ palette })=>palette.mode === 'dark' ? palette.background.default : palette.background.paper
@@ -194,7 +195,7 @@ const DashboardToolbar = (props)=>{
194
195
  paddingY: 2,
195
196
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
196
197
  FallbackComponent: _components.ErrorAlert,
197
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variables.TemplateVariableList, {
198
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_dashboardStickyToolbar.DashboardStickyToolbar, {
198
199
  initialVariableIsSticky: initialVariableIsSticky,
199
200
  sx: {
200
201
  backgroundColor: ({ palette })=>palette.mode === 'dark' ? palette.background.default : palette.background.paper
@@ -22,6 +22,7 @@ const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _react = require("react");
23
23
  const _material = require("@mui/material");
24
24
  const _components = require("@perses-dev/components");
25
+ const _pluginSystem = require("@perses-dev/plugin-system");
25
26
  const _dashboardProvider = require("../../context/DashboardProvider");
26
27
  const _useDashboard = require("../../context/useDashboard");
27
28
  const EditJsonDialog = ()=>{
@@ -42,11 +43,15 @@ const EditJsonDialog = ()=>{
42
43
  };
43
44
  const EditJsonDialogForm = ()=>{
44
45
  const { closeEditJsonDialog } = (0, _dashboardProvider.useEditJsonDialog)();
46
+ const { setTimeRange } = (0, _pluginSystem.useTimeRange)();
45
47
  const { dashboard , setDashboard } = (0, _useDashboard.useDashboard)();
46
48
  const [draftDashboard, setDraftDashboard] = (0, _react.useState)(dashboard);
47
49
  const handleApply = (e)=>{
48
50
  e.preventDefault();
49
51
  setDashboard(draftDashboard);
52
+ setTimeRange({
53
+ pastDuration: draftDashboard.spec.duration
54
+ });
50
55
  closeEditJsonDialog();
51
56
  };
52
57
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_components.Dialog.Form, {
@@ -98,17 +98,17 @@ const DEFAULT_HEIGHT = '34px';
98
98
  function TimeRangeControls({ heightPx , showRefresh =true }) {
99
99
  const { timeRange , setTimeRange , refresh } = (0, _pluginSystem.useTimeRange)();
100
100
  // TODO: Remove this since it couples to the dashboard context
101
- const defaultTimeRange = (0, _context.useDefaultTimeRange)();
101
+ const dashboardDuration = (0, _context.useDashboardDuration)();
102
102
  // Convert height to a string, then use the string for styling
103
103
  const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;
104
104
  // add time shortcut if one does not match duration from dashboard JSON
105
- if (!TIME_OPTIONS.some((option)=>option.value.pastDuration === defaultTimeRange.pastDuration)) {
106
- if ((0, _core.isDurationString)(defaultTimeRange.pastDuration)) {
105
+ if (!TIME_OPTIONS.some((option)=>option.value.pastDuration === dashboardDuration)) {
106
+ if ((0, _core.isDurationString)(dashboardDuration)) {
107
107
  TIME_OPTIONS.push({
108
108
  value: {
109
- pastDuration: defaultTimeRange.pastDuration
109
+ pastDuration: dashboardDuration
110
110
  },
111
- display: `Last ${defaultTimeRange.pastDuration}`
111
+ display: `Last ${dashboardDuration}`
112
112
  });
113
113
  }
114
114
  }
@@ -182,7 +182,7 @@ function VariableEditForm({ initialVariableDefinition , onChange , onCancel })
182
182
  const refreshPreview = ()=>{
183
183
  setPreviewKey((prev)=>prev + 1);
184
184
  };
185
- /** We use the `previewKey` that we increment to know when to explicity update the
185
+ /** We use the `previewKey` that we increment to know when to explicitly update the
186
186
  * spec that will be used for preview. The reason why we do this is to avoid
187
187
  * having to re-fetch the values when the user is still editing the spec.
188
188
  */ const previewSpec = (0, _react.useMemo)(()=>{
@@ -58,17 +58,15 @@ function getInitialState(initialVariableDefinition) {
58
58
  }
59
59
  function getVariableDefinitionFromState(state) {
60
60
  const { name , title , kind } = state;
61
- const commonSpec = {
62
- name,
63
- display: {
64
- name: title
65
- }
66
- };
61
+ const display = title ? {
62
+ name: title
63
+ } : undefined;
67
64
  if (kind === 'TextVariable') {
68
65
  return {
69
66
  kind,
70
67
  spec: {
71
- ...commonSpec,
68
+ name,
69
+ display,
72
70
  ...state.textVariableFields
73
71
  }
74
72
  };
@@ -77,7 +75,8 @@ function getVariableDefinitionFromState(state) {
77
75
  return {
78
76
  kind,
79
77
  spec: {
80
- ...commonSpec,
78
+ name,
79
+ display,
81
80
  allow_multiple: state.listVariableFields.allowMultiple,
82
81
  allow_all_value: state.listVariableFields.allowAll,
83
82
  capturing_regexp: state.listVariableFields.capturing_regexp,
@@ -19,66 +19,27 @@ Object.defineProperty(exports, "TemplateVariableList", {
19
19
  get: ()=>TemplateVariableList
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
- const _react = require("react");
23
22
  const _material = require("@mui/material");
24
- const _pinOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOutline"));
25
- const _pinOffOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PinOffOutline"));
26
23
  const _context = require("../../context");
27
24
  const _templateVariable = require("./TemplateVariable");
28
- function _interopRequireDefault(obj) {
29
- return obj && obj.__esModule ? obj : {
30
- default: obj
31
- };
32
- }
33
25
  const VARIABLE_INPUT_MIN_WIDTH = '120px';
34
26
  const VARIABLE_INPUT_MAX_WIDTH = '240px';
35
- function TemplateVariableList(props) {
36
- const [isPin, setIsPin] = (0, _react.useState)(props.initialVariableIsSticky);
27
+ function TemplateVariableList() {
37
28
  const variableDefinitions = (0, _context.useTemplateVariableDefinitions)();
38
- const scrollTrigger = (0, _material.useScrollTrigger)({
39
- disableHysteresis: true
40
- });
41
- const isSticky = scrollTrigger && props.initialVariableIsSticky && isPin;
42
- return(// marginBottom={-1} counteracts the marginBottom={1} on every variable input.
43
- // The margin on the inputs is for spacing between inputs, but is not meant to add space to bottom of the container.
44
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
45
- marginBottom: -1,
46
- "data-testid": "variable-list",
47
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.AppBar, {
48
- color: "inherit",
49
- position: isSticky ? 'fixed' : 'static',
50
- elevation: isSticky ? 4 : 0,
51
- sx: {
52
- backgroundColor: 'inherit',
53
- ...props.sx
54
- },
55
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
56
- display: "flex",
57
- flexWrap: "wrap",
58
- alignItems: "start",
59
- my: isSticky ? 2 : 0,
60
- ml: isSticky ? 2 : 0,
61
- children: [
62
- variableDefinitions.map((v)=>{
63
- var ref;
64
- /*#__PURE__*/ return (0, _jsxRuntime.jsx)(_material.Box, {
65
- display: ((ref = v.spec.display) === null || ref === void 0 ? void 0 : ref.hidden) ? 'none' : undefined,
66
- minWidth: VARIABLE_INPUT_MIN_WIDTH,
67
- maxWidth: VARIABLE_INPUT_MAX_WIDTH,
68
- marginBottom: 1,
69
- marginRight: 1,
70
- "data-testid": "template-variable",
71
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_templateVariable.TemplateVariable, {
72
- name: v.spec.name
73
- }, v.spec.name)
74
- }, v.spec.name);
75
- }),
76
- props.initialVariableIsSticky && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
77
- onClick: ()=>setIsPin(!isPin),
78
- children: isPin ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOutline.default, {}) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pinOffOutline.default, {})
79
- })
80
- ]
81
- })
29
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
30
+ children: variableDefinitions.map((v)=>{
31
+ var ref;
32
+ /*#__PURE__*/ return (0, _jsxRuntime.jsx)(_material.Box, {
33
+ display: ((ref = v.spec.display) === null || ref === void 0 ? void 0 : ref.hidden) ? 'none' : undefined,
34
+ minWidth: VARIABLE_INPUT_MIN_WIDTH,
35
+ maxWidth: VARIABLE_INPUT_MAX_WIDTH,
36
+ marginBottom: 1,
37
+ marginRight: 1,
38
+ "data-testid": "template-variable",
39
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_templateVariable.TemplateVariable, {
40
+ name: v.spec.name
41
+ }, v.spec.name)
42
+ }, v.spec.name);
82
43
  })
83
- }));
44
+ });
84
45
  }
@@ -18,6 +18,7 @@ _exportStar(require("./AddGroupButton"), exports);
18
18
  _exportStar(require("./AddPanelButton"), exports);
19
19
  _exportStar(require("./Dashboard"), exports);
20
20
  _exportStar(require("./DashboardToolbar"), exports);
21
+ _exportStar(require("./DashboardStickyToolbar"), exports);
21
22
  _exportStar(require("./DeletePanelDialog"), exports);
22
23
  _exportStar(require("./DeletePanelGroupDialog"), exports);
23
24
  _exportStar(require("./DiscardChangesConfirmationDialog"), exports);
@@ -100,14 +100,12 @@ function initStore(props) {
100
100
  ...(0, _editJsonDialogSlice.createEditJsonDialogSlice)(...args),
101
101
  metadata,
102
102
  display,
103
- defaultTimeRange: {
104
- pastDuration: duration
105
- },
103
+ duration,
106
104
  isEditMode: !!isEditMode,
107
105
  setEditMode: (isEditMode)=>set({
108
106
  isEditMode
109
107
  }),
110
- setDashboard: ({ metadata , spec: { display , panels ={} , layouts =[] } })=>{
108
+ setDashboard: ({ metadata , spec: { display , panels ={} , layouts =[] , duration } })=>{
111
109
  set((state)=>{
112
110
  state.metadata = metadata;
113
111
  state.display = display;
@@ -115,6 +113,7 @@ function initStore(props) {
115
113
  const { panelGroups , panelGroupOrder } = (0, _panelGroupSlice.convertLayoutsToPanelGroups)(layouts);
116
114
  state.panelGroups = panelGroups;
117
115
  state.panelGroupOrder = panelGroupOrder;
116
+ state.duration = duration;
118
117
  });
119
118
  }
120
119
  };
@@ -33,7 +33,7 @@ _export(exports, {
33
33
  usePanelActions: ()=>usePanelActions,
34
34
  usePanelEditor: ()=>usePanelEditor,
35
35
  useDeletePanelDialog: ()=>useDeletePanelDialog,
36
- useDefaultTimeRange: ()=>useDefaultTimeRange,
36
+ useDashboardDuration: ()=>useDashboardDuration,
37
37
  useDiscardChangesConfirmationDialog: ()=>useDiscardChangesConfirmationDialog,
38
38
  useEditJsonDialog: ()=>useEditJsonDialog
39
39
  });
@@ -189,9 +189,9 @@ function useDeletePanelDialog() {
189
189
  // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
190
190
  return (0, _dashboardProvider.useDashboardStore)(selectDeletePanelDialog);
191
191
  }
192
- const selectDefaultTimeRange = (state)=>state.defaultTimeRange;
193
- function useDefaultTimeRange() {
194
- return (0, _dashboardProvider.useDashboardStore)(selectDefaultTimeRange);
192
+ const selectDashboardDuration = (state)=>state.duration;
193
+ function useDashboardDuration() {
194
+ return (0, _dashboardProvider.useDashboardStore)(selectDashboardDuration);
195
195
  }
196
196
  const selectDiscardChangesConfirmationDialog = ({ discardChangesConfirmationDialog , openDiscardChangesConfirmationDialog , closeDiscardChangesConfirmationDialog })=>({
197
197
  discardChangesConfirmationDialog,
@@ -22,14 +22,14 @@ const _core = require("@perses-dev/core");
22
22
  const _dashboardProvider = require("./DashboardProvider");
23
23
  const _templateVariableProvider = require("./TemplateVariableProvider");
24
24
  function useDashboard() {
25
- const { panels , panelGroups , panelGroupOrder , defaultTimeRange , setDashboard: setDashboardResource , metadata , display , } = (0, _dashboardProvider.useDashboardStore)(({ panels , panelGroups , panelGroupOrder , defaultTimeRange , setDashboard , metadata , display })=>({
25
+ const { panels , panelGroups , panelGroupOrder , setDashboard: setDashboardResource , metadata , display , duration , } = (0, _dashboardProvider.useDashboardStore)(({ panels , panelGroups , panelGroupOrder , setDashboard , metadata , display , duration })=>({
26
26
  panels,
27
27
  panelGroups,
28
28
  panelGroupOrder,
29
- defaultTimeRange,
30
29
  setDashboard,
31
30
  metadata,
32
- display
31
+ display,
32
+ duration
33
33
  }));
34
34
  const { setVariableDefinitions } = (0, _templateVariableProvider.useTemplateVariableActions)();
35
35
  const variables = (0, _templateVariableProvider.useTemplateVariableDefinitions)();
@@ -42,7 +42,7 @@ function useDashboard() {
42
42
  panels,
43
43
  layouts,
44
44
  variables,
45
- duration: defaultTimeRange.pastDuration
45
+ duration
46
46
  }
47
47
  };
48
48
  const setDashboard = (dashboardResource)=>{
@@ -16,13 +16,8 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  _exportStar(require("./constants"), exports);
18
18
  _exportStar(require("./WithDashboard"), exports);
19
- _exportStar(require("./WithDataQueriesProvider"), exports);
20
19
  _exportStar(require("./WithDatasourceStore"), exports);
21
- _exportStar(require("./WithPluginRegistry"), exports);
22
- _exportStar(require("./WithQueryClient"), exports);
23
- _exportStar(require("./WithQueryParams"), exports);
24
20
  _exportStar(require("./WithTemplateVariables"), exports);
25
- _exportStar(require("./WithTimeRange"), exports);
26
21
  function _exportStar(from, to) {
27
22
  Object.keys(from).forEach(function(k) {
28
23
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { SxProps, Theme } from '@mui/material';
3
+ interface DashboardStickyToolbarProps {
4
+ initialVariableIsSticky?: boolean;
5
+ sx?: SxProps<Theme>;
6
+ }
7
+ export declare function DashboardStickyToolbar(props: DashboardStickyToolbarProps): JSX.Element;
8
+ export {};
9
+ //# sourceMappingURL=DashboardStickyToolbar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DashboardStickyToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardStickyToolbar/DashboardStickyToolbar.tsx"],"names":[],"mappings":";AAcA,OAAO,EAA2B,OAAO,EAAE,KAAK,EAAoB,MAAM,eAAe,CAAC;AAM1F,UAAU,2BAA2B;IACnC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,EAAE,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;CACrB;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,2BAA2B,eAgCxE"}
@@ -0,0 +1,68 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { useState } from 'react';
15
+ import { AppBar, Box, IconButton, useScrollTrigger } from '@mui/material';
16
+ import PinOutline from 'mdi-material-ui/PinOutline';
17
+ import PinOffOutline from 'mdi-material-ui/PinOffOutline';
18
+ import { TemplateVariableList } from '../Variables';
19
+ import { TimeRangeControls } from '../TimeRangeControls';
20
+ export function DashboardStickyToolbar(props) {
21
+ const [isPin, setIsPin] = useState(props.initialVariableIsSticky);
22
+ const scrollTrigger = useScrollTrigger({
23
+ disableHysteresis: true
24
+ });
25
+ const isSticky = scrollTrigger && props.initialVariableIsSticky && isPin;
26
+ return(// marginBottom={-1} counteracts the marginBottom={1} on every variable input.
27
+ // The margin on the inputs is for spacing between inputs, but is not meant to add space to bottom of the container.
28
+ /*#__PURE__*/ _jsx(Box, {
29
+ marginBottom: -1,
30
+ "data-testid": "variable-list",
31
+ children: /*#__PURE__*/ _jsx(AppBar, {
32
+ color: "inherit",
33
+ position: isSticky ? 'fixed' : 'static',
34
+ elevation: isSticky ? 4 : 0,
35
+ sx: {
36
+ backgroundColor: 'inherit',
37
+ ...props.sx
38
+ },
39
+ children: /*#__PURE__*/ _jsxs(Box, {
40
+ display: "flex",
41
+ justifyContent: "space-between",
42
+ children: [
43
+ /*#__PURE__*/ _jsxs(Box, {
44
+ display: "flex",
45
+ flexWrap: "wrap",
46
+ alignItems: "start",
47
+ my: isSticky ? 2 : 0,
48
+ ml: isSticky ? 2 : 0,
49
+ children: [
50
+ /*#__PURE__*/ _jsx(TemplateVariableList, {}),
51
+ props.initialVariableIsSticky && /*#__PURE__*/ _jsx(IconButton, {
52
+ onClick: ()=>setIsPin(!isPin),
53
+ children: isPin ? /*#__PURE__*/ _jsx(PinOutline, {}) : /*#__PURE__*/ _jsx(PinOffOutline, {})
54
+ })
55
+ ]
56
+ }),
57
+ isSticky && /*#__PURE__*/ _jsx(Box, {
58
+ my: 2,
59
+ mr: 2,
60
+ children: /*#__PURE__*/ _jsx(TimeRangeControls, {})
61
+ })
62
+ ]
63
+ })
64
+ })
65
+ }));
66
+ }
67
+
68
+ //# sourceMappingURL=DashboardStickyToolbar.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/DashboardStickyToolbar/DashboardStickyToolbar.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { AppBar, Box, IconButton, SxProps, Theme, useScrollTrigger } from '@mui/material';\nimport PinOutline from 'mdi-material-ui/PinOutline';\nimport PinOffOutline from 'mdi-material-ui/PinOffOutline';\nimport { TemplateVariableList } from '../Variables';\nimport { TimeRangeControls } from '../TimeRangeControls';\n\ninterface DashboardStickyToolbarProps {\n initialVariableIsSticky?: boolean;\n sx?: SxProps<Theme>;\n}\n\nexport function DashboardStickyToolbar(props: DashboardStickyToolbarProps) {\n const [isPin, setIsPin] = useState(props.initialVariableIsSticky);\n\n const scrollTrigger = useScrollTrigger({ disableHysteresis: true });\n const isSticky = scrollTrigger && props.initialVariableIsSticky && isPin;\n\n return (\n // marginBottom={-1} counteracts the marginBottom={1} on every variable input.\n // The margin on the inputs is for spacing between inputs, but is not meant to add space to bottom of the container.\n <Box marginBottom={-1} data-testid=\"variable-list\">\n <AppBar\n color=\"inherit\"\n position={isSticky ? 'fixed' : 'static'}\n elevation={isSticky ? 4 : 0}\n sx={{ backgroundColor: 'inherit', ...props.sx }}\n >\n <Box display=\"flex\" justifyContent=\"space-between\">\n <Box display=\"flex\" flexWrap=\"wrap\" alignItems=\"start\" my={isSticky ? 2 : 0} ml={isSticky ? 2 : 0}>\n <TemplateVariableList></TemplateVariableList>\n {props.initialVariableIsSticky && (\n <IconButton onClick={() => setIsPin(!isPin)}>{isPin ? <PinOutline /> : <PinOffOutline />}</IconButton>\n )}\n </Box>\n {isSticky && (\n <Box my={2} mr={2}>\n <TimeRangeControls></TimeRangeControls>\n </Box>\n )}\n </Box>\n </AppBar>\n </Box>\n );\n}\n"],"names":["useState","AppBar","Box","IconButton","useScrollTrigger","PinOutline","PinOffOutline","TemplateVariableList","TimeRangeControls","DashboardStickyToolbar","props","isPin","setIsPin","initialVariableIsSticky","scrollTrigger","disableHysteresis","isSticky","marginBottom","data-testid","color","position","elevation","sx","backgroundColor","display","justifyContent","flexWrap","alignItems","my","ml","onClick","mr"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,MAAM,EAAEC,GAAG,EAAEC,UAAU,EAAkBC,gBAAgB,QAAQ,eAAe,CAAC;AAC1F,OAAOC,UAAU,MAAM,4BAA4B,CAAC;AACpD,OAAOC,aAAa,MAAM,+BAA+B,CAAC;AAC1D,SAASC,oBAAoB,QAAQ,cAAc,CAAC;AACpD,SAASC,iBAAiB,QAAQ,sBAAsB,CAAC;AAOzD,OAAO,SAASC,sBAAsB,CAACC,KAAkC,EAAE;IACzE,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGZ,QAAQ,CAACU,KAAK,CAACG,uBAAuB,CAAC,AAAC;IAElE,MAAMC,aAAa,GAAGV,gBAAgB,CAAC;QAAEW,iBAAiB,EAAE,IAAI;KAAE,CAAC,AAAC;IACpE,MAAMC,QAAQ,GAAGF,aAAa,IAAIJ,KAAK,CAACG,uBAAuB,IAAIF,KAAK,AAAC;IAEzE,OACE,8EAA8E;IAC9E,oHAAoH;kBACpH,KAACT,GAAG;QAACe,YAAY,EAAE,CAAC,CAAC;QAAEC,aAAW,EAAC,eAAe;kBAChD,cAAA,KAACjB,MAAM;YACLkB,KAAK,EAAC,SAAS;YACfC,QAAQ,EAAEJ,QAAQ,GAAG,OAAO,GAAG,QAAQ;YACvCK,SAAS,EAAEL,QAAQ,GAAG,CAAC,GAAG,CAAC;YAC3BM,EAAE,EAAE;gBAAEC,eAAe,EAAE,SAAS;gBAAE,GAAGb,KAAK,CAACY,EAAE;aAAE;sBAE/C,cAAA,MAACpB,GAAG;gBAACsB,OAAO,EAAC,MAAM;gBAACC,cAAc,EAAC,eAAe;;kCAChD,MAACvB,GAAG;wBAACsB,OAAO,EAAC,MAAM;wBAACE,QAAQ,EAAC,MAAM;wBAACC,UAAU,EAAC,OAAO;wBAACC,EAAE,EAAEZ,QAAQ,GAAG,CAAC,GAAG,CAAC;wBAAEa,EAAE,EAAEb,QAAQ,GAAG,CAAC,GAAG,CAAC;;0CAC/F,KAACT,oBAAoB,KAAwB;4BAC5CG,KAAK,CAACG,uBAAuB,kBAC5B,KAACV,UAAU;gCAAC2B,OAAO,EAAE,IAAMlB,QAAQ,CAAC,CAACD,KAAK,CAAC;0CAAGA,KAAK,iBAAG,KAACN,UAAU,KAAG,iBAAG,KAACC,aAAa,KAAG;8BAAc,AACvG;;sBACG;oBACLU,QAAQ,kBACP,KAACd,GAAG;wBAAC0B,EAAE,EAAE,CAAC;wBAAEG,EAAE,EAAE,CAAC;kCACf,cAAA,KAACvB,iBAAiB,KAAqB;sBACnC,AACP;;cACG;UACC;MACL,EACN;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './DashboardStickyToolbar';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardStickyToolbar/index.ts"],"names":[],"mappings":"AAaA,cAAc,0BAA0B,CAAC"}
@@ -10,14 +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 { jsx as _jsx } from "react/jsx-runtime";
14
- import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
15
- export const WithQueryClient = (Story)=>{
16
- const queryClient = new QueryClient({});
17
- return /*#__PURE__*/ _jsx(QueryClientProvider, {
18
- client: queryClient,
19
- children: /*#__PURE__*/ _jsx(Story, {})
20
- });
21
- };
13
+ export * from './DashboardStickyToolbar';
22
14
 
23
- //# sourceMappingURL=WithQueryClient.js.map
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/DashboardStickyToolbar/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './DashboardStickyToolbar';\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,0BAA0B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAUrD,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBAoI5D,CAAC"}
1
+ {"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../../src/components/DashboardToolbar/DashboardToolbar.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAWrD,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,uBAAuB,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;IACtC,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,UAAU,EAAE,OAAO,CAAC;IACpB,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,mBAAmB,EAAE,MAAM,IAAI,CAAC;IAChC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACpE;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBAoI5D,CAAC"}
@@ -19,9 +19,10 @@ import { AddPanelButton } from '../AddPanelButton';
19
19
  import { AddGroupButton } from '../AddGroupButton';
20
20
  import { DownloadButton } from '../DownloadButton';
21
21
  import { TimeRangeControls } from '../TimeRangeControls';
22
- import { TemplateVariableList, EditVariablesButton } from '../Variables';
22
+ import { EditVariablesButton } from '../Variables';
23
23
  import { EditButton } from '../EditButton';
24
24
  import { EditJsonButton } from '../EditJsonButton';
25
+ import { DashboardStickyToolbar } from '../DashboardStickyToolbar';
25
26
  export const DashboardToolbar = (props)=>{
26
27
  const { dashboardName , dashboardTitleComponent , initialVariableIsSticky , isReadonly , onEditButtonClick , onCancelButtonClick , onSave , } = props;
27
28
  const dashboard = useDashboard();
@@ -98,7 +99,7 @@ export const DashboardToolbar = (props)=>{
98
99
  children: [
99
100
  /*#__PURE__*/ _jsx(ErrorBoundary, {
100
101
  FallbackComponent: ErrorAlert,
101
- children: /*#__PURE__*/ _jsx(TemplateVariableList, {
102
+ children: /*#__PURE__*/ _jsx(DashboardStickyToolbar, {
102
103
  initialVariableIsSticky: initialVariableIsSticky,
103
104
  sx: {
104
105
  backgroundColor: ({ palette })=>palette.mode === 'dark' ? palette.background.default : palette.background.paper
@@ -186,7 +187,7 @@ export const DashboardToolbar = (props)=>{
186
187
  paddingY: 2,
187
188
  children: /*#__PURE__*/ _jsx(ErrorBoundary, {
188
189
  FallbackComponent: ErrorAlert,
189
- children: /*#__PURE__*/ _jsx(TemplateVariableList, {
190
+ children: /*#__PURE__*/ _jsx(DashboardStickyToolbar, {
190
191
  initialVariableIsSticky: initialVariableIsSticky,
191
192
  sx: {
192
193
  backgroundColor: ({ palette })=>palette.mode === 'dark' ? palette.background.default : palette.background.paper