@perses-dev/plugin-system 0.44.0-rc2 → 0.45.0-rc0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +12 -3
  2. package/dist/cjs/components/{TimeSeriesQueryEditor/TimeSeriesQueryEditor.js → MultiQueryEditor/MultiQueryEditor.js} +35 -37
  3. package/dist/cjs/components/{TimeSeriesQueryEditor/TimeSeriesQueryInput.js → MultiQueryEditor/QueryEditorContainer.js} +22 -10
  4. package/dist/cjs/components/{TimeSeriesQueryEditor → MultiQueryEditor}/index.js +2 -2
  5. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +12 -46
  6. package/dist/cjs/components/PluginEditor/PluginEditor.js +6 -7
  7. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +43 -31
  8. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +25 -5
  9. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +5 -3
  10. package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
  11. package/dist/cjs/components/ProjectSelect.js +3 -2
  12. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +192 -0
  13. package/dist/cjs/components/{TraceQueryEditor → TimeRangeControls}/index.js +1 -1
  14. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +16 -4
  15. package/dist/cjs/components/index.js +2 -1
  16. package/dist/cjs/constants/user-interface-text.js +4 -1
  17. package/dist/cjs/runtime/DataQueriesProvider/model.js +6 -2
  18. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +8 -0
  19. package/dist/cjs/runtime/plugin-registry.js +7 -5
  20. package/dist/cjs/validation/resource.js +1 -1
  21. package/dist/cjs/validation/user.js +46 -0
  22. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  23. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +12 -3
  24. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  25. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +16 -0
  26. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -0
  27. package/dist/components/{TimeSeriesQueryEditor/TimeSeriesQueryEditor.js → MultiQueryEditor/MultiQueryEditor.js} +42 -37
  28. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -0
  29. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +28 -0
  30. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -0
  31. package/dist/components/{TimeSeriesQueryEditor/TimeSeriesQueryInput.js → MultiQueryEditor/QueryEditorContainer.js} +32 -9
  32. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -0
  33. package/dist/components/MultiQueryEditor/index.d.ts +2 -0
  34. package/dist/components/MultiQueryEditor/index.d.ts.map +1 -0
  35. package/dist/components/{TimeSeriesQueryEditor → MultiQueryEditor}/index.js +2 -2
  36. package/dist/components/{TraceQueryEditor → MultiQueryEditor}/index.js.map +1 -1
  37. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  38. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +13 -47
  39. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  40. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  41. package/dist/components/PluginEditor/PluginEditor.js +6 -7
  42. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  43. package/dist/components/PluginEditor/plugin-editor-api.d.ts +15 -9
  44. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  45. package/dist/components/PluginEditor/plugin-editor-api.js +43 -31
  46. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  47. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +10 -4
  48. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  49. package/dist/components/PluginKindSelect/PluginKindSelect.js +31 -8
  50. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  51. package/dist/components/PluginRegistry/PluginRegistry.js +5 -3
  52. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  53. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +3 -3
  54. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  55. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
  56. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  57. package/dist/components/ProjectSelect.js +3 -2
  58. package/dist/components/ProjectSelect.js.map +1 -1
  59. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +13 -0
  60. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -0
  61. package/dist/components/TimeRangeControls/TimeRangeControls.js +168 -0
  62. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  63. package/dist/components/TimeRangeControls/index.d.ts +2 -0
  64. package/dist/components/TimeRangeControls/index.d.ts.map +1 -0
  65. package/dist/components/{TraceQueryEditor → TimeRangeControls}/index.js +1 -1
  66. package/dist/components/TimeRangeControls/index.js.map +1 -0
  67. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  68. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +16 -4
  69. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  70. package/dist/components/index.d.ts +2 -1
  71. package/dist/components/index.d.ts.map +1 -1
  72. package/dist/components/index.js +2 -1
  73. package/dist/components/index.js.map +1 -1
  74. package/dist/constants/user-interface-text.d.ts +2 -0
  75. package/dist/constants/user-interface-text.d.ts.map +1 -1
  76. package/dist/constants/user-interface-text.js +4 -1
  77. package/dist/constants/user-interface-text.js.map +1 -1
  78. package/dist/model/panels.d.ts +7 -2
  79. package/dist/model/panels.d.ts.map +1 -1
  80. package/dist/model/panels.js.map +1 -1
  81. package/dist/model/plugin-base.d.ts +0 -1
  82. package/dist/model/plugin-base.d.ts.map +1 -1
  83. package/dist/model/plugin-base.js.map +1 -1
  84. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  85. package/dist/runtime/DataQueriesProvider/model.js +6 -2
  86. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  87. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +4 -0
  88. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  89. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +8 -1
  90. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  91. package/dist/runtime/plugin-registry.d.ts +5 -5
  92. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  93. package/dist/runtime/plugin-registry.js +7 -5
  94. package/dist/runtime/plugin-registry.js.map +1 -1
  95. package/dist/validation/resource.js +1 -1
  96. package/dist/validation/resource.js.map +1 -1
  97. package/dist/validation/user.d.ts +93 -0
  98. package/dist/validation/user.d.ts.map +1 -0
  99. package/dist/validation/user.js +38 -0
  100. package/dist/validation/user.js.map +1 -0
  101. package/package.json +4 -4
  102. package/dist/cjs/components/TraceQueryEditor/TraceQueryEditor.js +0 -143
  103. package/dist/cjs/components/TraceQueryEditor/TraceQueryInput.js +0 -96
  104. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts +0 -7
  105. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +0 -1
  106. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +0 -1
  107. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts +0 -12
  108. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts.map +0 -1
  109. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js.map +0 -1
  110. package/dist/components/TimeSeriesQueryEditor/index.d.ts +0 -2
  111. package/dist/components/TimeSeriesQueryEditor/index.d.ts.map +0 -1
  112. package/dist/components/TimeSeriesQueryEditor/index.js.map +0 -1
  113. package/dist/components/TraceQueryEditor/TraceQueryEditor.d.ts +0 -8
  114. package/dist/components/TraceQueryEditor/TraceQueryEditor.d.ts.map +0 -1
  115. package/dist/components/TraceQueryEditor/TraceQueryEditor.js +0 -130
  116. package/dist/components/TraceQueryEditor/TraceQueryEditor.js.map +0 -1
  117. package/dist/components/TraceQueryEditor/TraceQueryInput.d.ts +0 -12
  118. package/dist/components/TraceQueryEditor/TraceQueryInput.d.ts.map +0 -1
  119. package/dist/components/TraceQueryEditor/TraceQueryInput.js +0 -83
  120. package/dist/components/TraceQueryEditor/TraceQueryInput.js.map +0 -1
  121. package/dist/components/TraceQueryEditor/index.d.ts +0 -2
  122. package/dist/components/TraceQueryEditor/index.d.ts.map +0 -1
