@perses-dev/plugin-system 0.35.0 → 0.36.1

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 (36) hide show
  1. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +30 -1
  2. package/dist/cjs/model/legend.js +12 -0
  3. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +11 -11
  4. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +80 -1
  5. package/dist/cjs/runtime/template-variables.js +0 -2
  6. package/dist/cjs/runtime/time-series-queries.js +5 -2
  7. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +1 -0
  8. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.d.ts.map +1 -1
  9. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +32 -3
  10. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  11. package/dist/model/legend.d.ts +2 -1
  12. package/dist/model/legend.d.ts.map +1 -1
  13. package/dist/model/legend.js +12 -1
  14. package/dist/model/legend.js.map +1 -1
  15. package/dist/model/time-series-queries.d.ts +1 -0
  16. package/dist/model/time-series-queries.d.ts.map +1 -1
  17. package/dist/model/time-series-queries.js.map +1 -1
  18. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +5 -1
  19. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  20. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +12 -12
  21. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  22. package/dist/runtime/TimeRangeProvider/query-params.d.ts +12 -0
  23. package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
  24. package/dist/runtime/TimeRangeProvider/query-params.js +82 -1
  25. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
  26. package/dist/runtime/template-variables.d.ts +0 -1
  27. package/dist/runtime/template-variables.d.ts.map +1 -1
  28. package/dist/runtime/template-variables.js +0 -1
  29. package/dist/runtime/template-variables.js.map +1 -1
  30. package/dist/runtime/time-series-queries.d.ts +1 -1
  31. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  32. package/dist/runtime/time-series-queries.js +5 -2
  33. package/dist/runtime/time-series-queries.js.map +1 -1
  34. package/dist/stories/shared-utils/decorators/WithTimeRange.js +1 -0
  35. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  36. package/package.json +4 -4
@@ -35,6 +35,12 @@ const MODE_OPTIONS = Object.entries(_model.LEGEND_MODE_CONFIG).map(([id, config]
35
35
  ...config
36
36
  };
37
37
  });
