@perses-dev/dashboards 0.53.0-beta.0 → 0.53.0-beta.2
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/GridLayout/GridItemContent.js +3 -3
- package/dist/cjs/components/GridLayout/GridLayout.js +1 -1
- package/dist/cjs/components/Panel/Panel.js +4 -3
- package/dist/cjs/components/Panel/PanelActions.js +5 -3
- package/dist/cjs/components/Panel/PanelHeader.js +1 -9
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +165 -196
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +2 -23
- package/dist/cjs/components/PanelDrawer/PanelQueriesSharedControls.js +80 -0
- package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +18 -6
- package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +11 -6
- package/dist/cjs/components/Variables/Variable.js +34 -0
- package/dist/cjs/components/Variables/VariableEditor.js +15 -22
- package/dist/cjs/components/Variables/VariableList.js +2 -2
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +1 -1
- package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +1 -1
- package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +1 -1
- package/dist/cjs/context/DashboardProvider/index.js +1 -1
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +1 -1
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +1 -7
- package/dist/cjs/context/DashboardProvider/view-panel-slice.js +1 -1
- package/dist/cjs/context/DatasourceStoreProvider.js +3 -4
- package/dist/cjs/context/VariableProvider/VariableProvider.js +1 -1
- package/dist/cjs/context/VariableProvider/hydrationUtils.js +1 -1
- package/dist/cjs/context/VariableProvider/index.js +1 -1
- package/dist/cjs/context/VariableProvider/utils.js +1 -1
- package/dist/cjs/context/useDashboard.js +1 -1
- package/dist/cjs/utils/panelUtils.js +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +2 -2
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +1 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/Row.d.ts +2 -2
- package/dist/components/GridLayout/Row.d.ts.map +1 -1
- package/dist/components/GridLayout/Row.js.map +1 -1
- package/dist/components/Panel/Panel.d.ts +1 -2
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +5 -4
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/PanelActions.d.ts.map +1 -1
- package/dist/components/Panel/PanelActions.js +5 -3
- package/dist/components/Panel/PanelActions.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
- package/dist/components/Panel/PanelHeader.js +2 -10
- package/dist/components/Panel/PanelHeader.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +167 -198
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.js +2 -23
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.d.ts +13 -0
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.js +74 -0
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.js.map +1 -0
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +19 -7
- package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -1
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js +11 -6
- package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
- package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
- package/dist/components/Variables/EditVariablesButton.js.map +1 -1
- package/dist/components/Variables/Variable.js +37 -2
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts +1 -2
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditor.js +17 -24
- package/dist/components/Variables/VariableEditor.js.map +1 -1
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +2 -2
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -2
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js +1 -1
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.js +1 -1
- package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.js +1 -1
- package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
- package/dist/context/DashboardProvider/index.d.ts +0 -1
- package/dist/context/DashboardProvider/index.d.ts.map +1 -1
- package/dist/context/DashboardProvider/index.js +1 -1
- package/dist/context/DashboardProvider/index.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -2
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -24
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +1 -6
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +2 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.js +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
- package/dist/context/DatasourceStoreProvider.d.ts +1 -17
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +2 -3
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts +2 -2
- package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts.map +1 -1
- package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.d.ts +1 -10
- package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.js +1 -1
- package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
- package/dist/context/VariableProvider/hydrationUtils.d.ts +1 -2
- package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -1
- package/dist/context/VariableProvider/hydrationUtils.js +1 -1
- package/dist/context/VariableProvider/hydrationUtils.js.map +1 -1
- package/dist/context/VariableProvider/index.js +1 -1
- package/dist/context/VariableProvider/index.js.map +1 -1
- package/dist/context/VariableProvider/utils.d.ts +1 -2
- package/dist/context/VariableProvider/utils.d.ts.map +1 -1
- package/dist/context/VariableProvider/utils.js +1 -1
- package/dist/context/VariableProvider/utils.js.map +1 -1
- package/dist/context/useDashboard.d.ts.map +1 -1
- package/dist/context/useDashboard.js +1 -1
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/utils/panelUtils.d.ts +1 -2
- package/dist/utils/panelUtils.d.ts.map +1 -1
- package/dist/utils/panelUtils.js +1 -1
- package/dist/utils/panelUtils.js.map +1 -1
- package/package.json +5 -5
|
@@ -13,15 +13,14 @@
|
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
15
15
|
import { Box, Button, Grid, MenuItem, Stack, TextField, Typography } from '@mui/material';
|
|
16
|
-
import { DEFAULT_DASHBOARD_DURATION } from '@perses-dev/core';
|
|
17
16
|
import { DiscardChangesConfirmationDialog, ErrorAlert, ErrorBoundary } from '@perses-dev/components';
|
|
18
|
-
import { PluginKindSelect, usePluginEditor,
|
|
17
|
+
import { PluginKindSelect, usePluginEditor, getTitleAction, getSubmitText, useValidationSchemas } from '@perses-dev/plugin-system';
|
|
19
18
|
import { Controller, FormProvider, useForm, useWatch } from 'react-hook-form';
|
|
20
19
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
21
|
-
import {
|
|
20
|
+
import { useListPanelGroups } from '../../context';
|
|
22
21
|
import { PanelEditorProvider } from '../../context/PanelEditorProvider/PanelEditorProvider';
|
|
23
|
-
import { PanelPreview } from './PanelPreview';
|
|
24
22
|
import { usePanelEditor } from './usePanelEditor';
|
|
23
|
+
import { PanelQueriesSharedControls } from './PanelQueriesSharedControls';
|
|
25
24
|
export function PanelEditorForm(props) {
|
|
26
25
|
const { initialValues, initialAction, onSave, onClose } = props;
|
|
27
26
|
const pluginEditorRef = useRef(null);
|
|
@@ -35,9 +34,6 @@ export function PanelEditorForm(props) {
|
|
|
35
34
|
mode: 'onBlur',
|
|
36
35
|
defaultValues: initialValues
|
|
37
36
|
});
|
|
38
|
-
const { dashboard } = useDashboard();
|
|
39
|
-
const dashboardDuration = dashboard?.kind === 'Dashboard' ? dashboard.spec.duration : DEFAULT_DASHBOARD_DURATION;
|
|
40
|
-
const initialTimeRange = useInitialTimeRange(dashboardDuration);
|
|
41
37
|
// Use common plugin editor logic even though we've split the inputs up in this form
|
|
42
38
|
const pluginEditor = usePluginEditor({
|
|
43
39
|
pluginTypes: [
|
|
@@ -113,7 +109,6 @@ export function PanelEditorForm(props) {
|
|
|
113
109
|
control: form.control,
|
|
114
110
|
name: 'panelDefinition.spec.plugin.kind'
|
|
115
111
|
});
|
|
116
|
-
const { timeRange } = useTimeRangeParams(initialTimeRange);
|
|
117
112
|
const handleSubmit = useCallback(()=>{
|
|
118
113
|
pluginEditorRef.current?.flushChanges?.();
|
|
119
114
|
form.handleSubmit(processForm)();
|
|
@@ -121,204 +116,178 @@ export function PanelEditorForm(props) {
|
|
|
121
116
|
form,
|
|
122
117
|
processForm
|
|
123
118
|
]);
|
|
124
|
-
return /*#__PURE__*/ _jsx(
|
|
125
|
-
|
|
126
|
-
children: /*#__PURE__*/
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
/*#__PURE__*/ _jsxs(Typography, {
|
|
139
|
-
variant: "h2",
|
|
140
|
-
children: [
|
|
141
|
-
titleAction,
|
|
142
|
-
" Panel"
|
|
143
|
-
]
|
|
144
|
-
}),
|
|
145
|
-
/*#__PURE__*/ _jsxs(Stack, {
|
|
146
|
-
direction: "row",
|
|
147
|
-
spacing: 1,
|
|
148
|
-
marginLeft: "auto",
|
|
149
|
-
children: [
|
|
150
|
-
/*#__PURE__*/ _jsx(Button, {
|
|
151
|
-
variant: "contained",
|
|
152
|
-
disabled: !form.formState.isValid,
|
|
153
|
-
onClick: handleSubmit,
|
|
154
|
-
children: submitText
|
|
155
|
-
}),
|
|
156
|
-
/*#__PURE__*/ _jsx(Button, {
|
|
157
|
-
color: "secondary",
|
|
158
|
-
variant: "outlined",
|
|
159
|
-
onClick: handleCancel,
|
|
160
|
-
children: "Cancel"
|
|
161
|
-
})
|
|
162
|
-
]
|
|
163
|
-
})
|
|
164
|
-
]
|
|
165
|
-
}),
|
|
166
|
-
/*#__PURE__*/ _jsx(Box, {
|
|
167
|
-
id: panelEditorFormId,
|
|
168
|
-
sx: {
|
|
169
|
-
flex: 1,
|
|
170
|
-
overflowY: 'scroll',
|
|
171
|
-
padding: (theme)=>theme.spacing(2)
|
|
172
|
-
},
|
|
173
|
-
children: /*#__PURE__*/ _jsxs(Grid, {
|
|
174
|
-
container: true,
|
|
175
|
-
spacing: 2,
|
|
119
|
+
return /*#__PURE__*/ _jsx(FormProvider, {
|
|
120
|
+
...form,
|
|
121
|
+
children: /*#__PURE__*/ _jsxs(PanelEditorProvider, {
|
|
122
|
+
children: [
|
|
123
|
+
/*#__PURE__*/ _jsxs(Box, {
|
|
124
|
+
sx: {
|
|
125
|
+
display: 'flex',
|
|
126
|
+
alignItems: 'center',
|
|
127
|
+
padding: (theme)=>theme.spacing(1, 2),
|
|
128
|
+
borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
|
|
129
|
+
},
|
|
130
|
+
children: [
|
|
131
|
+
/*#__PURE__*/ _jsxs(Typography, {
|
|
132
|
+
variant: "h2",
|
|
176
133
|
children: [
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
onChange: (event)=>{
|
|
192
|
-
field.onChange(event);
|
|
193
|
-
setName(event.target.value);
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
})
|
|
197
|
-
}),
|
|
198
|
-
/*#__PURE__*/ _jsx(Grid, {
|
|
199
|
-
item: true,
|
|
200
|
-
xs: 4,
|
|
201
|
-
children: /*#__PURE__*/ _jsx(Controller, {
|
|
202
|
-
control: form.control,
|
|
203
|
-
name: "groupId",
|
|
204
|
-
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
205
|
-
select: true,
|
|
206
|
-
...field,
|
|
207
|
-
required: true,
|
|
208
|
-
fullWidth: true,
|
|
209
|
-
label: "Group",
|
|
210
|
-
error: !!fieldState.error,
|
|
211
|
-
helperText: fieldState.error?.message,
|
|
212
|
-
onChange: (event)=>{
|
|
213
|
-
field.onChange(event);
|
|
214
|
-
},
|
|
215
|
-
children: panelGroups.map((panelGroup, index)=>/*#__PURE__*/ _jsx(MenuItem, {
|
|
216
|
-
value: panelGroup.id,
|
|
217
|
-
children: panelGroup.title ?? `Group ${index + 1}`
|
|
218
|
-
}, panelGroup.id))
|
|
219
|
-
})
|
|
220
|
-
})
|
|
221
|
-
}),
|
|
222
|
-
/*#__PURE__*/ _jsx(Grid, {
|
|
223
|
-
item: true,
|
|
224
|
-
xs: 8,
|
|
225
|
-
children: /*#__PURE__*/ _jsx(Controller, {
|
|
226
|
-
control: form.control,
|
|
227
|
-
name: "panelDefinition.spec.display.description",
|
|
228
|
-
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
229
|
-
...field,
|
|
230
|
-
fullWidth: true,
|
|
231
|
-
label: "Description",
|
|
232
|
-
error: !!fieldState.error,
|
|
233
|
-
helperText: fieldState.error?.message,
|
|
234
|
-
value: watchedDescription ?? '',
|
|
235
|
-
onChange: (event)=>{
|
|
236
|
-
field.onChange(event);
|
|
237
|
-
setDescription(event.target.value);
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
})
|
|
241
|
-
}),
|
|
242
|
-
/*#__PURE__*/ _jsx(Grid, {
|
|
243
|
-
item: true,
|
|
244
|
-
xs: 4,
|
|
245
|
-
children: /*#__PURE__*/ _jsx(Controller, {
|
|
246
|
-
control: form.control,
|
|
247
|
-
name: "panelDefinition.spec.plugin.kind",
|
|
248
|
-
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(PluginKindSelect, {
|
|
249
|
-
...field,
|
|
250
|
-
pluginTypes: [
|
|
251
|
-
'Panel'
|
|
252
|
-
],
|
|
253
|
-
required: true,
|
|
254
|
-
fullWidth: true,
|
|
255
|
-
label: "Type",
|
|
256
|
-
disabled: pluginEditor.isLoading,
|
|
257
|
-
error: !!pluginEditor.error || !!fieldState.error,
|
|
258
|
-
helperText: pluginEditor.error?.message ?? fieldState.error?.message,
|
|
259
|
-
value: {
|
|
260
|
-
type: 'Panel',
|
|
261
|
-
kind: watchedPluginKind
|
|
262
|
-
},
|
|
263
|
-
onChange: (event)=>{
|
|
264
|
-
field.onChange(event.kind);
|
|
265
|
-
pluginEditor.onSelectionChange(event);
|
|
266
|
-
}
|
|
267
|
-
})
|
|
268
|
-
})
|
|
134
|
+
titleAction,
|
|
135
|
+
" Panel"
|
|
136
|
+
]
|
|
137
|
+
}),
|
|
138
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
|
139
|
+
direction: "row",
|
|
140
|
+
spacing: 1,
|
|
141
|
+
marginLeft: "auto",
|
|
142
|
+
children: [
|
|
143
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
144
|
+
variant: "contained",
|
|
145
|
+
disabled: !form.formState.isValid,
|
|
146
|
+
onClick: handleSubmit,
|
|
147
|
+
children: submitText
|
|
269
148
|
}),
|
|
270
|
-
/*#__PURE__*/
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
149
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
150
|
+
color: "secondary",
|
|
151
|
+
variant: "outlined",
|
|
152
|
+
onClick: handleCancel,
|
|
153
|
+
children: "Cancel"
|
|
154
|
+
})
|
|
155
|
+
]
|
|
156
|
+
})
|
|
157
|
+
]
|
|
158
|
+
}),
|
|
159
|
+
/*#__PURE__*/ _jsx(Box, {
|
|
160
|
+
id: panelEditorFormId,
|
|
161
|
+
sx: {
|
|
162
|
+
flex: 1,
|
|
163
|
+
overflowY: 'scroll',
|
|
164
|
+
padding: (theme)=>theme.spacing(2)
|
|
165
|
+
},
|
|
166
|
+
children: /*#__PURE__*/ _jsxs(Grid, {
|
|
167
|
+
container: true,
|
|
168
|
+
spacing: 2,
|
|
169
|
+
children: [
|
|
170
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
171
|
+
item: true,
|
|
172
|
+
xs: 8,
|
|
173
|
+
children: /*#__PURE__*/ _jsx(Controller, {
|
|
174
|
+
control: form.control,
|
|
175
|
+
name: "panelDefinition.spec.display.name",
|
|
176
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
177
|
+
...field,
|
|
178
|
+
required: true,
|
|
179
|
+
fullWidth: true,
|
|
180
|
+
label: "Name",
|
|
181
|
+
error: !!fieldState.error,
|
|
182
|
+
helperText: fieldState.error?.message,
|
|
183
|
+
value: watchedName ?? '',
|
|
184
|
+
onChange: (event)=>{
|
|
185
|
+
field.onChange(event);
|
|
186
|
+
setName(event.target.value);
|
|
187
|
+
}
|
|
284
188
|
})
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
189
|
+
})
|
|
190
|
+
}),
|
|
191
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
192
|
+
item: true,
|
|
193
|
+
xs: 4,
|
|
194
|
+
children: /*#__PURE__*/ _jsx(Controller, {
|
|
195
|
+
control: form.control,
|
|
196
|
+
name: "groupId",
|
|
197
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
198
|
+
select: true,
|
|
199
|
+
...field,
|
|
200
|
+
required: true,
|
|
201
|
+
fullWidth: true,
|
|
202
|
+
label: "Group",
|
|
203
|
+
error: !!fieldState.error,
|
|
204
|
+
helperText: fieldState.error?.message,
|
|
205
|
+
onChange: (event)=>{
|
|
206
|
+
field.onChange(event);
|
|
299
207
|
},
|
|
300
|
-
|
|
301
|
-
|
|
208
|
+
children: panelGroups.map((panelGroup, index)=>/*#__PURE__*/ _jsx(MenuItem, {
|
|
209
|
+
value: panelGroup.id,
|
|
210
|
+
children: panelGroup.title ?? `Group ${index + 1}`
|
|
211
|
+
}, panelGroup.id))
|
|
212
|
+
})
|
|
213
|
+
})
|
|
214
|
+
}),
|
|
215
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
216
|
+
item: true,
|
|
217
|
+
xs: 8,
|
|
218
|
+
children: /*#__PURE__*/ _jsx(Controller, {
|
|
219
|
+
control: form.control,
|
|
220
|
+
name: "panelDefinition.spec.display.description",
|
|
221
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
222
|
+
...field,
|
|
223
|
+
fullWidth: true,
|
|
224
|
+
label: "Description",
|
|
225
|
+
error: !!fieldState.error,
|
|
226
|
+
helperText: fieldState.error?.message,
|
|
227
|
+
value: watchedDescription ?? '',
|
|
228
|
+
onChange: (event)=>{
|
|
229
|
+
field.onChange(event);
|
|
230
|
+
setDescription(event.target.value);
|
|
302
231
|
}
|
|
303
232
|
})
|
|
304
|
-
})
|
|
305
233
|
})
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
234
|
+
}),
|
|
235
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
236
|
+
item: true,
|
|
237
|
+
xs: 4,
|
|
238
|
+
children: /*#__PURE__*/ _jsx(Controller, {
|
|
239
|
+
control: form.control,
|
|
240
|
+
name: "panelDefinition.spec.plugin.kind",
|
|
241
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(PluginKindSelect, {
|
|
242
|
+
...field,
|
|
243
|
+
pluginTypes: [
|
|
244
|
+
'Panel'
|
|
245
|
+
],
|
|
246
|
+
required: true,
|
|
247
|
+
fullWidth: true,
|
|
248
|
+
label: "Type",
|
|
249
|
+
disabled: pluginEditor.isLoading,
|
|
250
|
+
error: !!pluginEditor.error || !!fieldState.error,
|
|
251
|
+
helperText: pluginEditor.error?.message ?? fieldState.error?.message,
|
|
252
|
+
value: {
|
|
253
|
+
type: 'Panel',
|
|
254
|
+
kind: watchedPluginKind
|
|
255
|
+
},
|
|
256
|
+
onChange: (event)=>{
|
|
257
|
+
field.onChange(event.kind);
|
|
258
|
+
pluginEditor.onSelectionChange(event);
|
|
259
|
+
}
|
|
260
|
+
})
|
|
261
|
+
})
|
|
262
|
+
}),
|
|
263
|
+
/*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
264
|
+
FallbackComponent: ErrorAlert,
|
|
265
|
+
children: /*#__PURE__*/ _jsx(PanelQueriesSharedControls, {
|
|
266
|
+
control: form.control,
|
|
267
|
+
plugin: plugin,
|
|
268
|
+
panelDefinition: panelDefinition,
|
|
269
|
+
onQueriesChange: (q)=>setQueries(q),
|
|
270
|
+
onPluginSpecChange: (spec)=>{
|
|
271
|
+
pluginEditor.onSpecChange(spec);
|
|
272
|
+
},
|
|
273
|
+
onJSONChange: handlePanelDefinitionChange
|
|
274
|
+
})
|
|
275
|
+
})
|
|
276
|
+
]
|
|
319
277
|
})
|
|
320
|
-
|
|
321
|
-
|
|
278
|
+
}),
|
|
279
|
+
/*#__PURE__*/ _jsx(DiscardChangesConfirmationDialog, {
|
|
280
|
+
description: "You have unapplied changes in this panel. Are you sure you want to discard these changes? Changes cannot be recovered.",
|
|
281
|
+
isOpen: isDiscardDialogOpened,
|
|
282
|
+
onCancel: ()=>{
|
|
283
|
+
setDiscardDialogOpened(false);
|
|
284
|
+
},
|
|
285
|
+
onDiscardChanges: ()=>{
|
|
286
|
+
setDiscardDialogOpened(false);
|
|
287
|
+
onClose();
|
|
288
|
+
}
|
|
289
|
+
})
|
|
290
|
+
]
|
|
322
291
|
})
|
|
323
292
|
});
|
|
324
293
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelEditorForm.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 { ReactElement, useCallback, useEffect, useRef, useState } from 'react';\nimport { Box, Button, Grid, MenuItem, Stack, TextField, Typography } from '@mui/material';\nimport { Action, DEFAULT_DASHBOARD_DURATION, PanelDefinition, PanelEditorValues } from '@perses-dev/core';\nimport { DiscardChangesConfirmationDialog, ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport {\n PluginKindSelect,\n usePluginEditor,\n PanelSpecEditor,\n getTitleAction,\n getSubmitText,\n useValidationSchemas,\n PluginEditorRef,\n TimeRangeProvider,\n useTimeRangeParams,\n useInitialTimeRange,\n} from '@perses-dev/plugin-system';\nimport { Controller, FormProvider, SubmitHandler, useForm, useWatch } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { useDashboard, useListPanelGroups } from '../../context';\nimport { PanelEditorProvider } from '../../context/PanelEditorProvider/PanelEditorProvider';\nimport { PanelPreview } from './PanelPreview';\nimport { usePanelEditor } from './usePanelEditor';\n\nexport interface PanelEditorFormProps {\n initialValues: PanelEditorValues;\n initialAction: Action;\n onSave: (values: PanelEditorValues) => void;\n onClose: () => void;\n}\n\nexport function PanelEditorForm(props: PanelEditorFormProps): ReactElement {\n const { initialValues, initialAction, onSave, onClose } = props;\n const pluginEditorRef = useRef<PluginEditorRef>(null);\n const panelGroups = useListPanelGroups();\n const { panelDefinition, setName, setDescription, setLinks, setQueries, setPlugin, setPanelDefinition } =\n usePanelEditor(initialValues.panelDefinition);\n const { plugin } = panelDefinition.spec;\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n\n const { panelEditorSchema } = useValidationSchemas();\n const form = useForm<PanelEditorValues>({\n resolver: zodResolver(panelEditorSchema),\n mode: 'onBlur',\n defaultValues: initialValues,\n });\n\n const { dashboard } = useDashboard();\n const dashboardDuration = dashboard?.kind === 'Dashboard' ? dashboard.spec.duration : DEFAULT_DASHBOARD_DURATION;\n const initialTimeRange = useInitialTimeRange(dashboardDuration);\n\n // Use common plugin editor logic even though we've split the inputs up in this form\n const pluginEditor = usePluginEditor({\n pluginTypes: ['Panel'],\n value: { selection: { kind: plugin.kind, type: 'Panel' }, spec: plugin.spec },\n onChange: (plugin) => {\n form.setValue('panelDefinition.spec.plugin', { kind: plugin.selection.kind, spec: plugin.spec });\n setPlugin({\n kind: plugin.selection.kind,\n spec: plugin.spec,\n });\n },\n onHideQueryEditorChange: (isHidden) => {\n setQueries(undefined, isHidden);\n },\n });\n\n const titleAction = getTitleAction(initialAction, true);\n const submitText = getSubmitText(initialAction, true);\n\n const links = useWatch({ control: form.control, name: 'panelDefinition.spec.links' });\n useEffect(() => {\n setLinks(links);\n }, [setLinks, links]);\n\n const processForm: SubmitHandler<PanelEditorValues> = useCallback(\n (data) => {\n onSave(data);\n },\n [onSave]\n );\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialValues) !== JSON.stringify(form.getValues())) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n const handlePanelDefinitionChange = (nextPanelDefStr: string): void => {\n const nextPanelDef: PanelDefinition = JSON.parse(nextPanelDefStr);\n const { kind: pluginKind, spec: pluginSpec } = nextPanelDef.spec.plugin;\n // if panel plugin kind and spec are modified, then need to save current spec\n if (\n panelDefinition.spec.plugin.kind !== pluginKind &&\n JSON.stringify(panelDefinition.spec.plugin.spec) !== JSON.stringify(pluginSpec)\n ) {\n pluginEditor.rememberCurrentSpecState();\n }\n setPanelDefinition(nextPanelDef);\n };\n\n const watchedName = useWatch({ control: form.control, name: 'panelDefinition.spec.display.name' });\n const watchedDescription = useWatch({ control: form.control, name: 'panelDefinition.spec.display.description' });\n const watchedPluginKind = useWatch({ control: form.control, name: 'panelDefinition.spec.plugin.kind' });\n const { timeRange } = useTimeRangeParams(initialTimeRange);\n\n const handleSubmit = useCallback(() => {\n pluginEditorRef.current?.flushChanges?.();\n form.handleSubmit(processForm)();\n }, [form, processForm]);\n\n return (\n <TimeRangeProvider timeRange={timeRange}>\n <FormProvider {...form}>\n <PanelEditorProvider>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Panel</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button variant=\"contained\" disabled={!form.formState.isValid} onClick={handleSubmit}>\n {submitText}\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box id={panelEditorFormId} sx={{ flex: 1, overflowY: 'scroll', padding: (theme) => theme.spacing(2) }}>\n <Grid container spacing={2}>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"panelDefinition.spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n label=\"Name\"\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={watchedName ?? ''}\n onChange={(event) => {\n field.onChange(event);\n setName(event.target.value);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"groupId\"\n render={({ field, fieldState }) => (\n <TextField\n select\n {...field}\n required\n fullWidth\n label=\"Group\"\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n onChange={(event) => {\n field.onChange(event);\n }}\n >\n {panelGroups.map((panelGroup, index) => (\n <MenuItem key={panelGroup.id} value={panelGroup.id}>\n {panelGroup.title ?? `Group ${index + 1}`}\n </MenuItem>\n ))}\n </TextField>\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"panelDefinition.spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Description\"\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={watchedDescription ?? ''}\n onChange={(event) => {\n field.onChange(event);\n setDescription(event.target.value);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"panelDefinition.spec.plugin.kind\"\n render={({ field, fieldState }) => (\n <PluginKindSelect\n {...field}\n pluginTypes={['Panel']}\n required\n fullWidth\n label=\"Type\"\n disabled={pluginEditor.isLoading}\n error={!!pluginEditor.error || !!fieldState.error}\n helperText={pluginEditor.error?.message ?? fieldState.error?.message}\n value={{ type: 'Panel', kind: watchedPluginKind }}\n onChange={(event) => {\n field.onChange(event.kind);\n pluginEditor.onSelectionChange(event);\n }}\n />\n )}\n />\n </Grid>\n\n <Grid item xs={12}>\n <Typography variant=\"h4\" marginBottom={1}>\n Preview\n </Typography>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PanelPreview panelDefinition={panelDefinition} />\n </ErrorBoundary>\n </Grid>\n <Grid item xs={12}>\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PanelSpecEditor\n ref={pluginEditorRef}\n control={form.control}\n panelDefinition={panelDefinition}\n onJSONChange={handlePanelDefinitionChange}\n onQueriesChange={(queries) => {\n setQueries(queries);\n }}\n onPluginSpecChange={(spec) => {\n pluginEditor.onSpecChange(spec);\n }}\n />\n </ErrorBoundary>\n </Grid>\n </Grid>\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"You have unapplied changes in this panel. Are you sure you want to discard these changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => {\n setDiscardDialogOpened(false);\n }}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </PanelEditorProvider>\n </FormProvider>\n </TimeRangeProvider>\n );\n}\n\n/**\n * The `id` attribute added to the `PanelEditorForm` component, allowing submit buttons to live outside the form.\n */\nexport const panelEditorFormId = 'panel-editor-form';\n"],"names":["useCallback","useEffect","useRef","useState","Box","Button","Grid","MenuItem","Stack","TextField","Typography","DEFAULT_DASHBOARD_DURATION","DiscardChangesConfirmationDialog","ErrorAlert","ErrorBoundary","PluginKindSelect","usePluginEditor","PanelSpecEditor","getTitleAction","getSubmitText","useValidationSchemas","TimeRangeProvider","useTimeRangeParams","useInitialTimeRange","Controller","FormProvider","useForm","useWatch","zodResolver","useDashboard","useListPanelGroups","PanelEditorProvider","PanelPreview","usePanelEditor","PanelEditorForm","props","initialValues","initialAction","onSave","onClose","pluginEditorRef","panelGroups","panelDefinition","setName","setDescription","setLinks","setQueries","setPlugin","setPanelDefinition","plugin","spec","isDiscardDialogOpened","setDiscardDialogOpened","panelEditorSchema","form","resolver","mode","defaultValues","dashboard","dashboardDuration","kind","duration","initialTimeRange","pluginEditor","pluginTypes","value","selection","type","onChange","setValue","onHideQueryEditorChange","isHidden","undefined","titleAction","submitText","links","control","name","processForm","data","handleCancel","JSON","stringify","getValues","handlePanelDefinitionChange","nextPanelDefStr","nextPanelDef","parse","pluginKind","pluginSpec","rememberCurrentSpecState","watchedName","watchedDescription","watchedPluginKind","timeRange","handleSubmit","current","flushChanges","sx","display","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","direction","marginLeft","disabled","formState","isValid","onClick","color","id","panelEditorFormId","flex","overflowY","container","item","xs","render","field","fieldState","required","fullWidth","label","error","helperText","message","event","target","select","map","panelGroup","index","title","isLoading","onSelectionChange","marginBottom","FallbackComponent","ref","onJSONChange","onQueriesChange","queries","onPluginSpecChange","onSpecChange","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,SAAuBA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC/E,SAASC,GAAG,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAC1F,SAAiBC,0BAA0B,QAA4C,mBAAmB;AAC1G,SAASC,gCAAgC,EAAEC,UAAU,EAAEC,aAAa,QAAQ,yBAAyB;AACrG,SACEC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,cAAc,EACdC,aAAa,EACbC,oBAAoB,EAEpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,mBAAmB,QACd,4BAA4B;AACnC,SAASC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,EAAEC,QAAQ,QAAQ,kBAAkB;AAC7F,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,EAAEC,kBAAkB,QAAQ,gBAAgB;AACjE,SAASC,mBAAmB,QAAQ,wDAAwD;AAC5F,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,mBAAmB;AASlD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGJ;I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OAAO,CAAC,CAACjE,aAAaiE,KAAK,IAAI,CAAC,CAACJ,WAAWI,KAAK;gDACjDC,YAAYlE,aAAaiE,KAAK,EAAEE,WAAWN,WAAWI,KAAK,EAAEE;gDAC7DjE,OAAO;oDAAEE,MAAM;oDAASP,MAAMiC;gDAAkB;gDAChDzB,UAAU,CAAC+D;oDACTR,MAAMvD,QAAQ,CAAC+D,MAAMvE,IAAI;oDACzBG,aAAa4E,iBAAiB,CAACR;gDACjC;;;;8CAMR,MAAC7H;oCAAKkH,IAAI;oCAACC,IAAI;;sDACb,KAAC/G;4CAAWiG,SAAQ;4CAAKiC,cAAc;sDAAG;;sDAG1C,KAAC9H;4CAAc+H,mBAAmBhI;sDAChC,cAAA,KAACmB;gDAAaU,iBAAiBA;;;;;8CAGnC,KAACpC;oCAAKkH,IAAI;oCAACC,IAAI;8CACb,cAAA,KAAC3G;wCAAc+H,mBAAmBhI;kDAChC,cAAA,KAACI;4CACC6H,KAAKtG;4CACLoC,SAAStB,KAAKsB,OAAO;4CACrBlC,iBAAiBA;4CACjBqG,cAAc3D;4CACd4D,iBAAiB,CAACC;gDAChBnG,WAAWmG;4CACb;4CACAC,oBAAoB,CAAChG;gDACnBa,aAAaoF,YAAY,CAACjG;4CAC5B;;;;;;;kCAMV,KAACtC;wBACCwI,aAAY;wBACZC,QAAQlG;wBACRmG,UAAU;4BACRlG,uBAAuB;wBACzB;wBACAmG,kBAAkB;4BAChBnG,uBAAuB;4BACvBb;wBACF;;;;;;AAMZ;AAEA;;CAEC,GACD,OAAO,MAAM6E,oBAAoB,oBAAoB"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelEditorForm.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 { ReactElement, useCallback, useEffect, useRef, useState } from 'react';\nimport { Box, Button, Grid, MenuItem, Stack, TextField, Typography } from '@mui/material';\nimport { Action, PanelDefinition, PanelEditorValues } from '@perses-dev/core';\nimport { DiscardChangesConfirmationDialog, ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport {\n PluginKindSelect,\n usePluginEditor,\n getTitleAction,\n getSubmitText,\n useValidationSchemas,\n PluginEditorRef,\n} from '@perses-dev/plugin-system';\nimport { Controller, FormProvider, SubmitHandler, useForm, useWatch } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { useListPanelGroups } from '../../context';\nimport { PanelEditorProvider } from '../../context/PanelEditorProvider/PanelEditorProvider';\nimport { usePanelEditor } from './usePanelEditor';\nimport { PanelQueriesSharedControls } from './PanelQueriesSharedControls';\n\nexport interface PanelEditorFormProps {\n initialValues: PanelEditorValues;\n initialAction: Action;\n onSave: (values: PanelEditorValues) => void;\n onClose: () => void;\n}\n\nexport function PanelEditorForm(props: PanelEditorFormProps): ReactElement {\n const { initialValues, initialAction, onSave, onClose } = props;\n const pluginEditorRef = useRef<PluginEditorRef>(null);\n const panelGroups = useListPanelGroups();\n const { panelDefinition, setName, setDescription, setLinks, setQueries, setPlugin, setPanelDefinition } =\n usePanelEditor(initialValues.panelDefinition);\n const { plugin } = panelDefinition.spec;\n const [isDiscardDialogOpened, setDiscardDialogOpened] = useState<boolean>(false);\n\n const { panelEditorSchema } = useValidationSchemas();\n const form = useForm<PanelEditorValues>({\n resolver: zodResolver(panelEditorSchema),\n mode: 'onBlur',\n defaultValues: initialValues,\n });\n\n // Use common plugin editor logic even though we've split the inputs up in this form\n const pluginEditor = usePluginEditor({\n pluginTypes: ['Panel'],\n value: { selection: { kind: plugin.kind, type: 'Panel' }, spec: plugin.spec },\n onChange: (plugin) => {\n form.setValue('panelDefinition.spec.plugin', { kind: plugin.selection.kind, spec: plugin.spec });\n setPlugin({\n kind: plugin.selection.kind,\n spec: plugin.spec,\n });\n },\n onHideQueryEditorChange: (isHidden) => {\n setQueries(undefined, isHidden);\n },\n });\n\n const titleAction = getTitleAction(initialAction, true);\n const submitText = getSubmitText(initialAction, true);\n\n const links = useWatch({ control: form.control, name: 'panelDefinition.spec.links' });\n useEffect(() => {\n setLinks(links);\n }, [setLinks, links]);\n\n const processForm: SubmitHandler<PanelEditorValues> = useCallback(\n (data) => {\n onSave(data);\n },\n [onSave]\n );\n\n // When user click on cancel, several possibilities:\n // - create action: ask for discard approval\n // - update action: ask for discard approval if changed\n // - read action: don´t ask for discard approval\n function handleCancel(): void {\n if (JSON.stringify(initialValues) !== JSON.stringify(form.getValues())) {\n setDiscardDialogOpened(true);\n } else {\n onClose();\n }\n }\n\n const handlePanelDefinitionChange = (nextPanelDefStr: string): void => {\n const nextPanelDef: PanelDefinition = JSON.parse(nextPanelDefStr);\n const { kind: pluginKind, spec: pluginSpec } = nextPanelDef.spec.plugin;\n // if panel plugin kind and spec are modified, then need to save current spec\n if (\n panelDefinition.spec.plugin.kind !== pluginKind &&\n JSON.stringify(panelDefinition.spec.plugin.spec) !== JSON.stringify(pluginSpec)\n ) {\n pluginEditor.rememberCurrentSpecState();\n }\n setPanelDefinition(nextPanelDef);\n };\n\n const watchedName = useWatch({ control: form.control, name: 'panelDefinition.spec.display.name' });\n const watchedDescription = useWatch({ control: form.control, name: 'panelDefinition.spec.display.description' });\n const watchedPluginKind = useWatch({ control: form.control, name: 'panelDefinition.spec.plugin.kind' });\n\n const handleSubmit = useCallback(() => {\n pluginEditorRef.current?.flushChanges?.();\n form.handleSubmit(processForm)();\n }, [form, processForm]);\n\n return (\n <FormProvider {...form}>\n <PanelEditorProvider>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n padding: (theme) => theme.spacing(1, 2),\n borderBottom: (theme) => `1px solid ${theme.palette.divider}`,\n }}\n >\n <Typography variant=\"h2\">{titleAction} Panel</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button variant=\"contained\" disabled={!form.formState.isValid} onClick={handleSubmit}>\n {submitText}\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box id={panelEditorFormId} sx={{ flex: 1, overflowY: 'scroll', padding: (theme) => theme.spacing(2) }}>\n <Grid container spacing={2}>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"panelDefinition.spec.display.name\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n required\n fullWidth\n label=\"Name\"\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={watchedName ?? ''}\n onChange={(event) => {\n field.onChange(event);\n setName(event.target.value);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"groupId\"\n render={({ field, fieldState }) => (\n <TextField\n select\n {...field}\n required\n fullWidth\n label=\"Group\"\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n onChange={(event) => {\n field.onChange(event);\n }}\n >\n {panelGroups.map((panelGroup, index) => (\n <MenuItem key={panelGroup.id} value={panelGroup.id}>\n {panelGroup.title ?? `Group ${index + 1}`}\n </MenuItem>\n ))}\n </TextField>\n )}\n />\n </Grid>\n <Grid item xs={8}>\n <Controller\n control={form.control}\n name=\"panelDefinition.spec.display.description\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Description\"\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n value={watchedDescription ?? ''}\n onChange={(event) => {\n field.onChange(event);\n setDescription(event.target.value);\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={4}>\n <Controller\n control={form.control}\n name=\"panelDefinition.spec.plugin.kind\"\n render={({ field, fieldState }) => (\n <PluginKindSelect\n {...field}\n pluginTypes={['Panel']}\n required\n fullWidth\n label=\"Type\"\n disabled={pluginEditor.isLoading}\n error={!!pluginEditor.error || !!fieldState.error}\n helperText={pluginEditor.error?.message ?? fieldState.error?.message}\n value={{ type: 'Panel', kind: watchedPluginKind }}\n onChange={(event) => {\n field.onChange(event.kind);\n pluginEditor.onSelectionChange(event);\n }}\n />\n )}\n />\n </Grid>\n\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <PanelQueriesSharedControls\n control={form.control}\n plugin={plugin}\n panelDefinition={panelDefinition}\n onQueriesChange={(q) => setQueries(q)}\n onPluginSpecChange={(spec) => {\n pluginEditor.onSpecChange(spec);\n }}\n onJSONChange={handlePanelDefinitionChange}\n />\n </ErrorBoundary>\n </Grid>\n </Box>\n <DiscardChangesConfirmationDialog\n description=\"You have unapplied changes in this panel. Are you sure you want to discard these changes? Changes cannot be recovered.\"\n isOpen={isDiscardDialogOpened}\n onCancel={() => {\n setDiscardDialogOpened(false);\n }}\n onDiscardChanges={() => {\n setDiscardDialogOpened(false);\n onClose();\n }}\n />\n </PanelEditorProvider>\n </FormProvider>\n );\n}\n\n/**\n * The `id` attribute added to the `PanelEditorForm` component, allowing submit buttons to live outside the form.\n */\nexport const panelEditorFormId = 'panel-editor-form';\n"],"names":["useCallback","useEffect","useRef","useState","Box","Button","Grid","MenuItem","Stack","TextField","Typography","DiscardChangesConfirmationDialog","ErrorAlert","ErrorBoundary","PluginKindSelect","usePluginEditor","getTitleAction","getSubmitText","useValidationSchemas","Controller","FormProvider","useForm","useWatch","zodResolver","useListPanelGroups","PanelEditorProvider","usePanelEditor","PanelQueriesSharedControls","PanelEditorForm","props","initialValues","initialAction","onSave","onClose","pluginEditorRef","panelGroups","panelDefinition","setName","setDescription","setLinks","setQueries","setPlugin","setPanelDefinition","plugin","spec","isDiscardDialogOpened","setDiscardDialogOpened","panelEditorSchema","form","resolver","mode","defaultValues","pluginEditor","pluginTypes","value","selection","kind","type","onChange","setValue","onHideQueryEditorChange","isHidden","undefined","titleAction","submitText","links","control","name","processForm","data","handleCancel","JSON","stringify","getValues","handlePanelDefinitionChange","nextPanelDefStr","nextPanelDef","parse","pluginKind","pluginSpec","rememberCurrentSpecState","watchedName","watchedDescription","watchedPluginKind","handleSubmit","current","flushChanges","sx","display","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","direction","marginLeft","disabled","formState","isValid","onClick","color","id","panelEditorFormId","flex","overflowY","container","item","xs","render","field","fieldState","required","fullWidth","label","error","helperText","message","event","target","select","map","panelGroup","index","title","isLoading","onSelectionChange","FallbackComponent","onQueriesChange","q","onPluginSpecChange","onSpecChange","onJSONChange","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,SAAuBA,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC/E,SAASC,GAAG,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAE1F,SAASC,gCAAgC,EAAEC,UAAU,EAAEC,aAAa,QAAQ,yBAAyB;AACrG,SACEC,gBAAgB,EAChBC,eAAe,EACfC,cAAc,EACdC,aAAa,EACbC,oBAAoB,QAEf,4BAA4B;AACnC,SAASC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,EAAEC,QAAQ,QAAQ,kBAAkB;AAC7F,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,mBAAmB,QAAQ,wDAAwD;AAC5F,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,0BAA0B,QAAQ,+BAA+B;AAS1E,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,MAAM,EAA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AQ,CAAC8D,MAAMhE,IAAI;gDACzBJ,aAAa4E,iBAAiB,CAACR;4CACjC;;;;0CAMR,KAAC3G;gCAAcoH,mBAAmBrH;0CAChC,cAAA,KAACe;oCACCuC,SAASlB,KAAKkB,OAAO;oCACrBvB,QAAQA;oCACRP,iBAAiBA;oCACjB8F,iBAAiB,CAACC,IAAM3F,WAAW2F;oCACnCC,oBAAoB,CAACxF;wCACnBQ,aAAaiF,YAAY,CAACzF;oCAC5B;oCACA0F,cAAc5D;;;;;;8BAKtB,KAAC/D;oBACC4H,aAAY;oBACZC,QAAQ3F;oBACR4F,UAAU;wBACR3F,uBAAuB;oBACzB;oBACA4F,kBAAkB;wBAChB5F,uBAAuB;wBACvBb;oBACF;;;;;AAKV;AAEA;;CAEC,GACD,OAAO,MAAMwE,oBAAoB,oBAAoB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelPreview.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelPreview.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAsB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PanelPreview.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelPreview.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAsB,MAAM,OAAO,CAAC;AAEzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAOrD,wBAAgB,YAAY,CAAC,EAAE,eAAe,EAAE,EAAE,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,YAAY,GAAG,IAAI,CAoBjH"}
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { useContext, useRef } from 'react';
|
|
15
15
|
import { Box } from '@mui/material';
|
|
16
|
-
import { DataQueriesProvider, usePlugin, useSuggestedStepMs } from '@perses-dev/plugin-system';
|
|
17
16
|
import { Panel } from '../Panel';
|
|
18
17
|
import { PanelEditorContext } from '../../context';
|
|
19
18
|
const PANEL_PREVIEW_HEIGHT = 300;
|
|
@@ -26,34 +25,14 @@ export function PanelPreview({ panelDefinition }) {
|
|
|
26
25
|
width = boxRef.current.getBoundingClientRect().width;
|
|
27
26
|
panelEditorContext?.preview?.setPreviewPanelWidth?.(width);
|
|
28
27
|
}
|
|
29
|
-
const suggestedStepMs = useSuggestedStepMs(width);
|
|
30
|
-
const { data: plugin, isLoading } = usePlugin('Panel', panelDefinition.spec.plugin.kind);
|
|
31
|
-
if (isLoading) {
|
|
32
|
-
return null;
|
|
33
|
-
}
|
|
34
28
|
if (panelDefinition.spec.plugin.kind === '') {
|
|
35
29
|
return null;
|
|
36
30
|
}
|
|
37
|
-
const queries = panelDefinition.spec.queries ?? [];
|
|
38
|
-
// map TimeSeriesQueryDefinition to Definition<UnknownSpec>
|
|
39
|
-
const definitions = queries.length ? queries.map((query)=>{
|
|
40
|
-
return {
|
|
41
|
-
kind: query.spec.plugin.kind,
|
|
42
|
-
spec: query.spec.plugin.spec
|
|
43
|
-
};
|
|
44
|
-
}) : [];
|
|
45
31
|
return /*#__PURE__*/ _jsx(Box, {
|
|
46
32
|
ref: boxRef,
|
|
47
33
|
height: PANEL_PREVIEW_HEIGHT,
|
|
48
|
-
children: /*#__PURE__*/ _jsx(
|
|
49
|
-
|
|
50
|
-
options: {
|
|
51
|
-
suggestedStepMs,
|
|
52
|
-
...plugin?.queryOptions
|
|
53
|
-
},
|
|
54
|
-
children: /*#__PURE__*/ _jsx(Panel, {
|
|
55
|
-
definition: panelDefinition
|
|
56
|
-
})
|
|
34
|
+
children: /*#__PURE__*/ _jsx(Panel, {
|
|
35
|
+
definition: panelDefinition
|
|
57
36
|
})
|
|
58
37
|
});
|
|
59
38
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelPreview.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 { ReactElement, useContext, useRef } from 'react';\nimport { Box } from '@mui/material';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelPreview.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 { ReactElement, useContext, useRef } from 'react';\nimport { Box } from '@mui/material';\nimport { PanelEditorValues } from '@perses-dev/core';\nimport { Panel } from '../Panel';\nimport { PanelEditorContext } from '../../context';\n\nconst PANEL_PREVIEW_HEIGHT = 300;\nconst PANEL_PREVIEW_DEFAULT_WIDTH = 840;\n\nexport function PanelPreview({ panelDefinition }: Pick<PanelEditorValues, 'panelDefinition'>): ReactElement | null {\n const boxRef = useRef<HTMLDivElement>(null);\n let width = PANEL_PREVIEW_DEFAULT_WIDTH;\n\n const panelEditorContext = useContext(PanelEditorContext);\n\n if (boxRef.current !== null) {\n width = boxRef.current.getBoundingClientRect().width;\n panelEditorContext?.preview?.setPreviewPanelWidth?.(width);\n }\n\n if (panelDefinition.spec.plugin.kind === '') {\n return null;\n }\n\n return (\n <Box ref={boxRef} height={PANEL_PREVIEW_HEIGHT}>\n <Panel definition={panelDefinition} />\n </Box>\n );\n}\n"],"names":["useContext","useRef","Box","Panel","PanelEditorContext","PANEL_PREVIEW_HEIGHT","PANEL_PREVIEW_DEFAULT_WIDTH","PanelPreview","panelDefinition","boxRef","width","panelEditorContext","current","getBoundingClientRect","preview","setPreviewPanelWidth","spec","plugin","kind","ref","height","definition"],"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,SAAuBA,UAAU,EAAEC,MAAM,QAAQ,QAAQ;AACzD,SAASC,GAAG,QAAQ,gBAAgB;AAEpC,SAASC,KAAK,QAAQ,WAAW;AACjC,SAASC,kBAAkB,QAAQ,gBAAgB;AAEnD,MAAMC,uBAAuB;AAC7B,MAAMC,8BAA8B;AAEpC,OAAO,SAASC,aAAa,EAAEC,eAAe,EAA8C;IAC1F,MAAMC,SAASR,OAAuB;IACtC,IAAIS,QAAQJ;IAEZ,MAAMK,qBAAqBX,WAAWI;IAEtC,IAAIK,OAAOG,OAAO,KAAK,MAAM;QAC3BF,QAAQD,OAAOG,OAAO,CAACC,qBAAqB,GAAGH,KAAK;QACpDC,oBAAoBG,SAASC,uBAAuBL;IACtD;IAEA,IAAIF,gBAAgBQ,IAAI,CAACC,MAAM,CAACC,IAAI,KAAK,IAAI;QAC3C,OAAO;IACT;IAEA,qBACE,KAAChB;QAAIiB,KAAKV;QAAQW,QAAQf;kBACxB,cAAA,KAACF;YAAMkB,YAAYb;;;AAGzB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Definition, PanelDefinition, PanelEditorValues, QueryDefinition, UnknownSpec } from '@perses-dev/core';
|
|
2
|
+
import { Control } from 'react-hook-form';
|
|
3
|
+
import { ReactElement } from 'react';
|
|
4
|
+
export interface PanelQueriesSharedControlsProps {
|
|
5
|
+
control: Control<PanelEditorValues>;
|
|
6
|
+
plugin: Definition<UnknownSpec>;
|
|
7
|
+
panelDefinition: PanelDefinition;
|
|
8
|
+
onQueriesChange: (queries: QueryDefinition[]) => void;
|
|
9
|
+
onPluginSpecChange: (spec: UnknownSpec) => void;
|
|
10
|
+
onJSONChange: (panelDefinitionStr: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function PanelQueriesSharedControls({ plugin, control, panelDefinition, onQueriesChange, onPluginSpecChange, onJSONChange, }: PanelQueriesSharedControlsProps): ReactElement;
|
|
13
|
+
//# sourceMappingURL=PanelQueriesSharedControls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PanelQueriesSharedControls.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelQueriesSharedControls.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,iBAAiB,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChH,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAc,MAAM,OAAO,CAAC;AAEjD,MAAM,WAAW,+BAA+B;IAC9C,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACpC,MAAM,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC;IAChC,eAAe,EAAE,eAAe,CAAC;IACjC,eAAe,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;IACtD,kBAAkB,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAChD,YAAY,EAAE,CAAC,kBAAkB,EAAE,MAAM,KAAK,IAAI,CAAC;CACpD;AAID,wBAAgB,0BAA0B,CAAC,EACzC,MAAM,EACN,OAAO,EACP,eAAe,EACf,eAAe,EACf,kBAAkB,EAClB,YAAY,GACb,EAAE,+BAA+B,GAAG,YAAY,CA0ChD"}
|