@perses-dev/plugin-system 0.46.0-rc0 → 0.46.0-rc1

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.
@@ -28,16 +28,16 @@ const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
28
28
  const { pluginTypes, value: propValue, onChange, ...others } = props;
29
29
  const { data, isLoading } = (0, _runtime.useListPluginMetadata)(pluginTypes);
30
30
  // Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
31
- const value = propValue && isLoading ? '' : JSON.stringify(propValue);
31
+ const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
32
32
  const handleChange = (event)=>{
33
- onChange === null || onChange === void 0 ? void 0 : onChange(JSON.parse(event.target.value));
33
+ onChange === null || onChange === void 0 ? void 0 : onChange(optionValueToSelection(event.target.value));
34
34
  };
35
35
  const renderValue = (0, _react.useCallback)((selected)=>{
36
36
  var _data_find;
37
- const selectedValue = JSON.parse(selected);
38
- if (!selectedValue.kind) {
37
+ if (selected === '') {
39
38
  return '';
40
39
  }
40
+ const selectedValue = optionValueToSelection(selected);
41
41
  return data === null || data === void 0 ? void 0 : (_data_find = data.find((v)=>v.pluginType === selectedValue.type && v.kind === selectedValue.kind)) === null || _data_find === void 0 ? void 0 : _data_find.display.name;
42
42
  }, [
43
43
  data
@@ -60,7 +60,7 @@ const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
60
60
  }),
61
61
  data === null || data === void 0 ? void 0 : data.map((metadata)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
62
62
  "data-testid": "option",
63
- value: JSON.stringify({
63
+ value: selectionToOptionValue({
64
64
  type: metadata.pluginType,
65
65
  kind: metadata.kind
66
66
  }),
@@ -70,3 +70,31 @@ const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
70
70
  });
71
71
  });
72
72
  PluginKindSelect.displayName = 'PluginKindSelect';
73
+ // Delimiter used to stringify/parse option values
74
+ const OPTION_VALUE_DELIMITER = '_____';
75
+ /**
76
+ * Given a PluginEditorSelection,
77
+ * returns a string value like `{type}_____{kind}` that can be used as a Select input value.
78
+ * @param selector
79
+ */ function selectionToOptionValue(selector) {
80
+ return [
81
+ selector.type,
82
+ selector.kind
83
+ ].join(OPTION_VALUE_DELIMITER);
84
+ }
85
+ /**
86
+ * Given an option value name like `{type}_____{kind}`,
87
+ * returns a PluginEditorSelection to be used by the query data model.
88
+ * @param optionValue
89
+ */ function optionValueToSelection(optionValue) {
90
+ const words = optionValue.split(OPTION_VALUE_DELIMITER);
91
+ const type = words[0];
92
+ const kind = words[1];
93
+ if (type === undefined || kind === undefined) {
94
+ throw new Error('Invalid optionValue string');
95
+ }
96
+ return {
97
+ type,
98
+ kind
99
+ };
100
+ }
@@ -54,15 +54,12 @@ const _usequeryparams = require("use-query-params");
54
54
  const _datefns = require("date-fns");
55
55
  const _core = require("@perses-dev/core");
