@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,"file":"PanelSpecEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGtG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,KAAK,EAAE,iBAAiB,EAAe,MAAM,aAAa,CAAC;AAElE,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAM3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpC,eAAe,EAAE,eAAe,CAAC;IACjC,wBAAwB,EAAE,uBAAuB,EAAE,CAAC;IACpD,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,eAAe,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;IACtD,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC5D,kBAAkB,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,mBAAmB,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IAC7D,YAAY,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAED,eAAO,MAAM,eAAe,
|
|
1
|
+
{"version":3,"file":"PanelSpecEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.tsx"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGtG,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAG/C,OAAO,KAAK,EAAE,iBAAiB,EAAe,MAAM,aAAa,CAAC;AAElE,OAAO,KAAK,EAAE,UAAU,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAM3E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGvD,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpC,eAAe,EAAE,eAAe,CAAC;IACjC,wBAAwB,EAAE,uBAAuB,EAAE,CAAC;IACpD,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;IAC3B,eAAe,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;IACtD,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC5D,kBAAkB,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,mBAAmB,EAAE,CAAC,WAAW,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IAC7D,YAAY,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAED,eAAO,MAAM,eAAe,kHAmJ1B,CAAC"}
|
|
@@ -23,7 +23,10 @@ import { PanelAnnotationsEditor } from "./PanelAnnotationsEditor.js";
|
|
|
23
23
|
export const PanelSpecEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
24
24
|
const { control, panelDefinition, variableDefinitionGroups, panelGroups, onQueriesChange, onQueryRun, onPluginSpecChange, onAnnotationsChange, onJSONChange } = props;
|
|
25
25
|
const { kind } = panelDefinition.spec.plugin;
|
|
26
|
-
const { data: plugin, isLoading, error } = usePlugin('Panel', kind
|
|
26
|
+
const { data: plugin, isLoading, error } = usePlugin('Panel', kind, {
|
|
27
|
+
version: panelDefinition.spec.plugin.metadata?.version,
|
|
28
|
+
registry: panelDefinition.spec.plugin.metadata?.registry
|
|
29
|
+
});
|
|
27
30
|
const { queryResults } = useDataQueriesContext();
|
|
28
31
|
if (error) {
|
|
29
32
|
return /*#__PURE__*/ _jsx(ErrorAlert, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.tsx"],"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 { ErrorAlert, JSONEditor } from '@perses-dev/components';\nimport type { AnnotationSpec, PanelDefinition, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { ReactElement } from 'react';\nimport { forwardRef } from 'react';\nimport type { Control } from 'react-hook-form';\nimport { Controller } from 'react-hook-form';\n\nimport type { PanelEditorValues, PanelPlugin } from '../../model';\nimport { useDataQueriesContext, usePlugin } from '../../runtime';\nimport type { PanelGroup, VariableDefinitionGroup } from '../LayoutEditor';\nimport { LayoutEditor } from '../LayoutEditor';\nimport { LinksEditor } from '../LinksEditor';\nimport { MultiQueryEditor } from '../MultiQueryEditor';\nimport type { OptionsEditorTabsProps } from '../OptionsEditorTabs';\nimport { OptionsEditorTabs } from '../OptionsEditorTabs';\nimport type { PluginEditorRef } from '../PluginEditor';\nimport { PanelAnnotationsEditor } from './PanelAnnotationsEditor';\n\nexport interface PanelSpecEditorProps {\n control: Control<PanelEditorValues>;\n panelDefinition: PanelDefinition;\n variableDefinitionGroups: VariableDefinitionGroup[];\n panelGroups?: PanelGroup[];\n onQueriesChange: (queries: QueryDefinition[]) => void;\n onQueryRun: (index: number, query: QueryDefinition) => void;\n onPluginSpecChange: (spec: UnknownSpec) => void;\n onAnnotationsChange: (annotations: AnnotationSpec[]) => void;\n onJSONChange: (panelDefinitionStr: string) => void;\n}\n\nexport const PanelSpecEditor = forwardRef<PluginEditorRef, PanelSpecEditorProps>((props, ref): ReactElement | null => {\n const {\n control,\n panelDefinition,\n variableDefinitionGroups,\n panelGroups,\n onQueriesChange,\n onQueryRun,\n onPluginSpecChange,\n onAnnotationsChange,\n onJSONChange,\n } = props;\n const { kind } = panelDefinition.spec.plugin;\n const { data: plugin, isLoading, error } = usePlugin('Panel', kind);\n\n const { queryResults } = useDataQueriesContext();\n\n if (error) {\n return <ErrorAlert error={error} />;\n }\n\n if (isLoading) {\n return null;\n }\n\n if (!plugin) {\n throw new Error(`Missing implementation for panel plugin with kind '${kind}'`);\n }\n\n const { panelOptionsEditorComponents, hideQueryEditor, supportsAnnotations } = plugin as PanelPlugin;\n let tabs: OptionsEditorTabsProps['tabs'] = [];\n\n if (!hideQueryEditor) {\n tabs.push({\n label: 'Query',\n content: (\n <Controller\n control={control}\n name=\"panelDefinition.spec.queries\"\n render={({ field }) => (\n <MultiQueryEditor\n ref={ref}\n queryTypes={plugin.supportedQueryTypes ?? []}\n queries={panelDefinition.spec.queries ?? []}\n queryResults={queryResults}\n onChange={(queries) => {\n field.onChange(queries);\n onQueriesChange(queries);\n }}\n onQueryRun={(index, query) => {\n onQueryRun(index, query);\n // If spec has not changed, refetch to update the data\n if (JSON.stringify(panelDefinition.spec.queries?.[index]) === JSON.stringify(query)) {\n queryResults[index]?.refetch?.();\n }\n }}\n />\n )}\n />\n ),\n });\n }\n\n if (panelOptionsEditorComponents) {\n tabs = tabs.concat(\n panelOptionsEditorComponents.map(({ label, content: OptionsEditorComponent }) => ({\n label,\n content: (\n <Controller\n control={control}\n name=\"panelDefinition.spec.plugin.spec\"\n render={({ field }) => (\n <OptionsEditorComponent\n value={panelDefinition.spec.plugin.spec}\n onChange={(spec) => {\n field.onChange(spec);\n onPluginSpecChange(spec);\n }}\n />\n )}\n />\n ),\n })),\n );\n }\n\n // annotations are common to all panel plugins, but only shown for plugins that render them\n if (supportsAnnotations) {\n tabs.push({\n label: 'Annotations',\n content: (\n <Controller\n control={control}\n name=\"panelDefinition.spec.annotations\"\n render={({ field }) => (\n <PanelAnnotationsEditor\n value={panelDefinition.spec.annotations ?? []}\n onChange={(annotations) => {\n field.onChange(annotations);\n onAnnotationsChange(annotations);\n }}\n />\n )}\n />\n ),\n });\n }\n\n // Always show the JSON editor, Links editor, and Layout editor by default.\n tabs.push({\n label: 'Links',\n content: <LinksEditor control={control} />,\n });\n tabs.push({\n label: 'JSON',\n content: (\n <Controller\n control={control}\n name=\"panelDefinition\"\n render={({ field }) => (\n <JSONEditor\n maxHeight=\"80vh\"\n value={panelDefinition}\n onChange={(json) => {\n field.onChange(JSON.parse(json));\n onJSONChange(json);\n }}\n />\n )}\n />\n ),\n });\n tabs.push({\n label: 'Layout',\n content: (\n <LayoutEditor control={control} variableDefinitionGroups={variableDefinitionGroups} panelGroups={panelGroups} />\n ),\n });\n\n return <OptionsEditorTabs key={tabs.length} tabs={tabs} />;\n});\n\nPanelSpecEditor.displayName = 'PanelSpecEditor';\n"],"names":["ErrorAlert","JSONEditor","forwardRef","Controller","useDataQueriesContext","usePlugin","LayoutEditor","LinksEditor","MultiQueryEditor","OptionsEditorTabs","PanelAnnotationsEditor","PanelSpecEditor","props","ref","control","panelDefinition","variableDefinitionGroups","panelGroups","onQueriesChange","onQueryRun","onPluginSpecChange","onAnnotationsChange","onJSONChange","kind","spec","plugin","data","isLoading","error","queryResults","Error","panelOptionsEditorComponents","hideQueryEditor","supportsAnnotations","tabs","push","label","content","name","render","field","queryTypes","supportedQueryTypes","queries","onChange","index","query","JSON","stringify","refetch","concat","map","OptionsEditorComponent","value","annotations","maxHeight","json","parse","length","displayName"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C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BAAoBiC;wBACtB;;;QAKV;IACF;IAEA,2EAA2E;IAC3EpB,KAAKC,IAAI,CAAC;QACRC,OAAO;QACPC,uBAAS,KAAC9B;YAAYO,SAASA;;IACjC;IACAoB,KAAKC,IAAI,CAAC;QACRC,OAAO;QACPC,uBACE,KAAClC;YACCW,SAASA;YACTwB,MAAK;YACLC,QAAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,KAACvC;oBACCsD,WAAU;oBACVF,OAAOtC;oBACP6B,UAAU,CAACY;wBACThB,MAAMI,QAAQ,CAACG,KAAKU,KAAK,CAACD;wBAC1BlC,aAAakC;oBACf;;;IAKV;IACAtB,KAAKC,IAAI,CAAC;QACRC,OAAO;QACPC,uBACE,KAAC/B;YAAaQ,SAASA;YAASE,0BAA0BA;YAA0BC,aAAaA;;IAErG;IAEA,qBAAO,KAACR;QAAoCyB,MAAMA;OAAnBA,KAAKwB,MAAM;AAC5C,GAAG;AAEH/C,gBAAgBgD,WAAW,GAAG"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.tsx"],"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 { ErrorAlert, JSONEditor } from '@perses-dev/components';\nimport type { AnnotationSpec, PanelDefinition, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { ReactElement } from 'react';\nimport { forwardRef } from 'react';\nimport type { Control } from 'react-hook-form';\nimport { Controller } from 'react-hook-form';\n\nimport type { PanelEditorValues, PanelPlugin } from '../../model';\nimport { useDataQueriesContext, usePlugin } from '../../runtime';\nimport type { PanelGroup, VariableDefinitionGroup } from '../LayoutEditor';\nimport { LayoutEditor } from '../LayoutEditor';\nimport { LinksEditor } from '../LinksEditor';\nimport { MultiQueryEditor } from '../MultiQueryEditor';\nimport type { OptionsEditorTabsProps } from '../OptionsEditorTabs';\nimport { OptionsEditorTabs } from '../OptionsEditorTabs';\nimport type { PluginEditorRef } from '../PluginEditor';\nimport { PanelAnnotationsEditor } from './PanelAnnotationsEditor';\n\nexport interface PanelSpecEditorProps {\n control: Control<PanelEditorValues>;\n panelDefinition: PanelDefinition;\n variableDefinitionGroups: VariableDefinitionGroup[];\n panelGroups?: PanelGroup[];\n onQueriesChange: (queries: QueryDefinition[]) => void;\n onQueryRun: (index: number, query: QueryDefinition) => void;\n onPluginSpecChange: (spec: UnknownSpec) => void;\n onAnnotationsChange: (annotations: AnnotationSpec[]) => void;\n onJSONChange: (panelDefinitionStr: string) => void;\n}\n\nexport const PanelSpecEditor = forwardRef<PluginEditorRef, PanelSpecEditorProps>((props, ref): ReactElement | null => {\n const {\n control,\n panelDefinition,\n variableDefinitionGroups,\n panelGroups,\n onQueriesChange,\n onQueryRun,\n onPluginSpecChange,\n onAnnotationsChange,\n onJSONChange,\n } = props;\n const { kind } = panelDefinition.spec.plugin;\n const {\n data: plugin,\n isLoading,\n error,\n } = usePlugin('Panel', kind, {\n version: panelDefinition.spec.plugin.metadata?.version,\n registry: panelDefinition.spec.plugin.metadata?.registry,\n });\n\n const { queryResults } = useDataQueriesContext();\n\n if (error) {\n return <ErrorAlert error={error} />;\n }\n\n if (isLoading) {\n return null;\n }\n\n if (!plugin) {\n throw new Error(`Missing implementation for panel plugin with kind '${kind}'`);\n }\n\n const { panelOptionsEditorComponents, hideQueryEditor, supportsAnnotations } = plugin as PanelPlugin;\n let tabs: OptionsEditorTabsProps['tabs'] = [];\n\n if (!hideQueryEditor) {\n tabs.push({\n label: 'Query',\n content: (\n <Controller\n control={control}\n name=\"panelDefinition.spec.queries\"\n render={({ field }) => (\n <MultiQueryEditor\n ref={ref}\n queryTypes={plugin.supportedQueryTypes ?? []}\n queries={panelDefinition.spec.queries ?? []}\n queryResults={queryResults}\n onChange={(queries) => {\n field.onChange(queries);\n onQueriesChange(queries);\n }}\n onQueryRun={(index, query) => {\n onQueryRun(index, query);\n // If spec has not changed, refetch to update the data\n if (JSON.stringify(panelDefinition.spec.queries?.[index]) === JSON.stringify(query)) {\n queryResults[index]?.refetch?.();\n }\n }}\n />\n )}\n />\n ),\n });\n }\n\n if (panelOptionsEditorComponents) {\n tabs = tabs.concat(\n panelOptionsEditorComponents.map(({ label, content: OptionsEditorComponent }) => ({\n label,\n content: (\n <Controller\n control={control}\n name=\"panelDefinition.spec.plugin.spec\"\n render={({ field }) => (\n <OptionsEditorComponent\n value={panelDefinition.spec.plugin.spec}\n onChange={(spec) => {\n field.onChange(spec);\n onPluginSpecChange(spec);\n }}\n />\n )}\n />\n ),\n })),\n );\n }\n\n // annotations are common to all panel plugins, but only shown for plugins that render them\n if (supportsAnnotations) {\n tabs.push({\n label: 'Annotations',\n content: (\n <Controller\n control={control}\n name=\"panelDefinition.spec.annotations\"\n render={({ field }) => (\n <PanelAnnotationsEditor\n value={panelDefinition.spec.annotations ?? []}\n onChange={(annotations) => {\n field.onChange(annotations);\n onAnnotationsChange(annotations);\n }}\n />\n )}\n />\n ),\n });\n }\n\n // Always show the JSON editor, Links editor, and Layout editor by default.\n tabs.push({\n label: 'Links',\n content: <LinksEditor control={control} />,\n });\n tabs.push({\n label: 'JSON',\n content: (\n <Controller\n control={control}\n name=\"panelDefinition\"\n render={({ field }) => (\n <JSONEditor\n maxHeight=\"80vh\"\n value={panelDefinition}\n onChange={(json) => {\n field.onChange(JSON.parse(json));\n onJSONChange(json);\n }}\n />\n )}\n />\n ),\n });\n tabs.push({\n label: 'Layout',\n content: (\n <LayoutEditor control={control} variableDefinitionGroups={variableDefinitionGroups} panelGroups={panelGroups} />\n ),\n });\n\n return <OptionsEditorTabs key={tabs.length} tabs={tabs} />;\n});\n\nPanelSpecEditor.displayName = 'PanelSpecEditor';\n"],"names":["ErrorAlert","JSONEditor","forwardRef","Controller","useDataQueriesContext","usePlugin","LayoutEditor","LinksEditor","MultiQueryEditor","OptionsEditorTabs","PanelAnnotationsEditor","PanelSpecEditor","props","ref","control","panelDefinition","variableDefinitionGroups","panelGroups","onQueriesChange","onQueryRun","onPluginSpecChange","onAnnotationsChange","onJSONChange","kind","spec","plugin","data","isLoading","error","version","metadata","registry","queryResults","Error","panelOptionsEditorComponents","hideQueryEditor","supportsAnnotations","tabs","push","label","content","name","render","field","queryTypes","supportedQueryTypes","queries","onChange","index","query","JSON","stringify","refetch","concat","map","OptionsEditorComponent","value","annotations","maxHeight","json","parse","length","displayName"],"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;AAEjC,SAASA,UAAU,EAAEC,UAAU,QAAQ,yBAAyB;AAGhE,SAASC,UAAU,QAAQ,QAAQ;AAEnC,SAASC,UAAU,QAAQ,kBAAkB;AAG7C,SAASC,qBAAqB,EAAEC,SAAS,QAAQ,yBAAgB;AAEjE,SAASC,YAAY,QAAQ,2BAAkB;AAC/C,SAASC,WAAW,QAAQ,0BAAiB;AAC7C,SAASC,gBAAgB,QAAQ,+BAAsB;AAEvD,SAASC,iBAAiB,QAAQ,gCAAuB;AAEzD,SAASC,sBAAsB,QAAQ,8BAA2B;AAclE,OAAO,MAAMC,gCAAkBT,WAAkD,CAACU,OAAOC;IACvF,MAAM,EACJC,OAAO,EACPC,eAAe,EACfC,wBAAwB,EACxBC,WAAW,EACXC,eAAe,EACfC,UAAU,EACVC,kBAAkB,EAClBC,mBAAmB,EACnBC,YAAY,EACb,GAAGV;IACJ,MAAM,EAAEW,IAAI,EAAE,GAAGR,gBAAgBS,IAAI,CAACC,MAAM;IAC5C,MAAM,EACJ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AW,GAAG"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { BoxProps } from '@mui/material';
|
|
2
|
-
import type { DatasourceSpec, UnknownSpec } from '@perses-dev/spec';
|
|
2
|
+
import type { DatasourceSpec, PluginDefinitionMetadata, UnknownSpec } from '@perses-dev/spec';
|
|
3
3
|
import type { PluginType } from '../../model';
|
|
4
4
|
export interface PluginEditorSelection {
|
|
5
5
|
type: PluginType;
|
|
6
6
|
kind: string;
|
|
7
|
+
/**
|
|
8
|
+
* Optional plugin definition metadata (version and/or registry), matching the `metadata` field of a spec
|
|
9
|
+
* `Definition`. Only set when the user explicitly picks a specific version/registry of a plugin that has several of
|
|
10
|
+
* them available. When omitted, the latest available version is used.
|
|
11
|
+
*/
|
|
12
|
+
metadata?: PluginDefinitionMetadata;
|
|
7
13
|
}
|
|
8
14
|
export interface PluginEditorValue {
|
|
9
15
|
selection: PluginEditorSelection;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,wBAAwB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAK9F,OAAO,KAAK,EAAe,UAAU,EAAwB,MAAM,aAAa,CAAC;AAMjF,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,QAAQ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E,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAC1C,wBAAwB,EAAE,MAAM,IAAI,CAAC;CACtC,CAkIA"}
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
+
import { useMutation, useQueryClient } from "@tanstack/react-query";
|
|
13
14
|
import { produce } from "immer";
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
15
|
+
import { useRef, useEffect } from "react";
|
|
16
|
+
import { usePluginRegistry } from "../../runtime/index.js";
|
|
16
17
|
import { useEvent } from "../../utils/index.js";
|
|
17
18
|
/**
|
|
18
19
|
* Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide
|
|
@@ -20,7 +21,6 @@ import { useEvent } from "../../utils/index.js";
|
|
|
20
21
|
* remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin
|
|
21
22
|
* kind back.
|
|
22
23
|
*/ export function usePluginEditor(props) {
|
|
23
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
24
24
|
const { pluginTypes, value, onHideQueryEditorChange = ()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
|
|
25
25
|
// Keep a stable reference, so we don't run the effect below when we don't need to
|
|
26
26
|
const onChange = useEvent(props.onChange);
|
|
@@ -43,56 +43,63 @@ import { useEvent } from "../../utils/index.js";
|
|
|
43
43
|
const hideQueryState = useRef({
|
|
44
44
|
[value.selection.kind]: false
|
|
45
45
|
});
|
|
46
|
-
const { defaultPluginKinds } = usePluginRegistry();
|
|
46
|
+
const { defaultPluginKinds, getPlugin } = usePluginRegistry();
|
|
47
|
+
const queryClient = useQueryClient();
|
|
48
|
+
const currentRequest = useRef(undefined);
|
|
49
|
+
const selectionLoad = useMutation({
|
|
50
|
+
mutationFn: (selection)=>queryClient.fetchQuery({
|
|
51
|
+
queryKey: [
|
|
52
|
+
'getPlugin',
|
|
53
|
+
selection.type,
|
|
54
|
+
selection.kind,
|
|
55
|
+
selection.metadata?.version ?? '',
|
|
56
|
+
selection.metadata?.registry ?? ''
|
|
57
|
+
],
|
|
58
|
+
queryFn: ()=>getPlugin({
|
|
59
|
+
kind: selection.type,
|
|
60
|
+
name: selection.kind,
|
|
61
|
+
version: selection.metadata?.version,
|
|
62
|
+
registry: selection.metadata?.registry
|
|
63
|
+
})
|
|
64
|
+
})
|
|
65
|
+
});
|
|
66
|
+
const pendingSelection = selectionLoad.isSuccess ? undefined : selectionLoad.variables;
|
|
47
67
|
const defaultPluginType = pluginTypes[0];
|
|
48
68
|
const defaultPluginKind = defaultPluginType ? defaultPluginKinds?.[defaultPluginType] : undefined;
|
|
49
|
-
|
|
50
|
-
type: defaultPluginType,
|
|
51
|
-
kind: defaultPluginKind
|
|
52
|
-
} : undefined;
|
|
53
|
-
const initPendingSelection = !value.selection && defaultPluginSelection ? defaultPluginSelection : undefined;
|
|
54
|
-
// When kind changes and we haven't loaded that plugin before, we will need to enter a "pending" state so that we
|
|
55
|
-
// can generate proper initial spec values that match the new plugin kind
|
|
56
|
-
const [pendingSelection, setPendingSelection] = useState(initPendingSelection);
|
|
57
|
-
// Take a default kind in case user write explicitly an empty kind in the initial value
|
|
69
|
+
// Notify the owner instead of mutating the selection passed by the caller.
|
|
58
70
|
useEffect(()=>{
|
|
59
|
-
if (value.selection.kind === '') {
|
|
60
|
-
|
|
71
|
+
if (value.selection.kind === '' && defaultPluginKind) {
|
|
72
|
+
onChange({
|
|
73
|
+
...value,
|
|
74
|
+
selection: {
|
|
75
|
+
...value.selection,
|
|
76
|
+
kind: defaultPluginKind
|
|
77
|
+
}
|
|
78
|
+
});
|
|
61
79
|
}
|
|
62
80
|
}, [
|
|
63
|
-
value
|
|
64
|
-
defaultPluginKind
|
|
81
|
+
value,
|
|
82
|
+
defaultPluginKind,
|
|
83
|
+
onChange
|
|
65
84
|
]);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
//
|
|
69
|
-
if (!
|
|
70
|
-
|
|
71
|
-
if (plugin === undefined || isFetching) return;
|
|
72
|
-
// Fire an onChange to change to the pending kind with initial values from the plugin
|
|
85
|
+
// Apply each completed load once, independently of how the owner stores the selection metadata.
|
|
86
|
+
const applyLoadedSelection = useEvent((plugin, selection)=>{
|
|
87
|
+
// v4 `reset()` still observes the in-flight load, which then reports the current (empty or newer) result.
|
|
88
|
+
if (!plugin || selection !== currentRequest.current) return;
|
|
89
|
+
currentRequest.current = undefined;
|
|
73
90
|
rememberCurrentSpecState();
|
|
74
91
|
onChange({
|
|
75
|
-
selection
|
|
92
|
+
selection,
|
|
76
93
|
spec: plugin.createInitialOptions ? plugin.createInitialOptions() : {}
|
|
77
94
|
});
|
|
78
|
-
if (
|
|
95
|
+
if (selection.type === 'Panel') {
|
|
79
96
|
const panelPlugin = plugin;
|
|
80
|
-
hideQueryState.current[
|
|
97
|
+
hideQueryState.current[selection.kind] = !!panelPlugin.hideQueryEditor;
|
|
81
98
|
if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.selection.kind]) {
|
|
82
99
|
onHideQuery(!!panelPlugin.hideQueryEditor);
|
|
83
100
|
}
|
|
84
101
|
}
|
|
85
|
-
|
|
86
|
-
}, [
|
|
87
|
-
pendingSelection,
|
|
88
|
-
plugin,
|
|
89
|
-
isFetching,
|
|
90
|
-
rememberCurrentSpecState,
|
|
91
|
-
onChange,
|
|
92
|
-
onHideQuery,
|
|
93
|
-
hideQueryState,
|
|
94
|
-
value.selection
|
|
95
|
-
]);
|
|
102
|
+
});
|
|
96
103
|
/**
|
|
97
104
|
* When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we
|
|
98
105
|
* make the switch.
|
|
@@ -100,6 +107,8 @@ import { useEvent } from "../../utils/index.js";
|
|
|
100
107
|
// If we already have state for this plugin type/kind from a previous selection, just use it
|
|
101
108
|
const previousState = prevSpecState.current[nextSelection.type]?.[nextSelection.kind];
|
|
102
109
|
if (previousState !== undefined) {
|
|
110
|
+
currentRequest.current = undefined;
|
|
111
|
+
selectionLoad.reset();
|
|
103
112
|
rememberCurrentSpecState();
|
|
104
113
|
onChange({
|
|
105
114
|
selection: nextSelection,
|
|
@@ -107,7 +116,11 @@ import { useEvent } from "../../utils/index.js";
|
|
|
107
116
|
});
|
|
108
117
|
} else {
|
|
109
118
|
// Otherwise, kick off the async loading process
|
|
110
|
-
|
|
119
|
+
// Per-call callbacks run only for the latest mutation while the editor is mounted.
|
|
120
|
+
currentRequest.current = nextSelection;
|
|
121
|
+
selectionLoad.mutate(nextSelection, {
|
|
122
|
+
onSuccess: applyLoadedSelection
|
|
123
|
+
});
|
|
111
124
|
}
|
|
112
125
|
if (nextSelection.type === 'Panel' && hideQueryState.current[nextSelection.kind] !== undefined && hideQueryState.current[value.selection.kind] !== hideQueryState.current[nextSelection.kind]) {
|
|
113
126
|
onHideQuery(!!hideQueryState.current[nextSelection.kind]);
|
|
@@ -122,8 +135,8 @@ import { useEvent } from "../../utils/index.js";
|
|
|
122
135
|
};
|
|
123
136
|
return {
|
|
124
137
|
pendingSelection,
|
|
125
|
-
isLoading:
|
|
126
|
-
error,
|
|
138
|
+
isLoading: selectionLoad.isLoading,
|
|
139
|
+
error: selectionLoad.error,
|
|
127
140
|
onSelectionChange,
|
|
128
141
|
onSpecChange,
|
|
129
142
|
rememberCurrentSpecState
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.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 { BoxProps } from '@mui/material';\nimport type { DatasourceSpec, UnknownSpec } from '@perses-dev/spec';\nimport { produce } from 'immer';\nimport { useState, useRef, useEffect } from 'react';\n\nimport type { PanelPlugin, PluginType } from '../../model';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\nimport { useEvent } from '../../utils';\nimport type { PluginKindSelectProps } from '../PluginKindSelect';\nimport type { PluginSpecEditorProps } from '../PluginSpecEditor';\n\nexport interface PluginEditorSelection {\n type: PluginType;\n kind: string;\n}\n\nexport interface PluginEditorValue {\n selection: PluginEditorSelection;\n spec: UnknownSpec;\n}\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\nexport interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n pluginTypes: PluginType[];\n pluginKindLabel: string;\n value: PluginEditorValue;\n isReadonly?: boolean;\n withRunQueryButton?: boolean;\n filteredQueryPlugins?: string[];\n onChange: (next: PluginEditorValue) => void;\n onRunQuery?: () => void;\n testConnection?: (spec: DatasourceSpec, healthCheckPath: string) => Promise<void>;\n}\n\nexport interface PluginEditorRef {\n flushChanges?: () => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\ntype HideQueryEditorState = Record<string, boolean>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginTypes' | 'value' | 'onChange'> & {\n onHideQueryEditorChange?: (isHidden: boolean) => void;\n};\n\n/**\n * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide\n * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also\n * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin\n * kind back.\n */\nexport function usePluginEditor(props: UsePluginEditorProps): {\n pendingSelection?: PluginEditorSelection;\n isLoading: boolean;\n error: Error | null;\n onSelectionChange: (s: PluginEditorSelection) => void;\n onSpecChange: (next: UnknownSpec) => void;\n rememberCurrentSpecState: () => void;\n} {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const { pluginTypes, value, onHideQueryEditorChange = (): void => {} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function\n\n // Keep a stable reference, so we don't run the effect below when we don't need to\n const onChange = useEvent(props.onChange);\n const onHideQuery = useEvent(onHideQueryEditorChange);\n\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [value.selection.type]: { [value.selection.kind]: value.spec },\n });\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[value.selection.type];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[value.selection.type] = byPluginType;\n }\n byPluginType[value.selection.kind] = value.spec;\n });\n\n // The previous hide query state for each panel kind\n const hideQueryState = useRef<HideQueryEditorState>({\n [value.selection.kind]: false,\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginType = pluginTypes[0];\n const defaultPluginKind = defaultPluginType ? defaultPluginKinds?.[defaultPluginType] : undefined;\n const defaultPluginSelection =\n defaultPluginType && defaultPluginKind\n ? {\n type: defaultPluginType,\n kind: defaultPluginKind,\n }\n : undefined;\n const initPendingSelection = !value.selection && defaultPluginSelection ? defaultPluginSelection : undefined;\n\n // When kind changes and we haven't loaded that plugin before, we will need to enter a \"pending\" state so that we\n // can generate proper initial spec values that match the new plugin kind\n const [pendingSelection, setPendingSelection] = useState<PluginEditorSelection | undefined>(initPendingSelection);\n\n // Take a default kind in case user write explicitly an empty kind in the initial value\n useEffect(() => {\n if (value.selection.kind === '') {\n value.selection.kind = defaultPluginKind || '';\n }\n }, [value.selection, defaultPluginKind]);\n\n const { data: plugin, isFetching, error } = usePlugin(pendingSelection?.type, pendingSelection?.kind || '');\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (!pendingSelection) return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined || isFetching) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n selection: pendingSelection,\n spec: plugin.createInitialOptions ? plugin.createInitialOptions() : {},\n });\n\n if (pendingSelection.type === 'Panel') {\n const panelPlugin = plugin as PanelPlugin;\n hideQueryState.current[pendingSelection.kind] = !!panelPlugin.hideQueryEditor;\n if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.selection.kind]) {\n onHideQuery(!!panelPlugin.hideQueryEditor);\n }\n }\n setPendingSelection(undefined);\n }, [\n pendingSelection,\n plugin,\n isFetching,\n rememberCurrentSpecState,\n onChange,\n onHideQuery,\n hideQueryState,\n value.selection,\n ]);\n\n /**\n * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we\n * make the switch.\n */\n const onSelectionChange: PluginKindSelectProps['onChange'] = (nextSelection) => {\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[nextSelection.type]?.[nextSelection.kind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n selection: nextSelection,\n spec: previousState,\n });\n } else {\n // Otherwise, kick off the async loading process\n setPendingSelection(nextSelection);\n }\n\n if (\n nextSelection.type === 'Panel' &&\n hideQueryState.current[nextSelection.kind] !== undefined &&\n hideQueryState.current[value.selection.kind] !== hideQueryState.current[nextSelection.kind]\n ) {\n onHideQuery(!!hideQueryState.current[nextSelection.kind]);\n }\n };\n\n /**\n * Spec changes are independent and always just set the spec state.\n */\n const onSpecChange: PluginSpecEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.spec = next;\n }),\n );\n };\n\n return {\n pendingSelection,\n isLoading: isFetching,\n error,\n onSelectionChange,\n onSpecChange,\n rememberCurrentSpecState,\n };\n}\n"],"names":["produce","useState","useRef","useEffect","usePlugin","usePluginRegistry","useEvent","usePluginEditor","props","pluginTypes","value","onHideQueryEditorChange","onChange","onHideQuery","prevSpecState","selection","type","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","hideQueryState","defaultPluginKinds","defaultPluginType","defaultPluginKind","defaultPluginSelection","initPendingSelection","pendingSelection","setPendingSelection","data","plugin","isFetching","error","createInitialOptions","panelPlugin","hideQueryEditor","onSelectionChange","nextSelection","previousState","onSpecChange","next","draft","isLoading"],"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,OAAO,QAAQ,QAAQ;AAChC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QAAQ,QAAQ;AAGpD,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,yBAAgB;AAC7D,SAASC,QAAQ,QAAQ,uBAAc;AA4CvC;;;;;CAKC,GACD,OAAO,SAASC,gBAAgBC,KAA2B;IAQzD,gEAAgE;IAChE,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAEC,0BAA0B,KAAa,CAAC,EAAE,GAAGH,OAAO,8FAA8F;IAE9K,kFAAkF;IAClF,MAAMI,WAAWN,SAASE,MAAMI,QAAQ;IACxC,MAAMC,cAAcP,SAASK;IAE7B,uGAAuG;IACvG,MAAMG,gBAAgBZ,OAA0B;QAC9C,CAACQ,MAAMK,SAAS,CAACC,IAAI,CAAC,EAAE;YAAE,CAACN,MAAMK,SAAS,CAACE,IAAI,CAAC,EAAEP,MAAMQ,IAAI;QAAC;IAC/D;IACA,MAAMC,2BAA2Bb,SAAS;QACxC,IAAIc,eAAeN,cAAcO,OAAO,CAACX,MAAMK,SAAS,CAACC,IAAI,CAAC;QAC9D,IAAII,iBAAiBE,WAAW;YAC9BF,eAAe,CAAC;YAChBN,cAAcO,OAAO,CAACX,MAAMK,SAAS,CAACC,IAAI,CAAC,GAAGI;QAChD;QACAA,YAAY,CAACV,MAAMK,SAAS,CAACE,IAAI,CAAC,GAAGP,MAAMQ,IAAI;IACjD;IAEA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AI,CAAC,EAAE;gBAClFJ,YAAY,CAAC,CAACuB,YAAYC,eAAe;YAC3C;QACF;QACAP,oBAAoBR;IACtB,GAAG;QACDO;QACAG;QACAC;QACAd;QACAP;QACAC;QACAU;QACAb,MAAMK,SAAS;KAChB;IAED;;;GAGC,GACD,MAAMuB,oBAAuD,CAACC;QAC5D,4FAA4F;QAC5F,MAAMC,gBAAgB1B,cAAcO,OAAO,CAACkB,cAAcvB,IAAI,CAAC,EAAE,CAACuB,cAActB,IAAI,CAAC;QACrF,IAAIuB,kBAAkBlB,WAAW;YAC/BH;YACAP,SAAS;gBACPG,WAAWwB;gBACXrB,MAAMsB;YACR;QACF,OAAO;YACL,gDAAgD;YAChDV,oBAAoBS;QACtB;QAEA,IACEA,cAAcvB,IAAI,KAAK,WACvBO,eAAeF,OAAO,CAACkB,cAActB,IAAI,CAAC,KAAKK,aAC/CC,eAAeF,OAAO,CAACX,MAAMK,SAAS,CAACE,IAAI,CAAC,KAAKM,eAAeF,OAAO,CAACkB,cAActB,IAAI,CAAC,EAC3F;YACAJ,YAAY,CAAC,CAACU,eAAeF,OAAO,CAACkB,cAActB,IAAI,CAAC;QAC1D;IACF;IAEA;;GAEC,GACD,MAAMwB,eAAkD,CAACC;QACvD9B,SACEZ,QAAQU,OAAO,CAACiC;YACdA,MAAMzB,IAAI,GAAGwB;QACf;IAEJ;IAEA,OAAO;QACLb;QACAe,WAAWX;QACXC;QACAI;QACAG;QACAtB;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.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 { BoxProps } from '@mui/material';\nimport type { DatasourceSpec, PluginDefinitionMetadata, UnknownSpec } from '@perses-dev/spec';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport { produce } from 'immer';\nimport { useRef, useEffect } from 'react';\n\nimport type { PanelPlugin, PluginType, PluginImplementation } from '../../model';\nimport { usePluginRegistry } from '../../runtime';\nimport { useEvent } from '../../utils';\nimport type { PluginKindSelectProps } from '../PluginKindSelect';\nimport type { PluginSpecEditorProps } from '../PluginSpecEditor';\n\nexport interface PluginEditorSelection {\n type: PluginType;\n kind: string;\n /**\n * Optional plugin definition metadata (version and/or registry), matching the `metadata` field of a spec\n * `Definition`. Only set when the user explicitly picks a specific version/registry of a plugin that has several of\n * them available. When omitted, the latest available version is used.\n */\n metadata?: PluginDefinitionMetadata;\n}\n\nexport interface PluginEditorValue {\n selection: PluginEditorSelection;\n spec: UnknownSpec;\n}\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\nexport interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n pluginTypes: PluginType[];\n pluginKindLabel: string;\n value: PluginEditorValue;\n isReadonly?: boolean;\n withRunQueryButton?: boolean;\n filteredQueryPlugins?: string[];\n onChange: (next: PluginEditorValue) => void;\n onRunQuery?: () => void;\n testConnection?: (spec: DatasourceSpec, healthCheckPath: string) => Promise<void>;\n}\n\nexport interface PluginEditorRef {\n flushChanges?: () => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\ntype HideQueryEditorState = Record<string, boolean>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginTypes' | 'value' | 'onChange'> & {\n onHideQueryEditorChange?: (isHidden: boolean) => void;\n};\n\n/**\n * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide\n * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also\n * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin\n * kind back.\n */\nexport function usePluginEditor(props: UsePluginEditorProps): {\n pendingSelection?: PluginEditorSelection;\n isLoading: boolean;\n error: Error | null;\n onSelectionChange: (s: PluginEditorSelection) => void;\n onSpecChange: (next: UnknownSpec) => void;\n rememberCurrentSpecState: () => void;\n} {\n const { pluginTypes, value, onHideQueryEditorChange = (): void => {} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function\n\n // Keep a stable reference, so we don't run the effect below when we don't need to\n const onChange = useEvent(props.onChange);\n const onHideQuery = useEvent(onHideQueryEditorChange);\n\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [value.selection.type]: { [value.selection.kind]: value.spec },\n });\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[value.selection.type];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[value.selection.type] = byPluginType;\n }\n byPluginType[value.selection.kind] = value.spec;\n });\n\n // The previous hide query state for each panel kind\n const hideQueryState = useRef<HideQueryEditorState>({\n [value.selection.kind]: false,\n });\n\n const { defaultPluginKinds, getPlugin } = usePluginRegistry();\n const queryClient = useQueryClient();\n const currentRequest = useRef<PluginEditorSelection | undefined>(undefined);\n const selectionLoad = useMutation<PluginImplementation<PluginType>, Error, PluginEditorSelection>({\n mutationFn: (selection) =>\n queryClient.fetchQuery({\n queryKey: [\n 'getPlugin',\n selection.type,\n selection.kind,\n selection.metadata?.version ?? '',\n selection.metadata?.registry ?? '',\n ],\n queryFn: () =>\n getPlugin({\n kind: selection.type,\n name: selection.kind,\n version: selection.metadata?.version,\n registry: selection.metadata?.registry,\n }),\n }),\n });\n const pendingSelection = selectionLoad.isSuccess ? undefined : selectionLoad.variables;\n const defaultPluginType = pluginTypes[0];\n const defaultPluginKind = defaultPluginType ? defaultPluginKinds?.[defaultPluginType] : undefined;\n\n // Notify the owner instead of mutating the selection passed by the caller.\n useEffect(() => {\n if (value.selection.kind === '' && defaultPluginKind) {\n onChange({ ...value, selection: { ...value.selection, kind: defaultPluginKind } });\n }\n }, [value, defaultPluginKind, onChange]);\n\n // Apply each completed load once, independently of how the owner stores the selection metadata.\n const applyLoadedSelection = useEvent(\n (plugin: PluginImplementation<PluginType> | undefined, selection: PluginEditorSelection) => {\n // v4 `reset()` still observes the in-flight load, which then reports the current (empty or newer) result.\n if (!plugin || selection !== currentRequest.current) return;\n currentRequest.current = undefined;\n rememberCurrentSpecState();\n onChange({\n selection,\n spec: plugin.createInitialOptions ? plugin.createInitialOptions() : {},\n });\n\n if (selection.type === 'Panel') {\n const panelPlugin = plugin as PanelPlugin;\n hideQueryState.current[selection.kind] = !!panelPlugin.hideQueryEditor;\n if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.selection.kind]) {\n onHideQuery(!!panelPlugin.hideQueryEditor);\n }\n }\n },\n );\n\n /**\n * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we\n * make the switch.\n */\n const onSelectionChange: PluginKindSelectProps['onChange'] = (nextSelection) => {\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[nextSelection.type]?.[nextSelection.kind];\n if (previousState !== undefined) {\n currentRequest.current = undefined;\n selectionLoad.reset();\n rememberCurrentSpecState();\n onChange({\n selection: nextSelection,\n spec: previousState,\n });\n } else {\n // Otherwise, kick off the async loading process\n // Per-call callbacks run only for the latest mutation while the editor is mounted.\n currentRequest.current = nextSelection;\n selectionLoad.mutate(nextSelection, { onSuccess: applyLoadedSelection });\n }\n\n if (\n nextSelection.type === 'Panel' &&\n hideQueryState.current[nextSelection.kind] !== undefined &&\n hideQueryState.current[value.selection.kind] !== hideQueryState.current[nextSelection.kind]\n ) {\n onHideQuery(!!hideQueryState.current[nextSelection.kind]);\n }\n };\n\n /**\n * Spec changes are independent and always just set the spec state.\n */\n const onSpecChange: PluginSpecEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.spec = next;\n }),\n );\n };\n\n return {\n pendingSelection,\n isLoading: selectionLoad.isLoading,\n error: selectionLoad.error,\n onSelectionChange,\n onSpecChange,\n rememberCurrentSpecState,\n };\n}\n"],"names":["useMutation","useQueryClient","produce","useRef","useEffect","usePluginRegistry","useEvent","usePluginEditor","props","pluginTypes","value","onHideQueryEditorChange","onChange","onHideQuery","prevSpecState","selection","type","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","hideQueryState","defaultPluginKinds","getPlugin","queryClient","currentRequest","selectionLoad","mutationFn","fetchQuery","queryKey","metadata","version","registry","queryFn","name","pendingSelection","isSuccess","variables","defaultPluginType","defaultPluginKind","applyLoadedSelection","plugin","createInitialOptions","panelPlugin","hideQueryEditor","onSelectionChange","nextSelection","previousState","reset","mutate","onSuccess","onSpecChange","next","draft","isLoading","error"],"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,WAAW,EAAEC,cAAc,QAAQ,wBAAwB;AACpE,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,MAAM,EAAEC,SAAS,QAAQ,QAAQ;AAG1C,SAASC,iBAAiB,QAAQ,yBAAgB;AAClD,SAASC,QAAQ,QAAQ,uBAAc;AAkDvC;;;;;CAKC,GACD,OAAO,SAASC,gBAAgBC,KAA2B;IAQzD,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAEC,0BAA0B,KAAa,CAAC,EAAE,GAAGH,OAAO,8FAA8F;IAE9K,kFAAkF;IAClF,MAAMI,WAAWN,SAASE,MAAMI,QAAQ;IACxC,MAAMC,cAAcP,SAASK;IAE7B,uGAAuG;IACvG,MAAMG,gBAAgBX,OAA0B;QAC9C,CAACO,MAAMK,SAAS,CAACC,IAAI,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AeF,OAAO,CAAC2B,cAAc/B,IAAI,CAAC,KAAKK,aAC/CC,eAAeF,OAAO,CAACX,MAAMK,SAAS,CAACE,IAAI,CAAC,KAAKM,eAAeF,OAAO,CAAC2B,cAAc/B,IAAI,CAAC,EAC3F;YACAJ,YAAY,CAAC,CAACU,eAAeF,OAAO,CAAC2B,cAAc/B,IAAI,CAAC;QAC1D;IACF;IAEA;;GAEC,GACD,MAAMoC,eAAkD,CAACC;QACvD1C,SACEV,QAAQQ,OAAO,CAAC6C;YACdA,MAAMrC,IAAI,GAAGoC;QACf;IAEJ;IAEA,OAAO;QACLjB;QACAmB,WAAW5B,cAAc4B,SAAS;QAClCC,OAAO7B,cAAc6B,KAAK;QAC1BV;QACAM;QACAlC;IACF;AACF"}
|
|
@@ -6,6 +6,20 @@ export interface PluginKindSelectProps extends Omit<TextFieldProps, 'value' | 'o
|
|
|
6
6
|
pluginTypes: PluginType[];
|
|
7
7
|
value?: PluginEditorSelection;
|
|
8
8
|
onChange?: (s: PluginEditorSelection) => void;
|
|
9
|
+
/**
|
|
10
|
+
* When true, a plugin that has more than one version available is listed with a `<display name> - Latest` option and
|
|
11
|
+
* once per version, labeled `<display name> - <version>`. Selecting a specific version sets `metadata.version` on the
|
|
12
|
+
* selection so it can be persisted on the definition, while selecting Latest leaves the version unpinned. A plugin
|
|
13
|
+
* with a single available version is listed without a version, so it keeps resolving to the latest one. Defaults to
|
|
14
|
+
* false.
|
|
15
|
+
*/
|
|
16
|
+
enableVersionSelection?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* When true, a plugin that is available in more than one registry is listed once per registry, labeled
|
|
19
|
+
* `<display name> (<registry>)`. Selecting such an option sets `metadata.registry` on the selection. A plugin
|
|
20
|
+
* available in a single registry is listed without it. Defaults to false.
|
|
21
|
+
*/
|
|
22
|
+
enableRegistrySelection?: boolean;
|
|
9
23
|
}
|
|
10
24
|
/**
|
|
11
25
|
* Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginKindSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"PluginKindSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAMpD,OAAO,KAAK,EAA4B,UAAU,EAAE,MAAM,aAAa,CAAC;AAGxE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;IACpG,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAC9C;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;;OAIG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC;AAsFD;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,wHAkH3B,CAAC"}
|
|
@@ -14,6 +14,86 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
import { MenuItem, TextField } from "@mui/material";
|
|
15
15
|
import { forwardRef, useCallback, useMemo } from "react";
|
|
16
16
|
import { useListPluginMetadata } from "../../runtime/index.js";
|
|
17
|
+
import { comparePluginVersions } from "../../utils/index.js";
|
|
18
|
+
function getVariant(metadata) {
|
|
19
|
+
return {
|
|
20
|
+
version: metadata.metadata?.version ?? metadata.module?.version,
|
|
21
|
+
registry: metadata.metadata?.registry ?? metadata.module?.registry
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function getVariantKey(variant) {
|
|
25
|
+
return `${variant.version ?? ''}:${variant.registry ?? ''}`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Build the selectable entries of a plugin kind. A version (resp. registry) is only part of the entries when the caller
|
|
29
|
+
* enabled its selection *and* the plugin is actually installed in more than one version (resp. registry): there is
|
|
30
|
+
* nothing to pick otherwise, and leaving it out keeps the definition floating on the latest version.
|
|
31
|
+
*/ function getGroupOptions(group, enableVersionSelection, enableRegistrySelection) {
|
|
32
|
+
const showVersion = enableVersionSelection && group.hasMultipleVersions;
|
|
33
|
+
const showRegistry = enableRegistrySelection && group.hasMultipleRegistries;
|
|
34
|
+
if (!showVersion && !showRegistry) {
|
|
35
|
+
const selection = {
|
|
36
|
+
type: group.type,
|
|
37
|
+
kind: group.kind
|
|
38
|
+
};
|
|
39
|
+
return [
|
|
40
|
+
{
|
|
41
|
+
selection,
|
|
42
|
+
label: group.displayName,
|
|
43
|
+
value: selectionToOptionValue(selection)
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
}
|
|
47
|
+
const options = [];
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
if (showVersion) {
|
|
50
|
+
const selection = {
|
|
51
|
+
type: group.type,
|
|
52
|
+
kind: group.kind
|
|
53
|
+
};
|
|
54
|
+
options.push({
|
|
55
|
+
selection,
|
|
56
|
+
label: `${group.displayName} - Latest`,
|
|
57
|
+
value: selectionToOptionValue(selection)
|
|
58
|
+
});
|
|
59
|
+
seen.add(getVariantKey({}));
|
|
60
|
+
}
|
|
61
|
+
for (const variant of group.variants){
|
|
62
|
+
const version = showVersion ? variant.version : undefined;
|
|
63
|
+
const registry = showRegistry ? variant.registry : undefined;
|
|
64
|
+
const metadata = {
|
|
65
|
+
...version ? {
|
|
66
|
+
version
|
|
67
|
+
} : {},
|
|
68
|
+
...registry ? {
|
|
69
|
+
registry
|
|
70
|
+
} : {}
|
|
71
|
+
};
|
|
72
|
+
// Variants that only differ on a field we don't display collapse into a single entry.
|
|
73
|
+
const key = getVariantKey({
|
|
74
|
+
version,
|
|
75
|
+
registry
|
|
76
|
+
});
|
|
77
|
+
if (seen.has(key)) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
seen.add(key);
|
|
81
|
+
const selection = {
|
|
82
|
+
type: group.type,
|
|
83
|
+
kind: group.kind,
|
|
84
|
+
...version || registry ? {
|
|
85
|
+
metadata
|
|
86
|
+
} : {}
|
|
87
|
+
};
|
|
88
|
+
const label = `${group.displayName}${version ? ` - ${version}` : ''}${registry ? ` (${registry})` : ''}`;
|
|
89
|
+
options.push({
|
|
90
|
+
selection,
|
|
91
|
+
label,
|
|
92
|
+
value: selectionToOptionValue(selection)
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
return options;
|
|
96
|
+
}
|
|
17
97
|
/**
|
|
18
98
|
* Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific
|
|
19
99
|
* plugin types. (e.g. "Show a list of all the Panel plugins", or "Show a list of all the Variable plugins", or "Show
|
|
@@ -21,19 +101,78 @@ import { useListPluginMetadata } from "../../runtime/index.js";
|
|
|
21
101
|
* The value of the select is the kind of the plugin, but you can also listen to the `onPluginTypeChange` event to know
|
|
22
102
|
* when the user changes the plugin type (it fires at start for the default value.)
|
|
23
103
|
*/ export const PluginKindSelect = /*#__PURE__*/ forwardRef((props, ref)=>{
|
|
24
|
-
const { pluginTypes, value: propValue, onChange, filteredQueryPlugins, ...others } = props;
|
|
104
|
+
const { pluginTypes, value: propValue, onChange, filteredQueryPlugins, enableVersionSelection = false, enableRegistrySelection = false, ...others } = props;
|
|
25
105
|
const { data, isLoading } = useListPluginMetadata(pluginTypes);
|
|
26
106
|
const sortedData = useMemo(()=>{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
return data?.toSorted((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name));
|
|
107
|
+
const filtered = filteredQueryPlugins?.length ? data?.filter((i)=>filteredQueryPlugins.includes(i.spec.name)) : data;
|
|
108
|
+
return filtered?.toSorted((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name));
|
|
31
109
|
}, [
|
|
32
110
|
data,
|
|
33
111
|
filteredQueryPlugins
|
|
34
112
|
]);
|
|
113
|
+
// Group the metadata by plugin kind, collecting all the variants each one is installed under (newest version first).
|
|
114
|
+
const kindGroups = useMemo(()=>{
|
|
115
|
+
const groups = new Map();
|
|
116
|
+
for (const metadata of sortedData ?? []){
|
|
117
|
+
const key = `${metadata.kind}:${metadata.spec.name}`;
|
|
118
|
+
let group = groups.get(key);
|
|
119
|
+
if (group === undefined) {
|
|
120
|
+
group = {
|
|
121
|
+
type: metadata.kind,
|
|
122
|
+
kind: metadata.spec.name,
|
|
123
|
+
displayName: metadata.spec.display.name,
|
|
124
|
+
variants: [],
|
|
125
|
+
hasMultipleVersions: false,
|
|
126
|
+
hasMultipleRegistries: false
|
|
127
|
+
};
|
|
128
|
+
groups.set(key, group);
|
|
129
|
+
}
|
|
130
|
+
const variant = getVariant(metadata);
|
|
131
|
+
if (!group.variants.some((existing)=>getVariantKey(existing) === getVariantKey(variant))) {
|
|
132
|
+
group.variants.push(variant);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const group of groups.values()){
|
|
136
|
+
group.variants = group.variants.toSorted((a, b)=>comparePluginVersions(b.version ?? '', a.version ?? ''));
|
|
137
|
+
group.hasMultipleVersions = new Set(group.variants.map((v)=>v.version ?? '')).size > 1;
|
|
138
|
+
group.hasMultipleRegistries = new Set(group.variants.map((v)=>v.registry ?? '')).size > 1;
|
|
139
|
+
}
|
|
140
|
+
return [
|
|
141
|
+
...groups.values()
|
|
142
|
+
];
|
|
143
|
+
}, [
|
|
144
|
+
sortedData
|
|
145
|
+
]);
|
|
146
|
+
const options = useMemo(()=>kindGroups.flatMap((group)=>getGroupOptions(group, enableVersionSelection, enableRegistrySelection)), [
|
|
147
|
+
kindGroups,
|
|
148
|
+
enableVersionSelection,
|
|
149
|
+
enableRegistrySelection
|
|
150
|
+
]);
|
|
151
|
+
const labelsByValue = useMemo(()=>new Map(options.map((option)=>[
|
|
152
|
+
option.value,
|
|
153
|
+
option.label
|
|
154
|
+
])), [
|
|
155
|
+
options
|
|
156
|
+
]);
|
|
35
157
|
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
36
|
-
const value =
|
|
158
|
+
const value = useMemo(()=>{
|
|
159
|
+
if (!propValue || isLoading) {
|
|
160
|
+
return '';
|
|
161
|
+
}
|
|
162
|
+
const optionValue = selectionToOptionValue(propValue);
|
|
163
|
+
if (labelsByValue.has(optionValue)) {
|
|
164
|
+
return optionValue;
|
|
165
|
+
}
|
|
166
|
+
// The definition is not pinned (or is pinned to something we don't list): fall back to the first entry of that
|
|
167
|
+
// plugin kind, which is the one that will actually be used, so the Select has a matching value.
|
|
168
|
+
const fallback = options.find((option)=>option.selection.type === propValue.type && option.selection.kind === propValue.kind);
|
|
169
|
+
return fallback?.value ?? optionValue;
|
|
170
|
+
}, [
|
|
171
|
+
propValue,
|
|
172
|
+
isLoading,
|
|
173
|
+
labelsByValue,
|
|
174
|
+
options
|
|
175
|
+
]);
|
|
37
176
|
const handleChange = (event)=>{
|
|
38
177
|
onChange?.(optionValueToSelection(event.target.value));
|
|
39
178
|
};
|
|
@@ -41,10 +180,16 @@ import { useListPluginMetadata } from "../../runtime/index.js";
|
|
|
41
180
|
if (selected === '') {
|
|
42
181
|
return '';
|
|
43
182
|
}
|
|
44
|
-
const
|
|
45
|
-
|
|
183
|
+
const optionValue = selected;
|
|
184
|
+
const label = labelsByValue.get(optionValue);
|
|
185
|
+
if (label !== undefined) {
|
|
186
|
+
return label;
|
|
187
|
+
}
|
|
188
|
+
const selectedValue = optionValueToSelection(optionValue);
|
|
189
|
+
return kindGroups.find((group)=>group.type === selectedValue.type && group.kind === selectedValue.kind)?.displayName;
|
|
46
190
|
}, [
|
|
47
|
-
|
|
191
|
+
labelsByValue,
|
|
192
|
+
kindGroups
|
|
48
193
|
]);
|
|
49
194
|
// TODO: Does this need a loading indicator of some kind?
|
|
50
195
|
return /*#__PURE__*/ _jsxs(TextField, {
|
|
@@ -63,14 +208,11 @@ import { useListPluginMetadata } from "../../runtime/index.js";
|
|
|
63
208
|
value: "",
|
|
64
209
|
children: "Loading..."
|
|
65
210
|
}),
|
|
66
|
-
|
|
211
|
+
options.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
|
|
67
212
|
"data-testid": "option",
|
|
68
|
-
value:
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}),
|
|
72
|
-
children: metadata.spec.display.name
|
|
73
|
-
}, metadata.kind + metadata.spec.name))
|
|
213
|
+
value: option.value,
|
|
214
|
+
children: option.label
|
|
215
|
+
}, option.value))
|
|
74
216
|
]
|
|
75
217
|
});
|
|
76
218
|
});
|
|
@@ -78,29 +220,51 @@ PluginKindSelect.displayName = 'PluginKindSelect';
|
|
|
78
220
|
// Delimiter used to stringify/parse option values
|
|
79
221
|
const OPTION_VALUE_DELIMITER = '_____';
|
|
80
222
|
/**
|
|
81
|
-
* Given a PluginEditorSelection,
|
|
82
|
-
*
|
|
223
|
+
* Given a PluginEditorSelection, returns a string value like `{type}_____{kind}` that can be used as a Select input
|
|
224
|
+
* value. A pinned version and/or registry is appended as `{type}_____{kind}_____{version}_____{registry}`, with empty
|
|
225
|
+
* segments for the parts that are not pinned.
|
|
83
226
|
* @param selector
|
|
84
227
|
*/ function selectionToOptionValue(selector) {
|
|
85
|
-
|
|
228
|
+
const { version, registry } = selector.metadata ?? {};
|
|
229
|
+
const parts = [
|
|
86
230
|
selector.type,
|
|
87
231
|
selector.kind
|
|
88
|
-
]
|
|
232
|
+
];
|
|
233
|
+
if (version || registry) {
|
|
234
|
+
parts.push(version ?? '');
|
|
235
|
+
}
|
|
236
|
+
if (registry) {
|
|
237
|
+
parts.push(registry);
|
|
238
|
+
}
|
|
239
|
+
return parts.join(OPTION_VALUE_DELIMITER);
|
|
89
240
|
}
|
|
90
241
|
/**
|
|
91
|
-
* Given an option value name like `{type}_____{kind}`,
|
|
92
|
-
*
|
|
242
|
+
* Given an option value name like `{type}_____{kind}` or `{type}_____{kind}_____{version}_____{registry}`, returns a
|
|
243
|
+
* PluginEditorSelection to be used by the query data model.
|
|
93
244
|
* @param optionValue
|
|
94
245
|
*/ function optionValueToSelection(optionValue) {
|
|
95
246
|
const words = optionValue.split(OPTION_VALUE_DELIMITER);
|
|
96
247
|
const type = words[0];
|
|
97
248
|
const kind = words[1];
|
|
249
|
+
const version = words[2];
|
|
250
|
+
const registry = words[3];
|
|
98
251
|
if (type === undefined || kind === undefined) {
|
|
99
252
|
throw new Error('Invalid optionValue string');
|
|
100
253
|
}
|
|
254
|
+
const metadata = {
|
|
255
|
+
...version ? {
|
|
256
|
+
version
|
|
257
|
+
} : {},
|
|
258
|
+
...registry ? {
|
|
259
|
+
registry
|
|
260
|
+
} : {}
|
|
261
|
+
};
|
|
101
262
|
return {
|
|
102
263
|
type,
|
|
103
|
-
kind
|
|
264
|
+
kind,
|
|
265
|
+
...version || registry ? {
|
|
266
|
+
metadata
|
|
267
|
+
} : {}
|
|
104
268
|
};
|
|
105
269
|
}
|
|
106
270
|
|