@perses-dev/dashboards 0.17.0 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +49 -32
  2. package/dist/cjs/components/GridLayout/GridContainer.js +2 -2
  3. package/dist/cjs/components/GridLayout/GridTitle.js +1 -1
  4. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +2 -1
  5. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +28 -5
  6. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +11 -5
  7. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +17 -2
  8. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +5 -4
  9. package/dist/cjs/components/Variables/VariableList.js +3 -0
  10. package/dist/cjs/components/Variables/variable-model.js +38 -6
  11. package/dist/cjs/components/Variables/variable-model.test.js +106 -0
  12. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +0 -2
  13. package/dist/cjs/context/TemplateVariableProvider/query-params.js +3 -1
  14. package/dist/cjs/context/index.js +0 -1
  15. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  16. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +6 -4
  17. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +4 -2
  18. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
  19. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  20. package/dist/components/DashboardToolbar/DashboardToolbar.js +50 -33
  21. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  22. package/dist/components/GridLayout/GridContainer.js +2 -2
  23. package/dist/components/GridLayout/GridContainer.js.map +1 -1
  24. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  25. package/dist/components/GridLayout/GridTitle.js +1 -1
  26. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  27. package/dist/components/PanelDrawer/PanelDrawer.js +2 -1
  28. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  29. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  30. package/dist/components/TimeRangeControls/TimeRangeControls.js +24 -7
  31. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  32. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +11 -5
  33. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  34. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  35. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +17 -2
  36. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  37. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +1 -0
  38. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  39. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +5 -4
  40. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  41. package/dist/components/Variables/VariableList.d.ts +2 -0
  42. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  43. package/dist/components/Variables/VariableList.js +3 -0
  44. package/dist/components/Variables/VariableList.js.map +1 -1
  45. package/dist/components/Variables/variable-model.d.ts +3 -2
  46. package/dist/components/Variables/variable-model.d.ts.map +1 -1
  47. package/dist/components/Variables/variable-model.js +38 -7
  48. package/dist/components/Variables/variable-model.js.map +1 -1
  49. package/dist/components/Variables/variable-model.test.d.ts +2 -0
  50. package/dist/components/Variables/variable-model.test.d.ts.map +1 -0
  51. package/dist/components/Variables/variable-model.test.js +104 -0
  52. package/dist/components/Variables/variable-model.test.js.map +1 -0
  53. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  54. package/dist/context/DashboardProvider/panel-editor-slice.js +0 -2
  55. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  56. package/dist/context/TemplateVariableProvider/query-params.js +3 -1
  57. package/dist/context/TemplateVariableProvider/query-params.js.map +1 -1
  58. package/dist/context/index.d.ts +0 -1
  59. package/dist/context/index.d.ts.map +1 -1
  60. package/dist/context/index.js +0 -1
  61. package/dist/context/index.js.map +1 -1
  62. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
  63. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  64. package/dist/views/ViewDashboard/DashboardApp.js +2 -1
  65. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  66. package/dist/views/ViewDashboard/ViewDashboard.d.ts +1 -0
  67. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  68. package/dist/views/ViewDashboard/ViewDashboard.js +5 -3
  69. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  70. package/dist/views/ViewDashboard/tests/panelGroups.test.js +4 -2
  71. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  72. package/package.json +5 -5
  73. package/dist/cjs/context/TimeRangeProvider/TimeRangeProvider.js +0 -91
  74. package/dist/cjs/context/TimeRangeProvider/index.js +0 -29
  75. package/dist/cjs/context/TimeRangeProvider/query-params.js +0 -157
  76. package/dist/context/TimeRangeProvider/TimeRangeProvider.d.ts +0 -19
  77. package/dist/context/TimeRangeProvider/TimeRangeProvider.d.ts.map +0 -1
  78. package/dist/context/TimeRangeProvider/TimeRangeProvider.js +0 -44
  79. package/dist/context/TimeRangeProvider/TimeRangeProvider.js.map +0 -1
  80. package/dist/context/TimeRangeProvider/index.d.ts +0 -3
  81. package/dist/context/TimeRangeProvider/index.d.ts.map +0 -1
  82. package/dist/context/TimeRangeProvider/index.js +0 -16
  83. package/dist/context/TimeRangeProvider/index.js.map +0 -1
  84. package/dist/context/TimeRangeProvider/query-params.d.ts +0 -25
  85. package/dist/context/TimeRangeProvider/query-params.d.ts.map +0 -1
  86. package/dist/context/TimeRangeProvider/query-params.js +0 -149
  87. package/dist/context/TimeRangeProvider/query-params.js.map +0 -1
