@perses-dev/plugin-system 0.50.3 → 0.51.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +17 -71
- package/dist/cjs/components/DatasourceSelect.js +8 -13
- package/dist/cjs/components/HTTPSettingsEditor/HTTPSettingsEditor.js +534 -0
- package/dist/cjs/{stories/shared-utils → components/HTTPSettingsEditor}/index.js +2 -2
- package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -4
- package/dist/cjs/components/MetricLabelInput/MetricLabelInput.js +1 -1
- package/dist/cjs/components/MetricLabelInput/index.js +1 -1
- package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +15 -14
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +2 -2
- package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +7 -11
- package/dist/cjs/components/PluginEditor/PluginEditor.js +10 -6
- package/dist/cjs/components/PluginEditor/plugin-editor-api.js +4 -5
- package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +7 -8
- package/dist/cjs/components/PluginRegistry/PluginRegistry.js +7 -10
- package/dist/cjs/components/PluginRegistry/plugin-indexes.js +17 -14
- package/dist/cjs/components/ProjectSelect.js +2 -3
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +46 -92
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +6 -6
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +6 -11
- package/dist/cjs/components/Variables/variable-model.js +4 -7
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/index.js +1 -0
- package/dist/{stories/shared-utils/index.js → cjs/model/explore.js} +4 -3
- package/dist/cjs/remote/PersesPlugin.types.js +16 -0
- package/dist/cjs/remote/PluginLoaderComponent.js +75 -0
- package/dist/cjs/remote/PluginRuntime.js +267 -0
- package/dist/cjs/{stories/shared-utils/decorators → remote}/index.js +3 -7
- package/dist/cjs/remote/remotePluginLoader.js +61 -0
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -10
- package/dist/cjs/runtime/DataQueriesProvider/model.js +4 -7
- package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +2 -2
- package/dist/cjs/runtime/builtin-variables.js +1 -1
- package/dist/cjs/runtime/datasources.js +3 -3
- package/dist/cjs/runtime/plugin-registry.js +5 -6
- package/dist/cjs/runtime/time-series-queries.js +11 -18
- package/dist/cjs/runtime/trace-queries.js +1 -2
- package/dist/cjs/runtime/variables.js +10 -28
- package/dist/cjs/test/render.js +1 -2
- package/dist/cjs/test-utils/mock-plugin-registry.js +10 -10
- package/dist/cjs/utils/variables.js +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +17 -30
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/DatasourceSelect.d.ts +2 -2
- package/dist/components/DatasourceSelect.d.ts.map +1 -1
- package/dist/components/DatasourceSelect.js +8 -13
- package/dist/components/DatasourceSelect.js.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +11 -0
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +480 -0
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -0
- package/dist/components/HTTPSettingsEditor/index.d.ts +2 -0
- package/dist/components/HTTPSettingsEditor/index.d.ts.map +1 -0
- package/dist/{stories/shared-utils/decorators → components/HTTPSettingsEditor}/index.js +1 -6
- package/dist/components/HTTPSettingsEditor/index.js.map +1 -0
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +4 -4
- package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
- package/dist/components/MetricLabelInput/MetricLabelInput.js +1 -1
- package/dist/components/MetricLabelInput/MetricLabelInput.js.map +1 -1
- package/dist/components/MetricLabelInput/index.js +1 -1
- package/dist/components/MetricLabelInput/index.js.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +15 -14
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
- package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +7 -11
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +10 -6
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +4 -5
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +7 -8
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +7 -10
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +4 -4
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +17 -14
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/ProjectSelect.js +2 -3
- package/dist/components/ProjectSelect.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +46 -92
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +6 -6
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +6 -11
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
- package/dist/components/Variables/variable-model.js +4 -7
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/model/explore.d.ts +13 -0
- package/dist/model/explore.d.ts.map +1 -0
- package/dist/model/explore.js +17 -0
- package/dist/model/explore.js.map +1 -0
- package/dist/model/panels.d.ts +13 -3
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/plugins.d.ts +31 -17
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/remote/PersesPlugin.types.d.ts +7 -0
- package/dist/remote/PersesPlugin.types.d.ts.map +1 -0
- package/dist/remote/PersesPlugin.types.js +15 -0
- package/dist/remote/PersesPlugin.types.js.map +1 -0
- package/dist/remote/PluginLoaderComponent.d.ts +10 -0
- package/dist/remote/PluginLoaderComponent.d.ts.map +1 -0
- package/dist/remote/PluginLoaderComponent.js +67 -0
- package/dist/remote/PluginLoaderComponent.js.map +1 -0
- package/dist/remote/PluginRuntime.d.ts +11 -0
- package/dist/remote/PluginRuntime.d.ts.map +1 -0
- package/dist/remote/PluginRuntime.js +202 -0
- package/dist/remote/PluginRuntime.js.map +1 -0
- package/dist/remote/index.d.ts +3 -0
- package/dist/remote/index.d.ts.map +1 -0
- package/dist/remote/index.js +16 -0
- package/dist/remote/index.js.map +1 -0
- package/dist/remote/remotePluginLoader.d.ts +3 -0
- package/dist/remote/remotePluginLoader.d.ts.map +1 -0
- package/dist/remote/remotePluginLoader.js +53 -0
- package/dist/remote/remotePluginLoader.js.map +1 -0
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -10
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +4 -7
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +2 -2
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/builtin-variables.js +1 -1
- package/dist/runtime/builtin-variables.js.map +1 -1
- package/dist/runtime/datasources.d.ts +2 -2
- package/dist/runtime/datasources.js +3 -3
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +6 -6
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +5 -6
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/time-series-queries.js +11 -18
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.js +1 -2
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/runtime/variables.js +10 -28
- package/dist/runtime/variables.js.map +1 -1
- package/dist/test/render.js +1 -2
- package/dist/test/render.js.map +1 -1
- package/dist/test-utils/mock-plugin-registry.d.ts +5 -3
- package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
- package/dist/test-utils/mock-plugin-registry.js +10 -10
- package/dist/test-utils/mock-plugin-registry.js.map +1 -1
- package/dist/utils/variables.js +1 -1
- package/dist/utils/variables.js.map +1 -1
- package/package.json +9 -10
- package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +0 -41
- package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +0 -100
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +0 -42
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +0 -101
- package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemVariables.js +0 -42
- package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +0 -41
- package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts +0 -13
- package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts.map +0 -1
- package/dist/stories/shared-utils/decorators/WithDataQueries.js +0 -33
- package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts +0 -4
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +0 -46
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts +0 -13
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +0 -39
- package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts +0 -13
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +0 -95
- package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts +0 -13
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.d.ts.map +0 -1
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js +0 -39
- package/dist/stories/shared-utils/decorators/WithPluginSystemVariables.js.map +0 -1
- package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +0 -13
- package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +0 -1
- package/dist/stories/shared-utils/decorators/WithTimeRange.js +0 -33
- package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +0 -1
- package/dist/stories/shared-utils/decorators/index.d.ts +0 -7
- package/dist/stories/shared-utils/decorators/index.d.ts.map +0 -1
- package/dist/stories/shared-utils/decorators/index.js.map +0 -1
- package/dist/stories/shared-utils/index.d.ts +0 -2
- package/dist/stories/shared-utils/index.d.ts.map +0 -1
- package/dist/stories/shared-utils/index.js.map +0 -1
|
@@ -26,15 +26,14 @@ import { useListPluginMetadata } from '../../runtime';
|
|
|
26
26
|
// Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
|
|
27
27
|
const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
|
|
28
28
|
const handleChange = (event)=>{
|
|
29
|
-
onChange
|
|
29
|
+
onChange?.(optionValueToSelection(event.target.value));
|
|
30
30
|
};
|
|
31
31
|
const renderValue = useCallback((selected)=>{
|
|
32
|
-
var _data_find;
|
|
33
32
|
if (selected === '') {
|
|
34
33
|
return '';
|
|
35
34
|
}
|
|
36
35
|
const selectedValue = optionValueToSelection(selected);
|
|
37
|
-
return data
|
|
36
|
+
return data?.find((v)=>v.kind === selectedValue.type && v.spec.name === selectedValue.kind)?.spec.display.name;
|
|
38
37
|
}, [
|
|
39
38
|
data
|
|
40
39
|
]);
|
|
@@ -55,14 +54,14 @@ import { useListPluginMetadata } from '../../runtime';
|
|
|
55
54
|
value: "",
|
|
56
55
|
children: "Loading..."
|
|
57
56
|
}),
|
|
58
|
-
data
|
|
57
|
+
data?.map((metadata)=>/*#__PURE__*/ _jsx(MenuItem, {
|
|
59
58
|
"data-testid": "option",
|
|
60
59
|
value: selectionToOptionValue({
|
|
61
|
-
type: metadata.
|
|
62
|
-
kind: metadata.
|
|
60
|
+
type: metadata.kind,
|
|
61
|
+
kind: metadata.spec.name
|
|
63
62
|
}),
|
|
64
|
-
children: metadata.display.name
|
|
65
|
-
}, metadata.
|
|
63
|
+
children: metadata.spec.display.name
|
|
64
|
+
}, metadata.kind + metadata.spec.name))
|
|
66
65
|
]
|
|
67
66
|
});
|
|
68
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, ReactElement, 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): ReactElement => {\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 ? '' : selectionToOptionValue(propValue);\n\n const handleChange = (event: { target: { value: string } }): void => {\n onChange?.(optionValueToSelection(event.target.value));\n };\n\n const renderValue = useCallback(\n (selected: unknown) => {\n if (selected === '') {\n return '';\n }\n const selectedValue = optionValueToSelection(selected as string);\n return data?.find((v) => v.
|
|
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, ReactElement, 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): ReactElement => {\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 ? '' : selectionToOptionValue(propValue);\n\n const handleChange = (event: { target: { value: string } }): void => {\n onChange?.(optionValueToSelection(event.target.value));\n };\n\n const renderValue = useCallback(\n (selected: unknown) => {\n if (selected === '') {\n return '';\n }\n const selectedValue = optionValueToSelection(selected as string);\n return data?.find((v) => v.kind === selectedValue.type && v.spec.name === selectedValue.kind)?.spec.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 aria-label={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.kind + metadata.spec.name}\n value={selectionToOptionValue({ type: metadata.kind, kind: metadata.spec.name })}\n >\n {metadata.spec.display.name}\n </MenuItem>\n ))}\n </TextField>\n );\n});\nPluginKindSelect.displayName = 'PluginKindSelect';\n\n// Delimiter used to stringify/parse option values\nconst OPTION_VALUE_DELIMITER = '_____';\n\n/**\n * Given a PluginEditorSelection,\n * returns a string value like `{type}_____{kind}` that can be used as a Select input value.\n * @param selector\n */\nfunction selectionToOptionValue(selector: PluginEditorSelection): string {\n return [selector.type, selector.kind].join(OPTION_VALUE_DELIMITER);\n}\n\n/**\n * Given an option value name like `{type}_____{kind}`,\n * returns a PluginEditorSelection to be used by the query data model.\n * @param optionValue\n */\nfunction optionValueToSelection(optionValue: string): PluginEditorSelection {\n const words = optionValue.split(OPTION_VALUE_DELIMITER);\n const type = words[0] as PluginType | undefined;\n const kind = words[1];\n if (type === undefined || kind === undefined) {\n throw new Error('Invalid optionValue string');\n }\n return {\n type,\n kind,\n };\n}\n"],"names":["MenuItem","TextField","forwardRef","useCallback","useListPluginMetadata","PluginKindSelect","props","ref","pluginTypes","value","propValue","onChange","others","data","isLoading","selectionToOptionValue","handleChange","event","optionValueToSelection","target","renderValue","selected","selectedValue","find","v","kind","type","spec","name","display","select","inputRef","aria-label","SelectProps","data-testid","map","metadata","displayName","OPTION_VALUE_DELIMITER","selector","join","optionValue","words","split","undefined","Error"],"mappings":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M,uBAAuB;wBAAEW,MAAMU,SAASX,IAAI;wBAAEA,MAAMW,SAAST,IAAI,CAACC,IAAI;oBAAC;8BAE7EQ,SAAST,IAAI,CAACE,OAAO,CAACD,IAAI;mBAHtBQ,SAASX,IAAI,GAAGW,SAAST,IAAI,CAACC,IAAI;;;AAQjD,GAAG;AACHvB,iBAAiBgC,WAAW,GAAG;AAE/B,kDAAkD;AAClD,MAAMC,yBAAyB;AAE/B;;;;CAIC,GACD,SAASvB,uBAAuBwB,QAA+B;IAC7D,OAAO;QAACA,SAASb,IAAI;QAAEa,SAASd,IAAI;KAAC,CAACe,IAAI,CAACF;AAC7C;AAEA;;;;CAIC,GACD,SAASpB,uBAAuBuB,WAAmB;IACjD,MAAMC,QAAQD,YAAYE,KAAK,CAACL;IAChC,MAAMZ,OAAOgB,KAAK,CAAC,EAAE;IACrB,MAAMjB,OAAOiB,KAAK,CAAC,EAAE;IACrB,IAAIhB,SAASkB,aAAanB,SAASmB,WAAW;QAC5C,MAAM,IAAIC,MAAM;IAClB;IACA,OAAO;QACLnB;QACAD;IACF;AACF"}
|
|
@@ -35,21 +35,21 @@ import { usePluginIndexes, getTypeAndKindKey } from './plugin-indexes';
|
|
|
35
35
|
}
|
|
36
36
|
return request;
|
|
37
37
|
});
|
|
38
|
-
const getPlugin = useCallback(async (
|
|
38
|
+
const getPlugin = useCallback(async (kind, name)=>{
|
|
39
39
|
// Get the indexes of the installed plugins
|
|
40
40
|
const pluginIndexes = await getPluginIndexes();
|
|
41
41
|
// Figure out what module the plugin is in by looking in the index
|
|
42
|
-
const typeAndKindKey = getTypeAndKindKey(
|
|
43
|
-
const resource = pluginIndexes.
|
|
42
|
+
const typeAndKindKey = getTypeAndKindKey(kind, name);
|
|
43
|
+
const resource = pluginIndexes.pluginResourcesByNameAndKind.get(typeAndKindKey);
|
|
44
44
|
if (resource === undefined) {
|
|
45
|
-
throw new Error(`A ${
|
|
45
|
+
throw new Error(`A ${name} plugin for kind '${kind}' is not installed`);
|
|
46
46
|
}
|
|
47
47
|
// Treat the plugin module as a bunch of named exports that have plugins
|
|
48
48
|
const pluginModule = await loadPluginModule(resource);
|
|
49
49
|
// We currently assume that plugin modules will have named exports that match the kinds they handle
|
|
50
|
-
const plugin = pluginModule[
|
|
50
|
+
const plugin = pluginModule[name];
|
|
51
51
|
if (plugin === undefined) {
|
|
52
|
-
throw new Error(`The ${
|
|
52
|
+
throw new Error(`The ${name} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`);
|
|
53
53
|
}
|
|
54
54
|
return plugin;
|
|
55
55
|
}, [
|
|
@@ -58,10 +58,7 @@ import { usePluginIndexes, getTypeAndKindKey } from './plugin-indexes';
|
|
|
58
58
|
]);
|
|
59
59
|
const listPluginMetadata = useCallback(async (pluginTypes)=>{
|
|
60
60
|
const pluginIndexes = await getPluginIndexes();
|
|
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
|
-
});
|
|
61
|
+
return pluginTypes.flatMap((type)=>pluginIndexes.pluginMetadataByKind.get(type) ?? []);
|
|
65
62
|
}, [
|
|
66
63
|
getPluginIndexes
|
|
67
64
|
]);
|
|
@@ -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, ReactElement } 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): ReactElement {\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>(
|
|
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, ReactElement } 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): ReactElement {\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>(kind: T, name: 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(kind, name);\n const resource = pluginIndexes.pluginResourcesByNameAndKind.get(typeAndKindKey);\n if (resource === undefined) {\n throw new Error(`A ${name} 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[name];\n if (plugin === undefined) {\n throw new Error(\n `The ${name} 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: string[]) => {\n const pluginIndexes = await getPluginIndexes();\n return pluginTypes.flatMap((type) => pluginIndexes.pluginMetadataByKind.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","kind","name","pluginIndexes","typeAndKindKey","pluginResourcesByNameAndKind","Error","pluginModule","plugin","metadata","listPluginMetadata","pluginTypes","flatMap","type","pluginMetadataByKind","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,QAAiC,QAAQ;AAS9E,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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pB,iDAAiD;IACjD,MAAM2B,UAAUtC,QACd,IAAO,CAAA;YAAEuB;YAAWU;YAAoBvB;QAAmB,CAAA,GAC3D;QAACa;QAAWU;QAAoBvB;KAAmB;IAErD,qBAAO,KAACT,sBAAsBsC,QAAQ;QAACC,OAAOF;kBAAU7B;;AAC1D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PluginLoader,
|
|
1
|
+
import { PluginLoader, PluginMetadataWithModule, PluginModuleResource, PluginType } from '../../model';
|
|
2
2
|
export interface PluginIndexes {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
pluginResourcesByNameAndKind: Map<string, PluginModuleResource>;
|
|
4
|
+
pluginMetadataByKind: Map<string, PluginMetadataWithModule[]>;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
7
|
* Returns an async callback for getting indexes of the installed plugin data.
|
|
@@ -10,5 +10,5 @@ export declare function usePluginIndexes(getInstalledPlugins: PluginLoader['getI
|
|
|
10
10
|
/**
|
|
11
11
|
* Gets a unique key for a plugin type/kind that can be used as a cache key.
|
|
12
12
|
*/
|
|
13
|
-
export declare function getTypeAndKindKey(
|
|
13
|
+
export declare function getTypeAndKindKey(kind: PluginType, name: string): string;
|
|
14
14
|
//# sourceMappingURL=plugin-indexes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-indexes.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/plugin-indexes.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"plugin-indexes.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/plugin-indexes.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,oBAAoB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEvG,MAAM,WAAW,aAAa;IAE5B,4BAA4B,EAAE,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAEhE,oBAAoB,EAAE,GAAG,CAAC,MAAM,EAAE,wBAAwB,EAAE,CAAC,CAAC;CAC/D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,mBAAmB,EAAE,YAAY,CAAC,qBAAqB,CAAC,GACvD,MAAM,OAAO,CAAC,aAAa,CAAC,CAuD9B;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAExE"}
|
|
@@ -20,29 +20,32 @@ import { useCallback, useRef } from 'react';
|
|
|
20
20
|
const createPluginIndexes = useEvent(async ()=>{
|
|
21
21
|
const installedPlugins = await getInstalledPlugins();
|
|
22
22
|
// Create the two indexes from the installed plugins
|
|
23
|
-
const
|
|
24
|
-
const
|
|
23
|
+
const pluginResourcesByNameAndKind = new Map();
|
|
24
|
+
const pluginMetadataByKind = new Map();
|
|
25
25
|
for (const resource of installedPlugins){
|
|
26
26
|
for (const pluginMetadata of resource.spec.plugins){
|
|
27
|
-
const {
|
|
27
|
+
const { kind, spec: { name } } = pluginMetadata;
|
|
28
28
|
// Index the plugin by type and kind to point at the module that contains it
|
|
29
|
-
const key = getTypeAndKindKey(
|
|
30
|
-
if (
|
|
31
|
-
console.warn(`Got more than one ${
|
|
29
|
+
const key = getTypeAndKindKey(kind, name);
|
|
30
|
+
if (pluginResourcesByNameAndKind.has(key)) {
|
|
31
|
+
console.warn(`Got more than one ${kind} plugin for kind ${name}`);
|
|
32
32
|
}
|
|
33
|
-
|
|
33
|
+
pluginResourcesByNameAndKind.set(key, resource);
|
|
34
34
|
// Index the metadata by plugin type
|
|
35
|
-
let list =
|
|
35
|
+
let list = pluginMetadataByKind.get(kind);
|
|
36
36
|
if (list === undefined) {
|
|
37
37
|
list = [];
|
|
38
|
-
|
|
38
|
+
pluginMetadataByKind.set(kind, list);
|
|
39
39
|
}
|
|
40
|
-
list.push(
|
|
40
|
+
list.push({
|
|
41
|
+
...pluginMetadata,
|
|
42
|
+
module: resource.metadata
|
|
43
|
+
});
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
return {
|
|
44
|
-
|
|
45
|
-
|
|
47
|
+
pluginResourcesByNameAndKind,
|
|
48
|
+
pluginMetadataByKind
|
|
46
49
|
};
|
|
47
50
|
});
|
|
48
51
|
// De-dupe creating plugin indexes (i.e. requests to get installed plugins)
|
|
@@ -63,8 +66,8 @@ import { useCallback, useRef } from 'react';
|
|
|
63
66
|
}
|
|
64
67
|
/**
|
|
65
68
|
* Gets a unique key for a plugin type/kind that can be used as a cache key.
|
|
66
|
-
*/ export function getTypeAndKindKey(
|
|
67
|
-
return `${
|
|
69
|
+
*/ export function getTypeAndKindKey(kind, name) {
|
|
70
|
+
return `${kind}:${name}`;
|
|
68
71
|
}
|
|
69
72
|
|
|
70
73
|
//# sourceMappingURL=plugin-indexes.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginRegistry/plugin-indexes.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 { useEvent } from '@perses-dev/core';\nimport { useCallback, useRef } from 'react';\nimport { PluginLoader,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginRegistry/plugin-indexes.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 { useEvent } from '@perses-dev/core';\nimport { useCallback, useRef } from 'react';\nimport { PluginLoader, PluginMetadataWithModule, PluginModuleResource, PluginType } from '../../model';\n\nexport interface PluginIndexes {\n // Plugin resources by plugin type and kind (i.e. look up what module a plugin type and kind is in)\n pluginResourcesByNameAndKind: Map<string, PluginModuleResource>;\n // Plugin metadata by plugin type\n pluginMetadataByKind: Map<string, PluginMetadataWithModule[]>;\n}\n\n/**\n * Returns an async callback for getting indexes of the installed plugin data.\n */\nexport function usePluginIndexes(\n getInstalledPlugins: PluginLoader['getInstalledPlugins']\n): () => Promise<PluginIndexes> {\n // Creates indexes from the installed plugins data (does useEvent because this accesses the getInstalledPlugins prop\n // and we want a stable reference for the callback below)\n const createPluginIndexes = useEvent(async (): Promise<PluginIndexes> => {\n const installedPlugins = await getInstalledPlugins();\n\n // Create the two indexes from the installed plugins\n const pluginResourcesByNameAndKind = new Map<string, PluginModuleResource>();\n const pluginMetadataByKind = new Map<string, PluginMetadataWithModule[]>();\n\n for (const resource of installedPlugins) {\n for (const pluginMetadata of resource.spec.plugins) {\n const {\n kind,\n spec: { name },\n } = pluginMetadata;\n\n // Index the plugin by type and kind to point at the module that contains it\n const key = getTypeAndKindKey(kind, name);\n if (pluginResourcesByNameAndKind.has(key)) {\n console.warn(`Got more than one ${kind} plugin for kind ${name}`);\n }\n pluginResourcesByNameAndKind.set(key, resource);\n\n // Index the metadata by plugin type\n let list = pluginMetadataByKind.get(kind);\n if (list === undefined) {\n list = [];\n pluginMetadataByKind.set(kind, list);\n }\n list.push({ ...pluginMetadata, module: resource.metadata });\n }\n }\n\n return {\n pluginResourcesByNameAndKind,\n pluginMetadataByKind,\n };\n });\n\n // De-dupe creating plugin indexes (i.e. requests to get installed plugins)\n const pluginIndexesCache = useRef<Promise<PluginIndexes> | undefined>(undefined);\n const getPluginIndexes = useCallback(() => {\n let request = pluginIndexesCache.current;\n if (request === undefined) {\n request = createPluginIndexes();\n pluginIndexesCache.current = request;\n\n // Remove failed requests from the cache so they can potentially be retried\n request.catch(() => pluginIndexesCache.current === undefined);\n }\n return request;\n }, [createPluginIndexes]);\n\n return getPluginIndexes;\n}\n\n/**\n * Gets a unique key for a plugin type/kind that can be used as a cache key.\n */\nexport function getTypeAndKindKey(kind: PluginType, name: string): string {\n return `${kind}:${name}`;\n}\n"],"names":["useEvent","useCallback","useRef","usePluginIndexes","getInstalledPlugins","createPluginIndexes","installedPlugins","pluginResourcesByNameAndKind","Map","pluginMetadataByKind","resource","pluginMetadata","spec","plugins","kind","name","key","getTypeAndKindKey","has","console","warn","set","list","get","undefined","push","module","metadata","pluginIndexesCache","getPluginIndexes","request","current","catch"],"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,QAAQ,mBAAmB;AAC5C,SAASC,WAAW,EAAEC,MAAM,QAAQ,QAAQ;AAU5C;;CAEC,GACD,OAAO,SAASC,iBACdC,mBAAwD;IAExD,oHAAoH;IACpH,yDAAyD;IACzD,MAAMC,sBAAsBL,SAAS;QACnC,MAAMM,mBAAmB,MAAMF;QAE/B,oDAAoD;QACpD,MAAMG,+BAA+B,IAAIC;QACzC,MAAMC,uBAAuB,IAAID;QAEjC,KAAK,MAAME,YAAYJ,iBAAkB;YACvC,KAAK,MAAMK,kBAAkBD,SAASE,IAAI,CAACC,OAAO,CAAE;gBAClD,MAAM,EACJC,IAAI,EACJF,MAAM,EAAEG,IAAI,EAAE,EACf,GAAGJ;gBAEJ,4EAA4E;gBAC5E,MAAMK,MAAMC,kBAAkBH,MAAMC;gBACpC,IAAIR,6BAA6BW,GAAG,CAACF,MAAM;oBACzCG,QAAQC,IAAI,CAAC,CAAC,kBAAkB,EAAEN,KAAK,iBAAiB,EAAEC,MAAM;gBAClE;gBACAR,6BAA6Bc,GAAG,CAACL,KAAKN;gBAEtC,oCAAoC;gBACpC,IAAIY,OAAOb,qBAAqBc,GAAG,CAACT;gBACpC,IAAIQ,SAASE,WAAW;oBACtBF,OAAO,EAAE;oBACTb,qBAAqBY,GAAG,CAACP,MAAMQ;gBACjC;gBACAA,KAAKG,IAAI,CAAC;oBAAE,GAAGd,cAAc;oBAAEe,QAAQhB,SAASiB,QAAQ;gBAAC;YAC3D;QACF;QAEA,OAAO;YACLpB;YACAE;QACF;IACF;IAEA,2EAA2E;IAC3E,MAAMmB,qBAAqB1B,OAA2CsB;IACtE,MAAMK,mBAAmB5B,YAAY;QACnC,IAAI6B,UAAUF,mBAAmBG,OAAO;QACxC,IAAID,YAAYN,WAAW;YACzBM,UAAUzB;YACVuB,mBAAmBG,OAAO,GAAGD;YAE7B,2EAA2E;YAC3EA,QAAQE,KAAK,CAAC,IAAMJ,mBAAmBG,OAAO,KAAKP;QACrD;QACA,OAAOM;IACT,GAAG;QAACzB;KAAoB;IAExB,OAAOwB;AACT;AAEA;;CAEC,GACD,OAAO,SAASZ,kBAAkBH,IAAgB,EAAEC,IAAY;IAC9D,OAAO,GAAGD,KAAK,CAAC,EAAEC,MAAM;AAC1B"}
|
|
@@ -49,7 +49,7 @@ import { useProjectList } from '../context';
|
|
|
49
49
|
})
|
|
50
50
|
})
|
|
51
51
|
}),
|
|
52
|
-
data
|
|
52
|
+
data?.map((project)=>[
|
|
53
53
|
/*#__PURE__*/ _jsx(MenuItem, {
|
|
54
54
|
value: project.metadata.name,
|
|
55
55
|
children: /*#__PURE__*/ _jsx(Stack, {
|
|
@@ -72,8 +72,7 @@ import { useProjectList } from '../context';
|
|
|
72
72
|
* returns a string value that can be used as a Select input value.
|
|
73
73
|
* @param selector
|
|
74
74
|
*/ function projectToOptionValue(project) {
|
|
75
|
-
|
|
76
|
-
return (_project_metadata_name = project.metadata.name) !== null && _project_metadata_name !== void 0 ? _project_metadata_name : 'none';
|
|
75
|
+
return project.metadata.name ?? 'none';
|
|
77
76
|
}
|
|
78
77
|
/**
|
|
79
78
|
* Given an option value name,
|
|
@@ -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 { ReactElement } from 'react';\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): ReactElement {\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,SAASA,MAAM,EAAeC,QAAQ,EAAEC,KAAK,EAAEC,YAAY,QAAQ,gBAAgB;AAGnF,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,OAAM;0BACd,cAAA,KAACN;oBAAMiB,WAAU;oBAAMC,YAAW;oBAASC,gBAAe;oBAAgBC,OAAM;oBAAOC,QAAQ;8BAC7F,cAAA,KAACpB;kCAAa;;;;YAGjBO,
|
|
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 { ReactElement } from 'react';\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): ReactElement {\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,2EAA2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QACLgB,MAAM;QACNF,UAAU;YACRC,MAAMf;QACR;QACAiB,MAAM,CAAC;IACT;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport RefreshIcon from 'mdi-material-ui/Refresh';\nimport { Stack } from '@mui/material';\nimport {\n RefreshIntervalPicker,\n InfoTooltip,\n TimeOption,\n ToolbarIconButton,\n TimeRangeSelector,\n buildRelativeTimeOption,\n} from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/core';\nimport { ReactElement, useCallback } from 'react';\nimport { TOOLTIP_TEXT } from '../../constants';\nimport { useTimeRange, useShowCustomTimeRangeSetting, useTimeRangeOptionsSetting } from '../../runtime';\n\nexport const DEFAULT_REFRESH_INTERVAL_OPTIONS: TimeOption[] = [\n { value: { pastDuration: '0s' }, display: 'Off' },\n { value: { pastDuration: '5s' }, display: '5s' },\n { value: { pastDuration: '10s' }, display: '10s' },\n { value: { pastDuration: '15s' }, display: '15s' },\n { value: { pastDuration: '30s' }, display: '30s' },\n { value: { pastDuration: '60s' }, display: '1m' },\n];\n\nconst DEFAULT_HEIGHT = '34px';\n\ninterface TimeRangeControlsProps {\n // The controls look best at heights >= 28 pixels\n heightPx?: number;\n showTimeRangeSelector?: boolean;\n showRefreshButton?: boolean;\n showRefreshInterval?: boolean;\n showCustomTimeRange?: boolean;\n timePresets?: TimeOption[];\n}\n\nexport function TimeRangeControls({\n heightPx,\n showTimeRangeSelector = true,\n showRefreshButton = true,\n showRefreshInterval = true,\n showCustomTimeRange,\n timePresets,\n}: TimeRangeControlsProps): ReactElement {\n const { timeRange, setTimeRange, refresh, refreshInterval, setRefreshInterval } = useTimeRange();\n\n const showCustomTimeRangeValue = useShowCustomTimeRangeSetting(showCustomTimeRange);\n const timePresetsValue = useTimeRangeOptionsSetting(timePresets);\n\n // Convert height to a string, then use the string for styling\n const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;\n\n // add time preset if one does not match duration given in time range\n if (\n 'pastDuration' in timeRange &&\n !timePresetsValue.some((option) => option.value.pastDuration === timeRange['pastDuration'])\n ) {\n timePresetsValue.push(buildRelativeTimeOption(timeRange['pastDuration']));\n }\n\n // set the new refresh interval both in the dashboard context & as query param\n const handleRefreshIntervalChange = useCallback(\n (duration: DurationString) => {\n setRefreshInterval(duration);\n },\n [setRefreshInterval]\n );\n\n return (\n <Stack direction=\"row\" spacing={1}>\n {showTimeRangeSelector && (\n <TimeRangeSelector\n timeOptions={timePresetsValue}\n value={timeRange}\n onChange={setTimeRange}\n height={height}\n showCustomTimeRange={showCustomTimeRangeValue}\n />\n )}\n {showRefreshButton && (\n <InfoTooltip description={TOOLTIP_TEXT.refresh}>\n <ToolbarIconButton aria-label={TOOLTIP_TEXT.refresh} onClick={refresh} sx={{ height }}>\n <RefreshIcon />\n </ToolbarIconButton>\n </InfoTooltip>\n )}\n {showRefreshInterval && (\n <InfoTooltip description={TOOLTIP_TEXT.refreshInterval}>\n <RefreshIntervalPicker\n timeOptions={DEFAULT_REFRESH_INTERVAL_OPTIONS}\n value={refreshInterval}\n onChange={handleRefreshIntervalChange}\n height={height}\n />\n </InfoTooltip>\n )}\n </Stack>\n );\n}\n"],"names":["RefreshIcon","Stack","RefreshIntervalPicker","InfoTooltip","ToolbarIconButton","TimeRangeSelector","buildRelativeTimeOption","useCallback","TOOLTIP_TEXT","useTimeRange","useShowCustomTimeRangeSetting","useTimeRangeOptionsSetting","DEFAULT_REFRESH_INTERVAL_OPTIONS","value","pastDuration","display","DEFAULT_HEIGHT","TimeRangeControls","heightPx","showTimeRangeSelector","showRefreshButton","showRefreshInterval","showCustomTimeRange","timePresets","timeRange","setTimeRange","refresh","refreshInterval","setRefreshInterval","showCustomTimeRangeValue","timePresetsValue","height","undefined","some","option","push","handleRefreshIntervalChange","duration","direction","spacing","timeOptions","onChange","description","aria-label","onClick","sx"],"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,OAAOA,iBAAiB,0BAA0B;AAClD,SAASC,KAAK,QAAQ,gBAAgB;AACtC,SACEC,qBAAqB,EACrBC,WAAW,EAEXC,iBAAiB,EACjBC,iBAAiB,EACjBC,uBAAuB,QAClB,yBAAyB;AAEhC,SAAuBC,WAAW,QAAQ,QAAQ;AAClD,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,YAAY,EAAEC,6BAA6B,EAAEC,0BAA0B,QAAQ,gBAAgB;AAExG,OAAO,MAAMC,mCAAiD;IAC5D;QAAEC,OAAO;YAAEC,cAAc;QAAK;QAAGC,SAAS;IAAM;IAChD;QAAEF,OAAO;YAAEC,cAAc;QAAK;QAAGC,SAAS;IAAK;IAC/C;QAAEF,OAAO;YAAEC,cAAc;QAAM;QAAGC,SAAS;IAAM;IACjD;QAAEF,OAAO;YAAEC,cAAc;QAAM;QAAGC,SAAS;IAAM;IACjD;QAAEF,OAAO;YAAEC,cAAc;QAAM;QAAGC,SAAS;IAAM;IACjD;QAAEF,OAAO;YAAEC,cAAc;QAAM;QAAGC,SAAS;IAAK;CACjD,CAAC;AAEF,MAAMC,iBAAiB;AAYvB,OAAO,SAASC,kBAAkB,EAChCC,QAAQ,EACRC,wBAAwB,IAAI,EAC5BC,oBAAoB,IAAI,EACxBC,sBAAsB,IAAI,EAC1BC,mBAAmB,EACnBC,WAAW,EACY;IACvB,MAAM,EAAEC,SAAS,EAAEC,YAAY,EAAEC,OAAO,EAAEC,eAAe,EAAEC,kBAAkB,EAAE,GAAGnB;IAElF,MAAMoB,2BAA2BnB,8BAA8BY;IAC/D,MAAMQ,mBAAmBnB,2BAA2BY;IAEpD,8DAA8D;IAC9D,MAAMQ,SAASb,aAAac,YAAYhB,iBAAiB,
|
|
1
|
+
{"version":3,"sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport RefreshIcon from 'mdi-material-ui/Refresh';\nimport { Stack } from '@mui/material';\nimport {\n RefreshIntervalPicker,\n InfoTooltip,\n TimeOption,\n ToolbarIconButton,\n TimeRangeSelector,\n buildRelativeTimeOption,\n} from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/core';\nimport { ReactElement, useCallback } from 'react';\nimport { TOOLTIP_TEXT } from '../../constants';\nimport { useTimeRange, useShowCustomTimeRangeSetting, useTimeRangeOptionsSetting } from '../../runtime';\n\nexport const DEFAULT_REFRESH_INTERVAL_OPTIONS: TimeOption[] = [\n { value: { pastDuration: '0s' }, display: 'Off' },\n { value: { pastDuration: '5s' }, display: '5s' },\n { value: { pastDuration: '10s' }, display: '10s' },\n { value: { pastDuration: '15s' }, display: '15s' },\n { value: { pastDuration: '30s' }, display: '30s' },\n { value: { pastDuration: '60s' }, display: '1m' },\n];\n\nconst DEFAULT_HEIGHT = '34px';\n\ninterface TimeRangeControlsProps {\n // The controls look best at heights >= 28 pixels\n heightPx?: number;\n showTimeRangeSelector?: boolean;\n showRefreshButton?: boolean;\n showRefreshInterval?: boolean;\n showCustomTimeRange?: boolean;\n timePresets?: TimeOption[];\n}\n\nexport function TimeRangeControls({\n heightPx,\n showTimeRangeSelector = true,\n showRefreshButton = true,\n showRefreshInterval = true,\n showCustomTimeRange,\n timePresets,\n}: TimeRangeControlsProps): ReactElement {\n const { timeRange, setTimeRange, refresh, refreshInterval, setRefreshInterval } = useTimeRange();\n\n const showCustomTimeRangeValue = useShowCustomTimeRangeSetting(showCustomTimeRange);\n const timePresetsValue = useTimeRangeOptionsSetting(timePresets);\n\n // Convert height to a string, then use the string for styling\n const height = heightPx === undefined ? DEFAULT_HEIGHT : `${heightPx}px`;\n\n // add time preset if one does not match duration given in time range\n if (\n 'pastDuration' in timeRange &&\n !timePresetsValue.some((option) => option.value.pastDuration === timeRange['pastDuration'])\n ) {\n timePresetsValue.push(buildRelativeTimeOption(timeRange['pastDuration']));\n }\n\n // set the new refresh interval both in the dashboard context & as query param\n const handleRefreshIntervalChange = useCallback(\n (duration: DurationString) => {\n setRefreshInterval(duration);\n },\n [setRefreshInterval]\n );\n\n return (\n <Stack direction=\"row\" spacing={1}>\n {showTimeRangeSelector && (\n <TimeRangeSelector\n timeOptions={timePresetsValue}\n value={timeRange}\n onChange={setTimeRange}\n height={height}\n showCustomTimeRange={showCustomTimeRangeValue}\n />\n )}\n {showRefreshButton && (\n <InfoTooltip description={TOOLTIP_TEXT.refresh}>\n <ToolbarIconButton aria-label={TOOLTIP_TEXT.refresh} onClick={refresh} sx={{ height }}>\n <RefreshIcon />\n </ToolbarIconButton>\n </InfoTooltip>\n )}\n {showRefreshInterval && (\n <InfoTooltip description={TOOLTIP_TEXT.refreshInterval}>\n <RefreshIntervalPicker\n timeOptions={DEFAULT_REFRESH_INTERVAL_OPTIONS}\n value={refreshInterval}\n onChange={handleRefreshIntervalChange}\n height={height}\n />\n </InfoTooltip>\n )}\n </Stack>\n );\n}\n"],"names":["RefreshIcon","Stack","RefreshIntervalPicker","InfoTooltip","ToolbarIconButton","TimeRangeSelector","buildRelativeTimeOption","useCallback","TOOLTIP_TEXT","useTimeRange","useShowCustomTimeRangeSetting","useTimeRangeOptionsSetting","DEFAULT_REFRESH_INTERVAL_OPTIONS","value","pastDuration","display","DEFAULT_HEIGHT","TimeRangeControls","heightPx","showTimeRangeSelector","showRefreshButton","showRefreshInterval","showCustomTimeRange","timePresets","timeRange","setTimeRange","refresh","refreshInterval","setRefreshInterval","showCustomTimeRangeValue","timePresetsValue","height","undefined","some","option","push","handleRefreshIntervalChange","duration","direction","spacing","timeOptions","onChange","description","aria-label","onClick","sx"],"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,OAAOA,iBAAiB,0BAA0B;AAClD,SAASC,KAAK,QAAQ,gBAAgB;AACtC,SACEC,qBAAqB,EACrBC,WAAW,EAEXC,iBAAiB,EACjBC,iBAAiB,EACjBC,uBAAuB,QAClB,yBAAyB;AAEhC,SAAuBC,WAAW,QAAQ,QAAQ;AAClD,SAASC,YAAY,QAAQ,kBAAkB;AAC/C,SAASC,YAAY,EAAEC,6BAA6B,EAAEC,0BAA0B,QAAQ,gBAAgB;AAExG,OAAO,MAAMC,mCAAiD;IAC5D;QAAEC,OAAO;YAAEC,cAAc;QAAK;QAAGC,SAAS;IAAM;IAChD;QAAEF,OAAO;YAAEC,cAAc;QAAK;QAAGC,SAAS;IAAK;IAC/C;QAAEF,OAAO;YAAEC,cAAc;QAAM;QAAGC,SAAS;IAAM;IACjD;QAAEF,OAAO;YAAEC,cAAc;QAAM;QAAGC,SAAS;IAAM;IACjD;QAAEF,OAAO;YAAEC,cAAc;QAAM;QAAGC,SAAS;IAAM;IACjD;QAAEF,OAAO;YAAEC,cAAc;QAAM;QAAGC,SAA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