@perses-dev/plugin-system 0.0.0-snapshot-color-palette-gen-test-bc1b508 → 0.0.0-snapshot-tooltip-highlight-c995fc8
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/PanelSpecEditor/PanelSpecEditor.js +75 -0
- package/dist/cjs/components/PanelSpecEditor/index.js +28 -0
- package/dist/cjs/components/PluginEditor/PluginEditor.js +2 -2
- package/dist/cjs/components/PluginEditor/plugin-editor-api.js +27 -6
- package/dist/cjs/components/{PluginKindSelect.js → PluginKindSelect/PluginKindSelect.js} +1 -1
- package/dist/cjs/components/PluginKindSelect/index.js +28 -0
- package/dist/cjs/components/{PluginSpecEditor.js → PluginSpecEditor/PluginSpecEditor.js} +2 -30
- package/dist/cjs/components/PluginSpecEditor/index.js +28 -0
- package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +142 -0
- package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +94 -0
- package/dist/cjs/components/TimeSeriesQueryEditor/index.js +28 -0
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +88 -0
- package/dist/cjs/runtime/DataQueriesProvider/index.js +29 -0
- package/dist/cjs/runtime/DataQueriesProvider/model.js +16 -0
- package/dist/cjs/runtime/index.js +1 -0
- package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +39 -0
- package/dist/cjs/stories/shared-utils/decorators/WithDatasourceStore.js +83 -0
- package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +94 -0
- package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +38 -0
- package/dist/cjs/stories/shared-utils/decorators/index.js +31 -0
- package/dist/cjs/stories/shared-utils/index.js +28 -0
- package/dist/cjs/test/render.js +4 -1
- package/dist/cjs/test/test-plugins/bert/index.js +27 -20
- package/dist/cjs/test/test-plugins/ernie/index.js +37 -4
- package/dist/cjs/test-utils/mock-plugin-registry.js +4 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +10 -0
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -0
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +69 -0
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -0
- package/dist/components/PanelSpecEditor/index.d.ts +2 -0
- package/dist/components/PanelSpecEditor/index.d.ts.map +1 -0
- package/dist/components/PanelSpecEditor/index.js +15 -0
- package/dist/components/PanelSpecEditor/index.js.map +1 -0
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +2 -2
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +4 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +27 -6
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/{PluginKindSelect.d.ts → PluginKindSelect/PluginKindSelect.d.ts} +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -0
- package/dist/components/{PluginKindSelect.js → PluginKindSelect/PluginKindSelect.js} +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -0
- package/dist/components/PluginKindSelect/index.d.ts +2 -0
- package/dist/components/PluginKindSelect/index.d.ts.map +1 -0
- package/dist/components/PluginKindSelect/index.js +15 -0
- package/dist/components/PluginKindSelect/index.js.map +1 -0
- package/dist/components/PluginRegistry/PluginRegistry.d.ts +2 -2
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/{PluginSpecEditor.d.ts → PluginSpecEditor/PluginSpecEditor.d.ts} +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -0
- package/dist/components/{PluginSpecEditor.js → PluginSpecEditor/PluginSpecEditor.js} +3 -31
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -0
- package/dist/components/PluginSpecEditor/index.d.ts +2 -0
- package/dist/components/PluginSpecEditor/index.d.ts.map +1 -0
- package/dist/components/PluginSpecEditor/index.js +15 -0
- package/dist/components/PluginSpecEditor/index.js.map +1 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts +8 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +1 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +131 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +1 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts +13 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts.map +1 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +83 -0
- package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js.map +1 -0
- package/dist/components/TimeSeriesQueryEditor/index.d.ts +2 -0
- package/dist/components/TimeSeriesQueryEditor/index.d.ts.map +1 -0
- package/dist/components/TimeSeriesQueryEditor/index.js +15 -0
- package/dist/components/TimeSeriesQueryEditor/index.js.map +1 -0
- 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/model/panels.d.ts +6 -5
- package/dist/model/panels.d.ts.map +1 -1
- package/dist/model/panels.js.map +1 -1
- package/dist/model/plugin-base.d.ts +7 -0
- package/dist/model/plugin-base.d.ts.map +1 -1
- package/dist/model/plugin-base.js.map +1 -1
- package/dist/model/plugins.d.ts +3 -1
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +8 -0
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -0
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +74 -0
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -0
- package/dist/runtime/DataQueriesProvider/index.d.ts +3 -0
- package/dist/runtime/DataQueriesProvider/index.d.ts.map +1 -0
- package/dist/runtime/DataQueriesProvider/index.js +16 -0
- package/dist/runtime/DataQueriesProvider/index.js.map +1 -0
- package/dist/runtime/DataQueriesProvider/model.d.ts +27 -0
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -0
- package/dist/runtime/DataQueriesProvider/model.js +15 -0
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +1 -0
- package/dist/runtime/index.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +1 -1
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts +8 -0
- package/dist/stories/shared-utils/decorators/WithDataQueries.d.ts.map +1 -0
- package/dist/stories/shared-utils/decorators/WithDataQueries.js +33 -0
- package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -0
- package/dist/stories/shared-utils/decorators/WithDatasourceStore.d.ts +8 -0
- package/dist/stories/shared-utils/decorators/WithDatasourceStore.d.ts.map +1 -0
- package/dist/stories/shared-utils/decorators/WithDatasourceStore.js +77 -0
- package/dist/stories/shared-utils/decorators/WithDatasourceStore.js.map +1 -0
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts +4 -0
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.d.ts.map +1 -0
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js +49 -0
- package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -0
- package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts +8 -0
- package/dist/stories/shared-utils/decorators/WithTimeRange.d.ts.map +1 -0
- package/dist/stories/shared-utils/decorators/WithTimeRange.js +32 -0
- package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -0
- package/dist/stories/shared-utils/decorators/index.d.ts +5 -0
- package/dist/stories/shared-utils/decorators/index.d.ts.map +1 -0
- package/dist/stories/shared-utils/decorators/index.js +18 -0
- package/dist/stories/shared-utils/decorators/index.js.map +1 -0
- package/dist/stories/shared-utils/index.d.ts +2 -0
- package/dist/stories/shared-utils/index.d.ts.map +1 -0
- package/dist/stories/shared-utils/index.js +15 -0
- package/dist/stories/shared-utils/index.js.map +1 -0
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +4 -1
- package/dist/test/render.js.map +1 -1
- package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
- package/dist/test/test-plugins/bert/index.js +27 -20
- package/dist/test/test-plugins/bert/index.js.map +1 -1
- package/dist/test/test-plugins/ernie/index.d.ts +4 -1
- package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
- package/dist/test/test-plugins/ernie/index.js +28 -1
- package/dist/test/test-plugins/ernie/index.js.map +1 -1
- package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -1
- package/dist/test-utils/mock-plugin-registry.js +4 -1
- package/dist/test-utils/mock-plugin-registry.js.map +1 -1
- package/package.json +6 -3
- package/dist/cjs/components/TimeSeriesQueryEditor.js +0 -42
- package/dist/components/PluginKindSelect.d.ts.map +0 -1
- package/dist/components/PluginKindSelect.js.map +0 -1
- package/dist/components/PluginSpecEditor.d.ts.map +0 -1
- package/dist/components/PluginSpecEditor.js.map +0 -1
- package/dist/components/TimeSeriesQueryEditor.d.ts +0 -14
- package/dist/components/TimeSeriesQueryEditor.d.ts.map +0 -1
- package/dist/components/TimeSeriesQueryEditor.js +0 -38
- package/dist/components/TimeSeriesQueryEditor.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,
|
|
1
|
+
{"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,iBAAiB,EAAmB,MAAM,qBAAqB,CAAC;AAEzE;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAqBpD"}
|
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';
|
|
15
|
-
import { PluginKindSelect } from '../PluginKindSelect';
|
|
16
|
-
import { PluginSpecEditor } from '../PluginSpecEditor';
|
|
15
|
+
import { PluginKindSelect } from '../PluginKindSelect/PluginKindSelect';
|
|
16
|
+
import { PluginSpecEditor } from '../PluginSpecEditor/PluginSpecEditor';
|
|
17
17
|
import { usePluginEditor } from './plugin-editor-api';
|
|
18
18
|
/**
|
|
19
19
|
* A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';\nimport { PluginKindSelect } from '../PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor';\nimport { PluginEditorProps, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\nexport function PluginEditor(props: PluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { value, pluginType, pluginKindLabel, onChange: _, ...others } = props;\n const { pendingKind, isLoading, error, onKindChange, onSpecChange } = usePluginEditor(props);\n return (\n <Box {...others}>\n <FormControl margin=\"dense\" fullWidth={false} disabled={isLoading} error={error !== null} sx={{ mb: 1 }}>\n {/* TODO: How to ensure ids are unique? */}\n <InputLabel id=\"plugin-kind-label\">{pluginKindLabel}</InputLabel>\n <PluginKindSelect\n labelId=\"plugin-kind-label\"\n label={pluginKindLabel}\n pluginType={pluginType}\n value={pendingKind !== '' ? pendingKind : value.kind}\n onChange={onKindChange}\n />\n <FormHelperText>{error?.message ?? ''}</FormHelperText>\n </FormControl>\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, FormControl, FormHelperText, InputLabel } from '@mui/material';\nimport { PluginKindSelect } from '../PluginKindSelect/PluginKindSelect';\nimport { PluginSpecEditor } from '../PluginSpecEditor/PluginSpecEditor';\nimport { PluginEditorProps, usePluginEditor } from './plugin-editor-api';\n\n/**\n * A combination `PluginKindSelect` and `PluginSpecEditor` component. This is meant for editing the `plugin` property\n * that's common in our JSON specs where a user selects a plugin `kind` and then edits the `spec` via that plugin's\n * editor component. It takes care of transitioning from one plugin kind to another \"all at once\" so that when the\n * plugin's kind changes, the spec is also changed at the same time so those options editor components don't see a\n * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the\n * `usePluginEditor` hook that powers this component.\n */\nexport function PluginEditor(props: PluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const { value, pluginType, pluginKindLabel, onChange: _, ...others } = props;\n const { pendingKind, isLoading, error, onKindChange, onSpecChange } = usePluginEditor(props);\n return (\n <Box {...others}>\n <FormControl margin=\"dense\" fullWidth={false} disabled={isLoading} error={error !== null} sx={{ mb: 1 }}>\n {/* TODO: How to ensure ids are unique? */}\n <InputLabel id=\"plugin-kind-label\">{pluginKindLabel}</InputLabel>\n <PluginKindSelect\n labelId=\"plugin-kind-label\"\n label={pluginKindLabel}\n pluginType={pluginType}\n value={pendingKind !== '' ? pendingKind : value.kind}\n onChange={onKindChange}\n />\n <FormHelperText>{error?.message ?? ''}</FormHelperText>\n </FormControl>\n <PluginSpecEditor pluginType={pluginType} pluginKind={value.kind} value={value.spec} onChange={onSpecChange} />\n </Box>\n );\n}\n"],"names":["Box","FormControl","FormHelperText","InputLabel","PluginKindSelect","PluginSpecEditor","usePluginEditor","PluginEditor","props","value","pluginType","pluginKindLabel","onChange","_","others","pendingKind","isLoading","error","onKindChange","onSpecChange","margin","fullWidth","disabled","sx","mb","id","labelId","label","kind","message","pluginKind","spec"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE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kCAAEe,CAAAA,GAAc,GAAdA,KAAK,aAALA,KAAK,WAAS,GAAdA,KAAAA,CAAc,GAAdA,KAAK,CAAEY,OAAO,cAAdZ,GAAc,cAAdA,GAAc,GAAI,EAAE;sBAAkB;;cAC3C;0BACd,KAACZ,gBAAgB;gBAACK,UAAU,EAAEA,UAAU;gBAAEoB,UAAU,EAAErB,KAAK,CAACmB,IAAI;gBAAEnB,KAAK,EAAEA,KAAK,CAACsB,IAAI;gBAAEnB,QAAQ,EAAEO,YAAY;cAAI;;MAC3G,CACN;AACJ,CAAC"}
|
|
@@ -12,7 +12,9 @@ export interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {
|
|
|
12
12
|
/**
|
|
13
13
|
* Props needed by the usePluginEditor hook.
|
|
14
14
|
*/
|
|
15
|
-
export declare type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'
|
|
15
|
+
export declare type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'> & {
|
|
16
|
+
onHideQueryEditorChange?: (isHidden: boolean) => void;
|
|
17
|
+
};
|
|
16
18
|
/**
|
|
17
19
|
* Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide
|
|
18
20
|
* a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also
|
|
@@ -25,6 +27,7 @@ export declare function usePluginEditor(props: UsePluginEditorProps): {
|
|
|
25
27
|
error: Error | null;
|
|
26
28
|
onKindChange: (event: import("@mui/material").SelectChangeEvent<string>, child: import("react").ReactNode) => void;
|
|
27
29
|
onSpecChange: (next: UnknownSpec) => void;
|
|
30
|
+
rememberCurrentSpecState: () => void;
|
|
28
31
|
};
|
|
29
32
|
export {};
|
|
30
33
|
//# sourceMappingURL=plugin-editor-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAY,MAAM,kBAAkB,CAAC;AAGrE,OAAO,
|
|
1
|
+
{"version":3,"file":"plugin-editor-api.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"names":[],"mappings":";AAaA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAY,MAAM,kBAAkB,CAAC;AAGrE,OAAO,EAAe,UAAU,EAAE,MAAM,aAAa,CAAC;AAOtD,aAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAEzD,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,QAAQ,EAAE,eAAe,CAAC;IACxE,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAC/B,QAAQ,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;CACnD;AAKD;;GAEG;AACH,oBAAY,oBAAoB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,OAAO,GAAG,UAAU,CAAC,GAAG;IAChG,uBAAuB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CACvD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB;;;;;;;EAqG1D"}
|
|
@@ -20,9 +20,11 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
|
|
|
20
20
|
* remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin
|
|
21
21
|
* kind back.
|
|
22
22
|
*/ export function usePluginEditor(props) {
|
|
23
|
-
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
24
|
+
const { pluginType , value , onHideQueryEditorChange =()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
|
|
24
25
|
// Keep a stable reference so we don't run the effect below when we don't need to
|
|
25
26
|
const onChange = useEvent(props.onChange);
|
|
27
|
+
const onHideQuery = useEvent(onHideQueryEditorChange);
|
|
26
28
|
// The previous spec state for PluginType and kind and a helper function for remembering current values
|
|
27
29
|
const prevSpecState = useRef({
|
|
28
30
|
[pluginType]: {
|
|
@@ -37,6 +39,10 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
|
|
|
37
39
|
}
|
|
38
40
|
byPluginType[value.kind] = value.spec;
|
|
39
41
|
});
|
|
42
|
+
// The previous hide query state for each panel kind
|
|
43
|
+
const hideQueryState = useRef({
|
|
44
|
+
[value.kind]: false
|
|
45
|
+
});
|
|
40
46
|
const { defaultPluginKinds } = usePluginRegistry();
|
|
41
47
|
const defaultPluginKind = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[pluginType];
|
|
42
48
|
const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';
|
|
@@ -55,12 +61,23 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
|
|
|
55
61
|
kind: pendingKind,
|
|
56
62
|
spec: plugin.createInitialOptions()
|
|
57
63
|
});
|
|
64
|
+
if (pluginType === 'Panel') {
|
|
65
|
+
const panelPlugin = plugin;
|
|
66
|
+
hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;
|
|
67
|
+
if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {
|
|
68
|
+
onHideQuery(!!panelPlugin.hideQueryEditor);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
setPendingKind('');
|
|
59
72
|
}, [
|
|
60
73
|
pendingKind,
|
|
61
74
|
plugin,
|
|
62
75
|
rememberCurrentSpecState,
|
|
63
|
-
onChange
|
|
76
|
+
onChange,
|
|
77
|
+
onHideQuery,
|
|
78
|
+
hideQueryState,
|
|
79
|
+
pluginType,
|
|
80
|
+
value.kind
|
|
64
81
|
]);
|
|
65
82
|
/**
|
|
66
83
|
* When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we
|
|
@@ -76,10 +93,13 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
|
|
|
76
93
|
kind: nextKind,
|
|
77
94
|
spec: previousState
|
|
78
95
|
});
|
|
79
|
-
|
|
96
|
+
} else {
|
|
97
|
+
// Otherwise, kick off the async loading process
|
|
98
|
+
setPendingKind(nextKind);
|
|
99
|
+
}
|
|
100
|
+
if (pluginType === 'Panel' && hideQueryState.current[nextKind] !== undefined && hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]) {
|
|
101
|
+
onHideQuery(!!hideQueryState.current[nextKind]);
|
|
80
102
|
}
|
|
81
|
-
// Otherwise, kick off the async loading process
|
|
82
|
-
setPendingKind(nextKind);
|
|
83
103
|
};
|
|
84
104
|
/**
|
|
85
105
|
* Spec changes are independent and always just set the spec state.
|
|
@@ -93,7 +113,8 @@ import { usePlugin, usePluginRegistry } from '../../runtime';
|
|
|
93
113
|
isLoading: isFetching,
|
|
94
114
|
error,
|
|
95
115
|
onKindChange,
|
|
96
|
-
onSpecChange
|
|
116
|
+
onSpecChange,
|
|
117
|
+
rememberCurrentSpecState
|
|
97
118
|
};
|
|
98
119
|
}
|
|
99
120
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BoxProps } from '@mui/material';\nimport { Definition, UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useState, useRef, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { PluginType } from '../../model';\nimport { PluginKindSelectProps } from '../PluginKindSelect';\nimport { PluginSpecEditorProps } from '../PluginSpecEditor';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\nexport interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n pluginType: PluginType;\n pluginKindLabel: string;\n value: Definition<UnknownSpec>;\n onChange: (next: Definition<UnknownSpec>) => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'>;\n\n/**\n * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide\n * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also\n * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin\n * kind back.\n */\nexport function usePluginEditor(props: UsePluginEditorProps) {\n const { pluginType, value } = props;\n\n // Keep a stable reference so we don't run the effect below when we don't need to\n const onChange = useEvent(props.onChange);\n\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [pluginType]: { [value.kind]: value.spec },\n });\n\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[pluginType];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[pluginType] = byPluginType;\n }\n byPluginType[value.kind] = value.spec;\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginKind = defaultPluginKinds?.[pluginType];\n const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';\n\n // When kind changes and we haven't loaded that plugin before, we will need to enter a \"pending\" state so that we\n // can generate proper initial spec values that match the new plugin kind\n const [pendingKind, setPendingKind] = useState(initPendingKind);\n const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (pendingKind === '') return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n kind: pendingKind,\n spec: plugin.createInitialOptions(),\n });\n setPendingKind('');\n }, [pendingKind, plugin, rememberCurrentSpecState, onChange]);\n\n /**\n * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we\n * make the switch.\n */\n const onKindChange: PluginKindSelectProps['onChange'] = (e) => {\n const nextKind = e.target.value;\n\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[pluginType]?.[nextKind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n kind: nextKind,\n spec: previousState,\n });\n return;\n }\n\n // Otherwise, kick off the async loading process\n setPendingKind(nextKind);\n };\n\n /**\n * Spec changes are independent and always just set the spec state.\n */\n const onSpecChange: PluginSpecEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.spec = next;\n })\n );\n };\n\n return { pendingKind, isLoading: isFetching, error, onKindChange, onSpecChange };\n}\n"],"names":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","usePluginEditor","props","pluginType","value","onChange","prevSpecState","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","defaultPluginKinds","defaultPluginKind","initPendingKind","pendingKind","setPendingKind","data","plugin","isFetching","error","createInitialOptions","onKindChange","e","nextKind","target","previousState","onSpecChange","next","draft","isLoading"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAAkCA,QAAQ,Q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QAChDV,cAAc,CAACQ,QAAQ,CAAC,CAAC;IAC3B,CAAC,AAAC;IAEF;;GAEC,GACD,MAAMG,YAAY,GAAsC,CAACC,IAAI,GAAK;QAChExB,QAAQ,CACNP,OAAO,CAACM,KAAK,EAAE,CAAC0B,KAAK,GAAK;YACxBA,KAAK,CAACtB,IAAI,GAAGqB,IAAI,CAAC;QACpB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEb,WAAW;QAAEe,SAAS,EAAEX,UAAU;QAAEC,KAAK;QAAEE,YAAY;QAAEK,YAAY;KAAE,CAAC;AACnF,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginEditor/plugin-editor-api.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { BoxProps } from '@mui/material';\nimport { Definition, UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useState, useRef, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { PanelPlugin, PluginType } from '../../model';\nimport { PluginKindSelectProps } from '../PluginKindSelect/PluginKindSelect';\nimport { PluginSpecEditorProps } from '../PluginSpecEditor/PluginSpecEditor';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\nexport interface PluginEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n pluginType: PluginType;\n pluginKindLabel: string;\n value: Definition<UnknownSpec>;\n onChange: (next: Definition<UnknownSpec>) => void;\n}\n\ntype PreviousSpecState = Record<string, Record<string, UnknownSpec>>;\ntype HideQueryEditorState = Record<string, boolean>;\n\n/**\n * Props needed by the usePluginEditor hook.\n */\nexport type UsePluginEditorProps = Pick<PluginEditorProps, 'pluginType' | 'value' | 'onChange'> & {\n onHideQueryEditorChange?: (isHidden: boolean) => void;\n};\n\n/**\n * Returns the state/handlers that power the `PluginEditor` component. Useful for custom components that want to provide\n * a different UI, but want the same behavior of changing `kind` and `spec` together on plugin kind changes. Also\n * remembers previous `spec` values that it's seen, allowing and restores those values if a user switches the plugin\n * kind back.\n */\nexport function usePluginEditor(props: UsePluginEditorProps) {\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const { pluginType, value, onHideQueryEditorChange = () => {} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function\n\n // Keep a stable reference so we don't run the effect below when we don't need to\n const onChange = useEvent(props.onChange);\n const onHideQuery = useEvent(onHideQueryEditorChange);\n\n // The previous spec state for PluginType and kind and a helper function for remembering current values\n const prevSpecState = useRef<PreviousSpecState>({\n [pluginType]: { [value.kind]: value.spec },\n });\n const rememberCurrentSpecState = useEvent(() => {\n let byPluginType = prevSpecState.current[pluginType];\n if (byPluginType === undefined) {\n byPluginType = {};\n prevSpecState.current[pluginType] = byPluginType;\n }\n byPluginType[value.kind] = value.spec;\n });\n\n // The previous hide query state for each panel kind\n const hideQueryState = useRef<HideQueryEditorState>({\n [value.kind]: false,\n });\n\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultPluginKind = defaultPluginKinds?.[pluginType];\n const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';\n\n // When kind changes and we haven't loaded that plugin before, we will need to enter a \"pending\" state so that we\n // can generate proper initial spec values that match the new plugin kind\n const [pendingKind, setPendingKind] = useState(initPendingKind);\n const { data: plugin, isFetching, error } = usePlugin(pluginType, pendingKind);\n\n useEffect(() => {\n // Nothing to do if no new plugin kind is pending\n if (pendingKind === '') return;\n\n // Can't get spec value until we have a plugin\n if (plugin === undefined) return;\n\n // Fire an onChange to change to the pending kind with initial values from the plugin\n rememberCurrentSpecState();\n onChange({\n kind: pendingKind,\n spec: plugin.createInitialOptions(),\n });\n\n if (pluginType === 'Panel') {\n const panelPlugin = plugin as PanelPlugin;\n hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;\n if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {\n onHideQuery(!!panelPlugin.hideQueryEditor);\n }\n }\n\n setPendingKind('');\n }, [pendingKind, plugin, rememberCurrentSpecState, onChange, onHideQuery, hideQueryState, pluginType, value.kind]);\n\n /**\n * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we\n * make the switch.\n */\n const onKindChange: PluginKindSelectProps['onChange'] = (e) => {\n const nextKind = e.target.value;\n\n // If we already have state for this plugin type/kind from a previous selection, just use it\n const previousState = prevSpecState.current[pluginType]?.[nextKind];\n if (previousState !== undefined) {\n rememberCurrentSpecState();\n onChange({\n kind: nextKind,\n spec: previousState,\n });\n } else {\n // Otherwise, kick off the async loading process\n setPendingKind(nextKind);\n }\n\n if (\n pluginType === 'Panel' &&\n hideQueryState.current[nextKind] !== undefined &&\n hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]\n ) {\n onHideQuery(!!hideQueryState.current[nextKind]);\n }\n };\n\n /**\n * Spec changes are independent and always just set the spec state.\n */\n const onSpecChange: PluginSpecEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.spec = next;\n })\n );\n };\n\n return { pendingKind, isLoading: isFetching, error, onKindChange, onSpecChange, rememberCurrentSpecState };\n}\n"],"names":["useEvent","useState","useRef","useEffect","produce","usePlugin","usePluginRegistry","usePluginEditor","props","pluginType","value","onHideQueryEditorChange","onChange","onHideQuery","prevSpecState","kind","spec","rememberCurrentSpecState","byPluginType","current","undefined","hideQueryState","defaultPluginKinds","defaultPluginKind","initPendingKind","pendingKind","setPendingKind","data","plugin","isFetching","error","createInitialOptions","panelPlugin","hideQueryEditor","onKindChange","e","nextKind","target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Q,CAAC,CAAC,CAAC;QAClD,CAAC;IACH,CAAC,AAAC;IAEF;;GAEC,GACD,MAAMG,YAAY,GAAsC,CAACC,IAAI,GAAK;QAChE5B,QAAQ,CACNR,OAAO,CAACM,KAAK,EAAE,CAAC+B,KAAK,GAAK;YACxBA,KAAK,CAACzB,IAAI,GAAGwB,IAAI,CAAC;QACpB,CAAC,CAAC,CACH,CAAC;IACJ,CAAC,AAAC;IAEF,OAAO;QAAEf,WAAW;QAAEiB,SAAS,EAAEb,UAAU;QAAEC,KAAK;QAAEI,YAAY;QAAEK,YAAY;QAAEtB,wBAAwB;KAAE,CAAC;AAC7G,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { SelectProps } from '@mui/material';
|
|
3
|
-
import { PluginType } from '
|
|
3
|
+
import { PluginType } from '../../model';
|
|
4
4
|
export interface PluginKindSelectProps extends Omit<SelectProps<string>, 'children'> {
|
|
5
5
|
pluginType: PluginType;
|
|
6
6
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginKindSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAU,WAAW,EAAY,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC;IAClF,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,eAiB5D"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { Select, MenuItem } from '@mui/material';
|
|
15
|
-
import { useListPluginMetadata } from '
|
|
15
|
+
import { useListPluginMetadata } from '../../runtime';
|
|
16
16
|
/**
|
|
17
17
|
* Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of a specific
|
|
18
18
|
* plugin type. (e.g. "Show a list of all the Panel plugins" or "Show a list of all the Variable plugins").
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginKindSelect/PluginKindSelect.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Select, SelectProps, MenuItem } from '@mui/material';\nimport { PluginType } from '../../model';\nimport { useListPluginMetadata } from '../../runtime';\n\nexport interface PluginKindSelectProps extends Omit<SelectProps<string>, 'children'> {\n pluginType: PluginType;\n}\n\n/**\n * Displays a MUI Select input for selecting a plugin's kind from a list of all the available plugins of a specific\n * plugin type. (e.g. \"Show a list of all the Panel plugins\" or \"Show a list of all the Variable plugins\").\n */\nexport function PluginKindSelect(props: PluginKindSelectProps) {\n const { pluginType, value: propValue, ...others } = props;\n const { data, isLoading } = useListPluginMetadata(pluginType);\n\n // Pass an empty value while options are still loading so MUI doesn't complain about us using an \"out of range\" value\n const value = propValue !== '' && isLoading ? '' : propValue;\n\n // TODO: Does this need a loading indicator of some kind?\n return (\n <Select sx={{ minWidth: 120 }} {...others} value={value}>\n {data?.map((metadata) => (\n <MenuItem key={metadata.kind} value={metadata.kind}>\n {metadata.display.name}\n </MenuItem>\n ))}\n </Select>\n );\n}\n"],"names":["Select","MenuItem","useListPluginMetadata","PluginKindSelect","props","pluginType","value","propValue","others","data","isLoading","sx","minWidth","map","metadata","kind","display","name"],"mappings":"AAAA,o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023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './PluginKindSelect';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginKindSelect/index.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PluginKindSelect';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,oBAAoB,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { PluginLoader, DefaultPluginKinds } from '../../model';
|
|
3
3
|
export interface PluginRegistryProps {
|
|
4
|
-
children?: React.ReactNode;
|
|
5
4
|
pluginLoader: PluginLoader;
|
|
6
|
-
defaultPluginKinds
|
|
5
|
+
defaultPluginKinds: DefaultPluginKinds;
|
|
6
|
+
children?: React.ReactNode;
|
|
7
7
|
}
|
|
8
8
|
/**
|
|
9
9
|
* PluginRegistryContext provider that keeps track of all available plugins and provides an API for getting them or
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAKL,YAAY,EACZ,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,mBAAmB;IAClC,
|
|
1
|
+
{"version":3,"file":"PluginRegistry.d.ts","sourceRoot":"","sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"names":[],"mappings":";AAeA,OAAO,EAKL,YAAY,EACZ,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAIrB,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,YAAY,CAAC;IAC3B,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,eAoExD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useRef, useCallback, useMemo } from 'react';\nimport {\n PluginModuleResource,\n PluginType,\n PluginImplementation,\n Plugin,\n PluginLoader,\n DefaultPluginKinds,\n} from '../../model';\nimport { PluginRegistryContext } from '../../runtime';\nimport { usePluginIndexes, getTypeAndKindKey } from './plugin-indexes';\n\nexport interface PluginRegistryProps {\n
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginRegistry/PluginRegistry.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { UnknownSpec, useEvent } from '@perses-dev/core';\nimport { useRef, useCallback, useMemo } from 'react';\nimport {\n PluginModuleResource,\n PluginType,\n PluginImplementation,\n Plugin,\n PluginLoader,\n DefaultPluginKinds,\n} from '../../model';\nimport { PluginRegistryContext } from '../../runtime';\nimport { usePluginIndexes, getTypeAndKindKey } from './plugin-indexes';\n\nexport interface PluginRegistryProps {\n pluginLoader: PluginLoader;\n defaultPluginKinds: DefaultPluginKinds;\n children?: React.ReactNode;\n}\n\n/**\n * PluginRegistryContext provider that keeps track of all available plugins and provides an API for getting them or\n * querying the metadata about them.\n */\nexport function PluginRegistry(props: PluginRegistryProps) {\n const {\n pluginLoader: { getInstalledPlugins, importPluginModule },\n children,\n defaultPluginKinds,\n } = props;\n\n const getPluginIndexes = usePluginIndexes(getInstalledPlugins);\n\n // De-dupe calls to import plugin modules\n const importCache = useRef(new Map<PluginModuleResource, Promise<unknown>>());\n\n // Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the\n // callback below\n const loadPluginModule = useEvent((resource: PluginModuleResource) => {\n let request = importCache.current.get(resource);\n if (request === undefined) {\n request = importPluginModule(resource);\n importCache.current.set(resource, request);\n\n // Remove failed requests from the cache so they can potentially be retried\n request.catch(() => importCache.current.delete(resource));\n }\n return request;\n });\n\n const getPlugin = useCallback(\n async <T extends PluginType>(pluginType: T, kind: string): Promise<PluginImplementation<T>> => {\n // Get the indexes of the installed plugins\n const pluginIndexes = await getPluginIndexes();\n\n // Figure out what module the plugin is in by looking in the index\n const typeAndKindKey = getTypeAndKindKey(pluginType, kind);\n const resource = pluginIndexes.pluginResourcesByTypeAndKind.get(typeAndKindKey);\n if (resource === undefined) {\n throw new Error(`A ${pluginType} plugin for kind '${kind}' is not installed`);\n }\n\n // Treat the plugin module as a bunch of named exports that have plugins\n const pluginModule = (await loadPluginModule(resource)) as Record<string, Plugin<UnknownSpec>>;\n\n // We currently assume that plugin modules will have named exports that match the kinds they handle\n const plugin = pluginModule[kind];\n if (plugin === undefined) {\n throw new Error(\n `The ${pluginType} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`\n );\n }\n\n return plugin as PluginImplementation<T>;\n },\n [getPluginIndexes, loadPluginModule]\n );\n\n const listPluginMetadata = useCallback(\n async (pluginType: PluginType) => {\n const pluginIndexes = await getPluginIndexes();\n return pluginIndexes.pluginMetadataByType.get(pluginType) ?? [];\n },\n [getPluginIndexes]\n );\n\n // Create the registry's context value and render\n const context = useMemo(\n () => ({ getPlugin, listPluginMetadata, defaultPluginKinds }),\n [getPlugin, listPluginMetadata, defaultPluginKinds]\n );\n return <PluginRegistryContext.Provider value={context}>{children}</PluginRegistryContext.Provider>;\n}\n"],"names":["useEvent","useRef","useCallback","useMemo","PluginRegistryContext","usePluginIndexes","getTypeAndKindKey","PluginRegistry","props","pluginLoader","getInstalledPlugins","importPluginModule","children","defaultPluginKinds","getPluginIndexes","importCache","Map","loadPluginModule","resource","request","current","get","undefined","set","catch","delete","getPlugin","pluginType","kind","pluginIndexes","typeAndKindKey","pluginResourcesByTypeAndKind","Error","pluginModule","plugin","metadata","name","listPluginMetadata","pluginMetadataByType","context","Provider","value"],"mappings":"AAAA,oCAAoC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,GAAkD,GAAI,EAAE,CAAC;IAClE,CAAC,EACD;QAACf,gBAAgB;KAAC,CACnB,AAAC;IAEF,iDAAiD;IACjD,MAAMyB,OAAO,GAAGpC,OAAO,CACrB,IAAO,CAAA;YAAEuB,SAAS;YAAEW,kBAAkB;YAAExB,kBAAkB;SAAE,CAAA,AAAC,EAC7D;QAACa,SAAS;QAAEW,kBAAkB;QAAExB,kBAAkB;KAAC,CACpD,AAAC;IACF,qBAAO,KAACT,qBAAqB,CAACoC,QAAQ;QAACC,KAAK,EAAEF,OAAO;kBAAG3B,QAAQ;MAAkC,CAAC;AACrG,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { UnknownSpec } from '@perses-dev/core';
|
|
3
|
-
import { OptionsEditorProps, PluginType } from '
|
|
3
|
+
import { OptionsEditorProps, PluginType } from '../../model';
|
|
4
4
|
export interface PluginSpecEditorProps extends OptionsEditorProps<UnknownSpec> {
|
|
5
5
|
pluginType: PluginType;
|
|
6
6
|
pluginKind: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginSpecEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginSpecEditor/PluginSpecEditor.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAG7D,MAAM,WAAW,qBAAsB,SAAQ,kBAAkB,CAAC,WAAW,CAAC;IAC5E,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,sBA4B5D"}
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { ErrorAlert
|
|
15
|
-
import { usePlugin } from '
|
|
16
|
-
import { OptionsEditorTabs } from './OptionsEditorTabs';
|
|
14
|
+
import { ErrorAlert } from '@perses-dev/components';
|
|
15
|
+
import { usePlugin } from '../../runtime';
|
|
17
16
|
export function PluginSpecEditor(props) {
|
|
18
17
|
const { pluginType , pluginKind , ...others } = props;
|
|
19
18
|
const { data: plugin , isLoading , error } = usePlugin(pluginType, pluginKind);
|
|
@@ -30,34 +29,7 @@ export function PluginSpecEditor(props) {
|
|
|
30
29
|
throw new Error(`Missing implementation for ${pluginType} plugin with kind '${pluginKind}'`);
|
|
31
30
|
}
|
|
32
31
|
if (pluginType === 'Panel') {
|
|
33
|
-
|
|
34
|
-
let tabs = [];
|
|
35
|
-
if (PanelQueryEditorComponent !== undefined) {
|
|
36
|
-
tabs.push({
|
|
37
|
-
label: 'Query',
|
|
38
|
-
content: /*#__PURE__*/ _jsx(PanelQueryEditorComponent, {
|
|
39
|
-
...others
|
|
40
|
-
})
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
if (panelOptionsEditorComponents !== undefined) {
|
|
44
|
-
tabs = tabs.concat(panelOptionsEditorComponents.map(({ label , content: OptionsEditorComponent })=>({
|
|
45
|
-
label,
|
|
46
|
-
content: /*#__PURE__*/ _jsx(OptionsEditorComponent, {
|
|
47
|
-
...others
|
|
48
|
-
})
|
|
49
|
-
})));
|
|
50
|
-
}
|
|
51
|
-
// always show json editor by default
|
|
52
|
-
tabs.push({
|
|
53
|
-
label: 'JSON',
|
|
54
|
-
content: /*#__PURE__*/ _jsx(JSONEditor, {
|
|
55
|
-
...others
|
|
56
|
-
})
|
|
57
|
-
});
|
|
58
|
-
return /*#__PURE__*/ _jsx(OptionsEditorTabs, {
|
|
59
|
-
tabs: tabs
|
|
60
|
-
});
|
|
32
|
+
throw new Error('This editor should not be used for panel type. Please use Panel Spec Editor instead.');
|
|
61
33
|
}
|
|
62
34
|
const { OptionsEditorComponent } = plugin;
|
|
63
35
|
if (OptionsEditorComponent !== undefined) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginSpecEditor/PluginSpecEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ErrorAlert } from '@perses-dev/components';\nimport { UnknownSpec } from '@perses-dev/core';\nimport { OptionsEditorProps, PluginType } from '../../model';\nimport { usePlugin } from '../../runtime';\n\nexport interface PluginSpecEditorProps extends OptionsEditorProps<UnknownSpec> {\n pluginType: PluginType;\n pluginKind: string;\n}\n\nexport function PluginSpecEditor(props: PluginSpecEditorProps) {\n const { pluginType, pluginKind, ...others } = props;\n const { data: plugin, isLoading, error } = usePlugin(pluginType, pluginKind);\n\n if (error) {\n return <ErrorAlert error={error} />;\n }\n\n // TODO: Proper loading indicator\n if (isLoading) {\n return null;\n }\n\n if (plugin === undefined) {\n throw new Error(`Missing implementation for ${pluginType} plugin with kind '${pluginKind}'`);\n }\n\n if (pluginType === 'Panel') {\n throw new Error('This editor should not be used for panel type. Please use Panel Spec Editor instead.');\n }\n\n const { OptionsEditorComponent } = plugin;\n\n if (OptionsEditorComponent !== undefined) {\n return <OptionsEditorComponent {...others} />;\n }\n\n return null;\n}\n"],"names":["ErrorAlert","usePlugin","PluginSpecEditor","props","pluginType","pluginKind","others","data","plugin","isLoading","error","undefined","Error","OptionsEditorComponent"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACp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
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './PluginSpecEditor';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PluginSpecEditor/index.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PluginSpecEditor';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TimeSeriesQueryDefinition, QueryDefinition } from '@perses-dev/core';
|
|
3
|
+
export interface TimeSeriesQueryEditorProps {
|
|
4
|
+
queries?: TimeSeriesQueryDefinition[];
|
|
5
|
+
onChange: (queries: QueryDefinition[]) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function TimeSeriesQueryEditor({ queries, onChange }: TimeSeriesQueryEditorProps): JSX.Element;
|
|
8
|
+
//# sourceMappingURL=TimeSeriesQueryEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,yBAAyB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAM9E,MAAM,WAAW,0BAA0B;IACzC,OAAO,CAAC,EAAE,yBAAyB,EAAE,CAAC;IACtC,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAChD;AAED,wBAAgB,qBAAqB,CAAC,EAAE,OAAY,EAAE,QAAQ,EAAE,EAAE,0BAA0B,eAwG3F"}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { useState } from 'react';
|
|
15
|
+
import { produce } from 'immer';
|
|
16
|
+
import { Button, Stack } from '@mui/material';
|
|
17
|
+
import AddIcon from 'mdi-material-ui/Plus';
|
|
18
|
+
import { usePlugin, usePluginRegistry } from '../../runtime';
|
|
19
|
+
import { TimeSeriesQueryInput } from './TimeSeriesQueryInput';
|
|
20
|
+
const DEFAULT_QUERY_PLUGIN_TYPE = 'TimeSeriesQuery';
|
|
21
|
+
export function TimeSeriesQueryEditor({ queries =[] , onChange }) {
|
|
22
|
+
const hasMoreThanOneQuery = queries.length > 1;
|
|
23
|
+
const { defaultPluginKinds } = usePluginRegistry();
|
|
24
|
+
var ref;
|
|
25
|
+
const defaultTimeSeriesQueryKind = (ref = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[DEFAULT_QUERY_PLUGIN_TYPE]) !== null && ref !== void 0 ? ref : '';
|
|
26
|
+
const { data: defaultQueryPlugin } = usePlugin(DEFAULT_QUERY_PLUGIN_TYPE, defaultTimeSeriesQueryKind, {
|
|
27
|
+
useErrorBoundary: true,
|
|
28
|
+
enabled: true
|
|
29
|
+
});
|
|
30
|
+
// State for which queries are collapsed
|
|
31
|
+
// TODO: Would be easier if we had IDs for queries.
|
|
32
|
+
const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(()=>false));
|
|
33
|
+
// Query handlers
|
|
34
|
+
const handleQueryChange = (index, queryDef)=>{
|
|
35
|
+
onChange(produce(queries, (draft)=>{
|
|
36
|
+
if (draft) {
|
|
37
|
+
draft[index] = queryDef;
|
|
38
|
+
} else {
|
|
39
|
+
draft = [
|
|
40
|
+
queryDef
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
}));
|
|
44
|
+
};
|
|
45
|
+
const handleQueryAdd = ()=>{
|
|
46
|
+
if (!defaultQueryPlugin) return;
|
|
47
|
+
onChange(produce(queries, (draft)=>{
|
|
48
|
+
const queryDef = {
|
|
49
|
+
kind: DEFAULT_QUERY_PLUGIN_TYPE,
|
|
50
|
+
spec: {
|
|
51
|
+
plugin: {
|
|
52
|
+
kind: defaultTimeSeriesQueryKind,
|
|
53
|
+
spec: defaultQueryPlugin.createInitialOptions()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
if (draft) {
|
|
58
|
+
draft.push(queryDef);
|
|
59
|
+
} else {
|
|
60
|
+
draft = [
|
|
61
|
+
...queries,
|
|
62
|
+
queryDef
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
}));
|
|
66
|
+
setQueriesCollapsed((queriesCollapsed)=>{
|
|
67
|
+
queriesCollapsed.push(false);
|
|
68
|
+
return [
|
|
69
|
+
...queriesCollapsed
|
|
70
|
+
];
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
const handleQueryDelete = (index)=>{
|
|
74
|
+
onChange(produce(queries, (draft)=>{
|
|
75
|
+
draft.splice(index, 1);
|
|
76
|
+
}));
|
|
77
|
+
setQueriesCollapsed((queriesCollapsed)=>{
|
|
78
|
+
queriesCollapsed.splice(index, 1);
|
|
79
|
+
return [
|
|
80
|
+
...queriesCollapsed
|
|
81
|
+
];
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
const handleQueryCollapseExpand = (index)=>{
|
|
85
|
+
setQueriesCollapsed((queriesCollapsed)=>{
|
|
86
|
+
queriesCollapsed[index] = !queriesCollapsed[index];
|
|
87
|
+
return [
|
|
88
|
+
...queriesCollapsed
|
|
89
|
+
];
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
var ref1;
|
|
93
|
+
// show one query input if queries is empty
|
|
94
|
+
const queryDefinitions = queries.length ? queries : [
|
|
95
|
+
{
|
|
96
|
+
kind: 'TimeSeriesQuery',
|
|
97
|
+
spec: {
|
|
98
|
+
plugin: {
|
|
99
|
+
kind: (ref1 = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds['TimeSeriesQuery']) !== null && ref1 !== void 0 ? ref1 : '',
|
|
100
|
+
spec: {
|
|
101
|
+
query: ''
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
];
|
|
107
|
+
return /*#__PURE__*/ _jsxs(Stack, {
|
|
108
|
+
spacing: 1,
|
|
109
|
+
children: [
|
|
110
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
111
|
+
variant: "contained",
|
|
112
|
+
startIcon: /*#__PURE__*/ _jsx(AddIcon, {}),
|
|
113
|
+
sx: {
|
|
114
|
+
marginLeft: 'auto'
|
|
115
|
+
},
|
|
116
|
+
onClick: handleQueryAdd,
|
|
117
|
+
children: "Add Query"
|
|
118
|
+
}),
|
|
119
|
+
queryDefinitions.map((query, i)=>/*#__PURE__*/ _jsx(TimeSeriesQueryInput, {
|
|
120
|
+
index: i,
|
|
121
|
+
query: query,
|
|
122
|
+
isCollapsed: !!queriesCollapsed[i],
|
|
123
|
+
onChange: handleQueryChange,
|
|
124
|
+
onDelete: hasMoreThanOneQuery ? handleQueryDelete : undefined,
|
|
125
|
+
onCollapseExpand: handleQueryCollapseExpand
|
|
126
|
+
}, i))
|
|
127
|
+
]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
//# sourceMappingURL=TimeSeriesQueryEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.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 { useState } from 'react';\nimport { produce } from 'immer';\nimport { Button, Stack } from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { TimeSeriesQueryDefinition, QueryDefinition } from '@perses-dev/core';\nimport { usePlugin, usePluginRegistry } from '../../runtime';\nimport { TimeSeriesQueryInput } from './TimeSeriesQueryInput';\n\nconst DEFAULT_QUERY_PLUGIN_TYPE = 'TimeSeriesQuery';\n\nexport interface TimeSeriesQueryEditorProps {\n queries?: TimeSeriesQueryDefinition[];\n onChange: (queries: QueryDefinition[]) => void;\n}\n\nexport function TimeSeriesQueryEditor({ queries = [], onChange }: TimeSeriesQueryEditorProps) {\n const hasMoreThanOneQuery = queries.length > 1;\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultTimeSeriesQueryKind = defaultPluginKinds?.[DEFAULT_QUERY_PLUGIN_TYPE] ?? '';\n\n const { data: defaultQueryPlugin } = usePlugin(DEFAULT_QUERY_PLUGIN_TYPE, defaultTimeSeriesQueryKind, {\n useErrorBoundary: true,\n enabled: true,\n });\n\n // State for which queries are collapsed\n // TODO: Would be easier if we had IDs for queries.\n const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(() => false));\n\n // Query handlers\n const handleQueryChange = (index: number, queryDef: TimeSeriesQueryDefinition) => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft[index] = queryDef;\n } else {\n draft = [queryDef];\n }\n })\n );\n };\n\n const handleQueryAdd = () => {\n if (!defaultQueryPlugin) return;\n onChange(\n produce(queries, (draft) => {\n const queryDef: TimeSeriesQueryDefinition = {\n kind: DEFAULT_QUERY_PLUGIN_TYPE,\n spec: {\n plugin: { kind: defaultTimeSeriesQueryKind, spec: defaultQueryPlugin.createInitialOptions() },\n },\n };\n if (draft) {\n draft.push(queryDef);\n } else {\n draft = [...queries, queryDef];\n }\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.push(false);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryDelete = (index: number) => {\n onChange(\n produce(queries, (draft) => {\n draft.splice(index, 1);\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.splice(index, 1);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryCollapseExpand = (index: number) => {\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed[index] = !queriesCollapsed[index];\n return [...queriesCollapsed];\n });\n };\n\n // show one query input if queries is empty\n const queryDefinitions: TimeSeriesQueryDefinition[] = queries.length\n ? queries\n : [\n {\n kind: 'TimeSeriesQuery',\n spec: {\n plugin: {\n kind: defaultPluginKinds?.['TimeSeriesQuery'] ?? '',\n spec: {\n query: '',\n },\n },\n },\n },\n ];\n\n return (\n <Stack spacing={1}>\n <Button variant=\"contained\" startIcon={<AddIcon />} sx={{ marginLeft: 'auto' }} onClick={handleQueryAdd}>\n Add Query\n </Button>\n {queryDefinitions.map((query: TimeSeriesQueryDefinition, i: number) => (\n <TimeSeriesQueryInput\n key={i}\n index={i}\n query={query}\n isCollapsed={!!queriesCollapsed[i]}\n onChange={handleQueryChange}\n onDelete={hasMoreThanOneQuery ? handleQueryDelete : undefined}\n onCollapseExpand={handleQueryCollapseExpand}\n />\n ))}\n </Stack>\n );\n}\n"],"names":["useState","produce","Button","Stack","AddIcon","usePlugin","usePluginRegistry","TimeSeriesQueryInput","DEFAULT_QUERY_PLUGIN_TYPE","TimeSeriesQueryEditor","queries","onChange","hasMoreThanOneQuery","length","defaultPluginKinds","defaultTimeSeriesQueryKind","data","defaultQueryPlugin","useErrorBoundary","enabled","queriesCollapsed","setQueriesCollapsed","map","handleQueryChange","index","queryDef","draft","handleQueryAdd","kind","spec","plugin","createInitialOptions","push","handleQueryDelete","splice","handleQueryCollapseExpand","queryDefinitions","query","spacing","variant","startIcon","sx","marginLeft","onClick","i","isCollapsed","onDelete","undefined","onCollapseExpand"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,OAAO,QAAQ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C7DC,gBAAgB,EAAEb,yBAAyB;mBANtCS,CAAC,CAON,AACH,CAAC;;MACI,CACR;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TimeSeriesQueryDefinition } from '@perses-dev/core';
|
|
3
|
+
interface TimeSeriesQueryInputProps {
|
|
4
|
+
query: TimeSeriesQueryDefinition;
|
|
5
|
+
index: number;
|
|
6
|
+
onChange: (index: number, query: TimeSeriesQueryDefinition) => void;
|
|
7
|
+
onCollapseExpand: (index: number) => void;
|
|
8
|
+
isCollapsed?: boolean;
|
|
9
|
+
onDelete?: (index: number) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const TimeSeriesQueryInput: ({ index, query, isCollapsed, onDelete, onChange, onCollapseExpand, }: TimeSeriesQueryInputProps) => JSX.Element;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=TimeSeriesQueryInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeSeriesQueryInput.d.ts","sourceRoot":"","sources":["../../../src/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAO7D,UAAU,yBAAyB;IACjC,KAAK,EAAE,yBAAyB,CAAC;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,yBAAyB,KAAK,IAAI,CAAC;IACpE,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,eAAO,MAAM,oBAAoB,yEAO9B,yBAAyB,gBAsB3B,CAAC"}
|