38
+ const SIZE_OPTIONS = Object.entries(_model.LEGEND_SIZE_CONFIG).map(([id, config])=>{
39
+ return {
40
+ id: id,
41
+ ...config
42
+ };
43
+ });
38
44
  const VALUE_OPTIONS = Object.entries(_model.LEGEND_VALUE_CONFIG).map(([id, config])=>{
39
45
  return {
40
46
  id: id,
@@ -62,6 +68,13 @@ function LegendOptionsEditor({ value , onChange }) {
62
68
  mode: newValue.id
63
69
  });
64
70
  };
71
+ const handleLegendSizeChange = (_, newValue)=>{
72
+ onChange({
73
+ ...value,
74
+ position: currentPosition,
75
+ size: newValue.id
76
+ });
77
+ };
65
78
  const handleLegendValueChange = (_, newValue)=>{
66
79
  onChange({
67
80
  ...value,
@@ -76,6 +89,8 @@ function LegendOptionsEditor({ value , onChange }) {
76
89
  const legendPositionConfig = _model.LEGEND_POSITIONS_CONFIG[currentPosition];
77
90
  const currentMode = (0, _core.getLegendMode)(value === null || value === void 0 ? void 0 : value.mode);
78
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];
79
94
  const currentValues = (value === null || value === void 0 ? void 0 : value.values) || [];
80
95
  const legendValuesConfig = currentValues.reduce((result, item)=>{
81
96
  const config = _model.LEGEND_VALUE_CONFIG[item];
@@ -128,9 +143,23 @@ function LegendOptionsEditor({ value , onChange }) {
128
143
  disableClearable: true
129
144
  })
130
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
+ }),
131
161
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
132
162
  label: "Values",
133
- description: "Computed values ignore nulls.",
134
163
  control: // For some reason, the inferred option type doesn't always seem to work
135
164
  // quite right when `multiple` is true. Explicitly setting the generics
136
165
  // to work around this.
@@ -24,6 +24,7 @@ _export(exports, {
24
24
  legendValues: ()=>legendValues,
25
25
  LEGEND_POSITIONS_CONFIG: ()=>LEGEND_POSITIONS_CONFIG,
26
26
  LEGEND_MODE_CONFIG: ()=>LEGEND_MODE_CONFIG,
27
+ LEGEND_SIZE_CONFIG: ()=>LEGEND_SIZE_CONFIG,
27
28
  LEGEND_VALUE_CONFIG: ()=>LEGEND_VALUE_CONFIG,
28
29
  validateLegendSpec: ()=>validateLegendSpec
29
30
  });
@@ -54,6 +55,14 @@ const LEGEND_MODE_CONFIG = {
54
55
  label: 'Table'
55
56
  }
56
57
  };
58
+ const LEGEND_SIZE_CONFIG = {
59
+ Small: {
60
+ label: 'Small'
61
+ },
62
+ Medium: {
63
+ label: 'Medium'
64
+ }
65
+ };
57
66
  const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value)=>{
58
67
  config[value] = _core.CALCULATIONS_CONFIG[value];
59
68
  return config;
@@ -69,5 +78,8 @@ function validateLegendSpec(legend) {
69
78
  if (legend.mode && !(0, _core.isValidLegendMode)(legend.mode)) {
70
79
  return false;
71
80
  }
81
+ if (legend.size && !(0, _core.isValidLegendSize)(legend.size)) {
82
+ return false;
83
+ }
72
84
  return true;
73
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,14 +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
25
  useTemplateVariableValues: ()=>useTemplateVariableValues,
27
26
  useReplaceVariablesInString: ()=>useReplaceVariablesInString
28
27
  });
29
28
  const _react = require("react");
30
29
  const _utils = require("../utils");
31
- const DEFAULT_ALL_VALUE = '$__all';
32
30
  const TemplateVariableContext = (0, _react.createContext)(undefined);
33
31
  function useTemplateVariableContext() {
34
32
  const ctx = (0, _react.useContext)(TemplateVariableContext);
@@ -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
  },
@@ -1 +1 @@
1
- {"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAGL,iBAAiB,EAKlB,MAAM,aAAa,CAAC;AA4BrB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eA6GhF"}
1
+ {"version":3,"file":"LegendOptionsEditor.d.ts","sourceRoot":"","sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAGL,iBAAiB,EAMlB,MAAM,aAAa,CAAC;AAqCrB,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,iBAAiB,CAAC;IAC1B,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,wBAAwB,eAwIhF"}
@@ -12,9 +12,9 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
14
  import { Switch } from '@mui/material';
15
- import { DEFAULT_LEGEND, getLegendMode, getLegendPosition } from '@perses-dev/core';
15
+ import { DEFAULT_LEGEND, getLegendMode, getLegendPosition, getLegendSize } from '@perses-dev/core';
16
16
  import { ErrorAlert, OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';
17
- import { LEGEND_MODE_CONFIG, LEGEND_POSITIONS_CONFIG, validateLegendSpec, LEGEND_VALUE_CONFIG } from '../../model';
17
+ import { LEGEND_MODE_CONFIG, LEGEND_POSITIONS_CONFIG, validateLegendSpec, LEGEND_VALUE_CONFIG, LEGEND_SIZE_CONFIG } from '../../model';
18
18
  const POSITION_OPTIONS = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config])=>{
19
19
  return {
20
20
  id: id,
@@ -27,6 +27,12 @@ const MODE_OPTIONS = Object.entries(LEGEND_MODE_CONFIG).map(([id, config])=>{
27
27
  ...config
28
28
  };
29
29
  });
30
+ const SIZE_OPTIONS = Object.entries(LEGEND_SIZE_CONFIG).map(([id, config])=>{
31
+ return {
32
+ id: id,
33
+ ...config
34
+ };
35
+ });
30
36
  const VALUE_OPTIONS = Object.entries(LEGEND_VALUE_CONFIG).map(([id, config])=>{
31
37
  return {
32
38
  id: id,
@@ -54,6 +60,13 @@ export function LegendOptionsEditor({ value , onChange }) {
54
60
  mode: newValue.id
55
61
  });
56
62
  };
63
+ const handleLegendSizeChange = (_, newValue)=>{
64
+ onChange({
65
+ ...value,
66
+ position: currentPosition,
67
+ size: newValue.id
68
+ });
69
+ };
57
70
  const handleLegendValueChange = (_, newValue)=>{
58
71
  onChange({
59
72
  ...value,
@@ -68,6 +81,8 @@ export function LegendOptionsEditor({ value , onChange }) {
68
81
  const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];
69
82
  const currentMode = getLegendMode(value === null || value === void 0 ? void 0 : value.mode);
70
83
  const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];
84
+ const currentSize = getLegendSize(value === null || value === void 0 ? void 0 : value.size);
85
+ const legendSizeConfig = LEGEND_SIZE_CONFIG[currentSize];
71
86
  const currentValues = (value === null || value === void 0 ? void 0 : value.values) || [];
72
87
  const legendValuesConfig = currentValues.reduce((result, item)=>{
73
88
  const config = LEGEND_VALUE_CONFIG[item];
@@ -120,9 +135,23 @@ export function LegendOptionsEditor({ value , onChange }) {
120
135
  disableClearable: true
121
136
  })
122
137
  }),
138
+ /*#__PURE__*/ _jsx(OptionsEditorControl, {
139
+ label: "Size",
140
+ control: /*#__PURE__*/ _jsx(SettingsAutocomplete, {
141
+ value: {
142
+ ...legendSizeConfig,
143
+ id: currentSize
144
+ },
145
+ options: SIZE_OPTIONS,
146
+ onChange: handleLegendSizeChange,
147
+ // TODO: enable sizes for list mode when we normalize the layout of
148
+ // lists to more closely match tables.
149
+ disabled: value === undefined || currentMode !== 'Table',
150
+ disableClearable: true
151
+ })
152
+ }),
123
153
  /*#__PURE__*/ _jsx(OptionsEditorControl, {
124
154
  label: "Values",
125
- description: "Computed values ignore nulls.",
126
155
  control: // For some reason, the inferred option type doesn't always seem to work
127
156
  // quite right when `multiple` is true. Explicitly setting the generics
128
157
  // to work around this.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.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 { Switch, SwitchProps } from '@mui/material';\nimport { DEFAULT_LEGEND, getLegendMode, getLegendPosition } from '@perses-dev/core';\nimport { ErrorAlert, OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';\nimport {\n LEGEND_MODE_CONFIG,\n LEGEND_POSITIONS_CONFIG,\n LegendSpecOptions,\n LegendSingleSelectConfig,\n validateLegendSpec,\n LEGEND_VALUE_CONFIG,\n LegendValue,\n} from '../../model';\n\ntype LegendPositionOption = LegendSingleSelectConfig & { id: LegendSpecOptions['position'] };\n\nconst POSITION_OPTIONS: LegendPositionOption[] = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendSpecOptions['position'],\n ...config,\n };\n});\n\ntype LegendModeOption = LegendSingleSelectConfig & { id: Required<LegendSpecOptions>['mode'] };\n\nconst MODE_OPTIONS: LegendModeOption[] = Object.entries(LEGEND_MODE_CONFIG).map(([id, config]) => {\n return {\n id: id as Required<LegendSpecOptions>['mode'],\n ...config,\n };\n});\n\ntype LegendValueOption = LegendSingleSelectConfig & { id: LegendValue };\nconst VALUE_OPTIONS: LegendValueOption[] = Object.entries(LEGEND_VALUE_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendValue,\n ...config,\n };\n});\n\nexport interface LegendOptionsEditorProps {\n value?: LegendSpecOptions;\n onChange: (legend?: LegendSpecOptions) => void;\n}\n\nexport function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps) {\n const handleLegendShowChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n // legend is hidden when legend obj is undefined\n const legendValue = checked === true ? { position: DEFAULT_LEGEND.position } : undefined;\n onChange(legendValue);\n };\n\n const handleLegendPositionChange = (_: unknown, newValue: LegendPositionOption) => {\n onChange({\n ...value,\n position: newValue.id,\n });\n };\n\n const handleLegendModeChange = (_: unknown, newValue: LegendModeOption) => {\n onChange({\n ...value,\n position: currentPosition,\n mode: newValue.id,\n });\n };\n\n const handleLegendValueChange = (_: unknown, newValue: LegendValueOption[]) => {\n onChange({\n ...value,\n position: currentPosition,\n values: newValue.map((value) => {\n return value.id;\n }),\n });\n };\n\n const isValidLegend = validateLegendSpec(value);\n const currentPosition = getLegendPosition(value?.position);\n const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];\n\n const currentMode = getLegendMode(value?.mode);\n const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];\n\n const currentValues = value?.values || [];\n const legendValuesConfig = currentValues.reduce((result, item) => {\n const config = LEGEND_VALUE_CONFIG[item];\n if (config) {\n result.push({ ...config, id: item });\n }\n return result;\n }, [] as LegendValueOption[]);\n\n return (\n <>\n {!isValidLegend && <ErrorAlert error={{ name: 'invalid-legend', message: 'Invalid legend spec' }} />}\n <OptionsEditorControl\n label=\"Show\"\n control={<Switch checked={value !== undefined} onChange={handleLegendShowChange} />}\n />\n <OptionsEditorControl\n label=\"Position\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendPositionConfig,\n id: currentPosition,\n }}\n options={POSITION_OPTIONS}\n onChange={handleLegendPositionChange}\n disabled={value === undefined}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Mode\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendModeConfig,\n id: currentMode,\n }}\n options={MODE_OPTIONS}\n onChange={handleLegendModeChange}\n disabled={value === undefined}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Values\"\n description=\"Computed values ignore nulls.\"\n control={\n // For some reason, the inferred option type doesn't always seem to work\n // quite right when `multiple` is true. Explicitly setting the generics\n // to work around this.\n <SettingsAutocomplete<LegendValueOption, true, true>\n multiple={true}\n disableCloseOnSelect\n disableClearable\n value={legendValuesConfig}\n options={VALUE_OPTIONS}\n onChange={handleLegendValueChange}\n disabled={value === undefined || currentMode !== 'Table'}\n limitTags={1}\n ChipProps={{\n size: 'small',\n }}\n />\n }\n />\n </>\n );\n}\n"],"names":["Switch","DEFAULT_LEGEND","getLegendMode","getLegendPosition","ErrorAlert","OptionsEditorControl","SettingsAutocomplete","LEGEND_MODE_CONFIG","LEGEND_POSITIONS_CONFIG","validateLegendSpec","LEGEND_VALUE_CONFIG","POSITION_OPTIONS","Object","entries","map","id","config","MODE_OPTIONS","VALUE_OPTIONS","LegendOptionsEditor","value","onChange","handleLegendShowChange","_","checked","legendValue","position","undefined","handleLegendPositionChange","newValue","handleLegendModeChange","currentPosition","mode","handleLegendValueChange","values","isValidLegend","legendPositionConfig","currentMode","legendModeConfig","currentValues","legendValuesConfig","reduce","result","item","push","error","name","message","label","control","options","disabled","disableClearable","description","multiple","disableCloseOnSelect","limitTags","ChipProps","size"],"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,MAAM,QAAqB,eAAe,CAAC;AACpD,SAASC,cAAc,EAAEC,aAAa,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AACpF,SAASC,UAAU,EAAEC,oBAAoB,EAAEC,oBAAoB,QAAQ,wBAAwB,CAAC;AAChG,SACEC,kBAAkB,EAClBC,uBAAuB,EAGvBC,kBAAkB,EAClBC,mBAAmB,QAEd,aAAa,CAAC;AAIrB,MAAMC,gBAAgB,GAA2BC,MAAM,CAACC,OAAO,CAACL,uBAAuB,CAAC,CAACM,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAC7G,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,AAAC;AAIH,MAAMC,YAAY,GAAuBL,MAAM,CAACC,OAAO,CAACN,kBAAkB,CAAC,CAACO,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GAAK;IAChG,OAAO;QACLD,EAAE,EAAEA,EAAE;QACN,GAAGC,MAAM;KACV,CAAC;AACJ,CAAC,CAAC,AAAC;AAGH,MAAME,aAAa,GAAwBN,MAAM,CAACC,OAAO,CAACH,mBAAmB,CAAC,CAACI,GAAG,CAAC,CAAC,CAACC,EAAE,EAAEC,MAAM,CAAC,GA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AAE,EAAEgB,eAAe;qBACpB;oBACDmB,OAAO,EAAEvC,gBAAgB;oBACzBU,QAAQ,EAAEO,0BAA0B;oBACpCuB,QAAQ,EAAE/B,KAAK,KAAKO,SAAS;oBAC7ByB,gBAAgB;kBACM;cAE1B;0BACF,KAAC/C,oBAAoB;gBACnB2C,KAAK,EAAC,MAAM;gBACZC,OAAO,gBACL,KAAC3C,oBAAoB;oBACnBc,KAAK,EAAE;wBACL,GAAGkB,gBAAgB;wBACnBvB,EAAE,EAAEsB,WAAW;qBAChB;oBACDa,OAAO,EAAEjC,YAAY;oBACrBI,QAAQ,EAAES,sBAAsB;oBAChCqB,QAAQ,EAAE/B,KAAK,KAAKO,SAAS;oBAC7ByB,gBAAgB;kBACM;cAE1B;0BACF,KAAC/C,oBAAoB;gBACnB2C,KAAK,EAAC,QAAQ;gBACdK,WAAW,EAAC,+BAA+B;gBAC3CJ,OAAO,EACL,wEAAwE;gBACxE,uEAAuE;gBACvE,uBAAuB;8BACvB,KAAC3C,oBAAoB;oBACnBgD,QAAQ,EAAE,IAAI;oBACdC,oBAAoB;oBACpBH,gBAAgB;oBAChBhC,KAAK,EAAEoB,kBAAkB;oBACzBU,OAAO,EAAEhC,aAAa;oBACtBG,QAAQ,EAAEY,uBAAuB;oBACjCkB,QAAQ,EAAE/B,KAAK,KAAKO,SAAS,IAAIU,WAAW,KAAK,OAAO;oBACxDmB,SAAS,EAAE,CAAC;oBACZC,SAAS,EAAE;wBACTC,IAAI,EAAE,OAAO;qBACd;kBACD;cAEJ;;MACD,CACH;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/LegendOptionsEditor/LegendOptionsEditor.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 { Switch, SwitchProps } from '@mui/material';\nimport { DEFAULT_LEGEND, getLegendMode, getLegendPosition, getLegendSize } from '@perses-dev/core';\nimport { ErrorAlert, OptionsEditorControl, SettingsAutocomplete } from '@perses-dev/components';\nimport {\n LEGEND_MODE_CONFIG,\n LEGEND_POSITIONS_CONFIG,\n LegendSpecOptions,\n LegendSingleSelectConfig,\n validateLegendSpec,\n LEGEND_VALUE_CONFIG,\n LegendValue,\n LEGEND_SIZE_CONFIG,\n} from '../../model';\n\ntype LegendPositionOption = LegendSingleSelectConfig & { id: LegendSpecOptions['position'] };\n\nconst POSITION_OPTIONS: LegendPositionOption[] = Object.entries(LEGEND_POSITIONS_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendSpecOptions['position'],\n ...config,\n };\n});\n\ntype LegendModeOption = LegendSingleSelectConfig & { id: Required<LegendSpecOptions>['mode'] };\n\nconst MODE_OPTIONS: LegendModeOption[] = Object.entries(LEGEND_MODE_CONFIG).map(([id, config]) => {\n return {\n id: id as Required<LegendSpecOptions>['mode'],\n ...config,\n };\n});\n\ntype LegendSizeOption = LegendSingleSelectConfig & { id: Required<LegendSpecOptions>['size'] };\n\nconst SIZE_OPTIONS: LegendSizeOption[] = Object.entries(LEGEND_SIZE_CONFIG).map(([id, config]) => {\n return {\n id: id as Required<LegendSpecOptions>['size'],\n ...config,\n };\n});\n\ntype LegendValueOption = LegendSingleSelectConfig & { id: LegendValue };\nconst VALUE_OPTIONS: LegendValueOption[] = Object.entries(LEGEND_VALUE_CONFIG).map(([id, config]) => {\n return {\n id: id as LegendValue,\n ...config,\n };\n});\n\nexport interface LegendOptionsEditorProps {\n value?: LegendSpecOptions;\n onChange: (legend?: LegendSpecOptions) => void;\n}\n\nexport function LegendOptionsEditor({ value, onChange }: LegendOptionsEditorProps) {\n const handleLegendShowChange: SwitchProps['onChange'] = (_: unknown, checked: boolean) => {\n // legend is hidden when legend obj is undefined\n const legendValue = checked === true ? { position: DEFAULT_LEGEND.position } : undefined;\n onChange(legendValue);\n };\n\n const handleLegendPositionChange = (_: unknown, newValue: LegendPositionOption) => {\n onChange({\n ...value,\n position: newValue.id,\n });\n };\n\n const handleLegendModeChange = (_: unknown, newValue: LegendModeOption) => {\n onChange({\n ...value,\n position: currentPosition,\n mode: newValue.id,\n });\n };\n\n const handleLegendSizeChange = (_: unknown, newValue: LegendSizeOption) => {\n onChange({\n ...value,\n position: currentPosition,\n size: newValue.id,\n });\n };\n\n const handleLegendValueChange = (_: unknown, newValue: LegendValueOption[]) => {\n onChange({\n ...value,\n position: currentPosition,\n values: newValue.map((value) => {\n return value.id;\n }),\n });\n };\n\n const isValidLegend = validateLegendSpec(value);\n const currentPosition = getLegendPosition(value?.position);\n const legendPositionConfig = LEGEND_POSITIONS_CONFIG[currentPosition];\n\n const currentMode = getLegendMode(value?.mode);\n const legendModeConfig = LEGEND_MODE_CONFIG[currentMode];\n\n const currentSize = getLegendSize(value?.size);\n const legendSizeConfig = LEGEND_SIZE_CONFIG[currentSize];\n\n const currentValues = value?.values || [];\n const legendValuesConfig = currentValues.reduce((result, item) => {\n const config = LEGEND_VALUE_CONFIG[item];\n if (config) {\n result.push({ ...config, id: item });\n }\n return result;\n }, [] as LegendValueOption[]);\n\n return (\n <>\n {!isValidLegend && <ErrorAlert error={{ name: 'invalid-legend', message: 'Invalid legend spec' }} />}\n <OptionsEditorControl\n label=\"Show\"\n control={<Switch checked={value !== undefined} onChange={handleLegendShowChange} />}\n />\n <OptionsEditorControl\n label=\"Position\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendPositionConfig,\n id: currentPosition,\n }}\n options={POSITION_OPTIONS}\n onChange={handleLegendPositionChange}\n disabled={value === undefined}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Mode\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendModeConfig,\n id: currentMode,\n }}\n options={MODE_OPTIONS}\n onChange={handleLegendModeChange}\n disabled={value === undefined}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Size\"\n control={\n <SettingsAutocomplete\n value={{\n ...legendSizeConfig,\n id: currentSize,\n }}\n options={SIZE_OPTIONS}\n onChange={handleLegendSizeChange}\n // TODO: enable sizes for list mode when we normalize the layout of\n // lists to more closely match tables.\n disabled={value === undefined || currentMode !== 'Table'}\n disableClearable\n ></SettingsAutocomplete>\n }\n />\n <OptionsEditorControl\n label=\"Values\"\n control={\n // For some reason, the inferred option type doesn't always seem to work\n // quite right when `multiple` is true. Explicitly setting the generics\n // to work around this.\n <SettingsAutocomplete<LegendValueOption, true, true>\n multiple={true}\n disableCloseOnSelect\n disableClearable\n value={legendValuesConfig}\n options={VALUE_OPTIONS}\n onChange={handleLegendValueChange}\n disabled={value === undefined || currentMode !== 'Table'}\n limitTags={1}\n ChipProps={{\n size: 'small',\n }}\n />\n }\n />\n </>\n );\n}\n"],"names":["Switch","DEFAULT_LEGEND","getLegendMode","getLegendPosition","getLegendSize","ErrorAlert","OptionsEditorControl","SettingsAutocomplete","LEGEND_MODE_CONFIG","LEGEND_POSITIONS_CONFIG","validateLegendSpec","LEGEND_VALUE_CONFIG","LEGEND_SIZE_CONFIG","POSITION_OPTIONS","Object","entries","map","id","config","MODE_OPTIONS","SIZE_OPTIONS","VALUE_OPTIONS","LegendOptionsEditor","value","onChange","handleLegendShowChange","_","checked","legendValue","position","undefined","handleLegendPositionChange","newValue","handleLegendModeChange","currentPosition","mode","handleLegendSizeChange","size","handleLegendValueChange","values","isValidLegend","legendPositionConfig","currentMode","legendModeConfig","currentSize","legendSizeConfig","currentValues","legendValuesConfig","reduce","result","item","push","error","name","message","label","control","options","disabled","disableClearable","multiple","disableCloseOnSelect","limitTags","ChipProps"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF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ACL,wEAAwE;gBACxE,uEAAuE;gBACvE,uBAAuB;8BACvB,KAACjD,oBAAoB;oBACnBqD,QAAQ,EAAE,IAAI;oBACdC,oBAAoB;oBACpBF,gBAAgB;oBAChBpC,KAAK,EAAEwB,kBAAkB;oBACzBU,OAAO,EAAEpC,aAAa;oBACtBG,QAAQ,EAAEc,uBAAuB;oBACjCoB,QAAQ,EAAEnC,KAAK,KAAKO,SAAS,IAAIY,WAAW,KAAK,OAAO;oBACxDoB,SAAS,EAAE,CAAC;oBACZC,SAAS,EAAE;wBACT1B,IAAI,EAAE,OAAO;qBACd;kBACD;cAEJ;;MACD,CACH;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- import { CalculationType, LegendMode, LegendOptionsBase, LegendPositions } from '@perses-dev/core';
1
+ import { CalculationType, LegendMode, LegendOptionsBase, LegendPositions, LegendSize } from '@perses-dev/core';
2
2
  export declare const legendValues: CalculationType[];
3
3
  export declare type LegendValue = (typeof legendValues)[number];
4
4
  export interface LegendSpecOptions extends LegendOptionsBase {
@@ -10,6 +10,7 @@ export declare type LegendSingleSelectConfig = {
10
10
  };
11
11
  export declare const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>>;
12
12
  export declare const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>>;
13
+ export declare const LEGEND_SIZE_CONFIG: Readonly<Record<LegendSize, LegendSingleSelectConfig>>;
13
14
  export declare const LEGEND_VALUE_CONFIG: Partial<Record<"First" | "Last" | "FirstNumber" | "LastNumber" | "Mean" | "Sum" | "Min" | "Max", LegendSingleSelectConfig>>;
14
15
  export declare function validateLegendSpec(legend?: LegendOptionsBase): boolean;
15
16
  //# sourceMappingURL=legend.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"legend.d.ts","sourceRoot":"","sources":["../../src/model/legend.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,eAAe,EACf,UAAU,EACV,iBAAiB,EACjB,eAAe,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AAEF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAGrF,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,wBAAwB,CAAC,CAGrF,CAAC;AAEF,eAAO,MAAM,mBAAmB,6HAIgC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,iBAAiB,WAgB5D"}
@@ -10,7 +10,7 @@
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 { CALCULATIONS_CONFIG, isValidLegendMode, isValidLegendPosition } from '@perses-dev/core';
13
+ import { CALCULATIONS_CONFIG, isValidLegendMode, isValidLegendPosition, isValidLegendSize } from '@perses-dev/core';
14
14
  // This file contains legend-related model code specific to panel plugin specs.
15
15
  // See the `core` package for common/shared legend model code and the
16
16
  // `components` package for legend model code specific to the Legend component.
@@ -44,6 +44,14 @@ export const LEGEND_MODE_CONFIG = {
44
44
  label: 'Table'
45
45
  }
46
46
  };
47
+ export const LEGEND_SIZE_CONFIG = {
48
+ Small: {
49
+ label: 'Small'
50
+ },
51
+ Medium: {
52
+ label: 'Medium'
53
+ }
54
+ };
47
55
  export const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value)=>{
48
56
  config[value] = CALCULATIONS_CONFIG[value];
49
57
  return config;
@@ -59,6 +67,9 @@ export function validateLegendSpec(legend) {
59
67
  if (legend.mode && !isValidLegendMode(legend.mode)) {
60
68
  return false;
61
69
  }
70
+ if (legend.size && !isValidLegendSize(legend.size)) {
71
+ return false;
72
+ }
62
73
  return true;
63
74
  }
64
75
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/legend.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\nimport {\n CALCULATIONS_CONFIG,\n CalculationType,\n LegendMode,\n LegendOptionsBase,\n LegendPositions,\n isValidLegendMode,\n isValidLegendPosition,\n} from '@perses-dev/core';\n\n// This file contains legend-related model code specific to panel plugin specs.\n// See the `core` package for common/shared legend model code and the\n// `components` package for legend model code specific to the Legend component.\n\n// Explicity listing the calculations we intend to use for legend values because\n// we want them ordered in a specific way, and it may be possible in the future\n// that we only use a subset of calculations for the legend because the calculations\n// are also used by other features.\nexport const legendValues: CalculationType[] = [\n 'Mean',\n 'First',\n 'FirstNumber',\n 'Last',\n 'LastNumber',\n 'Min',\n 'Max',\n 'Sum',\n];\nexport type LegendValue = (typeof legendValues)[number];\n\n// Note: explicitly defining different options for the legend spec and\n// legend component that extend from some common options, so we can allow the\n// component and the spec to diverge in some upcoming work.\nexport interface LegendSpecOptions extends LegendOptionsBase {\n values?: LegendValue[];\n}\n\nexport type LegendSingleSelectConfig = {\n label: string;\n description?: string;\n};\n\nexport const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>> = {\n Bottom: { label: 'Bottom' },\n Right: { label: 'Right' },\n};\n\nexport const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>> = {\n List: { label: 'List' },\n Table: { label: 'Table' },\n};\n\nexport const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value) => {\n config[value] = CALCULATIONS_CONFIG[value];\n\n return config;\n}, {} as Partial<Record<LegendValue, LegendSingleSelectConfig>>);\n\nexport function validateLegendSpec(legend?: LegendOptionsBase) {\n if (legend === undefined) {\n // undefined is valid since this is how legend is hidden by default\n return true;\n }\n if (!isValidLegendPosition(legend.position)) {\n return false;\n }\n if (legend.mode && !isValidLegendMode(legend.mode)) {\n return false;\n }\n\n return true;\n}\n"],"names":["CALCULATIONS_CONFIG","isValidLegendMode","isValidLegendPosition","legendValues","LEGEND_POSITIONS_CONFIG","Bottom","label","Right","LEGEND_MODE_CONFIG","List","Table","LEGEND_VALUE_CONFIG","reduce","config","value","validateLegendSpec","legend","undefined","position","mode"],"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,SACEA,mBAAmB,EAKnBC,iBAAiB,EACjBC,qBAAqB,QAChB,kBAAkB,CAAC;AAE1B,+EAA+E;AAC/E,qEAAqE;AACrE,+EAA+E;AAE/E,gFAAgF;AAChF,+EAA+E;AAC/E,oFAAoF;AACpF,mCAAmC;AACnC,OAAO,MAAMC,YAAY,GAAsB;IAC7C,MAAM;IACN,OAAO;IACP,aAAa;IACb,MAAM;IACN,YAAY;IACZ,KAAK;IACL,KAAK;IACL,KAAK;CACN,CAAC;AAeF,OAAO,MAAMC,uBAAuB,GAAgE;IAClGC,MAAM,EAAE;QAAEC,KAAK,EAAE,QAAQ;KAAE;IAC3BC,KAAK,EAAE;QAAED,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAME,kBAAkB,GAA2D;IACxFC,IAAI,EAAE;QAAEH,KAAK,EAAE,MAAM;KAAE;IACvBI,KAAK,EAAE;QAAEJ,KAAK,EAAE,OAAO;KAAE;CAC1B,CAAC;AAEF,OAAO,MAAMK,mBAAmB,GAAGR,YAAY,CAACS,MAAM,CAAC,CAACC,MAAM,EAAEC,KAAK,GAAK;IACxED,MAAM,CAACC,KAAK,CAAC,GAAGd,mBAAmB,CAACc,KAAK,CAAC,CAAC;IAE3C,OAAOD,MAAM,CAAC;AAChB,CAAC,EAAE,EAAE,CAA2D,CAAC;AAEjE,OAAO,SAASE,kBAAkB,CAACC,MAA0B,EAAE;IAC7D,IAAIA,MAAM,KAAKC,SAAS,EAAE;QACxB,mEAAmE;QACnE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,CAACf,qBAAqB,CAACc,MAAM,CAACE,QAAQ,CAAC,EAAE;QAC3C,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAIF,MAAM,CAACG,IAAI,IAAI,CAAClB,iBAAiB,CAACe,MAAM,CAACG,IAAI,CAAC,EAAE;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
1
+ {"version":3,"sources":["../../src/model/legend.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\nimport {\n CALCULATIONS_CONFIG,\n CalculationType,\n LegendMode,\n LegendOptionsBase,\n LegendPositions,\n isValidLegendMode,\n isValidLegendPosition,\n LegendSize,\n isValidLegendSize,\n} from '@perses-dev/core';\n\n// This file contains legend-related model code specific to panel plugin specs.\n// See the `core` package for common/shared legend model code and the\n// `components` package for legend model code specific to the Legend component.\n\n// Explicity listing the calculations we intend to use for legend values because\n// we want them ordered in a specific way, and it may be possible in the future\n// that we only use a subset of calculations for the legend because the calculations\n// are also used by other features.\nexport const legendValues: CalculationType[] = [\n 'Mean',\n 'First',\n 'FirstNumber',\n 'Last',\n 'LastNumber',\n 'Min',\n 'Max',\n 'Sum',\n];\nexport type LegendValue = (typeof legendValues)[number];\n\n// Note: explicitly defining different options for the legend spec and\n// legend component that extend from some common options, so we can allow the\n// component and the spec to diverge in some upcoming work.\nexport interface LegendSpecOptions extends LegendOptionsBase {\n values?: LegendValue[];\n}\n\nexport type LegendSingleSelectConfig = {\n label: string;\n description?: string;\n};\n\nexport const LEGEND_POSITIONS_CONFIG: Readonly<Record<LegendPositions, LegendSingleSelectConfig>> = {\n Bottom: { label: 'Bottom' },\n Right: { label: 'Right' },\n};\n\nexport const LEGEND_MODE_CONFIG: Readonly<Record<LegendMode, LegendSingleSelectConfig>> = {\n List: { label: 'List' },\n Table: { label: 'Table' },\n};\n\nexport const LEGEND_SIZE_CONFIG: Readonly<Record<LegendSize, LegendSingleSelectConfig>> = {\n Small: { label: 'Small' },\n Medium: { label: 'Medium' },\n};\n\nexport const LEGEND_VALUE_CONFIG = legendValues.reduce((config, value) => {\n config[value] = CALCULATIONS_CONFIG[value];\n\n return config;\n}, {} as Partial<Record<LegendValue, LegendSingleSelectConfig>>);\n\nexport function validateLegendSpec(legend?: LegendOptionsBase) {\n if (legend === undefined) {\n // undefined is valid since this is how legend is hidden by default\n return true;\n }\n if (!isValidLegendPosition(legend.position)) {\n return false;\n }\n if (legend.mode && !isValidLegendMode(legend.mode)) {\n return false;\n }\n if (legend.size && !isValidLegendSize(legend.size)) {\n return false;\n }\n\n return true;\n}\n"],"names":["CALCULATIONS_CONFIG","isValidLegendMode","isValidLegendPosition","isValidLegendSize","legendValues","LEGEND_POSITIONS_CONFIG","Bottom","label","Right","LEGEND_MODE_CONFIG","List","Table","LEGEND_SIZE_CONFIG","Small","Medium","LEGEND_VALUE_CONFIG","reduce","config","value","validateLegendSpec","legend","undefined","position","mode","size"],"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,SACEA,mBAAmB,EAKnBC,iBAAiB,EACjBC,qBAAqB,E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iBAAiB,CAACmB,MAAM,CAACG,IAAI,CAAC,EAAE;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,IAAIH,MAAM,CAACI,IAAI,IAAI,CAACrB,iBAAiB,CAACiB,MAAM,CAACI,IAAI,CAAC,EAAE;QAClD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -27,6 +27,7 @@ export interface TimeSeriesQueryContext {
27
27
  variableState: VariableStateMap;
28
28
  datasourceStore: DatasourceStore;
29
29
  refreshKey: string;
30
+ refreshIntervalInMs: number;
30
31
  }
31
32
  export declare type TimeSeriesDataQuery = Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>;
32
33
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/model/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAEvC;;GAEG;AACH,aAAK,iCAAiC,GAAG;IACvC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,qBAAqB,CAAC,IAAI,GAAG,WAAW,CAAE,SAAQ,MAAM,CAAC,IAAI,CAAC;IAC7E,iBAAiB,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,sBAAsB,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAExF,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,sBAAsB,KAAK,iCAAiC,CAAC;CAC5F;AAED;;GAEG;AACH,M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;IACnB,mBAAmB,EAAE,MAAM,CAAC;CAC7B;AAED,oBAAY,mBAAmB,GAAG,KAAK,CAAC,cAAc,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/time-series-queries.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\nimport { Query, QueryKey } from '@tanstack/react-query';\nimport { AbsoluteTimeRange, UnknownSpec, TimeSeriesData } from '@perses-dev/core';\nimport { DatasourceStore, VariableStateMap } from '../runtime';\nimport { Plugin } from './plugin-base';\n\n/**\n * An object containing all the dependencies of a TimeSeriesQuery.\n */\ntype TimeSeriesQueryPluginDependencies = {\n /**\n * Returns a list of variables name this time series query depends on.\n */\n variables?: string[];\n};\n\n/**\n * A plugin for running time series queries.\n */\nexport interface TimeSeriesQueryPlugin<Spec = UnknownSpec> extends Plugin<Spec> {\n getTimeSeriesData: (spec: Spec, ctx: TimeSeriesQueryContext) => Promise<TimeSeriesData>;\n\n dependsOn?: (spec: Spec, ctx: TimeSeriesQueryContext) => TimeSeriesQueryPluginDependencies;\n}\n\n/**\n * Context available to TimeSeriesQuery plugins at runtime.\n */\nexport interface TimeSeriesQueryContext {\n suggestedStepMs?: number;\n timeRange: AbsoluteTimeRange;\n variableState: VariableStateMap;\n datasourceStore: DatasourceStore;\n refreshKey: string;\n}\n\nexport type TimeSeriesDataQuery = Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>;\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,WAmC2F"}
1
+ {"version":3,"sources":["../../src/model/time-series-queries.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\nimport { Query, QueryKey } from '@tanstack/react-query';\nimport { AbsoluteTimeRange, UnknownSpec, TimeSeriesData } from '@perses-dev/core';\nimport { DatasourceStore, VariableStateMap } from '../runtime';\nimport { Plugin } from './plugin-base';\n\n/**\n * An object containing all the dependencies of a TimeSeriesQuery.\n */\ntype TimeSeriesQueryPluginDependencies = {\n /**\n * Returns a list of variables name this time series query depends on.\n */\n variables?: string[];\n};\n\n/**\n * A plugin for running time series queries.\n */\nexport interface TimeSeriesQueryPlugin<Spec = UnknownSpec> extends Plugin<Spec> {\n getTimeSeriesData: (spec: Spec, ctx: TimeSeriesQueryContext) => Promise<TimeSeriesData>;\n\n dependsOn?: (spec: Spec, ctx: TimeSeriesQueryContext) => TimeSeriesQueryPluginDependencies;\n}\n\n/**\n * Context available to TimeSeriesQuery plugins at runtime.\n */\nexport interface TimeSeriesQueryContext {\n suggestedStepMs?: number;\n timeRange: AbsoluteTimeRange;\n variableState: VariableStateMap;\n datasourceStore: DatasourceStore;\n refreshKey: string;\n refreshIntervalInMs: number;\n}\n\nexport type TimeSeriesDataQuery = Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>;\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,WAoC2F"}
@@ -1,7 +1,8 @@
1
1
  import React from 'react';
2
- import { AbsoluteTimeRange, TimeRangeValue } from '@perses-dev/core';
2
+ import { AbsoluteTimeRange, DurationString, TimeRangeValue } from '@perses-dev/core';
3
3
  export interface TimeRangeProviderProps {
4
4
  initialTimeRange: TimeRangeValue;
5
+ initialRefreshInterval?: DurationString;
5
6
  enabledURLParams?: boolean;
6
7
  children?: React.ReactNode;
7
8
  }
@@ -11,6 +12,9 @@ export interface TimeRange {
11
12
  setTimeRange: (value: TimeRangeValue) => void;
12
13
  refresh: () => void;
13
14
  refreshKey: string;
15
+ refreshInterval?: DurationString;
16
+ refreshIntervalInMs: number;
17
+ setRefreshInterval: (value: DurationString) => void;
14
18
  }
15
19
  export declare const TimeRangeContext: React.Context<TimeRange | undefined>;
16
20
  export declare function useTimeRangeContext(): TimeRange;
@@ -1 +1 @@
1
- {"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAoE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAE,iBAAiB,EAAuB,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AAG/G,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,cAAc,CAAC;IACjC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,cAAc,CAAC;IAC1B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,YAAY,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,gBAAgB,sCAAkD,CAAC;AAEhF,wBAAgB,mBAAmB,cAMlC;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,SAAS,CAGxC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eAuB9D"}
1
+ {"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAoE,MAAM,OAAO,CAAC;AACzF,OAAO,EACL,iBAAiB,EACjB,cAAc,EAEd,cAAc,EAEf,MAAM,kBAAkB,CAAC;AAG1B,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,cAAc,CAAC;IACjC,sBAAsB,CAAC,EAAE,cAAc,CAAC;IACxC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,cAAc,CAAC;IAC1B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,YAAY,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CACrD;AAED,eAAO,MAAM,gBAAgB,sCAAkD,CAAC;AAEhF,wBAAgB,mBAAmB,cAMlC;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,SAAS,CAExC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eA8B9D"}
@@ -13,7 +13,7 @@
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import React, { useMemo, useState, useCallback, createContext, useContext } from 'react';
15
15
  import { isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/core';
16
- import { useSetTimeRangeParams } from './query-params';
16
+ import { useSetRefreshIntervalParams, useSetTimeRangeParams } from './query-params';
17
17
  export const TimeRangeContext = /*#__PURE__*/ createContext(undefined);
18
18
  export function useTimeRangeContext() {
19
19
  const ctx = useContext(TimeRangeContext);
@@ -25,20 +25,14 @@ export function useTimeRangeContext() {
25
25
  /**
26
26
  * Get and set the current resolved time range at runtime.
27
27
  */ export function useTimeRange() {
28
- const { timeRange , absoluteTimeRange , setTimeRange , refresh , refreshKey } = useTimeRangeContext();
29
- return {
30
- timeRange,
31
- absoluteTimeRange,
32
- setTimeRange,
33
- refresh,
34
- refreshKey
35
- };
28
+ return useTimeRangeContext();
36
29
  }
37
30
  /**
38
31
  * Provider implementation that supplies the time range state at runtime.
39
32
  */ export function TimeRangeProvider(props) {
40
- const { initialTimeRange , enabledURLParams , children } = props;
33
+ const { initialTimeRange , initialRefreshInterval , enabledURLParams , children } = props;
41
34
  const { timeRange , setTimeRange } = useSetTimeRangeParams(initialTimeRange, enabledURLParams);
35
+ const { refreshInterval , setRefreshInterval , refreshIntervalInMs } = useSetRefreshIntervalParams(initialRefreshInterval, enabledURLParams);
42
36
  const [refreshKey, setRefreshKey] = useState(0);
43
37
  const refresh = useCallback(()=>{
44
38
  setRefreshKey(refreshKey + 1);
@@ -52,13 +46,19 @@ export function useTimeRangeContext() {
52
46
  setTimeRange,
53
47
  absoluteTimeRange,
54
48
  refresh,
55
- refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshKey}`
49
+ refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshInterval}:${refreshKey}`,
50
+ refreshInterval,
51
+ refreshIntervalInMs,
52
+ setRefreshInterval
56
53
  };
57
54
  }, [
58
55
  timeRange,
59
56
  setTimeRange,
60
57
  refresh,
61
- refreshKey
58
+ refreshKey,
59
+ refreshInterval,
60
+ refreshIntervalInMs,
61
+ setRefreshInterval
62
62
  ]);
63
63
  return /*#__PURE__*/ _jsx(TimeRangeContext.Provider, {
64
64
  value: ctx,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.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 React, { useMemo, useState, useCallback, createContext, useContext } from 'react';\nimport { AbsoluteTimeRange, isRelativeTimeRange, TimeRangeValue, toAbsoluteTimeRange } from '@perses-dev/core';\nimport { useSetTimeRangeParams } from './query-params';\n\nexport interface TimeRangeProviderProps {\n initialTimeRange: TimeRangeValue;\n enabledURLParams?: boolean;\n children?: React.ReactNode;\n}\n\nexport interface TimeRange {\n timeRange: TimeRangeValue;\n absoluteTimeRange: AbsoluteTimeRange; // resolved absolute time for plugins to use\n setTimeRange: (value: TimeRangeValue) => void;\n refresh: () => void;\n refreshKey: string;\n}\n\nexport const TimeRangeContext = createContext<TimeRange | undefined>(undefined);\n\nexport function useTimeRangeContext() {\n const ctx = useContext(TimeRangeContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRange(): TimeRange {\n const { timeRange, absoluteTimeRange, setTimeRange, refresh, refreshKey } = useTimeRangeContext();\n return { timeRange, absoluteTimeRange, setTimeRange, refresh, refreshKey };\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps) {\n const { initialTimeRange, enabledURLParams, children } = props;\n\n const { timeRange, setTimeRange } = useSetTimeRangeParams(initialTimeRange, enabledURLParams);\n\n const [refreshKey, setRefreshKey] = useState(0);\n\n const refresh = useCallback(() => {\n setRefreshKey(refreshKey + 1);\n }, [refreshKey]);\n\n const ctx = useMemo(() => {\n const absoluteTimeRange = isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange;\n return {\n timeRange,\n setTimeRange,\n absoluteTimeRange,\n refresh,\n refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshKey}`,\n };\n }, [timeRange, setTimeRange, refresh, refreshKey]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","useMemo","useState","useCallback","createContext","useContext","isRelativeTimeRange","toAbsoluteTimeRange","useSetTimeRangeParams","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","timeRange","absoluteTimeRange","setTimeRange","refresh","refreshKey","TimeRangeProvider","props","initialTimeRange","enabledURLParams","children","setRefreshKey","start","end","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,KAAK,IAAIC,OAAO,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,aAAa,EAAEC,UAAU,QAAQ,OAAO,CAAC;AACzF,SAA4BC,mBAAmB,EAAkBC,mBAAmB,QAAQ,kBAAkB,CAAC;AAC/G,SAASC,qBAAqB,QAAQ,gBAAgB,CAAC;AAgBvD,OAAO,MAAMC,gBAAgB,iBAAGL,aAAa,CAAwBM,SAAS,CAAC,CAAC;AAEhF,OAAO,SAASC,mBAAmB,GAAG;IACpC,MAAMC,GAAG,GAAGP,UAAU,CAACI,gBAAgB,CAA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,iBAAiB,CAACW,GAAG,CAAC,CAAC,EAAER,UAAU,CAAC,CAAC;SAChF,CAAC;IACJ,CAAC,EAAE;QAACJ,SAAS;QAAEE,YAAY;QAAEC,OAAO;QAAEC,UAAU;KAAC,CAAC,AAAC;IAEnD,qBAAO,KAACV,gBAAgB,CAACmB,QAAQ;QAACC,KAAK,EAAEjB,GAAG;kBAAGY,QAAQ;MAA6B,CAAC;AACvF,CAAC"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.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 React, { useMemo, useState, useCallback, createContext, useContext } from 'react';\nimport {\n AbsoluteTimeRange,\n DurationString,\n isRelativeTimeRange,\n TimeRangeValue,\n toAbsoluteTimeRange,\n} from '@perses-dev/core';\nimport { useSetRefreshIntervalParams, useSetTimeRangeParams } from './query-params';\n\nexport interface TimeRangeProviderProps {\n initialTimeRange: TimeRangeValue;\n initialRefreshInterval?: DurationString;\n enabledURLParams?: boolean;\n children?: React.ReactNode;\n}\n\nexport interface TimeRange {\n timeRange: TimeRangeValue;\n absoluteTimeRange: AbsoluteTimeRange; // resolved absolute time for plugins to use\n setTimeRange: (value: TimeRangeValue) => void;\n refresh: () => void;\n refreshKey: string;\n refreshInterval?: DurationString;\n refreshIntervalInMs: number;\n setRefreshInterval: (value: DurationString) => void;\n}\n\nexport const TimeRangeContext = createContext<TimeRange | undefined>(undefined);\n\nexport function useTimeRangeContext() {\n const ctx = useContext(TimeRangeContext);\n if (ctx === undefined) {\n throw new Error('No TimeRangeContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Get and set the current resolved time range at runtime.\n */\nexport function useTimeRange(): TimeRange {\n return useTimeRangeContext();\n}\n\n/**\n * Provider implementation that supplies the time range state at runtime.\n */\nexport function TimeRangeProvider(props: TimeRangeProviderProps) {\n const { initialTimeRange, initialRefreshInterval, enabledURLParams, children } = props;\n\n const { timeRange, setTimeRange } = useSetTimeRangeParams(initialTimeRange, enabledURLParams);\n const { refreshInterval, setRefreshInterval, refreshIntervalInMs } = useSetRefreshIntervalParams(\n initialRefreshInterval,\n enabledURLParams\n );\n\n const [refreshKey, setRefreshKey] = useState(0);\n\n const refresh = useCallback(() => {\n setRefreshKey(refreshKey + 1);\n }, [refreshKey]);\n\n const ctx = useMemo(() => {\n const absoluteTimeRange = isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange;\n return {\n timeRange,\n setTimeRange,\n absoluteTimeRange,\n refresh,\n refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshInterval}:${refreshKey}`,\n refreshInterval,\n refreshIntervalInMs,\n setRefreshInterval,\n };\n }, [timeRange, setTimeRange, refresh, refreshKey, refreshInterval, refreshIntervalInMs, setRefreshInterval]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","useMemo","useState","useCallback","createContext","useContext","isRelativeTimeRange","toAbsoluteTimeRange","useSetRefreshIntervalParams","useSetTimeRangeParams","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","TimeRangeProvider","props","initialTimeRange","initialRefreshInterval","enabledURLParams","children","timeRange","setTimeRange","refreshInterval","setRefreshInterval","refreshIntervalInMs","refreshKey","setRefreshKey","refresh","absoluteTimeRange","start","end","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2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CyB,aAAa,CAACD,UAAU,GAAG,CAAC,CAAC,CAAC;IAChC,CAAC,EAAE;QAACA,UAAU;KAAC,CAAC,AAAC;IAEjB,MAAMd,GAAG,GAAGZ,OAAO,CAAC,IAAM;QACxB,MAAM6B,iBAAiB,GAAGxB,mBAAmB,CAACgB,SAAS,CAAC,GAAGf,mBAAmB,CAACe,SAAS,CAAC,GAAGA,SAAS,AAAC;QACtG,OAAO;YACLA,SAAS;YACTC,YAAY;YACZO,iBAAiB;YACjBD,OAAO;YACPF,UAAU,EAAE,CAAC,EAAEG,iBAAiB,CAACC,KAAK,CAAC,CAAC,EAAED,iBAAiB,CAACE,GAAG,CAAC,CAAC,EAAER,eAAe,CAAC,CAAC,EAAEG,UAAU,CAAC,CAAC;YAClGH,eAAe;YACfE,mBAAmB;YACnBD,kBAAkB;SACnB,CAAC;IACJ,CAAC,EAAE;QAACH,SAAS;QAAEC,YAAY;QAAEM,OAAO;QAAEF,UAAU;QAAEH,eAAe;QAAEE,mBAAmB;QAAED,kBAAkB;KAAC,CAAC,AAAC;IAE7G,qBAAO,KAACf,gBAAgB,CAACuB,QAAQ;QAACC,KAAK,EAAErB,GAAG;kBAAGQ,QAAQ;MAA6B,CAAC;AACvF,CAAC"}
@@ -13,6 +13,9 @@ export declare const timeRangeQueryConfig: {
13
13
  start: QueryParamConfig<TimeOptionValue, TimeOptionValue>;
14
14
  end: QueryParamConfig<TimeOptionValue, TimeOptionValue>;
15
15
  };
16
+ export declare const refreshIntervalQueryConfig: {
17
+ refresh: QueryParamConfig<TimeOptionValue, TimeOptionValue>;
18
+ };
16
19
  /**
17
20
  * Gets the initial time range taking into account URL params and dashboard JSON duration
18
21
  * Sets start query param if it is empty on page load
@@ -22,4 +25,13 @@ export declare function useInitialTimeRange(dashboardDuration: DurationString):
22
25
  * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization
23
26
  */
24
27
  export declare function useSetTimeRangeParams(initialTimeRange: TimeRangeValue, enabledURLParams?: boolean): Pick<TimeRange, 'timeRange' | 'setTimeRange'>;
28
+ /**
29
+ * Gets the initial refresh interval taking into account URL params and dashboard JSON duration
30
+ * Sets refresh query param if it is empty on page load
31
+ */
32
+ export declare function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString;
33
+ /**
34
+ * Returns refresh interval getter and setter, set enabledURLParams to false to disable query string serialization
35
+ */
36
+ export declare function useSetRefreshIntervalParams(initialRefreshInterval?: DurationString, enabledURLParams?: boolean): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval' | 'refreshIntervalInMs'>;
25
37
  //# sourceMappingURL=query-params.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/query-params.ts"],"names":[],"mappings":"AAcA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EACL,cAAc,EAGd,cAAc,EAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,oBAAY,eAAe,GAAG,IAAI,GAAG,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;AA2BvE,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAWhG;AAGD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GACtD,IAAI,GAAG,cAAc,GAAG,IAAI,GAAG,SAAS,CAI1C;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,eAAe,EAAE,eAAe,CAQ7E,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,cAAc,GAAG,cAAc,CAgBrF;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,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,EAAE,cAAc,EACvC,gBAAgB,UAAO,GACtB,IAAI,CAAC,SAAS,EAAE,iBAAiB,GAAG,oBAAoB,GAAG,qBAAqB,CAAC,CAqCnF"}
@@ -13,7 +13,7 @@
13
13
  import { useMemo, useCallback, useEffect, useState } from 'react';
14
14
  import { useQueryParams } from 'use-query-params';
15
15
  import { getUnixTime, isDate } from 'date-fns';
16
- import { isRelativeTimeRange, isDurationString } from '@perses-dev/core';
16
+ import { isRelativeTimeRange, isDurationString, parseDurationString } from '@perses-dev/core';
17
17
  /* Interprets an encoded string and returns either the string or null/undefined if not available */ function getEncodedValue(input, allowEmptyString) {
18
18
  if (input == null) {
19
19
  return input;
@@ -63,6 +63,9 @@ export const timeRangeQueryConfig = {
63
63
  start: TimeRangeParam,
64
64
  end: TimeRangeParam
65
65
  };
66
+ export const refreshIntervalQueryConfig = {
67
+ refresh: TimeRangeParam
68
+ };
66
69
  /**
67
70
  * Gets the initial time range taking into account URL params and dashboard JSON duration
68
71
  * Sets start query param if it is empty on page load
@@ -149,5 +152,83 @@ export const timeRangeQueryConfig = {
149
152
  setTimeRange: setTimeRange
150
153
  };
151
154
  }
155
+ /**
156
+ * Gets the initial refresh interval taking into account URL params and dashboard JSON duration
157
+ * Sets refresh query param if it is empty on page load
158
+ */ export function useInitialRefreshInterval(dashboardDuration) {
159
+ const [query] = useQueryParams(refreshIntervalQueryConfig, {
160
+ updateType: 'replaceIn'
161
+ });
162
+ const { refresh } = query;
163
+ return useMemo(()=>{
164
+ let initialTimeRange = dashboardDuration;
165
+ if (!refresh) {
166
+ return initialTimeRange;
167
+ }
168
+ const startStr = refresh.toString();
169
+ if (isDurationString(startStr)) {
170
+ initialTimeRange = startStr;
171
+ }
172
+ return initialTimeRange;
173
+ }, [
174
+ dashboardDuration,
175
+ refresh
176
+ ]);
177
+ }
178
+ function getRefreshIntervalInMs(refreshInterval) {
179
+ let refreshIntervalInMs = 0;
180
+ if (refreshInterval) {
181
+ const refreshIntervalDuration = parseDurationString(refreshInterval);
182
+ if (refreshIntervalDuration && refreshIntervalDuration.seconds) {
183
+ refreshIntervalInMs = (refreshIntervalDuration === null || refreshIntervalDuration === void 0 ? void 0 : refreshIntervalDuration.seconds) * 1000;
184
+ }
185
+ }
186
+ return refreshIntervalInMs;
187
+ }
188
+ /**
189
+ * Returns refresh interval getter and setter, set enabledURLParams to false to disable query string serialization
190
+ */ export function useSetRefreshIntervalParams(initialRefreshInterval, enabledURLParams = true) {
191
+ const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, {
192
+ updateType: 'replaceIn'
193
+ });
194
+ // determine whether initial param had previously been populated to fix back btn
195
+ const [paramsLoaded, setParamsLoaded] = useState(false);
196
+ // optional fallback when app does not want query string as source of truth
197
+ // this occurs when enabledURLParams is set to false on TimeRangeProvider
198
+ const [refreshIntervalState, setRefreshIntervalState] = useState(initialRefreshInterval);
199
+ const { refresh } = query;
200
+ useEffect(()=>{
201
+ // when dashboard loaded with no params, default to dashboard duration
202
+ if (enabledURLParams && !paramsLoaded && !refresh) {
203
+ setQuery({
204
+ refresh: initialRefreshInterval
205
+ });
206
+ setParamsLoaded(true);
207
+ }
208
+ }, [
209
+ initialRefreshInterval,
210
+ enabledURLParams,
211
+ paramsLoaded,
212
+ refresh,
213
+ setQuery
214
+ ]);
215
+ const setRefreshInterval = useCallback((refresh)=>setQuery({
216
+ refresh
217
+ }), [
218
+ setQuery
219
+ ]);
220
+ if (!enabledURLParams) {
221
+ return {
222
+ refreshInterval: refreshIntervalState,
223
+ setRefreshInterval: setRefreshIntervalState,
224
+ refreshIntervalInMs: getRefreshIntervalInMs(refreshIntervalState)
225
+ };
226
+ }
227
+ return {
228
+ refreshInterval: initialRefreshInterval,
229
+ setRefreshInterval: setRefreshInterval,
230
+ refreshIntervalInMs: getRefreshIntervalInMs(initialRefreshInterval)
231
+ };
232
+ }
152
233
 
153
234
  //# sourceMappingURL=query-params.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/query-params.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\nimport { useMemo, useCallback, useEffect, useState } from 'react';\nimport { useQueryParams, QueryParamConfig } from 'use-query-params';\nimport { getUnixTime, isDate } from 'date-fns';\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n isDurationString,\n DurationString,\n AbsoluteTimeRange,\n} from '@perses-dev/core';\nimport { TimeRange } from './TimeRangeProvider';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean\n): string | null | undefined {\n if (input == null) {\n return input;\n }\n // '' or []\n if (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== ''))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str == null) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (paramString == null) return paramString;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (valueA == null || valueB == null) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n const { start, end } = query;\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization\n */\nexport function useSetTimeRangeParams(\n initialTimeRange: TimeRangeValue,\n enabledURLParams = true\n): Pick<TimeRange, 'timeRange' | 'setTimeRange'> {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n // optional fallback when app does not want query string as source of truth\n // this occurs when enabledURLParams is set to false on TimeRangeProvider\n const [timeRangeState, setTimeRangeState] = useState<TimeRangeValue>(initialTimeRange);\n\n const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (enabledURLParams && !paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, enabledURLParams, paramsLoaded, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery]\n );\n\n if (!enabledURLParams) {\n return { timeRange: timeRangeState, setTimeRange: setTimeRangeState };\n }\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n"],"names":["useMemo","useCallback","useEffect","useState","useQueryParams","getUnixTime","isDate","isRelativeTimeRange","isDurationString","getEncodedValue","input","allowEmptyString","length","str","Array","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useSetTimeRangeParams","enabledURLParams","setQuery","paramsLoaded","setParamsLoaded","timeRangeState","setTimeRangeState","undefined","setTimeRange","value","timeRange"],"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,SAASA,OAAO,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAClE,SAASC,cAAc,QAA0B,kBAAkB,CAAC;AACpE,SAASC,WAAW,EAAEC,MAAM,QAAQ,UAAU,CAAC;AAC/C,SAEEC,mBAAmB,EACnBC,gBAAgB,QAGX,kBAAkB,CAAC;AAK1B,iGAAiG,GACjG,SAASC,eAAe,CACtBC,KAAuD,EACvDC,gBAA0B,EACC;IAC3B,IA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AAEkB,KAAK,CAACX,YAAY;gBAAEN,GAAG,EAAEe,SAAS;aAAE,CAAC,CAAC;QAC1D,OAAO;YACLL,QAAQ,CAACO,KAAK,CAAC,CAAC;QAClB,CAAC;IACH,CAAC,EACD;QAACP,QAAQ;KAAC,CACX,AAAC;IAEF,IAAI,CAACD,gBAAgB,EAAE;QACrB,OAAO;YAAES,SAAS,EAAEL,cAAc;YAAEG,YAAY,EAAEF,iBAAiB;SAAE,CAAC;IACxE,CAAC;IACD,OAAO;QAAEI,SAAS,EAAEb,gBAAgB;QAAEW,YAAY,EAAEA,YAAY;KAAE,CAAC;AACrE,CAAC"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/query-params.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\nimport { useMemo, useCallback, useEffect, useState } from 'react';\nimport { useQueryParams, QueryParamConfig } from 'use-query-params';\nimport { getUnixTime, isDate } from 'date-fns';\nimport {\n TimeRangeValue,\n isRelativeTimeRange,\n isDurationString,\n DurationString,\n AbsoluteTimeRange,\n parseDurationString,\n} from '@perses-dev/core';\nimport { TimeRange } from './TimeRangeProvider';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean\n): string | null | undefined {\n if (input == null) {\n return input;\n }\n // '' or []\n if (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== ''))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str == null) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (paramString == null) return paramString;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (valueA == null || valueB == null) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\nexport const refreshIntervalQueryConfig = {\n refresh: TimeRangeParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n const { start, end } = query;\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization\n */\nexport function useSetTimeRangeParams(\n initialTimeRange: TimeRangeValue,\n enabledURLParams = true\n): Pick<TimeRange, 'timeRange' | 'setTimeRange'> {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n // optional fallback when app does not want query string as source of truth\n // this occurs when enabledURLParams is set to false on TimeRangeProvider\n const [timeRangeState, setTimeRangeState] = useState<TimeRangeValue>(initialTimeRange);\n\n const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (enabledURLParams && !paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, enabledURLParams, paramsLoaded, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery]\n );\n\n if (!enabledURLParams) {\n return { timeRange: timeRangeState, setTimeRange: setTimeRangeState };\n }\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n\n/**\n * Gets the initial refresh interval taking into account URL params and dashboard JSON duration\n * Sets refresh query param if it is empty on page load\n */\nexport function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString {\n const [query] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n const { refresh } = query;\n return useMemo(() => {\n let initialTimeRange: DurationString = dashboardDuration;\n if (!refresh) {\n return initialTimeRange;\n }\n const startStr = refresh.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = startStr;\n }\n return initialTimeRange;\n }, [dashboardDuration, refresh]);\n}\n\nfunction getRefreshIntervalInMs(refreshInterval?: DurationString) {\n let refreshIntervalInMs = 0;\n if (refreshInterval) {\n const refreshIntervalDuration = parseDurationString(refreshInterval);\n if (refreshIntervalDuration && refreshIntervalDuration.seconds) {\n refreshIntervalInMs = refreshIntervalDuration?.seconds * 1000;\n }\n }\n return refreshIntervalInMs;\n}\n\n/**\n * Returns refresh interval getter and setter, set enabledURLParams to false to disable query string serialization\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString,\n enabledURLParams = true\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval' | 'refreshIntervalInMs'> {\n const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n // optional fallback when app does not want query string as source of truth\n // this occurs when enabledURLParams is set to false on TimeRangeProvider\n const [refreshIntervalState, setRefreshIntervalState] = useState<DurationString | undefined>(initialRefreshInterval);\n\n const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (enabledURLParams && !paramsLoaded && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n setParamsLoaded(true);\n }\n }, [initialRefreshInterval, enabledURLParams, paramsLoaded, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery]\n );\n\n if (!enabledURLParams) {\n return {\n refreshInterval: refreshIntervalState,\n setRefreshInterval: setRefreshIntervalState,\n refreshIntervalInMs: getRefreshIntervalInMs(refreshIntervalState),\n };\n }\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n refreshIntervalInMs: getRefreshIntervalInMs(initialRefreshInterval),\n };\n}\n"],"names":["useMemo","useCallback","useEffect","useState","useQueryParams","getUnixTime","isDate","isRelativeTimeRange","isDurationString","parseDurationString","getEncodedValue","input","allowEmptyString","length","str","Array","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","refreshIntervalQueryConfig","refresh","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useSetTimeRangeParams","enabledURLParams","setQuery","paramsLoaded","setParamsLoaded","timeRangeState","setTimeRangeState","undefined","setTimeRange","value","timeRange","useInitialRefreshInterval","getRefreshIntervalInMs","refreshInterval","refreshIntervalInMs","refreshIntervalDuration","seconds","useSetRefreshIntervalParams","initialRefreshInterval","refreshIntervalState","setRefreshIntervalState","setRefreshInterval"],"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,SAASA,OAAO,EAAEC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAClE,SAASC,cAAc,QAA0B,kBAAkB,CAAC;AACpE,SAASC,WAAW,EAAEC,MAAM,QAAQ,UAAU,CAAC;AAC/C,SAEEC,mBAAmB,EACnBC,gBAAgB,EAGhBC,mBAAmB,QACd,kBAAkB,CAAC;AAK1B,iGAAiG,GACjG,SAASC,eAAe,CACtBC,KAAuD,EACvDC,gBAA0B,EACC;IAC3B,IAAID,KAAK,IAAI,IAAI,EAAE;QACjB,OAAOA,KAAK,CAAC;IACf,CAAC;IACD,WAAW;IACX,IAAIA,KAAK,CAACE,MAAM,KAAK,CAAC,IAAK,CAAA,CAACD,gBAAgB,IAAKA,gBAAgB,IAAID,KAAK,KAAK,EAAE,AAAC,CAAA,AAAC,EAAE;QACnF,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAMG,GAAG,GAAGH,KAAK,YAAYI,KAAK,GAAGJ,KAAK,CAAC,CAAC,CAAC,GAAGA,K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M,sBAAsB,CAAC;KACpE,CAAC;AACJ,CAAC"}
@@ -1,7 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { VariableName, VariableValue } from '@perses-dev/core';
3
3
  import { VariableOption } from '../model';
4
- export declare const DEFAULT_ALL_VALUE: "$__all";
5
4
  export declare type VariableState = {
6
5
  value: VariableValue;
7
6
  options?: VariableOption[];
@@ -1 +1 @@
1
- {"version":3,"file":"template-variables.d.ts","sourceRoot":"","sources":["../../src/runtime/template-variables.ts"],"names":[],"mappings":";AAcA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,eAAO,MAAM,iBAAiB,UAAoB,CAAC;AAEnD,oBAAY,aAAa,GAAG;IAC1B,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEF,oBAAY,gBAAgB,GAAG,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;AAEnE,oBAAY,mBAAmB,GAAG;IAChC,KAAK,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,uBAAuB,0DAA4D,CAAC;AAUjG,wBAAgB,yBAAyB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,oBAmBzD;AAGD,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKvF"}
1
+ {"version":3,"file":"template-variables.d.ts","sourceRoot":"","sources":["../../src/runtime/template-variables.ts"],"names":[],"mappings":";AAcA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG1C,oBAAY,aAAa,GAAG;IAC1B,KAAK,EAAE,aAAa,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,EAAE,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAEF,oBAAY,gBAAgB,GAAG,MAAM,CAAC,YAAY,EAAE,aAAa,CAAC,CAAC;AAEnE,oBAAY,mBAAmB,GAAG;IAChC,KAAK,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,uBAAuB,0DAA4D,CAAC;AAUjG,wBAAgB,yBAAyB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,oBAmBzD;AAGD,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKvF"}
@@ -12,7 +12,6 @@
12
12
  // limitations under the License.
13
13
  import { createContext, useContext, useMemo } from 'react';
14
14
  import { parseTemplateVariables, replaceTemplateVariables } from '../utils';
15
- export const DEFAULT_ALL_VALUE = '$__all';
16
15
  export const TemplateVariableContext = createContext(undefined);
17
16
  function useTemplateVariableContext() {
18
17
  const ctx = useContext(TemplateVariableContext);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/template-variables.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\nimport { createContext, useContext, useMemo } from 'react';\nimport { VariableName, VariableValue } from '@perses-dev/core';\nimport { VariableOption } from '../model';\nimport { parseTemplateVariables, replaceTemplateVariables } from '../utils';\nexport const DEFAULT_ALL_VALUE = '$__all' as const;\n\nexport type VariableState = {\n value: VariableValue;\n options?: VariableOption[];\n loading: boolean;\n error?: Error;\n};\n\nexport type VariableStateMap = Record<VariableName, VariableState>;\n\nexport type TemplateVariableSrv = {\n state: VariableStateMap;\n};\n\nexport const TemplateVariableContext = createContext<TemplateVariableSrv | undefined>(undefined);\n\nfunction useTemplateVariableContext() {\n const ctx = useContext(TemplateVariableContext);\n if (ctx === undefined) {\n throw new Error('No TemplateVariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useTemplateVariableValues(names?: string[]) {\n const { state } = useTemplateVariableContext();\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = state[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [state, names]);\n\n if (names === undefined) {\n return state;\n }\n\n return values;\n}\n\n// Convenience hook for replacing template variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseTemplateVariables(str) : [];\n const variableValues = useTemplateVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceTemplateVariables(str, variableValues);\n}\n"],"names":["createContext","useContext","useMemo","parseTemplateVariables","replaceTemplateVariables","DEFAULT_ALL_VALUE","TemplateVariableContext","undefined","useTemplateVariableContext","ctx","Error","useTemplateVariableValues","names","state","values","forEach","name","s","useReplaceVariablesInString","str","variablesInString","variableValues"],"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,SAASA,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO,CAAC;AAG3D,SAASC,sBAAsB,EAAEC,wBAAwB,QAAQ,UAAU,CAAC;AAC5E,OAAO,MAAMC,iBAAiB,GAAG,QAAQ,AAAS,CAAC;AAenD,OAAO,MAAMC,uBAAuB,GAAGN,aAAa,CAAkCO,SAAS,CAAC,CAAC;AAE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sources":["../../src/runtime/template-variables.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\nimport { createContext, useContext, useMemo } from 'react';\nimport { VariableName, VariableValue } from '@perses-dev/core';\nimport { VariableOption } from '../model';\nimport { parseTemplateVariables, replaceTemplateVariables } from '../utils';\n\nexport type VariableState = {\n value: VariableValue;\n options?: VariableOption[];\n loading: boolean;\n error?: Error;\n};\n\nexport type VariableStateMap = Record<VariableName, VariableState>;\n\nexport type TemplateVariableSrv = {\n state: VariableStateMap;\n};\n\nexport const TemplateVariableContext = createContext<TemplateVariableSrv | undefined>(undefined);\n\nfunction useTemplateVariableContext() {\n const ctx = useContext(TemplateVariableContext);\n if (ctx === undefined) {\n throw new Error('No TemplateVariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useTemplateVariableValues(names?: string[]) {\n const { state } = useTemplateVariableContext();\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = state[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [state, names]);\n\n if (names === undefined) {\n return state;\n }\n\n return values;\n}\n\n// Convenience hook for replacing template variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseTemplateVariables(str) : [];\n const variableValues = useTemplateVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceTemplateVariables(str, variableValues);\n}\n"],"names":["createContext","useContext","useMemo","parseTemplateVariables","replaceTemplateVariables","TemplateVariableContext","undefined","useTemplateVariableContext","ctx","Error","useTemplateVariableValues","names","state","values","forEach","name","s","useReplaceVariablesIn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AAC;IAED,OAAOC,MAAM,CAAC;AAChB,CAAC;AAED,gEAAgE;AAChE,OAAO,SAASI,2BAA2B,CAACC,GAAuB,EAAsB;IACvF,MAAMC,iBAAiB,GAAGD,GAAG,GAAGf,sBAAsB,CAACe,GAAG,CAAC,GAAG,EAAE,AAAC;IACjE,MAAME,cAAc,GAAGV,yBAAyB,CAACS,iBAAiB,CAAC,AAAC;IACpE,IAAI,CAACD,GAAG,EAAE,OAAOZ,SAAS,CAAC;IAC3B,OAAOF,wBAAwB,CAACc,GAAG,EAAEE,cAAc,CAAC,CAAC;AACvD,CAAC"}
@@ -12,7 +12,7 @@ export declare const useTimeSeriesQuery: (definition: TimeSeriesQueryDefinition,
12
12
  /**
13
13
  * Runs multiple time series queries using plugins and returns the results.
14
14
  */
15
- export declare function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions): import("@tanstack/react-query").UseQueryResult<TimeSeriesData, unknown>[];
15
+ export declare function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions): import("@tanstack/react-query").UseQueryResult<unknown, unknown>[];
16
16
  /**
17
17
  * Get active time series queries for query results summary
18
18
  */
@@ -1 +1 @@
1
- {"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAA+C,UAAU,EAAY,MAAM,uBAAuB,CAAC;AAC1G,OAAO,EAAE,yBAAyB,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAiD,MAAM,UAAU,CAAC;AAM9F,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAmDvD;;GAEG;AACH,eAAO,MAAM,kBAAkB,eAAgB,yBAAyB,YAAY,yBAAyB,4EAkB5G,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,yBAAyB,EAAE,EAAE,OAAO,CAAC,EAAE,yBAAyB,6EA0BjH;AAkBD;;GAEG;AACH,wBAAgB,0BAA0B,0BAIzC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,yBAW3D"}
1
+ {"version":3,"file":"time-series-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/time-series-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAKL,UAAU,EAGX,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,yBAAyB,EAAe,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,mBAAmB,EAAiD,MAAM,UAAU,CAAC;AAM9F,MAAM,WAAW,yBAAyB;IACxC,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,eAAO,MAAM,qBAAqB,oBAAoB,CAAC;AAmDvD;;GAEG;AACH,eAAO,MAAM,kBAAkB,eAAgB,yBAAyB,YAAY,yBAAyB,4EAmB5G,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,yBAAyB,EAAE,EAAE,OAAO,CAAC,EAAE,yBAAyB,sEA2BjH;AAmBD;;GAEG;AACH,wBAAgB,0BAA0B,0BAIzC;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,UAAU,yBAW3D"}
@@ -69,6 +69,7 @@ function getQueryOptions({ plugin , definition , context }) {
69
69
  return useQuery({
70
70
  enabled: queryEnabled,
71
71
  queryKey: queryKey,
72
+ refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,
72
73
  queryFn: ()=>{
73
74
  // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking
74
75
  if (plugin === undefined) {
@@ -103,6 +104,7 @@ function getQueryOptions({ plugin , definition , context }) {
103
104
  return {
104
105
  enabled: queryEnabled,
105
106
  queryKey: queryKey,
107
+ refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,
106
108
  queryFn: async ()=>{
107
109
  // Keep options out of query key so we don't re-run queries because suggested step changes
108
110
  const ctx = {
@@ -120,14 +122,15 @@ function getQueryOptions({ plugin , definition , context }) {
120
122
  /**
121
123
  * Build the time series query context object from data available at runtime
122
124
  */ function useTimeSeriesQueryContext() {
123
- const { absoluteTimeRange , refreshKey } = useTimeRange();
125
+ const { absoluteTimeRange , refreshKey , refreshIntervalInMs } = useTimeRange();
124
126
  const variableState = useTemplateVariableValues();
125
127
  const datasourceStore = useDatasourceStore();
126
128
  return {
127
129
  timeRange: absoluteTimeRange,
128
130
  variableState,
129
131
  datasourceStore,
130
- refreshKey
132
+ refreshKey,
133
+ refreshIntervalInMs: refreshIntervalInMs
131
134
  };
132
135
  }
133
136
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/runtime/time-series-queries.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\nimport { useQuery, useQueries, useQueryClient, Query, QueryCache, QueryKey } from '@tanstack/react-query';\nimport { TimeSeriesQueryDefinition, UnknownSpec, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryPlugin } from '../model';\nimport { VariableStateMap, useTemplateVariableValues } from './template-variables';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\n\nexport interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction filterVariableStateMap(v: VariableStateMap, names?: string[]) {\n if (!names) {\n return v;\n }\n return Object.fromEntries(Object.entries(v).filter(([name]) => names.includes(name)));\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}) {\n const { timeRange, datasourceStore, suggestedStepMs, variableState, refreshKey } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n const queryKey = [definition, timeRange, datasourceStore, suggestedStepMs, variablesValueKey, refreshKey] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions) => {\n const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const context = useTimeSeriesQueryContext();\n\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: queryEnabled,\n queryKey: queryKey,\n queryFn: () => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions) {\n const { getPlugin } = usePluginRegistry();\n const context = useTimeSeriesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\n definitions.map((d) => ({ kind: d.spec.plugin.kind }))\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n queryFn: async () => {\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n return data;\n },\n };\n }),\n });\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange, refreshKey } = useTimeRange();\n const variableState = useTemplateVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n refreshKey,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries() {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache) {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQuery","useQueries","useQueryClient","useTemplateVariableValues","useTimeRange","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","TIME_SERIES_QUERY_KEY","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","filterVariableStateMap","names","fromEntries","entries","filter","name","includes","getQueryOptions","plugin","definition","context","timeRange","datasourceStore","suggestedStepMs","variableState","refreshKey","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","loading","queryEnabled","undefined","useTimeSeriesQuery","options","data","kind","useTimeSeriesQueryContext","enabled","queryFn","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","d","queries","idx","absoluteTimeRange","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","push"],"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,SAASA,QAAQ,EAAEC,UAAU,EAAEC,cAAc,QAAqC,uBAAuB,CAAC;AAG1G,SAA2BC,yBAAyB,QAAQ,sBAAsB,CAAC;AACnF,SAASC,YAAY,QAAQ,qBAAqB,CAAC;AACnD,SAASC,kBAAkB,QAAQ,eAAe,CAAC;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,mBAAmB,CAAC;AAM7E,OAAO,MAAMC,qBAAqB,GAAG,iBAAiB,CAAC;AAEvD;;CAEC,GACD,SAASC,oBAAoB,CAACC,CAAmB,EAAE;IACjD,OAAOC,MAAM,CAACC,MAAM,CAACF,CAAC,CAAC,CACpBG,GAAG,CAAC,CAACH,CAAC,G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AAGH,CAAAA,GAAc,GAAdA,KAAK,CAAC9B,QAAQ,cAAd8B,GAAc,WAAK,GAAnBA,KAAAA,CAAmB,GAAnBA,GAAc,AAAE,CAAC,CAAC,CAAC,AAAe,AAAC;QACrD,IAAIG,CAAAA,SAAS,aAATA,SAAS,WAAM,GAAfA,KAAAA,CAAe,GAAfA,SAAS,CAAExB,IAAI,CAAA,IAAI,AAACwB,SAAS,CAACxB,IAAI,CAAYyB,UAAU,CAACnE,qBAAqB,CAAC,EAAE;YACnFsD,OAAO,CAACc,IAAI,CAACL,KAAK,CAA6D,CAAC;QAClF,CAAC;IACH,CAAC;IAED,OAAOT,OAAO,CAAC;AACjB,CAAC"}
1
+ {"version":3,"sources":["../../src/runtime/time-series-queries.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\nimport {\n useQuery,\n useQueries,\n useQueryClient,\n Query,\n QueryCache,\n QueryKey,\n QueryObserverOptions,\n} from '@tanstack/react-query';\nimport { TimeSeriesQueryDefinition, UnknownSpec, TimeSeriesData } from '@perses-dev/core';\nimport { TimeSeriesDataQuery, TimeSeriesQueryContext, TimeSeriesQueryPlugin } from '../model';\nimport { VariableStateMap, useTemplateVariableValues } from './template-variables';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePluginRegistry, usePlugins } from './plugin-registry';\n\nexport interface UseTimeSeriesQueryOptions {\n suggestedStepMs?: number;\n}\n\nexport const TIME_SERIES_QUERY_KEY = 'TimeSeriesQuery';\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction filterVariableStateMap(v: VariableStateMap, names?: string[]) {\n if (!names) {\n return v;\n }\n return Object.fromEntries(Object.entries(v).filter(([name]) => names.includes(name)));\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: TimeSeriesQueryPlugin;\n definition: TimeSeriesQueryDefinition;\n context: TimeSeriesQueryContext;\n}) {\n const { timeRange, datasourceStore, suggestedStepMs, variableState, refreshKey } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n // Determine queryKey\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n const queryKey = [definition, timeRange, datasourceStore, suggestedStepMs, variablesValueKey, refreshKey] as const;\n\n // Determine queryEnabled\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n\n return {\n queryKey,\n queryEnabled,\n };\n}\n\n/**\n * Runs a time series query using a plugin and returns the results.\n */\nexport const useTimeSeriesQuery = (definition: TimeSeriesQueryDefinition, options?: UseTimeSeriesQueryOptions) => {\n const { data: plugin } = usePlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const context = useTimeSeriesQueryContext();\n\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return useQuery({\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,\n queryFn: () => {\n // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking\n if (plugin === undefined) {\n throw new Error('Expected plugin to be loaded');\n }\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n },\n });\n};\n\n/**\n * Runs multiple time series queries using plugins and returns the results.\n */\nexport function useTimeSeriesQueries(definitions: TimeSeriesQueryDefinition[], options?: UseTimeSeriesQueryOptions) {\n const { getPlugin } = usePluginRegistry();\n const context = useTimeSeriesQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n TIME_SERIES_QUERY_KEY,\n definitions.map((d) => ({ kind: d.spec.plugin.kind }))\n );\n\n return useQueries({\n queries: definitions.map<QueryObserverOptions>((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ plugin, definition, context });\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchInterval: context.refreshIntervalInMs > 0 ? context.refreshIntervalInMs : false,\n queryFn: async () => {\n // Keep options out of query key so we don't re-run queries because suggested step changes\n const ctx: TimeSeriesQueryContext = { ...context, suggestedStepMs: options?.suggestedStepMs };\n const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);\n const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);\n return data;\n },\n };\n }),\n });\n}\n\n/**\n * Build the time series query context object from data available at runtime\n */\nfunction useTimeSeriesQueryContext(): TimeSeriesQueryContext {\n const { absoluteTimeRange, refreshKey, refreshIntervalInMs } = useTimeRange();\n const variableState = useTemplateVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n timeRange: absoluteTimeRange,\n variableState,\n datasourceStore,\n refreshKey,\n refreshIntervalInMs: refreshIntervalInMs,\n };\n}\n\n/**\n * Get active time series queries for query results summary\n */\nexport function useActiveTimeSeriesQueries() {\n const queryClient = useQueryClient();\n const queryCache = queryClient.getQueryCache();\n return getActiveTimeSeriesQueries(queryCache);\n}\n\n/**\n * Filter all cached queries down to only active time series queries\n */\nexport function getActiveTimeSeriesQueries(cache: QueryCache) {\n const queries: TimeSeriesDataQuery[] = [];\n\n for (const query of cache.findAll({ type: 'active' })) {\n const firstPart = query.queryKey?.[0] as UnknownSpec;\n if (firstPart?.kind && (firstPart.kind as string).startsWith(TIME_SERIES_QUERY_KEY)) {\n queries.push(query as Query<TimeSeriesData, unknown, TimeSeriesData, QueryKey>);\n }\n }\n\n return queries;\n}\n"],"names":["useQuery","useQueries","useQueryClient","useTemplateVariableValues","useTimeRange","useDatasourceStore","usePlugin","usePluginRegistry","usePlugins","TIME_SERIES_QUERY_KEY","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","filterVariableStateMap","names","fromEntries","entries","filter","name","includes","getQueryOptions","plugin","definition","context","timeRange","datasourceStore","suggestedStepMs","variableState","refreshKey","dependencies","dependsOn","spec","variableDependencies","variables","filteredVariabledState","variablesValueKey","queryKey","waitToLoad","some","loading","queryEnabled","undefined","useTimeSeriesQuery","options","data","kind","useTimeSeriesQueryContext","enabled","refetchInterval","refreshIntervalInMs","queryFn","Error","ctx","getTimeSeriesData","useTimeSeriesQueries","definitions","getPlugin","pluginLoaderResponse","d","queries","idx","absoluteTimeRange","useActiveTimeSeriesQueries","queryClient","queryCache","getQueryCache","getActiveTimeSeriesQueries","cache","query","findAll","type","firstPart","startsWith","push"],"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,SACEA,QAAQ,EACRC,UAAU,EACVC,cAAc,QAKT,uBAAuB,CAAC;AAG/B,SAA2BC,yBAAyB,QAAQ,sBAAsB,CAAC;AACnF,SAASC,YAAY,QAAQ,qBAAqB,CAAC;AACnD,SAASC,kBAAkB,QAAQ,eAAe,CAAC;AACnD,SAASC,SAAS,EAAEC,iBAAiB,EAAEC,UAAU,QAAQ,mBAAmB,CAAC;AAM7E,OAAO,MAAMC,qBAAqB,GAAG,iBAAiB,CAAC;AAEvD;;CAE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AW,GAAGnE,cAAc,EAAE,AAAC;IACrC,MAAMoE,UAAU,GAAGD,WAAW,CAACE,aAAa,EAAE,AAAC;IAC/C,OAAOC,0BAA0B,CAACF,UAAU,CAAC,CAAC;AAChD,CAAC;AAED;;CAEC,GACD,OAAO,SAASE,0BAA0B,CAACC,KAAiB,EAAE;IAC5D,MAAMR,OAAO,GAA0B,EAAE,AAAC;IAE1C,KAAK,MAAMS,KAAK,IAAID,KAAK,CAACE,OAAO,CAAC;QAAEC,IAAI,EAAE,QAAQ;KAAE,CAAC,CAAE;YACnCF,GAAc;QAAhC,MAAMG,SAAS,GAAGH,CAAAA,GAAc,GAAdA,KAAK,CAAChC,QAAQ,cAAdgC,GAAc,WAAK,GAAnBA,KAAAA,CAAmB,GAAnBA,GAAc,AAAE,CAAC,CAAC,CAAC,AAAe,AAAC;QACrD,IAAIG,CAAAA,SAAS,aAATA,SAAS,WAAM,GAAfA,KAAAA,CAAe,GAAfA,SAAS,CAAE1B,IAAI,CAAA,IAAI,AAAC0B,SAAS,CAAC1B,IAAI,CAAY2B,UAAU,CAACrE,qBAAqB,CAAC,EAAE;YACnFwD,OAAO,CAACc,IAAI,CAACL,KAAK,CAA6D,CAAC;QAClF,CAAC;IACH,CAAC;IAED,OAAOT,OAAO,CAAC;AACjB,CAAC"}
@@ -21,6 +21,7 @@ export const WithTimeRange = (Story, context)=>{
21
21
  const parameter = isWithTimeRangeParameter(initParameter) ? initParameter : undefined;
22
22
  const props = parameter === null || parameter === void 0 ? void 0 : parameter.props;
23
23
  return /*#__PURE__*/ _jsx(TimeRangeProvider, {
24
+ initialRefreshInterval: "0s",
24
25
  initialTimeRange: {
25
26
  pastDuration: '1h'
26
27
  },
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/stories/shared-utils/decorators/WithTimeRange.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 { StoryFn, StoryContext } from '@storybook/react';\nimport { TimeRangeProvider, TimeRangeProviderProps } from '@perses-dev/plugin-system';\n\ndeclare module '@storybook/react' {\n interface Parameters {\n withTimeRange?: WithTimeRangeParameter;\n }\n}\n\nexport type WithTimeRangeParameter = {\n props: Partial<TimeRangeProviderProps>;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithTimeRangeParameter(parameter: unknown | WithTimeRangeParameter): parameter is WithTimeRangeParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithTimeRange = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.withTimeRange;\n const parameter = isWithTimeRangeParameter(initParameter) ? initParameter : undefined;\n const props = parameter?.props;\n\n return (\n <TimeRangeProvider initialTimeRange={{ pastDuration: '1h' }} {...props}>\n <Story />\n </TimeRangeProvider>\n );\n};\n"],"names":["TimeRangeProvider","isWithTimeRangeParameter","parameter","WithTimeRange","Story","context","initParameter","parameters","withTimeRange","undefined","props","initialTimeRange","pastDuration"],"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;AACA,SAASA,iBAAiB,QAAgC,2BAA2B,CAAC;AAYtF,yDAAyD;AACzD,SAASC,wBAAwB,CAACC,SAA2C,EAAuC;IAClH,OAAO,CAAC,CAACA,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,OAAO,IAAIA,SAAS,CAAC;AAC9E,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG,CAACC,KAAc,EAAEC,OAA8B,GAAK;IAC/E,MAAMC,aAAa,GAAGD,OAAO,CAACE,UAAU,CAACC,aAAa,AAAC;IACvD,MAAMN,SAAS,GAAGD,wBAAwB,CAACK,aAAa,CAAC,GAAGA,aAAa,GAAGG,SAAS,AAAC;IACtF,MAAMC,KAAK,GAAGR,SAAS,aAATA,SAAS,WAAO,GAAhBA,KAAAA,CAAgB,GAAhBA,SAAS,CAAEQ,KAAK,AAAC;IAE/B,qBACE,KAACV,iBAAiB;QAACW,gBAAgB,EAAE;YAAEC,YAAY,EAAE,IAAI;SAAE;QAAG,GAAGF,KAAK;kBACpE,cAAA,KAACN,KAAK,KAAG;MACS,CACpB;AACJ,CAAC,CAAC"}
1
+ {"version":3,"sources":["../../../../src/stories/shared-utils/decorators/WithTimeRange.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 { StoryFn, StoryContext } from '@storybook/react';\nimport { TimeRangeProvider, TimeRangeProviderProps } from '@perses-dev/plugin-system';\n\ndeclare module '@storybook/react' {\n interface Parameters {\n withTimeRange?: WithTimeRangeParameter;\n }\n}\n\nexport type WithTimeRangeParameter = {\n props: Partial<TimeRangeProviderProps>;\n};\n\n// Type guard because storybook types parameters as `any`\nfunction isWithTimeRangeParameter(parameter: unknown | WithTimeRangeParameter): parameter is WithTimeRangeParameter {\n return !!parameter && typeof parameter === 'object' && 'props' in parameter;\n}\n\nexport const WithTimeRange = (Story: StoryFn, context: StoryContext<unknown>) => {\n const initParameter = context.parameters.withTimeRange;\n const parameter = isWithTimeRangeParameter(initParameter) ? initParameter : undefined;\n const props = parameter?.props;\n\n return (\n <TimeRangeProvider initialRefreshInterval=\"0s\" initialTimeRange={{ pastDuration: '1h' }} {...props}>\n <Story />\n </TimeRangeProvider>\n );\n};\n"],"names":["TimeRangeProvider","isWithTimeRangeParameter","parameter","WithTimeRange","Story","context","initParameter","parameters","withTimeRange","undefined","props","initialRefreshInterval","initialTimeRange","pastDuration"],"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;AACA,SAASA,iBAAiB,QAAgC,2BAA2B,CAAC;AAYtF,yDAAyD;AACzD,SAASC,wBAAwB,CAACC,SAA2C,EAAuC;IAClH,OAAO,CAAC,CAACA,SAAS,IAAI,OAAOA,SAAS,KAAK,QAAQ,IAAI,OAAO,IAAIA,SAAS,CAAC;AAC9E,CAAC;AAED,OAAO,MAAMC,aAAa,GAAG,CAACC,KAAc,EAAEC,OAA8B,GAAK;IAC/E,MAAMC,aAAa,GAAGD,OAAO,CAACE,UAAU,CAACC,aAAa,AAAC;IACvD,MAAMN,SAAS,GAAGD,wBAAwB,CAACK,aAAa,CAAC,GAAGA,aAAa,GAAGG,SAAS,AAAC;IACtF,MAAMC,KAAK,GAAGR,SAAS,aAATA,SAAS,WAAO,GAAhBA,KAAAA,CAAgB,GAAhBA,SAAS,CAAEQ,KAAK,AAAC;IAE/B,qBACE,KAACV,iBAAiB;QAACW,sBAAsB,EAAC,IAAI;QAACC,gBAAgB,EAAE;YAAEC,YAAY,EAAE,IAAI;SAAE;QAAG,GAAGH,KAAK;kBAChG,cAAA,KAACN,KAAK,KAAG;MACS,CACpB;AACJ,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/plugin-system",
3
- "version": "0.35.0",
3
+ "version": "0.36.1",
4
4
  "description": "The plugin feature in Pereses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -28,14 +28,14 @@
28
28
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
29
29
  },
30
30
  "dependencies": {
31
- "@perses-dev/components": "0.35.0",
32
- "@perses-dev/core": "0.35.0",
31
+ "@perses-dev/components": "0.36.1",
32
+ "@perses-dev/core": "0.36.1",
33
33
  "immer": "^9.0.15",
34
34
  "use-immer": "^0.7.0",
35
35
  "use-query-params": "^2.1.2"
36
36
  },
37
37
  "devDependencies": {
38
- "@perses-dev/storybook": "0.35.0"
38
+ "@perses-dev/storybook": "0.36.1"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@mui/material": "^5.10.0",