@perses-dev/plugin-system 0.0.0-snapshot-saving-defaults-refinements-1b25cec → 0.0.0-snapshot-core-types-move-units-c7c5d31

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 (77) hide show
  1. package/dist/cjs/components/CalculationSelector/CalculationSelector.js +4 -9
  2. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +182 -0
  3. package/dist/cjs/components/LegendOptionsEditor/index.js +28 -0
  4. package/dist/cjs/components/index.js +1 -0
  5. package/dist/cjs/index.js +1 -0
  6. package/dist/cjs/model/index.js +1 -1
  7. package/dist/cjs/model/legend.js +85 -0
  8. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +11 -11
  9. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +80 -1
  10. package/dist/cjs/runtime/template-variables.js +9 -3
  11. package/dist/cjs/runtime/time-series-queries.js +5 -2
  12. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +1 -0
  13. package/dist/cjs/utils/index.js +28 -0
  14. package/dist/cjs/utils/variables.js +68 -0
  15. package/dist/components/CalculationSelector/CalculationSelector.d.ts +1 -1
  16. package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -1
  17. package/dist/components/CalculationSelector/CalculationSelector.js +3 -8
  18. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  19. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts +8 -0
  20. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -0
  21. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +176 -0
  22. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -0
  23. package/dist/components/LegendOptionsEditor/index.d.ts +2 -0
  24. package/dist/components/LegendOptionsEditor/index.d.ts.map +1 -0
  25. package/dist/components/LegendOptionsEditor/index.js +15 -0
  26. package/dist/components/LegendOptionsEditor/index.js.map +1 -0
  27. package/dist/components/index.d.ts +1 -0
  28. package/dist/components/index.d.ts.map +1 -1
  29. package/dist/components/index.js +1 -0
  30. package/dist/components/index.js.map +1 -1
  31. package/dist/index.d.ts +1 -0
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +1 -0
  34. package/dist/index.js.map +1 -1
  35. package/dist/model/index.d.ts +1 -1
  36. package/dist/model/index.d.ts.map +1 -1
  37. package/dist/model/index.js +1 -1
  38. package/dist/model/index.js.map +1 -1
  39. package/dist/model/legend.d.ts +16 -0
  40. package/dist/model/legend.d.ts.map +1 -0
  41. package/dist/model/legend.js +76 -0
  42. package/dist/model/legend.js.map +1 -0
  43. package/dist/model/time-series-queries.d.ts +1 -0
  44. package/dist/model/time-series-queries.d.ts.map +1 -1
  45. package/dist/model/time-series-queries.js.map +1 -1
  46. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +5 -1
  47. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  48. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +12 -12
  49. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  50. package/dist/runtime/TimeRangeProvider/query-params.d.ts +12 -0
  51. package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
  52. package/dist/runtime/TimeRangeProvider/query-params.js +82 -1
  53. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
  54. package/dist/runtime/template-variables.d.ts +1 -1
  55. package/dist/runtime/template-variables.d.ts.map +1 -1
  56. package/dist/runtime/template-variables.js +8 -1
  57. package/dist/runtime/template-variables.js.map +1 -1
  58. package/dist/runtime/time-series-queries.d.ts +1 -1
  59. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  60. package/dist/runtime/time-series-queries.js +5 -2
  61. package/dist/runtime/time-series-queries.js.map +1 -1
  62. package/dist/stories/shared-utils/decorators/WithTimeRange.js +1 -0
  63. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  64. package/dist/utils/index.d.ts +2 -0
  65. package/dist/utils/index.d.ts.map +1 -0
  66. package/dist/utils/index.js +15 -0
  67. package/dist/utils/index.js.map +1 -0
  68. package/dist/utils/variables.d.ts +9 -0
  69. package/dist/utils/variables.d.ts.map +1 -0
  70. package/dist/utils/variables.js +57 -0
  71. package/dist/utils/variables.js.map +1 -0
  72. package/package.json +5 -8
  73. package/dist/cjs/model/calculations.js +0 -82
  74. package/dist/model/calculations.d.ts +0 -21
  75. package/dist/model/calculations.d.ts.map +0 -1
  76. package/dist/model/calculations.js +0 -70
  77. package/dist/model/calculations.js.map +0 -1
