@perses-dev/dashboards 0.37.2 → 0.38.0
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/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +12 -52
- package/dist/cjs/components/Variables/TemplateVariable.js +2 -2
- package/dist/cjs/components/Variables/VariableEditor.js +17 -6
- package/dist/cjs/components/Variables/index.js +0 -2
- package/dist/cjs/context/DatasourceStoreProvider.js +22 -18
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts.map +1 -1
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js +11 -46
- package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map +1 -1
- package/dist/components/Variables/TemplateVariable.d.ts.map +1 -1
- package/dist/components/Variables/TemplateVariable.js +1 -1
- package/dist/components/Variables/TemplateVariable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +15 -4
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/index.d.ts +0 -2
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +0 -2
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/context/DatasourceStoreProvider.d.ts +4 -3
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +22 -18
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +2 -2
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/package.json +6 -6
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +0 -399
- package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +0 -178
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +0 -29
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +0 -91
- package/dist/cjs/components/Variables/variable-model.js +0 -117
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +0 -10
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +0 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +0 -354
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +0 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +0 -16
- package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +0 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +0 -122
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +0 -1
- package/dist/components/Variables/VariableEditorForm/index.d.ts +0 -3
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +0 -1
- package/dist/components/Variables/VariableEditorForm/index.js +0 -16
- package/dist/components/Variables/VariableEditorForm/index.js.map +0 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +0 -23
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +0 -1
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +0 -79
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +0 -1
- package/dist/components/Variables/variable-model.d.ts +0 -16
- package/dist/components/Variables/variable-model.d.ts.map +0 -1
- package/dist/components/Variables/variable-model.js +0 -105
- package/dist/components/Variables/variable-model.js.map +0 -1
|
@@ -1,122 +0,0 @@
|
|
|
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 React, { useState } from 'react';
|
|
15
|
-
import { Alert, Box, Card, Chip, CircularProgress, IconButton, Stack, Typography } from '@mui/material';
|
|
16
|
-
import { InfoTooltip, useSnackbar } from '@perses-dev/components';
|
|
17
|
-
import Refresh from 'mdi-material-ui/Refresh';
|
|
18
|
-
import Clipboard from 'mdi-material-ui/ClipboardOutline';
|
|
19
|
-
import { TOOLTIP_TEXT } from '../../../constants';
|
|
20
|
-
import { useListVariablePluginValues } from '../variable-model';
|
|
21
|
-
const DEFAULT_MAX_PREVIEW_VALUES = 50;
|
|
22
|
-
export function VariablePreview(props) {
|
|
23
|
-
const { values , onRefresh , isLoading , error } = props;
|
|
24
|
-
const [maxValues, setMaxValues] = useState(DEFAULT_MAX_PREVIEW_VALUES);
|
|
25
|
-
const { infoSnackbar } = useSnackbar();
|
|
26
|
-
const showAll = ()=>{
|
|
27
|
-
setMaxValues(undefined);
|
|
28
|
-
};
|
|
29
|
-
let notShown = 0;
|
|
30
|
-
if (values && (values === null || values === void 0 ? void 0 : values.length) > 0 && maxValues) {
|
|
31
|
-
notShown = values.length - maxValues;
|
|
32
|
-
}
|
|
33
|
-
return /*#__PURE__*/ _jsxs(Box, {
|
|
34
|
-
children: [
|
|
35
|
-
/*#__PURE__*/ _jsxs(Stack, {
|
|
36
|
-
direction: "row",
|
|
37
|
-
spacing: 1,
|
|
38
|
-
alignItems: "center",
|
|
39
|
-
mb: 1,
|
|
40
|
-
children: [
|
|
41
|
-
/*#__PURE__*/ _jsx(Typography, {
|
|
42
|
-
variant: "h4",
|
|
43
|
-
children: "Preview Values"
|
|
44
|
-
}),
|
|
45
|
-
onRefresh && /*#__PURE__*/ _jsx(InfoTooltip, {
|
|
46
|
-
description: TOOLTIP_TEXT.refreshVariableValues,
|
|
47
|
-
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
48
|
-
onClick: onRefresh,
|
|
49
|
-
size: "small",
|
|
50
|
-
children: /*#__PURE__*/ _jsx(Refresh, {})
|
|
51
|
-
})
|
|
52
|
-
}),
|
|
53
|
-
/*#__PURE__*/ _jsx(InfoTooltip, {
|
|
54
|
-
description: TOOLTIP_TEXT.copyVariableValues,
|
|
55
|
-
children: /*#__PURE__*/ _jsx(IconButton, {
|
|
56
|
-
onClick: async ()=>{
|
|
57
|
-
if (values === null || values === void 0 ? void 0 : values.length) {
|
|
58
|
-
await navigator.clipboard.writeText(values.map((value)=>value).join(', '));
|
|
59
|
-
infoSnackbar('Preview values copied to clipboard!');
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
size: "small",
|
|
63
|
-
children: /*#__PURE__*/ _jsx(Clipboard, {})
|
|
64
|
-
})
|
|
65
|
-
})
|
|
66
|
-
]
|
|
67
|
-
}),
|
|
68
|
-
/*#__PURE__*/ _jsx(Card, {
|
|
69
|
-
variant: "outlined",
|
|
70
|
-
children: /*#__PURE__*/ _jsxs(Box, {
|
|
71
|
-
sx: {
|
|
72
|
-
display: 'flex',
|
|
73
|
-
flexWrap: 'wrap',
|
|
74
|
-
gap: 1,
|
|
75
|
-
m: 2
|
|
76
|
-
},
|
|
77
|
-
children: [
|
|
78
|
-
error && /*#__PURE__*/ _jsx(Alert, {
|
|
79
|
-
severity: "error",
|
|
80
|
-
children: error
|
|
81
|
-
}),
|
|
82
|
-
(values === null || values === void 0 ? void 0 : values.length) === 0 && /*#__PURE__*/ _jsx(Alert, {
|
|
83
|
-
severity: "info",
|
|
84
|
-
children: "No results"
|
|
85
|
-
}),
|
|
86
|
-
isLoading && /*#__PURE__*/ _jsx(Stack, {
|
|
87
|
-
width: "100%",
|
|
88
|
-
sx: {
|
|
89
|
-
alignItems: 'center',
|
|
90
|
-
justifyContent: 'center'
|
|
91
|
-
},
|
|
92
|
-
children: /*#__PURE__*/ _jsx(CircularProgress, {})
|
|
93
|
-
}),
|
|
94
|
-
values === null || values === void 0 ? void 0 : values.slice(0, maxValues).map((val)=>/*#__PURE__*/ _jsx(Chip, {
|
|
95
|
-
size: "small",
|
|
96
|
-
label: val
|
|
97
|
-
}, val)),
|
|
98
|
-
notShown > 0 && /*#__PURE__*/ _jsx(Chip, {
|
|
99
|
-
onClick: showAll,
|
|
100
|
-
variant: "outlined",
|
|
101
|
-
size: "small",
|
|
102
|
-
label: `+${notShown} more`
|
|
103
|
-
})
|
|
104
|
-
]
|
|
105
|
-
})
|
|
106
|
-
})
|
|
107
|
-
]
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
export function VariableListPreview(props) {
|
|
111
|
-
const { definition , onRefresh } = props;
|
|
112
|
-
const { data , isFetching , error } = useListVariablePluginValues(definition);
|
|
113
|
-
const errorMessage = error === null || error === void 0 ? void 0 : error.message;
|
|
114
|
-
return /*#__PURE__*/ _jsx(VariablePreview, {
|
|
115
|
-
values: (data === null || data === void 0 ? void 0 : data.map((val)=>val.value)) || [],
|
|
116
|
-
onRefresh: onRefresh,
|
|
117
|
-
isLoading: isFetching,
|
|
118
|
-
error: errorMessage
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
//# sourceMappingURL=VariablePreview.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/VariablePreview.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 React, { useState } from 'react';\nimport { Alert, Box, Card, Chip, CircularProgress, IconButton, Stack, Typography } from '@mui/material';\nimport { InfoTooltip, useSnackbar } from '@perses-dev/components';\nimport Refresh from 'mdi-material-ui/Refresh';\nimport Clipboard from 'mdi-material-ui/ClipboardOutline';\nimport { ListVariableDefinition } from '@perses-dev/core';\nimport { TOOLTIP_TEXT } from '../../../constants';\nimport { useListVariablePluginValues } from '../variable-model';\n\nconst DEFAULT_MAX_PREVIEW_VALUES = 50;\n\ninterface VariablePreviewProps {\n values?: string[];\n onRefresh?: () => void;\n isLoading?: boolean;\n error?: string;\n}\n\nexport function VariablePreview(props: VariablePreviewProps) {\n const { values, onRefresh, isLoading, error } = props;\n const [maxValues, setMaxValues] = useState<number | undefined>(DEFAULT_MAX_PREVIEW_VALUES);\n const { infoSnackbar } = useSnackbar();\n const showAll = () => {\n setMaxValues(undefined);\n };\n let notShown = 0;\n\n if (values && values?.length > 0 && maxValues) {\n notShown = values.length - maxValues;\n }\n\n return (\n <Box>\n <Stack direction=\"row\" spacing={1} alignItems=\"center\" mb={1}>\n <Typography variant=\"h4\">Preview Values</Typography>\n {onRefresh && (\n <InfoTooltip description={TOOLTIP_TEXT.refreshVariableValues}>\n <IconButton onClick={onRefresh} size=\"small\">\n <Refresh />\n </IconButton>\n </InfoTooltip>\n )}\n <InfoTooltip description={TOOLTIP_TEXT.copyVariableValues}>\n <IconButton\n onClick={async () => {\n if (values?.length) {\n await navigator.clipboard.writeText(values.map((value) => value).join(', '));\n infoSnackbar('Preview values copied to clipboard!');\n }\n }}\n size=\"small\"\n >\n <Clipboard />\n </IconButton>\n </InfoTooltip>\n </Stack>\n <Card variant=\"outlined\">\n <Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1, m: 2 }}>\n {error && <Alert severity=\"error\">{error}</Alert>}\n {values?.length === 0 && <Alert severity=\"info\">No results</Alert>}\n {isLoading && (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n )}\n {values?.slice(0, maxValues).map((val) => (\n <Chip size=\"small\" key={val} label={val} />\n ))}\n {notShown > 0 && <Chip onClick={showAll} variant=\"outlined\" size=\"small\" label={`+${notShown} more`} />}\n </Box>\n </Card>\n </Box>\n );\n}\n\ninterface VariableListPreviewProps {\n definition: ListVariableDefinition;\n onRefresh: () => void;\n}\n\nexport function VariableListPreview(props: VariableListPreviewProps) {\n const { definition, onRefresh } = props;\n const { data, isFetching, error } = useListVariablePluginValues(definition);\n const errorMessage = (error as Error)?.message;\n\n return (\n <VariablePreview\n values={data?.map((val) => val.value) || []}\n onRefresh={onRefresh}\n isLoading={isFetching}\n error={errorMessage}\n />\n );\n}\n"],"names":["React","useState","Alert","Box","Card","Chip","CircularProgress","IconButton","Stack","Typography","InfoTooltip","useSnackbar","Refresh","Clipboard","TOOLTIP_TEXT","useListVariablePluginValues","DEFAULT_MAX_PREVIEW_VALUES","VariablePreview","props","values","onRefresh","isLoading","error","maxValues","setMaxValues","infoSnackbar","showAll","undefined","notShown","length","direction","spacing","alignItems","mb","variant","description","refreshVariableValues","onClick","size","copyVariableValues","navigator","clipboard","writeText","map","value","join","sx","display","flexWrap","gap","m","severity","width","justifyContent","slice","val","label","VariableListPreview","definition","data","isFetching","errorMessage","message"],"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,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO,CAAC;AACxC,SAASC,KAAK,EAAEC,GAAG,EAAEC,IAAI,EAAEC,IAAI,EAAEC,gBAAgB,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,QAAQ,eAAe,CAAC;AACxG,SAASC,WAAW,EAA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.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/index.ts"],"names":[],"mappings":"AAaA,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
export * from './VariableEditorForm';
|
|
14
|
-
export * from './VariablePreview';
|
|
15
|
-
|
|
16
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/index.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\nexport * from './VariableEditorForm';\nexport * from './VariablePreview';\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,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { VariableDefinition } from '@perses-dev/core';
|
|
2
|
-
export declare function getInitialState(initialVariableDefinition: VariableDefinition): {
|
|
3
|
-
name: string;
|
|
4
|
-
title: string | undefined;
|
|
5
|
-
kind: "TextVariable" | "ListVariable";
|
|
6
|
-
description: string;
|
|
7
|
-
listVariableFields: {
|
|
8
|
-
allowMultiple: boolean;
|
|
9
|
-
allowAll: boolean;
|
|
10
|
-
capturing_regexp: string | undefined;
|
|
11
|
-
plugin: {
|
|
12
|
-
kind: string;
|
|
13
|
-
spec: {};
|
|
14
|
-
};
|
|
15
|
-
customAllValue: string | undefined;
|
|
16
|
-
};
|
|
17
|
-
textVariableFields: {
|
|
18
|
-
value: string;
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
export declare type VariableEditorState = ReturnType<typeof getInitialState>;
|
|
22
|
-
export declare function getVariableDefinitionFromState(state: VariableEditorState): VariableDefinition;
|
|
23
|
-
//# sourceMappingURL=variable-editor-form-model.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"variable-editor-form-model.d.ts","sourceRoot":"","sources":["../../../../src/components/Variables/VariableEditorForm/variable-editor-form-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAmC,MAAM,kBAAkB,CAAC;AAEvF,wBAAgB,eAAe,CAAC,yBAAyB,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;EA+B5E;AAED,oBAAY,mBAAmB,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAErE,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,mBAAmB,GAAG,kBAAkB,CA+B7F"}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
// Copyright 2023 The Perses Authors
|
|
2
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
-
// you may not use this file except in compliance with the License.
|
|
4
|
-
// You may obtain a copy of the License at
|
|
5
|
-
//
|
|
6
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
//
|
|
8
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
-
// See the License for the specific language governing permissions and
|
|
12
|
-
// limitations under the License.
|
|
13
|
-
export function getInitialState(initialVariableDefinition) {
|
|
14
|
-
var ref;
|
|
15
|
-
var _value;
|
|
16
|
-
const textVariableFields = {
|
|
17
|
-
value: (_value = initialVariableDefinition.spec.value) !== null && _value !== void 0 ? _value : ''
|
|
18
|
-
};
|
|
19
|
-
const listVariableFields = {
|
|
20
|
-
allowMultiple: false,
|
|
21
|
-
allowAll: false,
|
|
22
|
-
capturing_regexp: undefined,
|
|
23
|
-
plugin: {
|
|
24
|
-
kind: '',
|
|
25
|
-
spec: {}
|
|
26
|
-
},
|
|
27
|
-
customAllValue: undefined
|
|
28
|
-
};
|
|
29
|
-
if (initialVariableDefinition.kind === 'ListVariable') {
|
|
30
|
-
var _allow_all_value;
|
|
31
|
-
listVariableFields.allowMultiple = (_allow_all_value = initialVariableDefinition.spec.allow_all_value) !== null && _allow_all_value !== void 0 ? _allow_all_value : false;
|
|
32
|
-
var _allow_all_value1;
|
|
33
|
-
listVariableFields.allowAll = (_allow_all_value1 = initialVariableDefinition.spec.allow_all_value) !== null && _allow_all_value1 !== void 0 ? _allow_all_value1 : false;
|
|
34
|
-
listVariableFields.capturing_regexp = initialVariableDefinition.spec.capturing_regexp;
|
|
35
|
-
listVariableFields.plugin = initialVariableDefinition.spec.plugin;
|
|
36
|
-
listVariableFields.customAllValue = initialVariableDefinition.spec.custom_all_value;
|
|
37
|
-
}
|
|
38
|
-
return {
|
|
39
|
-
name: initialVariableDefinition.spec.name,
|
|
40
|
-
title: (ref = initialVariableDefinition.spec.display) === null || ref === void 0 ? void 0 : ref.name,
|
|
41
|
-
kind: initialVariableDefinition.kind,
|
|
42
|
-
description: '',
|
|
43
|
-
listVariableFields,
|
|
44
|
-
textVariableFields
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
export function getVariableDefinitionFromState(state) {
|
|
48
|
-
const { name , title , kind } = state;
|
|
49
|
-
const display = title ? {
|
|
50
|
-
name: title
|
|
51
|
-
} : undefined;
|
|
52
|
-
if (kind === 'TextVariable') {
|
|
53
|
-
return {
|
|
54
|
-
kind,
|
|
55
|
-
spec: {
|
|
56
|
-
name,
|
|
57
|
-
display,
|
|
58
|
-
...state.textVariableFields
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
if (kind === 'ListVariable') {
|
|
63
|
-
return {
|
|
64
|
-
kind,
|
|
65
|
-
spec: {
|
|
66
|
-
name,
|
|
67
|
-
display,
|
|
68
|
-
allow_multiple: state.listVariableFields.allowMultiple,
|
|
69
|
-
allow_all_value: state.listVariableFields.allowAll,
|
|
70
|
-
capturing_regexp: state.listVariableFields.capturing_regexp,
|
|
71
|
-
plugin: state.listVariableFields.plugin,
|
|
72
|
-
custom_all_value: state.listVariableFields.customAllValue
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
throw new Error(`Unknown variable kind: ${kind}`);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
//# sourceMappingURL=variable-editor-form-model.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/components/Variables/VariableEditorForm/variable-editor-form-model.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 { VariableDefinition, TextVariableDefinition, Display } from '@perses-dev/core';\n\nexport function getInitialState(initialVariableDefinition: VariableDefinition) {\n const textVariableFields = {\n value: (initialVariableDefinition as TextVariableDefinition).spec.value ?? '',\n };\n\n const listVariableFields = {\n allowMultiple: false,\n allowAll: false,\n capturing_regexp: undefined as string | undefined,\n plugin: {\n kind: '',\n spec: {},\n },\n customAllValue: undefined as string | undefined,\n };\n if (initialVariableDefinition.kind === 'ListVariable') {\n listVariableFields.allowMultiple = initialVariableDefinition.spec.allow_all_value ?? false;\n listVariableFields.allowAll = initialVariableDefinition.spec.allow_all_value ?? false;\n listVariableFields.capturing_regexp = initialVariableDefinition.spec.capturing_regexp;\n listVariableFields.plugin = initialVariableDefinition.spec.plugin;\n listVariableFields.customAllValue = initialVariableDefinition.spec.custom_all_value;\n }\n\n return {\n name: initialVariableDefinition.spec.name,\n title: initialVariableDefinition.spec.display?.name,\n kind: initialVariableDefinition.kind,\n description: '',\n listVariableFields,\n textVariableFields,\n };\n}\n\nexport type VariableEditorState = ReturnType<typeof getInitialState>;\n\nexport function getVariableDefinitionFromState(state: VariableEditorState): VariableDefinition {\n const { name, title, kind } = state;\n\n const display: Display | undefined = title ? { name: title } : undefined;\n\n if (kind === 'TextVariable') {\n return {\n kind,\n spec: {\n name,\n display,\n ...state.textVariableFields,\n },\n };\n }\n\n if (kind === 'ListVariable') {\n return {\n kind,\n spec: {\n name,\n display,\n allow_multiple: state.listVariableFields.allowMultiple,\n allow_all_value: state.listVariableFields.allowAll,\n capturing_regexp: state.listVariableFields.capturing_regexp,\n plugin: state.listVariableFields.plugin,\n custom_all_value: state.listVariableFields.customAllValue,\n },\n };\n }\n throw new Error(`Unknown variable kind: ${kind}`);\n}\n"],"names":["getInitialState","initialVariableDefinition","textVariableFields","value","spec","listVariableFields","allowMultiple","allowAll","capturing_regexp","undefined","plugin","kind","customAllValue","allow_all_value","custom_all_value","name","title","display","description","getVariableDefinitionFromState","state","allow_multiple","Error"],"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;AAIjC,OAAO,SAASA,eAAe,CAACC,yBAA6C,EAAE;QAyBpEA,GAAsC;QAvBtC,MAAgE;IADzE,MAAMC,kBAAkB,GAAG;QACzBC,KAAK,EAAE,CAAA,MAAgE,GAAhE,AAACF,yBAAyB,CAA4BG,IAAI,CAACD,KAAK,cAAhE,MAAgE,cAAhE,MAAgE,GAAI,EAAE;KAC9E,AAAC;IAEF,MAAME,kBAAkB,GAAG;QACzBC,aAAa,EAAE,KAAK;QACpBC,QAAQ,EAAE,KAAK;QACfC,gBAAgB,EAAEC,SAAS;QAC3BC,MAAM,EAAE;YACNC,IAAI,EAAE,EAAE;YACRP,IAAI,EAAE,EAAE;SACT;QACDQ,cAAc,EAAEH,SAAS;KAC1B,AAAC;IACF,IAAIR,yBAAyB,CAACU,IAAI,KAAK,cAAc,EAAE;YAClBV,gBAA8C;QAAjFI,kBAAkB,CAACC,aAAa,GAAGL,CAAAA,gBAA8C,GAA9CA,yBAAyB,CAACG,IAAI,CAACS,eAAe,cAA9CZ,gBAA8C,cAA9CA,gBAA8C,GAAI,KAAK,CAAC;YAC7DA,iBAA8C;QAA5EI,kBAAkB,CAACE,QAAQ,GAAGN,CAAAA,iBAA8C,GAA9CA,yBAAyB,CAACG,IAAI,CAACS,eAAe,cAA9CZ,iBAA8C,cAA9CA,iBAA8C,GAAI,KAAK,CAAC;QACtFI,kBAAkB,CAACG,gBAAgB,GAAGP,yBAAyB,CAACG,IAAI,CAACI,gBAAgB,CAAC;QACtFH,kBAAkB,CAACK,MAAM,GAAGT,yBAAyB,CAACG,IAAI,CAACM,MAAM,CAAC;QAClEL,kBAAkB,C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AAM,IAAIU,KAAK,CAAC,CAAC,uBAAuB,EAAEX,IAAI,CAAC,CAAC,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ListVariableDefinition } from '@perses-dev/core';
|
|
2
|
-
import { VariableOption, VariableStateMap } from '@perses-dev/plugin-system';
|
|
3
|
-
export declare function filterVariableList(data: VariableOption[], capturedRegexp: RegExp): VariableOption[];
|
|
4
|
-
export declare function useListVariablePluginValues(definition: ListVariableDefinition): import("@tanstack/react-query").UseQueryResult<VariableOption[], unknown>;
|
|
5
|
-
/**
|
|
6
|
-
* Returns a serialized string of the current state of variable values.
|
|
7
|
-
*/
|
|
8
|
-
export declare function getVariableValuesKey(v: VariableStateMap): string;
|
|
9
|
-
export declare const VARIABLE_TYPES: readonly [{
|
|
10
|
-
readonly label: "List";
|
|
11
|
-
readonly kind: "ListVariable";
|
|
12
|
-
}, {
|
|
13
|
-
readonly label: "Text";
|
|
14
|
-
readonly kind: "TextVariable";
|
|
15
|
-
}];
|
|
16
|
-
//# sourceMappingURL=variable-model.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"variable-model.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/variable-model.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAKL,cAAc,EACd,gBAAgB,EACjB,MAAM,2BAA2B,CAAC;AAGnC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,cAAc,EAAE,EAAE,cAAc,EAAE,MAAM,GAAG,cAAc,EAAE,CAqBnG;AAED,wBAAgB,2BAA2B,CAAC,UAAU,EAAE,sBAAsB,6EAyC7E;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,gBAAgB,UAIvD;AAED,eAAO,MAAM,cAAc;;;;;;EAGjB,CAAC"}
|
|
@@ -1,105 +0,0 @@
|
|
|
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 { useDatasourceStore, usePlugin, useTemplateVariableValues, useTimeRange } from '@perses-dev/plugin-system';
|
|
14
|
-
import { useQuery } from '@tanstack/react-query';
|
|
15
|
-
export function filterVariableList(data, capturedRegexp) {
|
|
16
|
-
const result = [];
|
|
17
|
-
const filteredSet = new Set();
|
|
18
|
-
for (const variableValue of data){
|
|
19
|
-
const matches = variableValue.value.matchAll(capturedRegexp);
|
|
20
|
-
let concat = '';
|
|
21
|
-
for (const match of matches){
|
|
22
|
-
for(let i = 1; i < match.length; i++){
|
|
23
|
-
const m = match[i];
|
|
24
|
-
if (m !== undefined) {
|
|
25
|
-
concat = `${concat}${m}`;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (concat !== '' && !filteredSet.has(concat)) {
|
|
30
|
-
// like that we are avoiding to have duplicating variable value
|
|
31
|
-
filteredSet.add(concat);
|
|
32
|
-
result.push({
|
|
33
|
-
label: variableValue.label,
|
|
34
|
-
value: concat
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
export function useListVariablePluginValues(definition) {
|
|
41
|
-
const { data: variablePlugin } = usePlugin('Variable', definition.spec.plugin.kind);
|
|
42
|
-
const datasourceStore = useDatasourceStore();
|
|
43
|
-
const allVariables = useTemplateVariableValues();
|
|
44
|
-
const { absoluteTimeRange: timeRange , refreshKey } = useTimeRange();
|
|
45
|
-
const variablePluginCtx = {
|
|
46
|
-
timeRange,
|
|
47
|
-
datasourceStore,
|
|
48
|
-
variables: allVariables
|
|
49
|
-
};
|
|
50
|
-
const spec = definition.spec.plugin.spec;
|
|
51
|
-
const capturingRegexp = definition.spec.capturing_regexp !== undefined ? new RegExp(definition.spec.capturing_regexp, 'g') : undefined;
|
|
52
|
-
let dependsOnVariables;
|
|
53
|
-
if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
|
|
54
|
-
const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);
|
|
55
|
-
dependsOnVariables = dependencies.variables;
|
|
56
|
-
}
|
|
57
|
-
const variables = useTemplateVariableValues(dependsOnVariables);
|
|
58
|
-
let waitToLoad = false;
|
|
59
|
-
if (dependsOnVariables) {
|
|
60
|
-
waitToLoad = dependsOnVariables.some((v)=>{
|
|
61
|
-
var ref;
|
|
62
|
-
return (ref = variables[v]) === null || ref === void 0 ? void 0 : ref.loading;
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
const variablesValueKey = getVariableValuesKey(variables);
|
|
66
|
-
return useQuery([
|
|
67
|
-
name,
|
|
68
|
-
definition,
|
|
69
|
-
variablesValueKey,
|
|
70
|
-
timeRange,
|
|
71
|
-
refreshKey
|
|
72
|
-
], async ()=>{
|
|
73
|
-
const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
|
|
74
|
-
datasourceStore,
|
|
75
|
-
variables,
|
|
76
|
-
timeRange
|
|
77
|
-
}));
|
|
78
|
-
if (resp === undefined) {
|
|
79
|
-
return [];
|
|
80
|
-
}
|
|
81
|
-
if (capturingRegexp === undefined) {
|
|
82
|
-
return resp.data;
|
|
83
|
-
}
|
|
84
|
-
return filterVariableList(resp.data, capturingRegexp);
|
|
85
|
-
}, {
|
|
86
|
-
enabled: !!variablePlugin || waitToLoad
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Returns a serialized string of the current state of variable values.
|
|
91
|
-
*/ export function getVariableValuesKey(v) {
|
|
92
|
-
return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
|
|
93
|
-
}
|
|
94
|
-
export const VARIABLE_TYPES = [
|
|
95
|
-
{
|
|
96
|
-
label: 'List',
|
|
97
|
-
kind: 'ListVariable'
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
label: 'Text',
|
|
101
|
-
kind: 'TextVariable'
|
|
102
|
-
}
|
|
103
|
-
];
|
|
104
|
-
|
|
105
|
-
//# sourceMappingURL=variable-model.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Variables/variable-model.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 { ListVariableDefinition } from '@perses-dev/core';\nimport {\n useDatasourceStore,\n usePlugin,\n useTemplateVariableValues,\n useTimeRange,\n VariableOption,\n VariableStateMap,\n} from '@perses-dev/plugin-system';\nimport { useQuery } from '@tanstack/react-query';\n\nexport function filterVariableList(data: VariableOption[], capturedRegexp: RegExp): VariableOption[] {\n const result: VariableOption[] = [];\n const filteredSet = new Set<string>();\n for (const variableValue of data) {\n const matches = variableValue.value.matchAll(capturedRegexp);\n let concat = '';\n for (const match of matches) {\n for (let i = 1; i < match.length; i++) {\n const m = match[i];\n if (m !== undefined) {\n concat = `${concat}${m}`;\n }\n }\n }\n if (concat !== '' && !filteredSet.has(concat)) {\n // like that we are avoiding to have duplicating variable value\n filteredSet.add(concat);\n result.push({ label: variableValue.label, value: concat });\n }\n }\n return result;\n}\n\nexport function useListVariablePluginValues(definition: ListVariableDefinition) {\n const { data: variablePlugin } = usePlugin('Variable', definition.spec.plugin.kind);\n const datasourceStore = useDatasourceStore();\n const allVariables = useTemplateVariableValues();\n const { absoluteTimeRange: timeRange, refreshKey } = useTimeRange();\n\n const variablePluginCtx = { timeRange, datasourceStore, variables: allVariables };\n\n const spec = definition.spec.plugin.spec;\n const capturingRegexp =\n definition.spec.capturing_regexp !== undefined ? new RegExp(definition.spec.capturing_regexp, 'g') : undefined;\n\n let dependsOnVariables: string[] | undefined;\n if (variablePlugin?.dependsOn) {\n const dependencies = variablePlugin.dependsOn(spec, variablePluginCtx);\n dependsOnVariables = dependencies.variables;\n }\n\n const variables = useTemplateVariableValues(dependsOnVariables);\n\n let waitToLoad = false;\n if (dependsOnVariables) {\n waitToLoad = dependsOnVariables.some((v) => variables[v]?.loading);\n }\n\n const variablesValueKey = getVariableValuesKey(variables);\n\n return useQuery(\n [name, definition, variablesValueKey, timeRange, refreshKey],\n async () => {\n const resp = await variablePlugin?.getVariableOptions(spec, { datasourceStore, variables, timeRange });\n if (resp === undefined) {\n return [];\n }\n if (capturingRegexp === undefined) {\n return resp.data;\n }\n return filterVariableList(resp.data, capturingRegexp);\n },\n { enabled: !!variablePlugin || waitToLoad }\n );\n}\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nexport function getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nexport const VARIABLE_TYPES = [\n { label: 'List', kind: 'ListVariable' },\n { label: 'Text', kind: 'TextVariable' },\n] as const;\n"],"names":["useDatasourceStore","usePlugin","useTemplateVariableValues","useTimeRange","useQuery","filterVariableList","data","capturedRegexp","result","filteredSet","Set","variableValue","matches","value","matchAll","concat","match","i","length","m","undefined","has","add","push","label","useListVariablePluginValues","definition","variablePlugin","spec","plugin","kind","datasourceStore","allVariables","absoluteTimeRange","timeRange","refreshKey","variablePluginCtx","variables","capturingRegexp","capturing_regexp","RegExp","dependsOnVariables","dependsOn","dependencies","waitToLoad","some","v","loading","variablesValueKey","getVariableValuesKey","name","resp","getVariableOptions","enabled","Object","values","map","JSON","stringify","join","VARIABLE_TYPES"],"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,SACEA,kBAAkB,EAClBC,SAAS,EACTC,yBAAyB,EACzBC,YAAY,QAGP,2BAA2B,CAAC;AACnC,SAASC,QAAQ,QAAQ,uBAAuB,CAAC;AAEjD,OAAO,SAASC,kBAAkB,CAACC,IAAsB,EAAEC,cAAsB,EAAoB;IACnG,MAAMC,MAAM,GAAqB,EAAE,AAAC;IACpC,MAAMC,WAAW,GAAG,IAAIC,GAAG,EAAU,AAAC;IACtC,KAAK,MAAMC,aAAa,IAAIL,IAAI,CAAE;QAChC,MAAMM,OAAO,GAAGD,aAAa,CAACE,KAAK,CAACC,QAAQ,CAACP,cAAc,CAAC,AAAC;QAC7D,IAAIQ,MAAM,GAAG,EAAE,AAAC;QAChB,KAAK,MAAMC,KAAK,IAAIJ,OAAO,CAAE;YAC3B,IAAK,IAAIK,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGD,KAAK,CAACE,MAAM,EAAED,CAAC,EAAE,CAAE;gBACrC,MAAME,CAAC,GAAGH,KAAK,CAACC,CAAC,CAAC,AAAC;gBACnB,IAAIE,CAAC,KAAKC,SAAS,EAAE;oBACnBL,MAAM,GAAG,CAAC,EAAEA,MAAM,CAAC,EAAEI,CAAC,CAAC,CAAC,CAAC;gBAC3B,CAAC;YACH,CAAC;QACH,CAAC;QACD,IAAIJ,MAAM,KAAK,EAAE,IAAI,CAACN,WAAW,CAACY,GAAG,CAACN,MAA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