@@ -21,84 +21,96 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
21
21
  * kind back.
22
22
  */ export function usePluginEditor(props) {
23
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
25
- // Keep a stable reference so we don't run the effect below when we don't need to
24
+ const { pluginTypes, value, onHideQueryEditorChange = ()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
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);
27
27
  const onHideQuery = useEvent(onHideQueryEditorChange);
28
28
  // The previous spec state for PluginType and kind and a helper function for remembering current values
29
29
  const prevSpecState = useRef({
30
- [pluginType]: {
31
- [value.kind]: value.spec
30
+ [value.selection.type]: {
31
+ [value.selection.kind]: value.spec
32
32
  }
33
33
  });
34
34
  const rememberCurrentSpecState = useEvent(()=>{
35
- let byPluginType = prevSpecState.current[pluginType];
35
+ let byPluginType = prevSpecState.current[value.selection.type];
36
36
  if (byPluginType === undefined) {
37
37
  byPluginType = {};
38
- prevSpecState.current[pluginType] = byPluginType;
38
+ prevSpecState.current[value.selection.type] = byPluginType;
39
39
  }
40
- byPluginType[value.kind] = value.spec;
40
+ byPluginType[value.selection.kind] = value.spec;
41
41
  });
42
42
  // The previous hide query state for each panel kind
43
43
  const hideQueryState = useRef({
44
- [value.kind]: false
44
+ [value.selection.kind]: false
45
45
  });
46
46
  const { defaultPluginKinds } = usePluginRegistry();
47
- const defaultPluginKind = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[pluginType];
48
- const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';
47
+ const defaultPluginType = pluginTypes[0];
48
+ const defaultPluginKind = defaultPluginType ? defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[defaultPluginType] : undefined;
49
+ const defaultPluginSelection = defaultPluginType && defaultPluginKind ? {
50
+ type: defaultPluginType,
51
+ kind: defaultPluginKind
52
+ } : undefined;
53
+ const initPendingSelection = !value.selection && defaultPluginSelection ? defaultPluginSelection : undefined;
49
54
  // When kind changes and we haven't loaded that plugin before, we will need to enter a "pending" state so that we
50
55
  // can generate proper initial spec values that match the new plugin kind
51
- const [pendingKind, setPendingKind] = useState(initPendingKind);
52
- const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);
56
+ const [pendingSelection, setPendingSelection] = useState(initPendingSelection);
57
+ // Take a default kind in case user write explicitly an empty kind in the initial value
58
+ useEffect(()=>{
59
+ if (value.selection.kind === '') {
60
+ value.selection.kind = defaultPluginKind || '';
61
+ }
62
+ }, [
63
+ value.selection,
64
+ defaultPluginKind
65
+ ]);
66
+ const { data: plugin, isFetching, error } = usePlugin(pendingSelection === null || pendingSelection === void 0 ? void 0 : pendingSelection.type, (pendingSelection === null || pendingSelection === void 0 ? void 0 : pendingSelection.kind) || '');
53
67
  useEffect(()=>{
54
68
  // Nothing to do if no new plugin kind is pending
55
- if (pendingKind === '') return;
69
+ if (!pendingSelection) return;
56
70
  // Can't get spec value until we have a plugin
57
71
  if (plugin === undefined) return;
58
72
  // Fire an onChange to change to the pending kind with initial values from the plugin
59
73
  rememberCurrentSpecState();
60
74
  onChange({
61
- kind: pendingKind,
75
+ selection: pendingSelection,
62
76
  spec: plugin.createInitialOptions()
63
77
  });
64
- if (pluginType === 'Panel') {
78
+ if (pendingSelection.type === 'Panel') {
65
79
  const panelPlugin = plugin;
66
- hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;
67
- if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {
80
+ hideQueryState.current[pendingSelection.kind] = !!panelPlugin.hideQueryEditor;
81
+ if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.selection.kind]) {
68
82
  onHideQuery(!!panelPlugin.hideQueryEditor);
69
83
  }
70
84
  }
71
- setPendingKind('');
85
+ setPendingSelection(undefined);
72
86
  }, [
73
- pendingKind,
87
+ pendingSelection,
74
88
  plugin,
75
89
  rememberCurrentSpecState,
76
90
  onChange,
77
91
  onHideQuery,
78
92
  hideQueryState,
79
- pluginType,
80
- value.kind
93
+ value.selection
81
94
  ]);
82
95
  /**
83
96
  * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we
84
97
  * make the switch.
85
- */ const onKindChange = (e)=>{
86
- var _prevSpecState_current_pluginType;
87
- const nextKind = e.target.value;
98
+ */ const onSelectionChange = (nextSelection)=>{
99
+ var _prevSpecState_current_nextSelection_type;
88
100
  // If we already have state for this plugin type/kind from a previous selection, just use it
89
- const previousState = (_prevSpecState_current_pluginType = prevSpecState.current[pluginType]) === null || _prevSpecState_current_pluginType === void 0 ? void 0 : _prevSpecState_current_pluginType[nextKind];
101
+ const previousState = (_prevSpecState_current_nextSelection_type = prevSpecState.current[nextSelection.type]) === null || _prevSpecState_current_nextSelection_type === void 0 ? void 0 : _prevSpecState_current_nextSelection_type[nextSelection.kind];
90
102
  if (previousState !== undefined) {
91
103
  rememberCurrentSpecState();
92
104
  onChange({
93
- kind: nextKind,
105
+ selection: nextSelection,
94
106
  spec: previousState
95
107
  });
96
108
  } else {
97
109
  // Otherwise, kick off the async loading process
98
- setPendingKind(nextKind);
110
+ setPendingSelection(nextSelection);
99
111
  }
100
- if (pluginType === 'Panel' && hideQueryState.current[nextKind] !== undefined && hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]) {
101
- onHideQuery(!!hideQueryState.current[nextKind]);
112
+ if (nextSelection.type === 'Panel' && hideQueryState.current[nextSelection.kind] !== undefined && hideQueryState.current[value.selection.kind] !== hideQueryState.current[nextSelection.kind]) {
113
+ onHideQuery(!!hideQueryState.current[nextSelection.kind]);
102
114
  }
103
115
  };
104
116
  /**
@@ -109,10 +121,10 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
109
121
  }));
110
122
  };
111
123
  return {
112
- pendingKind,
124
+ pendingSelection,
113
125
  isLoading: isFetching,
114
126
  error,
115
- onKindChange,
127
+ onSelectionChange,
116
128
  onSpecChange,
117
129
  rememberCurrentSpecState
118
130
  };
@@ -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 { 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 isReadonly?: boolean;\n isExplore?: boolean;\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,mBAAmB;AACrE,SAASC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QAAQ,QAAQ;AACpD,SAASC,OAAO,QAAQ,QAAQ;AAIhC,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,gBAAgB;AAyB7D;;;;;CAKC,GACD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,gEAAgE;IAChE,MAAM,EAAEC,UAAU,EAAEC,KAAK,EAAEC,0BAA0B,KAAO,CAAC,EAAE,GAAGH,OAAO,8FAA8F;IAEvK,iFAAiF;IACjF,MAAMI,WAAWZ,SAASQ,MAAMI,QAAQ;IACxC,MAAMC,cAAcb,SAASW;IAE7B,uGAAuG;IACvG,MAAMG,gBAAgBZ,OAA0B;QAC9C,CAACO,WAAW,EAAE;YAAE,CAACC,MAAMK,IAAI,CAAC,EAAEL,MAAMM,IAAI;QAAC;IAC3C;IACA,MAAMC,2BAA2BjB,SAAS;QACxC,IAAIkB,eAAeJ,cAAcK,OAAO,CAACV,WAAW;QACpD,IAAIS,iBAAiBE,WAAW;YAC9BF,eAAe,CAAC;YAChBJ,cAAcK,OAAO,CAACV,WAAW,GAAGS;QACtC;QACAA,YAAY,CAACR,MAAMK,IAAI,CAAC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kBAAkBlB,WAAW;YAC/BH;YACAL,SAAS;gBACPG,MAAMqB;gBACNpB,MAAMsB;YACR;QACF,OAAO;YACL,gDAAgD;YAChDZ,eAAeU;QACjB;QAEA,IACE3B,eAAe,WACfY,eAAeF,OAAO,CAACiB,SAAS,KAAKhB,aACrCC,eAAeF,OAAO,CAACT,MAAMK,IAAI,CAAC,KAAKM,eAAeF,OAAO,CAACiB,SAAS,EACvE;YACAvB,YAAY,CAAC,CAACQ,eAAeF,OAAO,CAACiB,SAAS;QAChD;IACF;IAEA;;GAEC,GACD,MAAMG,eAAkD,CAACC;QACvD5B,SACER,QAAQM,OAAO,CAAC+B;YACdA,MAAMzB,IAAI,GAAGwB;QACf;IAEJ;IAEA,OAAO;QAAEf;QAAaiB,WAAWb;QAAYC;QAAOI;QAAcK;QAActB;IAAyB;AAC3G"}
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 { 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\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 onChange: (next: PluginEditorValue) => 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 // eslint-disable-next-line @typescript-eslint/no-empty-function\n const { pluginTypes, 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 [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) 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(),\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 }, [pendingSelection, plugin, rememberCurrentSpecState, onChange, onHideQuery, hideQueryState, value.selection]);\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":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","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,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAAsBA,QAAQ,QAAQ,mBAAmB;AACzD,SAASC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QAAQ,QAAQ;AACpD,SAASC,OAAO,QAAQ,QAAQ;AAIhC,SAASC,SAAS,EAAEC,iBAAiB,QAAQ,gBAAgB;AAkC7D;;;;;CAKC,GACD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,gEAAgE;IAChE,MAAM,EAAEC,WAAW,EAAEC,KAAK,EAAEC,0BAA0B,KAAO,CAAC,EAAE,GAAGH,OAAO,8FAA8F;IAExK,kFAAkF;IAClF,MAAMI,WAAWZ,SAASQ,MAAM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,EAC3F;YACAJ,YAAY,CAAC,CAACU,eAAeF,OAAO,CAACkB,cAActB,IAAI,CAAC;QAC1D;IACF;IAEA;;GAEC,GACD,MAAMwB,eAAkD,CAACC;QACvD9B,SACER,QAAQM,OAAO,CAACiC;YACdA,MAAMzB,IAAI,GAAGwB;QACf;IAEJ;IAEA,OAAO;QACLb;QACAe,WAAWX;QACXC;QACAI;QACAG;QACAtB;IACF;AACF"}
@@ -1,12 +1,18 @@
1
1
  /// <reference types="react" />
2
2
  import { TextFieldProps } from '@mui/material';
3
3
  import { PluginType } from '../../model';
4
- export interface PluginKindSelectProps extends Omit<TextFieldProps, 'children'> {
5
- pluginType: PluginType;
4
+ import { PluginEditorSelection } from '../PluginEditor';
5
+ export interface PluginKindSelectProps extends Omit<TextFieldProps, 'value' | 'onChange' | 'children'> {
6
+ pluginTypes: PluginType[];
7
+ value?: PluginEditorSelection;
8
+ onChange?: (s: PluginEditorSelection) => void;
6
9
  }
7
10
  /**
8
- * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of a specific
9
- * plugin type. (e.g. "Show a list of all the Panel plugins" or "Show a list of all the Variable plugins").
11
+ * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific
12
+ * plugin types. (e.g. "Show a list of all the Panel plugins", or "Show a list of all the Variable plugins", or "Show
13
+ * a list of all the TimeSeriesQuery, TraceQuery, and LogQuery plugins").
14
+ * The value of the select is the kind of the plugin, but you can also listen to the `onPluginTypeChange` event to know
15
+ * when the user changes the plugin type (it fires at start for the default value.)
10
16
  */
11
17
  export declare const PluginKindSelect: import("react").ForwardRefExoticComponent<Omit<PluginKindSelectProps, "ref"> & import("react").RefAttributes<unknown>>;
12
18
  //# sourceMappingURL=PluginKindSelect.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PluginKindSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAuB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,cAAc,EAAE,UAAU,CAAC;IAC7E,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,wHAkB3B,CAAC"}
1
+ {"version":3,"file":"PluginKindSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAuB,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,cAAc,EAAE,OAAO,GAAG,UAAU,GAAG,UAAU,CAAC;IACpG,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,KAAK,CAAC,EAAE,qBAAqB,CAAC;IAC9B,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;CAC/C;AAED;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,wHA6C3B,CAAC"}
@@ -12,22 +12,42 @@
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { MenuItem, TextField } from '@mui/material';
15
- import { forwardRef } from 'react';
15
+ import { forwardRef, useCallback } from 'react';
16
16
  import { useListPluginMetadata } from '../../runtime';
17
17
  /**
18
- * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of a specific
19
- * plugin type. (e.g. "Show a list of all the Panel plugins" or "Show a list of all the Variable plugins").
18
+ * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific
19
+ * plugin types. (e.g. "Show a list of all the Panel plugins", or "Show a list of all the Variable plugins", or "Show
20
+ * a list of all the TimeSeriesQuery, TraceQuery, and LogQuery plugins").
21
+ * The value of the select is the kind of the plugin, but you can also listen to the `onPluginTypeChange` event to know
22
+ * when the user changes the plugin type (it fires at start for the default value.)
20
23
  */ export const PluginKindSelect = /*#__PURE__*/ forwardRef((props, ref)=>{
21
- const { pluginType, value: propValue, ...others } = props;
22
- const { data, isLoading } = useListPluginMetadata(pluginType);
24
+ const { pluginTypes, value: propValue, onChange, ...others } = props;
25
+ const { data, isLoading } = useListPluginMetadata(pluginTypes);
23
26
  // Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
24
- const value = propValue !== '' && isLoading ? '' : propValue;
27
+ const value = propValue && isLoading ? '' : JSON.stringify(propValue);
28
+ const handleChange = (event)=>{
29
+ onChange === null || onChange === void 0 ? void 0 : onChange(JSON.parse(event.target.value));
30
+ };
31
+ const renderValue = useCallback((selected)=>{
32
+ var _data_find;
33
+ const selectedValue = JSON.parse(selected);
34
+ if (!selectedValue.kind) {
35
+ return '';
36
+ }
37
+ return data === null || data === void 0 ? void 0 : (_data_find = data.find((v)=>v.pluginType === selectedValue.type && v.kind === selectedValue.kind)) === null || _data_find === void 0 ? void 0 : _data_find.display.name;
38
+ }, [
39
+ data
40
+ ]);
25
41
  // TODO: Does this need a loading indicator of some kind?
26
42
  return /*#__PURE__*/ _jsxs(TextField, {
27
43
  select: true,
28
44
  inputRef: ref,
29
45
  ...others,
30
46
  value: value,
47
+ onChange: handleChange,
48
+ SelectProps: {
49
+ renderValue
50
+ },
31
51
  "data-testid": "plugin-kind-select",
32
52
  children: [
33
53
  isLoading && /*#__PURE__*/ _jsx(MenuItem, {
@@ -36,9 +56,12 @@ import { useListPluginMetadata } from '../../runtime';
36
56
  }),
37
57
  data === null || data === void 0 ? void 0 : data.map((metadata)=>/*#__PURE__*/ _jsx(MenuItem, {
38
58
  "data-testid": "option",
39
- value: metadata.kind,
59
+ value: JSON.stringify({
60
+ type: metadata.pluginType,
61
+ kind: metadata.kind
62
+ }),
40
63
  children: metadata.display.name
41
- }, metadata.kind))
64
+ }, metadata.pluginType + metadata.kind))
42
65
  ]
43
66
  });
44
67
  });