@@ -19,10 +19,9 @@ Object.defineProperty(exports, "CalculationSelector", {
19
19
  get: ()=>CalculationSelector
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
- const _material = require("@mui/material");
23
22
  const _components = require("@perses-dev/components");
24
- const _calculations = require("../../model/calculations");
25
- const CALC_OPTIONS = Object.entries(_calculations.CALCULATIONS_CONFIG).map(([id, config])=>{
23
+ const _core = require("@perses-dev/core");
24
+ const CALC_OPTIONS = Object.entries(_core.CALCULATIONS_CONFIG).map(([id, config])=>{
26
25
  return {
27
26
  id: id,
28
27
  ...config
@@ -32,19 +31,15 @@ function CalculationSelector({ value , onChange }) {
32
31
  const handleCalculationChange = (_, newValue)=>{
33
32
  onChange(newValue.id);
34
33
  };
35
- const calcConfig = _calculations.CALCULATIONS_CONFIG[value];
34
+ const calcConfig = _core.CALCULATIONS_CONFIG[value];
36
35
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
37
36
  label: "Calculation",
38
- control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Autocomplete, {
37
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
39
38
  value: {
40
39
  ...calcConfig,
41
40
  id: value
42
41
  },
43
42
  options: CALC_OPTIONS,
44
- isOptionEqualToValue: (option, value)=>option.id === value.id,
45
- renderInput: (params)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
46
- ...params
47
- }),
48
43
  onChange: handleCalculationChange,
49
44
  disableClearable: true
50
45
  })
@@ -0,0 +1,182 @@
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, "LegendOptionsEditor", {
18
+ enumerable: true,
19
+ get: ()=>LegendOptionsEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _core = require("@perses-dev/core");
24
+ const _components = require("@perses-dev/components");
25
+ const _model = require("../../model");
26
+ const POSITION_OPTIONS = Object.entries(_model.LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
27
+ return {
28
+ id: id,
29
+ ...config
30
+ };
31
+ });
32
+ const MODE_OPTIONS = Object.entries(_model.LEGEND_MODE_CONFIG).map(([id, config])=>{
33
+ return {
34
+ id: id,
35
+ ...config
36
+ };
37
+ });
38
+ const SIZE_OPTIONS = Object.entries(_model.LEGEND_SIZE_CONFIG).map(([id, config])=>{
39
+ return {
40
+ id: id,
41
+ ...config
42
+ };
43
+ });
44
+ const VALUE_OPTIONS = Object.entries(_model.LEGEND_VALUE_CONFIG).map(([id, config])=>{
45
+ return {
46
+ id: id,
47
+ ...config
48
+ };
49
+ });
50
+ function LegendOptionsEditor({ value , onChange }) {
51
+ const handleLegendShowChange = (_, checked)=>{
52
+ // legend is hidden when legend obj is undefined
53
+ const legendValue = checked === true ? {
54
+ position: _core.DEFAULT_LEGEND.position
55
+ } : undefined;
56
+ onChange(legendValue);
57
+ };
58
+ const handleLegendPositionChange = (_, newValue)=>{
59
+ onChange({
60
+ ...value,
61
+ position: newValue.id
62
+ });
63
+ };
64
+ const handleLegendModeChange = (_, newValue)=>{
65
+ onChange({
66
+ ...value,
67
+ position: currentPosition,
68
+ mode: newValue.id
69
+ });
70
+ };
71
+ const handleLegendSizeChange = (_, newValue)=>{
72
+ onChange({
73
+ ...value,
74
+ position: currentPosition,
75
+ size: newValue.id
76
+ });
77
+ };
78
+ const handleLegendValueChange = (_, newValue)=>{
79
+ onChange({
80
+ ...value,
81
+ position: currentPosition,
82
+ values: newValue.map((value)=>{
83
+ return value.id;
84
+ })
85
+ });
86
+ };
87
+ const isValidLegend = (0, _model.validateLegendSpec)(value);
88
+ const currentPosition = (0, _core.getLegendPosition)(value === null || value === void 0 ? void 0 : value.position);
89
+ const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
90
+ const currentMode = (0, _core.getLegendMode)(value === null || value === void 0 ? void 0 : value.mode);
91
+ const legendModeConfig = _model.LEGEND_MODE_CONFIG[currentMode];
92
+ const currentSize = (0, _core.getLegendSize)(value === null || value === void 0 ? void 0 : value.size);
93
+ const legendSizeConfig = _model.LEGEND_SIZE_CONFIG[currentSize];
94
+ const currentValues = (value === null || value === void 0 ? void 0 : value.values) || [];
95
+ const legendValuesConfig = currentValues.reduce((result, item)=>{
96
+ const config = _model.LEGEND_VALUE_CONFIG[item];
97
+ if (config) {
98
+ result.push({
99
+ ...config,
100
+ id: item
101
+ });
102
+ }
103
+ return result;
104
+ }, []);
105
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
106
+ children: [
107
+ !isValidLegend && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorAlert, {
108
+ error: {
109
+ name: 'invalid-legend',
110
+ message: 'Invalid legend spec'
111
+ }
112
+ }),
113
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
114
+ label: "Show",
115
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
116
+ checked: value !== undefined,
117
+ onChange: handleLegendShowChange
118
+ })
119
+ }),
120
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
121
+ label: "Position",
122
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
123
+ value: {
124
+ ...legendPositionConfig,
125
+ id: currentPosition
126
+ },
127
+ options: POSITION_OPTIONS,
128
+ onChange: handleLegendPositionChange,
129
+ disabled: value === undefined,
130
+ disableClearable: true
131
+ })
132
+ }),
133
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
134
+ label: "Mode",
135
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
136
+ value: {
137
+ ...legendModeConfig,
138
+ id: currentMode
139
+ },
140
+ options: MODE_OPTIONS,
141
+ onChange: handleLegendModeChange,
142
+ disabled: value === undefined,
143
+ disableClearable: true
144
+ })
145
+ }),
146
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
147
+ label: "Size",
148
+ control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
149
+ value: {
150
+ ...legendSizeConfig,
151
+ id: currentSize
152
+ },
153
+ options: SIZE_OPTIONS,
154
+ onChange: handleLegendSizeChange,
155
+ // TODO: enable sizes for list mode when we normalize the layout of
156
+ // lists to more closely match tables.
157
+ disabled: value === undefined || currentMode !== 'Table',
158
+ disableClearable: true
159
+ })
160
+ }),
161
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
162
+ label: "Values",
163
+ control: // For some reason, the inferred option type doesn't always seem to work
164
+ // quite right when `multiple` is true. Explicitly setting the generics
165
+ // to work around this.
166
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
167
+ multiple: true,
168
+ disableCloseOnSelect: true,
169
+ disableClearable: true,
170
+ value: legendValuesConfig,
171
+ options: VALUE_OPTIONS,
172
+ onChange: handleLegendValueChange,
173
+ disabled: value === undefined || currentMode !== 'Table',
174
+ limitTags: 1,
175
+ ChipProps: {
176
+ size: 'small'
177
+ }
178
+ })
179
+ })
180
+ ]
181
+ });
182
+ }
@@ -0,0 +1,28 @@
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
+ _exportStar(require("./LegendOptionsEditor"), 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
+ });
26
+ });
27
+ return from;
28
+ }
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  _exportStar(require("./CalculationSelector"), exports);
18
18
  _exportStar(require("./DatasourceSelect"), exports);
