@perses-dev/dashboards 0.52.0 → 0.53.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/dist/cjs/components/DashboardStickyToolbar/DashboardStickyToolbar.js +0 -2
  2. package/dist/cjs/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +5 -20
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +6 -64
  4. package/dist/cjs/components/LeaveDialog/LeaveDialog.js +10 -1
  5. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +186 -183
  6. package/dist/cjs/components/PanelDrawer/PanelPreview.js +3 -0
  7. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +6 -21
  8. package/dist/cjs/components/QueryViewerDialog/QueryViewerDialog.js +121 -0
  9. package/dist/cjs/components/QueryViewerDialog/index.js +30 -0
  10. package/dist/cjs/components/Variables/ListVariableListBox.js +201 -0
  11. package/dist/cjs/components/Variables/Variable.js +130 -72
  12. package/dist/cjs/components/Variables/index.js +1 -0
  13. package/dist/cjs/components/index.js +2 -1
  14. package/dist/cjs/context/PanelEditorProvider/PanelEditorProvider.js +49 -0
  15. package/dist/cjs/context/PanelEditorProvider/index.js +23 -0
  16. package/dist/cjs/context/index.js +1 -0
  17. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts.map +1 -1
  18. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +0 -2
  19. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  20. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
  21. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +5 -15
  22. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
  23. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  24. package/dist/components/GridLayout/GridItemContent.js +8 -66
  25. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  26. package/dist/components/LeaveDialog/LeaveDialog.d.ts +2 -1
  27. package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
  28. package/dist/components/LeaveDialog/LeaveDialog.js +10 -1
  29. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
  30. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  31. package/dist/components/PanelDrawer/PanelEditorForm.js +186 -183
  32. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  33. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  34. package/dist/components/PanelDrawer/PanelPreview.js +4 -1
  35. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  36. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  37. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +5 -15
  38. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  39. package/dist/components/QueryViewerDialog/QueryViewerDialog.d.ts +9 -0
  40. package/dist/components/QueryViewerDialog/QueryViewerDialog.d.ts.map +1 -0
  41. package/dist/components/QueryViewerDialog/QueryViewerDialog.js +72 -0
  42. package/dist/components/QueryViewerDialog/QueryViewerDialog.js.map +1 -0
  43. package/dist/components/QueryViewerDialog/index.d.ts +2 -0
  44. package/dist/components/QueryViewerDialog/index.d.ts.map +1 -0
  45. package/dist/components/QueryViewerDialog/index.js +15 -0
  46. package/dist/components/QueryViewerDialog/index.js.map +1 -0
  47. package/dist/components/Variables/ListVariableListBox.d.ts +16 -0
  48. package/dist/components/Variables/ListVariableListBox.d.ts.map +1 -0
  49. package/dist/components/Variables/ListVariableListBox.js +141 -0
  50. package/dist/components/Variables/ListVariableListBox.js.map +1 -0
  51. package/dist/components/Variables/Variable.d.ts.map +1 -1
  52. package/dist/components/Variables/Variable.js +134 -76
  53. package/dist/components/Variables/Variable.js.map +1 -1
  54. package/dist/components/Variables/index.d.ts +1 -0
  55. package/dist/components/Variables/index.d.ts.map +1 -1
  56. package/dist/components/Variables/index.js +1 -0
  57. package/dist/components/Variables/index.js.map +1 -1
  58. package/dist/components/index.d.ts +2 -1
  59. package/dist/components/index.d.ts.map +1 -1
  60. package/dist/components/index.js +2 -1
  61. package/dist/components/index.js.map +1 -1
  62. package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts +13 -0
  63. package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts.map +1 -0
  64. package/dist/context/PanelEditorProvider/PanelEditorProvider.js +33 -0
  65. package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -0
  66. package/dist/context/PanelEditorProvider/index.d.ts +3 -0
  67. package/dist/context/PanelEditorProvider/index.d.ts.map +1 -0
  68. package/dist/context/PanelEditorProvider/index.js +16 -0
  69. package/dist/context/PanelEditorProvider/index.js.map +1 -0
  70. package/dist/context/index.d.ts +1 -0
  71. package/dist/context/index.d.ts.map +1 -1
  72. package/dist/context/index.js +1 -0
  73. package/dist/context/index.js.map +1 -1
  74. package/package.json +5 -5
