@perses-dev/plugin-system 0.0.0-snapshot-color-palette-gen-test-0ebddd6 → 0.0.0-snapshot-saving-defaults-refinements-1b25cec

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +75 -0
  2. package/dist/cjs/components/PanelSpecEditor/index.js +28 -0
  3. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +27 -6
  4. package/dist/cjs/components/{PluginKindSelect.js → PluginKindSelect/PluginKindSelect.js} +1 -1
  5. package/dist/cjs/components/PluginKindSelect/index.js +28 -0
  6. package/dist/cjs/components/{PluginSpecEditor.js → PluginSpecEditor/PluginSpecEditor.js} +2 -30
  7. package/dist/cjs/components/PluginSpecEditor/index.js +28 -0
  8. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +142 -0
  9. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +94 -0
  10. package/dist/cjs/components/TimeSeriesQueryEditor/index.js +28 -0
  11. package/dist/cjs/components/index.js +1 -0
  12. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +88 -0
  13. package/dist/cjs/runtime/DataQueriesProvider/index.js +29 -0
  14. package/dist/cjs/runtime/DataQueriesProvider/model.js +16 -0
  15. package/dist/cjs/runtime/index.js +1 -0
  16. package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +39 -0
  17. package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +95 -0
  18. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +83 -0
  19. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js +40 -0
  20. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +38 -0
  21. package/dist/cjs/stories/shared-utils/decorators/index.js +32 -0
  22. package/dist/cjs/stories/shared-utils/index.js +28 -0
  23. package/dist/cjs/test/render.js +4 -1
  24. package/dist/cjs/test/test-plugins/bert/index.js +27 -20
  25. package/dist/cjs/test/test-plugins/ernie/index.js +37 -4
  26. package/dist/cjs/test-utils/mock-plugin-registry.js +4 -1
  27. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +10 -0
  28. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -0
  29. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +69 -0
  30. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -0
  31. package/dist/components/PanelSpecEditor/index.d.ts +2 -0
  32. package/dist/components/PanelSpecEditor/index.d.ts.map +1 -0
  33. package/dist/components/PanelSpecEditor/index.js +15 -0
  34. package/dist/components/PanelSpecEditor/index.js.map +1 -0
  35. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  36. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  37. package/dist/components/PluginEditor/plugin-editor-api.d.ts +4 -1
  38. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  39. package/dist/components/PluginEditor/plugin-editor-api.js +27 -6
  40. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  41. package/dist/components/{PluginKindSelect.d.ts → PluginKindSelect/PluginKindSelect.d.ts} +1 -1
  42. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -0
  43. package/dist/components/{PluginKindSelect.js → PluginKindSelect/PluginKindSelect.js} +1 -1
  44. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -0
  45. package/dist/components/PluginKindSelect/index.d.ts +2 -0
  46. package/dist/components/PluginKindSelect/index.d.ts.map +1 -0
  47. package/dist/components/PluginKindSelect/index.js +15 -0
  48. package/dist/components/PluginKindSelect/index.js.map +1 -0
  49. package/dist/components/PluginRegistry/PluginRegistry.d.ts +2 -2
  50. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  51. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  52. package/dist/components/{PluginSpecEditor.d.ts → PluginSpecEditor/PluginSpecEditor.d.ts} +1 -1
  53. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -0
  54. package/dist/components/{PluginSpecEditor.js → PluginSpecEditor/PluginSpecEditor.js} +3 -31
  55. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -0
  56. package/dist/components/PluginSpecEditor/index.d.ts +2 -0
  57. package/dist/components/PluginSpecEditor/index.d.ts.map +1 -0
  58. package/dist/components/PluginSpecEditor/index.js +15 -0
  59. package/dist/components/PluginSpecEditor/index.js.map +1 -0
  60. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts +8 -0
  61. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +1 -0
  62. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +131 -0
  63. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +1 -0
  64. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts +13 -0
  65. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts.map +1 -0
  66. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +83 -0
  67. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js.map +1 -0
  68. package/dist/components/TimeSeriesQueryEditor/index.d.ts +2 -0
  69. package/dist/components/TimeSeriesQueryEditor/index.d.ts.map +1 -0
  70. package/dist/components/TimeSeriesQueryEditor/index.js +15 -0
  71. package/dist/components/TimeSeriesQueryEditor/index.js.map +1 -0
  72. package/dist/components/index.d.ts +1 -0
  73. package/dist/components/index.d.ts.map +1 -1
  74. package/dist/components/index.js +1 -0
  75. package/dist/components/index.js.map +1 -1
  76. package/dist/model/panels.d.ts +6 -5
  77. package/dist/model/panels.d.ts.map +1 -1
  78. package/dist/model/panels.js.map +1 -1
  79. package/dist/model/plugin-base.d.ts +7 -0
  80. package/dist/model/plugin-base.d.ts.map +1 -1
  81. package/dist/model/plugin-base.js.map +1 -1
  82. package/dist/model/plugins.d.ts +3 -1
  83. package/dist/model/plugins.d.ts.map +1 -1
  84. package/dist/model/plugins.js.map +1 -1
  85. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +8 -0
  86. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -0
  87. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +74 -0
  88. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -0
  89. package/dist/runtime/DataQueriesProvider/index.d.ts +3 -0
  90. package/dist/runtime/DataQueriesProvider/index.d.ts.map +1 -0
  91. package/dist/runtime/DataQueriesProvider/index.js +16 -0
  92. package/dist/runtime/DataQueriesProvider/index.js.map +1 -0
  93. package/dist/runtime/DataQueriesProvider/model.d.ts +27 -0
  94. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -0
  95. package/dist/runtime/DataQueriesProvider/model.js +15 -0
  96. package/dist/runtime/DataQueriesProvider/model.js.map +1 -0
  97. package/dist/runtime/index.d.ts +1 -0
  98. package/dist/runtime/index.d.ts.map +1 -1
  99. package/dist/runtime/index.js +1 -0
  100. package/dist/runtime/index.js.map +1 -1
  101. package/dist/runtime/plugin-registry.d.ts +1 -1
  102. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  103. package/dist/runtime/plugin-registry.js.map +1 -1
  104. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts +13 -0
  105. package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts.map +1 -0
  106. package/dist/stories/shared-utils/decorators/WithDataQueries.js +33 -0
  107. package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -0
  108. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts +4 -0
  109. package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -0
  110. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +45 -0
  111. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -0
  112. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts +13 -0
  113. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -0
  114. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +79 -0
  115. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -0
  116. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts +13 -0
  117. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.d.ts.map +1 -0
  118. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js +39 -0
  119. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js.map +1 -0
  120. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +13 -0
  121. package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +1 -0
  122. package/dist/stories/shared-utils/decorators/WithTimeRange.js +32 -0
  123. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -0
  124. package/dist/stories/shared-utils/decorators/index.d.ts +6 -0
  125. package/dist/stories/shared-utils/decorators/index.d.ts.map +1 -0
  126. package/dist/stories/shared-utils/decorators/index.js +19 -0
  127. package/dist/stories/shared-utils/decorators/index.js.map +1 -0
  128. package/dist/stories/shared-utils/index.d.ts +2 -0
  129. package/dist/stories/shared-utils/index.d.ts.map +1 -0
  130. package/dist/stories/shared-utils/index.js +15 -0
  131. package/dist/stories/shared-utils/index.js.map +1 -0
  132. package/dist/test/render.d.ts.map +1 -1
  133. package/dist/test/render.js +4 -1
  134. package/dist/test/render.js.map +1 -1
  135. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  136. package/dist/test/test-plugins/bert/index.js +27 -20
  137. package/dist/test/test-plugins/bert/index.js.map +1 -1
  138. package/dist/test/test-plugins/ernie/index.d.ts +4 -1
  139. package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
  140. package/dist/test/test-plugins/ernie/index.js +28 -1
  141. package/dist/test/test-plugins/ernie/index.js.map +1 -1
  142. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
  143. package/dist/test-utils/mock-plugin-registry.js +4 -1
  144. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  145. package/package.json +6 -3
  146. package/dist/cjs/components/TimeSeriesQueryEditor.js +0 -42
  147. package/dist/components/PluginKindSelect.d.ts.map +0 -1
  148. package/dist/components/PluginKindSelect.js.map +0 -1
  149. package/dist/components/PluginSpecEditor.d.ts.map +0 -1
  150. package/dist/components/PluginSpecEditor.js.map +0 -1
  151. package/dist/components/TimeSeriesQueryEditor.d.ts +0 -14
  152. package/dist/components/TimeSeriesQueryEditor.d.ts.map +0 -1
  153. package/dist/components/TimeSeriesQueryEditor.js +0 -38
  154. package/dist/components/TimeSeriesQueryEditor.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PanelSpecEditor/PanelSpecEditor.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 { ErrorAlert, JSONEditor } from '@perses-dev/components';\nimport { PanelDefinition, QueryDefinition, UnknownSpec } from '@perses-dev/core';\nimport { usePlugin } from '../../runtime';\nimport { PanelPlugin } from '../../model';\nimport { OptionsEditorTabsProps, OptionsEditorTabs } from '../OptionsEditorTabs';\nimport { TimeSeriesQueryEditor } from '../TimeSeriesQueryEditor';\n\nexport interface PanelSpecEditorProps {\n panelDefinition: PanelDefinition;\n onQueriesChange: (queries: QueryDefinition[]) => void;\n onPluginSpecChange: (spec: UnknownSpec) => void;\n onJSONChange: (panelDefinition: PanelDefinition) => void;\n}\n\nexport function PanelSpecEditor(props: PanelSpecEditorProps) {\n const { panelDefinition, onJSONChange, onQueriesChange, onPluginSpecChange } = props;\n const { kind } = panelDefinition.spec.plugin;\n const { data: plugin, isLoading, error } = usePlugin('Panel', kind);\n\n if (error) {\n return <ErrorAlert error={error} />;\n }\n\n // TODO: Proper loading indicator\n if (isLoading) {\n return null;\n }\n\n if (plugin === undefined) {\n throw new Error(`Missing implementation for panel plugin with kind '${kind}'`);\n }\n\n const { panelOptionsEditorComponents, hideQueryEditor } = plugin as PanelPlugin;\n let tabs: OptionsEditorTabsProps['tabs'] = [];\n\n if (!hideQueryEditor) {\n // Since we only support TimeSeriesQuery for now, we will always show a TimeSeriesQueryEditor\n tabs.push({\n label: 'Query',\n content: <TimeSeriesQueryEditor queries={panelDefinition.spec.queries ?? []} onChange={onQueriesChange} />,\n });\n }\n\n if (panelOptionsEditorComponents !== undefined) {\n tabs = tabs.concat(\n panelOptionsEditorComponents.map(({ label, content: OptionsEditorComponent }) => ({\n label,\n content: <OptionsEditorComponent value={panelDefinition.spec.plugin.spec} onChange={onPluginSpecChange} />,\n }))\n );\n }\n\n // always show json editor by default\n tabs.push({ label: 'JSON', content: <JSONEditor value={panelDefinition} onChange={onJSONChange} /> });\n\n return <OptionsEditorTabs key={tabs.length} tabs={tabs} />;\n}\n"],"names":["ErrorAlert","JSONEditor","usePlugin","OptionsEditorTabs","TimeSeriesQueryEditor","PanelSpecEditor","props","panelDefinition","onJSONChange","onQueriesChange","onPluginSpecChange","kind","spec","plugin","data","isLoading","error","undefined","Error","panelOptionsEditorComponents","hideQueryEditor","tabs","push","label","content","queries","onChange","concat","map","OptionsEditorComponent","value","length"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE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CAACa,OAAO,cAA5BlB,QAA4B,cAA5BA,QAA4B,GAAI,EAAE;gBAAEmB,QAAQ,EAAEjB,eAAe;cAAI;SAC3G,CAAC,CAAC;IACL,CAAC;IAED,IAAIU,4BAA4B,KAAKF,SAAS,EAAE;QAC9CI,IAAI,GAAGA,IAAI,CAACM,MAAM,CAChBR,4BAA4B,CAACS,GAAG,CAAC,CAAC,EAAEL,KAAK,CAAA,EAAEC,OAAO,EAAEK,sBAAsB,CAAA,EAAE,GAAM,CAAA;gBAChFN,KAAK;gBACLC,OAAO,gBAAE,KAACK,sBAAsB;oBAACC,KAAK,EAAEvB,eAAe,CAACK,IAAI,CAACC,MAAM,CAACD,IAAI;oBAAEc,QAAQ,EAAEhB,kBAAkB;kBAAI;aAC3G,CAAA,AAAC,CAAC,CACJ,CAAC;IACJ,CAAC;IAED,qCAAqC;IACrCW,IAAI,CAACC,IAAI,CAAC;QAAEC,KAAK,EAAE,MAAM;QAAEC,OAAO,gBAAE,KAACvB,UAAU;YAAC6B,KAAK,EAAEvB,eAAe;YAAEmB,QAAQ,EAAElB,YAAY;UAAI;KAAE,CAAC,CAAC;IAEtG,qBAAO,KAACL,iBAAiB;QAAmBkB,IAAI,EAAEA,IAAI;OAAvBA,IAAI,CAACU,MAAM,CAAgB,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './PanelSpecEditor';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PanelSpecEditor/index.tsx"],"names":[],"mappings":"AAaA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './PanelSpecEditor';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PanelSpecEditor/index.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\nexport * from './PanelSpecEditor';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,mBAAmB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAsBpD"}
1
+ {"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAqBpD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.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 { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\nexport function PluginEditor(props: PluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { value, pluginType, pluginKindLabel, onChange: _, ...others } = props;\n const { pendingKind, isLoading, error, onKindChange, onSpecChange } = usePluginEditor(props);\n return (\n <Box {...others}>\n <FormControl margin=\"dense\" fullWidth={false} disabled={isLoading} error={error !== null} sx={{ mb: 1 }}>\n {/* TODO: How to ensure ids are unique? */}\n <InputLabel id=\"plugin-kind-label\">{pluginKindLabel}</InputLabel>\n <PluginKindSelect\n labelId=\"plugin-kind-label\"\n label={pluginKindLabel}\n pluginType={pluginType}\n value={pendingKind !== '' ? pendingKind : value.kind}\n onChange={onKindChange}\n />\n <FormHelperText>{error?.message ?? ''}</FormHelperText>\n </FormControl>\n\n <PluginSpecEditor pluginType={pluginType} pluginKind={value.kind} value={value.spec} onChange={onSpecChange} />\n </Box>\n );\n}\n"],"names":["Box","FormControl","FormHelperText","InputLabel","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","value","pluginType","pluginKindLabel","onChange","_","others","pendingKind","isLoading","error","onKindChange","onSpecChange","margin","fullWidth","disabled","sx","mb","id","labelId","label","kind","message","pluginKind","spec"],"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;AAAA,SAASA,GAAG,EAAEC,WAAW,EAAEC,cAAc,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC7E,SAASC,gBAAgB,QAAQ,qBAAqB,CAAC;AACvD,SAASC,gBAAgB,QAAQ,qBAAqB,CAAC;AACvD,SAA4BC,eAAe,QAAQ,qBAAqB,CAAC;AAEzE;;;;;;;CAOC,GACD,OAAO,SAASC,YAAY,CAACC,KAAwB,EAAE;IACrD,6DAA6D;IAC7D,MAAM,EAAEC,KAAK,CAAA,EAAEC,UAAU,CAAA,EAAEC,eAAe,CAAA,EAAEC,QAAQ,EAAEC,CAAC,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGN,KAAK,AAAC;IAC7E,MAAM,EAAEO,WAAW,CAAA,EAAEC,SAAS,CAAA,EAAEC,KAAK,CAAA,EAAEC,YAAY,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGb,eAAe,CAACE,KAAK,CAAC,AAAC;QAatES,GAAc;IAZrC,qBACE,MAACjB,GAAG;QAAE,GAAGc,MAAM;;0BACb,MAACb,WAAW;gBAACmB,MAAM,EAAC,OAAO;gBAACC,SAAS,EAAE,KAAK;gBAAEC,QAAQ,EAAEN,SAAS;gBAAEC,KAAK,EAAEA,KAAK,KAAK,IAAI;gBAAEM,EAAE,EAAE;oBAAEC,EAAE,EAAE,CAAC;iBAAE;;kCAErG,KAACrB,UAAU;wBAACsB,EAAE,EAAC,mBAAmB;kCAAEd,eAAe;sBAAc;kCACjE,KAACP,gBAAgB;wBACfsB,OAAO,EAAC,mBAAmB;wBAC3BC,KAAK,EAAEhB,eAAe;wBACtBD,UAAU,EAAEA,UAAU;wBACtBD,KAAK,EAAEM,WAAW,KAAK,EAAE,GAAGA,WAAW,GAAGN,KAAK,CAACmB,IAAI;wBACpDhB,QAAQ,EAAEM,YAAY;sBACtB;kCACF,KAAChB,cAAc;kCAAEe,CAAAA,GAAc,GAAdA,KAAK,aAALA,KAAK,WAAS,GAAdA,KAAAA,CAAc,GAAdA,KAAK,CAAEY,OAAO,cAAdZ,GAAc,cAAdA,GAAc,GAAI,EAAE;sBAAkB;;cAC3C;0BAEd,KAACZ,gBAAgB;gBAACK,UAAU,EAAEA,UAAU;gBAAEoB,UAAU,EAAErB,KAAK,CAACmB,IAAI;gBAAEnB,KAAK,EAAEA,KAAK,CAACsB,IAAI;gBAAEnB,QAAQ,EAAEO,YAAY;cAAI;;MAC3G,CACN;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.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 { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\nexport function PluginEditor(props: PluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { value, pluginType, pluginKindLabel, onChange: _, ...others } = props;\n const { pendingKind, isLoading, error, onKindChange, onSpecChange } = usePluginEditor(props);\n return (\n <Box {...others}>\n <FormControl margin=\"dense\" fullWidth={false} disabled={isLoading} error={error !== null} sx={{ mb: 1 }}>\n {/* TODO: How to ensure ids are unique? */}\n <InputLabel id=\"plugin-kind-label\">{pluginKindLabel}</InputLabel>\n <PluginKindSelect\n labelId=\"plugin-kind-label\"\n label={pluginKindLabel}\n pluginType={pluginType}\n value={pendingKind !== '' ? pendingKind : value.kind}\n onChange={onKindChange}\n />\n <FormHelperText>{error?.message ?? ''}</FormHelperText>\n </FormControl>\n <PluginSpecEditor pluginType={pluginType} pluginKind={value.kind} value={value.spec} onChange={onSpecChange} />\n </Box>\n );\n}\n"],"names":["Box","FormControl","FormHelperText","InputLabel","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","value","pluginType","pluginKindLabel","onChange","_","others","pendingKind","isLoading","error","onKindChange","onSpecChange","margin","fullWidth","disabled","sx","mb","id","labelId","label","kind","message","pluginKind","spec"],"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;AAAA,SAASA,GAAG,EAAEC,WAAW,EAAEC,cAAc,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC7E,SAASC,gBAAgB,QAAQ,qBA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,EAAEA,UAAU;gBAAEoB,UAAU,EAAErB,KAAK,CAACmB,IAAI;gBAAEnB,KAAK,EAAEA,KAAK,CAACsB,IAAI;gBAAEnB,QAAQ,EAAEO,YAAY;cAAI;;MAC3G,CACN;AACJ,CAAC"}
@@ -12,7 +12,9 @@ export interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {
12
12
  /**
13
13
  * Props needed by the usePluginEditor hook.
14
14
  */
15
- export declare type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'>;
15
+ export declare type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'> & {
16
+ onHideQueryEditorChange?: (isHidden: boolean) => void;
17
+ };
16
18
  /**
17
19
  * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide
18
20
  * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also
@@ -25,6 +27,7 @@ export declare function usePluginEditor(props: UsePluginEditorProps): {
25
27
  error: Error | null;
26
28
  onKindChange: (event: import("@mui/material").SelectChangeEvent<string>, child: import("react").ReactNode) => void;
27
29
  onSpecChange: (next: UnknownSpec) => void;
30
+ rememberCurrentSpecState: () => void;
28
31
  };
29
32
  export {};
30
33
  //# sourceMappingURL=plugin-editor-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAY,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAOzC,aAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC;IACxE,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACnD;AAID;;GAEG;AACH,oBAAY,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,CAAC;AAEhG;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB;;;;;;EA+E1D"}
1
+ {"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAY,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAe,UAAU,EAAE,MAAM,aAAa,CAAC;AAOtD,aAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC;IACxE,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACnD;AAKD;;GAEG;AACH,oBAAY,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,GAAG;IAChG,uBAAuB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB;;;;;;;EAqG1D"}
@@ -20,9 +20,11 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
20
20
  * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin
21
21
  * kind back.
22
22
  */ export function usePluginEditor(props) {
23
- const { pluginType , value } = props;
23
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
24
+ const { pluginType , value , onHideQueryEditorChange =()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
24
25
  // Keep a stable reference so we don't run the effect below when we don't need to
25
26
  const onChange = useEvent(props.onChange);
27
+ const onHideQuery = useEvent(onHideQueryEditorChange);
26
28
  // The previous spec state for PluginType and kind and a helper function for remembering current values
27
29
  const prevSpecState = useRef({
28
30
  [pluginType]: {
@@ -37,6 +39,10 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
37
39
  }
38
40
  byPluginType[value.kind] = value.spec;
39
41
  });
42
+ // The previous hide query state for each panel kind
43
+ const hideQueryState = useRef({
44
+ [value.kind]: false
45
+ });
40
46
  const { defaultPluginKinds } = usePluginRegistry();
41
47
  const defaultPluginKind = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[pluginType];
42
48
  const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';
@@ -55,12 +61,23 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
55
61
  kind: pendingKind,
56
62
  spec: plugin.createInitialOptions()
57
63
  });
