@perses-dev/plugin-system 0.41.1 → 0.42.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 (166) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +26 -55
  2. package/dist/cjs/components/DatasourceSelect.js +22 -10
  3. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +1 -0
  4. package/dist/cjs/components/PluginEditor/PluginEditor.js +2 -1
  5. package/dist/cjs/components/ProjectSelect.js +96 -0
  6. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +14 -12
  7. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +50 -2
  8. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +11 -8
  9. package/dist/cjs/components/index.js +1 -0
  10. package/dist/cjs/context/ProjectStoreProvider.js +78 -0
  11. package/dist/cjs/context/index.js +30 -0
  12. package/dist/cjs/context/query-params.js +49 -0
  13. package/dist/cjs/index.js +1 -0
  14. package/dist/cjs/model/index.js +1 -0
  15. package/dist/cjs/model/trace-queries.js +16 -0
  16. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +17 -5
  17. package/dist/cjs/runtime/DataQueriesProvider/model.js +27 -7
  18. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +27 -18
  19. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js +43 -0
  20. package/dist/cjs/runtime/TimeRangeProvider/index.js +1 -0
  21. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +7 -39
  22. package/dist/cjs/runtime/TimeRangeProvider/refresh-interval.js +30 -0
  23. package/dist/cjs/runtime/datasources.js +3 -2
  24. package/dist/cjs/runtime/index.js +1 -0
  25. package/dist/cjs/runtime/trace-queries.js +59 -0
  26. package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +2 -1
  27. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +12 -0
  28. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +2 -2
  29. package/dist/cjs/test/mock-data.js +26 -3
  30. package/dist/cjs/validation/role.js +85 -0
  31. package/dist/cjs/validation/rolebinding.js +55 -0
  32. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +7 -7
  33. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  34. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +26 -16
  35. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  36. package/dist/components/DatasourceSelect.d.ts +1 -0
  37. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  38. package/dist/components/DatasourceSelect.js +22 -10
  39. package/dist/components/DatasourceSelect.js.map +1 -1
  40. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +1 -1
  41. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  42. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +1 -0
  43. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  44. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  45. package/dist/components/PluginEditor/PluginEditor.js +2 -1
  46. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  47. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
  48. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  49. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  50. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +1 -0
  51. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  52. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  53. package/dist/components/ProjectSelect.d.ts +15 -0
  54. package/dist/components/ProjectSelect.d.ts.map +1 -0
  55. package/dist/components/ProjectSelect.js +91 -0
  56. package/dist/components/ProjectSelect.js.map +1 -0
  57. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +1 -1
  58. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +15 -13
  59. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +1 -1
  60. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +1 -2
  61. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  62. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +50 -2
  63. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  64. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +2 -1
  65. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  66. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +11 -8
  67. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  68. package/dist/components/index.d.ts +1 -0
  69. package/dist/components/index.d.ts.map +1 -1
  70. package/dist/components/index.js +1 -0
  71. package/dist/components/index.js.map +1 -1
  72. package/dist/context/ProjectStoreProvider.d.ts +16 -0
  73. package/dist/context/ProjectStoreProvider.d.ts.map +1 -0
  74. package/dist/context/ProjectStoreProvider.js +56 -0
  75. package/dist/context/ProjectStoreProvider.js.map +1 -0
  76. package/dist/context/index.d.ts +2 -0
  77. package/dist/context/index.d.ts.map +1 -0
  78. package/dist/context/index.js +15 -0
  79. package/dist/context/index.js.map +1 -0
  80. package/dist/context/query-params.d.ts +5 -0
  81. package/dist/context/query-params.d.ts.map +1 -0
  82. package/dist/context/query-params.js +41 -0
  83. package/dist/context/query-params.js.map +1 -0
  84. package/dist/index.d.ts +1 -0
  85. package/dist/index.d.ts.map +1 -1
  86. package/dist/index.js +1 -0
  87. package/dist/index.js.map +1 -1
  88. package/dist/model/index.d.ts +1 -0
  89. package/dist/model/index.d.ts.map +1 -1
  90. package/dist/model/index.js +1 -0
  91. package/dist/model/index.js.map +1 -1
  92. package/dist/model/plugin-base.d.ts +1 -0
  93. package/dist/model/plugin-base.d.ts.map +1 -1
  94. package/dist/model/plugin-base.js.map +1 -1
  95. package/dist/model/plugins.d.ts +2 -0
  96. package/dist/model/plugins.d.ts.map +1 -1
  97. package/dist/model/plugins.js.map +1 -1
  98. package/dist/model/trace-queries.d.ts +18 -0
  99. package/dist/model/trace-queries.d.ts.map +1 -0
  100. package/dist/model/trace-queries.js +15 -0
  101. package/dist/model/trace-queries.js.map +1 -0
  102. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
  103. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +17 -5
  104. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  105. package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
  106. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  107. package/dist/runtime/DataQueriesProvider/model.js +27 -7
  108. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  109. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +4 -3
  110. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  111. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +28 -19
  112. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  113. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts +9 -0
  114. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts.map +1 -0
  115. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js +30 -0
  116. package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js.map +1 -0
  117. package/dist/runtime/TimeRangeProvider/index.d.ts +1 -0
  118. package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -1
  119. package/dist/runtime/TimeRangeProvider/index.js +1 -0
  120. package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
  121. package/dist/runtime/TimeRangeProvider/query-params.d.ts +4 -4
  122. package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
  123. package/dist/runtime/TimeRangeProvider/query-params.js +8 -40
  124. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
  125. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts +7 -0
  126. package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts.map +1 -0
  127. package/dist/runtime/TimeRangeProvider/refresh-interval.js +25 -0
  128. package/dist/runtime/TimeRangeProvider/refresh-interval.js.map +1 -0
  129. package/dist/runtime/datasources.d.ts +29 -2
  130. package/dist/runtime/datasources.d.ts.map +1 -1
  131. package/dist/runtime/datasources.js +3 -2
  132. package/dist/runtime/datasources.js.map +1 -1
  133. package/dist/runtime/index.d.ts +1 -0
  134. package/dist/runtime/index.d.ts.map +1 -1
  135. package/dist/runtime/index.js +1 -0
  136. package/dist/runtime/index.js.map +1 -1
  137. package/dist/runtime/trace-queries.d.ts +10 -0
  138. package/dist/runtime/trace-queries.d.ts.map +1 -0
  139. package/dist/runtime/trace-queries.js +47 -0
  140. package/dist/runtime/trace-queries.js.map +1 -0
  141. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
  142. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +2 -1
  143. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
  144. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -1
  145. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +12 -0
  146. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
  147. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +2 -2
  148. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +1 -1
  149. package/dist/stories/shared-utils/decorators/WithTimeRange.js +2 -2
  150. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  151. package/dist/test/mock-data.d.ts +2 -1
  152. package/dist/test/mock-data.d.ts.map +1 -1
  153. package/dist/test/mock-data.js +15 -0
  154. package/dist/test/mock-data.js.map +1 -1
  155. package/dist/utils/action.d.ts +1 -1
  156. package/dist/utils/action.d.ts.map +1 -1
  157. package/dist/utils/action.js.map +1 -1
  158. package/dist/validation/role.d.ts +228 -0
  159. package/dist/validation/role.d.ts.map +1 -0
  160. package/dist/validation/role.js +66 -0
  161. package/dist/validation/role.js.map +1 -0
  162. package/dist/validation/rolebinding.d.ts +137 -0
  163. package/dist/validation/rolebinding.d.ts.map +1 -0
  164. package/dist/validation/rolebinding.js +47 -0
  165. package/dist/validation/rolebinding.js.map +1 -0
  166. package/package.json +5 -4
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI7E,aAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAC5C,MAAM,WAAW,wBAAwB,CAAC,eAAe,GAAG,WAAW;IACrE,WAAW,EAAE,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC,CAAC;IAChD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,YAAY,CAAC,EAAE,oBAAoB,CAAC;CACrC;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,SAAS,EAAE,CAAC;IAC1B,UAAU,EAAE,MAAM,IAAI,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,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O,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,OAAO,EAAE,CAAC;CACnB;AAED,MAAM,WAAW,mBAAmB,CAAC,CAAC,CAAE,SAAQ,IAAI,CAAC,sBAAsB,EAAE,cAAc,CAAC;IAC1F,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC;AAED,oBAAY,SAAS,CAAC,CAAC,GAAG,aAAa,IAAI;IACzC,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,eAAe,CAAC;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,8BAW9F;AAED,wBAAgB,YAAY,IAAI,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAsDzE"}
@@ -25,23 +25,42 @@ export function transformQueryResults(results, definitions) {
25
25
  });
