@perses-dev/plugin-system 0.41.0 → 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.
- package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +26 -55
- package/dist/cjs/components/DatasourceSelect.js +22 -10
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +1 -0
- package/dist/cjs/components/PluginEditor/PluginEditor.js +2 -1
- package/dist/cjs/components/ProjectSelect.js +96 -0
- package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +14 -12
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +50 -2
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +11 -8
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/ProjectStoreProvider.js +78 -0
- package/dist/cjs/context/index.js +30 -0
- package/dist/cjs/context/query-params.js +49 -0
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/model/index.js +1 -0
- package/dist/cjs/model/trace-queries.js +16 -0
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +17 -5
- package/dist/cjs/runtime/DataQueriesProvider/model.js +27 -7
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +27 -18
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js +43 -0
- package/dist/cjs/runtime/TimeRangeProvider/index.js +1 -0
- package/dist/cjs/runtime/TimeRangeProvider/query-params.js +7 -39
- package/dist/cjs/runtime/TimeRangeProvider/refresh-interval.js +30 -0
- package/dist/cjs/runtime/datasources.js +3 -2
- package/dist/cjs/runtime/index.js +1 -0
- package/dist/cjs/runtime/trace-queries.js +59 -0
- package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +2 -1
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +12 -0
- package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +2 -2
- package/dist/cjs/test/mock-data.js +26 -3
- package/dist/cjs/validation/role.js +85 -0
- package/dist/cjs/validation/rolebinding.js +55 -0
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +7 -7
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +26 -16
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/DatasourceSelect.d.ts +1 -0
- package/dist/components/DatasourceSelect.d.ts.map +1 -1
- package/dist/components/DatasourceSelect.js +22 -10
- package/dist/components/DatasourceSelect.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +1 -0
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +2 -1
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +1 -0
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/ProjectSelect.d.ts +15 -0
- package/dist/components/ProjectSelect.d.ts.map +1 -0
- package/dist/components/ProjectSelect.js +91 -0
- package/dist/components/ProjectSelect.js.map +1 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +1 -1
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +15 -13
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +1 -2
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +50 -2
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +2 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +11 -8
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/ProjectStoreProvider.d.ts +16 -0
- package/dist/context/ProjectStoreProvider.d.ts.map +1 -0
- package/dist/context/ProjectStoreProvider.js +56 -0
- package/dist/context/ProjectStoreProvider.js.map +1 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/context/index.d.ts.map +1 -0
- package/dist/context/index.js +15 -0
- package/dist/context/index.js.map +1 -0
- package/dist/context/query-params.d.ts +5 -0
- package/dist/context/query-params.d.ts.map +1 -0
- package/dist/context/query-params.js +41 -0
- package/dist/context/query-params.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.d.ts.map +1 -1
- package/dist/model/index.js +1 -0
- package/dist/model/index.js.map +1 -1
- package/dist/model/plugin-base.d.ts +1 -0
- package/dist/model/plugin-base.d.ts.map +1 -1
- package/dist/model/plugin-base.js.map +1 -1
- package/dist/model/plugins.d.ts +2 -0
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/model/trace-queries.d.ts +18 -0
- package/dist/model/trace-queries.d.ts.map +1 -0
- package/dist/model/trace-queries.js +15 -0
- package/dist/model/trace-queries.js.map +1 -0
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +17 -5
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +27 -7
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +4 -3
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +28 -19
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts +9 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.d.ts.map +1 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js +30 -0
- package/dist/runtime/TimeRangeProvider/TimeRangeProviderWithQueryParams.js.map +1 -0
- package/dist/runtime/TimeRangeProvider/index.d.ts +1 -0
- package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/index.js +1 -0
- package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.d.ts +4 -4
- package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js +8 -40
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts +7 -0
- package/dist/runtime/TimeRangeProvider/refresh-interval.d.ts.map +1 -0
- package/dist/runtime/TimeRangeProvider/refresh-interval.js +25 -0
- package/dist/runtime/TimeRangeProvider/refresh-interval.js.map +1 -0
- package/dist/runtime/datasources.d.ts +29 -2
- package/dist/runtime/datasources.d.ts.map +1 -1
- package/dist/runtime/datasources.js +3 -2
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/trace-queries.d.ts +10 -0
- package/dist/runtime/trace-queries.d.ts.map +1 -0
- package/dist/runtime/trace-queries.js +47 -0
- package/dist/runtime/trace-queries.js.map +1 -0
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +2 -1
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +12 -0
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +2 -2
- package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +1 -1
- package/dist/stories/shared-utils/decorators/WithTimeRange.js +2 -2
- package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
- package/dist/test/mock-data.d.ts +2 -1
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js +15 -0
- package/dist/test/mock-data.js.map +1 -1
- package/dist/utils/action.d.ts +1 -1
- package/dist/utils/action.d.ts.map +1 -1
- package/dist/utils/action.js.map +1 -1
- package/dist/validation/role.d.ts +228 -0
- package/dist/validation/role.d.ts.map +1 -0
- package/dist/validation/role.js +66 -0
- package/dist/validation/role.js.map +1 -0
- package/dist/validation/rolebinding.d.ts +137 -0
- package/dist/validation/rolebinding.d.ts.map +1 -0
- package/dist/validation/rolebinding.js +47 -0
- package/dist/validation/rolebinding.js.map +1 -0
- 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,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,qB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AAC;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
|
|
36
|
-
(
|
|
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
|
-
|
|
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
|
-
|
|
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('
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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,
|
|
1
|
+
{"version":3,"file":"TimeRangeProvider.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/TimeRangeProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAA+E,MAAM,OAAO,CAAC;AACpG,OAAO,EACL,iBAAiB,EACjB,cAAc,EACd,cAAc,EAGf,MAAM,kBAAkB,CAAC;AAG1B,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,cAAc,CAAC;IAC1B,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC/C,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,cAAc,CAAC;IAC1B,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,YAAY,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;IAC9C,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,eAAe,CAAC,EAAE,cAAc,CAAC;IACjC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,kBAAkB,EAAE,CAAC,KAAK,EAAE,cAAc,KAAK,IAAI,CAAC;CACrD;AAED,eAAO,MAAM,gBAAgB,sCAAkD,CAAC;AAEhF,wBAAgB,mBAAmB,cAMlC;AAED;;GAEG;AACH,wBAAgB,YAAY,IAAI,SAAS,CAExC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,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, {
|
|
14
|
+
import React, { createContext, useCallback, useContext, useEffect, useMemo, useState } from 'react';
|
|
15
15
|
import { isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/core';
|
|
16
|
-
import {
|
|
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 {
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const [
|
|
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
|
-
|
|
48
|
+
setRefreshCounter((counter)=>counter + 1);
|
|
39
49
|
}, [
|
|
40
|
-
|
|
50
|
+
setRefreshCounter
|
|
41
51
|
]);
|
|
42
52
|
const ctx = useMemo(()=>{
|
|
43
|
-
const absoluteTimeRange = isRelativeTimeRange(
|
|
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}:${
|
|
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
|
-
|
|
65
|
+
localTimeRange,
|
|
56
66
|
setTimeRange,
|
|
57
67
|
refresh,
|
|
58
|
-
|
|
59
|
-
|
|
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, {
|
|
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, { 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,QAAQ,QAAQ;AACpG,SAIEC,mBAAmB,EACnBC,mBAAmB,QACd,mBAAmB;AAC1B,SAASC,sBAAsB,QAAQ,qBAAqB;AAqB5D,OAAO,MAAMC,iCAAmBT,cAAqCU,WAAW;AAEhF,OAAO,SAASC;IACd,MAAMC,MAAMV,WAAWO;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;CAEC,GACD,OAAO,SAASE;IACd,OAAOH;AACT;AAEA;;CAEC,GACD,OAAO,SAASI,kBAAkBC,KAA6B;IAC7D,MAAM,EAAEC,UAAS,EAAEC,gBAAe,EAAEC,SAAQ,EAAEC,aAAY,EAAEC,mBAAkB,EAAE,GAAGL;IAEnF,MAAM,CAACM,gBAAgBC,kBAAkB,GAAGlB,SAAyBY;IACrE,MAAM,CAACO,sBAAsBC,uBAAuB,GAAGpB,SAAqCa;IAE5F,MAAM,CAACQ,gBAAgBC,kBAAkB,GAAGtB,SAAS;IAErDF,UAAU;QACRoB,kBAAkBN;IACpB,GAAG;QAACA;KAAU;IAEdd,UAAU;QACRsB,uBAAuBP;IACzB,GAAG;QAACA;KAAgB;IAEpB,MAAMU,UAAU3B,YAAY;QAC1B0B,kBAAkB,CAACE,UAAYA,UAAU;IAC3C,GAAG;QAACF;KAAkB;IAEtB,MAAMf,MAAMR,QAAQ;QAClB,MAAM0B,oBAAoBxB,oBAAoBgB,kBAC1Cf,oBAAoBe,kBACpBA;QACJ,OAAO;YACLL,WAAWK;YACXF,cAAcA,yBAAAA,0BAAAA,eAAgBG;YAC9BO;YACAF;YACAG,YAAY,CAAC,EAAED,kBAAkBE,MAAM,CAAC,EAAEF,kBAAkBG,IAAI,CAAC,EAAET,qBAAqB,CAAC,EAAEE,eAAe,CAAC;YAC3GR,iBAAiBM;YACjBU,qBAAqB1B,uBAAuBgB;YAC5CH,oBAAoBA,+BAAAA,gCAAAA,qBAAsBI;QAC5C;IACF,GAAG;QAACH;QAAgBF;QAAcQ;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 +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,
|
|
25
|
+
* Returns time range getter and setter, taking the URL query params.
|
|
26
26
|
*/
|
|
27
|
-
export declare function
|
|
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,
|
|
34
|
+
* Returns refresh interval getter and setter, taking the URL query params.
|
|
35
35
|
*/
|
|
36
|
-
export declare function useSetRefreshIntervalParams(initialRefreshInterval?: DurationString
|
|
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,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EACL,cAAc,EAGd,cAAc,
|
|
1
|
+
{"version":3,"file":"query-params.d.ts","sourceRoot":"","sources":["../../../src/runtime/TimeRangeProvider/query-params.ts"],"names":[],"mappings":"AAcA,OAAO,EAAkB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EACL,cAAc,EAGd,cAAc,EAEf,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,oBAAY,eAAe,GAAG,IAAI,GAAG,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;AA2BvE,wBAAgB,oBAAoB,CAAC,eAAe,EAAE,eAAe,GAAG,MAAM,GAAG,IAAI,GAAG,SAAS,CAWhG;AAGD,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,IAAI,GAAG,SAAS,GACtD,IAAI,GAAG,cAAc,GAAG,IAAI,GAAG,SAAS,CAI1C;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,gBAAgB,CAAC,eAAe,EAAE,eAAe,CAQ7E,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;CAGhC,CAAC;AAEF,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
|
|
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,
|
|
104
|
-
*/ export function
|
|
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 (
|
|
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,
|
|
190
|
-
*/ export function useSetRefreshIntervalParams(initialRefreshInterval
|
|
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 (
|
|
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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
|
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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GzC,SAAkB;IAE1D,MAAM,EAAE8B,QAAO,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"}
|
|
@@ -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"}
|