@perses-dev/dashboards 0.53.0-beta.1 → 0.53.0-beta.3
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/Panel/PanelActions.js +41 -3
- package/dist/cjs/components/Panel/PanelPluginLoader.js +4 -2
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +165 -198
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +2 -23
- package/dist/cjs/components/PanelDrawer/PanelQueriesSharedControls.js +96 -0
- package/dist/cjs/components/Variables/VariableEditor.js +15 -22
- package/dist/cjs/context/PanelEditorProvider/PanelEditorProvider.js +1 -2
- package/dist/components/Panel/PanelActions.d.ts.map +1 -1
- package/dist/components/Panel/PanelActions.js +41 -3
- package/dist/components/Panel/PanelActions.js.map +1 -1
- package/dist/components/Panel/PanelPluginLoader.d.ts.map +1 -1
- package/dist/components/Panel/PanelPluginLoader.js +4 -2
- package/dist/components/Panel/PanelPluginLoader.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +168 -201
- 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 +90 -0
- package/dist/components/PanelDrawer/PanelQueriesSharedControls.js.map +1 -0
- 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/context/PanelEditorProvider/PanelEditorProvider.d.ts +3 -3
- package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts.map +1 -1
- package/dist/context/PanelEditorProvider/PanelEditorProvider.js +1 -2
- package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -1
- package/package.json +5 -5
|
@@ -11,20 +11,18 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
-
import { useCallback, useEffect,
|
|
14
|
+
import { useCallback, useEffect, 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
|
-
const pluginEditorRef = useRef(null);
|
|
28
26
|
const panelGroups = useListPanelGroups();
|
|
29
27
|
const { panelDefinition, setName, setDescription, setLinks, setQueries, setPlugin, setPanelDefinition } = usePanelEditor(initialValues.panelDefinition);
|
|
30
28
|
const { plugin } = panelDefinition.spec;
|
|
@@ -35,9 +33,6 @@ export function PanelEditorForm(props) {
|
|
|
35
33
|
mode: 'onBlur',
|
|
36
34
|
defaultValues: initialValues
|
|
37
35
|
});
|
|
38
|
-
const { dashboard } = useDashboard();
|
|
39
|
-
const dashboardDuration = dashboard?.kind === 'Dashboard' ? dashboard.spec.duration : DEFAULT_DASHBOARD_DURATION;
|
|
40
|
-
const initialTimeRange = useInitialTimeRange(dashboardDuration);
|
|
41
36
|
// Use common plugin editor logic even though we've split the inputs up in this form
|
|
42
37
|
const pluginEditor = usePluginEditor({
|
|
43
38
|
pluginTypes: [
|
|
@@ -113,212 +108,184 @@ export function PanelEditorForm(props) {
|
|
|
113
108
|
control: form.control,
|
|
114
109
|
name: 'panelDefinition.spec.plugin.kind'
|
|
115
110
|
});
|
|
116
|
-
const { timeRange } = useTimeRangeParams(initialTimeRange);
|
|
117
111
|
const handleSubmit = useCallback(()=>{
|
|
118
|
-
pluginEditorRef.current?.flushChanges?.();
|
|
119
112
|
form.handleSubmit(processForm)();
|
|
120
113
|
}, [
|
|
121
114
|
form,
|
|
122
115
|
processForm
|
|
123
116
|
]);
|
|
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,
|
|
117
|
+
return /*#__PURE__*/ _jsx(FormProvider, {
|
|
118
|
+
...form,
|
|
119
|
+
children: /*#__PURE__*/ _jsxs(PanelEditorProvider, {
|
|
120
|
+
children: [
|
|
121
|
+
/*#__PURE__*/ _jsxs(Box, {
|
|
122
|
+
sx: {
|
|
123
|
+
display: 'flex',
|
|
124
|
+
alignItems: 'center',
|
|
125
|
+
padding: (theme)=>theme.spacing(1, 2),
|
|
126
|
+
borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
|
|
127
|
+
},
|
|
128
|
+
children: [
|
|
129
|
+
/*#__PURE__*/ _jsxs(Typography, {
|
|
130
|
+
variant: "h2",
|
|
176
131
|
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
|
-
})
|
|
132
|
+
titleAction,
|
|
133
|
+
" Panel"
|
|
134
|
+
]
|
|
135
|
+
}),
|
|
136
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
|
137
|
+
direction: "row",
|
|
138
|
+
spacing: 1,
|
|
139
|
+
marginLeft: "auto",
|
|
140
|
+
children: [
|
|
141
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
142
|
+
variant: "contained",
|
|
143
|
+
disabled: !form.formState.isValid,
|
|
144
|
+
onClick: handleSubmit,
|
|
145
|
+
children: submitText
|
|
269
146
|
}),
|
|
270
|
-
/*#__PURE__*/
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
147
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
148
|
+
color: "secondary",
|
|
149
|
+
variant: "outlined",
|
|
150
|
+
onClick: handleCancel,
|
|
151
|
+
children: "Cancel"
|
|
152
|
+
})
|
|
153
|
+
]
|
|
154
|
+
})
|
|
155
|
+
]
|
|
156
|
+
}),
|
|
157
|
+
/*#__PURE__*/ _jsx(Box, {
|
|
158
|
+
id: panelEditorFormId,
|
|
159
|
+
sx: {
|
|
160
|
+
flex: 1,
|
|
161
|
+
overflowY: 'scroll',
|
|
162
|
+
padding: (theme)=>theme.spacing(2)
|
|
163
|
+
},
|
|
164
|
+
children: /*#__PURE__*/ _jsxs(Grid, {
|
|
165
|
+
container: true,
|
|
166
|
+
spacing: 2,
|
|
167
|
+
children: [
|
|
168
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
169
|
+
item: true,
|
|
170
|
+
xs: 8,
|
|
171
|
+
children: /*#__PURE__*/ _jsx(Controller, {
|
|
172
|
+
control: form.control,
|
|
173
|
+
name: "panelDefinition.spec.display.name",
|
|
174
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
175
|
+
...field,
|
|
176
|
+
required: true,
|
|
177
|
+
fullWidth: true,
|
|
178
|
+
label: "Name",
|
|
179
|
+
error: !!fieldState.error,
|
|
180
|
+
helperText: fieldState.error?.message,
|
|
181
|
+
value: watchedName ?? '',
|
|
182
|
+
onChange: (event)=>{
|
|
183
|
+
field.onChange(event);
|
|
184
|
+
setName(event.target.value);
|
|
185
|
+
}
|
|
284
186
|
})
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
187
|
+
})
|
|
188
|
+
}),
|
|
189
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
190
|
+
item: true,
|
|
191
|
+
xs: 4,
|
|
192
|
+
children: /*#__PURE__*/ _jsx(Controller, {
|
|
193
|
+
control: form.control,
|
|
194
|
+
name: "groupId",
|
|
195
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
196
|
+
select: true,
|
|
197
|
+
...field,
|
|
198
|
+
required: true,
|
|
199
|
+
fullWidth: true,
|
|
200
|
+
label: "Group",
|
|
201
|
+
error: !!fieldState.error,
|
|
202
|
+
helperText: fieldState.error?.message,
|
|
203
|
+
onChange: (event)=>{
|
|
204
|
+
field.onChange(event);
|
|
299
205
|
},
|
|
300
|
-
|
|
301
|
-
|
|
206
|
+
children: panelGroups.map((panelGroup, index)=>/*#__PURE__*/ _jsx(MenuItem, {
|
|
207
|
+
value: panelGroup.id,
|
|
208
|
+
children: panelGroup.title ?? `Group ${index + 1}`
|
|
209
|
+
}, panelGroup.id))
|
|
210
|
+
})
|
|
211
|
+
})
|
|
212
|
+
}),
|
|
213
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
214
|
+
item: true,
|
|
215
|
+
xs: 8,
|
|
216
|
+
children: /*#__PURE__*/ _jsx(Controller, {
|
|
217
|
+
control: form.control,
|
|
218
|
+
name: "panelDefinition.spec.display.description",
|
|
219
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
|
|
220
|
+
...field,
|
|
221
|
+
fullWidth: true,
|
|
222
|
+
label: "Description",
|
|
223
|
+
error: !!fieldState.error,
|
|
224
|
+
helperText: fieldState.error?.message,
|
|
225
|
+
value: watchedDescription ?? '',
|
|
226
|
+
onChange: (event)=>{
|
|
227
|
+
field.onChange(event);
|
|
228
|
+
setDescription(event.target.value);
|
|
302
229
|
}
|
|
303
230
|
})
|
|
304
|
-
})
|
|
305
231
|
})
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
232
|
+
}),
|
|
233
|
+
/*#__PURE__*/ _jsx(Grid, {
|
|
234
|
+
item: true,
|
|
235
|
+
xs: 4,
|
|
236
|
+
children: /*#__PURE__*/ _jsx(Controller, {
|
|
237
|
+
control: form.control,
|
|
238
|
+
name: "panelDefinition.spec.plugin.kind",
|
|
239
|
+
render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(PluginKindSelect, {
|
|
240
|
+
...field,
|
|
241
|
+
pluginTypes: [
|
|
242
|
+
'Panel'
|
|
243
|
+
],
|
|
244
|
+
required: true,
|
|
245
|
+
fullWidth: true,
|
|
246
|
+
label: "Type",
|
|
247
|
+
disabled: pluginEditor.isLoading,
|
|
248
|
+
error: !!pluginEditor.error || !!fieldState.error,
|
|
249
|
+
helperText: pluginEditor.error?.message ?? fieldState.error?.message,
|
|
250
|
+
value: {
|
|
251
|
+
type: 'Panel',
|
|
252
|
+
kind: watchedPluginKind
|
|
253
|
+
},
|
|
254
|
+
onChange: (event)=>{
|
|
255
|
+
field.onChange(event.kind);
|
|
256
|
+
pluginEditor.onSelectionChange(event);
|
|
257
|
+
}
|
|
258
|
+
})
|
|
259
|
+
})
|
|
260
|
+
}),
|
|
261
|
+
/*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
262
|
+
FallbackComponent: ErrorAlert,
|
|
263
|
+
children: /*#__PURE__*/ _jsx(PanelQueriesSharedControls, {
|
|
264
|
+
control: form.control,
|
|
265
|
+
plugin: plugin,
|
|
266
|
+
panelDefinition: panelDefinition,
|
|
267
|
+
onQueriesChange: (q)=>setQueries(q),
|
|
268
|
+
onPluginSpecChange: (spec)=>{
|
|
269
|
+
pluginEditor.onSpecChange(spec);
|
|
270
|
+
},
|
|
271
|
+
onJSONChange: handlePanelDefinitionChange
|
|
272
|
+
})
|
|
273
|
+
})
|
|
274
|
+
]
|
|
319
275
|
})
|
|
320
|
-
|
|
321
|
-
|
|
276
|
+
}),
|
|
277
|
+
/*#__PURE__*/ _jsx(DiscardChangesConfirmationDialog, {
|
|
278
|
+
description: "You have unapplied changes in this panel. Are you sure you want to discard these changes? Changes cannot be recovered.",
|
|
279
|
+
isOpen: isDiscardDialogOpened,
|
|
280
|
+
onCancel: ()=>{
|
|
281
|
+
setDiscardDialogOpened(false);
|
|
282
|
+
},
|
|
283
|
+
onDiscardChanges: ()=>{
|
|
284
|
+
setDiscardDialogOpened(false);
|
|
285
|
+
onClose();
|
|
286
|
+
}
|
|
287
|
+
})
|
|
288
|
+
]
|
|
322
289
|
})
|
|
323
290
|
});
|
|
324
291
|
}
|
|
@@ -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,O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Aa2E,SAAS;gDAChCV,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, 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} 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 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 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","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","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","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,QAAQ,QAAQ,QAAQ;AACvE,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,QACf,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,EAAEC,OAAO,EAAE,GAAGJ;IAC1D,MAAMK,cAAcV;IACpB,MAAM,EAAEW,eAAe,EAAEC,OAAO,EAAEC,cAAc,E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B,QAAQA;oCACRP,iBAAiBA;oCACjB4F,iBAAiB,CAACC,IAAMzF,WAAWyF;oCACnCC,oBAAoB,CAACtF;wCACnBQ,aAAa+E,YAAY,CAACvF;oCAC5B;oCACAwF,cAAc1D;;;;;;8BAKtB,KAAC9D;oBACCyH,aAAY;oBACZC,QAAQzF;oBACR0F,UAAU;wBACRzF,uBAAuB;oBACzB;oBACA0F,kBAAkB;wBAChB1F,uBAAuB;wBACvBZ;oBACF;;;;;AAKV;AAEA;;CAEC,GACD,OAAO,MAAMqE,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,EAA8C,MAAM,OAAO,CAAC;AAEjF,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,CA2DhD"}
|