56
56
  /* Interprets an encoded string and returns either the string or null/undefined if not available */ function getEncodedValue(input, allowEmptyString) {
57
- if (input == null) {
58
- return input;
59
- }
60
57
  // '' or []
61
- if (input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
58
+ if (!input || input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
62
59
  return null;
63
60
  }
64
61
  const str = input instanceof Array ? input[0] : input;
65
- if (str == null) {
62
+ if (str === null || str === undefined) {
66
63
  return str;
67
64
  }
68
65
  if (!allowEmptyString && str === '') {
@@ -83,7 +80,7 @@ function encodeTimeRangeValue(timeOptionValue) {
83
80
  }
84
81
  function decodeTimeRangeValue(input) {
85
82
  const paramString = getEncodedValue(input);
86
- if (paramString == null) return paramString;
83
+ if (!paramString) return null;
87
84
  return (0, _core.isDurationString)(paramString) ? paramString : new Date(Number(paramString));
88
85
  }
89
86
  const TimeRangeParam = {
@@ -91,7 +88,7 @@ const TimeRangeParam = {
91
88
  decode: decodeTimeRangeValue,
92
89
  equals: (valueA, valueB)=>{
93
90
  if (valueA === valueB) return true;
94
- if (valueA == null || valueB == null) return valueA === valueB;
91
+ if (!valueA || !valueB) return valueA === valueB;
95
92
  return valueA.valueOf() === valueB.valueOf();
96
93
  }
97
94
  };
@@ -24,16 +24,16 @@ import { useListPluginMetadata } from '../../runtime';
24
24
  const { pluginTypes, value: propValue, onChange, ...others } = props;
25
25
  const { data, isLoading } = useListPluginMetadata(pluginTypes);
26
26
  // Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
27
- const value = propValue && isLoading ? '' : JSON.stringify(propValue);
27
+ const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
28
28
  const handleChange = (event)=>{
29
- onChange === null || onChange === void 0 ? void 0 : onChange(JSON.parse(event.target.value));
29
+ onChange === null || onChange === void 0 ? void 0 : onChange(optionValueToSelection(event.target.value));
30
30
  };
31
31
  const renderValue = useCallback((selected)=>{
32
32
  var _data_find;
33
- const selectedValue = JSON.parse(selected);
34
- if (!selectedValue.kind) {
33
+ if (selected === '') {
35
34
  return '';
36
35
  }
36
+ const selectedValue = optionValueToSelection(selected);
37
37
  return data === null || data === void 0 ? void 0 : (_data_find = data.find((v)=>v.pluginType === selectedValue.type && v.kind === selectedValue.kind)) === null || _data_find === void 0 ? void 0 : _data_find.display.name;
38
38
  }, [
39
39
  data
@@ -56,7 +56,7 @@ import { useListPluginMetadata } from '../../runtime';
56
56
  }),
57
57
  data === null || data === void 0 ? void 0 : data.map((metadata)=>/*#__PURE__*/ _jsx(MenuItem, {
58
58
  "data-testid": "option",
59
- value: JSON.stringify({
59
+ value: selectionToOptionValue({
60
60
  type: metadata.pluginType,
61
61
  kind: metadata.kind
62
62
  }),
@@ -66,5 +66,33 @@ import { useListPluginMetadata } from '../../runtime';
66
66
  });
67
67
  });
68
68
  PluginKindSelect.displayName = 'PluginKindSelect';
69
+ // Delimiter used to stringify/parse option values
70
+ const OPTION_VALUE_DELIMITER = '_____';
71
+ /**
72
+ * Given a PluginEditorSelection,
73
+ * returns a string value like `{type}_____{kind}` that can be used as a Select input value.
74
+ * @param selector
75
+ */ function selectionToOptionValue(selector) {
76
+ return [
77
+ selector.type,
78
+ selector.kind
79
+ ].join(OPTION_VALUE_DELIMITER);
80
+ }
81
+ /**
82
+ * Given an option value name like `{type}_____{kind}`,
83
+ * returns a PluginEditorSelection to be used by the query data model.
84
+ * @param optionValue
85
+ */ function optionValueToSelection(optionValue) {
86
+ const words = optionValue.split(OPTION_VALUE_DELIMITER);
87
+ const type = words[0];
88
+ const kind = words[1];
89
+ if (type === undefined || kind === undefined) {
90
+ throw new Error('Invalid optionValue string');
91
+ }
92
+ return {
93
+ type,
94
+ kind
95
+ };
96
+ }
69
97
 
70
98
  //# sourceMappingURL=PluginKindSelect.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PluginKindSelect/PluginKindSelect.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 { MenuItem, TextField, TextFieldProps } from '@mui/material';\nimport { forwardRef, useCallback } from 'react';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata } from '../../runtime';\nimport { PluginEditorSelection } from '../PluginEditor';\n\nexport interface PluginKindSelectProps extends Omit<TextFieldProps, 'value' | 'onChange' | 'children'> {\n pluginTypes: PluginType[];\n value?: PluginEditorSelection;\n onChange?: (s: PluginEditorSelection) => void;\n}\n\n/**\n * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific\n * plugin types. (e.g. \"Show a list of all the Panel plugins\", or \"Show a list of all the Variable plugins\", or \"Show\n * a list of all the TimeSeriesQuery, TraceQuery, and LogQuery plugins\").\n * The value of the select is the kind of the plugin, but you can also listen to the `onPluginTypeChange` event to know\n * when the user changes the plugin type (it fires at start for the default value.)\n */\nexport const PluginKindSelect = forwardRef((props: PluginKindSelectProps, ref) => {\n const { pluginTypes, value: propValue, onChange, ...others } = props;\n const { data, isLoading } = useListPluginMetadata(pluginTypes);\n\n // Pass an empty value while options are still loading so MUI doesn't complain about us using an \"out of range\" value\n const value = propValue && isLoading ? '' : JSON.stringify(propValue);\n\n const handleChange = (event: { target: { value: string } }) => {\n onChange?.(JSON.parse(event.target.value));\n };\n\n const renderValue = useCallback(\n (selected: unknown) => {\n const selectedValue = JSON.parse(selected as string);\n if (!selectedValue.kind) {\n return '';\n }\n return data?.find((v) => v.pluginType === selectedValue.type && v.kind === selectedValue.kind)?.display.name;\n },\n [data]\n );\n\n // TODO: Does this need a loading indicator of some kind?\n return (\n <TextField\n select\n inputRef={ref}\n {...others}\n value={value}\n onChange={handleChange}\n SelectProps={{ renderValue }}\n data-testid=\"plugin-kind-select\"\n >\n {isLoading && <MenuItem value=\"\">Loading...</MenuItem>}\n {data?.map((metadata) => (\n <MenuItem\n data-testid=\"option\"\n key={metadata.pluginType + metadata.kind}\n value={JSON.stringify({ type: metadata.pluginType, kind: metadata.kind })}\n >\n {metadata.display.name}\n </MenuItem>\n ))}\n </TextField>\n );\n});\nPluginKindSelect.displayName = 'PluginKindSelect';\n"],"names":["MenuItem","TextField","forwardRef","useCallback","useListPluginMetadata","PluginKindSelect","props","ref","pluginTypes","value","propValue","onChange","others","data","isLoading","JSON","stringify","handleChange","event","parse","target","renderValue","selected","selectedValue","kind","find","v","pluginType","type","display","name","select","inputRef","SelectProps","data-testid","map","metadata","displayName"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAs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UAAU;wBAAEH,MAAMY,SAASZ,IAAI;oBAAC;8BAEtEY,SAASP,OAAO,CAACC,IAAI;mBAHjBM,SAAST,UAAU,GAAGS,SAASZ,IAAI;;;AAQlD,GAAG;AACHnB,iBAAiBgC,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../src/components/PluginKindSelect/PluginKindSelect.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 { MenuItem, TextField, TextFieldProps } from '@mui/material';\nimport { forwardRef, useCallback } from 'react';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata } from '../../runtime';\nimport { PluginEditorSelection } from '../PluginEditor';\n\nexport interface PluginKindSelectProps extends Omit<TextFieldProps, 'value' | 'onChange' | 'children'> {\n pluginTypes: PluginType[];\n value?: PluginEditorSelection;\n onChange?: (s: PluginEditorSelection) => void;\n}\n\n/**\n * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific\n * plugin types. (e.g. \"Show a list of all the Panel plugins\", or \"Show a list of all the Variable plugins\", or \"Show\n * a list of all the TimeSeriesQuery, TraceQuery, and LogQuery plugins\").\n * The value of the select is the kind of the plugin, but you can also listen to the `onPluginTypeChange` event to know\n * when the user changes the plugin type (it fires at start for the default value.)\n */\nexport const PluginKindSelect = forwardRef((props: PluginKindSelectProps, ref) => {\n const { pluginTypes, value: propValue, onChange, ...others } = props;\n const { data, isLoading } = useListPluginMetadata(pluginTypes);\n\n // Pass an empty value while options are still loading so MUI doesn't complain about us using an \"out of range\" value\n const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);\n\n const handleChange = (event: { target: { value: string } }) => {\n onChange?.(optionValueToSelection(event.target.value));\n };\n\n const renderValue = useCallback(\n (selected: unknown) => {\n if (selected === '') {\n return '';\n }\n const selectedValue = optionValueToSelection(selected as string);\n return data?.find((v) => v.pluginType === selectedValue.type && v.kind === selectedValue.kind)?.display.name;\n },\n [data]\n );\n\n // TODO: Does this need a loading indicator of some kind?\n return (\n <TextField\n select\n inputRef={ref}\n {...others}\n value={value}\n onChange={handleChange}\n SelectProps={{ renderValue }}\n data-testid=\"plugin-kind-select\"\n >\n {isLoading && <MenuItem value=\"\">Loading...</MenuItem>}\n {data?.map((metadata) => (\n <MenuItem\n data-testid=\"option\"\n key={metadata.pluginType + metadata.kind}\n value={selectionToOptionValue({ type: metadata.pluginType, kind: metadata.kind })}\n >\n {metadata.display.name}\n </MenuItem>\n ))}\n </TextField>\n );\n});\nPluginKindSelect.displayName = 'PluginKindSelect';\n\n// Delimiter used to stringify/parse option values\nconst OPTION_VALUE_DELIMITER = '_____';\n\n/**\n * Given a PluginEditorSelection,\n * returns a string value like `{type}_____{kind}` that can be used as a Select input value.\n * @param selector\n */\nfunction selectionToOptionValue(selector: PluginEditorSelection): string {\n return [selector.type, selector.kind].join(OPTION_VALUE_DELIMITER);\n}\n\n/**\n * Given an option value name like `{type}_____{kind}`,\n * returns a PluginEditorSelection to be used by the query data model.\n * @param optionValue\n */\nfunction optionValueToSelection(optionValue: string): PluginEditorSelection {\n const words = optionValue.split(OPTION_VALUE_DELIMITER);\n const type = words[0] as PluginType | undefined;\n const kind = words[1];\n if (type === undefined || kind === undefined) {\n throw new Error('Invalid optionValue string');\n }\n return {\n type,\n kind,\n };\n}\n"],"names":["MenuItem","TextField","forwardRef","useCallback","useListPluginMetadata","PluginKindSelect","props","ref","pluginTypes","value","propValue","onChange","others","data","isLoading","selectionToOptionValue","handleChange","event","optionValueToSelection","target","renderValue","selected","selectedValue","find","v","pluginType","type","kind","display","name","select","inputRef","SelectProps","data-testid","map","metadata","displayName","OPTION_VALUE_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d;gBAASS,OAAM;0BAAG;;YAChCI,iBAAAA,2BAAAA,KAAMqB,GAAG,CAAC,CAACC,yBACV,KAACnC;oBACCiC,eAAY;oBAEZxB,OAAOM,uBAAuB;wBAAEW,MAAMS,SAASV,UAAU;wBAAEE,MAAMQ,SAASR,IAAI;oBAAC;8BAE9EQ,SAASP,OAAO,CAACC,IAAI;mBAHjBM,SAASV,UAAU,GAAGU,SAASR,IAAI;;;AAQlD,GAAG;AACHtB,iBAAiB+B,WAAW,GAAG;AAE/B,kDAAkD;AAClD,MAAMC,yBAAyB;AAE/B;;;;CAIC,GACD,SAAStB,uBAAuBuB,QAA+B;IAC7D,OAAO;QAACA,SAASZ,IAAI;QAAEY,SAASX,IAAI;KAAC,CAACY,IAAI,CAACF;AAC7C;AAEA;;;;CAIC,GACD,SAASnB,uBAAuBsB,WAAmB;IACjD,MAAMC,QAAQD,YAAYE,KAAK,CAACL;IAChC,MAAMX,OAAOe,KAAK,CAAC,EAAE;IACrB,MAAMd,OAAOc,KAAK,CAAC,EAAE;IACrB,IAAIf,SAASiB,aAAahB,SAASgB,WAAW;QAC5C,MAAM,IAAIC,MAAM;IAClB;IACA,OAAO;QACLlB;QACAC;IACF;AACF"}
@@ -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,MAAM,MAAM,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,EA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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,eAAO,MAAM,0BAA0B;;CAEtC,CAAC;AAEF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,cAAc,GAAG,cAAc,CAgBrF;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,gBAAgB,EAAE,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,GAAG,cAAc,CAAC,CA8BlH;AAED;;;GAGG;AACH,wBAAgB,yBAAyB,CAAC,iBAAiB,EAAE,cAAc,GAAG,cAAc,CAc3F;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CACzC,sBAAsB,CAAC,EAAE,cAAc,GACtC,IAAI,CAAC,SAAS,EAAE,iBAAiB,GAAG,oBAAoB,CAAC,CAyB3D"}
@@ -15,15 +15,12 @@ import { useQueryParams } from 'use-query-params';
15
15
  import { getUnixTime, isDate } from 'date-fns';
16
16
  import { isRelativeTimeRange, isDurationString } 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
- if (input == null) {
19
- return input;
20
- }
21
18
  // '' or []
22
- if (input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
19
+ if (!input || input.length === 0 && (!allowEmptyString || allowEmptyString && input !== '')) {
23
20
  return null;
24
21
  }
25
22
  const str = input instanceof Array ? input[0] : input;
26
- if (str == null) {
23
+ if (str === null || str === undefined) {
27
24
  return str;
28
25
  }
29
26
  if (!allowEmptyString && str === '') {
@@ -44,7 +41,7 @@ import { isRelativeTimeRange, isDurationString } from '@perses-dev/core';
44
41
  }
45
42
  /* Converts param input to supported relative or absolute time range format */ export function decodeTimeRangeValue(input) {
46
43
  const paramString = getEncodedValue(input);
47
- if (paramString == null) return paramString;
44
+ if (!paramString) return null;
48
45
  return isDurationString(paramString) ? paramString : new Date(Number(paramString));
49
46
  }
50
47
  /**
@@ -55,7 +52,7 @@ import { isRelativeTimeRange, isDurationString } from '@perses-dev/core';
55
52
  decode: decodeTimeRangeValue,
56
53
  equals: (valueA, valueB)=>{
57
54
  if (valueA === valueB) return true;
58
- if (valueA == null || valueB == null) return valueA === valueB;
55
+ if (!valueA || !valueB) return valueA === valueB;
59
56
  return valueA.valueOf() === valueB.valueOf();
60
57
  }
61
58
  };
@@ -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\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, taking the URL query params.\n */\nexport function useTimeRangeParams(initialTimeRange: TimeRangeValue): 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 const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (!paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, 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 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\n/**\n * Returns refresh interval getter and setter, taking the URL query params.\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval'> {\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 const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard refresh interval\n if (!paramsLoaded && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n setParamsLoaded(true);\n }\n }, [initialRefreshInterval, paramsLoaded, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery]\n );\n\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n };\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","refreshIntervalQueryConfig","refresh","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useTimeRangeParams","setQuery","paramsLoaded","setParamsLoaded","undefined","setTimeRange","value","timeRange","useInitialRefreshInterval","useSetRefreshIntervalParams","initialRefreshInterval","setRefreshInterval","refreshInterval"],"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,QAAQ;AAClE,SAASC,cAAc,QAA0B,mBAAmB;AACpE,SAASC,WAAW,EAAEC,MAAM,QAAQ,WAAW;AAC/C,SAEEC,mBAAmB,EACnBC,gBAAgB,QAGX,mBAAmB;AAK1B,iGAAiG,GACjG,SAASC,gBACPC,KAAuD,EACvDC,gBAA0B;IAE1B,IAAID,SAAS,MAAM;QACjB,OAAOA;IACT;IACA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AAY;IACrF,MAAM,EAAEJ,OAAO,EAAE,GAAGG;IACpB,OAAOpC,QAAQ;QACb,IAAIsC,mBAAmCH;QACvC,IAAI,CAACF,SAAS;YACZ,OAAOK;QACT;QACA,MAAME,WAAWP,QAAQhB,QAAQ;QACjC,IAAIT,iBAAiBgC,WAAW;YAC9BF,mBAAmBE;QACrB;QACA,OAAOF;IACT,GAAG;QAACH;QAAmBF;KAAQ;AACjC;AAEA;;CAEC,GACD,OAAO,SAASiB,4BACdC,sBAAuC;IAEvC,MAAM,CAACf,OAAOM,SAAS,GAAGtC,eAAe4B,4BAA4B;QAAEK,YAAY;IAAY;IAE/F,gFAAgF;IAChF,MAAM,CAACM,cAAcC,gBAAgB,GAAGzC,SAAkB;IAE1D,MAAM,EAAE8B,OAAO,EAAE,GAAGG;IAEpBlC,UAAU;QACR,8EAA8E;QAC9E,IAAI,CAACyC,gBAAgB,CAACV,SAAS;YAC7BS,SAAS;gBAAET,SAASkB;YAAuB;YAC3CP,gBAAgB;QAClB;IACF,GAAG;QAACO;QAAwBR;QAAcV;QAASS;KAAS;IAE5D,MAAMU,qBAAsDnD,YAC1D,CAACgC,UAA4BS,SAAS;YAAET;QAAQ,IAChD;QAACS;KAAS;IAGZ,OAAO;QACLW,iBAAiBF;QACjBC,oBAAoBA;IACtB;AACF"}
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 // '' or []\n if (!input || (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== '')))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str === null || str === undefined) {\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) return null;\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 || !valueB) 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, taking the URL query params.\n */\nexport function useTimeRangeParams(initialTimeRange: TimeRangeValue): 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 const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (!paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, 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 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\n/**\n * Returns refresh interval getter and setter, taking the URL query params.\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval'> {\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 const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard refresh interval\n if (!paramsLoaded && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n setParamsLoaded(true);\n }\n }, [initialRefreshInterval, paramsLoaded, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery]\n );\n\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n };\n}\n"],"names":["useMemo","useCallback","useEffect","useState","useQueryParams","getUnixTime","isDate","isRelativeTimeRange","isDurationString","getEncodedValue","input","allowEmptyString","length","str","Array","undefined","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","useTimeRangeParams","setQuery","paramsLoaded","setParamsLoaded","setTimeRange","value","timeRange","useInitialRefreshInterval","useSetRefreshIntervalParams","initialRefreshInterval","setRefreshInterval","refreshInterval"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CA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-1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/plugin-system",
3
- "version": "0.46.0-rc0",
3
+ "version": "0.46.0-rc1",
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,8 +28,8 @@
28
28
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
29
29
  },
30
30
  "dependencies": {
31
- "@perses-dev/components": "0.46.0-rc0",
32
- "@perses-dev/core": "0.46.0-rc0",
31
+ "@perses-dev/components": "0.46.0-rc1",
32
+ "@perses-dev/core": "0.46.0-rc1",
33
33
  "date-fns": "^2.30.0",
34
34
  "immer": "^9.0.15",
35
35
  "react-hook-form": "^7.46.1",
@@ -38,7 +38,7 @@
38
38
  "zod": "^3.22.2"
39
39
  },
40
40
  "devDependencies": {
41
- "@perses-dev/storybook": "0.46.0-rc0"
41
+ "@perses-dev/storybook": "0.46.0-rc1"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@mui/material": "^5.10.0",