19
+ _exportStar(require("./LegendOptionsEditor"), exports);
19
20
  _exportStar(require("./OptionsEditorTabs"), exports);
20
21
  _exportStar(require("./PanelSpecEditor"), exports);
21
22
  _exportStar(require("./PluginEditor"), exports);
package/dist/cjs/index.js CHANGED
@@ -18,6 +18,7 @@ _exportStar(require("./components"), exports);
18
18
  _exportStar(require("./model"), exports);
19
19
  _exportStar(require("./runtime"), exports);
20
20
  _exportStar(require("./test-utils"), exports);
21
+ _exportStar(require("./utils"), exports);
21
22
  function _exportStar(from, to) {
22
23
  Object.keys(from).forEach(function(k) {
23
24
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -14,8 +14,8 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _exportStar(require("./calculations"), exports);
18
17
  _exportStar(require("./datasource"), exports);
18
+ _exportStar(require("./legend"), exports);
19
19
  _exportStar(require("./panels"), exports);
20
20
  _exportStar(require("./plugins"), exports);
21
21
  _exportStar(require("./plugin-base"), exports);
@@ -0,0 +1,85 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ legendValues: ()=>legendValues,
25
+ LEGEND_POSITIONS_CONFIG: ()=>LEGEND_POSITIONS_CONFIG,
26
+ LEGEND_MODE_CONFIG: ()=>LEGEND_MODE_CONFIG,
27
+ LEGEND_SIZE_CONFIG: ()=>LEGEND_SIZE_CONFIG,
28
+ LEGEND_VALUE_CONFIG: ()=>LEGEND_VALUE_CONFIG,
29
+ validateLegendSpec: ()=>validateLegendSpec
30
+ });
31
+ const _core = require("@perses-dev/core");
32
+ const legendValues = [
33
+ 'Mean',
34
+ 'First',
35
+ 'FirstNumber',
36
+ 'Last',
37
+ 'LastNumber',
38
+ 'Min',
39
+ 'Max',
40
+ 'Sum'
41
+ ];
42
+ const LEGEND_POSITIONS_CONFIG = {
43
+ Bottom: {
44
+ label: 'Bottom'
45
+ },
46
+ Right: {
47
+ label: 'Right'
48
+ }
49
+ };
50
+ const LEGEND_MODE_CONFIG = {
51
+ List: {
52
+ label: 'List'
53
+ },
54
+ Table: {
55
+ label: 'Table'
56
+ }
57
+ };
58
+ const LEGEND_SIZE_CONFIG = {
59
+ Small: {
60
+ label: 'Small'
61
+ },
62
+ Medium: {
63
+ label: 'Medium'
64
+ }
65
+ };
66
+ const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value)=>{
67
+ config[value] = _core.CALCULATIONS_CONFIG[value];
68
+ return config;
69
+ }, {});
70
+ function validateLegendSpec(legend) {
71
+ if (legend === undefined) {
72
+ // undefined is valid since this is how legend is hidden by default
73
+ return true;
74
+ }
75
+ if (!(0, _core.isValidLegendPosition)(legend.position)) {
76
+ return false;
77
+ }
78
+ if (legend.mode && !(0, _core.isValidLegendMode)(legend.mode)) {
79
+ return false;
80
+ }
81
+ if (legend.size && !(0, _core.isValidLegendSize)(legend.size)) {
82
+ return false;
83
+ }
84
+ return true;
85
+ }
@@ -78,18 +78,12 @@ function useTimeRangeContext() {
78
78
  return ctx;
79
79
  }