26
26
  }
27
27
  export function useQueryType() {
28
- const { data: timeSeriesQueryPlugins , isLoading } = useListPluginMetadata('TimeSeriesQuery');
28
+ const { data: timeSeriesQueryPlugins , isLoading: isTimeSeriesQueryLoading } = useListPluginMetadata('TimeSeriesQuery');
29
+ const { data: traceQueryPlugins , isLoading: isTraceQueryPluginLoading } = useListPluginMetadata('TraceQuery');
30
+ // For example, `map: {"TimeSeriesQuery":["PrometheusTimeSeriesQuery"],"TraceQuery":["TempoTraceQuery"]}`
29
31
  const queryTypeMap = useMemo(()=>{
30
32
  const map = {
31
- TimeSeriesQuery: []
33
+ TimeSeriesQuery: [],
34
+ TraceQuery: []
32
35
  };
33
36
  if (timeSeriesQueryPlugins) {
34
37
  timeSeriesQueryPlugins.forEach((plugin)=>{
35
- var _map_TimeSeriesQuery;
36
- (_map_TimeSeriesQuery = map['TimeSeriesQuery']) === null || _map_TimeSeriesQuery === void 0 ? void 0 : _map_TimeSeriesQuery.push(plugin.kind);
38
+ var _map_plugin_pluginType;
39
+ (_map_plugin_pluginType = map[plugin.pluginType]) === null || _map_plugin_pluginType === void 0 ? void 0 : _map_plugin_pluginType.push(plugin.kind);
40
+ });
41
+ }
42
+ if (traceQueryPlugins) {
43
+ traceQueryPlugins.forEach((plugin)=>{
44
+ var _map_plugin_pluginType;
45
+ (_map_plugin_pluginType = map[plugin.pluginType]) === null || _map_plugin_pluginType === void 0 ? void 0 : _map_plugin_pluginType.push(plugin.kind);
37
46
  });
38
47
  }
39
48
  return map;
40
49
  }, [
41
- timeSeriesQueryPlugins
50
+ timeSeriesQueryPlugins,
51
+ traceQueryPlugins
42
52
  ]);
43
53
  const getQueryType = useCallback((pluginKind)=>{
44
- if (isLoading) {
54
+ const isLoading = (pluginKind)=>{
55
+ switch(pluginKind){
56
+ case 'PrometheusTimeSeriesQuery':
57
+ return isTimeSeriesQueryLoading;
58
+ case 'TempoTraceQuery':
59
+ return isTraceQueryPluginLoading;
60
+ }
61
+ throw new Error(`Unable to determine the query type: ${pluginKind}`);
62
+ };
63
+ if (isLoading(pluginKind)) {
45
64
  return undefined;
46
65
  }
47
66
  for(const queryType in queryTypeMap){
@@ -53,7 +72,8 @@ export function useQueryType() {
53
72
  throw new Error(`Unable to determine the query type: ${pluginKind}`);
54
73
  }, [
55
74
  queryTypeMap,
56
- isLoading
75
+ isTimeSeriesQueryLoading,
76
+ isTraceQueryPluginLoading
57
77
  ]);
58
78
  return getQueryType;
59
79
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.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 { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\ntype QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n children?: React.ReactNode;\n options?: QueryOptions;\n queryOptions?: QueryObserverOptions;\n}\n\nexport interface DataQueriesContextType {\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: unknown;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]) {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n\nexport function useQueryType(): (pluginKind: string) => string | undefined {\n const { data: timeSeriesQueryPlugins, isLoading } = useListPluginMetadata('TimeSeriesQuery');\n\n const queryTypeMap = useMemo(() => {\n const map: Record<string, string[]> = {\n TimeSeriesQuery: [],\n };\n\n if (timeSeriesQueryPlugins) {\n timeSeriesQueryPlugins.forEach((plugin) => {\n map['TimeSeriesQuery']?.push(plugin.kind);\n });\n }\n\n return map;\n }, [timeSeriesQueryPlugins]);\n\n const getQueryType = useCallback(\n (pluginKind: string) => {\n if (isLoading) {\n return undefined;\n }\n\n for (const queryType in queryTypeMap) {\n if (queryTypeMap[queryType]?.includes(pluginKind)) {\n return queryType;\n }\n }\n\n throw new Error(`Unable to determine the query type: ${pluginKind}`);\n },\n [queryTypeMap, isLoading]\n );\n\n return getQueryType;\n}\n"],"names":["useCallback","useMemo","useListPluginMetadata","transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition","useQueryType","timeSeriesQueryPlugins","queryTypeMap","TimeSeriesQuery","forEach","plugin","push","kind","getQueryType","pluginKind","undefined","queryType","includes","Error"],"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;AAIjC,SAASA,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC7C,SAASC,qBAAqB,QAAQ,qBAAqB;AA+B3D,OAAO,SAASC,sBAAsBC,OAAyB,EAAEC,WAA8B;IAC7F,OAAOD,QAAQE,IAAI,CAAC,EAAEC,KAAI,EAAEC,WAAU,EAAEC,UAAS,EAAEC,QAAO,EAAEC,MAAK,EAAE,EAAEC;QACnE,OAAO;YACLC,YAAYR,WAAW,CAACO,EAAE;YAC1BL;YACAC;YACAC;YACAC;YACAC;QACF;IACF;AACF;AAEA,OAAO,SAASG;IACd,MAAM,EAAEP,MAAMQ,uBAAsB,EAAEN,UAAS,EAAE,GAAGP,sBAAsB;IAE1E,MAAMc,eAAef,QAAQ;QAC3B,MAAMK,MAAgC;YACpCW,iBAAiB,EAAE;QACrB;QAEA,IAAIF,wBAAwB;YAC1BA,uBAAuBG,QAAQ,CAACC;oBAC9Bb;gBAAAA,CAAAA,uBAAAA,GAAG,CAAC,kBAAkB,cAAtBA,kCAAAA,KAAAA,IAAAA,qBAAwBc,KAAKD,OAAOE;YACtC;QACF;QAEA,OAAOf;IACT,GAAG;QAACS;KAAuB;IAE3B,MAAMO,eAAetB,YACnB,CAACuB;QACC,IAAId,WAAW;YACb,OAAOe;QACT;QAEA,IAAK,MAAMC,aAAaT,aAAc;gBAChCA;YAAJ,IAAIA,CAAAA,0BAAAA,YAAY,CAACS,UAAU,cAAvBT,qCAAAA,KAAAA,IAAAA,wBAAyBU,SAASH,aAAa;gBACjD,OAAOE;YACT;QACF;QAEA,MAAM,IAAIE,MAAM,CAAC,oCAAoC,EAAEJ,WAAW,CAAC;IACrE,GACA;QAACP;QAAcP;KAAU;IAG3B,OAAOa;AACT"}
1
+ {"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.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 { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\ntype QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n children?: React.ReactNode;\n options?: QueryOptions;\n queryOptions?: QueryObserverOptions;\n}\n\nexport interface DataQueriesContextType {\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: unknown;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]) {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n\nexport function useQueryType(): (pluginKind: string) => string | undefined {\n const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } =\n useListPluginMetadata('TimeSeriesQuery');\n const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = useListPluginMetadata('TraceQuery');\n\n // For example, `map: {\"TimeSeriesQuery\":[\"PrometheusTimeSeriesQuery\"],\"TraceQuery\":[\"TempoTraceQuery\"]}`\n const queryTypeMap = useMemo(() => {\n const map: Record<string, string[]> = {\n TimeSeriesQuery: [],\n TraceQuery: [],\n };\n\n if (timeSeriesQueryPlugins) {\n timeSeriesQueryPlugins.forEach((plugin) => {\n map[plugin.pluginType]?.push(plugin.kind);\n });\n }\n\n if (traceQueryPlugins) {\n traceQueryPlugins.forEach((plugin) => {\n map[plugin.pluginType]?.push(plugin.kind);\n });\n }\n return map;\n }, [timeSeriesQueryPlugins, traceQueryPlugins]);\n\n const getQueryType = useCallback(\n (pluginKind: string) => {\n const isLoading = (pluginKind: string) => {\n switch (pluginKind) {\n case 'PrometheusTimeSeriesQuery':\n return isTimeSeriesQueryLoading;\n case 'TempoTraceQuery':\n return isTraceQueryPluginLoading;\n }\n throw new Error(`Unable to determine the query type: ${pluginKind}`);\n };\n\n if (isLoading(pluginKind)) {\n return undefined;\n }\n\n for (const queryType in queryTypeMap) {\n if (queryTypeMap[queryType]?.includes(pluginKind)) {\n return queryType;\n }\n }\n\n throw new Error(`Unable to determine the query type: ${pluginKind}`);\n },\n [queryTypeMap, isTimeSeriesQueryLoading, isTraceQueryPluginLoading]\n );\n\n return getQueryType;\n}\n"],"names":["useCallback","useMemo","useListPluginMetadata","transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition","useQueryType","timeSeriesQueryPlugins","isTimeSeriesQueryLoading","traceQueryPlugins","isTraceQueryPluginLoading","queryTypeMap","TimeSeriesQuery","TraceQuery","forEach","plugin","pluginType","push","kind","getQueryType","pluginKind","Error","undefined","queryType","includes"],"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;AAIjC,SAASA,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC7C,SAASC,qBAAqB,QAAQ,qBAAqB;AA+B3D,OAAO,SAASC,sBAAsBC,OAAyB,EAAEC,WAA8B;IAC7F,OAAOD,QAAQE,IAAI,CAAC,EAAEC,KAAI,EAAEC,WAAU,EAAEC,UAAS,EAAEC,QAAO,EAAEC,MAAK,EAAE,EAAEC;QACnE,OAAO;YACLC,YAAYR,WAAW,CAACO,EAAE;YAC1BL;YACAC;YACAC;YACAC;YACAC;QACF;IACF;AACF;AAEA,OAAO,SAASG;IACd,MAAM,EAAEP,MAAMQ,uBAAsB,EAAEN,WAAWO,yBAAwB,EAAE,GACzEd,sBAAsB;IACxB,MAAM,EAAEK,MAAMU,kBAAiB,EAAER,WAAWS,0BAAyB,EAAE,GAAGhB,sBAAsB;IAEhG,yGAAyG;IACzG,MAAMiB,eAAelB,QAAQ;QAC3B,MAAMK,MAAgC;YACpCc,iBAAiB,EAAE;YACnBC,YAAY,EAAE;QAChB;QAEA,IAAIN,wBAAwB;YAC1BA,uBAAuBO,QAAQ,CAACC;oBAC9BjB;gBAAAA,CAAAA,yBAAAA,GAAG,CAACiB,OAAOC,WAAW,cAAtBlB,oCAAAA,KAAAA,IAAAA,uBAAwBmB,KAAKF,OAAOG;YACtC;QACF;QAEA,IAAIT,mBAAmB;YACrBA,kBAAkBK,QAAQ,CAACC;oBACzBjB;gBAAAA,CAAAA,yBAAAA,GAAG,CAACiB,OAAOC,WAAW,cAAtBlB,oCAAAA,KAAAA,IAAAA,uBAAwBmB,KAAKF,OAAOG;YACtC;QACF;QACA,OAAOpB;IACT,GAAG;QAACS;QAAwBE;KAAkB;IAE9C,MAAMU,eAAe3B,YACnB,CAAC4B;QACC,MAAMnB,YAAY,CAACmB;YACjB,OAAQA;gBACN,KAAK;oBACH,OAAOZ;gBACT,KAAK;oBACH,OAAOE;YACX;YACA,MAAM,IAAIW,MAAM,CAAC,oCAAoC,EAAED,WAAW,CAAC;QACrE;QAEA,IAAInB,UAAUmB,aAAa;YACzB,OAAOE;QACT;QAEA,IAAK,MAAMC,aAAaZ,aAAc;gBAChCA;YAAJ,IAAIA,CAAAA,0BAAAA,YAAY,CAACY,UAAU,cAAvBZ,qCAAAA,KAAAA,IAAAA,wBAAyBa,SAASJ,aAAa;gBACjD,OAAOG;YACT;QACF;QAEA,MAAM,IAAIF,MAAM,CAAC,oCAAoC,EAAED,WAAW,CAAC;IACrE,GACA;QAACT;QAAcH;QAA0BE;KAA0B;IAGrE,OAAOS;AACT"}
@@ -1,9 +1,10 @@
1
1
  import React from 'react';
2
2
  import { AbsoluteTimeRange, DurationString, TimeRangeValue } from '@perses-dev/core';
3
3
  export interface TimeRangeProviderProps {
4
- initialTimeRange: TimeRangeValue;
5
- initialRefreshInterval?: DurationString;
6
- enabledURLParams?: boolean;
4
+ timeRange: TimeRangeValue;
5
+ refreshInterval?: DurationString;
6
+ setTimeRange?: (value: TimeRangeValue) => void;
7
+ setRefreshInterval?: (value: DurationString) => void;
7
8
  children?: React.ReactNode;
8
9
  }
9
10
  export interface 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,EACL,iBAAiB,EACjB,cAAc,EAEd,cAAc,EAEf,MAAM,kBAAkB,CAAC;AAG1B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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,eAqC9D"}
@@ -11,9 +11,9 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import React, { useMemo, useState, useCallback, createContext, useContext } from 'react';
14
+ import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
15
15
  import { isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/core';
16
- import { useSetRefreshIntervalParams, useSetTimeRangeParams } from './query-params';
16
+ import { getRefreshIntervalInMs } from './refresh-interval';
17
17
  export const TimeRangeContext = /*#__PURE__*/ createContext(undefined);
18
18
  export function useTimeRangeContext() {
19
19
  const ctx = useContext(TimeRangeContext);
@@ -30,34 +30,43 @@ export function useTimeRangeContext() {
30
30
  /**
31
31
  * Provider implementation that supplies the time range state at runtime.
32
32
  */ export function TimeRangeProvider(props) {
33
- const { initialTimeRange , initialRefreshInterval , enabledURLParams , children } = props;
34
- const { timeRange , setTimeRange } = useSetTimeRangeParams(initialTimeRange, enabledURLParams);
35
- const { refreshInterval , setRefreshInterval , refreshIntervalInMs } = useSetRefreshIntervalParams(initialRefreshInterval, enabledURLParams);
36
- const [refreshKey, setRefreshKey] = useState(0);
33
+ const { timeRange , refreshInterval , children , setTimeRange , setRefreshInterval } = props;
34
+ const [localTimeRange, setLocalTimeRange] = useState(timeRange);
35
+ const [localRefreshInterval, setLocalefreshInterval] = useState(refreshInterval);
36
+ const [refreshCounter, setRefreshCounter] = useState(0);
37
+ useEffect(()=>{
38
+ setLocalTimeRange(timeRange);
39
+ }, [
40
+ timeRange
41
+ ]);
42
+ useEffect(()=>{
43
+ setLocalefreshInterval(refreshInterval);
44
+ }, [
45
+ refreshInterval
46
+ ]);
37
47
  const refresh = useCallback(()=>{
38
- setRefreshKey(refreshKey + 1);
48
+ setRefreshCounter((counter)=>counter + 1);
39
49
  }, [
40
- refreshKey
50
+ setRefreshCounter
41
51
  ]);
42
52
  const ctx = useMemo(()=>{
43
- const absoluteTimeRange = isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange;
53
+ const absoluteTimeRange = isRelativeTimeRange(localTimeRange) ? toAbsoluteTimeRange(localTimeRange) : localTimeRange;
44
54
  return {
45
- timeRange,
46
- setTimeRange,
55
+ timeRange: localTimeRange,
56
+ setTimeRange: setTimeRange !== null && setTimeRange !== void 0 ? setTimeRange : setLocalTimeRange,
47
57
  absoluteTimeRange,
48
58
  refresh,
49
- refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${refreshInterval}:${refreshKey}`,
50
- refreshInterval,
51
- refreshIntervalInMs,
52
- setRefreshInterval
59
+ refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${localRefreshInterval}:${refreshCounter}`,
60
+ refreshInterval: localRefreshInterval,
61
+ refreshIntervalInMs: getRefreshIntervalInMs(localRefreshInterval),
62
+ setRefreshInterval: setRefreshInterval !== null && setRefreshInterval !== void 0 ? setRefreshInterval : setLocalefreshInterval
53
63
  };
54
64
  }, [
55
- timeRange,
65
+ localTimeRange,
56
66
  setTimeRange,
57
67
  refresh,
58
- refreshKey,
59
- refreshInterval,
60
- refreshIntervalInMs,
68
+ refreshCounter,
69
+ localRefreshInterval,
61
70
  setRefreshInterval
62
71
  ]);
63
72
  return /*#__PURE__*/ _jsx(TimeRangeContext.Provider, {
@@ -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 {\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,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,SAASC,OAAO,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,aAAa,EAAEC,UAAU,QAAQ,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ors\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, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';\nimport {\n AbsoluteTimeRange,\n DurationString,\n TimeRangeValue,\n isRelativeTimeRange,\n toAbsoluteTimeRange,\n} from '@perses-dev/core';\nimport { getRefreshIntervalInMs } from './refresh-interval';\n\nexport interface TimeRangeProviderProps {\n timeRange: TimeRangeValue;\n refreshInterval?: DurationString;\n setTimeRange?: (value: TimeRangeValue) => void;\n setRefreshInterval?: (value: DurationString) => void;\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 { timeRange, refreshInterval, children, setTimeRange, setRefreshInterval } = props;\n\n const [localTimeRange, setLocalTimeRange] = useState<TimeRangeValue>(timeRange);\n const [localRefreshInterval, setLocalefreshInterval] = useState<DurationString | undefined>(refreshInterval);\n\n const [refreshCounter, setRefreshCounter] = useState(0);\n\n useEffect(() => {\n setLocalTimeRange(timeRange);\n }, [timeRange]);\n\n useEffect(() => {\n setLocalefreshInterval(refreshInterval);\n }, [refreshInterval]);\n\n const refresh = useCallback(() => {\n setRefreshCounter((counter) => counter + 1);\n }, [setRefreshCounter]);\n\n const ctx = useMemo(() => {\n const absoluteTimeRange = isRelativeTimeRange(localTimeRange)\n ? toAbsoluteTimeRange(localTimeRange)\n : localTimeRange;\n return {\n timeRange: localTimeRange,\n setTimeRange: setTimeRange ?? setLocalTimeRange,\n absoluteTimeRange,\n refresh,\n refreshKey: `${absoluteTimeRange.start}:${absoluteTimeRange.end}:${localRefreshInterval}:${refreshCounter}`,\n refreshInterval: localRefreshInterval,\n refreshIntervalInMs: getRefreshIntervalInMs(localRefreshInterval),\n setRefreshInterval: setRefreshInterval ?? setLocalefreshInterval,\n };\n }, [localTimeRange, setTimeRange, refresh, refreshCounter, localRefreshInterval, setRefreshInterval]);\n\n return <TimeRangeContext.Provider value={ctx}>{children}</TimeRangeContext.Provider>;\n}\n"],"names":["React","createContext","useCallback","useContext","useEffect","useMemo","useState","isRelativeTimeRange","toAbsoluteTimeRange","getRefreshIntervalInMs","TimeRangeContext","undefined","useTimeRangeContext","ctx","Error","useTimeRange","TimeRangeProvider","props","timeRange","refreshInterval","children","setTimeRange","setRefreshInterval","localTimeRange","setLocalTimeRange","localRefreshInterval","setLocalefreshInterval","refreshCounter","setRefreshCounter","refresh","counter","absoluteTimeRange","refreshKey","start","end","refreshIntervalInMs","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,OAAOA,SAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAA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cQ;QAASF;QAAgBF;QAAsBH;KAAmB;IAEpG,qBAAO,KAACZ,iBAAiB0B;QAASC,OAAOxB;kBAAMO;;AACjD"}
@@ -0,0 +1,9 @@
1
+ import { DurationString, TimeRangeValue } from '@perses-dev/core';
2
+ import React from 'react';
3
+ export interface TimeRangeFromQueryProps {
4
+ initialTimeRange: TimeRangeValue;
5
+ initialRefreshInterval?: DurationString;
6
+ children?: React.ReactNode;
7
+ }
8
+ export declare function TimeRangeProviderWithQueryParams(props: TimeRangeFromQueryProps): JSX.Element;
9
+ //# sourceMappingURL=TimeRangeProviderWithQueryParams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeRangeProviderWithQueryParams.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,uBAAuB;IACtC,gBAAgB,EAAE,cAAc,CAAC;IACjC,sBAAsB,CAAC,EAAE,cAAc,CAAC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,uBAAuB,eAgB9E"}
@@ -0,0 +1,30 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import React from 'react';
15
+ import { TimeRangeProvider } from './TimeRangeProvider';
16
+ import { useSetRefreshIntervalParams, useTimeRangeParams } from './query-params';
17
+ export function TimeRangeProviderWithQueryParams(props) {
18
+ const { initialTimeRange , initialRefreshInterval , children } = props;
19
+ const { timeRange , setTimeRange } = useTimeRangeParams(initialTimeRange);
20
+ const { refreshInterval , setRefreshInterval } = useSetRefreshIntervalParams(initialRefreshInterval);
21
+ return /*#__PURE__*/ _jsx(TimeRangeProvider, {
22
+ timeRange: timeRange,
23
+ refreshInterval: refreshInterval,
24
+ setTimeRange: setTimeRange,
25
+ setRefreshInterval: setRefreshInterval,
26
+ children: children
27
+ });
28
+ }
29
+
30
+ //# sourceMappingURL=TimeRangeProviderWithQueryParams.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.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 { DurationString, TimeRangeValue } from '@perses-dev/core';\nimport React from 'react';\nimport { TimeRangeProvider } from './TimeRangeProvider';\nimport { useSetRefreshIntervalParams, useTimeRangeParams } from './query-params';\n\nexport interface TimeRangeFromQueryProps {\n initialTimeRange: TimeRangeValue;\n initialRefreshInterval?: DurationString;\n children?: React.ReactNode;\n}\n\nexport function TimeRangeProviderWithQueryParams(props: TimeRangeFromQueryProps) {\n const { initialTimeRange, initialRefreshInterval, children } = props;\n\n const { timeRange, setTimeRange } = useTimeRangeParams(initialTimeRange);\n const { refreshInterval, setRefreshInterval } = useSetRefreshIntervalParams(initialRefreshInterval);\n\n return (\n <TimeRangeProvider\n timeRange={timeRange}\n refreshInterval={refreshInterval}\n setTimeRange={setTimeRange}\n setRefreshInterval={setRefreshInterval}\n >\n {children}\n </TimeRangeProvider>\n );\n}\n"],"names":["React","TimeRangeProvider","useSetRefreshIntervalParams","useTimeRangeParams","TimeRangeProviderWithQueryParams","props","initialTimeRange","initialRefreshInterval","children","timeRange","setTimeRange","refreshInterval","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;;AAGjC,OAAOA,WAAW,QAAQ;AAC1B,SAASC,iBAAiB,QAAQ,sBAAsB;AACxD,SAASC,2BAA2B,EAAEC,kBAAkB,QAAQ,iBAAiB;AAQjF,OAAO,SAASC,iCAAiCC,KAA8B;IAC7E,MAAM,EAAEC,iBAAgB,EAAEC,uBAAsB,EAAEC,SAAQ,EAAE,GAAGH;IAE/D,MAAM,EAAEI,UAAS,EAAEC,aAAY,EAAE,GAAGP,mBAAmBG;IACvD,MAAM,EAAEK,gBAAe,EAAEC,mBAAkB,EAAE,GAAGV,4BAA4BK;IAE5E,qBACE,KAACN;QACCQ,WAAWA;QACXE,iBAAiBA;QACjBD,cAAcA;QACdE,oBAAoBA;kBAEnBJ;;AAGP"}
@@ -1,3 +1,4 @@
1
1
  export * from './TimeRangeProvider';
2
+ export * from './TimeRangeProviderWithQueryParams';
2
3
  export * from './query-params';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oCAAoC,CAAC;AACnD,cAAc,gBAAgB,CAAC"}
@@ -11,6 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  export * from './TimeRangeProvider';
14
+ export * from './TimeRangeProviderWithQueryParams';
14
15
  export * from './query-params';
15
16
 
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './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,sBAAsB;AACpC,cAAc,iBAAiB"}
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './TimeRangeProvider';\nexport * from './TimeRangeProviderWithQueryParams';\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,sBAAsB;AACpC,cAAc,qCAAqC;AACnD,cAAc,iBAAiB"}
@@ -22,16 +22,16 @@ export declare const refreshIntervalQueryConfig: {
22
22
  */
23
23
  export declare function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue;
24
24
  /**
25
- * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization
25
+ * Returns time range getter and setter, taking the URL query params.
26
26
  */
27
- export declare function useSetTimeRangeParams(initialTimeRange: TimeRangeValue, enabledURLParams?: boolean): Pick<TimeRange, 'timeRange' | 'setTimeRange'>;
27
+ export declare function useTimeRangeParams(initialTimeRange: TimeRangeValue): Pick<TimeRange, 'timeRange' | 'setTimeRange'>;
28
28
  /**
29
29
  * Gets the initial refresh interval taking into account URL params and dashboard JSON duration
30
30
  * Sets refresh query param if it is empty on page load
31
31
  */
32
32
  export declare function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString;
33
33
  /**
34
- * Returns refresh interval getter and setter, set enabledURLParams to false to disable query string serialization
34
+ * Returns refresh interval getter and setter, taking the URL query params.
35
35
  */
36
- export declare function useSetRefreshIntervalParams(initialRefreshInterval?: DurationString, enabledURLParams?: boolean): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval' | 'refreshIntervalInMs'>;
36
+ export declare function useSetRefreshIntervalParams(initialRefreshInterval?: DurationString): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval'>;
37
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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BAAgB,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,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"}
@@ -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, parseDurationString } from '@perses-dev/core';
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
18
  if (input == null) {
19
19
  return input;
@@ -100,20 +100,17 @@ export const refreshIntervalQueryConfig = {
100
100
  ]);
101
101
  }
102
102
  /**
103
- * Returns time range getter and setter, set enabledURLParams to false to disable query string serialization
104
- */ export function useSetTimeRangeParams(initialTimeRange, enabledURLParams = true) {
103
+ * Returns time range getter and setter, taking the URL query params.
104
+ */ export function useTimeRangeParams(initialTimeRange) {
105
105
  const [query, setQuery] = useQueryParams(timeRangeQueryConfig, {
106
106
  updateType: 'replaceIn'
107
107
  });
108
108
  // determine whether initial param had previously been populated to fix back btn
109
109
  const [paramsLoaded, setParamsLoaded] = useState(false);
110
- // optional fallback when app does not want query string as source of truth
111
- // this occurs when enabledURLParams is set to false on TimeRangeProvider
112
- const [timeRangeState, setTimeRangeState] = useState(initialTimeRange);
113
110
  const { start } = query;
114
111
  useEffect(()=>{
115
112
  // when dashboard loaded with no params, default to dashboard duration
116
- if (enabledURLParams && !paramsLoaded && !start) {
113
+ if (!paramsLoaded && !start) {
117
114
  if (isRelativeTimeRange(initialTimeRange)) {
118
115
  setQuery({
119
116
  start: initialTimeRange.pastDuration,
@@ -124,7 +121,6 @@ export const refreshIntervalQueryConfig = {
124
121
  }
125
122
  }, [
126
123
  initialTimeRange,
127
- enabledURLParams,
128
124
  paramsLoaded,
129
125
  start,
130
126
  setQuery
@@ -141,12 +137,6 @@ export const refreshIntervalQueryConfig = {
141
137
  }, [
142
138
  setQuery
143
139
  ]);
144
- if (!enabledURLParams) {
145
- return {
146
- timeRange: timeRangeState,
147
- setTimeRange: setTimeRangeState
148
- };
149
- }
150
140
  return {
151
141
  timeRange: initialTimeRange,
152
142
  setTimeRange: setTimeRange
@@ -175,31 +165,18 @@ export const refreshIntervalQueryConfig = {
175
165
  refresh
176
166
  ]);
177
167
  }
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
168
  /**
189
- * Returns refresh interval getter and setter, set enabledURLParams to false to disable query string serialization
190
- */ export function useSetRefreshIntervalParams(initialRefreshInterval, enabledURLParams = true) {
169
+ * Returns refresh interval getter and setter, taking the URL query params.
170
+ */ export function useSetRefreshIntervalParams(initialRefreshInterval) {
191
171
  const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, {
192
172
  updateType: 'replaceIn'
193
173
  });
194
174
  // determine whether initial param had previously been populated to fix back btn
195
175
  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
176
  const { refresh } = query;
200
177
  useEffect(()=>{
201
178
  // when dashboard loaded with no params, default to dashboard refresh interval
202
- if (enabledURLParams && !paramsLoaded && !refresh) {
179
+ if (!paramsLoaded && !refresh) {
203
180
  setQuery({
204
181
  refresh: initialRefreshInterval
205
182
  });
@@ -207,7 +184,6 @@ function getRefreshIntervalInMs(refreshInterval) {
207
184
  }
208
185
  }, [
209
186
  initialRefreshInterval,
210
- enabledURLParams,
211
187
  paramsLoaded,
212
188
  refresh,
213
189
  setQuery
@@ -217,17 +193,9 @@ function getRefreshIntervalInMs(refreshInterval) {
217
193
  }), [
218
194
  setQuery
219
195
  ]);
220
- if (!enabledURLParams) {
221
- return {
222
- refreshInterval: refreshIntervalState,
223
- setRefreshInterval: setRefreshIntervalState,
224
- refreshIntervalInMs: getRefreshIntervalInMs(refreshIntervalState)
225
- };
226
- }
227
196
  return {
228
197
  refreshInterval: initialRefreshInterval,
229
- setRefreshInterval: setRefreshInterval,
230
- refreshIntervalInMs: getRefreshIntervalInMs(initialRefreshInterval)
198
+ setRefreshInterval: setRefreshInterval
231
199
  };
232
200
  }
233
201
 
@@ -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 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 refresh interval\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,QAAQ;AAClE,SAASC,cAAc,QAA0B,mBAAmB;AACpE,SAASC,WAAW,EAAEC,MAAM,QAAQ,WAAW;AAC/C,SAEEC,mBAAmB,EACnBC,gBAAgB,EAGhBC,mBAAmB,QACd,mBAAmB;AAK1B,iGAAiG,GACjG,SAASC,gBACPC,KAAuD,EACvDC,gBAA0B;IAE1B,IAAID,SAAS,MAAM;QACjB,OAAOA;IACT;IACA,WAAW;IACX,IAAIA,MAAME,WAAW,KAAM,CAAA,CAACD,oBAAqBA,oBAAoBD,UAAU,EAAE,GAAI;QACnF,OAAO;IACT;IAEA,MAAMG,MAAMH,iBAAiBI,QAAQJ,KAAK,CAAC,EAAE,GAAGA;IAChD,IAAIG,OAAO,MAAM;QACf,OAAOA;IACT;IACA,IAAI,CAACF,oBAAoBE,QAAQ,IAAI;QACnC,OAAO;IACT;IAEA,OAAOA;AACT;AAEA,mGAAmG,GACnG,OAAO,SAASE,qBAAqBC,eAAgC;IACnE,IAAI,CAACA,iBAAiB;QACpB,OAAOA;IACT;IAEA,IAAI,OAAOA,oBAAoB,UAAU;QACvC,IAAIT,iBAAiBS,kBAAkB;YACrC,OAAOA;QACT;IACF;IACA,OAAO,AAACZ,CAAAA,YAAYY,mBAAmB,IAAG,EAAGC;AAC/C;AAEA,4EAA4E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,2BAA2BA,wBAAwBC,SAAS;YAC9DF,sBAAsBC,CAAAA,oCAAAA,qCAAAA,KAAAA,IAAAA,wBAAyBC,OAAM,IAAI;QAC3D;IACF;IACA,OAAOF;AACT;AAEA;;CAEC,GACD,OAAO,SAASG,4BACdC,sBAAuC,EACvCjB,mBAAmB,IAAI;IAEvB,MAAM,CAACN,OAAOO,SAAS,GAAGxC,eAAe6B,4BAA4B;QAAEK,YAAY;IAAY;IAE/F,gFAAgF;IAChF,MAAM,CAACO,cAAcC,gBAAgB,GAAG3C,SAAkB;IAE1D,2EAA2E;IAC3E,yEAAyE;IACzE,MAAM,CAAC0D,sBAAsBC,wBAAwB,GAAG3D,SAAqCyD;IAE7F,MAAM,EAAE1B,QAAO,EAAE,GAAGG;IAEpBnC,UAAU;QACR,8EAA8E;QAC9E,IAAIyC,oBAAoB,CAACE,gBAAgB,CAACX,SAAS;YACjDU,SAAS;gBAAEV,SAAS0B;YAAuB;YAC3Cd,gBAAgB;QAClB;IACF,GAAG;QAACc;QAAwBjB;QAAkBE;QAAcX;QAASU;KAAS;IAE9E,MAAMmB,qBAAsD9D,YAC1D,CAACiC,UAA4BU,SAAS;YAAEV;QAAQ,IAChD;QAACU;KAAS;IAGZ,IAAI,CAACD,kBAAkB;QACrB,OAAO;YACLY,iBAAiBM;YACjBE,oBAAoBD;YACpBN,qBAAqBF,uBAAuBO;QAC9C;IACF;IACA,OAAO;QACLN,iBAAiBK;QACjBG,oBAAoBA;QACpBP,qBAAqBF,uBAAuBM;IAC9C;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 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,WAAW;IACX,IAAIA,MAAME,WAAW,KAAM,CAAA,CAACD,oBAAqBA,oBAAoBD,UAAU,EAAE,GAAI;QACnF,OAAO;IACT;IAEA,MAAMG,MAAMH,iBAAiBI,QAAQJ,KAAK,CAAC,EAAE,GAAGA;IAChD,IAAIG,OAAO,MAAM;QACf,OAAOA;IACT;IACA,IAAI,CAACF,oBAAoBE,QAAQ,IAAI;QACnC,OAAO;IACT;IAEA,OAAOA;AACT;AAEA,mGAAmG,GACnG,OAAO,SAASE,qBAAqBC,eAAgC;IACnE,IAAI,CAACA,iBAAiB;QACpB,OAAOA;IACT;IAEA,IAAI,OAAOA,oBAAoB,UAAU;QACvC,IAAIR,iBAAiBQ,kBAAkB;YACrC,OAAOA;QACT;IACF;IACA,OAAO,AAACX,CAAAA,YAAYW,mBAAmB,IAAG,EAAGC;AAC/C;AAEA,4EAA4E,GAC5E,OAAO,SAASC,qBACdR,KAAuD;IAEvD,MAAMS,cAAcV,gBAAgBC;IACpC,IAAIS,eAAe,MAAM,OAAOA;IAChC,OAAOX,iBAAiBW,eAAeA,cAAc,IAAIC,K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AAQ,IAChD;QAACS;KAAS;IAGZ,OAAO;QACLW,iBAAiBF;QACjBC,oBAAoBA;IACtB;AACF"}
@@ -0,0 +1,7 @@
1
+ import { DurationString } from '@perses-dev/core';
2
+ /**
3
+ * Utils function to transform a refresh interval in {@link DurationString} format into a number of ms.
4
+ * @param refreshInterval
5
+ */
6
+ export declare function getRefreshIntervalInMs(refreshInterval?: DurationString): number;
7
+ //# sourceMappingURL=refresh-interval.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"refresh-interval.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/refresh-interval.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AAGvE;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,eAAe,CAAC,EAAE,cAAc,UAKtE"}
@@ -0,0 +1,25 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { parseDurationString } from '@perses-dev/core';
14
+ import { milliseconds } from 'date-fns';
15
+ /**
16
+ * Utils function to transform a refresh interval in {@link DurationString} format into a number of ms.
17
+ * @param refreshInterval
18
+ */ export function getRefreshIntervalInMs(refreshInterval) {
19
+ if (refreshInterval !== undefined && refreshInterval !== null) {
20
+ return milliseconds(parseDurationString(refreshInterval));
21
+ }
22
+ return 0;
23
+ }
24
+
25
+ //# sourceMappingURL=refresh-interval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/runtime/TimeRangeProvider/refresh-interval.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 { DurationString, parseDurationString } from '@perses-dev/core';\nimport { milliseconds } from 'date-fns';\n\n/**\n * Utils function to transform a refresh interval in {@link DurationString} format into a number of ms.\n * @param refreshInterval\n */\nexport function getRefreshIntervalInMs(refreshInterval?: DurationString) {\n if (refreshInterval !== undefined && refreshInterval !== null) {\n return milliseconds(parseDurationString(refreshInterval));\n }\n return 0;\n}\n"],"names":["parseDurationString","milliseconds","getRefreshIntervalInMs","refreshInterval","undefined"],"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,SAAyBA,mBAAmB,QAAQ,mBAAmB;AACvE,SAASC,YAAY,QAAQ,WAAW;AAExC;;;CAGC,GACD,OAAO,SAASC,uBAAuBC,eAAgC;IACrE,IAAIA,oBAAoBC,aAAaD,oBAAoB,MAAM;QAC7D,OAAOF,aAAaD,oBAAoBG;IAC1C;IACA,OAAO;AACT"}