@@ -19,6 +19,7 @@ import { PluginKindSelect, usePluginEditor, PanelSpecEditor, getTitleAction, get
19
19
  import { Controller, FormProvider, useForm, useWatch } from 'react-hook-form';
20
20
  import { zodResolver } from '@hookform/resolvers/zod';
21
21
  import { useDashboard, useListPanelGroups } from '../../context';
22
+ import { PanelEditorProvider } from '../../context/PanelEditorProvider/PanelEditorProvider';
22
23
  import { PanelPreview } from './PanelPreview';
23
24
  import { usePanelEditor } from './usePanelEditor';
24
25
  export function PanelEditorForm(props) {
@@ -122,200 +123,202 @@ export function PanelEditorForm(props) {
122
123
  ]);
123
124
  return /*#__PURE__*/ _jsx(TimeRangeProvider, {
124
125
  timeRange: timeRange,
125
- children: /*#__PURE__*/ _jsxs(FormProvider, {
126
+ children: /*#__PURE__*/ _jsx(FormProvider, {
126
127
  ...form,
127
- children: [
128
- /*#__PURE__*/ _jsxs(Box, {
129
- sx: {
130
- display: 'flex',
131
- alignItems: 'center',
132
- padding: (theme)=>theme.spacing(1, 2),
133
- borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
134
- },
135
- children: [
136
- /*#__PURE__*/ _jsxs(Typography, {
137
- variant: "h2",
138
- children: [
139
- titleAction,
140
- " Panel"
141
- ]
142
- }),
143
- /*#__PURE__*/ _jsxs(Stack, {
144
- direction: "row",
145
- spacing: 1,
146
- marginLeft: "auto",
147
- children: [
148
- /*#__PURE__*/ _jsx(Button, {
149
- variant: "contained",
150
- disabled: !form.formState.isValid,
151
- onClick: handleSubmit,
152
- children: submitText
153
- }),
154
- /*#__PURE__*/ _jsx(Button, {
155
- color: "secondary",
156
- variant: "outlined",
157
- onClick: handleCancel,
158
- children: "Cancel"
159
- })
160
- ]
161
- })
162
- ]
163
- }),
164
- /*#__PURE__*/ _jsx(Box, {
165
- id: panelEditorFormId,
166
- sx: {
167
- flex: 1,
168
- overflowY: 'scroll',
169
- padding: (theme)=>theme.spacing(2)
170
- },
171
- children: /*#__PURE__*/ _jsxs(Grid, {
172
- container: true,
173
- spacing: 2,
128
+ children: /*#__PURE__*/ _jsxs(PanelEditorProvider, {
129
+ children: [
130
+ /*#__PURE__*/ _jsxs(Box, {
131
+ sx: {
132
+ display: 'flex',
133
+ alignItems: 'center',
134
+ padding: (theme)=>theme.spacing(1, 2),
135
+ borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
136
+ },
174
137
  children: [
175
- /*#__PURE__*/ _jsx(Grid, {
176
- item: true,
177
- xs: 8,
178
- children: /*#__PURE__*/ _jsx(Controller, {
179
- control: form.control,
180
- name: "panelDefinition.spec.display.name",
181
- render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
182
- ...field,
183
- required: true,
184
- fullWidth: true,
185
- label: "Name",
186
- error: !!fieldState.error,
187
- helperText: fieldState.error?.message,
188
- value: watchedName ?? '',
189
- onChange: (event)=>{
190
- field.onChange(event);
191
- setName(event.target.value);
192
- }
193
- })
194
- })
195
- }),
196
- /*#__PURE__*/ _jsx(Grid, {
197
- item: true,
198
- xs: 4,
199
- children: /*#__PURE__*/ _jsx(Controller, {
200
- control: form.control,
201
- name: "groupId",
202
- render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
203
- select: true,
204
- ...field,
205
- required: true,
206
- fullWidth: true,
207
- label: "Group",
208
- error: !!fieldState.error,
209
- helperText: fieldState.error?.message,
210
- onChange: (event)=>{
211
- field.onChange(event);
212
- },
213
- children: panelGroups.map((panelGroup, index)=>/*#__PURE__*/ _jsx(MenuItem, {
214
- value: panelGroup.id,
215
- children: panelGroup.title ?? `Group ${index + 1}`
216
- }, panelGroup.id))
217
- })
218
- })
219
- }),
220
- /*#__PURE__*/ _jsx(Grid, {
221
- item: true,
222
- xs: 8,
223
- children: /*#__PURE__*/ _jsx(Controller, {
224
- control: form.control,
225
- name: "panelDefinition.spec.display.description",
226
- render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
227
- ...field,
228
- fullWidth: true,
229
- label: "Description",
230
- error: !!fieldState.error,
231
- helperText: fieldState.error?.message,
232
- value: watchedDescription ?? '',
233
- onChange: (event)=>{
234
- field.onChange(event);
235
- setDescription(event.target.value);
236
- }
237
- })
238
- })
239
- }),
240
- /*#__PURE__*/ _jsx(Grid, {
241
- item: true,
242
- xs: 4,
243
- children: /*#__PURE__*/ _jsx(Controller, {
244
- control: form.control,
245
- name: "panelDefinition.spec.plugin.kind",
246
- render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(PluginKindSelect, {
247
- ...field,
248
- pluginTypes: [
249
- 'Panel'
250
- ],
251
- required: true,
252
- fullWidth: true,
253
- label: "Type",
254
- disabled: pluginEditor.isLoading,
255
- error: !!pluginEditor.error || !!fieldState.error,
256
- helperText: pluginEditor.error?.message ?? fieldState.error?.message,
257
- value: {
258
- type: 'Panel',
259
- kind: watchedPluginKind
260
- },
261
- onChange: (event)=>{
262
- field.onChange(event.kind);
263
- pluginEditor.onSelectionChange(event);
264
- }
265
- })
266
- })
138
+ /*#__PURE__*/ _jsxs(Typography, {
139
+ variant: "h2",
140
+ children: [
141
+ titleAction,
142
+ " Panel"
143
+ ]
267
144
  }),
268
- /*#__PURE__*/ _jsxs(Grid, {
269
- item: true,
270
- xs: 12,
145
+ /*#__PURE__*/ _jsxs(Stack, {
146
+ direction: "row",
147
+ spacing: 1,
148
+ marginLeft: "auto",
271
149
  children: [
272
- /*#__PURE__*/ _jsx(Typography, {
273
- variant: "h4",
274
- marginBottom: 1,
275
- children: "Preview"
150
+ /*#__PURE__*/ _jsx(Button, {
151
+ variant: "contained",
152
+ disabled: !form.formState.isValid,
153
+ onClick: handleSubmit,
154
+ children: submitText
276
155
  }),
277
- /*#__PURE__*/ _jsx(ErrorBoundary, {
278
- FallbackComponent: ErrorAlert,
279
- children: /*#__PURE__*/ _jsx(PanelPreview, {
280
- panelDefinition: panelDefinition
281
- })
156
+ /*#__PURE__*/ _jsx(Button, {
157
+ color: "secondary",
158
+ variant: "outlined",
159
+ onClick: handleCancel,
160
+ children: "Cancel"
282
161
  })
283
162
  ]
284
- }),
285
- /*#__PURE__*/ _jsx(Grid, {
286
- item: true,
287
- xs: 12,
288
- children: /*#__PURE__*/ _jsx(ErrorBoundary, {
289
- FallbackComponent: ErrorAlert,
290
- children: /*#__PURE__*/ _jsx(PanelSpecEditor, {
291
- ref: pluginEditorRef,
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,
176
+ children: [
177
+ /*#__PURE__*/ _jsx(Grid, {
178
+ item: true,
179
+ xs: 8,
180
+ children: /*#__PURE__*/ _jsx(Controller, {
181
+ control: form.control,
182
+ name: "panelDefinition.spec.display.name",
183
+ render: ({ field, fieldState })=>/*#__PURE__*/ _jsx(TextField, {
184
+ ...field,
185
+ required: true,
186
+ fullWidth: true,
187
+ label: "Name",
188
+ error: !!fieldState.error,
189
+ helperText: fieldState.error?.message,
190
+ value: watchedName ?? '',
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, {
292
246
  control: form.control,
293
- panelDefinition: panelDefinition,
294
- onJSONChange: handlePanelDefinitionChange,
295
- onQueriesChange: (queries)=>{
296
- setQueries(queries);
297
- },
298
- onPluginSpecChange: (spec)=>{
299
- pluginEditor.onSpecChange(spec);
300
- }
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
+ })
269
+ }),
270
+ /*#__PURE__*/ _jsxs(Grid, {
271
+ item: true,
272
+ xs: 12,
273
+ children: [
274
+ /*#__PURE__*/ _jsx(Typography, {
275
+ variant: "h4",
276
+ marginBottom: 1,
277
+ children: "Preview"
278
+ }),
279
+ /*#__PURE__*/ _jsx(ErrorBoundary, {
280
+ FallbackComponent: ErrorAlert,
281
+ children: /*#__PURE__*/ _jsx(PanelPreview, {
282
+ panelDefinition: panelDefinition
283
+ })
284
+ })
285
+ ]
286
+ }),
287
+ /*#__PURE__*/ _jsx(Grid, {
288
+ item: true,
289
+ xs: 12,
290
+ children: /*#__PURE__*/ _jsx(ErrorBoundary, {
291
+ FallbackComponent: ErrorAlert,
292
+ children: /*#__PURE__*/ _jsx(PanelSpecEditor, {
293
+ ref: pluginEditorRef,
294
+ control: form.control,
295
+ panelDefinition: panelDefinition,
296
+ onJSONChange: handlePanelDefinitionChange,
297
+ onQueriesChange: (queries)=>{
298
+ setQueries(queries);
299
+ },
300
+ onPluginSpecChange: (spec)=>{
301
+ pluginEditor.onSpecChange(spec);
302
+ }
303
+ })
301
304
  })
302
305
  })
303
- })
304
- ]
306
+ ]
307
+ })
308
+ }),
309
+ /*#__PURE__*/ _jsx(DiscardChangesConfirmationDialog, {
310
+ description: "You have unapplied changes in this panel. Are you sure you want to discard these changes? Changes cannot be recovered.",
311
+ isOpen: isDiscardDialogOpened,
312
+ onCancel: ()=>{
313
+ setDiscardDialogOpened(false);
314
+ },
315
+ onDiscardChanges: ()=>{
316
+ setDiscardDialogOpened(false);
317
+ onClose();
318
+ }
305
319
  })
306
- }),
307
- /*#__PURE__*/ _jsx(DiscardChangesConfirmationDialog, {
308
- description: "You have unapplied changes in this panel. Are you sure you want to discard these changes? Changes cannot be recovered.",
309
- isOpen: isDiscardDialogOpened,
310
- onCancel: ()=>{
311
- setDiscardDialogOpened(false);
312
- },
313
- onDiscardChanges: ()=>{
314
- setDiscardDialogOpened(false);
315
- onClose();
316
- }
317
- })
318
- ]
320
+ ]
321
+ })
319
322
  })
320
323
  });
321
324
  }
@@ -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 { 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 <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 <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 </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","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,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,mBAAmB;AASlD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM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CACTC,OAAM;4CACNjB,UAAU/C,aAAa2E,SAAS;4CAChCV,OAAO,CAAC,CAACjE,aAAaiE,KAAK,IAAI,CAAC,CAACJ,WAAWI,KAAK;4CACjDC,YAAYlE,aAAaiE,KAAK,EAAEE,WAAWN,WAAWI,KAAK,EAAEE;4CAC7DjE,OAAO;gDAAEE,MAAM;gDAASP,MAAMiC;4CAAkB;4CAChDzB,UAAU,CAAC+D;gDACTR,MAAMvD,QAAQ,CAAC+D,MAAMvE,IAAI;gDACzBG,aAAa4E,iBAAiB,CAACR;4CACjC;;;;0CAKR,MAAC5H;gCAAKiH,IAAI;gCAACC,IAAI;;kDACb,KAAC9G;wCAAWgG,SAAQ;wCAAKiC,cAAc;kDAAG;;kDAG1C,KAAC7H;wCAAc8H,mBAAmB/H;kDAChC,cAAA,KAACkB;4CAAaU,iBAAiBA;;;;;0CAGnC,KAACnC;gCAAKiH,IAAI;gCAACC,IAAI;0CACb,cAAA,KAAC1G;oCAAc8H,mBAAmB/H;8CAChC,cAAA,KAACI;wCACC4H,KAAKtG;wCACLoC,SAAStB,KAAKsB,OAAO;wCACrBlC,iBAAiBA;wCACjBqG,cAAc3D;wCACd4D,iBAAiB,CAACC;4CAChBnG,WAAWmG;wCACb;wCACAC,oBAAoB,CAAChG;4CACnBa,aAAaoF,YAAY,CAACjG;wCAC5B;;;;;;;8BAMV,KAACrC;oBACCuI,aAAY;oBACZC,QAAQlG;oBACRmG,UAAU;wBACRlG,uBAAuB;oBACzB;oBACAmG,kBAAkB;wBAChBnG,uBAAuB;wBACvBb;oBACF;;;;;AAKV;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, 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,QAA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;;;;;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 +1 @@
1
- {"version":3,"file":"PanelPreview.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelPreview.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAU,MAAM,OAAO,CAAC;AAG7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAMrD,wBAAgB,YAAY,CAAC,EAAE,eAAe,EAAE,EAAE,IAAI,CAAC,iBAAiB,EAAE,iBAAiB,CAAC,GAAG,YAAY,GAAG,IAAI,CAoCjH"}
1
+ {"version":3,"file":"PanelPreview.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelPreview.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAsB,MAAM,OAAO,CAAC;AAGzD,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,CAyCjH"}
@@ -11,17 +11,20 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- import { useRef } from 'react';
14
+ import { useContext, useRef } from 'react';
15
15
  import { Box } from '@mui/material';
16
16
  import { DataQueriesProvider, usePlugin, useSuggestedStepMs } from '@perses-dev/plugin-system';
17
17
  import { Panel } from '../Panel';
18
+ import { PanelEditorContext } from '../../context';
18
19
  const PANEL_PREVIEW_HEIGHT = 300;
19
20
  const PANEL_PREVIEW_DEFAULT_WIDTH = 840;
20
21
  export function PanelPreview({ panelDefinition }) {
21
22
  const boxRef = useRef(null);
22
23
  let width = PANEL_PREVIEW_DEFAULT_WIDTH;
24
+ const panelEditorContext = useContext(PanelEditorContext);
23
25
  if (boxRef.current !== null) {
24
26
  width = boxRef.current.getBoundingClientRect().width;
27
+ panelEditorContext?.preview?.setPreviewPanelWidth?.(width);
25
28
  }
26
29
  const suggestedStepMs = useSuggestedStepMs(width);
27
30
  const { data: plugin, isLoading } = usePlugin('Panel', panelDefinition.spec.plugin.kind);
@@ -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, useRef } from 'react';\nimport { Box } from '@mui/material';\nimport { DataQueriesProvider, usePlugin, useSuggestedStepMs } from '@perses-dev/plugin-system';\nimport { PanelEditorValues } from '@perses-dev/core';\nimport { Panel } from '../Panel';\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 if (boxRef.current !== null) {\n width = boxRef.current.getBoundingClientRect().width;\n }\n const suggestedStepMs = useSuggestedStepMs(width);\n\n const { data: plugin, isLoading } = usePlugin('Panel', panelDefinition.spec.plugin.kind);\n if (isLoading) {\n return null;\n }\n\n if (panelDefinition.spec.plugin.kind === '') {\n return null;\n }\n\n const queries = panelDefinition.spec.queries ?? [];\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const definitions = queries.length\n ? queries.map((query) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n })\n : [];\n\n return (\n <Box ref={boxRef} height={PANEL_PREVIEW_HEIGHT}>\n <DataQueriesProvider definitions={definitions} options={{ suggestedStepMs, ...plugin?.queryOptions }}>\n <Panel definition={panelDefinition} />\n </DataQueriesProvider>\n </Box>\n );\n}\n"],"names":["useRef","Box","DataQueriesProvider","usePlugin","useSuggestedStepMs","Panel","PANEL_PREVIEW_HEIGHT","PANEL_PREVIEW_DEFAULT_WIDTH","PanelPreview","panelDefinition","boxRef","width","current","getBoundingClientRect","suggestedStepMs","data","plugin","isLoading","spec","kind","queries","definitions","length","map","query","ref","height","options","queryOptions","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,MAAM,QAAQ,QAAQ;AAC7C,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,mBAAmB,EAAEC,SAAS,EAAEC,kBAAkB,QAAQ,4BAA4B;AAE/F,SAASC,KAAK,QAAQ,WAAW;AAEjC,MAAMC,uBAAuB;AAC7B,MAAMC,8BAA8B;AAEpC,OAAO,SAASC,aAAa,EAAEC,eAAe,EAA8C;IAC1F,MAAMC,SAASV,OAAuB;IACtC,IAAIW,QAAQJ;IACZ,IAAIG,OAAOE,OAAO,KAAK,MAAM;QAC3BD,QAAQD,OAAOE,OAAO,CAACC,qBAAqB,GAAGF,KAAK;IACtD;IACA,MAAMG,kBAAkBV,mBAAmBO;IAE3C,MAAM,EAAEI,MAAMC,MAAM,EAAEC,SAAS,EAAE,GAAGd,UAAU,SAASM,gBAAgBS,IAAI,CAACF,MAAM,CAACG,IAAI;IACvF,IAAIF,WAAW;QACb,OAAO;IACT;IAEA,IAAIR,gBAAgBS,IAAI,CAACF,MAAM,CAACG,IAAI,KAAK,IAAI;QAC3C,OAAO;IACT;IAEA,MAAMC,UAAUX,gBAAgBS,IAAI,CAACE,OAAO,IAAI,EAAE;IAElD,2DAA2D;IAC3D,MAAMC,cAAcD,QAAQE,MAAM,GAC9BF,QAAQG,GAAG,CAAC,CAACC;QACX,OAAO;YACLL,MAAMK,MAAMN,IAAI,CAACF,MAAM,CAACG,IAAI;YAC5BD,MAAMM,MAAMN,IAAI,CAACF,MAAM,CAACE,IAAI;QAC9B;IACF,KACA,EAAE;IAEN,qBACE,KAACjB;QAAIwB,KAAKf;QAAQgB,QAAQpB;kBACxB,cAAA,KAACJ;YAAoBmB,aAAaA;YAAaM,SAAS;gBAAEb;gBAAiB,GAAGE,QAAQY,YAAY;YAAC;sBACjG,cAAA,KAACvB;gBAAMwB,YAAYpB;;;;AAI3B"}
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 { DataQueriesProvider, usePlugin, useSuggestedStepMs } from '@perses-dev/plugin-system';\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 const suggestedStepMs = useSuggestedStepMs(width);\n\n const { data: plugin, isLoading } = usePlugin('Panel', panelDefinition.spec.plugin.kind);\n if (isLoading) {\n return null;\n }\n\n if (panelDefinition.spec.plugin.kind === '') {\n return null;\n }\n\n const queries = panelDefinition.spec.queries ?? [];\n\n // map TimeSeriesQueryDefinition to Definition<UnknownSpec>\n const definitions = queries.length\n ? queries.map((query) => {\n return {\n kind: query.spec.plugin.kind,\n spec: query.spec.plugin.spec,\n };\n })\n : [];\n\n return (\n <Box ref={boxRef} height={PANEL_PREVIEW_HEIGHT}>\n <DataQueriesProvider definitions={definitions} options={{ suggestedStepMs, ...plugin?.queryOptions }}>\n <Panel definition={panelDefinition} />\n </DataQueriesProvider>\n </Box>\n );\n}\n"],"names":["useContext","useRef","Box","DataQueriesProvider","usePlugin","useSuggestedStepMs","Panel","PanelEditorContext","PANEL_PREVIEW_HEIGHT","PANEL_PREVIEW_DEFAULT_WIDTH","PanelPreview","panelDefinition","boxRef","width","panelEditorContext","current","getBoundingClientRect","preview","setPreviewPanelWidth","suggestedStepMs","data","plugin","isLoading","spec","kind","queries","definitions","length","map","query","ref","height","options","queryOptions","definition"],"mappings":"AAA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AE;IAEN,qBACE,KAACrB;QAAI4B,KAAKlB;QAAQmB,QAAQvB;kBACxB,cAAA,KAACL;YAAoBuB,aAAaA;YAAaM,SAAS;gBAAEb;gBAAiB,GAAGE,QAAQY,YAAY;YAAC;sBACjG,cAAA,KAAC3B;gBAAM4B,YAAYvB;;;;AAI3B"}
@@ -1 +1 @@
1
- {"version":3,"file":"PanelGroupDialog.d.ts","sourceRoot":"","sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.tsx"],"names":[],"mappings":"AAeA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAK/C;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CA6D/C"}
1
+ {"version":3,"file":"PanelGroupDialog.d.ts","sourceRoot":"","sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAO/C;;GAEG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CAkD/C"}
@@ -11,10 +11,10 @@
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, Fragment as _Fragment } from "react/jsx-runtime";
14
- import { IconButton, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/material';
15
- import CloseIcon from 'mdi-material-ui/Close';
16
14
  import { useState } from 'react';
17
15
  import { useVariableValues } from '@perses-dev/plugin-system';
16
+ import { Dialog } from '@perses-dev/components';
17
+ import { Button } from '@mui/material';
18
18
  import { usePanelGroupEditor } from '../../context';
19
19
  import { PanelGroupEditorForm, panelGroupEditorFormId } from './PanelGroupEditorForm';
20
20
  /**
@@ -47,23 +47,13 @@ import { PanelGroupEditorForm, panelGroupEditorFormId } from './PanelGroupEditor
47
47
  },
48
48
  children: panelGroupEditor !== undefined && /*#__PURE__*/ _jsxs(_Fragment, {
49
49
  children: [
50
- /*#__PURE__*/ _jsxs(DialogTitle, {
50
+ /*#__PURE__*/ _jsxs(Dialog.Header, {
51
51
  children: [
52
52
  panelGroupEditor.mode,
53
53
  " Panel Group"
54
54
  ]
55
55
  }),
56
- /*#__PURE__*/ _jsx(IconButton, {
57
- "aria-label": "Close",
58
- onClick: panelGroupEditor.close,
59
- sx: (theme)=>({
60
- position: 'absolute',
61
- top: theme.spacing(0.5),
62
- right: theme.spacing(0.5)
63
- }),
64
- children: /*#__PURE__*/ _jsx(CloseIcon, {})
65
- }),
66
- /*#__PURE__*/ _jsx(DialogContent, {
56
+ /*#__PURE__*/ _jsx(Dialog.Content, {
67
57
  dividers: true,
68
58
  sx: {
69
59
  width: '500px'
@@ -74,7 +64,7 @@ import { PanelGroupEditorForm, panelGroupEditorFormId } from './PanelGroupEditor
74
64
  onSubmit: handleSubmit
75
65
  })
76
66
  }),
77
- /*#__PURE__*/ _jsxs(DialogActions, {
67
+ /*#__PURE__*/ _jsxs(Dialog.Actions, {
78
68
  children: [
79
69
  /*#__PURE__*/ _jsx(Button, {
80
70
  variant: "contained",