@@ -1,157 +0,0 @@
1
- // Copyright 2022 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- "use strict";
14
- Object.defineProperty(exports, "__esModule", {
15
- value: true
16
- });
17
- function _export(target, all) {
18
- for(var name in all)Object.defineProperty(target, name, {
19
- enumerable: true,
20
- get: all[name]
21
- });
22
- }
23
- _export(exports, {
24
- encodeTimeRangeValue: ()=>encodeTimeRangeValue,
25
- decodeTimeRangeValue: ()=>decodeTimeRangeValue,
26
- TimeRangeParam: ()=>TimeRangeParam,
27
- timeRangeQueryConfig: ()=>timeRangeQueryConfig,
28
- useInitialTimeRange: ()=>useInitialTimeRange,
29
- useSetTimeRangeParams: ()=>useSetTimeRangeParams
30
- });
31
- const _react = require("react");
32
- const _useQueryParams = require("use-query-params");
33
- const _dateFns = require("date-fns");
34
- const _core = require("@perses-dev/core");
35
- /* Interprets an encoded string and returns either the string or null/undefined if not available */ function getEncodedValue(input, allowEmptyString) {
36
- if (input == null) {
37
- return input;
38
- }
39
- // '' or []
40
- if (input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
41
- return null;
42
- }
43
- const str = input instanceof Array ? input[0] : input;
44
- if (str == null) {
45
- return str;
46
- }
47
- if (!allowEmptyString && str === '') {
48
- return null;
49
- }
50
- return str;
51
- }
52
- function encodeTimeRangeValue(timeOptionValue) {
53
- if (!timeOptionValue) {
54
- return timeOptionValue;
55
- }
56
- if (typeof timeOptionValue === 'string') {
57
- if ((0, _core.isDurationString)(timeOptionValue)) {
58
- return timeOptionValue;
59
- }
60
- }
61
- return ((0, _dateFns.getUnixTime)(timeOptionValue) * 1000).toString();
62
- }
63
- function decodeTimeRangeValue(input) {
64
- const paramString = getEncodedValue(input);
65
- if (paramString == null) return paramString;
66
- return (0, _core.isDurationString)(paramString) ? paramString : new Date(Number(paramString));
67
- }
68
- const TimeRangeParam = {
69
- encode: encodeTimeRangeValue,
70
- decode: decodeTimeRangeValue,
71
- equals: (valueA, valueB)=>{
72
- if (valueA === valueB) return true;
73
- if (valueA == null || valueB == null) return valueA === valueB;
74
- return valueA.valueOf() === valueB.valueOf();
75
- }
76
- };
77
- const timeRangeQueryConfig = {
78
- start: TimeRangeParam,
79
- end: TimeRangeParam
80
- };
81
- function useInitialTimeRange(dashboardDuration) {
82
- const [query] = (0, _useQueryParams.useQueryParams)(timeRangeQueryConfig);
83
- const { start , end } = query;
84
- return (0, _react.useMemo)(()=>{
85
- let initialTimeRange = {
86
- pastDuration: dashboardDuration
87
- };
88
- if (!start) {
89
- return initialTimeRange;
90
- }
91
- const startStr = start.toString();
92
- if ((0, _core.isDurationString)(startStr)) {
93
- initialTimeRange = {
94
- pastDuration: startStr
95
- };
96
- } else if ((0, _dateFns.isDate)(start) && (0, _dateFns.isDate)(end)) {
97
- initialTimeRange = {
98
- start: start,
99
- end: end
100
- };
101
- }
102
- return initialTimeRange;
103
- }, [
104
- start,
105
- end,
106
- dashboardDuration
107
- ]);
108
- }
109
- function useSetTimeRangeParams(initialTimeRange, enabledURLParams = true) {
110
- const [query, setQuery] = (0, _useQueryParams.useQueryParams)(timeRangeQueryConfig);
111
- // determine whether initial param had previously been populated to fix back btn
112
- const [paramsLoaded, setParamsLoaded] = (0, _react.useState)(false);
113
- // optional fallback when app does not want query string as source of truth
114
- // this occurs when enabledURLParams is set to false on TimeRangeProvider
115
- const [timeRangeState, setTimeRangeState] = (0, _react.useState)(initialTimeRange);
116
- const { start } = query;
117
- (0, _react.useEffect)(()=>{
118
- // when dashboard loaded with no params, default to dashboard duration
119
- if (enabledURLParams && !paramsLoaded && !start) {
120
- if ((0, _core.isRelativeTimeRange)(initialTimeRange)) {
121
- setQuery({
122
- start: initialTimeRange.pastDuration,
123
- end: undefined
124
- });
125
- setParamsLoaded(true);
126
- }
127
- }
128
- }, [
129
- initialTimeRange,
130
- enabledURLParams,
131
- paramsLoaded,
132
- start,
133
- setQuery
134
- ]);
135
- const setTimeRange = (0, _react.useCallback)((value)=>{
136
- if ((0, _core.isRelativeTimeRange)(value)) {
137
- setQuery({
138
- start: value.pastDuration,
139
- end: undefined
140
- });
141
- } else {
142
- setQuery(value);
143
- }
144
- }, [
145
- setQuery
146
- ]);
147
- if (!enabledURLParams) {
148
- return {
149
- timeRange: timeRangeState,
150
- setTimeRange: setTimeRangeState
151
- };
152
- }
153
- return {
154
- timeRange: initialTimeRange,
155
- setTimeRange: setTimeRange
156
- };
157
- }
@@ -1,19 +0,0 @@
1
- import React from 'react';
2
- import { TimeRangeValue } from '@perses-dev/core';
3
- export interface TimeRangeProviderProps {
4
- initialTimeRange: TimeRangeValue;
5
- enabledURLParams?: boolean;
6
- children?: React.ReactNode;
7
- }
8
- /**
9
- * Provider implementation that supplies the time range state at runtime.
10
- */
11
- export declare function TimeRangeProvider(props: TimeRangeProviderProps): JSX.Element;
12
- /**
13
- * Internal version of time range hook to get all supported values
14
- */
15
- export declare function useDashboardTimeRange(): {
16
- timeRange: TimeRangeValue;
17
- setTimeRange: (value: TimeRangeValue) => void;
18
- };
19
- //# sourceMappingURL=TimeRangeProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../../src/context/TimeRangeProvider/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAkB,MAAM,OAAO,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAIlD,MAAM,WAAW,sBAAsB;IACrC,gBAAgB,EAAE,cAAc,CAAC;IACjC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eAc9D;AAED;;GAEG;AACH,wBAAgB,qBAAqB;;;EAGpC"}
@@ -1,44 +0,0 @@
1
- // Copyright 2022 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
- import React, { useMemo } from 'react';
15
- import { TimeRangeContext, useTimeRangeContext } from '@perses-dev/plugin-system';
16
- import { useSetTimeRangeParams } from './query-params';
17
- /**
18
- * Provider implementation that supplies the time range state at runtime.
19
- */ export function TimeRangeProvider(props) {
20
- const { initialTimeRange , enabledURLParams , children } = props;
21
- const { timeRange , setTimeRange } = useSetTimeRangeParams(initialTimeRange, enabledURLParams);
22
- const ctx = useMemo(()=>({
23
- timeRange,
24
- setTimeRange
25
- }), [
26
- timeRange,
27
- setTimeRange
28
- ]);
29
- return /*#__PURE__*/ _jsx(TimeRangeContext.Provider, {
30
- value: ctx,
31
- children: children
32
- });
33
- }
34
- /**
35
- * Internal version of time range hook to get all supported values
36
- */ export function useDashboardTimeRange() {
37
- const { timeRange , setTimeRange } = useTimeRangeContext();
38
- return {
39
- timeRange,
40
- setTimeRange
41
- };
42
- }
43
-
44
- //# sourceMappingURL=TimeRangeProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/context/TimeRangeProvider/TimeRangeProvider.tsx"],"sourcesContent":["// Copyright 2022 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 } from 'react';\nimport { TimeRangeValue } from '@perses-dev/core';\nimport { TimeRangeContext, useTimeRangeContext } from '@perses-dev/plugin-system';\nimport { useSetTimeRangeParams } from './query-params';\n\nexport interface TimeRangeProviderProps {\n initialTimeRange: TimeRangeValue;\n enabledURLParams?: boolean;\n children?: React.ReactNode;\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 ctx = useMemo(\n () => ({\n timeRange,\n setTimeRange,\n }),\n [timeRange, setTimeRange]\n );\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n\n/**\n * Internal version of time range hook to get all supported values\n */\nexport function useDashboardTimeRange() {\n const { timeRange, setTimeRange } = useTimeRangeContext();\n return { timeRange, setTimeRange };\n}\n"],"names":["React","useMemo","TimeRangeContext","useTimeRangeContext","useSetTimeRangeParams","TimeRangeProvider","props","initialTimeRange","enabledURLParams","children","timeRange","setTimeRange","ctx","Provider","value","useDashboardTimeRange"],"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,QAAQ,OAAO,CAAC;AAEvC,SAASC,gBAAgB,EAAEC,mBAAmB,QAAQ,2BAA2B,CAAC;AAClF,SAASC,qBAAqB,QAAQ,gBAAgB,CAAC;AAQvD;;CAEC,GACD,OAAO,SAASC,iBAAiB,CAACC,KAA6B,EAAE;IAC/D,MAAM,EAAEC,gBAAgB,CAAA,EAAEC,gBAAgB,CAAA,EAAEC,QAAQ,CAAA,EAAE,GAAGH,KAAK,AAAC;IAE/D,MAAM,EAAEI,SAAS,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGP,qBAAqB,CAACG,gBAAgB,EAAEC,gBAAgB,CAAC,AAAC;IAE9F,MAAMI,GAAG,GAAGX,OAAO,CACjB,IAAO,CAAA;YACLS,SAAS;YACTC,YAAY;SACb,CAAA,AAAC,EACF;QAACD,SAAS;QAAEC,YAAY;KAAC,CAC1B,AAAC;IAEF,qBAAO,KAACT,gBAAgB,CAACW,QAAQ;QAACC,KAAK,EAAEF,GAAG;kBAAGH,QAAQ;MAA6B,CAAC;AACvF,CAAC;AAED;;CAEC,GACD,OAAO,SAASM,qBAAqB,GAAG;IACtC,MAAM,EAAEL,SAAS,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGR,mBAAmB,EAAE,AAAC;IAC1D,OAAO;QAAEO,SAAS;QAAEC,YAAY;KAAE,CAAC;AACrC,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from './TimeRangeProvider';
2
- export * from './query-params';
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/TimeRangeProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
@@ -1,16 +0,0 @@
1
- // Copyright 2022 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- export * from './TimeRangeProvider';
14
- export * from './query-params';
15
-
16
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/context/TimeRangeProvider/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './TimeRangeProvider';\nexport * from './query-params';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
@@ -1,25 +0,0 @@
1
- import { QueryParamConfig } from 'use-query-params';
2
- import { TimeRangeValue, DurationString } from '@perses-dev/core';
3
- import { TimeRange } from '@perses-dev/plugin-system';
4
- export declare type TimeOptionValue = Date | DurationString | null | undefined;
5
- export declare function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined;
6
- export declare function decodeTimeRangeValue(input: string | Array<string | null> | null | undefined): Date | DurationString | null | undefined;
7
- /**
8
- * Custom TimeRangeValue param type
9
- * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types
10
- */
11
- export declare const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue>;
12
- export declare const timeRangeQueryConfig: {
13
- start: QueryParamConfig<TimeOptionValue, TimeOptionValue>;
14
- end: QueryParamConfig<TimeOptionValue, TimeOptionValue>;
15
- };
16
- /**
17
- * Gets the initial time range taking into account URL params and dashboard JSON duration
18
- * Sets start query param if it is empty on page load
19
- */
20
- export declare function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue;
21
- /**
22
- * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization
23
- */
24
- export declare function useSetTimeRangeParams(initialTimeRange: TimeRangeValue, enabledURLParams?: boolean): TimeRange;
25
- //# sourceMappingURL=query-params.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/context/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,2BAA2B,CAAC;AAEtD,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,CAAC,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,UAAO,GAAG,SAAS,CAqC1G"}
@@ -1,149 +0,0 @@
1
- // Copyright 2022 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { useMemo, useCallback, useEffect, useState } from 'react';
14
- import { useQueryParams } from 'use-query-params';
15
- import { getUnixTime, isDate } from 'date-fns';
16
- import { isRelativeTimeRange, isDurationString } from '@perses-dev/core';
17
- /* Interprets an encoded string and returns either the string or null/undefined if not available */ function getEncodedValue(input, allowEmptyString) {
18
- if (input == null) {
19
- return input;
20
- }
21
- // '' or []
22
- if (input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
23
- return null;
24
- }
25
- const str = input instanceof Array ? input[0] : input;
26
- if (str == null) {
27
- return str;
28
- }
29
- if (!allowEmptyString && str === '') {
30
- return null;
31
- }
32
- return str;
33
- }
34
- /* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */ export function encodeTimeRangeValue(timeOptionValue) {
35
- if (!timeOptionValue) {
36
- return timeOptionValue;
37
- }
38
- if (typeof timeOptionValue === 'string') {
39
- if (isDurationString(timeOptionValue)) {
40
- return timeOptionValue;
41
- }
42
- }
43
- return (getUnixTime(timeOptionValue) * 1000).toString();
44
- }
45
- /* Converts param input to supported relative or absolute time range format */ export function decodeTimeRangeValue(input) {
46
- const paramString = getEncodedValue(input);
47
- if (paramString == null) return paramString;
48
- return isDurationString(paramString) ? paramString : new Date(Number(paramString));
49
- }
50
- /**
51
- * Custom TimeRangeValue param type
52
- * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types
53
- */ export const TimeRangeParam = {
54
- encode: encodeTimeRangeValue,
55
- decode: decodeTimeRangeValue,
56
- equals: (valueA, valueB)=>{
57
- if (valueA === valueB) return true;
58
- if (valueA == null || valueB == null) return valueA === valueB;
59
- return valueA.valueOf() === valueB.valueOf();
60
- }
61
- };
62
- export const timeRangeQueryConfig = {
63
- start: TimeRangeParam,
64
- end: TimeRangeParam
65
- };
66
- /**
67
- * Gets the initial time range taking into account URL params and dashboard JSON duration
68
- * Sets start query param if it is empty on page load
69
- */ export function useInitialTimeRange(dashboardDuration) {
70
- const [query] = useQueryParams(timeRangeQueryConfig);
71
- const { start , end } = query;
72
- return useMemo(()=>{
73
- let initialTimeRange = {
74
- pastDuration: dashboardDuration
75
- };
76
- if (!start) {
77
- return initialTimeRange;
78
- }
79
- const startStr = start.toString();
80
- if (isDurationString(startStr)) {
81
- initialTimeRange = {
82
- pastDuration: startStr
83
- };
84
- } else if (isDate(start) && isDate(end)) {
85
- initialTimeRange = {
86
- start: start,
87
- end: end
88
- };
89
- }
90
- return initialTimeRange;
91
- }, [
92
- start,
93
- end,
94
- dashboardDuration
95
- ]);
96
- }
97
- /**
98
- * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization
99
- */ export function useSetTimeRangeParams(initialTimeRange, enabledURLParams = true) {
100
- const [query, setQuery] = useQueryParams(timeRangeQueryConfig);
101
- // determine whether initial param had previously been populated to fix back btn
102
- const [paramsLoaded, setParamsLoaded] = useState(false);
103
- // optional fallback when app does not want query string as source of truth
104
- // this occurs when enabledURLParams is set to false on TimeRangeProvider
105
- const [timeRangeState, setTimeRangeState] = useState(initialTimeRange);
106
- const { start } = query;
107
- useEffect(()=>{
108
- // when dashboard loaded with no params, default to dashboard duration
109
- if (enabledURLParams && !paramsLoaded && !start) {
110
- if (isRelativeTimeRange(initialTimeRange)) {
111
- setQuery({
112
- start: initialTimeRange.pastDuration,
113
- end: undefined
114
- });
115
- setParamsLoaded(true);
116
- }
117
- }
118
- }, [
119
- initialTimeRange,
120
- enabledURLParams,
121
- paramsLoaded,
122
- start,
123
- setQuery
124
- ]);
125
- const setTimeRange = useCallback((value)=>{
126
- if (isRelativeTimeRange(value)) {
127
- setQuery({
128
- start: value.pastDuration,
129
- end: undefined
130
- });
131
- } else {
132
- setQuery(value);
133
- }
134
- }, [
135
- setQuery
136
- ]);
137
- if (!enabledURLParams) {
138
- return {
139
- timeRange: timeRangeState,
140
- setTimeRange: setTimeRangeState
141
- };
142
- }
143
- return {
144
- timeRange: initialTimeRange,
145
- setTimeRange: setTimeRange
146
- };
147
- }
148
-
149
- //# sourceMappingURL=query-params.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/context/TimeRangeProvider/query-params.ts"],"sourcesContent":["// Copyright 2022 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 '@perses-dev/plugin-system';\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);\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(initialTimeRange: TimeRangeValue, enabledURLParams = true): TimeRange {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig);\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","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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