@@ -1 +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 { MenuItem, TextField, TextFieldProps } from '@mui/material';\nimport { forwardRef } from 'react';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata } from '../../runtime';\n\nexport interface PluginKindSelectProps extends Omit<TextFieldProps, '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 const PluginKindSelect = forwardRef((props: PluginKindSelectProps, ref) => {\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 <TextField select inputRef={ref} {...others} value={value} data-testid=\"plugin-kind-select\">\n {isLoading && <MenuItem value=\"\">Loading...</MenuItem>}\n {data?.map((metadata) => (\n <MenuItem data-testid=\"option\" key={metadata.kind} value={metadata.kind}>\n {metadata.display.name}\n </MenuItem>\n ))}\n </TextField>\n );\n});\nPluginKindSelect.displayName = 'PluginKindSelect';\n"],"names":["MenuItem","TextField","forwardRef","useListPluginMetadata","PluginKindSelect","props","ref","pluginType","value","propValue","others","data","isLoading","select","inputRef","data-testid","map","metadata","kind","display","name","displayName"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,QAAQ,EAAEC,SAAS,QAAwB,gBAAgB;AACpE,SAASC,UAAU,QAAQ,QAAQ;AAEnC,SAASC,qBAAqB,QAAQ,gBAAgB;AAMtD;;;CAGC,GACD,OAAO,MAAMC,iCAAmBF,WAAW,CAACG,OAA8BC;IACxE,MAAM,EAAEC,UAAU,EAAEC,OAAOC,SAAS,EAAE,GAAGC,QAAQ,GAAGL;IACpD,MAAM,EAAEM,IAAI,EAAEC,SAAS,EAAE,GAAGT,sBAAsBI;IAElD,qHAAqH;IACrH,MAAMC,QAAQC,cAAc,MAAMG,YAAY,KAAKH;IAEnD,yDAAyD;IACzD,qBACE,MAACR;QAAUY,MAAM;QAACC,UAAUR;QAAM,GAAGI,MAAM;QAAEF,OAAOA;QAAOO,eAAY;;YACpEH,2BAAa,KAACZ;gBAASQ,OAAM;0BAAG;;YAChCG,iBAAAA,2BAAAA,KAAMK,GAAG,CAAC,CAACC,yBACV,KAACjB;oBAASe,eAAY;oBAA6BP,OAAOS,SAASC,IAAI;8BACpED,SAASE,OAAO,CAACC,IAAI;mBADYH,SAASC,IAAI;;;AAMzD,GAAG;AACHd,iBAAiBiB,WAAW,GAAG"}
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 { MenuItem, TextField, TextFieldProps } from '@mui/material';\nimport { forwardRef, useCallback } from 'react';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata } from '../../runtime';\nimport { PluginEditorSelection } from '../PluginEditor';\n\nexport interface PluginKindSelectProps extends Omit<TextFieldProps, 'value' | 'onChange' | 'children'> {\n pluginTypes: PluginType[];\n value?: PluginEditorSelection;\n onChange?: (s: PluginEditorSelection) => void;\n}\n\n/**\n * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of some specific\n * plugin types. (e.g. \"Show a list of all the Panel plugins\", or \"Show a list of all the Variable plugins\", or \"Show\n * a list of all the TimeSeriesQuery, TraceQuery, and LogQuery plugins\").\n * The value of the select is the kind of the plugin, but you can also listen to the `onPluginTypeChange` event to know\n * when the user changes the plugin type (it fires at start for the default value.)\n */\nexport const PluginKindSelect = forwardRef((props: PluginKindSelectProps, ref) => {\n const { pluginTypes, value: propValue, onChange, ...others } = props;\n const { data, isLoading } = useListPluginMetadata(pluginTypes);\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 ? '' : JSON.stringify(propValue);\n\n const handleChange = (event: { target: { value: string } }) => {\n onChange?.(JSON.parse(event.target.value));\n };\n\n const renderValue = useCallback(\n (selected: unknown) => {\n const selectedValue = JSON.parse(selected as string);\n if (!selectedValue.kind) {\n return '';\n }\n return data?.find((v) => v.pluginType === selectedValue.type && v.kind === selectedValue.kind)?.display.name;\n },\n [data]\n );\n\n // TODO: Does this need a loading indicator of some kind?\n return (\n <TextField\n select\n inputRef={ref}\n {...others}\n value={value}\n onChange={handleChange}\n SelectProps={{ renderValue }}\n data-testid=\"plugin-kind-select\"\n >\n {isLoading && <MenuItem value=\"\">Loading...</MenuItem>}\n {data?.map((metadata) => (\n <MenuItem\n data-testid=\"option\"\n key={metadata.pluginType + metadata.kind}\n value={JSON.stringify({ type: metadata.pluginType, kind: metadata.kind })}\n >\n {metadata.display.name}\n </MenuItem>\n ))}\n </TextField>\n );\n});\nPluginKindSelect.displayName = 'PluginKindSelect';\n"],"names":["MenuItem","TextField","forwardRef","useCallback","useListPluginMetadata","PluginKindSelect","props","ref","pluginTypes","value","propValue","onChange","others","data","isLoading","JSON","stringify","handleChange","event","parse","target","renderValue","selected","selectedValue","kind","find","v","pluginType","type","display","name","select","inputRef","SelectProps","data-testid","map","metadata","displayName"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,QAAQ,EAAEC,SAAS,QAAwB,gBAAgB;AACpE,SAASC,UAAU,EAAEC,WAAW,QAAQ,QAAQ;AAEhD,SAASC,qBAAqB,QAAQ,gBAAgB;AAStD;;;;;;CAMC,GACD,OAAO,MAAMC,iCAAmBH,WAAW,CAACI,OAA8BC;IACxE,MAAM,EAAEC,WAAW,EAAEC,OAAOC,SAAS,EAAEC,QAAQ,EAAE,GAAGC,QAAQ,GAAGN;IAC/D,MAAM,EAAEO,IAAI,EAAEC,SAAS,EAAE,GAAGV,sBAAsBI;IAElD,qHAAqH;IACrH,MAAMC,QAAQC,aAAaI,YAAY,KAAKC,KAAKC,SAAS,CAACN;IAE3D,MAAMO,eAAe,CAACC;QACpBP,qBAAAA,+BAAAA,SAAWI,KAAKI,KAAK,CAACD,MAAME,MAAM,CAACX,KAAK;IAC1C;IAEA,MAAMY,cAAclB,YAClB,CAACmB;YAKQT;QAJP,MAAMU,gBAAgBR,KAAKI,KAAK,CAACG;QACjC,IAAI,CAACC,cAAcC,IAAI,EAAE;YACvB,OAAO;QACT;QACA,OAAOX,iBAAAA,4BAAAA,aAAAA,KAAMY,IAAI,CAAC,CAACC,IAAMA,EAAEC,UAAU,KAAKJ,cAAcK,IAAI,IAAIF,EAAEF,IAAI,KAAKD,cAAcC,IAAI,eAAtFX,iCAAAA,WAAyFgB,OAAO,CAACC,IAAI;IAC9G,GACA;QAACjB;KAAK;IAGR,yDAAyD;IACzD,qBACE,MAACZ;QACC8B,MAAM;QACNC,UAAUzB;QACT,GAAGK,MAAM;QACVH,OAAOA;QACPE,UAAUM;QACVgB,aAAa;YAAEZ;QAAY;QAC3Ba,eAAY;;YAEXpB,2BAAa,KAACd;gBAASS,OAAM;0BAAG;;YAChCI,iBAAAA,2BAAAA,KAAMsB,GAAG,CAAC,CAACC,yBACV,KAACpC;oBACCkC,eAAY;oBAEZzB,OAAOM,KAAKC,SAAS,CAAC;wBAAEY,MAAMQ,SAAST,UAAU;wBAAEH,MAAMY,SAASZ,IAAI;oBAAC;8BAEtEY,SAASP,OAAO,CAACC,IAAI;mBAHjBM,SAAST,UAAU,GAAGS,SAASZ,IAAI;;;AAQlD,GAAG;AACHnB,iBAAiBgC,WAAW,GAAG"}
@@ -56,10 +56,12 @@ import { usePluginIndexes, getTypeAndKindKey } from './plugin-indexes';
56
56
  getPluginIndexes,
57
57
  loadPluginModule
58
58
  ]);
