@perses-dev/dashboards 0.37.1 → 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/GridLayout/index.js +3 -1
- 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/GridLayout/index.d.ts +3 -1
- package/dist/components/GridLayout/index.d.ts.map +1 -1
- package/dist/components/GridLayout/index.js +3 -1
- package/dist/components/GridLayout/index.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
package/dist/cjs/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js
CHANGED
|
@@ -14,62 +14,22 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
Object.defineProperty(exports, "
|
|
17
|
+
Object.defineProperty(exports, "DashboardDiscardChangesConfirmationDialog", {
|
|
18
18
|
enumerable: true,
|
|
19
|
-
get: ()=>
|
|
19
|
+
get: ()=>DashboardDiscardChangesConfirmationDialog
|
|
20
20
|
});
|
|
21
21
|
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
-
const
|
|
23
|
-
const _close = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Close"));
|
|
22
|
+
const _components = require("@perses-dev/components");
|
|
24
23
|
const _context = require("../../context");
|
|
25
|
-
|
|
26
|
-
return obj && obj.__esModule ? obj : {
|
|
27
|
-
default: obj
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
const DiscardChangesConfirmationDialog = ()=>{
|
|
24
|
+
const DashboardDiscardChangesConfirmationDialog = ()=>{
|
|
31
25
|
const { discardChangesConfirmationDialog: dialog } = (0, _context.useDiscardChangesConfirmationDialog)();
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
41
|
-
"aria-label": "Close",
|
|
42
|
-
onClick: dialog.onCancel,
|
|
43
|
-
sx: (theme)=>({
|
|
44
|
-
position: 'absolute',
|
|
45
|
-
top: theme.spacing(0.5),
|
|
46
|
-
right: theme.spacing(0.5)
|
|
47
|
-
}),
|
|
48
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_close.default, {})
|
|
49
|
-
}),
|
|
50
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogContent, {
|
|
51
|
-
dividers: true,
|
|
52
|
-
sx: {
|
|
53
|
-
width: '500px'
|
|
54
|
-
},
|
|
55
|
-
children: dialog.description || 'You have unsaved changes in this dashboard. Are you sure you want to discard these changes? Changes cannot be recovered.'
|
|
56
|
-
}),
|
|
57
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.DialogActions, {
|
|
58
|
-
children: [
|
|
59
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
60
|
-
variant: "contained",
|
|
61
|
-
onClick: dialog.onDiscardChanges,
|
|
62
|
-
children: "Discard Changes"
|
|
63
|
-
}),
|
|
64
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
65
|
-
variant: "outlined",
|
|
66
|
-
color: "secondary",
|
|
67
|
-
onClick: dialog.onCancel,
|
|
68
|
-
children: "Cancel"
|
|
69
|
-
})
|
|
70
|
-
]
|
|
71
|
-
})
|
|
72
|
-
]
|
|
73
|
-
})
|
|
26
|
+
if (dialog === undefined) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.DiscardChangesConfirmationDialog, {
|
|
30
|
+
description: dialog.description || 'You have unsaved changes in this dashboard. Are you sure you want to discard these changes? Changes cannot be recovered.',
|
|
31
|
+
isOpen: true,
|
|
32
|
+
onCancel: dialog.onCancel,
|
|
33
|
+
onDiscardChanges: dialog.onDiscardChanges
|
|
74
34
|
});
|
|
75
35
|
};
|
|
@@ -14,8 +14,10 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_exportStar(require("./
|
|
17
|
+
_exportStar(require("./GridContainer"), exports);
|
|
18
18
|
_exportStar(require("./GridItemContent"), exports);
|
|
19
|
+
_exportStar(require("./GridLayout"), exports);
|
|
20
|
+
_exportStar(require("./GridTitle"), exports);
|
|
19
21
|
function _exportStar(from, to) {
|
|
20
22
|
Object.keys(from).forEach(function(k) {
|
|
21
23
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -22,8 +22,8 @@ const _jsxRuntime = require("react/jsx-runtime");
|
|
|
22
22
|
const _react = require("react");
|
|
23
23
|
const _material = require("@mui/material");
|
|
24
24
|
const _core = require("@perses-dev/core");
|
|
25
|
+
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
25
26
|
const _context = require("../../context");
|
|
26
|
-
const _variableModel = require("./variable-model");
|
|
27
27
|
function TemplateVariable({ name }) {
|
|
28
28
|
var ref;
|
|
29
29
|
const ctx = (0, _context.useTemplateVariable)(name);
|
|
@@ -49,7 +49,7 @@ function ListVariable({ name }) {
|
|
|
49
49
|
var ref, ref1, ref2, ref3;
|
|
50
50
|
const ctx = (0, _context.useTemplateVariable)(name);
|
|
51
51
|
const definition = ctx.definition;
|
|
52
|
-
const variablesOptionsQuery = (0,
|
|
52
|
+
const variablesOptionsQuery = (0, _pluginSystem.useListVariablePluginValues)(definition);
|
|
53
53
|
const { setVariableValue , setVariableLoading , setVariableOptions } = (0, _context.useTemplateVariableActions)();
|
|
54
54
|
const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_multiple) === true;
|
|
55
55
|
const allowAllValue = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_all_value) === true;
|
|
@@ -27,9 +27,8 @@ const _pencil = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pe
|
|
|
27
27
|
const _trashCan = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/TrashCan"));
|
|
28
28
|
const _arrowUp = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/ArrowUp"));
|
|
29
29
|
const _arrowDown = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/ArrowDown"));
|
|
30
|
+
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
30
31
|
const _context = require("../../context");
|
|
31
|
-
const _variableEditorForm = require("./VariableEditorForm");
|
|
32
|
-
const _variableModel = require("./variable-model");
|
|
33
32
|
function _interopRequireDefault(obj) {
|
|
34
33
|
return obj && obj.__esModule ? obj : {
|
|
35
34
|
default: obj
|
|
@@ -37,7 +36,7 @@ function _interopRequireDefault(obj) {
|
|
|
37
36
|
}
|
|
38
37
|
function getVariableLabelByKind(kind) {
|
|
39
38
|
var ref;
|
|
40
|
-
return (ref =
|
|
39
|
+
return (ref = _pluginSystem.VARIABLE_TYPES.find((variableType)=>variableType.kind === kind)) === null || ref === void 0 ? void 0 : ref.label;
|
|
41
40
|
}
|
|
42
41
|
function getValidation(variableDefinitions) {
|
|
43
42
|
const errors = [];
|
|
@@ -54,6 +53,7 @@ function getValidation(variableDefinitions) {
|
|
|
54
53
|
function VariableEditor(props) {
|
|
55
54
|
const [variableDefinitions, setVariableDefinitions] = (0, _useImmer.useImmer)(props.variableDefinitions);
|
|
56
55
|
const [variableEditIdx, setVariableEditIdx] = (0, _react.useState)(null);
|
|
56
|
+
const [variableFormAction, setVariableFormAction] = (0, _react.useState)('update');
|
|
57
57
|
const validation = (0, _react.useMemo)(()=>getValidation(variableDefinitions), [
|
|
58
58
|
variableDefinitions
|
|
59
59
|
]);
|
|
@@ -81,6 +81,7 @@ function VariableEditor(props) {
|
|
|
81
81
|
});
|
|
82
82
|
};
|
|
83
83
|
const addVariable = ()=>{
|
|
84
|
+
setVariableFormAction('create');
|
|
84
85
|
setVariableDefinitions((draft)=>{
|
|
85
86
|
draft.push({
|
|
86
87
|
kind: 'TextVariable',
|
|
@@ -92,6 +93,10 @@ function VariableEditor(props) {
|
|
|
92
93
|
});
|
|
93
94
|
setVariableEditIdx(variableDefinitions.length);
|
|
94
95
|
};
|
|
96
|
+
const editVariable = (index)=>{
|
|
97
|
+
setVariableFormAction('update');
|
|
98
|
+
setVariableEditIdx(index);
|
|
99
|
+
};
|
|
95
100
|
const toggleVariableVisibility = (index, visible)=>{
|
|
96
101
|
setVariableDefinitions((draft)=>{
|
|
97
102
|
const v = draft[index];
|
|
@@ -131,7 +136,7 @@ function VariableEditor(props) {
|
|
|
131
136
|
var ref;
|
|
132
137
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
133
138
|
children: [
|
|
134
|
-
currentEditingVariableDefinition && /*#__PURE__*/ (0, _jsxRuntime.jsx)(
|
|
139
|
+
currentEditingVariableDefinition && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.VariableEditForm, {
|
|
135
140
|
initialVariableDefinition: currentEditingVariableDefinition,
|
|
136
141
|
onChange: (definition)=>{
|
|
137
142
|
setVariableDefinitions((draft)=>{
|
|
@@ -139,7 +144,13 @@ function VariableEditor(props) {
|
|
|
139
144
|
setVariableEditIdx(null);
|
|
140
145
|
});
|
|
141
146
|
},
|
|
142
|
-
onCancel: ()=>
|
|
147
|
+
onCancel: ()=>{
|
|
148
|
+
if (variableFormAction === 'create') {
|
|
149
|
+
removeVariable(variableEditIdx);
|
|
150
|
+
}
|
|
151
|
+
setVariableEditIdx(null);
|
|
152
|
+
},
|
|
153
|
+
action: variableFormAction
|
|
143
154
|
}),
|
|
144
155
|
!currentEditingVariableDefinition && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
145
156
|
children: [
|
|
@@ -255,7 +266,7 @@ function VariableEditor(props) {
|
|
|
255
266
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_arrowDown.default, {})
|
|
256
267
|
}),
|
|
257
268
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
258
|
-
onClick: ()=>
|
|
269
|
+
onClick: ()=>editVariable(idx),
|
|
259
270
|
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencil.default, {})
|
|
260
271
|
}),
|
|
261
272
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
@@ -17,9 +17,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
17
17
|
_exportStar(require("./EditVariablesButton"), exports);
|
|
18
18
|
_exportStar(require("./TemplateVariable"), exports);
|
|
19
19
|
_exportStar(require("./VariableEditor"), exports);
|
|
20
|
-
_exportStar(require("./VariableEditorForm"), exports);
|
|
21
20
|
_exportStar(require("./VariableList"), exports);
|
|
22
|
-
_exportStar(require("./variable-model"), exports);
|
|
23
21
|
function _exportStar(from, to) {
|
|
24
22
|
Object.keys(from).forEach(function(k) {
|
|
25
23
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
@@ -23,26 +23,30 @@ const _react = require("react");
|
|
|
23
23
|
const _core = require("@perses-dev/core");
|
|
24
24
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
25
25
|
function DatasourceStoreProvider(props) {
|
|
26
|
-
const { dashboardResource , datasourceApi , onCreate , children } = props;
|
|
27
|
-
const
|
|
26
|
+
const { dashboardResource , projectName , datasourceApi , onCreate , children } = props;
|
|
27
|
+
const project = projectName !== null && projectName !== void 0 ? projectName : dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.metadata.project;
|
|
28
28
|
const { getPlugin , listPluginMetadata } = (0, _pluginSystem.usePluginRegistry)();
|
|
29
29
|
const findDatasource = (0, _core.useEvent)(async (selector)=>{
|
|
30
30
|
// Try to find it in dashboard spec
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
if (dashboardResource) {
|
|
32
|
+
const { datasources } = dashboardResource.spec;
|
|
33
|
+
const dashboardDatasource = findDashboardDatasource(datasources, selector);
|
|
34
|
+
if (dashboardDatasource !== undefined) {
|
|
35
|
+
return {
|
|
36
|
+
spec: dashboardDatasource,
|
|
37
|
+
proxyUrl: undefined
|
|
38
|
+
};
|
|
39
|
+
}
|
|
38
40
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
if (project) {
|
|
42
|
+
// Try to find it at the project level as a Datasource resource
|
|
43
|
+
const datasource = await datasourceApi.getDatasource(project, selector);
|
|
44
|
+
if (datasource !== undefined) {
|
|
45
|
+
return {
|
|
46
|
+
spec: datasource.resource.spec,
|
|
47
|
+
proxyUrl: datasource.proxyUrl
|
|
48
|
+
};
|
|
49
|
+
}
|
|
46
50
|
}
|
|
47
51
|
// Try to find it at the global level as a GlobalDatasource resource
|
|
48
52
|
const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
|
|
@@ -84,7 +88,7 @@ function DatasourceStoreProvider(props) {
|
|
|
84
88
|
const listDatasourceMetadata = (0, _core.useEvent)(async (datasourcePluginKind)=>{
|
|
85
89
|
const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
|
|
86
90
|
listPluginMetadata('Datasource'),
|
|
87
|
-
datasourceApi.listDatasources(project, datasourcePluginKind),
|
|
91
|
+
project ? datasourceApi.listDatasources(project, datasourcePluginKind) : [],
|
|
88
92
|
datasourceApi.listGlobalDatasources(datasourcePluginKind)
|
|
89
93
|
]);
|
|
90
94
|
// Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource
|
|
@@ -95,7 +99,7 @@ function DatasourceStoreProvider(props) {
|
|
|
95
99
|
// Get helper for de-duping results properly
|
|
96
100
|
const { results , addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);
|
|
97
101
|
// Start with dashboard datasources that have highest precedence
|
|
98
|
-
if (dashboardResource.spec.datasources
|
|
102
|
+
if (dashboardResource === null || dashboardResource === void 0 ? void 0 : dashboardResource.spec.datasources) {
|
|
99
103
|
for(const selectorName in dashboardResource.spec.datasources){
|
|
100
104
|
const spec = dashboardResource.spec.datasources[selectorName];
|
|
101
105
|
if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;
|
|
@@ -97,7 +97,7 @@ const DashboardApp = (props)=>{
|
|
|
97
97
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.PanelGroupDialog, {}),
|
|
98
98
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.DeletePanelGroupDialog, {}),
|
|
99
99
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.DeletePanelDialog, {}),
|
|
100
|
-
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.
|
|
100
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.DashboardDiscardChangesConfirmationDialog, {}),
|
|
101
101
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.EditJsonDialog, {}),
|
|
102
102
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.SaveChangesConfirmationDialog, {})
|
|
103
103
|
]
|
package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiscardChangesConfirmationDialog.d.ts","sourceRoot":"","sources":["../../../src/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"DiscardChangesConfirmationDialog.d.ts","sourceRoot":"","sources":["../../../src/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.tsx"],"names":[],"mappings":";AAgBA,eAAO,MAAM,yCAAyC,0BAgBrD,CAAC"}
|
package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js
CHANGED
|
@@ -10,54 +10,19 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx
|
|
14
|
-
import {
|
|
15
|
-
import CloseIcon from 'mdi-material-ui/Close';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { DiscardChangesConfirmationDialog } from '@perses-dev/components';
|
|
16
15
|
import { useDiscardChangesConfirmationDialog } from '../../context';
|
|
17
|
-
export const
|
|
16
|
+
export const DashboardDiscardChangesConfirmationDialog = ()=>{
|
|
18
17
|
const { discardChangesConfirmationDialog: dialog } = useDiscardChangesConfirmationDialog();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
/*#__PURE__*/ _jsx(IconButton, {
|
|
28
|
-
"aria-label": "Close",
|
|
29
|
-
onClick: dialog.onCancel,
|
|
30
|
-
sx: (theme)=>({
|
|
31
|
-
position: 'absolute',
|
|
32
|
-
top: theme.spacing(0.5),
|
|
33
|
-
right: theme.spacing(0.5)
|
|
34
|
-
}),
|
|
35
|
-
children: /*#__PURE__*/ _jsx(CloseIcon, {})
|
|
36
|
-
}),
|
|
37
|
-
/*#__PURE__*/ _jsx(DialogContent, {
|
|
38
|
-
dividers: true,
|
|
39
|
-
sx: {
|
|
40
|
-
width: '500px'
|
|
41
|
-
},
|
|
42
|
-
children: dialog.description || 'You have unsaved changes in this dashboard. Are you sure you want to discard these changes? Changes cannot be recovered.'
|
|
43
|
-
}),
|
|
44
|
-
/*#__PURE__*/ _jsxs(DialogActions, {
|
|
45
|
-
children: [
|
|
46
|
-
/*#__PURE__*/ _jsx(Button, {
|
|
47
|
-
variant: "contained",
|
|
48
|
-
onClick: dialog.onDiscardChanges,
|
|
49
|
-
children: "Discard Changes"
|
|
50
|
-
}),
|
|
51
|
-
/*#__PURE__*/ _jsx(Button, {
|
|
52
|
-
variant: "outlined",
|
|
53
|
-
color: "secondary",
|
|
54
|
-
onClick: dialog.onCancel,
|
|
55
|
-
children: "Cancel"
|
|
56
|
-
})
|
|
57
|
-
]
|
|
58
|
-
})
|
|
59
|
-
]
|
|
60
|
-
})
|
|
18
|
+
if (dialog === undefined) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
return /*#__PURE__*/ _jsx(DiscardChangesConfirmationDialog, {
|
|
22
|
+
description: dialog.description || 'You have unsaved changes in this dashboard. Are you sure you want to discard these changes? Changes cannot be recovered.',
|
|
23
|
+
isOpen: true,
|
|
24
|
+
onCancel: dialog.onCancel,
|
|
25
|
+
onDiscardChanges: dialog.onDiscardChanges
|
|
61
26
|
});
|
|
62
27
|
};
|
|
63
28
|
|
package/dist/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/DiscardChangesConfirmationDialog/DiscardChangesConfirmationDialog.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 { DiscardChangesConfirmationDialog } from '@perses-dev/components';\nimport { useDiscardChangesConfirmationDialog } from '../../context';\n\nexport const DashboardDiscardChangesConfirmationDialog = () => {\n const { discardChangesConfirmationDialog: dialog } = useDiscardChangesConfirmationDialog();\n if (dialog === undefined) {\n return null;\n }\n return (\n <DiscardChangesConfirmationDialog\n description={\n dialog.description ||\n 'You have unsaved changes in this dashboard. Are you sure you want to discard these changes? Changes cannot be recovered.'\n }\n isOpen={true}\n onCancel={dialog.onCancel}\n onDiscardChanges={dialog.onDiscardChanges}\n />\n );\n};\n"],"names":["DiscardChangesConfirmationDialog","useDiscardChangesConfirmationDialog","DashboardDiscardChangesConfirmationDialog","discardChangesConfirmationDialog","dialog","undefined","description","isOpen","onCancel","onDiscardChanges"],"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,gCAAgC,QAAQ,wBAAwB,CAAC;AAC1E,SAASC,mCAAmC,QAAQ,eAAe,CAAC;AAEpE,OAAO,MAAMC,yCAAyC,GAAG,IAAM;IAC7D,MAAM,EAAEC,gCAAgC,EAAEC,MAAM,CAAA,EAAE,GAAGH,mCAAmC,EAAE,AAAC;IAC3F,IAAIG,MAAM,KAAKC,SAAS,EAAE;QACxB,OAAO,IAAI,CAAC;IACd,CAAC;IACD,qBACE,KAACL,gCAAgC;QAC/BM,WAAW,EACTF,MAAM,CAACE,WAAW,IAClB,0HAA0H;QAE5HC,MAAM,EAAE,IAAI;QACZC,QAAQ,EAAEJ,MAAM,CAACI,QAAQ;QACzBC,gBAAgB,EAAEL,MAAM,CAACK,gBAAgB;MACzC,CACF;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/index.ts"],"names":[],"mappings":"AAaA,cAAc,cAAc,CAAC;AAC7B,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/index.ts"],"names":[],"mappings":"AAaA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
export * from './
|
|
13
|
+
export * from './GridContainer';
|
|
14
14
|
export * from './GridItemContent';
|
|
15
|
+
export * from './GridLayout';
|
|
16
|
+
export * from './GridTitle';
|
|
15
17
|
|
|
16
18
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/GridLayout/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 './
|
|
1
|
+
{"version":3,"sources":["../../../src/components/GridLayout/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 './GridContainer';\nexport * from './GridItemContent';\nexport * from './GridLayout';\nexport * from './GridTitle';\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,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TemplateVariable.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/TemplateVariable.tsx"],"names":[],"mappings":";AAeA,OAAO,EAA6C,YAAY,EAAiB,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"TemplateVariable.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/TemplateVariable.tsx"],"names":[],"mappings":";AAeA,OAAO,EAA6C,YAAY,EAAiB,MAAM,kBAAkB,CAAC;AAI1G,aAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE,qBAAqB,eAW/D"}
|
|
@@ -14,8 +14,8 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
14
14
|
import { useEffect, useMemo, useState } from 'react';
|
|
15
15
|
import { Select, FormControl, InputLabel, MenuItem, Box, LinearProgress, TextField } from '@mui/material';
|
|
16
16
|
import { DEFAULT_ALL_VALUE } from '@perses-dev/core';
|
|
17
|
+
import { useListVariablePluginValues } from '@perses-dev/plugin-system';
|
|
17
18
|
import { useTemplateVariable, useTemplateVariableActions } from '../../context';
|
|
18
|
-
import { useListVariablePluginValues } from './variable-model';
|
|
19
19
|
export function TemplateVariable({ name }) {
|
|
20
20
|
var ref;
|
|
21
21
|
const ctx = useTemplateVariable(name);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/Variables/TemplateVariable.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 { useEffect, useMemo, useState } from 'react';\nimport { Select, FormControl, InputLabel, MenuItem, Box, LinearProgress, TextField } from '@mui/material';\nimport { DEFAULT_ALL_VALUE, ListVariableDefinition, VariableName, VariableValue } from '@perses-dev/core';\nimport { useTemplateVariable, useTemplateVariableActions } from '../../context';\nimport { useListVariablePluginValues } from './variable-model';\ntype TemplateVariableProps = {\n name: VariableName;\n};\n\nexport function TemplateVariable({ name }: TemplateVariableProps) {\n const ctx = useTemplateVariable(name);\n const kind = ctx.definition?.kind;\n switch (kind) {\n case 'TextVariable':\n return <TextVariable name={name} />;\n case 'ListVariable':\n return <ListVariable name={name} />;\n }\n\n return <div>Unsupported Variable Kind: ${kind}</div>;\n}\n\nfunction ListVariable({ name }: TemplateVariableProps) {\n const ctx = useTemplateVariable(name);\n const definition = ctx.definition as ListVariableDefinition;\n const variablesOptionsQuery = useListVariablePluginValues(definition);\n const { setVariableValue, setVariableLoading, setVariableOptions } = useTemplateVariableActions();\n\n const allowMultiple = definition?.spec.allow_multiple === true;\n const allowAllValue = definition?.spec.allow_all_value === true;\n const title = definition?.spec.display?.name ?? name;\n\n useEffect(() => {\n setVariableLoading(name, variablesOptionsQuery.isFetching);\n if (variablesOptionsQuery.data) {\n setVariableOptions(name, variablesOptionsQuery.data);\n }\n }, [variablesOptionsQuery, name, setVariableLoading, setVariableOptions]);\n\n let value = ctx.state?.value;\n const options = ctx.state?.options;\n const loading = ctx.state?.loading;\n\n // Make sure value is an array if allowMultiple is true\n if (allowMultiple && !Array.isArray(value)) {\n value = typeof value === 'string' ? [value] : [];\n }\n\n const finalOptions = useMemo(() => {\n let computedOptions = options ? [...options] : [];\n\n // Add the all value if it's allowed\n if (allowAllValue) {\n computedOptions = [{ value: DEFAULT_ALL_VALUE, label: 'All' }, ...computedOptions];\n }\n return computedOptions;\n }, [options, allowAllValue]);\n\n const valueIsInOptions = useMemo(\n () =>\n Boolean(\n finalOptions.find((v) => {\n if (allowMultiple) {\n return (value as string[]).includes(v.value);\n }\n return value === v.value;\n })\n ),\n [finalOptions, value, allowMultiple]\n );\n\n let selectValue = value;\n if (!valueIsInOptions) {\n selectValue = allowMultiple ? [] : '';\n }\n\n useEffect(() => {\n const firstOption = finalOptions?.[0];\n\n // If there is no value but there are options, set the value to the first option.\n if (!value && firstOption) {\n setVariableValue(name, firstOption.value);\n }\n }, [finalOptions, setVariableValue, value, name, allowMultiple]);\n\n return (\n <Box display={'flex'}>\n <FormControl fullWidth>\n <InputLabel id={name}>{title}</InputLabel>\n <Select\n sx={{ minWidth: 100, maxWidth: 250 }}\n id={name}\n label={title}\n value={selectValue}\n onChange={(e) => {\n // Must be selected\n if (e.target.value === null || e.target.value.length === 0) {\n if (allowAllValue) {\n setVariableValue(name, DEFAULT_ALL_VALUE);\n }\n return;\n }\n setVariableValue(name, e.target.value as VariableValue);\n }}\n multiple={allowMultiple}\n >\n {loading && (\n <MenuItem value=\"loading\" disabled>\n Loading\n </MenuItem>\n )}\n\n {finalOptions.length === 0 && (\n <MenuItem value=\"empty\" disabled>\n No options\n </MenuItem>\n )}\n {finalOptions.map((option) => (\n <MenuItem key={option.value} value={option.value}>\n {option.label}\n </MenuItem>\n ))}\n </Select>\n {loading && <LinearProgress />}\n </FormControl>\n </Box>\n );\n}\n\nfunction TextVariable({ name }: TemplateVariableProps) {\n const { state, definition } = useTemplateVariable(name);\n const [tempValue, setTempValue] = useState(state?.value ?? '');\n const { setVariableValue } = useTemplateVariableActions();\n\n useEffect(() => {\n setTempValue(state?.value ?? '');\n }, [state?.value]);\n\n return (\n <TextField\n value={tempValue}\n onChange={(e) => setTempValue(e.target.value)}\n onBlur={() => setVariableValue(name, tempValue)}\n placeholder={name}\n label={definition?.spec.display?.name ?? name}\n />\n );\n}\n"],"names":["useEffect","useMemo","useState","Select","FormControl","InputLabel","MenuItem","Box","LinearProgress","TextField","DEFAULT_ALL_VALUE","useTemplateVariable","useTemplateVariableActions","useListVariablePluginValues","TemplateVariable","name","ctx","kind","definition","TextVariable","ListVariable","div","variablesOptionsQuery","setVariableValue","setVariableLoading","setVariableOptions","allowMultiple","spec","allow_multiple","allowAllValue","allow_all_value","title","display","isFetching","data","value","state","options","loading","Array","isArray","finalOptions","computedOptions","label","valueIsInOptions","Boolean","find","v","includes","selectValue","firstOption","fullWidth","id","sx","minWidth","maxWidth","onChange","e","target","length","multiple","disabled","map","option","tempValue","setTempValue","onBlur","placeholder"],"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,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrD,SAASC,MAAM,EAAEC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,cAAc,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAC1G,SAASC,iBAAiB,QAA6D,kBAAkB,CAAC;AAC1G,SAASC,mBAAmB,EAAEC,0BAA0B,QAAQ,eAAe,CAAC;AAChF,SAASC,2BAA2B,QAAQ,kBAAkB,CAAC;AAK/D,OAAO,SAASC,gBAAgB,CAAC,EAAEC,IAAI,CAAA,EAAyB,EAAE;QAEnDC,GAAc;IAD3B,MAAMA,GAAG,GAAGL,mBAAmB,CAACI,IAAI,CAAC,AAAC;IACtC,MAAME,IAAI,GAAGD,CAAAA,GAAc,GAAdA,GAAG,CAACE,UAAU,cAAdF,GAAc,WAAM,GAApBA,KAAAA,CAAoB,GAApBA,GAAc,CAAEC,IAAI,AAAC;IAClC,OAAQA,IAAI;QACV,KAAK,cAAc;YACjB,qBAAO,KAACE,YAAY;gBAACJ,IAAI,EAAEA,IAAI;cAAI,CAAC;QACtC,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AAI,EAAE,CAAC,AAAC;IAC/D,MAAM,EAAEb,gBAAgB,CAAA,EAAE,GAAGX,0BAA0B,EAAE,AAAC;IAE1DZ,SAAS,CAAC,IAAM;YACDoC,GAAY;QAAzB6B,YAAY,CAAC7B,CAAAA,GAAY,GAAZA,KAAK,aAALA,KAAK,WAAO,GAAZA,KAAAA,CAAY,GAAZA,KAAK,CAAED,KAAK,cAAZC,GAAY,cAAZA,GAAY,GAAI,EAAE,CAAC,CAAC;IACnC,CAAC,EAAE;QAACA,KAAK,aAALA,KAAK,WAAO,GAAZA,KAAAA,CAAY,GAAZA,KAAK,CAAED,KAAK;KAAC,CAAC,CAAC;QAQRjB,IAA8B;IANzC,qBACE,KAACT,SAAS;QACR0B,KAAK,EAAE6B,SAAS;QAChBR,QAAQ,EAAE,CAACC,CAAC,GAAKQ,YAAY,CAACR,CAAC,CAACC,MAAM,CAACvB,KAAK,CAAC;QAC7C+B,MAAM,EAAE,IAAM3C,gBAAgB,CAACR,IAAI,EAAEiD,SAAS,CAAC;QAC/CG,WAAW,EAAEpD,IAAI;QACjB4B,KAAK,EAAEzB,CAAAA,IAA8B,GAA9BA,OAAAA,UAAU,aAAVA,UAAU,WAAM,GAAhBA,KAAAA,CAAgB,GAAhBA,UAAU,CAAES,IAAI,CAACK,OAAO,4BAAM,GAA9Bd,KAAAA,CAA8B,OAAJH,IAAI,cAA9BG,IAA8B,cAA9BA,IAA8B,GAAIH,IAAI;MAC7C,CACF;AACJ,CAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Variables/TemplateVariable.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 { useEffect, useMemo, useState } from 'react';\nimport { Select, FormControl, InputLabel, MenuItem, Box, LinearProgress, TextField } from '@mui/material';\nimport { DEFAULT_ALL_VALUE, ListVariableDefinition, VariableName, VariableValue } from '@perses-dev/core';\nimport { useListVariablePluginValues } from '@perses-dev/plugin-system';\nimport { useTemplateVariable, useTemplateVariableActions } from '../../context';\n\ntype TemplateVariableProps = {\n name: VariableName;\n};\n\nexport function TemplateVariable({ name }: TemplateVariableProps) {\n const ctx = useTemplateVariable(name);\n const kind = ctx.definition?.kind;\n switch (kind) {\n case 'TextVariable':\n return <TextVariable name={name} />;\n case 'ListVariable':\n return <ListVariable name={name} />;\n }\n\n return <div>Unsupported Variable Kind: ${kind}</div>;\n}\n\nfunction ListVariable({ name }: TemplateVariableProps) {\n const ctx = useTemplateVariable(name);\n const definition = ctx.definition as ListVariableDefinition;\n const variablesOptionsQuery = useListVariablePluginValues(definition);\n const { setVariableValue, setVariableLoading, setVariableOptions } = useTemplateVariableActions();\n\n const allowMultiple = definition?.spec.allow_multiple === true;\n const allowAllValue = definition?.spec.allow_all_value === true;\n const title = definition?.spec.display?.name ?? name;\n\n useEffect(() => {\n setVariableLoading(name, variablesOptionsQuery.isFetching);\n if (variablesOptionsQuery.data) {\n setVariableOptions(name, variablesOptionsQuery.data);\n }\n }, [variablesOptionsQuery, name, setVariableLoading, setVariableOptions]);\n\n let value = ctx.state?.value;\n const options = ctx.state?.options;\n const loading = ctx.state?.loading;\n\n // Make sure value is an array if allowMultiple is true\n if (allowMultiple && !Array.isArray(value)) {\n value = typeof value === 'string' ? [value] : [];\n }\n\n const finalOptions = useMemo(() => {\n let computedOptions = options ? [...options] : [];\n\n // Add the all value if it's allowed\n if (allowAllValue) {\n computedOptions = [{ value: DEFAULT_ALL_VALUE, label: 'All' }, ...computedOptions];\n }\n return computedOptions;\n }, [options, allowAllValue]);\n\n const valueIsInOptions = useMemo(\n () =>\n Boolean(\n finalOptions.find((v) => {\n if (allowMultiple) {\n return (value as string[]).includes(v.value);\n }\n return value === v.value;\n })\n ),\n [finalOptions, value, allowMultiple]\n );\n\n let selectValue = value;\n if (!valueIsInOptions) {\n selectValue = allowMultiple ? [] : '';\n }\n\n useEffect(() => {\n const firstOption = finalOptions?.[0];\n\n // If there is no value but there are options, set the value to the first option.\n if (!value && firstOption) {\n setVariableValue(name, firstOption.value);\n }\n }, [finalOptions, setVariableValue, value, name, allowMultiple]);\n\n return (\n <Box display={'flex'}>\n <FormControl fullWidth>\n <InputLabel id={name}>{title}</InputLabel>\n <Select\n sx={{ minWidth: 100, maxWidth: 250 }}\n id={name}\n label={title}\n value={selectValue}\n onChange={(e) => {\n // Must be selected\n if (e.target.value === null || e.target.value.length === 0) {\n if (allowAllValue) {\n setVariableValue(name, DEFAULT_ALL_VALUE);\n }\n return;\n }\n setVariableValue(name, e.target.value as VariableValue);\n }}\n multiple={allowMultiple}\n >\n {loading && (\n <MenuItem value=\"loading\" disabled>\n Loading\n </MenuItem>\n )}\n\n {finalOptions.length === 0 && (\n <MenuItem value=\"empty\" disabled>\n No options\n </MenuItem>\n )}\n {finalOptions.map((option) => (\n <MenuItem key={option.value} value={option.value}>\n {option.label}\n </MenuItem>\n ))}\n </Select>\n {loading && <LinearProgress />}\n </FormControl>\n </Box>\n );\n}\n\nfunction TextVariable({ name }: TemplateVariableProps) {\n const { state, definition } = useTemplateVariable(name);\n const [tempValue, setTempValue] = useState(state?.value ?? '');\n const { setVariableValue } = useTemplateVariableActions();\n\n useEffect(() => {\n setTempValue(state?.value ?? '');\n }, [state?.value]);\n\n return (\n <TextField\n value={tempValue}\n onChange={(e) => setTempValue(e.target.value)}\n onBlur={() => setVariableValue(name, tempValue)}\n placeholder={name}\n label={definition?.spec.display?.name ?? name}\n />\n );\n}\n"],"names":["useEffect","useMemo","useState","Select","FormControl","InputLabel","MenuItem","Box","LinearProgress","TextField","DEFAULT_ALL_VALUE","useListVariablePluginValues","useTemplateVariable","useTemplateVariableActions","TemplateVariable","name","ctx","kind","definition","TextVariable","ListVariable","div","variablesOptionsQuery","setVariableValue","setVariableLoading","setVariableOptions","allowMultiple","spec","allow_multiple","allowAllValue","allow_all_value","title","display","isFetching","data","value","state","options","loading","Array","isArray","finalOptions","computedOptions","label","valueIsInOptions","Boolean","find","v","includes","selectValue","firstOption","fullWidth","id","sx","minWidth","maxWidth","onChange","e","target","length","multiple","disabled","map","option","tempValue","setTempValue","onBlur","placeholder"],"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,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrD,SAASC,MAAM,EAAEC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,cAAc,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAC1G,SAASC,iBAAiB,QAA6D,kBAAkB,CAAC;AAC1G,SAASC,2BAA2B,QAAQ,2BAA2B,CAAC;AACxE,SAASC,mBAAmB,EAAEC,0BAA0B,QAAQ,eAAe,CAAC;AAMhF,OAAO,SAASC,gBAAgB,CAAC,EAAEC,IAAI,CAAA,EAAyB,EAAE;QAEnDC,GAAc;IAD3B,MAAMA,GAAG,GAAGJ,mBAAmB,CAACG,IAAI,CAAC,AAAC;IACtC,MAAME,IAAI,GAAGD,CAAAA,GAAc,GAAdA,GAAG,CAACE,UAAU,cAAdF,GAAc,WAAM,GAApBA,KAAAA,CAAoB,GAApBA,GAAc,CAAEC,IAAI,AAAC;IAClC,OAAQA,IAAI;QACV,KAAK,cAAc;YACjB,qBAAO,KAACE,YAAY;gBAACJ,IAAI,EAAEA,IAAI;cAAI,CAAC;QACtC,KAAK,cAAc;YACjB,qBAAO,KAACK,YAAY;gBAACL,IA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BAAgB,CAAA,EAAE,GAAGV,0BAA0B,EAAE,AAAC;IAE1Db,SAAS,CAAC,IAAM;YACDoC,GAAY;QAAzB6B,YAAY,CAAC7B,CAAAA,GAAY,GAAZA,KAAK,aAALA,KAAK,WAAO,GAAZA,KAAAA,CAAY,GAAZA,KAAK,CAAED,KAAK,cAAZC,GAAY,cAAZA,GAAY,GAAI,EAAE,CAAC,CAAC;IACnC,CAAC,EAAE;QAACA,KAAK,aAALA,KAAK,WAAO,GAAZA,KAAAA,CAAY,GAAZA,KAAK,CAAED,KAAK;KAAC,CAAC,CAAC;QAQRjB,IAA8B;IANzC,qBACE,KAACT,SAAS;QACR0B,KAAK,EAAE6B,SAAS;QAChBR,QAAQ,EAAE,CAACC,CAAC,GAAKQ,YAAY,CAACR,CAAC,CAACC,MAAM,CAACvB,KAAK,CAAC;QAC7C+B,MAAM,EAAE,IAAM3C,gBAAgB,CAACR,IAAI,EAAEiD,SAAS,CAAC;QAC/CG,WAAW,EAAEpD,IAAI;QACjB4B,KAAK,EAAEzB,CAAAA,IAA8B,GAA9BA,OAAAA,UAAU,aAAVA,UAAU,WAAM,GAAhBA,KAAAA,CAAgB,GAAhBA,UAAU,CAAES,IAAI,CAACK,OAAO,4BAAM,GAA9Bd,KAAAA,CAA8B,OAAJH,IAAI,cAA9BG,IAA8B,cAA9BA,IAA8B,GAAIH,IAAI;MAC7C,CACF;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableEditor.tsx"],"names":[],"mappings":";AA+BA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"VariableEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableEditor.tsx"],"names":[],"mappings":";AA+BA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AA4BtD,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,QAAQ,EAAE,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAC9D,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,eA4MA"}
|
|
@@ -19,9 +19,8 @@ import PencilIcon from 'mdi-material-ui/Pencil';
|
|
|
19
19
|
import TrashIcon from 'mdi-material-ui/TrashCan';
|
|
20
20
|
import ArrowUp from 'mdi-material-ui/ArrowUp';
|
|
21
21
|
import ArrowDown from 'mdi-material-ui/ArrowDown';
|
|
22
|
+
import { VariableEditForm, VARIABLE_TYPES } from '@perses-dev/plugin-system';
|
|
22
23
|
import { useDiscardChangesConfirmationDialog } from '../../context';
|
|
23
|
-
import { VariableEditForm } from './VariableEditorForm';
|
|
24
|
-
import { VARIABLE_TYPES } from './variable-model';
|
|
25
24
|
function getVariableLabelByKind(kind) {
|
|
26
25
|
var ref;
|
|
27
26
|
return (ref = VARIABLE_TYPES.find((variableType)=>variableType.kind === kind)) === null || ref === void 0 ? void 0 : ref.label;
|
|
@@ -41,6 +40,7 @@ function getValidation(variableDefinitions) {
|
|
|
41
40
|
export function VariableEditor(props) {
|
|
42
41
|
const [variableDefinitions, setVariableDefinitions] = useImmer(props.variableDefinitions);
|
|
43
42
|
const [variableEditIdx, setVariableEditIdx] = useState(null);
|
|
43
|
+
const [variableFormAction, setVariableFormAction] = useState('update');
|
|
44
44
|
const validation = useMemo(()=>getValidation(variableDefinitions), [
|
|
45
45
|
variableDefinitions
|
|
46
46
|
]);
|
|
@@ -68,6 +68,7 @@ export function VariableEditor(props) {
|
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
70
|
const addVariable = ()=>{
|
|
71
|
+
setVariableFormAction('create');
|
|
71
72
|
setVariableDefinitions((draft)=>{
|
|
72
73
|
draft.push({
|
|
73
74
|
kind: 'TextVariable',
|
|
@@ -79,6 +80,10 @@ export function VariableEditor(props) {
|
|
|
79
80
|
});
|
|
80
81
|
setVariableEditIdx(variableDefinitions.length);
|
|
81
82
|
};
|
|
83
|
+
const editVariable = (index)=>{
|
|
84
|
+
setVariableFormAction('update');
|
|
85
|
+
setVariableEditIdx(index);
|
|
86
|
+
};
|
|
82
87
|
const toggleVariableVisibility = (index, visible)=>{
|
|
83
88
|
setVariableDefinitions((draft)=>{
|
|
84
89
|
const v = draft[index];
|
|
@@ -126,7 +131,13 @@ export function VariableEditor(props) {
|
|
|
126
131
|
setVariableEditIdx(null);
|
|
127
132
|
});
|
|
128
133
|
},
|
|
129
|
-
onCancel: ()=>
|
|
134
|
+
onCancel: ()=>{
|
|
135
|
+
if (variableFormAction === 'create') {
|
|
136
|
+
removeVariable(variableEditIdx);
|
|
137
|
+
}
|
|
138
|
+
setVariableEditIdx(null);
|
|
139
|
+
},
|
|
140
|
+
action: variableFormAction
|
|
130
141
|
}),
|
|
131
142
|
!currentEditingVariableDefinition && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
132
143
|
children: [
|
|
@@ -242,7 +253,7 @@ export function VariableEditor(props) {
|
|
|
242
253
|
children: /*#__PURE__*/ _jsx(ArrowDown, {})
|
|
243
254
|
}),
|
|
244
255
|
/*#__PURE__*/ _jsx(IconButton, {
|
|
245
|
-
onClick: ()=>
|
|
256
|
+
onClick: ()=>editVariable(idx),
|
|
246
257
|
children: /*#__PURE__*/ _jsx(PencilIcon, {})
|
|
247
258
|
}),
|
|
248
259
|
/*#__PURE__*/ _jsx(IconButton, {
|