@perses-dev/plugin-system 0.55.0-beta.9 → 0.55.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.js +0 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
- package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.d.ts.map +1 -1
- package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.js +2 -7
- package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.js.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPProxyOAuthPassthroughEditor.d.ts +11 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyOAuthPassthroughEditor.d.ts.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyOAuthPassthroughEditor.js +62 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyOAuthPassthroughEditor.js.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyTimeoutEditor.d.ts +11 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyTimeoutEditor.d.ts.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyTimeoutEditor.js +58 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyTimeoutEditor.js.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +44 -15
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.d.ts.map +1 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +7 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js.map +1 -1
- package/dist/components/LinksEditor/LinksEditor.js +5 -0
- package/dist/components/LinksEditor/LinksEditor.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +4 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +7 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +54 -41
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +14 -0
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +187 -23
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +72 -7
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +6 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js +6 -2
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +0 -2
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/variable-model.d.ts.map +1 -1
- package/dist/components/Variables/variable-model.js +7 -2
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/model/datasource.d.ts +3 -0
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/plugin-loading.d.ts +1 -0
- package/dist/model/plugin-loading.d.ts.map +1 -1
- package/dist/model/plugin-loading.js.map +1 -1
- package/dist/model/plugins.d.ts +11 -0
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/remote/PluginLoaderComponent.d.ts.map +1 -1
- package/dist/remote/PluginLoaderComponent.js +28 -15
- package/dist/remote/PluginLoaderComponent.js.map +1 -1
- package/dist/remote/PluginRuntime.d.ts.map +1 -1
- package/dist/remote/PluginRuntime.js +32 -24
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/remote/remotePluginLoader.d.ts.map +1 -1
- package/dist/remote/remotePluginLoader.js +1 -0
- package/dist/remote/remotePluginLoader.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +21 -15
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +23 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts +3 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js +2 -2
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js +7 -9
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
- package/dist/runtime/UsageMetricsProvider.js +24 -20
- package/dist/runtime/UsageMetricsProvider.js.map +1 -1
- package/dist/runtime/alerts-queries.d.ts.map +1 -1
- package/dist/runtime/alerts-queries.js +6 -2
- package/dist/runtime/alerts-queries.js.map +1 -1
- package/dist/runtime/annotations.d.ts +8 -0
- package/dist/runtime/annotations.d.ts.map +1 -1
- package/dist/runtime/annotations.js +47 -83
- package/dist/runtime/annotations.js.map +1 -1
- package/dist/runtime/datasources.d.ts +4 -0
- package/dist/runtime/datasources.d.ts.map +1 -1
- package/dist/runtime/datasources.js +4 -3
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/log-queries.d.ts.map +1 -1
- package/dist/runtime/log-queries.js +3 -1
- package/dist/runtime/log-queries.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +23 -8
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +52 -16
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/profile-queries.d.ts.map +1 -1
- package/dist/runtime/profile-queries.js +3 -1
- package/dist/runtime/profile-queries.js.map +1 -1
- package/dist/runtime/silences-queries.d.ts.map +1 -1
- package/dist/runtime/silences-queries.js +6 -2
- package/dist/runtime/silences-queries.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +10 -3
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.d.ts.map +1 -1
- package/dist/runtime/trace-queries.js +6 -2
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/runtime/variables.d.ts +6 -0
- package/dist/runtime/variables.d.ts.map +1 -1
- package/dist/runtime/variables.js +17 -1
- package/dist/runtime/variables.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/plugin-versions.d.ts +18 -0
- package/dist/utils/plugin-versions.d.ts.map +1 -0
- package/dist/utils/plugin-versions.js +52 -0
- package/dist/utils/plugin-versions.js.map +1 -0
- package/package.json +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/alerts-queries.ts"],"sourcesContent":["// Copyright 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 type { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;\nexport const ALERTS_QUERY_KEY = 'AlertsQuery';\n\n/**\n * Run an alerts query using an AlertsQuery plugin and return the results.\n * Alerts represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for an alerts query\n */\nexport function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAlertsQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'AlertsQuery',\n definitions.map((d) => ({
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/alerts-queries.ts"],"sourcesContent":["// Copyright 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 type { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;\nexport const ALERTS_QUERY_KEY = 'AlertsQuery';\n\n/**\n * Run an alerts query using an AlertsQuery plugin and return the results.\n * Alerts represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for an alerts query\n */\nexport function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAlertsQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'AlertsQuery',\n definitions.map((d) => ({\n kind: d.spec.plugin.kind,\n version: d.spec.plugin.metadata?.version,\n registry: d.spec.plugin.metadata?.registry,\n })),\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const alertsQueryKind = definition?.spec?.plugin?.kind;\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: 60_000,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<AlertsData> => {\n const plugin = await getPlugin({\n kind: ALERTS_QUERY_KEY,\n name: alertsQueryKind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getAlertsData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n };\n }),\n });\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AlertsQueryPlugin;\n definition: AlertsQueryDefinition;\n context: AlertsQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n // Note: no absoluteTimeRange in query key since alerts are current state\n const queryKey = ['query', ALERTS_QUERY_KEY, definition, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nfunction useAlertsQueryContext(): AlertsQueryContext {\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n };\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","usePlugins","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ALERTS_QUERY_KEY","useAlertsQueries","definitions","getPlugin","context","useAlertsQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","version","metadata","registry","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","alertsQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","queryFn","signal","name","getAlertsData","variableState","dependencies","dependsOn","variableDependencies","variables","filteredVariabledState","variablesValueKey","waitToLoad","some","v","loading","undefined","datasourceStore"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,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AMI,OAAO,MAAMP,OAAOoB,aAAa,CAACf,WAAWN,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,SAASyB;oBAC9E,OAAOX;gBACT;YACF;QACF;IACF;AACF;AAEA,SAASG,gBAAgB,EACvBV,MAAM,EACNK,UAAU,EACVZ,OAAO,EAKR;IAIC,MAAM,EAAE4B,aAAa,EAAE,GAAG5B;IAE1B,MAAM6B,eAAetB,QAAQuB,YAAYvB,OAAOuB,SAAS,CAAClB,WAAWN,IAAI,CAACC,MAAM,CAACD,IAAI,EAAEN,WAAW,CAAC;IACnG,MAAM+B,uBAAuBF,cAAcG;IAE3C,MAAMC,yBAAyBxC,uBAAuBmC,eAAeG;IACrE,MAAMG,oBAAoBxC,qBAAqBuC;IAC/C,yEAAyE;IACzE,MAAMjB,WAAW;QAAC;QAASpB;QAAkBgB;QAAYsB;KAAkB;IAE3E,IAAIC,aAAa;IACjB,IAAIJ,sBAAsB;QACxBI,aAAaJ,qBAAqBK,IAAI,CAAC,CAACC,IAAMT,aAAa,CAACS,EAAE,EAAEC;IAClE;IAEA,MAAMvB,eAAeR,WAAWgC,aAAa,CAACJ;IAC9C,OAAO;QACLnB;QACAD;IACF;AACF;AAEA,SAASd;IACP,MAAM2B,gBAAgBjC;IACtB,MAAM6C,kBAAkBlD;IAExB,OAAO;QACLsC;QACAY;IACF;AACF"}
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';
|
|
2
2
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
export declare const ANNOTATION_KEY = "Annotation";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves annotation specs through the shared query cache. Panels requesting the same spec,
|
|
6
|
+
* absolute time range, and variable values share both in-flight requests and cached data with previews.
|
|
7
|
+
*/
|
|
4
8
|
export declare function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>>;
|
|
9
|
+
/**
|
|
10
|
+
* Resolves one annotation spec using the same cache and fetch policy as {@link useAnnotations}.
|
|
11
|
+
* Used by annotation previews; also exposes loading, error, and refetch state to individual consumers.
|
|
12
|
+
*/
|
|
5
13
|
export declare function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]>;
|
|
6
14
|
//# sourceMappingURL=annotations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/runtime/annotations.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/runtime/annotations.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAU7E,eAAO,MAAM,cAAc,eAAe,CAAC;AAgD3C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,CAiBrG;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,CAAC,cAAc,EAAE,CAAC,CAQxF"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { useQueries, useQuery } from "@tanstack/react-query";
|
|
14
14
|
import { useDatasourceStore } from "./datasources.js";
|
|
15
|
-
import { usePlugin,
|
|
15
|
+
import { usePlugin, usePlugins } from "./plugin-registry.js";
|
|
16
16
|
import { useTimeRange } from "./TimeRangeProvider/index.js";
|
|
17
17
|
import { filterVariableStateMap, getVariableValuesKey } from "./utils.js";
|
|
18
18
|
import { useAllVariableValues } from "./variables.js";
|
|
@@ -29,101 +29,65 @@ function useAnnotationContext() {
|
|
|
29
29
|
}
|
|
30
30
|
function getQueryOptions({ plugin, definition, context }) {
|
|
31
31
|
const { variableState, absoluteTimeRange } = context;
|
|
32
|
-
const dependencies = plugin?.dependsOn
|
|
33
|
-
const
|
|
34
|
-
const filteredVariableState = filterVariableStateMap(variableState, variableDependencies);
|
|
32
|
+
const dependencies = plugin?.dependsOn?.(definition.plugin.spec, context);
|
|
33
|
+
const filteredVariableState = filterVariableStateMap(variableState, dependencies?.variables);
|
|
35
34
|
const variablesValueKey = getVariableValuesKey(filteredVariableState);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
definition,
|
|
39
|
-
absoluteTimeRange,
|
|
40
|
-
variablesValueKey
|
|
41
|
-
];
|
|
42
|
-
let waitToLoad = false;
|
|
43
|
-
if (variableDependencies) {
|
|
44
|
-
waitToLoad = variableDependencies.some((v)=>variableState[v]?.loading);
|
|
45
|
-
}
|
|
46
|
-
const queryEnabled = plugin !== undefined && !waitToLoad;
|
|
35
|
+
// Only declared variable dependencies delay the query, like other query plugins.
|
|
36
|
+
const waitToLoad = dependencies?.variables?.some((name)=>variableState[name]?.loading) ?? false;
|
|
47
37
|
return {
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
// ['annotation', spec] prefix: refreshed by TimeRangeProvider and invalidated by the annotation editor preview.
|
|
39
|
+
queryKey: [
|
|
40
|
+
'annotation',
|
|
41
|
+
definition,
|
|
42
|
+
absoluteTimeRange,
|
|
43
|
+
variablesValueKey
|
|
44
|
+
],
|
|
45
|
+
enabled: plugin !== undefined && !waitToLoad,
|
|
46
|
+
refetchOnMount: false,
|
|
47
|
+
refetchOnWindowFocus: false,
|
|
48
|
+
refetchOnReconnect: false,
|
|
49
|
+
staleTime: Infinity,
|
|
50
|
+
queryFn: async ({ signal })=>{
|
|
51
|
+
if (plugin === undefined) {
|
|
52
|
+
throw new Error('Expected annotation plugin to be loaded');
|
|
53
|
+
}
|
|
54
|
+
const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
50
57
|
};
|
|
51
58
|
}
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Resolves annotation specs through the shared query cache. Panels requesting the same spec,
|
|
61
|
+
* absolute time range, and variable values share both in-flight requests and cached data with previews.
|
|
62
|
+
*/ export function useAnnotations(definitions) {
|
|
54
63
|
const context = useAnnotationContext();
|
|
55
64
|
const pluginLoaderResponse = usePlugins('Annotation', definitions.map((d)=>({
|
|
56
|
-
kind: d.plugin.kind
|
|
65
|
+
kind: d.plugin.kind,
|
|
66
|
+
version: d.plugin.metadata?.version,
|
|
67
|
+
registry: d.plugin.metadata?.registry
|
|
57
68
|
})));
|
|
58
|
-
// useQueries() handles data fetching from query plugins
|
|
59
69
|
return useQueries({
|
|
60
|
-
queries: definitions.map((definition,
|
|
61
|
-
const plugin = pluginLoaderResponse[idx]?.data;
|
|
62
|
-
const { queryEnabled, queryKey } = getQueryOptions({
|
|
70
|
+
queries: definitions.map((definition, index)=>getQueryOptions({
|
|
63
71
|
context,
|
|
64
72
|
definition,
|
|
65
|
-
plugin
|
|
66
|
-
})
|
|
67
|
-
const annotationKind = definition?.plugin?.kind;
|
|
68
|
-
return {
|
|
69
|
-
enabled: queryEnabled,
|
|
70
|
-
queryKey: queryKey,
|
|
71
|
-
refetchOnMount: false,
|
|
72
|
-
refetchOnWindowFocus: false,
|
|
73
|
-
refetchOnReconnect: false,
|
|
74
|
-
staleTime: Infinity,
|
|
75
|
-
queryFn: async ({ signal })=>{
|
|
76
|
-
const plugin = await getPlugin({
|
|
77
|
-
kind: ANNOTATION_KEY,
|
|
78
|
-
name: annotationKind
|
|
79
|
-
});
|
|
80
|
-
const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);
|
|
81
|
-
return data;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
})
|
|
73
|
+
plugin: pluginLoaderResponse[index]?.data
|
|
74
|
+
}))
|
|
85
75
|
});
|
|
86
76
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
datasourceStore,
|
|
95
|
-
variableState: allVariables
|
|
96
|
-
};
|
|
97
|
-
let dependsOnVariables = Object.keys(allVariables); // Default to all variables
|
|
98
|
-
if (annotationPlugin?.dependsOn) {
|
|
99
|
-
const dependencies = annotationPlugin.dependsOn(spec.plugin.spec, variablePluginCtx);
|
|
100
|
-
dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;
|
|
101
|
-
}
|
|
102
|
-
const variables = useAllVariableValues(dependsOnVariables);
|
|
103
|
-
let waitToLoad = false;
|
|
104
|
-
if (dependsOnVariables) {
|
|
105
|
-
waitToLoad = dependsOnVariables.some((v)=>variables[v]?.loading);
|
|
106
|
-
}
|
|
107
|
-
const variablesValueKey = getVariableValuesKey(variables);
|
|
108
|
-
return useQuery({
|
|
109
|
-
queryKey: [
|
|
110
|
-
'annotation',
|
|
111
|
-
spec,
|
|
112
|
-
timeRange,
|
|
113
|
-
variablesValueKey
|
|
114
|
-
],
|
|
115
|
-
queryFn: async ({ signal })=>{
|
|
116
|
-
const resp = await annotationPlugin?.getAnnotationData(spec.plugin.spec, {
|
|
117
|
-
...variablePluginCtx,
|
|
118
|
-
variableState: variables
|
|
119
|
-
}, signal);
|
|
120
|
-
if (!resp?.length) {
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
return resp;
|
|
124
|
-
},
|
|
125
|
-
enabled: !!annotationPlugin || waitToLoad
|
|
77
|
+
/**
|
|
78
|
+
* Resolves one annotation spec using the same cache and fetch policy as {@link useAnnotations}.
|
|
79
|
+
* Used by annotation previews; also exposes loading, error, and refetch state to individual consumers.
|
|
80
|
+
*/ export function useAnnotationData(spec) {
|
|
81
|
+
const { data: plugin } = usePlugin(ANNOTATION_KEY, spec.plugin.kind, {
|
|
82
|
+
version: spec.plugin.metadata?.version,
|
|
83
|
+
registry: spec.plugin.metadata?.registry
|
|
126
84
|
});
|
|
85
|
+
const context = useAnnotationContext();
|
|
86
|
+
return useQuery(getQueryOptions({
|
|
87
|
+
plugin,
|
|
88
|
+
definition: spec,
|
|
89
|
+
context
|
|
90
|
+
}));
|
|
127
91
|
}
|
|
128
92
|
|
|
129
93
|
//# sourceMappingURL=annotations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/annotations.ts"],"sourcesContent":["// Copyright 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 type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/annotations.ts"],"sourcesContent":["// Copyright 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 type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';\nimport type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery } from '@tanstack/react-query';\n\nimport type { AnnotationContext, AnnotationPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport const ANNOTATION_KEY = 'Annotation';\n\nfunction useAnnotationContext(): AnnotationContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n absoluteTimeRange,\n };\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AnnotationPlugin;\n definition: AnnotationSpec;\n context: AnnotationContext;\n}): UseQueryOptions<AnnotationData[]> {\n const { variableState, absoluteTimeRange } = context;\n const dependencies = plugin?.dependsOn?.(definition.plugin.spec, context);\n const filteredVariableState = filterVariableStateMap(variableState, dependencies?.variables);\n const variablesValueKey = getVariableValuesKey(filteredVariableState);\n // Only declared variable dependencies delay the query, like other query plugins.\n const waitToLoad = dependencies?.variables?.some((name) => variableState[name]?.loading) ?? false;\n\n return {\n // ['annotation', spec] prefix: refreshed by TimeRangeProvider and invalidated by the annotation editor preview.\n queryKey: ['annotation', definition, absoluteTimeRange, variablesValueKey],\n enabled: plugin !== undefined && !waitToLoad,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }): Promise<AnnotationData[]> => {\n if (plugin === undefined) {\n throw new Error('Expected annotation plugin to be loaded');\n }\n const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);\n return data;\n },\n };\n}\n\n/**\n * Resolves annotation specs through the shared query cache. Panels requesting the same spec,\n * absolute time range, and variable values share both in-flight requests and cached data with previews.\n */\nexport function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>> {\n const context = useAnnotationContext();\n\n const pluginLoaderResponse = usePlugins(\n 'Annotation',\n definitions.map((d) => ({\n kind: d.plugin.kind,\n version: d.plugin.metadata?.version,\n registry: d.plugin.metadata?.registry,\n })),\n );\n\n return useQueries({\n queries: definitions.map((definition, index) =>\n getQueryOptions({ context, definition, plugin: pluginLoaderResponse[index]?.data }),\n ),\n });\n}\n\n/**\n * Resolves one annotation spec using the same cache and fetch policy as {@link useAnnotations}.\n * Used by annotation previews; also exposes loading, error, and refetch state to individual consumers.\n */\nexport function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]> {\n const { data: plugin } = usePlugin(ANNOTATION_KEY, spec.plugin.kind, {\n version: spec.plugin.metadata?.version,\n registry: spec.plugin.metadata?.registry,\n });\n const context = useAnnotationContext();\n\n return useQuery(getQueryOptions({ plugin, definition: spec, context }));\n}\n"],"names":["useQueries","useQuery","useDatasourceStore","usePlugin","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ANNOTATION_KEY","useAnnotationContext","absoluteTimeRange","variableState","datasourceStore","getQueryOptions","plugin","definition","context","dependencies","dependsOn","spec","filteredVariableState","variables","variablesValueKey","waitToLoad","some","name","loading","queryKey","enabled","undefined","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","Error","data","getAnnotationData","useAnnotations","definitions","pluginLoaderResponse","map","d","kind","version","metadata","registry","queries","index","useAnnotationData"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,EAAEC,QAAQ,QAAQ,wBAAwB;AAG7D,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,SAAS,EAAEC,UAAU,QAAQ,uBAAoB;AAC1D,SAASC,YAAY,QAAQ,+BAAsB;AACnD,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,aAAU;AACvE,SAASC,oBAAoB,QAAQ,iBAAc;AAEnD,OAAO,MAAMC,iBAAiB,aAAa;AAE3C,SAASC;IACP,MAAM,EAAEC,iBAAiB,EAAE,GAAGN;IAC9B,MAAMO,gBAAgBJ;IACtB,MAAMK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AAoB,CAACQ,MAAM,EAAEZ;YAAK;IAErF;AACF;AAEA;;;CAGC,GACD,OAAO,SAASa,kBAAkBhC,IAAoB;IACpD,MAAM,EAAEmB,MAAMxB,MAAM,EAAE,GAAGZ,UAAUM,gBAAgBW,KAAKL,MAAM,CAAC+B,IAAI,EAAE;QACnEC,SAAS3B,KAAKL,MAAM,CAACiC,QAAQ,EAAED;QAC/BE,UAAU7B,KAAKL,MAAM,CAACiC,QAAQ,EAAEC;IAClC;IACA,MAAMhC,UAAUP;IAEhB,OAAOT,SAASa,gBAAgB;QAAEC;QAAQC,YAAYI;QAAMH;IAAQ;AACtE"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';
|
|
2
2
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
export interface DatasourceStore {
|
|
4
|
+
/**
|
|
5
|
+
* Project whose datasources are listed alongside global ones. Undefined for a global-only scope.
|
|
6
|
+
*/
|
|
7
|
+
project?: string;
|
|
4
8
|
getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;
|
|
5
9
|
/**
|
|
6
10
|
* Gets a cached datasource spec synchronously if available.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasources.d.ts","sourceRoot":"","sources":["../../src/runtime/datasources.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI5D,MAAM,WAAW,eAAe;
|
|
1
|
+
{"version":3,"file":"datasources.d.ts","sourceRoot":"","sources":["../../src/runtime/datasources.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI5D,MAAM,WA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AC;CAChB;AAED,eAAO,MAAM,sBAAsB,sDAAwD,CAAC;AAE5F,wBAAgB,kBAAkB,IAAI,eAAe,CAMpD;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,oBAAoB,EAAE,MAAM,EAC5B,OAAO,CAAC,EAAE,MAAM,GACf,cAAc,CAAC,yBAAyB,EAAE,CAAC,CAO7C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,cAAc,CAAC,MAAM,CAAC,CAMhG;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,cAAc,CAAC,cAAc,CAAC,CAM1F"}
|
|
@@ -24,14 +24,15 @@ export function useDatasourceStore() {
|
|
|
24
24
|
* Lists all available Datasource selection items for a given datasource plugin kind.
|
|
25
25
|
* Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)
|
|
26
26
|
*/ export function useListDatasourceSelectItems(datasourcePluginName, project) {
|
|
27
|
-
const
|
|
27
|
+
const store = useDatasourceStore();
|
|
28
|
+
// Results are scoped by the store's project; the explicit parameter only remains as a fallback discriminator.
|
|
28
29
|
return useQuery({
|
|
29
30
|
queryKey: [
|
|
30
31
|
'listDatasourceSelectItems',
|
|
31
32
|
datasourcePluginName,
|
|
32
|
-
project
|
|
33
|
+
store.project ?? project
|
|
33
34
|
],
|
|
34
|
-
queryFn: ()=>listDatasourceSelectItems(datasourcePluginName)
|
|
35
|
+
queryFn: ()=>store.listDatasourceSelectItems(datasourcePluginName)
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/datasources.ts"],"sourcesContent":["// Copyright 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 type { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nexport interface DatasourceStore {\n // TODO: Do we even need this method?\n getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;\n\n /**\n * Gets a cached datasource spec synchronously if available.\n * Used by variable dependency resolution to avoid async calls in dependsOn().\n * Returns undefined if the spec is not cached.\n */\n getDatasourceSpecSync?(selector: DatasourceSelector): DatasourceSpec | undefined;\n\n /**\n * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.\n */\n getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;\n\n /**\n * Gets a list of datasource selection items for a plugin kind.\n */\n listDatasourceSelectItems(datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]>;\n\n /**\n * Gets the list of datasources defined in the dashboard\n */\n getLocalDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources defined in the dashboard\n */\n setLocalDatasources(datasources: Record<string, DatasourceSpec>): void;\n\n /**\n * Gets the list of datasources that are available in the dashboard (i.e. dashboards that have been created on the server side that we can use).\n */\n getSavedDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources that are saved in the dashboard\n */\n setSavedDatasources(datasources: Record<string, DatasourceSpec>): void;\n}\n\nexport interface DatasourceSelectItemGroup {\n group?: string;\n editLink?: string;\n items: DatasourceSelectItem[];\n}\n\nexport interface DatasourceSelectItem {\n name: string;\n overridden?: boolean;\n overriding?: boolean;\n saved?: boolean;\n selector: DatasourceSelectItemSelector;\n}\n\n/**\n * Datasource Selector used by the frontend only to differentiate datasources coming from different group.\n */\nexport interface DatasourceSelectItemSelector extends DatasourceSelector {\n /**\n * Group of the datasource.\n * Omit it if you don't store datasource by group.\n */\n group?: string;\n}\n\nexport const DatasourceStoreContext = createContext<DatasourceStore | undefined>(undefined);\n\nexport function useDatasourceStore(): DatasourceStore {\n const ctx = useContext(DatasourceStoreContext);\n if (ctx === undefined) {\n throw new Error('No DatasourceStoreContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Lists all available Datasource selection items for a given datasource plugin kind.\n * Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)\n */\nexport function useListDatasourceSelectItems(\n datasourcePluginName: string,\n project?: string,\n): UseQueryResult<DatasourceSelectItemGroup[]> {\n const
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/datasources.ts"],"sourcesContent":["// Copyright 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 type { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nexport interface DatasourceStore {\n /**\n * Project whose datasources are listed alongside global ones. Undefined for a global-only scope.\n */\n project?: string;\n\n // TODO: Do we even need this method?\n getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;\n\n /**\n * Gets a cached datasource spec synchronously if available.\n * Used by variable dependency resolution to avoid async calls in dependsOn().\n * Returns undefined if the spec is not cached.\n */\n getDatasourceSpecSync?(selector: DatasourceSelector): DatasourceSpec | undefined;\n\n /**\n * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.\n */\n getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;\n\n /**\n * Gets a list of datasource selection items for a plugin kind.\n */\n listDatasourceSelectItems(datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]>;\n\n /**\n * Gets the list of datasources defined in the dashboard\n */\n getLocalDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources defined in the dashboard\n */\n setLocalDatasources(datasources: Record<string, DatasourceSpec>): void;\n\n /**\n * Gets the list of datasources that are available in the dashboard (i.e. dashboards that have been created on the server side that we can use).\n */\n getSavedDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources that are saved in the dashboard\n */\n setSavedDatasources(datasources: Record<string, DatasourceSpec>): void;\n}\n\nexport interface DatasourceSelectItemGroup {\n group?: string;\n editLink?: string;\n items: DatasourceSelectItem[];\n}\n\nexport interface DatasourceSelectItem {\n name: string;\n overridden?: boolean;\n overriding?: boolean;\n saved?: boolean;\n selector: DatasourceSelectItemSelector;\n}\n\n/**\n * Datasource Selector used by the frontend only to differentiate datasources coming from different group.\n */\nexport interface DatasourceSelectItemSelector extends DatasourceSelector {\n /**\n * Group of the datasource.\n * Omit it if you don't store datasource by group.\n */\n group?: string;\n}\n\nexport const DatasourceStoreContext = createContext<DatasourceStore | undefined>(undefined);\n\nexport function useDatasourceStore(): DatasourceStore {\n const ctx = useContext(DatasourceStoreContext);\n if (ctx === undefined) {\n throw new Error('No DatasourceStoreContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Lists all available Datasource selection items for a given datasource plugin kind.\n * Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)\n */\nexport function useListDatasourceSelectItems(\n datasourcePluginName: string,\n project?: string,\n): UseQueryResult<DatasourceSelectItemGroup[]> {\n const store = useDatasourceStore();\n // Results are scoped by the store's project; the explicit parameter only remains as a fallback discriminator.\n return useQuery<DatasourceSelectItemGroup[]>({\n queryKey: ['listDatasourceSelectItems', datasourcePluginName, store.project ?? project],\n queryFn: () => store.listDatasourceSelectItems(datasourcePluginName),\n });\n}\n\n/**\n * Provides a convenience hook for getting a DatasourceClient for a given DatasourceSelector.\n */\nexport function useDatasourceClient<Client>(selector: DatasourceSelector): UseQueryResult<Client> {\n const store = useDatasourceStore();\n return useQuery<Client>({\n queryKey: ['getDatasourceClient', selector],\n queryFn: () => store.getDatasourceClient<Client>(selector),\n });\n}\n\nexport function useDatasource(selector: DatasourceSelector): UseQueryResult<DatasourceSpec> {\n const store = useDatasourceStore();\n return useQuery<DatasourceSpec>({\n queryKey: ['getDatasource', selector],\n queryFn: () => store.getDatasource(selector),\n });\n}\n"],"names":["useQuery","createContext","useContext","DatasourceStoreContext","undefined","useDatasourceStore","ctx","Error","useListDatasourceSelectItems","datasourcePluginName","project","store","queryKey","queryFn","listDatasourceSelectItems","useDatasourceClient","selector","getDatasourceClient","useDatasource","getDatasource"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,QAAQ,QAAQ,wBAAwB;AACjD,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AA0ElD,OAAO,MAAMC,yBAAyBF,cAA2CG,WAAW;AAE5F,OAAO,SAASC;IACd,MAAMC,MAAMJ,WAAWC;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;;CAGC,GACD,OAAO,SAASE,6BACdC,oBAA4B,EAC5BC,OAAgB;IAEhB,MAAMC,QAAQN;IACd,8GAA8G;IAC9G,OAAOL,SAAsC;QAC3CY,UAAU;YAAC;YAA6BH;YAAsBE,MAAMD,OAAO,IAAIA;SAAQ;QACvFG,SAAS,IAAMF,MAAMG,yBAAyB,CAACL;IACjD;AACF;AAEA;;CAEC,GACD,OAAO,SAASM,oBAA4BC,QAA4B;IACtE,MAAML,QAAQN;IACd,OAAOL,SAAiB;QACtBY,UAAU;YAAC;YAAuBI;SAAS;QAC3CH,SAAS,IAAMF,MAAMM,mBAAmB,CAASD;IACnD;AACF;AAEA,OAAO,SAASE,cAAcF,QAA4B;IACxD,MAAML,QAAQN;IACd,OAAOL,SAAyB;QAC9BY,UAAU;YAAC;YAAiBI;SAAS;QACrCH,SAAS,IAAMF,MAAMQ,aAAa,CAACH;IACrC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/log-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,MAAM,MAAM,kBAAkB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AACnG,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,wBAAgB,aAAa,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"log-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/log-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,MAAM,MAAM,kBAAkB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AACnG,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,wBAAgB,aAAa,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAsCtG"}
|
|
@@ -46,7 +46,9 @@ export function useLogQueries(definitions) {
|
|
|
46
46
|
queryFn: async ({ signal })=>{
|
|
47
47
|
const plugin = await getPlugin({
|
|
48
48
|
kind: LOG_QUERY_KEY,
|
|
49
|
-
name: logQueryKind
|
|
49
|
+
name: logQueryKind,
|
|
50
|
+
version: definition.spec.plugin.metadata?.version,
|
|
51
|
+
registry: definition.spec.plugin.metadata?.registry
|
|
50
52
|
});
|
|
51
53
|
const data = await plugin.getLogData(definition.spec.plugin.spec, context, signal);
|
|
52
54
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/log-queries.ts"],"sourcesContent":["// Copyright 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 type { QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { LogQueryResult } from '../model/log-queries';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useVariableValues } from './variables';\n\nexport type LogQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'LogQuery', PluginSpec>;\nexport const LOG_QUERY_KEY = 'LogQuery';\n\nexport function useLogQueries(definitions: LogQueryDefinition[]): Array<UseQueryResult<LogQueryResult>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n const variableValues = useVariableValues();\n\n const context = {\n timeRange: absoluteTimeRange,\n variableState: variableValues,\n datasourceStore,\n refreshKey: '',\n };\n\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = ['query', LOG_QUERY_KEY, definition, absoluteTimeRange, variableValues] as const;\n const logQueryKind = definition?.spec?.plugin?.kind;\n return {\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<LogQueryResult> => {\n const plugin = await getPlugin({
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/log-queries.ts"],"sourcesContent":["// Copyright 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 type { QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { LogQueryResult } from '../model/log-queries';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useVariableValues } from './variables';\n\nexport type LogQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'LogQuery', PluginSpec>;\nexport const LOG_QUERY_KEY = 'LogQuery';\n\nexport function useLogQueries(definitions: LogQueryDefinition[]): Array<UseQueryResult<LogQueryResult>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n const variableValues = useVariableValues();\n\n const context = {\n timeRange: absoluteTimeRange,\n variableState: variableValues,\n datasourceStore,\n refreshKey: '',\n };\n\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = ['query', LOG_QUERY_KEY, definition, absoluteTimeRange, variableValues] as const;\n const logQueryKind = definition?.spec?.plugin?.kind;\n return {\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<LogQueryResult> => {\n const plugin = await getPlugin({\n kind: LOG_QUERY_KEY,\n name: logQueryKind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getLogData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n\n structuralSharing: false,\n };\n }),\n });\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","useTimeRange","useVariableValues","LOG_QUERY_KEY","useLogQueries","definitions","getPlugin","datasourceStore","absoluteTimeRange","variableValues","context","timeRange","variableState","refreshKey","queries","map","definition","queryKey","logQueryKind","spec","plugin","kind","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","name","version","metadata","registry","data","getLogData","structuralSharing"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,UAAU,QAAQ,wBAAwB;AAGnD,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,iBAAiB,QAAQ,uBAAoB;AACtD,SAASC,YAAY,QAAQ,+BAAsB;AACnD,SAASC,iBAAiB,QAAQ,iBAAc;AAGhD,OAAO,MAAMC,gBAAgB,WAAW;AAExC,OAAO,SAASC,cAAcC,WAAiC;IAC7D,MAAM,EAAEC,SAAS,EAAE,GAAGN;IACtB,MAAMO,kBAAkBR;IACxB,MAAM,EAAES,iBAAiB,EAAE,GAAGP;IAC9B,MAAMQ,iBAAiBP;IAEvB,MAAMQ,UAAU;QACdC,WAAWH;QACXI,eAAeH;QACfF;QACAM,YAAY;IACd;IAEA,OAAOf,WAAW;QAChBgB,SAAST,YAAYU,GAAG,CAAC,CAACC;YACxB,MAAMC,WAAW;gBAAC;gBAASd;gBAAea;gBAAYR;gBAAmBC;aAAe;YACxF,MAAMS,eAAeF,YAAYG,MAAMC,QAAQC;YAC/C,OAAO;gBACLJ,UAAUA;gBACVK,gBAAgB;gBAChBC,sBAAsB;gBACtBC,oBAAoB;gBACpBC,WAAWC;gBACXC,SAAS,OAAO,EAAEC,MAAM,EAA4B;oBAClD,MAAMR,SAAS,MAAMd,UAAU;wBAC7Be,MAAMlB;wBACN0B,MAAMX;wBACNY,SAASd,WAAWG,IAAI,CAACC,MAAM,CAACW,QAAQ,EAAED;wBAC1CE,UAAUhB,WAAWG,IAAI,CAACC,MAAM,CAACW,QAAQ,EAAEC;oBAC7C;oBACA,MAAMC,OAAO,MAAMb,OAAOc,UAAU,CAAClB,WAAWG,IAAI,CAACC,MAAM,CAACD,IAAI,EAAET,SAASkB;oBAC3E,OAAOK;gBACT;gBAEAE,mBAAmB;YACrB;QACF;IACF;AACF"}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import type { BuiltinVariableDefinition } from '@perses-dev/spec';
|
|
1
|
+
import type { BuiltinVariableDefinition, PluginDefinitionMetadata } from '@perses-dev/spec';
|
|
2
2
|
import type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
import type { DefaultPluginKinds, PluginImplementation, PluginMetadataWithModule, PluginType, PluginCompoundKey } from '../model';
|
|
4
4
|
export interface PluginRegistryContextType {
|
|
5
5
|
getPlugin<T extends PluginType>(compoundKey: PluginCompoundKey<T>): Promise<PluginImplementation<T>>;
|
|
6
|
-
listPluginMetadata(pluginTypes
|
|
6
|
+
listPluginMetadata(pluginTypes?: PluginType[]): Promise<PluginMetadataWithModule[]>;
|
|
7
7
|
defaultPluginKinds?: DefaultPluginKinds;
|
|
8
|
+
pluginsBaseURL?: string;
|
|
8
9
|
}
|
|
9
10
|
export declare const PluginRegistryContext: import("react").Context<PluginRegistryContextType | undefined>;
|
|
10
11
|
/**
|
|
@@ -12,22 +13,36 @@ export declare const PluginRegistryContext: import("react").Context<PluginRegist
|
|
|
12
13
|
* be using `usePlugin` or `useListPluginMetadata` instead.
|
|
13
14
|
*/
|
|
14
15
|
export declare function usePluginRegistry(): PluginRegistryContextType;
|
|
15
|
-
type
|
|
16
|
+
type UsePluginQueryKey = [string, PluginType | undefined, string, string, string];
|
|
17
|
+
type UsePluginOptions<T extends PluginType> = Omit<UseQueryOptions<PluginImplementation<T>, Error, PluginImplementation<T>, UsePluginQueryKey>, 'queryKey' | 'queryFn'> & {
|
|
18
|
+
/** Pin resolution to a specific plugin version. When omitted, the latest available version is used. */
|
|
19
|
+
version?: string;
|
|
20
|
+
/** Pin resolution to a specific plugin registry. */
|
|
21
|
+
registry?: string;
|
|
22
|
+
};
|
|
16
23
|
/**
|
|
17
24
|
* Loads a plugin and returns the plugin implementation, along with loading/error state.
|
|
25
|
+
*
|
|
26
|
+
* When `options.version` is provided, the plugin is resolved with an exact version match: if that version is not
|
|
27
|
+
* installed, the query fails instead of silently falling back to the latest available version.
|
|
18
28
|
*/
|
|
19
29
|
export declare function usePlugin<T extends PluginType>(pluginType: T | undefined, kind: string, options?: UsePluginOptions<T>): UseQueryResult<PluginImplementation<T>, Error>;
|
|
20
30
|
/**
|
|
21
|
-
*
|
|
31
|
+
* A plugin reference to load, optionally pinned to a specific version/registry.
|
|
22
32
|
*/
|
|
23
|
-
export
|
|
33
|
+
export interface UsePluginsItem extends PluginDefinitionMetadata {
|
|
24
34
|
kind: string;
|
|
25
|
-
}
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Loads a list of plugins and returns the plugin implementation, along with loading/error state.
|
|
38
|
+
*/
|
|
39
|
+
export declare function usePlugins<T extends PluginType>(pluginType: T, plugins: UsePluginsItem[]): Array<UseQueryResult<PluginImplementation<T>>>;
|
|
26
40
|
type UseListPluginMetadataOptions = Omit<UseQueryOptions<PluginMetadataWithModule[], Error, PluginMetadataWithModule[], [string, string[]]>, 'queryKey' | 'queryFn'>;
|
|
27
41
|
/**
|
|
28
|
-
* Gets a list of plugin metadata for the specified plugin
|
|
42
|
+
* Gets a list of plugin metadata for the specified plugin types and returns it, along with loading/error state. When
|
|
43
|
+
* `pluginTypes` is omitted, the metadata of every installed plugin is returned, whatever its type.
|
|
29
44
|
*/
|
|
30
|
-
export declare function useListPluginMetadata(pluginTypes
|
|
45
|
+
export declare function useListPluginMetadata(pluginTypes?: PluginType[], options?: UseListPluginMetadataOptions): UseQueryResult<PluginMetadataWithModule[]>;
|
|
31
46
|
export declare function usePluginBuiltinVariableDefinitions(): UseQueryResult<BuiltinVariableDefinition[]>;
|
|
32
47
|
export {};
|
|
33
48
|
//# sourceMappingURL=plugin-registry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/plugin-registry.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-registry.d.ts","sourceRoot":"","sources":["../../src/runtime/plugin-registry.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,yBAAyB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5F,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI7E,OAAO,KAAK,EACV,kBAAkB,EAClB,oBAAoB,EACpB,wBAAwB,EACxB,UAAU,EACV,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,MAAM,WAAW,yBAAyB;IACxC,SAAS,CAAC,CAAC,SAAS,UAAU,EAAE,WAAW,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC,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BhD;AAGD,KAAK,4BAA4B,GAAG,IAAI,CACtC,eAAe,CAAC,wBAAwB,EAAE,EAAE,KAAK,EAAE,wBAAwB,EAAE,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,EAClG,UAAU,GAAG,SAAS,CACvB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,CAAC,EAAE,UAAU,EAAE,EAC1B,OAAO,CAAC,EAAE,4BAA4B,GACrC,cAAc,CAAC,wBAAwB,EAAE,CAAC,CAQ5C;AAED,wBAAgB,mCAAmC,IAAI,cAAc,CAAC,yBAAyB,EAAE,CAAC,CAkBjG"}
|
|
@@ -25,63 +25,99 @@ export const PluginRegistryContext = createContext(undefined);
|
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Loads a plugin and returns the plugin implementation, along with loading/error state.
|
|
28
|
+
*
|
|
29
|
+
* When `options.version` is provided, the plugin is resolved with an exact version match: if that version is not
|
|
30
|
+
* installed, the query fails instead of silently falling back to the latest available version.
|
|
28
31
|
*/ export function usePlugin(pluginType, kind, options) {
|
|
32
|
+
const { version, registry, ...queryOptions } = options ?? {};
|
|
29
33
|
// We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically
|
|
30
|
-
|
|
31
|
-
...
|
|
32
|
-
enabled: (
|
|
34
|
+
const useQueryOptions = {
|
|
35
|
+
...queryOptions,
|
|
36
|
+
enabled: (queryOptions.enabled ?? true) && pluginType !== undefined && kind !== ''
|
|
33
37
|
};
|
|
34
38
|
const { getPlugin } = usePluginRegistry();
|
|
35
39
|
return useQuery({
|
|
36
40
|
queryKey: [
|
|
37
41
|
'getPlugin',
|
|
38
42
|
pluginType,
|
|
39
|
-
kind
|
|
43
|
+
kind,
|
|
44
|
+
version ?? '',
|
|
45
|
+
registry ?? ''
|
|
40
46
|
],
|
|
41
47
|
queryFn: ()=>getPlugin({
|
|
42
48
|
kind: pluginType,
|
|
43
|
-
name: kind
|
|
49
|
+
name: kind,
|
|
50
|
+
version,
|
|
51
|
+
registry
|
|
44
52
|
}),
|
|
45
|
-
...
|
|
53
|
+
...useQueryOptions
|
|
46
54
|
});
|
|
47
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* Full identity of a plugin to load. Two definitions pinned to different versions (or registries) of the same kind are
|
|
58
|
+
* distinct plugins and must be loaded independently.
|
|
59
|
+
*/ function getUsePluginsItemIdentity(plugin) {
|
|
60
|
+
return `${plugin.kind}:${plugin.version ?? ''}:${plugin.registry ?? ''}`;
|
|
61
|
+
}
|
|
48
62
|
/**
|
|
49
63
|
* Loads a list of plugins and returns the plugin implementation, along with loading/error state.
|
|
50
64
|
*/ export function usePlugins(pluginType, plugins) {
|
|
51
65
|
const { getPlugin } = usePluginRegistry();
|
|
52
|
-
// useQueries() does not support queries with duplicate keys, therefore we de-duplicate the
|
|
66
|
+
// useQueries() does not support queries with duplicate keys, therefore we de-duplicate the plugins before running useQueries()
|
|
53
67
|
// This resolves the following warning in the JS console: "[QueriesObserver]: Duplicate Queries found. This might result in unexpected behavior."
|
|
54
68
|
// https://github.com/TanStack/query/issues/8224#issuecomment-2523554831
|
|
55
69
|
// https://github.com/TanStack/query/issues/4187#issuecomment-1256336901
|
|
56
|
-
const
|
|
57
|
-
|
|
70
|
+
const uniquePlugins = new Map();
|
|
71
|
+
for (const p of plugins){
|
|
72
|
+
const key = getUsePluginsItemIdentity(p);
|
|
73
|
+
if (!uniquePlugins.has(key)) {
|
|
74
|
+
uniquePlugins.set(key, p);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const uniqueKeys = [
|
|
78
|
+
...uniquePlugins.keys()
|
|
79
|
+
];
|
|
80
|
+
const uniqueValues = [
|
|
81
|
+
...uniquePlugins.values()
|
|
58
82
|
];
|
|
59
83
|
const result = useQueries({
|
|
60
|
-
queries:
|
|
84
|
+
queries: uniqueValues.map((p)=>{
|
|
61
85
|
return {
|
|
62
86
|
queryKey: [
|
|
63
87
|
'getPlugin',
|
|
64
88
|
pluginType,
|
|
65
|
-
kind
|
|
89
|
+
p.kind,
|
|
90
|
+
p.version ?? '',
|
|
91
|
+
p.registry ?? ''
|
|
66
92
|
],
|
|
67
93
|
queryFn: ()=>getPlugin({
|
|
68
94
|
kind: pluginType,
|
|
69
|
-
name: kind
|
|
95
|
+
name: p.kind,
|
|
96
|
+
version: p.version,
|
|
97
|
+
registry: p.registry
|
|
70
98
|
})
|
|
71
99
|
};
|
|
72
100
|
})
|
|
73
101
|
});
|
|
74
|
-
// Re-assemble array in original order
|
|
75
|
-
|
|
102
|
+
// Re-assemble array in original order. Index lookups go through a Map so this stays linear on large panels.
|
|
103
|
+
const indexByIdentity = new Map(uniqueKeys.map((key, index)=>[
|
|
104
|
+
key,
|
|
105
|
+
index
|
|
106
|
+
]));
|
|
107
|
+
return plugins.map((p)=>result[indexByIdentity.get(getUsePluginsItemIdentity(p))]);
|
|
76
108
|
}
|
|
77
109
|
/**
|
|
78
|
-
* Gets a list of plugin metadata for the specified plugin
|
|
110
|
+
* Gets a list of plugin metadata for the specified plugin types and returns it, along with loading/error state. When
|
|
111
|
+
* `pluginTypes` is omitted, the metadata of every installed plugin is returned, whatever its type.
|
|
79
112
|
*/ export function useListPluginMetadata(pluginTypes, options) {
|
|
80
113
|
const { listPluginMetadata } = usePluginRegistry();
|
|
81
114
|
return useQuery({
|
|
115
|
+
// `['*']` marks the "every plugin type" query so it gets its own cache entry.
|
|
82
116
|
queryKey: [
|
|
83
117
|
'listPluginMetadata',
|
|
84
|
-
pluginTypes
|
|
118
|
+
pluginTypes ?? [
|
|
119
|
+
'*'
|
|
120
|
+
]
|
|
85
121
|
],
|
|
86
122
|
queryFn: ()=>listPluginMetadata(pluginTypes),
|
|
87
123
|
...options
|