59
- const listPluginMetadata = useCallback(async (pluginType)=>{
59
+ const listPluginMetadata = useCallback(async (pluginTypes)=>{
60
60
  const pluginIndexes = await getPluginIndexes();
61
- var _pluginIndexes_pluginMetadataByType_get;
62
- return (_pluginIndexes_pluginMetadataByType_get = pluginIndexes.pluginMetadataByType.get(pluginType)) !== null && _pluginIndexes_pluginMetadataByType_get !== void 0 ? _pluginIndexes_pluginMetadataByType_get : [];
61
+ return pluginTypes.flatMap((type)=>{
62
+ var _pluginIndexes_pluginMetadataByType_get;
63
+ return (_pluginIndexes_pluginMetadataByType_get = pluginIndexes.pluginMetadataByType.get(type)) !== null && _pluginIndexes_pluginMetadataByType_get !== void 0 ? _pluginIndexes_pluginMetadataByType_get : [];
64
+ });
63
65
  }, [
64
66
  getPluginIndexes
65
67
  ]);
@@ -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, ReactNode } 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?: 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;;AA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I,EAAEL,WAAW,kBAAkB,EAAEC,KAAK,sBAAsB,EAAEV,SAASiB,QAAQ,CAACC,IAAI,CAAC,cAAc,CAAC;QAE7G;QAEA,OAAOF;IACT,GACA;QAACpB;QAAkBG;KAAiB;IAGtC,MAAMoB,qBAAqBnC,YACzB,OAAOyB;QACL,MAAME,gBAAgB,MAAMf;YACrBe;QAAP,OAAOA,CAAAA,0CAAAA,cAAcS,oBAAoB,CAACjB,GAAG,CAACM,yBAAvCE,qDAAAA,0CAAsD,EAAE;IACjE,GACA;QAACf;KAAiB;IAGpB,iDAAiD;IACjD,MAAMyB,UAAUpC,QACd,IAAO,CAAA;YAAEuB;YAAWW;YAAoBxB;QAAmB,CAAA,GAC3D;QAACa;QAAWW;QAAoBxB;KAAmB;IAErD,qBAAO,KAACT,sBAAsBoC,QAAQ;QAACC,OAAOF;kBAAU3B;;AAC1D"}
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, ReactNode } 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?: 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 (pluginTypes: PluginType[]) => {\n const pluginIndexes = await getPluginIndexes();\n return pluginTypes.flatMap((type) => pluginIndexes.pluginMetadataByType.get(type) ?? []);\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","pluginTypes","flatMap","type","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,SAAsBA,QAAQ,QAAQ,mBAAmB;AACzD,SAASC,MAAM,EAAEC,WAAW,EAAEC,OAAO,QAAmB,QAAQ;AAShE,SAASC,qBAAqB,QAAQ,gBAAgB;AACtD,SAASC,gBAAgB,EAAEC,iBAAiB,QAAQ,mBAAmB;AAQvE;;;CAGC,GACD,OAAO,SAASC,eAAeC,KAA0B;IACvD,MAAM,EACJC,cAAc,EAAEC,mBAAmB,EAAEC,kBAAkB,EAAE,EACzDC,QAAQ,EACRC,kBAAkB,EACnB,GAAGL;IAEJ,MAAMM,mBAAmBT,iBAAiBK;IAE1C,yCAAyC;IACzC,MAAMK,cAAcd,OAAO,IAAIe;IAE/B,gHAAgH;IAChH,iBAAiB;IACjB,MAAMC,mBAAmBjB,SAAS,CAACkB;QACjC,IAAIC,UAAUJ,YAAYK,OAAO,CAACC,GAAG,CAACH;QACtC,IAAIC,YAAYG,WAAW;YACzBH,UAAUR,mBAAmBO;YAC7BH,YAAYK,OAAO,CAACG,GAAG,CAACL,UAAUC;YAElC,2E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
2
- import { OptionsEditorProps, PluginType } from '../../model';
2
+ import { OptionsEditorProps } from '../../model';
3
+ import { PluginEditorSelection } from '../PluginEditor';
3
4
  export interface PluginSpecEditorProps extends OptionsEditorProps<UnknownSpec> {
4
- pluginType: PluginType;
5
- pluginKind: string;
5
+ pluginSelection: PluginEditorSelection;
6
6
  isEditor?: boolean;
7
7
  }
8
8
  export declare function PluginSpecEditor(props: PluginSpecEditorProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1 +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;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,kDA4B5D"}
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,MAAM,aAAa,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAC;AAExD,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB,CAAC,WAAW,CAAC;IAC5E,eAAe,EAAE,qBAAqB,CAAC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,kDA+B5D"}
@@ -14,7 +14,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { ErrorAlert } from '@perses-dev/components';
15
15
  import { usePlugin } from '../../runtime';
16
16
  export function PluginSpecEditor(props) {
17
- const { pluginType, pluginKind, ...others } = props;
17
+ const { pluginSelection: { type: pluginType, kind: pluginKind }, ...others } = props;
18
18
  const { data: plugin, isLoading, error } = usePlugin(pluginType, pluginKind);
19
19
  if (error) {
20
20
  return /*#__PURE__*/ _jsx(ErrorAlert, {
@@ -1 +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 isEditor?: boolean;\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;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,QAAQ,yBAAyB;AAGpD,SAASC,SAAS,QAAQ,gBAAgB;AAQ1C,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAE,GAAGC,QAAQ,GAAGH;IAC9C,MAAM,EAAEI,MAAMC,MAAM,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGT,UAAUG,YAAYC;IAEjE,IAAIK,OAAO;QACT,qBAAO,KAACV;YAAWU,OAAOA;;IAC5B;IAEA,iCAAiC;IACjC,IAAID,WAAW;QACb,OAAO;IACT;IAEA,IAAID,WAAWG,WAAW;QACxB,MAAM,IAAIC,MAAM,CAAC,2BAA2B,EAAER,WAAW,mBAAmB,EAAEC,WAAW,CAAC,CAAC;IAC7F;IAEA,IAAID,eAAe,SAAS;QAC1B,MAAM,IAAIQ,MAAM;IAClB;IAEA,MAAM,EAAEC,sBAAsB,EAAE,GAAGL;IAEnC,IAAIK,2BAA2BF,WAAW;QACxC,qBAAO,KAACE;YAAwB,GAAGP,MAAM;;IAC3C;IAEA,OAAO;AACT"}
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 } from '../../model';\nimport { usePlugin } from '../../runtime';\nimport { PluginEditorSelection } from '../PluginEditor';\n\nexport interface PluginSpecEditorProps extends OptionsEditorProps<UnknownSpec> {\n pluginSelection: PluginEditorSelection;\n isEditor?: boolean;\n}\n\nexport function PluginSpecEditor(props: PluginSpecEditorProps) {\n const {\n pluginSelection: { type: pluginType, kind: pluginKind },\n ...others\n } = 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","pluginSelection","type","pluginType","kind","pluginKind","others","data","plugin","isLoading","error","undefined","Error","OptionsEditorComponent"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,UAAU,QAAQ,yBAAyB;AAGpD,SAASC,SAAS,QAAQ,gBAAgB;AAQ1C,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EACJC,iBAAiB,EAAEC,MAAMC,UAAU,EAAEC,MAAMC,UAAU,EAAE,EACvD,GAAGC,QACJ,GAAGN;IACJ,MAAM,EAAEO,MAAMC,MAAM,EAAEC,SAAS,EAAEC,KAAK,EAAE,GAAGZ,UAAUK,YAAYE;IAEjE,IAAIK,OAAO;QACT,qBAAO,KAACb;YAAWa,OAAOA;;IAC5B;IAEA,iCAAiC;IACjC,IAAID,WAAW;QACb,OAAO;IACT;IAEA,IAAID,WAAWG,WAAW;QACxB,MAAM,IAAIC,MAAM,CAAC,2BAA2B,EAAET,WAAW,mBAAmB,EAAEE,WAAW,CAAC,CAAC;IAC7F;IAEA,IAAIF,eAAe,SAAS;QAC1B,MAAM,IAAIS,MAAM;IAClB;IAEA,MAAM,EAAEC,sBAAsB,EAAE,GAAGL;IAEnC,IAAIK,2BAA2BF,WAAW;QACxC,qBAAO,KAACE;YAAwB,GAAGP,MAAM;;IAC3C;IAEA,OAAO;AACT"}
@@ -37,7 +37,7 @@ import { useProjectList } from '../context';
37
37
  onChange: handleChange,
38
38
  children: [
39
39
  /*#__PURE__*/ _jsx(MenuItem, {
40
- value: 'none',
40
+ value: "none",
41
41
  children: /*#__PURE__*/ _jsx(Stack, {
42
42
  direction: "row",
43
43
  alignItems: "center",
@@ -84,7 +84,8 @@ import { useProjectList } from '../context';
84
84
  kind: 'Project',
85
85
  metadata: {
86
86
  name: optionValue
87
- }
87
+ },
88
+ spec: {}
88
89
  };
89
90
  }
90
91
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/ProjectSelect.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, Stack, ListItemText } from '@mui/material';\nimport { ProjectResource } from '@perses-dev/core';\nimport { useProjectList } from '../context';\n\n// Props on MUI Select 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 ProjectSelectProps extends Omit<SelectProps<string>, OmittedMuiProps> {\n onChange: (next: ProjectResource) => void;\n value: ProjectResource;\n}\n\n/**\n * Displays a MUI input for selecting a Project of a particular kind. Note: The 'value' and `onChange` handler for\n * the input deal with a `ProjectSelector`.\n */\nexport function ProjectSelect(props: ProjectSelectProps) {\n const { onChange, value, ...others } = props;\n\n const { data, isLoading } = useProjectList();\n\n // While loading available values, just use an empty string so MUI select doesn't warn about values out of range\n const optionValue = isLoading ? '' : projectToOptionValue(value);\n\n // When the user makes a selection, convert the string option value back to a DatasourceSelector\n const handleChange: SelectProps<string>['onChange'] = (e) => {\n const next = optionValueToSelector(e.target.value);\n onChange(next);\n };\n\n // TODO:\n // - Does this need a loading indicator of some kind?\n // - The group's edit link is not clickable once selected.\n // - The group's edit link is disabled if datasource is overridden.\n // Ref: https://github.com/mui/material-ui/issues/36572\n return (\n <Select {...others} value={optionValue} onChange={handleChange}>\n <MenuItem value={'none'}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\" height={32}>\n <ListItemText>None</ListItemText>\n </Stack>\n </MenuItem>\n {data?.map((project: ProjectResource) => [\n <MenuItem key={project.metadata.name} value={project.metadata.name}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\" height={32}>\n <ListItemText>{project.metadata.name}</ListItemText>\n </Stack>\n </MenuItem>,\n ])}\n </Select>\n );\n}\n\n/**\n * Given a ProjectSelectItemSelector,\n * returns a string value that can be used as a Select input value.\n * @param selector\n */\nfunction projectToOptionValue(project: ProjectResource): string {\n return project.metadata.name ?? 'none';\n}\n\n/**\n * Given an option value name,\n * returns a ProjectResource to be used by the query data model.\n * @param optionValue\n */\nfunction optionValueToSelector(optionValue: string): ProjectResource {\n return {\n kind: 'Project',\n metadata: {\n name: optionValue,\n },\n };\n}\n"],"names":["Select","MenuItem","Stack","ListItemText","useProjectList","ProjectSelect","props","onChange","value","others","data","isLoading","optionValue","projectToOptionValue","handleChange","e","next","optionValueToSelector","target","direction","alignItems","justifyContent","width","height","map","project","metadata","name","kind"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,MAAM,EAAeC,QAAQ,EAAEC,KAAK,EAAEC,YAAY,QAAQ,gBAAgB;AAEnF,SAASC,cAAc,QAAQ,aAAa;AAW5C;;;CAGC,GACD,OAAO,SAASC,cAAcC,KAAyB;IACrD,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGC,QAAQ,GAAGH;IAEvC,MAAM,EAAEI,IAAI,EAAEC,SAAS,EAAE,GAAGP;IAE5B,gHAAgH;IAChH,MAAMQ,cAAcD,YAAY,KAAKE,qBAAqBL;IAE1D,gGAAgG;IAChG,MAAMM,eAAgD,CAACC;QACrD,MAAMC,OAAOC,sBAAsBF,EAAEG,MAAM,CAACV,KAAK;QACjDD,SAASS;IACX;IAEA,QAAQ;IACR,sDAAsD;IACtD,2DAA2D;IAC3D,oEAAoE;IACpE,0DAA0D;IAC1D,qBACE,MAAChB;QAAQ,GAAGS,MAAM;QAAED,OAAOI;QAAaL,UAAUO;;0BAChD,KAACb;gBAASO,OAAO;0BACf,cAAA,KAACN;oBAAMiB,WAAU;oBAAMC,YAAW;oBAASC,gBAAe;oBAAgBC,OAAM;oBAAOC,QAAQ;8BAC7F,cAAA,KAACpB;kCAAa;;;;YAGjBO,iBAAAA,2BAAAA,KAAMc,GAAG,CAAC,CAACC,UAA6B;kCACvC,KAACxB;wBAAqCO,OAAOiB,QAAQC,QAAQ,CAACC,IAAI;kCAChE,cAAA,KAACzB;4BAAMiB,WAAU;4BAAMC,YAAW;4BAASC,gBAAe;4BAAgBC,OAAM;4BAAOC,QAAQ;sCAC7F,cAAA,KAACpB;0CAAcsB,QAAQC,QAAQ,CAACC,IAAI;;;uBAFzBF,QAAQC,QAAQ,CAACC,IAAI;iBAKrC;;;AAGP;AAEA;;;;CAIC,GACD,SAASd,qBAAqBY,OAAwB;QAC7CA;IAAP,OAAOA,CAAAA,yBAAAA,QAAQC,QAAQ,CAACC,IAAI,cAArBF,oCAAAA,yBAAyB;AAClC;AAEA;;;;CAIC,GACD,SAASR,sBAAsBL,WAAmB;IAChD,OAAO;QACLgB,MAAM;QACNF,UAAU;YACRC,MAAMf;QACR;IACF;AACF"}
1
+ {"version":3,"sources":["../../src/components/ProjectSelect.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, Stack, ListItemText } from '@mui/material';\nimport { ProjectResource } from '@perses-dev/core';\nimport { useProjectList } from '../context';\n\n// Props on MUI Select 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 ProjectSelectProps extends Omit<SelectProps<string>, OmittedMuiProps> {\n onChange: (next: ProjectResource) => void;\n value: ProjectResource;\n}\n\n/**\n * Displays a MUI input for selecting a Project of a particular kind. Note: The 'value' and `onChange` handler for\n * the input deal with a `ProjectSelector`.\n */\nexport function ProjectSelect(props: ProjectSelectProps) {\n const { onChange, value, ...others } = props;\n\n const { data, isLoading } = useProjectList();\n\n // While loading available values, just use an empty string so MUI select doesn't warn about values out of range\n const optionValue = isLoading ? '' : projectToOptionValue(value);\n\n // When the user makes a selection, convert the string option value back to a DatasourceSelector\n const handleChange: SelectProps<string>['onChange'] = (e) => {\n const next = optionValueToSelector(e.target.value);\n onChange(next);\n };\n\n // TODO:\n // - Does this need a loading indicator of some kind?\n // - The group's edit link is not clickable once selected.\n // - The group's edit link is disabled if datasource is overridden.\n // Ref: https://github.com/mui/material-ui/issues/36572\n return (\n <Select {...others} value={optionValue} onChange={handleChange}>\n <MenuItem value=\"none\">\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\" height={32}>\n <ListItemText>None</ListItemText>\n </Stack>\n </MenuItem>\n {data?.map((project: ProjectResource) => [\n <MenuItem key={project.metadata.name} value={project.metadata.name}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\" height={32}>\n <ListItemText>{project.metadata.name}</ListItemText>\n </Stack>\n </MenuItem>,\n ])}\n </Select>\n );\n}\n\n/**\n * Given a ProjectSelectItemSelector,\n * returns a string value that can be used as a Select input value.\n * @param selector\n */\nfunction projectToOptionValue(project: ProjectResource): string {\n return project.metadata.name ?? 'none';\n}\n\n/**\n * Given an option value name,\n * returns a ProjectResource to be used by the query data model.\n * @param optionValue\n */\nfunction optionValueToSelector(optionValue: string): ProjectResource {\n return {\n kind: 'Project',\n metadata: {\n name: optionValue,\n },\n spec: {},\n };\n}\n"],"names":["Select","MenuItem","Stack","ListItemText","useProjectList","ProjectSelect","props","onChange","value","others","data","isLoading","optionValue","projectToOptionValue","handleChange","e","next","optionValueToSelector","target","direction","alignItems","justifyContent","width","height","map","project","metadata","name","kind","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,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sBL,WAAmB;IAChD,OAAO;QACLgB,MAAM;QACNF,UAAU;YACRC,MAAMf;QACR;QACAiB,MAAM,CAAC;IACT;AACF"}
@@ -0,0 +1,13 @@
1
+ import { TimeOption } from '@perses-dev/components';
2
+ export declare const DEFAULT_TIME_RANGE_OPTIONS: TimeOption[];
3
+ export declare const DEFAULT_REFRESH_INTERVAL_OPTIONS: TimeOption[];
4
+ interface TimeRangeControlsProps {
5
+ heightPx?: number;
6
+ showTimeRangeSelector?: boolean;
7
+ showRefreshButton?: boolean;
8
+ showRefreshInterval?: boolean;
9
+ timePresets?: TimeOption[];
10
+ }
11
+ export declare function TimeRangeControls({ heightPx, showTimeRangeSelector, showRefreshButton, showRefreshInterval, timePresets, }: TimeRangeControlsProps): import("react/jsx-runtime").JSX.Element;
12
+ export {};
13
+ //# sourceMappingURL=TimeRangeControls.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"names":[],"mappings":"AAeA,OAAO,EAIL,UAAU,EAEX,MAAM,wBAAwB,CAAC;AAMhC,eAAO,MAAM,0BAA0B,EAAE,UAAU,EAUlD,CAAC;AAEF,eAAO,MAAM,gCAAgC,EAAE,UAAU,EAOxD,CAAC;AAIF,UAAU,sBAAsB;IAE9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,WAAW,CAAC,EAAE,UAAU,EAAE,CAAC;CAC5B;AAED,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,qBAA4B,EAC5B,iBAAwB,EACxB,mBAA0B,EAC1B,WAAwC,GACzC,EAAE,sBAAsB,2CAiDxB"}