80
80
  function useTimeRange() {
81
- const { timeRange , absoluteTimeRange , setTimeRange , refresh , refreshKey } = useTimeRangeContext();
82
- return {
83
- timeRange,
84
- absoluteTimeRange,
85
- setTimeRange,
86
- refresh,
87
- refreshKey
88
- };
81
+ return useTimeRangeContext();
89
82
  }
90
83
  function TimeRangeProvider(props) {
91
- const { initialTimeRange , enabledURLParams , children } = props;
84
+ const { initialTimeRange , initialRefreshInterval , enabledURLParams , children } = props;
92
85
  const { timeRange , setTimeRange } = (0, _queryParams.useSetTimeRangeParams)(initialTimeRange, enabledURLParams);
86
+ const { refreshInterval , setRefreshInterval , refreshIntervalInMs } = (0, _queryParams.useSetRefreshIntervalParams)(initialRefreshInterval, enabledURLParams);
93
87
  const [refreshKey, setRefreshKey] = (0, _react.useState)(0);
94
88
  const refresh = (0, _react.useCallback)(()=>{
95
89
  setRefreshKey(refreshKey + 1);
@@ -103,13 +97,19 @@ function TimeRangeProvider(props) {
103
97
  setTimeRange,
104
98
  absoluteTimeRange,
105
99
  refresh,
106
- refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshKey}`
100
+ refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshInterval}:${refreshKey}`,
101
+ refreshInterval,
102
+ refreshIntervalInMs,
103
+ setRefreshInterval
107
104
  };
108
105
  }, [
109
106
  timeRange,
110
107
  setTimeRange,
111
108
  refresh,
112
- refreshKey
109
+ refreshKey,
110
+ refreshInterval,
111
+ refreshIntervalInMs,
112
+ setRefreshInterval
113
113
  ]);
