@perses-dev/dashboards 0.46.0 → 0.47.0-rc0
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/DashboardStickyToolbar/DashboardStickyToolbar.js +2 -2
- package/dist/cjs/components/Datasources/DatasourceEditor.js +15 -13
- package/dist/cjs/components/EmptyDashboard/EmptyDashboard.js +1 -1
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +30 -38
- package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +2 -2
- package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +2 -2
- package/dist/cjs/components/Variables/EditVariablesButton.js +4 -4
- package/dist/cjs/components/Variables/{TemplateVariable.js → Variable.js} +16 -19
- package/dist/cjs/components/Variables/VariableEditor.js +19 -17
- package/dist/cjs/components/Variables/VariableList.js +17 -17
- package/dist/cjs/components/Variables/index.js +2 -2
- package/dist/cjs/constants/styles.js +7 -7
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +4 -4
- package/dist/cjs/context/{TemplateVariableProvider/TemplateVariableProvider.js → VariableProvider/VariableProvider.js} +51 -56
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.js +8 -8
- package/dist/cjs/{validation → context/VariableProvider}/index.js +2 -2
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/query-params.js +1 -1
- package/dist/cjs/context/{TemplateVariableProvider → VariableProvider}/utils.js +1 -1
- package/dist/cjs/context/index.js +2 -2
- package/dist/cjs/context/useDashboard.js +4 -4
- package/dist/cjs/stories/decorators/{WithTemplateVariables.js → WithVariables.js} +8 -8
- package/dist/cjs/stories/decorators/index.js +2 -2
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +3 -3
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +3 -3
- package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
- package/dist/components/Datasources/DatasourceEditor.js +16 -14
- package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
- package/dist/components/EmptyDashboard/EmptyDashboard.js +1 -1
- package/dist/components/EmptyDashboard/EmptyDashboard.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -2
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +31 -39
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +3 -3
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js +3 -3
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
- package/dist/components/Variables/EditVariablesButton.js +5 -5
- package/dist/components/Variables/EditVariablesButton.js.map +1 -1
- package/dist/components/Variables/{TemplateVariable.d.ts → Variable.d.ts} +3 -3
- package/dist/components/Variables/Variable.d.ts.map +1 -0
- package/dist/components/Variables/{TemplateVariable.js → Variable.js} +17 -20
- package/dist/components/Variables/Variable.js.map +1 -0
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +20 -18
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.d.ts +2 -2
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +15 -15
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -1
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +2 -2
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/constants/styles.d.ts +2 -2
- package/dist/constants/styles.d.ts.map +1 -1
- package/dist/constants/styles.js +3 -3
- package/dist/constants/styles.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +2 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +1 -2
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -9
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -2
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
- package/dist/context/DatasourceStoreProvider.d.ts +5 -5
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.d.ts +126 -0
- package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider/TemplateVariableProvider.js → VariableProvider/VariableProvider.js} +40 -41
- package/dist/context/VariableProvider/VariableProvider.js.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.d.ts +1 -1
- package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/hydrationUtils.js +6 -6
- package/dist/context/VariableProvider/hydrationUtils.js.map +1 -0
- package/dist/context/VariableProvider/index.d.ts +2 -0
- package/dist/context/VariableProvider/index.d.ts.map +1 -0
- package/dist/{validation → context/VariableProvider}/index.js +2 -2
- package/dist/context/VariableProvider/index.js.map +1 -0
- package/dist/context/VariableProvider/query-params.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/query-params.js +1 -1
- package/dist/context/VariableProvider/query-params.js.map +1 -0
- package/dist/context/VariableProvider/utils.d.ts.map +1 -0
- package/dist/context/{TemplateVariableProvider → VariableProvider}/utils.js +1 -1
- package/dist/context/VariableProvider/utils.js.map +1 -0
- package/dist/context/index.d.ts +1 -1
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +2 -2
- package/dist/context/index.js.map +1 -1
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +4 -4
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/stories/decorators/{WithTemplateVariables.js → WithVariables.js} +8 -8
- package/dist/stories/decorators/WithVariables.js.map +1 -0
- package/dist/stories/decorators/index.js +2 -2
- package/dist/stories/decorators/index.js.map +1 -1
- package/dist/test/datasource-provider.d.ts +2 -2
- package/dist/test/datasource-provider.d.ts.map +1 -1
- package/dist/test/datasource-provider.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -2
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +4 -4
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/package.json +7 -7
- package/dist/cjs/context/TemplateVariableProvider/index.js +0 -30
- package/dist/cjs/validation/panel.js +0 -39
- package/dist/components/Variables/TemplateVariable.d.ts.map +0 -1
- package/dist/components/Variables/TemplateVariable.js.map +0 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts +0 -77
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +0 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/hydrationUtils.js.map +0 -1
- package/dist/context/TemplateVariableProvider/index.d.ts +0 -2
- package/dist/context/TemplateVariableProvider/index.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/index.js +0 -15
- package/dist/context/TemplateVariableProvider/index.js.map +0 -1
- package/dist/context/TemplateVariableProvider/query-params.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/query-params.js.map +0 -1
- package/dist/context/TemplateVariableProvider/utils.d.ts.map +0 -1
- package/dist/context/TemplateVariableProvider/utils.js.map +0 -1
- package/dist/stories/decorators/WithTemplateVariables.js.map +0 -1
- package/dist/validation/index.d.ts +0 -2
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js.map +0 -1
- package/dist/validation/panel.d.ts +0 -67
- package/dist/validation/panel.d.ts.map +0 -1
- package/dist/validation/panel.js +0 -31
- package/dist/validation/panel.js.map +0 -1
- /package/dist/context/{TemplateVariableProvider → VariableProvider}/query-params.d.ts +0 -0
- /package/dist/context/{TemplateVariableProvider → VariableProvider}/utils.d.ts +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReactNode } from 'react';
|
|
2
|
-
import { DashboardResource,
|
|
2
|
+
import { DashboardResource, DatasourceResource, DatasourceSelector, DatasourceSpec, GlobalDatasourceResource, EphemeralDashboardResource } from '@perses-dev/core';
|
|
3
3
|
import { DatasourceClient } from '@perses-dev/plugin-system';
|
|
4
4
|
export interface DatasourceStoreProviderProps {
|
|
5
5
|
dashboardResource?: DashboardResource | EphemeralDashboardResource;
|
|
@@ -20,10 +20,10 @@ export type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) =>
|
|
|
20
20
|
*/
|
|
21
21
|
export interface DatasourceApi {
|
|
22
22
|
buildProxyUrl?: BuildDatasourceProxyUrlFunc;
|
|
23
|
-
getDatasource: (project: string, selector: DatasourceSelector) => Promise<
|
|
24
|
-
getGlobalDatasource: (selector: DatasourceSelector) => Promise<
|
|
25
|
-
listDatasources: (project: string, pluginKind?: string) => Promise<
|
|
26
|
-
listGlobalDatasources: (pluginKind?: string) => Promise<
|
|
23
|
+
getDatasource: (project: string, selector: DatasourceSelector) => Promise<DatasourceResource | undefined>;
|
|
24
|
+
getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasourceResource | undefined>;
|
|
25
|
+
listDatasources: (project: string, pluginKind?: string) => Promise<DatasourceResource[]>;
|
|
26
|
+
listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasourceResource[]>;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
29
|
* A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,SAAS,EAAkC,MAAM,OAAO,CAAC;AAClE,OAAO,EACL,iBAAiB,EAEjB,
|
|
1
|
+
{"version":3,"file":"DatasourceStoreProvider.d.ts","source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AkB,EAAE,CAAC,CAAC;IAEzF,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,wBAAwB,EAAE,CAAC,CAAC;CACrF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,2CAyL1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/context/DatasourceStoreProvider.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 { ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n ProjectDatasource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<ProjectDatasource | undefined>;\n\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasource | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<ProjectDatasource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata(['Datasource']),\n project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginKind),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.kind === datasourcePluginKind);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved }: AddDatasouceSelectItemParams) => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E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
{"version":3,"sources":["../../src/context/DatasourceStoreProvider.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 { ReactNode, useCallback, useMemo, useState } from 'react';\nimport {\n DashboardResource,\n DashboardSpec,\n DatasourceResource,\n DatasourceSelector,\n DatasourceSpec,\n GlobalDatasourceResource,\n useEvent,\n EphemeralDashboardResource,\n DatasourceDefinition,\n} from '@perses-dev/core';\nimport {\n DatasourceStoreContext,\n DatasourceStore,\n DatasourceSelectItemGroup,\n usePluginRegistry,\n DatasourceClient,\n DatasourceSelectItem,\n} from '@perses-dev/plugin-system';\n\nexport interface DatasourceStoreProviderProps {\n dashboardResource?: DashboardResource | EphemeralDashboardResource;\n projectName?: string;\n datasourceApi: DatasourceApi;\n children?: ReactNode;\n savedDatasources?: Record<string, DatasourceSpec>;\n onCreate?: (client: DatasourceClient) => DatasourceClient;\n}\n\nexport type BuildDatasourceProxyUrlParams = {\n project?: string;\n dashboard?: string;\n name: string;\n};\n\nexport type BuildDatasourceProxyUrlFunc = (p: BuildDatasourceProxyUrlParams) => string;\n\n/**\n * The external API for fetching datasource resources\n */\nexport interface DatasourceApi {\n buildProxyUrl?: BuildDatasourceProxyUrlFunc;\n\n getDatasource: (project: string, selector: DatasourceSelector) => Promise<DatasourceResource | undefined>;\n\n getGlobalDatasource: (selector: DatasourceSelector) => Promise<GlobalDatasourceResource | undefined>;\n\n listDatasources: (project: string, pluginKind?: string) => Promise<DatasourceResource[]>;\n\n listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasourceResource[]>;\n}\n\n/**\n * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.\n */\nexport function DatasourceStoreProvider(props: DatasourceStoreProviderProps) {\n const { projectName, datasourceApi, onCreate, children } = props;\n const [dashboardResource, setDashboardResource] = useState(props.dashboardResource);\n const [savedDatasources, setSavedDatasources] = useState<Record<string, DatasourceSpec>>(\n props.savedDatasources ?? {}\n );\n const project = projectName ?? dashboardResource?.metadata.project;\n\n const { getPlugin, listPluginMetadata } = usePluginRegistry();\n\n const findDatasource = useEvent(async (selector: DatasourceSelector) => {\n // Try to find it in dashboard spec\n if (dashboardResource) {\n const { datasources } = dashboardResource.spec;\n const dashboardDatasource = findDashboardDatasource(datasources, selector);\n if (dashboardDatasource !== undefined) {\n return {\n spec: dashboardDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: dashboardResource.metadata.project,\n dashboard: dashboardResource.metadata.name,\n name: dashboardDatasource.name,\n }),\n };\n }\n }\n\n if (project) {\n // Try to find it at the project level as a Datasource resource\n const datasource = await datasourceApi.getDatasource(project, selector);\n if (datasource !== undefined) {\n return {\n spec: datasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n project: datasource.metadata.project,\n name: datasource.metadata.name,\n }),\n };\n }\n }\n\n // Try to find it at the global level as a GlobalDatasource resource\n const globalDatasource = await datasourceApi.getGlobalDatasource(selector);\n if (globalDatasource !== undefined) {\n return {\n spec: globalDatasource.spec,\n proxyUrl: buildDatasourceProxyUrl(datasourceApi, {\n name: globalDatasource.metadata.name,\n }),\n };\n }\n\n throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);\n });\n\n // Gets a datasource spec for a given selector\n const getDatasource = useCallback(\n async (selector: DatasourceSelector): Promise<DatasourceSpec> => {\n const { spec } = await findDatasource(selector);\n return spec;\n },\n [findDatasource]\n );\n\n // Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client\n const getDatasourceClient = useCallback(\n async function getClient<Client extends DatasourceClient>(selector: DatasourceSelector): Promise<Client> {\n const { kind } = selector;\n const [{ spec, proxyUrl }, plugin] = await Promise.all([findDatasource(selector), getPlugin('Datasource', kind)]);\n\n // allows extending client\n const client = plugin.createClient(spec.plugin.spec, { proxyUrl }) as Client;\n if (onCreate !== undefined) {\n return onCreate(client) as Client;\n }\n return client;\n },\n [findDatasource, getPlugin, onCreate]\n );\n\n const listDatasourceSelectItems = useEvent(\n async (datasourcePluginKind: string): Promise<DatasourceSelectItemGroup[]> => {\n const [pluginMetadata, datasources, globalDatasources] = await Promise.all([\n listPluginMetadata(['Datasource']),\n project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],\n datasourceApi.listGlobalDatasources(datasourcePluginKind),\n ]);\n\n // Find the metadata for the plugin type they asked for, so we can use it for the name of the default datasource\n const datasourcePluginMetadata = pluginMetadata.find((metadata) => metadata.kind === datasourcePluginKind);\n if (datasourcePluginMetadata === undefined) {\n throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);\n }\n\n // Get helper for computing results properly\n const { results, addItem } = buildDatasourceSelectItemGroups(datasourcePluginMetadata.display.name);\n\n // Start with dashboard datasources with the highest precedence\n if (dashboardResource?.spec.datasources) {\n for (const selectorName in dashboardResource.spec.datasources) {\n const spec = dashboardResource.spec.datasources[selectorName];\n if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;\n\n const saved = selectorName in savedDatasources;\n addItem({ spec, selectorName, selectorGroup: 'dashboard', saved });\n }\n }\n\n // Now look at project-level datasources\n for (const datasource of datasources) {\n const selectorName = datasource.metadata.name;\n addItem({\n spec: datasource.spec,\n selectorName,\n selectorGroup: 'project',\n editLink: `/projects/${project}/datasources`,\n });\n }\n\n // And finally global datasources\n for (const globalDatasource of globalDatasources) {\n const selectorName = globalDatasource.metadata.name;\n addItem({ spec: globalDatasource.spec, selectorName, selectorGroup: 'global', editLink: '/admin/datasources' });\n }\n\n return results;\n }\n );\n\n const getLocalDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return dashboardResource?.spec.datasources ?? {};\n }, [dashboardResource]);\n\n const getSavedDatasources = useCallback((): Record<string, DatasourceSpec> => {\n return savedDatasources;\n }, [savedDatasources]);\n\n const setLocalDatasources = useCallback(\n (datasources: Record<string, DatasourceSpec>) => {\n if (dashboardResource) {\n setDashboardResource(\n dashboardResource.kind === 'Dashboard'\n ? ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as DashboardResource)\n : ({\n ...dashboardResource,\n spec: {\n ...dashboardResource.spec,\n datasources: datasources,\n },\n } as EphemeralDashboardResource)\n );\n }\n },\n [dashboardResource]\n );\n\n const ctxValue: DatasourceStore = useMemo(\n () =>\n ({\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n setSavedDatasources,\n getSavedDatasources,\n listDatasourceSelectItems,\n }) as DatasourceStore,\n [\n getDatasource,\n getDatasourceClient,\n getLocalDatasources,\n setLocalDatasources,\n listDatasourceSelectItems,\n setSavedDatasources,\n getSavedDatasources,\n ]\n );\n\n return <DatasourceStoreContext.Provider value={ctxValue}>{children}</DatasourceStoreContext.Provider>;\n}\n\nfunction buildDatasourceProxyUrl(api: DatasourceApi, params: BuildDatasourceProxyUrlParams): string {\n return api.buildProxyUrl ? api.buildProxyUrl(params) : '';\n}\n\n// Helper to find a datasource in the list embedded in a dashboard spec\nfunction findDashboardDatasource(\n dashboardDatasources: DashboardSpec['datasources'],\n selector: DatasourceSelector\n): DatasourceDefinition | undefined {\n if (dashboardDatasources === undefined) return undefined;\n\n // If using a name in the selector...\n if (selector.name !== undefined) {\n const named = dashboardDatasources[selector.name];\n if (named === undefined) return undefined;\n return named.plugin.kind === selector.kind ? { name: selector.name, spec: named } : undefined;\n }\n\n // If only using a kind, try to find one with that kind that is the default\n const result = Object.entries(dashboardDatasources).find(\n (entry) => entry[1].plugin.kind === selector.kind && entry[1].default\n );\n if (!result) {\n return undefined;\n }\n return { name: result[0], spec: result[1] };\n}\n\ninterface AddDatasouceSelectItemParams {\n spec: DatasourceSpec;\n selectorName: string;\n selectorGroup?: string;\n editLink?: string;\n saved?: boolean;\n}\n\ntype AddDatasourceSelectItemFunc = (params: AddDatasouceSelectItemParams) => void;\n\n/**\n * Helper for building a list of DatasourceSelectItemGroup results.\n * @param pluginDisplayName\n */\nfunction buildDatasourceSelectItemGroups(pluginDisplayName: string): {\n results: DatasourceSelectItemGroup[];\n addItem: AddDatasourceSelectItemFunc;\n} {\n const results: DatasourceSelectItemGroup[] = [];\n const usedNames = new Set<string>();\n let isFirst = true;\n let explicitDefaultAdded = false;\n const groupIndices: Record<string, number> = {};\n let currentGroupIndex = 1; // 0 is the default group, always there as it contains at least the first item.\n\n const addItem = ({ spec, selectorName, selectorGroup: group, editLink, saved }: AddDatasouceSelectItemParams) => {\n group = group ?? '';\n\n // Ensure the default group is always present as soon as an item is added.\n if (isFirst) {\n results.push({\n group: `Default ${pluginDisplayName}`,\n items: [],\n });\n }\n\n // Create the group if necessary\n let selectItemGroup = results[groupIndices[group] ?? -1];\n if (!selectItemGroup) {\n groupIndices[group] = currentGroupIndex;\n selectItemGroup = { items: [], group, editLink };\n results[currentGroupIndex] = selectItemGroup;\n currentGroupIndex++;\n }\n\n // Add item to the group\n const isOverridden = usedNames.has(selectorName);\n selectItemGroup.items.push({\n name: spec.display?.name ?? selectorName,\n overridden: isOverridden,\n saved,\n selector: {\n kind: spec.plugin.kind,\n name: selectorName,\n group,\n },\n });\n usedNames.add(selectorName);\n\n const isExplicitDefault = !isOverridden && spec.default && !explicitDefaultAdded;\n if (results[0] && (isFirst || isExplicitDefault)) {\n // If we haven't added a default yet and this is a default, add default option to the beginning of the results\n results[0].items = [\n {\n name: `Default (${selectorName} from ${group})`,\n selector: {\n kind: spec.plugin.kind,\n },\n },\n ];\n // We consider that we added the default datasource only if it has been explicitly set as default.\n // If we add this datasource as default just because it's the first, it still needs to be overridable by\n // another datasource explicitly set as default.\n explicitDefaultAdded = isExplicitDefault;\n }\n\n // At the end, we make sure the overriding item(s) is well flagged so\n if (isOverridden) {\n for (let i = explicitDefaultAdded ? 1 : 0; i < currentGroupIndex; i++) {\n (results[i]?.items ?? [])\n .filter((item: DatasourceSelectItem) => item.selector.name === selectorName)\n .forEach((item: DatasourceSelectItem) => {\n item.overriding = true;\n });\n }\n }\n\n isFirst = false;\n };\n\n return { results, addItem };\n}\n"],"names":["useCallback","useMemo","useState","useEvent","DatasourceStoreContext","usePluginRegistry","DatasourceStoreProvider","props","projectName","datasourceApi","onCreate","children","dashboardResource","setDashboardResource","savedDatasources","setSavedDatasources","project","metadata","getPlugin","listPluginMetadata","findDatasource","selector","datasources","spec","dashboardDatasource","findDashboardDatasource","undefined","proxyUrl","buildDatasourceProxyUrl","dashboard","name","datasource","getDatasource","globalDatasource","getGlobalDatasource","Error","kind","getDatasourceClient","getClient","plugin","Promise","all","client","createClient","listDatasourceSelectItems","datasourcePluginKind","pluginMetadata","globalDatasources","listDatasources","listGlobalDatasources","datasourcePluginMetadata","find","results","addItem","buildDatasourceSelectItemGroups","display","selectorName","saved","selectorGroup","editLink","getLocalDatasources","getSavedDatasources","setLocalDatasources","ctxValue","Provider","value","api","params","buildProxyUrl","dashboardDatasources","named","result","Object","entries","entry","default","pluginDisplayName","usedNames","Set","isFirst","explicitDefaultAdded","groupIndices","currentGroupIndex","group","push","items","selectItemGroup","isOverridden","has","overridden","add","isExplicitDefault","i","filter","item","forEach","overriding"],"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,SAAoBA,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAClE,SAOEC,QAAQ,QAGH,mBAAmB;AAC1B,SACEC,sBAAsB,EAGtBC,iBAAiB,QAGZ,4BAA4B;AAkCnC;;CAEC,GACD,OAAO,SAASC,wBAAwBC,KA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9B;YACApC,UAAU;gBACRe,MAAMb,KAAKgB,MAAM,CAACH,IAAI;gBACtBN,MAAM0B;gBACN2B;YACF;QACF;QACAN,UAAUa,GAAG,CAAClC;QAEd,MAAMmC,oBAAoB,CAACJ,gBAAgBhE,KAAKoD,OAAO,IAAI,CAACK;QAC5D,IAAI5B,OAAO,CAAC,EAAE,IAAK2B,CAAAA,WAAWY,iBAAgB,GAAI;YAChD,8GAA8G;YAC9GvC,OAAO,CAAC,EAAE,CAACiC,KAAK,GAAG;gBACjB;oBACEvD,MAAM,CAAC,SAAS,EAAE0B,aAAa,MAAM,EAAE2B,MAAM,CAAC,CAAC;oBAC/C9D,UAAU;wBACRe,MAAMb,KAAKgB,MAAM,CAACH,IAAI;oBACxB;gBACF;aACD;YACD,kGAAkG;YAClG,wGAAwG;YACxG,gDAAgD;YAChD4C,uBAAuBW;QACzB;QAEA,qEAAqE;QACrE,IAAIJ,cAAc;YAChB,IAAK,IAAIK,IAAIZ,uBAAuB,IAAI,GAAGY,IAAIV,mBAAmBU,IAAK;oBACpExC;oBAAAA;gBAAAA,CAAAA,CAAAA,oBAAAA,aAAAA,OAAO,CAACwC,EAAE,cAAVxC,iCAAAA,WAAYiC,KAAK,cAAjBjC,8BAAAA,mBAAqB,EAAE,AAAD,EACpByC,MAAM,CAAC,CAACC,OAA+BA,KAAKzE,QAAQ,CAACS,IAAI,KAAK0B,cAC9DuC,OAAO,CAAC,CAACD;oBACRA,KAAKE,UAAU,GAAG;gBACpB;YACJ;QACF;QAEAjB,UAAU;IACZ;IAEA,OAAO;QAAE3B;QAASC;IAAQ;AAC5B"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
import { VariableStateMap, VariableState, VariableStoreStateMap, VariableOption } from '@perses-dev/plugin-system';
|
|
3
|
+
import { VariableName, VariableValue, VariableDefinition, BuiltinVariableDefinition } from '@perses-dev/core';
|
|
4
|
+
/**
|
|
5
|
+
* This store is used to manipulate and read the definition of the variables and their state.
|
|
6
|
+
* - being local or external variables.
|
|
7
|
+
* - being text or list variables.
|
|
8
|
+
* - being of any state (value, options, loading, error, ...) check {@VariableState}
|
|
9
|
+
* Go and read each property documentation for more details.
|
|
10
|
+
*/
|
|
11
|
+
type VariableDefinitionStore = {
|
|
12
|
+
/**
|
|
13
|
+
* List of local variables definitions.
|
|
14
|
+
* This is typically the variable definition that can be modified through the setVariableDefinition setter.
|
|
15
|
+
*
|
|
16
|
+
* In Perses App ecosystem, this is typically the dashboard scope variables, that's why we call them local.
|
|
17
|
+
* Note that depending on the form, we can reuse this store to modify higher scope variables. For example,
|
|
18
|
+
* when we modify the variable of a project, we'll set this field with project scope variables. To be able to modify
|
|
19
|
+
* them.
|
|
20
|
+
*/
|
|
21
|
+
variableDefinitions: VariableDefinition[];
|
|
22
|
+
/**
|
|
23
|
+
* List of external variable definitions.
|
|
24
|
+
* This is static variable definitions that won´t be modified under this context.
|
|
25
|
+
* You'll have to set one list of external variable definition by scope. See {@link ExternalVariableDefinition} for
|
|
26
|
+
* more details.
|
|
27
|
+
*
|
|
28
|
+
* In Perses App ecosystem, this is typically the project or global scope variables.
|
|
29
|
+
* Note that depending on the form, we can reuse this store to modify higher scope variables. For example,
|
|
30
|
+
* when we modify the variable of a project, we'll set this field with global scope variables. Which means we
|
|
31
|
+
* won't be able to modify them from this form.
|
|
32
|
+
*/
|
|
33
|
+
externalVariableDefinitions: ExternalVariableDefinition[];
|
|
34
|
+
/**
|
|
35
|
+
* Additionally to definitions, we need to associate to each variable a state. That's what this map is meant for.
|
|
36
|
+
* This can be heavily modified under this context, using the different setters available.
|
|
37
|
+
* Note that the state of local AND external variables can be modified.
|
|
38
|
+
*/
|
|
39
|
+
variableState: VariableStoreStateMap;
|
|
40
|
+
/**
|
|
41
|
+
* Allow to modify the `value` property of a variable in the state map.
|
|
42
|
+
* @param variableName identify the variable
|
|
43
|
+
* @param value new value
|
|
44
|
+
* @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}
|
|
45
|
+
*/
|
|
46
|
+
setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;
|
|
47
|
+
/**
|
|
48
|
+
* Allow to modify the `options` property of a variable in the state map.
|
|
49
|
+
* @param variableName identify the variable
|
|
50
|
+
* @param options new value
|
|
51
|
+
* @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}
|
|
52
|
+
*/
|
|
53
|
+
setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Allow to modify the `loading` property of a variable in the state map.
|
|
56
|
+
* @param variableName identify the variable
|
|
57
|
+
* @param laoding new value
|
|
58
|
+
* @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}
|
|
59
|
+
*/
|
|
60
|
+
setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;
|
|
61
|
+
setVariableDefinitions: (definitions: VariableDefinition[]) => void;
|
|
62
|
+
setVariableDefaultValues: () => VariableDefinition[];
|
|
63
|
+
getSavedVariablesStatus: () => {
|
|
64
|
+
isSavedVariableModified: boolean;
|
|
65
|
+
modifiedVariableNames: string[];
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
export declare function useVariableDefinitionStoreCtx(): Omit<Omit<import("zustand").StoreApi<VariableDefinitionStore>, "setState"> & {
|
|
69
|
+
setState<A extends string | {
|
|
70
|
+
type: string;
|
|
71
|
+
}>(partial: VariableDefinitionStore | Partial<VariableDefinitionStore> | ((state: VariableDefinitionStore) => VariableDefinitionStore | Partial<VariableDefinitionStore>), replace?: boolean | undefined, action?: A | undefined): void;
|
|
72
|
+
}, "setState"> & {
|
|
73
|
+
setState(nextStateOrUpdater: VariableDefinitionStore | Partial<VariableDefinitionStore> | ((state: import("immer/dist/internal").WritableDraft<VariableDefinitionStore>) => void), shouldReplace?: boolean | undefined, action?: string | {
|
|
74
|
+
type: string;
|
|
75
|
+
} | undefined): void;
|
|
76
|
+
};
|
|
77
|
+
export declare function useVariableDefinitionStates(variableNames?: string[]): VariableStateMap;
|
|
78
|
+
/**
|
|
79
|
+
* Get the state and definition of a variable from the variables context.
|
|
80
|
+
* @param name name of the variable
|
|
81
|
+
* @param source if given, it searches in the external variables
|
|
82
|
+
*/
|
|
83
|
+
export declare function useVariableDefinitionAndState(name: string, source?: string): {
|
|
84
|
+
state: VariableState | undefined;
|
|
85
|
+
definition: VariableDefinition | undefined;
|
|
86
|
+
};
|
|
87
|
+
export declare function useVariableDefinitionActions(): {
|
|
88
|
+
setVariableValue: (variableName: string, value: VariableValue, source?: string | undefined) => void;
|
|
89
|
+
setVariableLoading: (name: string, loading: boolean, source?: string | undefined) => void;
|
|
90
|
+
setVariableOptions: (name: string, options: VariableOption[], source?: string | undefined) => void;
|
|
91
|
+
setVariableDefinitions: (definitions: VariableDefinition[]) => void;
|
|
92
|
+
setVariableDefaultValues: () => VariableDefinition[];
|
|
93
|
+
getSavedVariablesStatus: () => {
|
|
94
|
+
isSavedVariableModified: boolean;
|
|
95
|
+
modifiedVariableNames: string[];
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
export declare function useVariableDefinitions(): VariableDefinition[];
|
|
99
|
+
export declare function useExternalVariableDefinitions(): ExternalVariableDefinition[];
|
|
100
|
+
/**
|
|
101
|
+
* The external variables allow you to give to the provider some additional variables, not defined in the dashboard and static.
|
|
102
|
+
* It means that you won´t be able to update them from the dashboard itself, but you will see them appear and will be able
|
|
103
|
+
* to modify their runtime value as any other variable.
|
|
104
|
+
* If one of the external variable has the same name as a local one, it will be marked as overridden.
|
|
105
|
+
* You can define one list of variable definition by source and as many source as you want.
|
|
106
|
+
* The order of the sources is important as first one will take precedence on the following ones, in case they have same names.
|
|
107
|
+
*/
|
|
108
|
+
export type ExternalVariableDefinition = {
|
|
109
|
+
source: string;
|
|
110
|
+
tooltip?: {
|
|
111
|
+
title?: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
};
|
|
114
|
+
editLink?: string;
|
|
115
|
+
definitions: VariableDefinition[];
|
|
116
|
+
};
|
|
117
|
+
export interface VariableProviderProps {
|
|
118
|
+
children: ReactNode;
|
|
119
|
+
initialVariableDefinitions?: VariableDefinition[];
|
|
120
|
+
externalVariableDefinitions?: ExternalVariableDefinition[];
|
|
121
|
+
builtinVariableDefinitions?: BuiltinVariableDefinition[];
|
|
122
|
+
}
|
|
123
|
+
export declare function VariableProvider({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions, }: VariableProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
124
|
+
export declare function VariableProviderWithQueryParams({ children, initialVariableDefinitions, externalVariableDefinitions, builtinVariableDefinitions: builtinVariables, }: VariableProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
125
|
+
export {};
|
|
126
|
+
//# sourceMappingURL=VariableProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/VariableProvider/VariableProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAiB,SAAS,EAAiC,MAAM,OAAO,CAAC;AAMhF,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,qBAAqB,EACrB,cAAc,EAGf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,kBAAkB,EAGlB,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAK1B;;;;;;GAMG;AACH,KAAK,uBAAuB,GAAG;IAC7B;;;;;;;;OAQG;IACH,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C;;;;;;;;;;OAUG;IACH,2BAA2B,EAAE,0BAA0B,EAAE,CAAC;IAC1D;;;;OAIG;IACH,aAAa,EAAE,qBAAqB,CAAC;IACrC;;;;;OAKG;IACH,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9F;;;;;OAKG;IACH,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;IAC3D,0BAA0B,CAAC,EAAE,yBAAyB,EAAE,CAAC;CAC1D;AAGD,wBAAgB,gBAAgB,CAAC,EAC/B,QAAQ,EACR,0BAA+B,EAC/B,2BAAgC,EAChC,0BAA+B,GAChC,EAAE,qBAAqB,2CAQvB;AAED,wBAAgB,+BAA+B,CAAC,EAC9C,QAAQ,EACR,0BAA+B,EAC/B,2BAAgC,EAChC,0BAA0B,EAAE,gBAAqB,GAClD,EAAE,qBAAqB,2CAYvB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -17,23 +17,25 @@ import { useStoreWithEqualityFn } from 'zustand/traditional';
|
|
|
17
17
|
import { immer } from 'zustand/middleware/immer';
|
|
18
18
|
import { devtools } from 'zustand/middleware';
|
|
19
19
|
import produce from 'immer';
|
|
20
|
-
import {
|
|
20
|
+
import { VariableContext, BuiltinVariableContext, useTimeRange } from '@perses-dev/plugin-system';
|
|
21
21
|
import { DEFAULT_ALL_VALUE as ALL_VALUE, formatDuration, intervalToPrometheusDuration } from '@perses-dev/core';
|
|
22
22
|
import { checkSavedDefaultVariableStatus, findVariableDefinitionByName, mergeVariableDefinitions } from './utils';
|
|
23
|
-
import {
|
|
23
|
+
import { hydrateVariableDefinitionStates as hydrateVariableDefinitionStates } from './hydrationUtils';
|
|
24
24
|
import { getInitalValuesFromQueryParameters, getURLQueryParamName, useVariableQueryParams } from './query-params';
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/**
|
|
26
|
+
* Context object for {@link VariableDefinitionStore}.
|
|
27
|
+
*/ const VariableDefinitionStoreContext = /*#__PURE__*/ createContext(undefined);
|
|
28
|
+
export function useVariableDefinitionStoreCtx() {
|
|
29
|
+
const context = useContext(VariableDefinitionStoreContext);
|
|
28
30
|
if (!context) {
|
|
29
|
-
throw new Error('
|
|
31
|
+
throw new Error('VariableStoreContext not initialized');
|
|
30
32
|
}
|
|
31
33
|
return context;
|
|
32
34
|
}
|
|
33
|
-
export function
|
|
34
|
-
const store =
|
|
35
|
+
export function useVariableDefinitionStates(variableNames) {
|
|
36
|
+
const store = useVariableDefinitionStoreCtx();
|
|
35
37
|
return useStoreWithEqualityFn(store, (s)=>{
|
|
36
|
-
const
|
|
38
|
+
const varStates = {};
|
|
37
39
|
// Collect values of local variables, from the variable state
|
|
38
40
|
const names = variableNames !== null && variableNames !== void 0 ? variableNames : s.variableDefinitions.map((value)=>value.spec.name);
|
|
39
41
|
names.forEach((name)=>{
|
|
@@ -43,7 +45,7 @@ export function useTemplateVariableValues(variableNames) {
|
|
|
43
45
|
if (!varState || varState.overridden) {
|
|
44
46
|
return;
|
|
45
47
|
}
|
|
46
|
-
|
|
48
|
+
varStates[name] = varState;
|
|
47
49
|
});
|
|
48
50
|
// Collect values of external variables, from the variable state
|
|
49
51
|
s.externalVariableDefinitions.forEach((d)=>{
|
|
@@ -57,20 +59,20 @@ export function useTemplateVariableValues(variableNames) {
|
|
|
57
59
|
if (!varState || varState.overridden) {
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
60
|
-
|
|
62
|
+
varStates[name] = varState;
|
|
61
63
|
});
|
|
62
64
|
});
|
|
63
|
-
return
|
|
65
|
+
return varStates;
|
|
64
66
|
}, (left, right)=>{
|
|
65
67
|
return JSON.stringify(left) === JSON.stringify(right);
|
|
66
68
|
});
|
|
67
69
|
}
|
|
68
70
|
/**
|
|
69
|
-
* Get the state and definition of a variable from the
|
|
71
|
+
* Get the state and definition of a variable from the variables context.
|
|
70
72
|
* @param name name of the variable
|
|
71
73
|
* @param source if given, it searches in the external variables
|
|
72
|
-
*/ export function
|
|
73
|
-
const store =
|
|
74
|
+
*/ export function useVariableDefinitionAndState(name, source) {
|
|
75
|
+
const store = useVariableDefinitionStoreCtx();
|
|
74
76
|
return useStore(store, (s)=>{
|
|
75
77
|
var _s_externalVariableDefinitions_find;
|
|
76
78
|
const state = s.variableState.get({
|
|
@@ -85,8 +87,8 @@ export function useTemplateVariableValues(variableNames) {
|
|
|
85
87
|
};
|
|
86
88
|
});
|
|
87
89
|
}
|
|
88
|
-
export function
|
|
89
|
-
const store =
|
|
90
|
+
export function useVariableDefinitionActions() {
|
|
91
|
+
const store = useVariableDefinitionStoreCtx();
|
|
90
92
|
return useStore(store, (s)=>{
|
|
91
93
|
return {
|
|
92
94
|
setVariableValue: s.setVariableValue,
|
|
@@ -98,22 +100,18 @@ export function useTemplateVariableActions() {
|
|
|
98
100
|
};
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
|
-
export function
|
|
102
|
-
const store =
|
|
103
|
+
export function useVariableDefinitions() {
|
|
104
|
+
const store = useVariableDefinitionStoreCtx();
|
|
103
105
|
return useStore(store, (s)=>s.variableDefinitions);
|
|
104
106
|
}
|
|
105
|
-
export function
|
|
106
|
-
const store =
|
|
107
|
+
export function useExternalVariableDefinitions() {
|
|
108
|
+
const store = useVariableDefinitionStoreCtx();
|
|
107
109
|
return useStore(store, (s)=>s.externalVariableDefinitions);
|
|
108
110
|
}
|
|
109
|
-
export function useTemplateVariableStore() {
|
|
110
|
-
const store = useTemplateVariableStoreCtx();
|
|
111
|
-
return useStore(store);
|
|
112
|
-
}
|
|
113
111
|
function PluginProvider({ children, builtinVariables }) {
|
|
114
|
-
const originalValues =
|
|
115
|
-
const definitions =
|
|
116
|
-
const externalDefinitions =
|
|
112
|
+
const originalValues = useVariableDefinitionStates();
|
|
113
|
+
const definitions = useVariableDefinitions();
|
|
114
|
+
const externalDefinitions = useExternalVariableDefinitions();
|
|
117
115
|
const { absoluteTimeRange } = useTimeRange();
|
|
118
116
|
const values = useMemo(()=>{
|
|
119
117
|
const contextValues = {};
|
|
@@ -221,7 +219,7 @@ function PluginProvider({ children, builtinVariables }) {
|
|
|
221
219
|
value: {
|
|
222
220
|
variables: allBuiltinVariables
|
|
223
221
|
},
|
|
224
|
-
children: /*#__PURE__*/ _jsx(
|
|
222
|
+
children: /*#__PURE__*/ _jsx(VariableContext.Provider, {
|
|
225
223
|
value: {
|
|
226
224
|
state: values
|
|
227
225
|
},
|
|
@@ -229,16 +227,16 @@ function PluginProvider({ children, builtinVariables }) {
|
|
|
229
227
|
})
|
|
230
228
|
});
|
|
231
229
|
}
|
|
232
|
-
function
|
|
230
|
+
function createVariableDefinitionStore({ initialVariableDefinitions = [], externalVariableDefinitions = [], queryParams }) {
|
|
233
231
|
const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});
|
|
234
232
|
const store = createStore()(devtools(immer((set, get)=>({
|
|
235
|
-
variableState:
|
|
233
|
+
variableState: hydrateVariableDefinitionStates(initialVariableDefinitions, initialParams, externalVariableDefinitions),
|
|
236
234
|
variableDefinitions: initialVariableDefinitions,
|
|
237
235
|
externalVariableDefinitions: externalVariableDefinitions,
|
|
238
236
|
setVariableDefinitions (definitions) {
|
|
239
237
|
set((state)=>{
|
|
240
238
|
state.variableDefinitions = definitions;
|
|
241
|
-
state.variableState =
|
|
239
|
+
state.variableState = hydrateVariableDefinitionStates(definitions, initialParams, externalVariableDefinitions);
|
|
242
240
|
}, false, '[Variables] setVariableDefinitions' // Used for action name in Redux devtools
|
|
243
241
|
);
|
|
244
242
|
},
|
|
@@ -336,28 +334,29 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions = [], exter
|
|
|
336
334
|
}))));
|
|
337
335
|
return store;
|
|
338
336
|
}
|
|
339
|
-
|
|
340
|
-
|
|
337
|
+
// TODO: merge the different providers related to Variables under a single one (and keep "VariableProvider" as a name)
|
|
338
|
+
export function VariableProvider({ children, initialVariableDefinitions = [], externalVariableDefinitions = [], builtinVariableDefinitions = [] }) {
|
|
339
|
+
const [store] = useState(createVariableDefinitionStore({
|
|
341
340
|
initialVariableDefinitions,
|
|
342
341
|
externalVariableDefinitions
|
|
343
342
|
}));
|
|
344
|
-
return /*#__PURE__*/ _jsx(
|
|
343
|
+
return /*#__PURE__*/ _jsx(VariableDefinitionStoreContext.Provider, {
|
|
345
344
|
value: store,
|
|
346
345
|
children: /*#__PURE__*/ _jsx(PluginProvider, {
|
|
347
|
-
builtinVariables:
|
|
346
|
+
builtinVariables: builtinVariableDefinitions,
|
|
348
347
|
children: children
|
|
349
348
|
})
|
|
350
349
|
});
|
|
351
350
|
}
|
|
352
|
-
export function
|
|
351
|
+
export function VariableProviderWithQueryParams({ children, initialVariableDefinitions = [], externalVariableDefinitions = [], builtinVariableDefinitions: builtinVariables = [] }) {
|
|
353
352
|
const allVariableDefs = mergeVariableDefinitions(initialVariableDefinitions, externalVariableDefinitions);
|
|
354
353
|
const queryParams = useVariableQueryParams(allVariableDefs);
|
|
355
|
-
const [store] = useState(
|
|
354
|
+
const [store] = useState(createVariableDefinitionStore({
|
|
356
355
|
initialVariableDefinitions,
|
|
357
356
|
externalVariableDefinitions,
|
|
358
357
|
queryParams
|
|
359
358
|
}));
|
|
360
|
-
return /*#__PURE__*/ _jsx(
|
|
359
|
+
return /*#__PURE__*/ _jsx(VariableDefinitionStoreContext.Provider, {
|
|
361
360
|
value: store,
|
|
362
361
|
children: /*#__PURE__*/ _jsx(PluginProvider, {
|
|
363
362
|
builtinVariables: builtinVariables,
|
|
@@ -366,4 +365,4 @@ export function TemplateVariableProviderWithQueryParams({ children, initialVaria
|
|
|
366
365
|
});
|
|
367
366
|
}
|
|
368
367
|
|
|
369
|
-
//# sourceMappingURL=
|
|
368
|
+
//# sourceMappingURL=VariableProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/VariableProvider/VariableProvider.tsx"],"sourcesContent":["// Copyright 2024 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 { createContext, ReactNode, useContext, useMemo, useState } from 'react';\nimport { createStore, useStore } from 'zustand';\nimport { useStoreWithEqualityFn } from 'zustand/traditional';\nimport { immer } from 'zustand/middleware/immer';\nimport { devtools } from 'zustand/middleware';\nimport produce from 'immer';\nimport {\n VariableContext,\n VariableStateMap,\n VariableState,\n VariableStoreStateMap,\n VariableOption,\n BuiltinVariableContext,\n useTimeRange,\n} from '@perses-dev/plugin-system';\nimport {\n DEFAULT_ALL_VALUE as ALL_VALUE,\n VariableName,\n VariableValue,\n VariableDefinition,\n formatDuration,\n intervalToPrometheusDuration,\n BuiltinVariableDefinition,\n} from '@perses-dev/core';\nimport { checkSavedDefaultVariableStatus, findVariableDefinitionByName, mergeVariableDefinitions } from './utils';\nimport { hydrateVariableDefinitionStates as hydrateVariableDefinitionStates } from './hydrationUtils';\nimport { getInitalValuesFromQueryParameters, getURLQueryParamName, useVariableQueryParams } from './query-params';\n\n/**\n * This store is used to manipulate and read the definition of the variables and their state.\n * - being local or external variables.\n * - being text or list variables.\n * - being of any state (value, options, loading, error, ...) check {@VariableState}\n * Go and read each property documentation for more details.\n */\ntype VariableDefinitionStore = {\n /**\n * List of local variables definitions.\n * This is typically the variable definition that can be modified through the setVariableDefinition setter.\n *\n * In Perses App ecosystem, this is typically the dashboard scope variables, that's why we call them local.\n * Note that depending on the form, we can reuse this store to modify higher scope variables. For example,\n * when we modify the variable of a project, we'll set this field with project scope variables. To be able to modify\n * them.\n */\n variableDefinitions: VariableDefinition[];\n /**\n * List of external variable definitions.\n * This is static variable definitions that won´t be modified under this context.\n * You'll have to set one list of external variable definition by scope. See {@link ExternalVariableDefinition} for\n * more details.\n *\n * In Perses App ecosystem, this is typically the project or global scope variables.\n * Note that depending on the form, we can reuse this store to modify higher scope variables. For example,\n * when we modify the variable of a project, we'll set this field with global scope variables. Which means we\n * won't be able to modify them from this form.\n */\n externalVariableDefinitions: ExternalVariableDefinition[];\n /**\n * Additionally to definitions, we need to associate to each variable a state. That's what this map is meant for.\n * This can be heavily modified under this context, using the different setters available.\n * Note that the state of local AND external variables can be modified.\n */\n variableState: VariableStoreStateMap;\n /**\n * Allow to modify the `value` property of a variable in the state map.\n * @param variableName identify the variable\n * @param value new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableValue: (variableName: VariableName, value: VariableValue, source?: string) => void;\n /**\n * Allow to modify the `options` property of a variable in the state map.\n * @param variableName identify the variable\n * @param options new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableOptions: (name: VariableName, options: VariableOption[], source?: string) => void;\n /**\n * Allow to modify the `loading` property of a variable in the state map.\n * @param variableName identify the variable\n * @param laoding new value\n * @param source identify the variable source if this is an external variable. See {@link ExternalVariableDefinition}\n */\n setVariableLoading: (name: VariableName, loading: boolean, source?: string) => void;\n setVariableDefinitions: (definitions: VariableDefinition[]) => void;\n setVariableDefaultValues: () => VariableDefinition[];\n getSavedVariablesStatus: () => { isSavedVariableModified: boolean; modifiedVariableNames: string[] };\n};\n\n/**\n * Context object for {@link VariableDefinitionStore}.\n */\nconst VariableDefinitionStoreContext = createContext<ReturnType<typeof createVariableDefinitionStore> | undefined>(\n undefined\n);\nexport function useVariableDefinitionStoreCtx() {\n const context = useContext(VariableDefinitionStoreContext);\n if (!context) {\n throw new Error('VariableStoreContext not initialized');\n }\n return context;\n}\n\nexport function useVariableDefinitionStates(variableNames?: string[]): VariableStateMap {\n const store = useVariableDefinitionStoreCtx();\n return useStoreWithEqualityFn(\n store,\n (s) => {\n const varStates: VariableStateMap = {};\n\n // Collect values of local variables, from the variable state\n const names = variableNames ?? s.variableDefinitions.map((value) => value.spec.name);\n names.forEach((name) => {\n const varState = s.variableState.get({ name });\n if (!varState || varState.overridden) {\n return;\n }\n varStates[name] = varState;\n });\n\n // Collect values of external variables, from the variable state\n s.externalVariableDefinitions.forEach((d) => {\n const source = d.source;\n d.definitions.forEach((value) => {\n const name = value.spec.name;\n const varState = s.variableState.get({ name, source });\n if (!varState || varState.overridden) {\n return;\n }\n varStates[name] = varState;\n });\n });\n\n return varStates;\n },\n (left, right) => {\n return JSON.stringify(left) === JSON.stringify(right);\n }\n );\n}\n\n/**\n * Get the state and definition of a variable from the variables context.\n * @param name name of the variable\n * @param source if given, it searches in the external variables\n */\nexport function useVariableDefinitionAndState(name: string, source?: string) {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => {\n const state = s.variableState.get({ name, source });\n const definitions = source\n ? s.externalVariableDefinitions.find((v) => v.source === source)?.definitions\n : s.variableDefinitions;\n const definition = (definitions || []).find((v) => v.spec.name === name);\n\n return { state, definition };\n });\n}\n\nexport function useVariableDefinitionActions() {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => {\n return {\n setVariableValue: s.setVariableValue,\n setVariableLoading: s.setVariableLoading,\n setVariableOptions: s.setVariableOptions,\n setVariableDefinitions: s.setVariableDefinitions,\n setVariableDefaultValues: s.setVariableDefaultValues,\n getSavedVariablesStatus: s.getSavedVariablesStatus,\n };\n });\n}\n\nexport function useVariableDefinitions() {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => s.variableDefinitions);\n}\n\nexport function useExternalVariableDefinitions() {\n const store = useVariableDefinitionStoreCtx();\n return useStore(store, (s) => s.externalVariableDefinitions);\n}\n\ninterface PluginProviderProps {\n children: ReactNode;\n builtinVariables?: BuiltinVariableDefinition[];\n}\n\nfunction PluginProvider({ children, builtinVariables }: PluginProviderProps) {\n const originalValues = useVariableDefinitionStates();\n const definitions = useVariableDefinitions();\n const externalDefinitions = useExternalVariableDefinitions();\n const { absoluteTimeRange } = useTimeRange();\n\n const values = useMemo(() => {\n const contextValues: VariableStateMap = {};\n\n // This will loop through all the current variables values\n // and update any variables that have ALL_VALUE as their current value\n // to include all options.\n Object.keys(originalValues).forEach((name) => {\n const v = { ...originalValues[name] } as VariableState;\n\n if (v.value === ALL_VALUE) {\n const definition = findVariableDefinitionByName(name, definitions, externalDefinitions);\n // If the variable is a list variable and has a custom all value, then use that value instead\n if (definition?.kind === 'ListVariable' && definition.spec.customAllValue) {\n v.value = definition.spec.customAllValue;\n } else {\n v.value = v.options?.map((o: { value: string }) => o.value) ?? null;\n }\n }\n contextValues[name] = v;\n });\n return contextValues;\n }, [originalValues, definitions, externalDefinitions]);\n\n const allBuiltinVariables: BuiltinVariableDefinition[] = useMemo(() => {\n const result: BuiltinVariableDefinition[] = [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__from',\n value: () => absoluteTimeRange.start.valueOf().toString(),\n source: 'Dashboard',\n display: {\n name: '__from',\n description: 'Start time of the current time range in unix millisecond epoch',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__to',\n value: () => absoluteTimeRange.end.valueOf().toString(),\n source: 'Dashboard',\n display: {\n name: '__to',\n description: 'End time of the current time range in unix millisecond epoch',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range',\n value: () => formatDuration(intervalToPrometheusDuration(absoluteTimeRange)),\n source: 'Dashboard',\n display: {\n name: '__range',\n description: 'The range for the current dashboard in human readable format',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range_s',\n value: () => ((absoluteTimeRange.end.valueOf() - absoluteTimeRange.start.valueOf()) / 1000).toString(),\n source: 'Dashboard',\n display: {\n name: '__range_s',\n description: 'The range for the current dashboard in second',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__range_ms',\n value: () => (absoluteTimeRange.end.valueOf() - absoluteTimeRange.start.valueOf()).toString(),\n source: 'Dashboard',\n display: {\n name: '__range_ms',\n description: 'The range for the current dashboard in millisecond',\n hidden: true,\n },\n },\n },\n ];\n builtinVariables?.forEach((def) => result.push(def));\n return result;\n }, [absoluteTimeRange, builtinVariables]);\n\n return (\n <BuiltinVariableContext.Provider value={{ variables: allBuiltinVariables }}>\n <VariableContext.Provider value={{ state: values }}>{children}</VariableContext.Provider>\n </BuiltinVariableContext.Provider>\n );\n}\n\ninterface VariableDefinitionStoreArgs {\n initialVariableDefinitions?: VariableDefinition[];\n externalVariableDefinitions?: ExternalVariableDefinition[];\n queryParams?: ReturnType<typeof useVariableQueryParams>;\n}\n\nfunction createVariableDefinitionStore({\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n queryParams,\n}: VariableDefinitionStoreArgs) {\n const initialParams = getInitalValuesFromQueryParameters(queryParams ? queryParams[0] : {});\n const store = createStore<VariableDefinitionStore>()(\n devtools(\n immer((set, get) => ({\n variableState: hydrateVariableDefinitionStates(\n initialVariableDefinitions,\n initialParams,\n externalVariableDefinitions\n ),\n variableDefinitions: initialVariableDefinitions,\n externalVariableDefinitions: externalVariableDefinitions,\n setVariableDefinitions(definitions: VariableDefinition[]) {\n set(\n (state) => {\n state.variableDefinitions = definitions;\n state.variableState = hydrateVariableDefinitionStates(\n definitions,\n initialParams,\n externalVariableDefinitions\n );\n },\n false,\n '[Variables] setVariableDefinitions' // Used for action name in Redux devtools\n );\n },\n setVariableOptions(name, options, source?: string) {\n set(\n (state) => {\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n varState.options = options;\n },\n false,\n '[Variables] setVariableOptions'\n );\n },\n setVariableLoading(name, loading, source?: string) {\n set(\n (state) => {\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n varState.loading = loading;\n },\n false,\n '[Variables] setVariableLoading'\n );\n },\n setVariableValue: (name, value, source?: string) =>\n set(\n (state) => {\n let val = value;\n const varState = state.variableState.get({ name, source });\n if (!varState) {\n return;\n }\n\n // Make sure there is only one all value\n if (Array.isArray(val) && val.includes(ALL_VALUE)) {\n if (val.at(-1) === ALL_VALUE) {\n val = ALL_VALUE;\n } else {\n val = val.filter((v) => v !== ALL_VALUE);\n }\n }\n if (queryParams) {\n const setQueryParams = queryParams[1];\n setQueryParams({ [getURLQueryParamName(name)]: val });\n }\n varState.value = val;\n },\n false,\n '[Variables] setVariableValue'\n ),\n setVariableDefaultValues: () => {\n const variableDefinitions = get().variableDefinitions;\n const variableState = get().variableState;\n const updatedVariables = produce(variableDefinitions, (draft) => {\n draft.forEach((variable, index) => {\n const name = variable.spec.name;\n if (variable.kind === 'ListVariable') {\n const currentVariable = variableState.get({ name });\n if (currentVariable?.value !== undefined) {\n draft[index] = {\n kind: 'ListVariable',\n spec: produce(variable.spec, (specDraft) => {\n specDraft.defaultValue = currentVariable.value;\n }),\n };\n }\n } else if (variable.kind === 'TextVariable') {\n const currentVariable = variableState.get({ name });\n const currentVariableValue = typeof currentVariable?.value === 'string' ? currentVariable.value : '';\n if (currentVariable?.value !== undefined) {\n draft[index] = {\n kind: 'TextVariable',\n spec: produce(variable.spec, (specDraft) => {\n specDraft.value = currentVariableValue;\n }),\n };\n }\n }\n });\n });\n set(\n (state) => {\n state.variableDefinitions = updatedVariables;\n },\n false,\n '[Variables] setVariableDefaultValues'\n );\n return updatedVariables;\n },\n getSavedVariablesStatus: () => {\n return checkSavedDefaultVariableStatus(get().variableDefinitions, get().variableState);\n },\n }))\n )\n );\n\n return store;\n}\n\n/**\n * The external variables allow you to give to the provider some additional variables, not defined in the dashboard and static.\n * It means that you won´t be able to update them from the dashboard itself, but you will see them appear and will be able\n * to modify their runtime value as any other variable.\n * If one of the external variable has the same name as a local one, it will be marked as overridden.\n * You can define one list of variable definition by source and as many source as you want.\n * The order of the sources is important as first one will take precedence on the following ones, in case they have same names.\n */\nexport type ExternalVariableDefinition = {\n source: string;\n tooltip?: {\n title?: string;\n description?: string;\n };\n editLink?: string;\n definitions: VariableDefinition[];\n};\n\nexport interface VariableProviderProps {\n children: ReactNode;\n initialVariableDefinitions?: VariableDefinition[];\n externalVariableDefinitions?: ExternalVariableDefinition[];\n builtinVariableDefinitions?: BuiltinVariableDefinition[];\n}\n\n// TODO: merge the different providers related to Variables under a single one (and keep \"VariableProvider\" as a name)\nexport function VariableProvider({\n children,\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n builtinVariableDefinitions = [],\n}: VariableProviderProps) {\n const [store] = useState(createVariableDefinitionStore({ initialVariableDefinitions, externalVariableDefinitions }));\n\n return (\n <VariableDefinitionStoreContext.Provider value={store}>\n <PluginProvider builtinVariables={builtinVariableDefinitions}>{children}</PluginProvider>\n </VariableDefinitionStoreContext.Provider>\n );\n}\n\nexport function VariableProviderWithQueryParams({\n children,\n initialVariableDefinitions = [],\n externalVariableDefinitions = [],\n builtinVariableDefinitions: builtinVariables = [],\n}: VariableProviderProps) {\n const allVariableDefs = mergeVariableDefinitions(initialVariableDefinitions, externalVariableDefinitions);\n const queryParams = useVariableQueryParams(allVariableDefs);\n const [store] = useState(\n createVariableDefinitionStore({ initialVariableDefinitions, externalVariableDefinitions, queryParams })\n );\n\n return (\n <VariableDefinitionStoreContext.Provider value={store}>\n <PluginProvider builtinVariables={builtinVariables}>{children}</PluginProvider>\n </VariableDefinitionStoreContext.Provider>\n );\n}\n"],"names":["createContext","useContext","useMemo","useState","createStore","useStore","useStoreWithEqualityFn","immer","devtools","produce","VariableContext","BuiltinVariableContext","useTimeRange","DEFAULT_ALL_VALUE","ALL_VALUE","formatDuration","intervalToPrometheusDuration","checkSavedDefaultVariableStatus","findVariableDefinitionByName","mergeVariableDefinitions","hydrateVariableDefinitionStates","getInitalValuesFromQueryParameters","getURLQueryParamName","useVariableQueryParams","VariableDefinitionStoreContext","undefined","useVariableDefinitionStoreCtx","context","Error","useVariableDefinitionStates","variableNames","store","s","varStates","names","variableDefinitions","map","value","spec","name","forEach","varState","variableState","get","overridden","externalVariableDefinitions","d","source","definitions","left","right","JSON","stringify","useVariableDefinitionAndState","state","find","v","definition","useVariableDefinitionActions","setVariableValue","setVariableLoading","setVariableOptions","setVariableDefinitions","setVariableDefaultValues","getSavedVariablesStatus","useVariableDefinitions","useExternalVariableDefinitions","PluginProvider","children","builtinVariables","originalValues","externalDefinitions","absoluteTimeRange","values","contextValues","Object","keys","kind","customAllValue","options","o","allBuiltinVariables","result","start","valueOf","toString","display","description","hidden","end","def","push","Provider","variables","createVariableDefinitionStore","initialVariableDefinitions","queryParams","initialParams","set","loading","val","Array","isArray","includes","at","filter","setQueryParams","updatedVariables","draft","variable","index","currentVariable","specDraft","defaultValue","currentVariableValue","VariableProvider","builtinVariableDefinitions","VariableProviderWithQueryParams","allVariableDefs"],"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,aAAa,EAAaC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AAChF,SAASC,WAAW,EAAEC,QAAQ,QAAQ,UAAU;AAChD,SAASC,sBAAsB,QAAQ,sBAAsB;AAC7D,SAASC,KAAK,QAAQ,2BAA2B;AACjD,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,OAAOC,aAAa,QAAQ;AAC5B,SACEC,eAAe,EAKfC,sBAAsB,EACtBC,YAAY,QACP,4BAA4B;AACnC,SACEC,qBAAqBC,SAAS,EAI9BC,cAAc,EACdC,4BAA4B,QAEvB,mBAAmB;AAC1B,SAASC,+BAA+B,EAAEC,4BAA4B,EAAEC,wBAAwB,QAAQ,UAAU;AAClH,SAASC,mCAAmCA,+BAA+B,QAAQ,mBAAmB;AACtG,SAASC,kCAAkC,EAAEC,oBAAoB,EAAEC,sBAAsB,QAAQ,iBAAiB;AAgElH;;CAEC,GACD,MAAMC,+CAAiCxB,cACrCyB;AAEF,OAAO,SAASC;IACd,MAAMC,UAAU1B,WAAWuB;IAC3B,IAAI,CAACG,SAAS;QACZ,MAAM,IAAIC,MAAM;IAClB;IACA,OAAOD;AACT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F,MAAM,GAAG5B,SAAS2F,8BAA8B;QAAEC;QAA4BlD;IAA4B;IAEjH,qBACE,KAACrB,+BAA+BoE,QAAQ;QAACvD,OAAON;kBAC9C,cAAA,KAACoC;YAAeE,kBAAkB+C;sBAA6BhD;;;AAGrE;AAEA,OAAO,SAASiD,gCAAgC,EAC9CjD,QAAQ,EACR2B,6BAA6B,EAAE,EAC/BlD,8BAA8B,EAAE,EAChCuE,4BAA4B/C,mBAAmB,EAAE,EAC3B;IACtB,MAAMiD,kBAAkBnG,yBAAyB4E,4BAA4BlD;IAC7E,MAAMmD,cAAczE,uBAAuB+F;IAC3C,MAAM,CAACvF,MAAM,GAAG5B,SACd2F,8BAA8B;QAAEC;QAA4BlD;QAA6BmD;IAAY;IAGvG,qBACE,KAACxE,+BAA+BoE,QAAQ;QAACvD,OAAON;kBAC9C,cAAA,KAACoC;YAAeE,kBAAkBA;sBAAmBD;;;AAG3D"}
|
|
@@ -7,5 +7,5 @@ import { ExternalVariableDefinition } from '@perses-dev/dashboards';
|
|
|
7
7
|
* @param externalDefinitions external variables definitions. Static part.
|
|
8
8
|
* @param initialValues values coming from query parameters
|
|
9
9
|
*/
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function hydrateVariableDefinitionStates(localDefinitions: VariableDefinition[], initialValues: Record<string, VariableValue>, externalDefinitions?: ExternalVariableDefinition[]): VariableStoreStateMap;
|
|
11
11
|
//# sourceMappingURL=hydrationUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hydrationUtils.d.ts","sourceRoot":"","sources":["../../../src/context/VariableProvider/hydrationUtils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAqB,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAiB,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,0BAA0B,EAAE,MAAM,wBAAwB,CAAC;AAyCpE;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC7C,gBAAgB,EAAE,kBAAkB,EAAE,EACtC,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,EAC5C,mBAAmB,GAAE,0BAA0B,EAAO,GACrD,qBAAqB,CAoEvB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2024 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { DEFAULT_ALL_VALUE } from '@perses-dev/core';
|
|
14
14
|
import { VariableStoreStateMap } from '@perses-dev/plugin-system';
|
|
15
|
-
// TODO: move to
|
|
16
|
-
function
|
|
15
|
+
// TODO: move to VariableProvider/utils.ts
|
|
16
|
+
function hydrateVariableState(variable, initialValue) {
|
|
17
17
|
const varState = {
|
|
18
18
|
value: null,
|
|
19
19
|
loading: false,
|
|
@@ -58,7 +58,7 @@ function hydrateTemplateVariableState(variable, initialValue) {
|
|
|
58
58
|
* @param localDefinitions local variable definitions. Dynamic part.
|
|
59
59
|
* @param externalDefinitions external variables definitions. Static part.
|
|
60
60
|
* @param initialValues values coming from query parameters
|
|
61
|
-
*/ export function
|
|
61
|
+
*/ export function hydrateVariableDefinitionStates(localDefinitions, initialValues, externalDefinitions = []) {
|
|
62
62
|
const state = new VariableStoreStateMap();
|
|
63
63
|
// Collect the names used by local definitions
|
|
64
64
|
let overridingNames = {};
|
|
@@ -78,7 +78,7 @@ function hydrateTemplateVariableState(variable, initialValue) {
|
|
|
78
78
|
source,
|
|
79
79
|
name
|
|
80
80
|
}, {
|
|
81
|
-
...
|
|
81
|
+
...hydrateVariableState(v, initialValue),
|
|
82
82
|
overridden: !!overridingNames[name]
|
|
83
83
|
});
|
|
84
84
|
overridingNames[name] = true;
|
|
@@ -94,7 +94,7 @@ function hydrateTemplateVariableState(variable, initialValue) {
|
|
|
94
94
|
state.set({
|
|
95
95
|
name
|
|
96
96
|
}, {
|
|
97
|
-
...
|
|
97
|
+
...hydrateVariableState(v, initialValue),
|
|
98
98
|
overriding: !!overriddenNames[name]
|
|
99
99
|
});
|
|
100
100
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/context/VariableProvider/hydrationUtils.ts"],"sourcesContent":["// Copyright 2024 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 { DEFAULT_ALL_VALUE, VariableValue, VariableDefinition } from '@perses-dev/core';\nimport { VariableStoreStateMap, VariableState } from '@perses-dev/plugin-system';\nimport { ExternalVariableDefinition } from '@perses-dev/dashboards';\n\n// TODO: move to VariableProvider/utils.ts\nfunction hydrateVariableState(variable: VariableDefinition, initialValue?: VariableValue): VariableState {\n const varState: VariableState = {\n value: null,\n loading: false,\n overriding: false,\n overridden: false,\n };\n switch (variable.kind) {\n case 'TextVariable':\n varState.value = initialValue ?? variable.spec.value;\n break;\n case 'ListVariable':\n varState.options = [];\n varState.value = initialValue ?? variable.spec.defaultValue ?? null;\n // TODO: smarter fallbacks for defaultValue when allowAllValue is true\n if (varState.options.length > 0 && !varState.value) {\n const firstOptionValue = varState.options[0]?.value ?? null;\n if (firstOptionValue !== null) {\n varState.value = variable.spec.allowMultiple ? [firstOptionValue] : firstOptionValue;\n }\n }\n\n // \"all\" variable handling assumes the value is not in an array. This is\n // handled properly during internal variable interactions, but it is possible\n // to end up in a buggy state if the variables are initialized with an \"all\"\n // value inside an array. When hydrating variables, normalize this to minimize\n // bugs.\n if (Array.isArray(varState.value) && varState.value.length === 1 && varState.value[0] === DEFAULT_ALL_VALUE) {\n varState.value = DEFAULT_ALL_VALUE;\n }\n\n break;\n default:\n break;\n }\n return varState;\n}\n\n/**\n * Build the local variable states according to the given definitions\n * @param localDefinitions local variable definitions. Dynamic part.\n * @param externalDefinitions external variables definitions. Static part.\n * @param initialValues values coming from query parameters\n */\nexport function hydrateVariableDefinitionStates(\n localDefinitions: VariableDefinition[],\n initialValues: Record<string, VariableValue>,\n externalDefinitions: ExternalVariableDefinition[] = []\n): VariableStoreStateMap {\n const state: VariableStoreStateMap = new VariableStoreStateMap();\n\n // Collect the names used by local definitions\n let overridingNames: Record<string, boolean> = {};\n localDefinitions.forEach(\n (v) => {\n overridingNames[v.spec.name] = true;\n },\n {} as Record<string, boolean>\n );\n\n // Then populate the external variables state,\n // taking care of well flagging each name as used, so the overridden state can be filled accordingly.\n const overriddenNames: Record<string, boolean> = {};\n externalDefinitions.forEach(\n (externalDef) => {\n const source = externalDef.source;\n externalDef.definitions.forEach((v) => {\n const name = v.spec.name;\n const param = initialValues[name];\n const initialValue = param ? param : null;\n state.set(\n { source, name },\n {\n ...hydrateVariableState(v, initialValue),\n overridden: !!overridingNames[name],\n }\n );\n\n overridingNames[name] = true;\n overriddenNames[v.spec.name] = true;\n });\n },\n {} as Record<string, boolean>\n );\n\n // Then populate the local variables state,\n // taking care the overriding state is filled according to the names used in external variables.\n localDefinitions.forEach((v) => {\n const name = v.spec.name;\n const param = initialValues[name];\n const initialValue = param ? param : null;\n state.set(\n { name },\n {\n ...hydrateVariableState(v, initialValue),\n overriding: !!overriddenNames[name],\n }\n );\n });\n\n overridingNames = {};\n externalDefinitions\n .slice()\n .reverse()\n .forEach((externalDef) => {\n const source = externalDef.source;\n externalDef.definitions.forEach((v) => {\n const name = v.spec.name;\n const value = state.get({ source, name });\n if (value) {\n value.overriding = !!overridingNames[name];\n }\n overridingNames[name] = true;\n });\n });\n return state;\n}\n"],"names":["DEFAULT_ALL_VALUE","VariableStoreStateMap","hydrateVariableState","variable","initialValue","varState","value","loading","overriding","overridden","kind","spec","options","defaultValue","length","firstOptionValue","allowMultiple","Array","isArray","hydrateVariableDefinitionStates","localDefinitions","initialValues","externalDefinitions","state","overridingNames","forEach","v","name","overriddenNames","externalDef","source","definitions","param","set","slice","reverse","get"],"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,iBAAiB,QAA2C,mBAAmB;AACxF,SAASC,qBAAqB,QAAuB,4BAA4B;AAGjF,0CAA0C;AAC1C,SAASC,qBAAqBC,QAA4B,EAAEC,YAA4B;IACtF,MAAMC,WAA0B;QAC9BC,OAAO;QACPC,SAAS;QACTC,YAAY;QACZC,YAAY;IACd;IACA,OAAQN,SAASO,IAAI;QACnB,KAAK;YACHL,SAASC,KAAK,GAAGF,yBAAAA,0BAAAA,eAAgBD,SAASQ,IAAI,CAACL,KAAK;YACpD;QACF,KAAK;YACHD,SAASO,OAAO,GAAG,EAAE;gBACJR;YAAjBC,SAASC,KAAK,GAAGF,CAAAA,OAAAA,yBAAAA,0BAAAA,eAAgBD,SAASQ,IAAI,CAACE,YAAY,cAA1CT,kBAAAA,OAA8C;YAC/D,sEAAsE;YACtE,IAAIC,SAASO,OAAO,CAACE,MAAM,GAAG,KAAK,CAACT,SAASC,KAAK,EAAE;oBACzBD;oBAAAA;gBAAzB,MAAMU,mBAAmBV,CAAAA,4BAAAA,qBAAAA,SAASO,OAAO,CAAC,EAAE,cAAnBP,yCAAAA,mBAAqBC,KAAK,cAA1BD,sCAAAA,2BAA8B;gBACvD,IAAIU,qBAAqB,MAAM;oBAC7BV,SAASC,KAAK,GAAGH,SAASQ,IAAI,CAACK,aAAa,GAAG;wBAACD;qBAAiB,GAAGA;gBACtE;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