64
+ if (pluginType === 'Panel') {
65
+ const panelPlugin = plugin;
66
+ hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;
67
+ if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {
68
+ onHideQuery(!!panelPlugin.hideQueryEditor);
69
+ }
70
+ }
58
71
  setPendingKind('');
59
72
  }, [
60
73
  pendingKind,
61
74
  plugin,
62
75
  rememberCurrentSpecState,
63
- onChange
76
+ onChange,
77
+ onHideQuery,
78
+ hideQueryState,
79
+ pluginType,
80
+ value.kind
64
81
  ]);
65
82
  /**
66
83
  * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we
@@ -76,10 +93,13 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
76
93
  kind: nextKind,
77
94
  spec: previousState
78
95
  });
79
- return;
96
+ } else {
97
+ // Otherwise, kick off the async loading process
98
+ setPendingKind(nextKind);
99
+ }
100
+ if (pluginType === 'Panel' && hideQueryState.current[nextKind] !== undefined && hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]) {
101
+ onHideQuery(!!hideQueryState.current[nextKind]);
80
102
  }
81
- // Otherwise, kick off the async loading process
82
- setPendingKind(nextKind);
83
103
  };
84
104
  /**
85
105
  * Spec changes are independent and always just set the spec state.
@@ -93,7 +113,8 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
93
113
  isLoading: isFetching,
94
114
  error,
95
115
  onKindChange,
96
- onSpecChange
116
+ onSpecChange,
117
+ rememberCurrentSpecState
97
118
  };
98
119
  }
99
120
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BoxProps } from '@mui/material';\nimport { Definition, UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useState, useRef, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { PluginType } from '../../model';\nimport { PluginKindSelectProps } from '../PluginKindSelect';\nimport { PluginSpecEditorProps } from '../PluginSpecEditor';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\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 pluginType: PluginType;\n pluginKindLabel: string;\n value: Definition<UnknownSpec>;\n onChange: (next: Definition<UnknownSpec>) => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'>;\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 const { pluginType, value } = props;\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\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [pluginType]: { [value.kind]: value.spec },\n });\n\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[pluginType];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[pluginType] = byPluginType;\n }\n byPluginType[value.kind] = value.spec;\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginKind = defaultPluginKinds?.[pluginType];\n const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';\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 [pendingKind, setPendingKind] = useState(initPendingKind);\n const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (pendingKind === '') return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n kind: pendingKind,\n spec: plugin.createInitialOptions(),\n });\n setPendingKind('');\n }, [pendingKind, plugin, rememberCurrentSpecState, onChange]);\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 onKindChange: PluginKindSelectProps['onChange'] = (e) => {\n const nextKind = e.target.value;\n\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[pluginType]?.[nextKind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n kind: nextKind,\n spec: previousState,\n });\n return;\n }\n\n // Otherwise, kick off the async loading process\n setPendingKind(nextKind);\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 { pendingKind, isLoading: isFetching, error, onKindChange, onSpecChange };\n}\n"],"names":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","usePluginEditor","props","pluginType","value","onChange","prevSpecState","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","defaultPluginKinds","defaultPluginKind","initPendingKind","pendingKind","setPendingKind","data","plugin","isFetching","error","createInitialOptions","onKindChange","e","nextKind","target","previousState","onSpecChange","next","draft","isLoading"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAAkCA,QAAQ,QAAQ,kBAAkB,CAAC;AACrE,SAASC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QAAQ,OAAO,CAAC;AACpD,SAASC,OAAO,QAAQ,OAAO,CAAC;AAIhC,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,eAAe,CAAC;AAoB7D;;;;;CAKC,GACD,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,MAAM,EAAEC,UAAU,CAAA,EAAEC,KAAK,CAAA,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Eb,WAAW;QAAEe,SAAS,EAAEX,UAAU;QAAEC,KAAK;QAAEE,YAAY;QAAEK,YAAY;KAAE,CAAC;AACnF,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BoxProps } from '@mui/material';\nimport { Definition, UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useState, useRef, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { PanelPlugin, PluginType } from '../../model';\nimport { PluginKindSelectProps } from '../PluginKindSelect/PluginKindSelect';\nimport { PluginSpecEditorProps } from '../PluginSpecEditor/PluginSpecEditor';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\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 pluginType: PluginType;\n pluginKindLabel: string;\n value: Definition<UnknownSpec>;\n onChange: (next: Definition<UnknownSpec>) => 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, 'pluginType' | '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 // eslint-disable-next-line @typescript-eslint/no-empty-function\n const { pluginType, value, onHideQueryEditorChange = () => {} } = 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 [pluginType]: { [value.kind]: value.spec },\n });\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[pluginType];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[pluginType] = byPluginType;\n }\n byPluginType[value.kind] = value.spec;\n });\n\n // The previous hide query state for each panel kind\n const hideQueryState = useRef<HideQueryEditorState>({\n [value.kind]: false,\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginKind = defaultPluginKinds?.[pluginType];\n const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';\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 [pendingKind, setPendingKind] = useState(initPendingKind);\n const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (pendingKind === '') return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n kind: pendingKind,\n spec: plugin.createInitialOptions(),\n });\n\n if (pluginType === 'Panel') {\n const panelPlugin = plugin as PanelPlugin;\n hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;\n if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {\n onHideQuery(!!panelPlugin.hideQueryEditor);\n }\n }\n\n setPendingKind('');\n }, [pendingKind, plugin, rememberCurrentSpecState, onChange, onHideQuery, hideQueryState, pluginType, value.kind]);\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 onKindChange: PluginKindSelectProps['onChange'] = (e) => {\n const nextKind = e.target.value;\n\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[pluginType]?.[nextKind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n kind: nextKind,\n spec: previousState,\n });\n } else {\n // Otherwise, kick off the async loading process\n setPendingKind(nextKind);\n }\n\n if (\n pluginType === 'Panel' &&\n hideQueryState.current[nextKind] !== undefined &&\n hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]\n ) {\n onHideQuery(!!hideQueryState.current[nextKind]);\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 { pendingKind, isLoading: isFetching, error, onKindChange, onSpecChange, rememberCurrentSpecState };\n}\n"],"names":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","usePluginEditor","props","pluginType","value","onHideQueryEditorChange","onChange","onHideQuery","prevSpecState","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","hideQueryState","defaultPluginKinds","defaultPluginKind","initPendingKind","pendingKind","setPendingKind","data","plugin","isFetching","error","createInitialOptions","panelPlugin","hideQueryEditor","onKindChange","e","nextKind","target","previousState","onSpecChange","next","draft","isLoading"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAAkCA,QAAQ,QAAQ,kBAAkB,CAAC;AACrE,SAASC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QA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iB,SAAS,EAAEb,UAAU;QAAEC,KAAK;QAAEI,YAAY;QAAEK,YAAY;QAAEtB,wBAAwB;KAAE,CAAC;AAC7G,CAAC"}
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { SelectProps } from '@mui/material';
3
- import { PluginType } from '../model';
3
+ import { PluginType } from '../../model';
4
4
  export interface PluginKindSelectProps extends Omit<SelectProps<string>, 'children'> {
5
5
  pluginType: PluginType;
6
6
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginKindSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAU,WAAW,EAAY,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAClF,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,eAiB5D"}
@@ -12,7 +12,7 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { Select, MenuItem } from '@mui/material';
15
- import { useListPluginMetadata } from '../runtime';
15
+ import { useListPluginMetadata } from '../../runtime';
16
16
  /**
17
17
  * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of a specific
18
18
  * plugin type. (e.g. "Show a list of all the Panel plugins" or "Show a list of all the Variable plugins").
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PluginKindSelect/PluginKindSelect.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 { Select, SelectProps, MenuItem } from '@mui/material';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata } from '../../runtime';\n\nexport interface PluginKindSelectProps extends Omit<SelectProps<string>, 'children'> {\n pluginType: PluginType;\n}\n\n/**\n * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of a specific\n * plugin type. (e.g. \"Show a list of all the Panel plugins\" or \"Show a list of all the Variable plugins\").\n */\nexport function PluginKindSelect(props: PluginKindSelectProps) {\n const { pluginType, value: propValue, ...others } = props;\n const { data, isLoading } = useListPluginMetadata(pluginType);\n\n // Pass an empty value while options are still loading so MUI doesn't complain about us using an \"out of range\" value\n const value = propValue !== '' && isLoading ? '' : propValue;\n\n // TODO: Does this need a loading indicator of some kind?\n return (\n <Select sx={{ minWidth: 120 }} {...others} value={value}>\n {data?.map((metadata) => (\n <MenuItem key={metadata.kind} value={metadata.kind}>\n {metadata.display.name}\n </MenuItem>\n ))}\n </Select>\n );\n}\n"],"names":["Select","MenuItem","useListPluginMetadata","PluginKindSelect","props","pluginType","value","propValue","others","data","isLoading","sx","minWidth","map","metadata","kind","display","name"],"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;AAAA,SAASA,MAAM,EAAeC,QAAQ,QAAQ,eAAe,CAAC;AAE9D,SAASC,qBAAqB,QAAQ,eAAe,CAAC;AAMtD;;;CAGC,GACD,OAAO,SAASC,gBAAgB,CAACC,KAA4B,EAAE;IAC7D,MAAM,EAAEC,UAAU,CAAA,EAAEC,KAAK,EAAEC,SAAS,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGJ,KAAK,AAAC;IAC1D,MAAM,EAAEK,IAAI,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAGR,qBAAqB,CAACG,UAAU,CAAC,AAAC;IAE9D,qHAAqH;IACrH,MAAMC,KAAK,GAAGC,SAAS,KAAK,EAAE,IAAIG,SAAS,GAAG,EAAE,GAAGH,SAAS,AAAC;IAE7D,yDAAyD;IACzD,qBACE,KAACP,MAAM;QAACW,EAAE,EAAE;YAAEC,QAAQ,EAAE,GAAG;SAAE;QAAG,GAAGJ,MAAM;QAAEF,KAAK,EAAEA,KAAK;kBACpDG,IAAI,aAAJA,IAAI,WAAK,GAATA,KAAAA,CAAS,GAATA,IAAI,CAAEI,GAAG,CAAC,CAACC,QAAQ,iBAClB,KAACb,QAAQ;gBAAqBK,KAAK,EAAEQ,QAAQ,CAACC,IAAI;0BAC/CD,QAAQ,CAACE,OAAO,CAACC,IAAI;eADTH,QAAQ,CAACC,IAAI,CAEjB,AACZ,CAAC;MACK,CACT;AACJ,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './PluginKindSelect';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/index.tsx"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './PluginKindSelect';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PluginKindSelect/index.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\nexport * from './PluginKindSelect';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,oBAAoB,CAAC"}
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
2
  import { PluginLoader, DefaultPluginKinds } from '../../model';
3
3
  export interface PluginRegistryProps {
4
- children?: React.ReactNode;
5
4
  pluginLoader: PluginLoader;
6
- defaultPluginKinds?: DefaultPluginKinds;
5
+ defaultPluginKinds: DefaultPluginKinds;
6
+ children?: React.ReactNode;
7
7
  }
8
8
  /**
9
9
  * PluginRegistryContext provider that keeps track of all available plugins and provides an API for getting them or
@@ -1 +1 @@
1
- {"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAKL,YAAY,EACZ,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,YAAY,EAAE,YAAY,CAAC;IAC3B,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;CACzC;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eAoExD"}
1
+ {"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAKL,YAAY,EACZ,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,YAAY,CAAC;IAC3B,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eAoExD"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PluginRegistry/PluginRegistry.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 { UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useRef, useCallback, useMemo } from 'react';\nimport {\n PluginModuleResource,\n PluginType,\n PluginImplementation,\n Plugin,\n PluginLoader,\n DefaultPluginKinds,\n} from '../../model';\nimport { PluginRegistryContext } from '../../runtime';\nimport { usePluginIndexes, getTypeAndKindKey } from './plugin-indexes';\n\nexport interface PluginRegistryProps {\n children?: React.ReactNode;\n pluginLoader: PluginLoader;\n defaultPluginKinds?: DefaultPluginKinds;\n}\n\n/**\n * PluginRegistryContext provider that keeps track of all available plugins and provides an API for getting them or\n * querying the metadata about them.\n */\nexport function PluginRegistry(props: PluginRegistryProps) {\n const {\n pluginLoader: { getInstalledPlugins, importPluginModule },\n children,\n defaultPluginKinds,\n } = props;\n\n const getPluginIndexes = usePluginIndexes(getInstalledPlugins);\n\n // De-dupe calls to import plugin modules\n const importCache = useRef(new Map<PluginModuleResource, Promise<unknown>>());\n\n // Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the\n // callback below\n const loadPluginModule = useEvent((resource: PluginModuleResource) => {\n let request = importCache.current.get(resource);\n if (request === undefined) {\n request = importPluginModule(resource);\n importCache.current.set(resource, request);\n\n // Remove failed requests from the cache so they can potentially be retried\n request.catch(() => importCache.current.delete(resource));\n }\n return request;\n });\n\n const getPlugin = useCallback(\n async <T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>> => {\n // Get the indexes of the installed plugins\n const pluginIndexes = await getPluginIndexes();\n\n // Figure out what module the plugin is in by looking in the index\n const typeAndKindKey = getTypeAndKindKey(pluginType, kind);\n const resource = pluginIndexes.pluginResourcesByTypeAndKind.get(typeAndKindKey);\n if (resource === undefined) {\n throw new Error(`A ${pluginType} plugin for kind '${kind}' is not installed`);\n }\n\n // Treat the plugin module as a bunch of named exports that have plugins\n const pluginModule = (await loadPluginModule(resource)) as Record<string, Plugin<UnknownSpec>>;\n\n // We currently assume that plugin modules will have named exports that match the kinds they handle\n const plugin = pluginModule[kind];\n if (plugin === undefined) {\n throw new Error(\n `The ${pluginType} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`\n );\n }\n\n return plugin as PluginImplementation<T>;\n },\n [getPluginIndexes, loadPluginModule]\n );\n\n const listPluginMetadata = useCallback(\n async (pluginType: PluginType) => {\n const pluginIndexes = await getPluginIndexes();\n return pluginIndexes.pluginMetadataByType.get(pluginType) ?? [];\n },\n [getPluginIndexes]\n );\n\n // Create the registry's context value and render\n const context = useMemo(\n () => ({ getPlugin, listPluginMetadata, defaultPluginKinds }),\n [getPlugin, listPluginMetadata, defaultPluginKinds]\n );\n return <PluginRegistryContext.Provider value={context}>{children}</PluginRegistryContext.Provider>;\n}\n"],"names":["useEvent","useRef","useCallback","useMemo","PluginRegistryContext","usePluginIndexes","getTypeAndKindKey","PluginRegistry","props","pluginLoader","getInstalledPlugins","importPluginModule","children","defaultPluginKinds","getPluginIndexes","importCache","Map","loadPluginModule","resource","request","current","get","undefined","set","catch","delete","getPlugin","pluginType","kind","pluginIndexes","typeAndKindKey","pluginResourcesByTypeAndKind","Error","pluginModule","plugin","metadata","name","listPluginMetadata","pluginMetadataByType","context","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAAsBA,QAAQ,QAAQ,kBAAkB,CAAC;AACzD,SAASC,MAAM,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO,CAAC;AASrD,SAASC,qBAAqB,QAAQ,eAAe,CAAC;AACtD,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AAQvE;;;CAGC,GACD,OAAO,SAASC,cAAc,CAACC,KAA0B,EAAE;IACzD,MAAM,EACJC,YAAY,EAAE,EAAEC,mBAAmB,CAAA,EAAEC,kBAAkB,CAAA,EAAE,CAAA,EACzDC,QAAQ,CAAA,EACRC,kBAAkB,CAAA,IACnB,GAAGL,KAAK,AAAC;IAEV,MAAMM,gBAAgB,GAAGT,gBAAgB,CAACK,mBAAmB,CAAC,AAAC;IAE/D,yCAAyC;IACzC,MAAMK,WAAW,GAAGd,MAAM,CAAC,IAAIe,GAAG,EAA0C,CAAC,AAAC;IAE9E,gHAAgH;IAChH,iBAAiB;IACjB,MAAMC,gBAAgB,GAAGjB,QAAQ,CAAC,CAACkB,QAA8B,GAAK;QACpE,IAAIC,OAAO,GAAGJ,WAAW,CAACK,OAAO,CAACC,GAAG,CAACH,QAAQ,CAAC,AAAC;QAChD,IAAIC,OAAO,KAAKG,SAAS,EAAE;YACzBH,OAAO,GAAGR,kBAAkB,CAACO,QAAQ,CAAC,CAAC;YACvC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,kBAAkB,GAAGnC,WAAW,CACpC,OAAOyB,UAAsB,GAAK;QAChC,MAAME,aAAa,GAAG,MAAMf,gBAAgB,EAAE,AAAC;YACxCe,GAAkD;QAAzD,OAAOA,CAAAA,GAAkD,GAAlDA,aAAa,CAACS,oBAAoB,CAACjB,GAAG,CAACM,UAAU,CAAC,cAAlDE,GAAkD,cAAlDA,GAAkD,GAAI,EAAE,CAAC;IAClE,CAAC,EACD;QAACf,gBAAgB;KAAC,CACnB,AAAC;IAEF,iDAAiD;IACjD,MAAMyB,OAAO,GAAGpC,OAAO,CACrB,IAAO,CAAA;YAAEuB,SAAS;YAAEW,kBAAkB;YAAExB,kBAAkB;SAAE,CAAA,AAAC,EAC7D;QAACa,SAAS;QAAEW,kBAAkB;QAAExB,kBAAkB;KAAC,CACpD,AAAC;IACF,qBAAO,KAACT,qBAAqB,CAACoC,QAAQ;QAACC,KAAK,EAAEF,OAAO;kBAAG3B,QAAQ;MAAkC,CAAC;AACrG,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/PluginRegistry/PluginRegistry.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 { UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useRef, useCallback, useMemo } from 'react';\nimport {\n PluginModuleResource,\n PluginType,\n PluginImplementation,\n Plugin,\n PluginLoader,\n DefaultPluginKinds,\n} from '../../model';\nimport { PluginRegistryContext } from '../../runtime';\nimport { usePluginIndexes, getTypeAndKindKey } from './plugin-indexes';\n\nexport interface PluginRegistryProps {\n pluginLoader: PluginLoader;\n defaultPluginKinds: DefaultPluginKinds;\n children?: React.ReactNode;\n}\n\n/**\n * PluginRegistryContext provider that keeps track of all available plugins and provides an API for getting them or\n * querying the metadata about them.\n */\nexport function PluginRegistry(props: PluginRegistryProps) {\n const {\n pluginLoader: { getInstalledPlugins, importPluginModule },\n children,\n defaultPluginKinds,\n } = props;\n\n const getPluginIndexes = usePluginIndexes(getInstalledPlugins);\n\n // De-dupe calls to import plugin modules\n const importCache = useRef(new Map<PluginModuleResource, Promise<unknown>>());\n\n // Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the\n // callback below\n const loadPluginModule = useEvent((resource: PluginModuleResource) => {\n let request = importCache.current.get(resource);\n if (request === undefined) {\n request = importPluginModule(resource);\n importCache.current.set(resource, request);\n\n // Remove failed requests from the cache so they can potentially be retried\n request.catch(() => importCache.current.delete(resource));\n }\n return request;\n });\n\n const getPlugin = useCallback(\n async <T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>> => {\n // Get the indexes of the installed plugins\n const pluginIndexes = await getPluginIndexes();\n\n // Figure out what module the plugin is in by looking in the index\n const typeAndKindKey = getTypeAndKindKey(pluginType, kind);\n const resource = pluginIndexes.pluginResourcesByTypeAndKind.get(typeAndKindKey);\n if (resource === undefined) {\n throw new Error(`A ${pluginType} plugin for kind '${kind}' is not installed`);\n }\n\n // Treat the plugin module as a bunch of named exports that have plugins\n const pluginModule = (await loadPluginModule(resource)) as Record<string, Plugin<UnknownSpec>>;\n\n // We currently assume that plugin modules will have named exports that match the kinds they handle\n const plugin = pluginModule[kind];\n if (plugin === undefined) {\n throw new Error(\n `The ${pluginType} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`\n );\n }\n\n return plugin as PluginImplementation<T>;\n },\n [getPluginIndexes, loadPluginModule]\n );\n\n const listPluginMetadata = useCallback(\n async (pluginType: PluginType) => {\n const pluginIndexes = await getPluginIndexes();\n return pluginIndexes.pluginMetadataByType.get(pluginType) ?? [];\n },\n [getPluginIndexes]\n );\n\n // Create the registry's context value and render\n const context = useMemo(\n () => ({ getPlugin, listPluginMetadata, defaultPluginKinds }),\n [getPlugin, listPluginMetadata, defaultPluginKinds]\n );\n return <PluginRegistryContext.Provider value={context}>{children}</PluginRegistryContext.Provider>;\n}\n"],"names":["useEvent","useRef","useCallback","useMemo","PluginRegistryContext","usePluginIndexes","getTypeAndKindKey","PluginRegistry","props","pluginLoader","getInstalledPlugins","importPluginModule","children","defaultPluginKinds","getPluginIndexes","importCache","Map","loadPluginModule","resource","request","current","get","undefined","set","catch","delete","getPlugin","pluginType","kind","pluginIndexes","typeAndKindKey","pluginResourcesByTypeAndKind","Error","pluginModule","plugin","metadata","name","listPluginMetadata","pluginMetadataByType","context","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAAsBA,QAAQ,QAAQ,kBAAkB,CAAC;AACzD,SAASC,MAAM,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO,CAAC;AASrD,SAASC,qBAAqB,QAAQ,eAAe,CAAC;AACtD,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,kBAAkB,CAAC;AAQvE;;;CAGC,GACD,OAAO,SAASC,cAAc,CAACC,KAA0B,EAAE;IACzD,MAAM,EACJC,YAAY,EAAE,EAAEC,mBAAmB,CAAA,EAAEC,kBAAkB,CAAA,EAAE,CAAA,EACzDC,QAAQ,CAAA,EACRC,kBAAkB,CAAA,IACnB,GAAGL,KAAK,AAAC;IAEV,MAAMM,gBAAgB,GAAGT,gBAAgB,CAACK,mBAAmB,CAAC,AAAC;IAE/D,yCAAyC;IACzC,MAAMK,WAAW,GAAGd,MAAM,CAAC,IAAIe,GAAG,EAA0C,CAAC,AAAC;IAE9E,gHAAgH;IAChH,iBAAiB;IACjB,MAAMC,gBAA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kBAAkB,EAAEC,IAAI,CAAC,sBAAsB,EAAEV,QAAQ,CAACiB,QAAQ,CAACC,IAAI,CAAC,cAAc,CAAC,CAC1G,CAAC;QACJ,CAAC;QAED,OAAOF,MAAM,CAA4B;IAC3C,CAAC,EACD;QAACpB,gBAAgB;QAAEG,gBAAgB;KAAC,CACrC,AAAC;IAEF,MAAMoB,kBAAkB,GAAGnC,WAAW,CACpC,OAAOyB,UAAsB,GAAK;QAChC,MAAME,aAAa,GAAG,MAAMf,gBAAgB,EAAE,AAAC;YACxCe,GAAkD;QAAzD,OAAOA,CAAAA,GAAkD,GAAlDA,aAAa,CAACS,oBAAoB,CAACjB,GAAG,CAACM,UAAU,CAAC,cAAlDE,GAAkD,cAAlDA,GAAkD,GAAI,EAAE,CAAC;IAClE,CAAC,EACD;QAACf,gBAAgB;KAAC,CACnB,AAAC;IAEF,iDAAiD;IACjD,MAAMyB,OAAO,GAAGpC,OAAO,CACrB,IAAO,CAAA;YAAEuB,SAAS;YAAEW,kBAAkB;YAAExB,kBAAkB;SAAE,CAAA,AAAC,EAC7D;QAACa,SAAS;QAAEW,kBAAkB;QAAExB,kBAAkB;KAAC,CACpD,AAAC;IACF,qBAAO,KAACT,qBAAqB,CAACoC,QAAQ;QAACC,KAAK,EAAEF,OAAO;kBAAG3B,QAAQ;MAAkC,CAAC;AACrG,CAAC"}
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { UnknownSpec } from '@perses-dev/core';
3
- import { OptionsEditorProps, PluginType } from '../model';
3
+ import { OptionsEditorProps, PluginType } from '../../model';
4
4
  export interface PluginSpecEditorProps extends OptionsEditorProps<UnknownSpec> {
5
5
  pluginType: PluginType;
6
6
  pluginKind: string;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PluginSpecEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginSpecEditor/PluginSpecEditor.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG7D,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB,CAAC,WAAW,CAAC;IAC5E,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,sBA4B5D"}
@@ -11,9 +11,8 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { ErrorAlert, JSONEditor } from '@perses-dev/components';
15
- import { usePlugin } from '../runtime';
16
- import { OptionsEditorTabs } from './OptionsEditorTabs';
14
+ import { ErrorAlert } from '@perses-dev/components';
15
+ import { usePlugin } from '../../runtime';
17
16
  export function PluginSpecEditor(props) {
18
17
  const { pluginType , pluginKind , ...others } = props;
19
18
  const { data: plugin , isLoading , error } = usePlugin(pluginType, pluginKind);
@@ -30,34 +29,7 @@ export function PluginSpecEditor(props) {
30
29
  throw new Error(`Missing implementation for ${pluginType} plugin with kind '${pluginKind}'`);
31
30
  }
32
31
  if (pluginType === 'Panel') {
33
- const { PanelQueryEditorComponent , panelOptionsEditorComponents } = plugin;
34
- let tabs = [];
35
- if (PanelQueryEditorComponent !== undefined) {
36
- tabs.push({
37
- label: 'Query',
38
- content: /*#__PURE__*/ _jsx(PanelQueryEditorComponent, {
39
- ...others
40
- })
41
- });
42
- }
43
- if (panelOptionsEditorComponents !== undefined) {
44
- tabs = tabs.concat(panelOptionsEditorComponents.map(({ label , content: OptionsEditorComponent })=>({
45
- label,
46
- content: /*#__PURE__*/ _jsx(OptionsEditorComponent, {
47
- ...others
48
- })
49
- })));
50
- }
51
- // always show json editor by default
52
- tabs.push({
53
- label: 'JSON',
54
- content: /*#__PURE__*/ _jsx(JSONEditor, {
55
- ...others
56
- })
57
- });
58
- return /*#__PURE__*/ _jsx(OptionsEditorTabs, {
59
- tabs: tabs
60
- });
32
+ throw new Error('This editor should not be used for panel type. Please use Panel Spec Editor instead.');
61
33
  }
62
34
  const { OptionsEditorComponent } = plugin;
63
35
  if (OptionsEditorComponent !== undefined) {
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PluginSpecEditor/PluginSpecEditor.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 { ErrorAlert } from '@perses-dev/components';\nimport { UnknownSpec } from '@perses-dev/core';\nimport { OptionsEditorProps, PluginType } from '../../model';\nimport { usePlugin } from '../../runtime';\n\nexport interface PluginSpecEditorProps extends OptionsEditorProps<UnknownSpec> {\n pluginType: PluginType;\n pluginKind: string;\n}\n\nexport function PluginSpecEditor(props: PluginSpecEditorProps) {\n const { pluginType, pluginKind, ...others } = props;\n const { data: plugin, isLoading, error } = usePlugin(pluginType, pluginKind);\n\n if (error) {\n return <ErrorAlert error={error} />;\n }\n\n // TODO: Proper loading indicator\n if (isLoading) {\n return null;\n }\n\n if (plugin === undefined) {\n throw new Error(`Missing implementation for ${pluginType} plugin with kind '${pluginKind}'`);\n }\n\n if (pluginType === 'Panel') {\n throw new Error('This editor should not be used for panel type. Please use Panel Spec Editor instead.');\n }\n\n const { OptionsEditorComponent } = plugin;\n\n if (OptionsEditorComponent !== undefined) {\n return <OptionsEditorComponent {...others} />;\n }\n\n return null;\n}\n"],"names":["ErrorAlert","usePlugin","PluginSpecEditor","props","pluginType","pluginKind","others","data","plugin","isLoading","error","undefined","Error","OptionsEditorComponent"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACn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":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PluginSpecEditor/index.tsx"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './PluginSpecEditor';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PluginSpecEditor/index.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\nexport * from './PluginSpecEditor';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { TimeSeriesQueryDefinition, QueryDefinition } from '@perses-dev/core';
3
+ export interface TimeSeriesQueryEditorProps {
4
+ queries?: TimeSeriesQueryDefinition[];
5
+ onChange: (queries: QueryDefinition[]) => void;
6
+ }
7
+ export declare function TimeSeriesQueryEditor({ queries, onChange }: TimeSeriesQueryEditorProps): JSX.Element;
8
+ //# sourceMappingURL=TimeSeriesQueryEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAM9E,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,EAAE,yBAAyB,EAAE,CAAC;IACtC,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,qBAAqB,CAAC,EAAE,OAAY,EAAE,QAAQ,EAAE,EAAE,0BAA0B,eAwG3F"}
@@ -0,0 +1,131 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { useState } from 'react';
15
+ import { produce } from 'immer';
16
+ import { Button, Stack } from '@mui/material';
17
+ import AddIcon from 'mdi-material-ui/Plus';
18
+ import { usePlugin, usePluginRegistry } from '../../runtime';
19
+ import { TimeSeriesQueryInput } from './TimeSeriesQueryInput';
20
+ const DEFAULT_QUERY_PLUGIN_TYPE = 'TimeSeriesQuery';
21
+ export function TimeSeriesQueryEditor({ queries =[] , onChange }) {
22
+ const hasMoreThanOneQuery = queries.length > 1;
23
+ const { defaultPluginKinds } = usePluginRegistry();
24
+ var ref;
25
+ const defaultTimeSeriesQueryKind = (ref = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[DEFAULT_QUERY_PLUGIN_TYPE]) !== null && ref !== void 0 ? ref : '';
26
+ const { data: defaultQueryPlugin } = usePlugin(DEFAULT_QUERY_PLUGIN_TYPE, defaultTimeSeriesQueryKind, {
27
+ useErrorBoundary: true,
28
+ enabled: true
29
+ });
30
+ // State for which queries are collapsed
31
+ // TODO: Would be easier if we had IDs for queries.
32
+ const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(()=>false));
33
+ // Query handlers
34
+ const handleQueryChange = (index, queryDef)=>{
35
+ onChange(produce(queries, (draft)=>{
36
+ if (draft) {
37
+ draft[index] = queryDef;
38
+ } else {
39
+ draft = [
40
+ queryDef
41
+ ];
42
+ }
43
+ }));
44
+ };
45
+ const handleQueryAdd = ()=>{
46
+ if (!defaultQueryPlugin) return;
47
+ onChange(produce(queries, (draft)=>{
48
+ const queryDef = {
49
+ kind: DEFAULT_QUERY_PLUGIN_TYPE,
50
+ spec: {
51
+ plugin: {
52
+ kind: defaultTimeSeriesQueryKind,
53
+ spec: defaultQueryPlugin.createInitialOptions()
54
+ }
55
+ }
56
+ };
57
+ if (draft) {
58
+ draft.push(queryDef);
59
+ } else {
60
+ draft = [
61
+ ...queries,
62
+ queryDef
63
+ ];
64
+ }
65
+ }));
66
+ setQueriesCollapsed((queriesCollapsed)=>{
67
+ queriesCollapsed.push(false);
68
+ return [
69
+ ...queriesCollapsed
70
+ ];
71
+ });
72
+ };
73
+ const handleQueryDelete = (index)=>{
74
+ onChange(produce(queries, (draft)=>{
75
+ draft.splice(index, 1);
76
+ }));
77
+ setQueriesCollapsed((queriesCollapsed)=>{
78
+ queriesCollapsed.splice(index, 1);
79
+ return [
80
+ ...queriesCollapsed
81
+ ];
82
+ });
83
+ };
84
+ const handleQueryCollapseExpand = (index)=>{
85
+ setQueriesCollapsed((queriesCollapsed)=>{
86
+ queriesCollapsed[index] = !queriesCollapsed[index];
87
+ return [
88
+ ...queriesCollapsed
89
+ ];
90
+ });
91
+ };
92
+ var ref1;
93
+ // show one query input if queries is empty
94
+ const queryDefinitions = queries.length ? queries : [
95
+ {
96
+ kind: 'TimeSeriesQuery',
97
+ spec: {
98
+ plugin: {
99
+ kind: (ref1 = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds['TimeSeriesQuery']) !== null && ref1 !== void 0 ? ref1 : '',
100
+ spec: {
101
+ query: ''
102
+ }
103
+ }
104
+ }
105
+ }
106
+ ];
107
+ return /*#__PURE__*/ _jsxs(Stack, {
108
+ spacing: 1,
109
+ children: [
110
+ /*#__PURE__*/ _jsx(Button, {
111
+ variant: "contained",
112
+ startIcon: /*#__PURE__*/ _jsx(AddIcon, {}),
113
+ sx: {
114
+ marginLeft: 'auto'
115
+ },
116
+ onClick: handleQueryAdd,
117
+ children: "Add Query"
118
+ }),
119
+ queryDefinitions.map((query, i)=>/*#__PURE__*/ _jsx(TimeSeriesQueryInput, {
120
+ index: i,
121
+ query: query,
122
+ isCollapsed: !!queriesCollapsed[i],
123
+ onChange: handleQueryChange,
124
+ onDelete: hasMoreThanOneQuery ? handleQueryDelete : undefined,
125
+ onCollapseExpand: handleQueryCollapseExpand
126
+ }, i))
127
+ ]
128
+ });
129
+ }
130
+
131
+ //# sourceMappingURL=TimeSeriesQueryEditor.js.map