114
114
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(TimeRangeContext.Provider, {
115
115
  value: ctx,
@@ -25,8 +25,11 @@ _export(exports, {
25
25
  decodeTimeRangeValue: ()=>decodeTimeRangeValue,
26
26
  TimeRangeParam: ()=>TimeRangeParam,
27
27
  timeRangeQueryConfig: ()=>timeRangeQueryConfig,
28
+ refreshIntervalQueryConfig: ()=>refreshIntervalQueryConfig,
28
29
  useInitialTimeRange: ()=>useInitialTimeRange,
29
- useSetTimeRangeParams: ()=>useSetTimeRangeParams
30
+ useSetTimeRangeParams: ()=>useSetTimeRangeParams,
31
+ useInitialRefreshInterval: ()=>useInitialRefreshInterval,
32
+ useSetRefreshIntervalParams: ()=>useSetRefreshIntervalParams
30
33
  });
31
34
  const _react = require("react");
32
35
  const _useQueryParams = require("use-query-params");
@@ -78,6 +81,9 @@ const timeRangeQueryConfig = {
78
81
  start: TimeRangeParam,
79
82
  end: TimeRangeParam
80
83
  };
84
+ const refreshIntervalQueryConfig = {
85
+ refresh: TimeRangeParam
86
+ };
81
87
  function useInitialTimeRange(dashboardDuration) {
82
88
  const [query] = (0, _useQueryParams.useQueryParams)(timeRangeQueryConfig, {
83
89
  updateType: 'replaceIn'
@@ -159,3 +165,76 @@ function useSetTimeRangeParams(initialTimeRange, enabledURLParams = true) {
159
165
  setTimeRange: setTimeRange
160
166
  };
161
167
  }
168
+ function useInitialRefreshInterval(dashboardDuration) {
169
+ const [query] = (0, _useQueryParams.useQueryParams)(refreshIntervalQueryConfig, {
170
+ updateType: 'replaceIn'
171
+ });
172
+ const { refresh } = query;
173
+ return (0, _react.useMemo)(()=>{
174
+ let initialTimeRange = dashboardDuration;
175
+ if (!refresh) {
176
+ return initialTimeRange;
177
+ }
178
+ const startStr = refresh.toString();
179
+ if ((0, _core.isDurationString)(startStr)) {
180
+ initialTimeRange = startStr;
181
+ }
182
+ return initialTimeRange;
183
+ }, [
184
+ dashboardDuration,
185
+ refresh
186
+ ]);
187
+ }
188
+ function getRefreshIntervalInMs(refreshInterval) {
189
+ let refreshIntervalInMs = 0;
190
+ if (refreshInterval) {
191
+ const refreshIntervalDuration = (0, _core.parseDurationString)(refreshInterval);
192
+ if (refreshIntervalDuration && refreshIntervalDuration.seconds) {
193
+ refreshIntervalInMs = (refreshIntervalDuration === null || refreshIntervalDuration === void 0 ? void 0 : refreshIntervalDuration.seconds) * 1000;
194
+ }
195
+ }
196
+ return refreshIntervalInMs;
197
+ }
198
+ function useSetRefreshIntervalParams(initialRefreshInterval, enabledURLParams = true) {
199
+ const [query, setQuery] = (0, _useQueryParams.useQueryParams)(refreshIntervalQueryConfig, {
200
+ updateType: 'replaceIn'
201
+ });
202
+ // determine whether initial param had previously been populated to fix back btn
203
+ const [paramsLoaded, setParamsLoaded] = (0, _react.useState)(false);
204
+ // optional fallback when app does not want query string as source of truth
205
+ // this occurs when enabledURLParams is set to false on TimeRangeProvider
206
+ const [refreshIntervalState, setRefreshIntervalState] = (0, _react.useState)(initialRefreshInterval);
207
+ const { refresh } = query;
208
+ (0, _react.useEffect)(()=>{
209
+ // when dashboard loaded with no params, default to dashboard duration
210
+ if (enabledURLParams && !paramsLoaded && !refresh) {
211
+ setQuery({
212
+ refresh: initialRefreshInterval
213
+ });
214
+ setParamsLoaded(true);
215
+ }
216
+ }, [
217
+ initialRefreshInterval,
218
+ enabledURLParams,
219
+ paramsLoaded,
220
+ refresh,
221
+ setQuery
222
+ ]);
223
+ const setRefreshInterval = (0, _react.useCallback)((refresh)=>setQuery({
224
+ refresh
225
+ }), [
226
+ setQuery
227
+ ]);
228
+ if (!enabledURLParams) {
229
+ return {
230
+ refreshInterval: refreshIntervalState,
231
+ setRefreshInterval: setRefreshIntervalState,
232
+ refreshIntervalInMs: getRefreshIntervalInMs(refreshIntervalState)
233
+ };
234
+ }
235
+ return {
236
+ refreshInterval: initialRefreshInterval,
237
+ setRefreshInterval: setRefreshInterval,
238
+ refreshIntervalInMs: getRefreshIntervalInMs(initialRefreshInterval)
239
+ };
240
+ }
@@ -21,12 +21,12 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
- DEFAULT_ALL_VALUE: ()=>DEFAULT_ALL_VALUE,
25
24
  TemplateVariableContext: ()=>TemplateVariableContext,
26
- useTemplateVariableValues: ()=>useTemplateVariableValues
25
+ useTemplateVariableValues: ()=>useTemplateVariableValues,
26
+ useReplaceVariablesInString: ()=>useReplaceVariablesInString
27
27
  });
28
28
  const _react = require("react");
29
- const DEFAULT_ALL_VALUE = '$__all';
29
+ const _utils = require("../utils");
30
30
  const TemplateVariableContext = (0, _react.createContext)(undefined);
31
31
  function useTemplateVariableContext() {
32
32
  const ctx = (0, _react.useContext)(TemplateVariableContext);
@@ -55,3 +55,9 @@ function useTemplateVariableValues(names) {
55
55
  }
56
56
  return values;
57
57
  }
58
+ function useReplaceVariablesInString(str) {
59
+ const variablesInString = str ? (0, _utils.parseTemplateVariables)(str) : [];
60
+ const variableValues = useTemplateVariableValues(variablesInString);
61
+ if (!str) return undefined;
62
+ return (0, _utils.replaceTemplateVariables)(str, variableValues);
63
+ }
@@ -84,6 +84,7 @@ const useTimeSeriesQuery = (definition, options)=>{
84
84
  return (0, _reactQuery.useQuery)({
85
85
  enabled: queryEnabled,
86
86
  queryKey: queryKey,
87
+ refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,
87
88
  queryFn: ()=>{
88
89
  // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking
89
90
  if (plugin === undefined) {
@@ -116,6 +117,7 @@ function useTimeSeriesQueries(definitions, options) {
116
117
  return {
117
118
  enabled: queryEnabled,
118
119
  queryKey: queryKey,
120
+ refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,
119
121
  queryFn: async ()=>{
120
122
  // Keep options out of query key so we don't re-run queries because suggested step changes
121
123
  const ctx = {
@@ -133,14 +135,15 @@ function useTimeSeriesQueries(definitions, options) {
133
135
  /**
134
136
  * Build the time series query context object from data available at runtime
135
137
  */ function useTimeSeriesQueryContext() {
136
- const { absoluteTimeRange , refreshKey } = (0, _timeRangeProvider.useTimeRange)();
138
+ const { absoluteTimeRange , refreshKey , refreshIntervalInMs } = (0, _timeRangeProvider.useTimeRange)();
137
139
  const variableState = (0, _templateVariables.useTemplateVariableValues)();
138
140
  const datasourceStore = (0, _datasources.useDatasourceStore)();
139
141
  return {
140
142
  timeRange: absoluteTimeRange,
141
143
  variableState,
142
144
  datasourceStore,
143
- refreshKey
145
+ refreshKey,
146
+ refreshIntervalInMs: refreshIntervalInMs
144
147
  };
145
148
  }
146
149
  function useActiveTimeSeriesQueries() {
@@ -29,6 +29,7 @@ const WithTimeRange = (Story, context)=>{
29
29
  const parameter = isWithTimeRangeParameter(initParameter) ? initParameter : undefined;
30
30
  const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
31
31
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.TimeRangeProvider, {
32
+ initialRefreshInterval: "0s",
32
33
  initialTimeRange: {
33
34
  pastDuration: '1h'
34
35
  },
@@ -0,0 +1,28 @@
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
+ _exportStar(require("./variables"), 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
+ });
26
+ });
27
+ return from;
28
+ }
@@ -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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ replaceTemplateVariables: ()=>replaceTemplateVariables,
25
+ replaceTemplateVariable: ()=>replaceTemplateVariable,
26
+ parseTemplateVariables: ()=>parseTemplateVariables
27
+ });
28
+ function replaceTemplateVariables(text, variableState) {
29
+ const variables = parseTemplateVariables(text);
30
+ let finalText = text;
31
+ variables.forEach((v)=>{
32
+ const variable = variableState[v];
33
+ if (variable && (variable === null || variable === void 0 ? void 0 : variable.value)) {
34
+ finalText = replaceTemplateVariable(finalText, v, variable === null || variable === void 0 ? void 0 : variable.value);
35
+ }
36
+ });
37
+ return finalText;
38
+ }
39
+ function replaceTemplateVariable(text, varName, templateVariableValue) {
40
+ const variableTemplate = '$' + varName;
41
+ let replaceString = '';
42
+ if (Array.isArray(templateVariableValue)) {
43
+ replaceString = `(${templateVariableValue.join('|')})`; // regex style
44
+ }
45
+ if (typeof templateVariableValue === 'string') {
46
+ replaceString = templateVariableValue;
47
+ }
48
+ return text.replaceAll(variableTemplate, replaceString);
49
+ }
50
+ // This regular expression is designed to identify variable references in a template string.
51
+ // It supports two formats for referencing variables:
52
+ // 1. $variableName - This is a simpler format, and the regular expression captures the variable name (\w+ matches one or more word characters).
53
+ // 2. [COMING SOON] ${variableName:value} - This is a more complex format that allows specifying a format function as well.
54
+ // TODO: Fix this lint error
55
+ // eslint-disable-next-line no-useless-escape
56
+ const TEMPLATE_VARIABLE_REGEX = /\$(\w+)|\${(\w+)(?:\.([^:^\}]+))?(?::([^\}]+))?}/gm;
57
+ const parseTemplateVariables = (text)=>{
58
+ const regex = TEMPLATE_VARIABLE_REGEX;
59
+ const matches = new Set();
60
+ let match;
61
+ while((match = regex.exec(text)) !== null){
62
+ if (match && match.length > 1 && match[1]) {
63
+ matches.add(match[1]);
64
+ }
65
+ }
66
+ // return unique matches
67
+ return Array.from(matches.values());
68
+ };