@perses-dev/dashboards 0.54.0-beta.6 → 0.54.0-beta.7

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 (54) hide show
  1. package/dist/cjs/context/DatasourceStoreProvider.js +33 -3
  2. package/dist/cjs/model/index.js +0 -1
  3. package/dist/components/Annotations/AnnotationsEditor.js.map +1 -1
  4. package/dist/components/Datasources/DatasourceEditor.d.ts.map +1 -1
  5. package/dist/components/Datasources/DatasourceEditor.js.map +1 -1
  6. package/dist/components/DownloadButton/serializeDashboard.d.ts +1 -1
  7. package/dist/components/DownloadButton/serializeDashboard.d.ts.map +1 -1
  8. package/dist/components/DownloadButton/serializeDashboard.js.map +1 -1
  9. package/dist/components/LeaveDialog/LeaveDialog.d.ts +1 -1
  10. package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
  11. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
  12. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
  13. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  14. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  15. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  16. package/dist/components/Variables/VariableEditor.js.map +1 -1
  17. package/dist/context/DashboardProvider/DashboardProvider.d.ts +1 -2
  18. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  19. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  20. package/dist/context/DashboardProvider/common.d.ts +1 -1
  21. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  22. package/dist/context/DashboardProvider/common.js.map +1 -1
  23. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +2 -1
  24. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  25. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  26. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +1 -1
  27. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  28. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  29. package/dist/context/DatasourceStoreProvider.d.ts +1 -2
  30. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  31. package/dist/context/DatasourceStoreProvider.js +34 -4
  32. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  33. package/dist/context/useDashboard.d.ts +1 -1
  34. package/dist/context/useDashboard.d.ts.map +1 -1
  35. package/dist/context/useDashboard.js.map +1 -1
  36. package/dist/model/index.d.ts +0 -1
  37. package/dist/model/index.d.ts.map +1 -1
  38. package/dist/model/index.js +0 -1
  39. package/dist/model/index.js.map +1 -1
  40. package/dist/test/dashboard-provider.d.ts +1 -1
  41. package/dist/test/dashboard-provider.d.ts.map +1 -1
  42. package/dist/test/dashboard-provider.js.map +1 -1
  43. package/dist/test/testDashboard.d.ts +1 -1
  44. package/dist/test/testDashboard.d.ts.map +1 -1
  45. package/dist/test/testDashboard.js.map +1 -1
  46. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -1
  47. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  48. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  49. package/package.json +5 -4
  50. package/dist/cjs/model/DashboardResource.js +0 -16
  51. package/dist/model/DashboardResource.d.ts +0 -9
  52. package/dist/model/DashboardResource.d.ts.map +0 -1
  53. package/dist/model/DashboardResource.js +0 -15
  54. package/dist/model/DashboardResource.js.map +0 -1
@@ -27,15 +27,24 @@ function DatasourceStoreProvider(props) {
27
27
  const { projectName, datasourceApi, onCreate, children } = props;
28
28
  const [dashboardResource, setDashboardResource] = (0, _react.useState)(props.dashboardResource);
29
29
  const [savedDatasources, setSavedDatasources] = (0, _react.useState)(props.savedDatasources ?? {});
30
+ // Cache for synchronous datasource spec access
31
+ const datasourceSpecCache = (0, _react.useRef)(new Map());
30
32
  const project = projectName ?? dashboardResource?.metadata.project;
31
33
  const { getPlugin, listPluginMetadata } = (0, _pluginsystem.usePluginRegistry)();
34
+ // Helper to create cache key from DatasourceSelector
35
+ const createCacheKey = (0, _react.useCallback)((selector)=>{
36
+ const name = selector.name === undefined ? '__undefined__' : selector.name;
37
+ return `${selector.kind}:${name}:${project ?? 'global'}`;
38
+ }, [
39
+ project
40
+ ]);
32
41
  const findDatasource = (0, _pluginsystem.useEvent)(async (selector)=>{
33
42
  // Try to find it in dashboard spec
34
43
  if (dashboardResource) {
35
44
  const { datasources } = dashboardResource.spec;
36
45
  const dashboardDatasource = findDashboardDatasource(datasources, selector);
37
46
  if (dashboardDatasource !== undefined) {
38
- return {
47
+ const result = {
39
48
  spec: dashboardDatasource.spec,
40
49
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
41
50
  project: dashboardResource.metadata.project,
@@ -43,30 +52,42 @@ function DatasourceStoreProvider(props) {
43
52
  name: dashboardDatasource.name
44
53
  })
45
54
  };
55
+ // Cache the spec for synchronous access
56
+ const cacheKey = createCacheKey(selector);
57
+ datasourceSpecCache.current.set(cacheKey, result.spec);
58
+ return result;
46
59
  }
47
60
  }
48
61
  if (project) {
49
62
  // Try to find it at the project level as a Datasource resource
50
63
  const datasource = await datasourceApi.getDatasource(String(project), selector);
51
64
  if (datasource !== undefined) {
52
- return {
65
+ const result = {
53
66
  spec: datasource.spec,
54
67
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
55
68
  project: datasource.metadata.project,
56
69
  name: datasource.metadata.name
57
70
  })
58
71
  };
72
+ // Cache the spec for synchronous access
73
+ const cacheKey = createCacheKey(selector);
74
+ datasourceSpecCache.current.set(cacheKey, result.spec);
75
+ return result;
59
76
  }
60
77
  }
61
78
  // Try to find it at the global level as a GlobalDatasource resource
62
79
  const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
63
80
  if (globalDatasource !== undefined) {
64
- return {
81
+ const result = {
65
82
  spec: globalDatasource.spec,
66
83
  proxyUrl: buildDatasourceProxyUrl(datasourceApi, {
67
84
  name: globalDatasource.metadata.name
68
85
  })
69
86
  };
87
+ // Cache the spec for synchronous access
88
+ const cacheKey = createCacheKey(selector);
89
+ datasourceSpecCache.current.set(cacheKey, result.spec);
90
+ return result;
70
91
  }
71
92
  throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
72
93
  });
@@ -161,6 +182,13 @@ function DatasourceStoreProvider(props) {
161
182
  }, [
162
183
  savedDatasources
163
184
  ]);
185
+ // Gets a cached datasource spec synchronously if available
186
+ const getDatasourceSpecSync = (0, _react.useCallback)((selector)=>{
187
+ const cacheKey = createCacheKey(selector);
188
+ return datasourceSpecCache.current.get(cacheKey);
189
+ }, [
190
+ createCacheKey
191
+ ]);
164
192
  const setLocalDatasources = (0, _react.useCallback)((datasources)=>{
165
193
  if (dashboardResource) {
166
194
  setDashboardResource({
@@ -177,6 +205,7 @@ function DatasourceStoreProvider(props) {
177
205
  const ctxValue = (0, _react.useMemo)(()=>({
178
206
  getDatasource,
179
207
  getDatasourceClient,
208
+ getDatasourceSpecSync,
180
209
  getLocalDatasources,
181
210
  setLocalDatasources,
182
211
  setSavedDatasources,
@@ -185,6 +214,7 @@ function DatasourceStoreProvider(props) {
185
214
  }), [
186
215
  getDatasource,
187
216
  getDatasourceClient,
217
+ getDatasourceSpecSync,
188
218
  getLocalDatasources,
189
219
  setLocalDatasources,
190
220
  listDatasourceSelectItems,
@@ -14,7 +14,6 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _export_star(require("./DashboardResource"), exports);
18
17
  _export_star(require("./PanelGroupDefinition"), exports);
19
18
  _export_star(require("./VariableDefinition"), exports);
20
19
  function _export_star(from, to) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Annotations/AnnotationsEditor.tsx"],"sourcesContent":["// Copyright 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 { useState, useMemo, ReactElement } from 'react';\nimport {\n Button,\n Stack,\n Box,\n TableContainer,\n TableBody,\n TableRow,\n TableCell as MuiTableCell,\n Table,\n TableHead,\n Switch,\n Typography,\n IconButton,\n Alert,\n styled,\n} from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { AnnotationSpec, Definition, UnknownSpec } from '@perses-dev/spec';\nimport { useImmer } from 'use-immer';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\nimport ArrowUp from 'mdi-material-ui/ArrowUp';\nimport ArrowDown from 'mdi-material-ui/ArrowDown';\n\nimport { ValidationProvider, AnnotationEditorForm } from '@perses-dev/plugin-system';\nimport { Action } from '@perses-dev/components';\nimport { useDiscardChangesConfirmationDialog } from '../../context';\n\nfunction validateAnnotationSpecs(annotationSpecs: AnnotationSpec[]): { isValid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n const annotationNames: string[] = [];\n\n for (const annotationSpec of annotationSpecs) {\n if (annotationNames.includes(annotationSpec.display.name)) {\n errors.push(`Duplicate annotation name: ${annotationSpec.display.name}`);\n } else {\n annotationNames.push(annotationSpec.display.name);\n }\n }\n\n return {\n errors: errors,\n isValid: errors.length === 0,\n };\n}\n\nexport function AnnotationEditor(props: {\n annotationSpecs: AnnotationSpec[];\n onChange: (annotationSpecs: AnnotationSpec[]) => void;\n onCancel: () => void;\n}): ReactElement {\n const [annotationSpecs, setAnnotationSpecs] = useImmer(props.annotationSpecs);\n const [annotationEditIdx, setAnnotationEditIdx] = useState<number | null>(null);\n const [annotationFormAction, setAnnotationFormAction] = useState<Action>('update');\n\n const validation = useMemo(() => validateAnnotationSpecs(annotationSpecs), [annotationSpecs]);\n const currentEditingAnnotationSpec: AnnotationSpec | undefined =\n annotationEditIdx !== null ? annotationSpecs[annotationEditIdx] : undefined;\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n const handleCancel = (): void => {\n if (JSON.stringify(props.annotationSpecs) !== JSON.stringify(annotationSpecs)) {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n closeDiscardChangesConfirmationDialog();\n props.onCancel();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n description:\n 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.',\n });\n } else {\n props.onCancel();\n }\n };\n\n const removeAnnotation = (index: number): void => {\n setAnnotationSpecs((draft) => {\n draft.splice(index, 1);\n });\n };\n\n const addAnnotation = (): void => {\n setAnnotationFormAction('create');\n setAnnotationSpecs((draft) => {\n draft.push({\n display: { name: 'NewAnnotation' },\n plugin: {} as Definition<UnknownSpec>,\n });\n });\n setAnnotationEditIdx(annotationSpecs.length);\n };\n\n const editAnnotation = (index: number): void => {\n setAnnotationFormAction('update');\n setAnnotationEditIdx(index);\n };\n\n const toggleAnnotationVisibility = (index: number, visible: boolean): void => {\n setAnnotationSpecs((draft) => {\n const v = draft[index];\n if (!v) {\n return;\n }\n v.display.hidden = !visible;\n });\n };\n\n const changeAnnotationOrder = (index: number, direction: 'up' | 'down'): void => {\n const step = direction === 'up' ? -1 : 1;\n\n setAnnotationSpecs((draft) => {\n const current = draft[index];\n const adjacent = draft[index + step];\n\n if (!current || !adjacent) {\n return;\n }\n\n draft[index + step] = current;\n draft[index] = adjacent;\n });\n };\n\n return (\n <>\n {annotationEditIdx !== null && currentEditingAnnotationSpec ? (\n <ValidationProvider>\n <AnnotationEditorForm\n initialAnnotationSpec={currentEditingAnnotationSpec}\n action={annotationFormAction}\n isDraft={true}\n onActionChange={setAnnotationFormAction}\n onSave={(definition: AnnotationSpec) => {\n setAnnotationSpecs((draft) => {\n draft[annotationEditIdx] = definition;\n setAnnotationEditIdx(null);\n });\n }}\n onClose={() => {\n if (annotationFormAction === 'create') {\n removeAnnotation(annotationEditIdx);\n }\n setAnnotationEditIdx(null);\n }}\n />\n </ValidationProvider>\n ) : (\n <>\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\">Edit Dashboard Annotations</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button\n disabled={props.annotationSpecs === annotationSpecs || !validation.isValid}\n variant=\"contained\"\n onClick={() => {\n props.onChange(annotationSpecs);\n }}\n >\n Apply\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Stack spacing={2}>\n <Stack spacing={2}>\n {!validation.isValid &&\n validation.errors.map((error) => (\n <Alert severity=\"error\" key={error}>\n {error}\n </Alert>\n ))}\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of annotations\">\n <TableHead>\n <TableRow>\n <TableCell>Visibility</TableCell>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {annotationSpecs.map((v, idx) => (\n <TableRow key={v.display.name}>\n <TableCell component=\"th\" scope=\"row\">\n <Switch\n checked={v.display?.hidden !== true}\n onChange={(e) => {\n toggleAnnotationVisibility(idx, e.target.checked);\n }}\n />\n </TableCell>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n {v.display.name}\n </TableCell>\n <TableCell>{v.plugin.kind}</TableCell>\n <TableCell>{v.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\" sx={{ whiteSpace: 'nowrap' }}>\n <IconButton onClick={() => changeAnnotationOrder(idx, 'up')} disabled={idx === 0}>\n <ArrowUp />\n </IconButton>\n <IconButton\n onClick={() => changeAnnotationOrder(idx, 'down')}\n disabled={idx === annotationSpecs.length - 1}\n >\n <ArrowDown />\n </IconButton>\n <IconButton onClick={() => editAnnotation(idx)}>\n <PencilIcon />\n </IconButton>\n <IconButton onClick={() => removeAnnotation(idx)}>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </TableContainer>\n <Box display=\"flex\">\n <Button\n variant=\"contained\"\n startIcon={<AddIcon />}\n sx={{ marginLeft: 'auto' }}\n onClick={addAnnotation}\n >\n Add Annotation\n </Button>\n </Box>\n </Stack>\n </Stack>\n </Box>\n </>\n )}\n </>\n );\n}\n\nconst TableCell = styled(MuiTableCell)(({ theme }) => ({\n borderBottom: `solid 1px ${theme.palette.divider}`,\n}));\n"],"names":["useState","useMemo","Button","Stack","Box","TableContainer","TableBody","TableRow","TableCell","MuiTableCell","Table","TableHead","Switch","Typography","IconButton","Alert","styled","AddIcon","useImmer","PencilIcon","TrashIcon","ArrowUp","ArrowDown","ValidationProvider","AnnotationEditorForm","useDiscardChangesConfirmationDialog","validateAnnotationSpecs","annotationSpecs","errors","annotationNames","annotationSpec","includes","display","name","push","isValid","length","AnnotationEditor","props","setAnnotationSpecs","annotationEditIdx","setAnnotationEditIdx","annotationFormAction","setAnnotationFormAction","validation","currentEditingAnnotationSpec","undefined","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleCancel","JSON","stringify","onDiscardChanges","onCancel","description","removeAnnotation","index","draft","splice","addAnnotation","plugin","editAnnotation","toggleAnnotationVisibility","visible","v","hidden","changeAnnotationOrder","direction","step","current","adjacent","initialAnnotationSpec","action","isDraft","onActionChange","onSave","definition","onClose","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","marginLeft","disabled","onClick","onChange","color","overflowY","map","error","severity","minWidth","aria-label","align","idx","component","scope","checked","e","target","fontWeight","kind","whiteSpace","startIcon"],"mappings":";AAAA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,SAAS,IAAMlC,iBAAiB4C;kFAC1C,cAAA,KAAC/E;;;;;uDA5BQ4C,EAAEhC,OAAO,CAACC,IAAI;;;;;8CAoCrC,KAAC7B;oCAAI4B,SAAQ;8CACX,cAAA,KAAC9B;wCACCoF,SAAQ;wCACRsB,yBAAW,KAAC3F;wCACZ6D,IAAI;4CAAES,YAAY;wCAAO;wCACzBE,SAAS9B;kDACV;;;;;;;;;;AAWnB;AAEA,MAAMnD,YAAYQ,OAAOP,cAAc,CAAC,EAAEwE,KAAK,EAAE,GAAM,CAAA;QACrDE,cAAc,CAAC,UAAU,EAAEF,MAAMG,OAAO,CAACC,OAAO,EAAE;IACpD,CAAA"}
1
+ {"version":3,"sources":["../../../src/components/Annotations/AnnotationsEditor.tsx"],"sourcesContent":["// Copyright 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 { useState, useMemo, ReactElement } from 'react';\nimport {\n Button,\n Stack,\n Box,\n TableContainer,\n TableBody,\n TableRow,\n TableCell as MuiTableCell,\n Table,\n TableHead,\n Switch,\n Typography,\n IconButton,\n Alert,\n styled,\n} from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { AnnotationSpec, Definition, UnknownSpec } from '@perses-dev/spec';\nimport { useImmer } from 'use-immer';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\nimport ArrowUp from 'mdi-material-ui/ArrowUp';\nimport ArrowDown from 'mdi-material-ui/ArrowDown';\n\nimport { ValidationProvider, AnnotationEditorForm } from '@perses-dev/plugin-system';\nimport { Action } from '@perses-dev/client';\nimport { useDiscardChangesConfirmationDialog } from '../../context';\n\nfunction validateAnnotationSpecs(annotationSpecs: AnnotationSpec[]): { isValid: boolean; errors: string[] } {\n const errors: string[] = [];\n\n const annotationNames: string[] = [];\n\n for (const annotationSpec of annotationSpecs) {\n if (annotationNames.includes(annotationSpec.display.name)) {\n errors.push(`Duplicate annotation name: ${annotationSpec.display.name}`);\n } else {\n annotationNames.push(annotationSpec.display.name);\n }\n }\n\n return {\n errors: errors,\n isValid: errors.length === 0,\n };\n}\n\nexport function AnnotationEditor(props: {\n annotationSpecs: AnnotationSpec[];\n onChange: (annotationSpecs: AnnotationSpec[]) => void;\n onCancel: () => void;\n}): ReactElement {\n const [annotationSpecs, setAnnotationSpecs] = useImmer(props.annotationSpecs);\n const [annotationEditIdx, setAnnotationEditIdx] = useState<number | null>(null);\n const [annotationFormAction, setAnnotationFormAction] = useState<Action>('update');\n\n const validation = useMemo(() => validateAnnotationSpecs(annotationSpecs), [annotationSpecs]);\n const currentEditingAnnotationSpec: AnnotationSpec | undefined =\n annotationEditIdx !== null ? annotationSpecs[annotationEditIdx] : undefined;\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n const handleCancel = (): void => {\n if (JSON.stringify(props.annotationSpecs) !== JSON.stringify(annotationSpecs)) {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n closeDiscardChangesConfirmationDialog();\n props.onCancel();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n description:\n 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.',\n });\n } else {\n props.onCancel();\n }\n };\n\n const removeAnnotation = (index: number): void => {\n setAnnotationSpecs((draft) => {\n draft.splice(index, 1);\n });\n };\n\n const addAnnotation = (): void => {\n setAnnotationFormAction('create');\n setAnnotationSpecs((draft) => {\n draft.push({\n display: { name: 'NewAnnotation' },\n plugin: {} as Definition<UnknownSpec>,\n });\n });\n setAnnotationEditIdx(annotationSpecs.length);\n };\n\n const editAnnotation = (index: number): void => {\n setAnnotationFormAction('update');\n setAnnotationEditIdx(index);\n };\n\n const toggleAnnotationVisibility = (index: number, visible: boolean): void => {\n setAnnotationSpecs((draft) => {\n const v = draft[index];\n if (!v) {\n return;\n }\n v.display.hidden = !visible;\n });\n };\n\n const changeAnnotationOrder = (index: number, direction: 'up' | 'down'): void => {\n const step = direction === 'up' ? -1 : 1;\n\n setAnnotationSpecs((draft) => {\n const current = draft[index];\n const adjacent = draft[index + step];\n\n if (!current || !adjacent) {\n return;\n }\n\n draft[index + step] = current;\n draft[index] = adjacent;\n });\n };\n\n return (\n <>\n {annotationEditIdx !== null && currentEditingAnnotationSpec ? (\n <ValidationProvider>\n <AnnotationEditorForm\n initialAnnotationSpec={currentEditingAnnotationSpec}\n action={annotationFormAction}\n isDraft={true}\n onActionChange={setAnnotationFormAction}\n onSave={(definition: AnnotationSpec) => {\n setAnnotationSpecs((draft) => {\n draft[annotationEditIdx] = definition;\n setAnnotationEditIdx(null);\n });\n }}\n onClose={() => {\n if (annotationFormAction === 'create') {\n removeAnnotation(annotationEditIdx);\n }\n setAnnotationEditIdx(null);\n }}\n />\n </ValidationProvider>\n ) : (\n <>\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\">Edit Dashboard Annotations</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button\n disabled={props.annotationSpecs === annotationSpecs || !validation.isValid}\n variant=\"contained\"\n onClick={() => {\n props.onChange(annotationSpecs);\n }}\n >\n Apply\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Stack spacing={2}>\n <Stack spacing={2}>\n {!validation.isValid &&\n validation.errors.map((error) => (\n <Alert severity=\"error\" key={error}>\n {error}\n </Alert>\n ))}\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of annotations\">\n <TableHead>\n <TableRow>\n <TableCell>Visibility</TableCell>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {annotationSpecs.map((v, idx) => (\n <TableRow key={v.display.name}>\n <TableCell component=\"th\" scope=\"row\">\n <Switch\n checked={v.display?.hidden !== true}\n onChange={(e) => {\n toggleAnnotationVisibility(idx, e.target.checked);\n }}\n />\n </TableCell>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n {v.display.name}\n </TableCell>\n <TableCell>{v.plugin.kind}</TableCell>\n <TableCell>{v.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\" sx={{ whiteSpace: 'nowrap' }}>\n <IconButton onClick={() => changeAnnotationOrder(idx, 'up')} disabled={idx === 0}>\n <ArrowUp />\n </IconButton>\n <IconButton\n onClick={() => changeAnnotationOrder(idx, 'down')}\n disabled={idx === annotationSpecs.length - 1}\n >\n <ArrowDown />\n </IconButton>\n <IconButton onClick={() => editAnnotation(idx)}>\n <PencilIcon />\n </IconButton>\n <IconButton onClick={() => removeAnnotation(idx)}>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n ))}\n </TableBody>\n </Table>\n </TableContainer>\n <Box display=\"flex\">\n <Button\n variant=\"contained\"\n startIcon={<AddIcon />}\n sx={{ marginLeft: 'auto' }}\n onClick={addAnnotation}\n >\n Add Annotation\n </Button>\n </Box>\n </Stack>\n </Stack>\n </Box>\n </>\n )}\n </>\n );\n}\n\nconst TableCell = styled(MuiTableCell)(({ theme }) => ({\n borderBottom: `solid 1px ${theme.palette.divider}`,\n}));\n"],"names":["useState","useMemo","Button","Stack","Box","TableContainer","TableBody","TableRow","TableCell","MuiTableCell","Table","TableHead","Switch","Typography","IconButton","Alert","styled","AddIcon","useImmer","PencilIcon","TrashIcon","ArrowUp","ArrowDown","ValidationProvider","AnnotationEditorForm","useDiscardChangesConfirmationDialog","validateAnnotationSpecs","annotationSpecs","errors","annotationNames","annotationSpec","includes","display","name","push","isValid","length","AnnotationEditor","props","setAnnotationSpecs","annotationEditIdx","setAnnotationEditIdx","annotationFormAction","setAnnotationFormAction","validation","currentEditingAnnotationSpec","undefined","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleCancel","JSON","stringify","onDiscardChanges","onCancel","description","removeAnnotation","index","draft","splice","addAnnotation","plugin","editAnnotation","toggleAnnotationVisibility","visible","v","hidden","changeAnnotationOrder","direction","step","current","adjacent","initialAnnotationSpec","action","isDraft","onActionChange","onSave","definition","onClose","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","marginLeft","disabled","onClick","onChange","color","overflowY","map","error","severity","minWidth","aria-label","align","idx","component","scope","checked","e","target","fontWeight","kind","whiteSpace","startIcon"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,QAAQ,EAAEC,OAAO,QAAsB,QAAQ;AACxD,SACEC,MAAM,EACNC,KAAK,EACLC,GAAG,EACHC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,aAAaC,YAAY,EACzBC,KAAK,EACLC,SAAS,EACTC,MAAM,EACNC,UAAU,EACVC,UAAU,EACVC,KAAK,EACLC,MAAM,QACD,gBAAgB;AACvB,OAAOC,aAAa,uBAAuB;AAE3C,SAASC,QAAQ,QAAQ,YAAY;AACrC,OAAOC,gBAAgB,yBAAyB;AAChD,OAAOC,eAAe,2BAA2B;AACjD,OAAOC,aAAa,0BAA0B;AAC9C,OAAOC,eAAe,4BAA4B;AAElD,SAASC,kBAAkB,EAAEC,oBAAoB,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CAAC;AAK/C,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,KAAK,IAAI,CAAC;IAChE,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,YAAY,CA4Jf"}
1
+ {"version":3,"file":"DatasourceEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Datasources/DatasourceEditor.tsx"],"names":[],"mappings":"AA6BA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAK/C,wBAAgB,gBAAgB,CAAC,KAAK,EAAE;IACtC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,QAAQ,EAAE,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,KAAK,IAAI,CAAC;IAChE,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,GAAG,YAAY,CA4Jf"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Datasources/DatasourceEditor.tsx"],"sourcesContent":["// Copyright 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 {\n Box,\n Button,\n IconButton,\n Stack,\n Table,\n TableBody,\n TableCell,\n TableContainer,\n TableHead,\n TableRow,\n Typography,\n} from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\nimport { Action } from '@perses-dev/components';\nimport { DatasourceSpec } from '@perses-dev/spec';\nimport { DatasourceEditorForm, ValidationProvider } from '@perses-dev/plugin-system';\nimport { ReactElement, useState } from 'react';\nimport { useImmer } from 'use-immer';\nimport { DatasourceDefinition } from '@perses-dev/client';\nimport { useDiscardChangesConfirmationDialog } from '../../context';\n\nexport function DatasourceEditor(props: {\n datasources: Record<string, DatasourceSpec>;\n onChange: (datasources: Record<string, DatasourceSpec>) => void;\n onCancel: () => void;\n}): ReactElement {\n const [datasources, setDatasources] = useImmer(props.datasources);\n const [datasourceFormAction, setDatasourceFormAction] = useState<Action>('update');\n const [datasourceEdit, setDatasourceEdit] = useState<DatasourceDefinition | null>(null);\n const defaultSpec: DatasourceSpec = {\n default: false,\n plugin: {\n // TODO: find a way to avoid assuming that the PrometheusDatasource plugin is installed\n kind: 'PrometheusDatasource',\n spec: {},\n },\n };\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleCancel = (): void => {\n if (JSON.stringify(props.datasources) !== JSON.stringify(datasources)) {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n closeDiscardChangesConfirmationDialog();\n props.onCancel();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n description:\n 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.',\n });\n } else {\n props.onCancel();\n }\n };\n\n const removeDatasource = (name: string): void => {\n setDatasources((draft) => {\n delete draft[name];\n });\n };\n\n const addDatasource = (): void => {\n setDatasourceFormAction('create');\n setDatasourceEdit({\n name: 'NewDatasource',\n spec: defaultSpec,\n });\n };\n\n const editDatasource = (name: string): void => {\n setDatasourceFormAction('update');\n setDatasourceEdit({\n name: name,\n spec: datasources[name] ?? defaultSpec,\n });\n };\n\n return (\n <>\n {datasourceEdit ? (\n <ValidationProvider>\n <DatasourceEditorForm\n initialDatasourceDefinition={datasourceEdit}\n action={datasourceFormAction}\n isDraft={true}\n onActionChange={setDatasourceFormAction}\n onSave={(def: DatasourceDefinition) => {\n setDatasources((draft) => {\n delete draft[datasourceEdit.name]; // to tackle the case where datasource name has been changed\n draft[def.name] = def.spec;\n setDatasourceEdit(null);\n });\n }}\n onClose={() => {\n setDatasourceEdit(null);\n }}\n />\n </ValidationProvider>\n ) : (\n <>\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\">Edit Dashboard Datasources</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button\n disabled={props.datasources === datasources}\n variant=\"contained\"\n onClick={() => {\n props.onChange(datasources);\n }}\n >\n Apply\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Stack spacing={2}>\n <Stack spacing={2}>\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of datasources\">\n <TableHead>\n <TableRow>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {Object.entries(datasources).map(([name, spec]) => {\n return (\n <TableRow key={name}>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n {name}\n </TableCell>\n <TableCell>{spec.plugin.kind}</TableCell>\n <TableCell>{spec.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\" sx={{ whiteSpace: 'nowrap' }}>\n <IconButton onClick={() => editDatasource(name)}>\n <PencilIcon />\n </IconButton>\n <IconButton onClick={() => removeDatasource(name)}>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n );\n })}\n </TableBody>\n </Table>\n </TableContainer>\n <Box display=\"flex\">\n <Button\n variant=\"contained\"\n startIcon={<AddIcon />}\n sx={{ marginLeft: 'auto' }}\n onClick={addDatasource}\n >\n Add Datasource\n </Button>\n </Box>\n </Stack>\n </Stack>\n </Box>\n </>\n )}\n </>\n );\n}\n"],"names":["Box","Button","IconButton","Stack","Table","TableBody","TableCell","TableContainer","TableHead","TableRow","Typography","AddIcon","PencilIcon","TrashIcon","DatasourceEditorForm","ValidationProvider","useState","useImmer","useDiscardChangesConfirmationDialog","DatasourceEditor","props","datasources","setDatasources","datasourceFormAction","setDatasourceFormAction","datasourceEdit","setDatasourceEdit","defaultSpec","default","plugin","kind","spec","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleCancel","JSON","stringify","onDiscardChanges","onCancel","description","removeDatasource","name","draft","addDatasource","editDatasource","initialDatasourceDefinition","action","isDraft","onActionChange","onSave","def","onClose","sx","display","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","direction","marginLeft","disabled","onClick","onChange","color","overflowY","minWidth","aria-label","align","Object","entries","map","component","scope","fontWeight","whiteSpace","startIcon"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SACEA,GAAG,EACHC,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,UAAU,QACL,gBAAgB;AACvB,OAAOC,aAAa,uBAAuB;AAC3C,OAAOC,gBAAgB,yBAAyB;AAChD,OAAOC,eAAe,2BAA2B;AAGjD,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,4BAA4B;AACrF,SAAuBC,QAAQ,QAAQ,QAAQ;AAC/C,SAASC,QAAQ,QAAQ,YAAY;AAErC,SAASC,mCAAmC,QA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d,eAAe;;0EACzC,MAACjC;gEAAUiE,OAAM;gEAAQnB,IAAI;oEAAE0B,YAAY;gEAAS;;kFAClD,KAAC5E;wEAAW+D,SAAS,IAAMrB,eAAeH;kFACxC,cAAA,KAAC7B;;kFAEH,KAACV;wEAAW+D,SAAS,IAAMzB,iBAAiBC;kFAC1C,cAAA,KAAC5B;;;;;uDAXQ4B;gDAgBnB;;;;;8CAIN,KAACzC;oCAAIqD,SAAQ;8CACX,cAAA,KAACpD;wCACC4D,SAAQ;wCACRkB,yBAAW,KAACpE;wCACZyC,IAAI;4CAAEW,YAAY;wCAAO;wCACzBE,SAAStB;kDACV;;;;;;;;;;AAWnB"}
1
+ {"version":3,"sources":["../../../src/components/Datasources/DatasourceEditor.tsx"],"sourcesContent":["// Copyright 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 {\n Box,\n Button,\n IconButton,\n Stack,\n Table,\n TableBody,\n TableCell,\n TableContainer,\n TableHead,\n TableRow,\n Typography,\n} from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport TrashIcon from 'mdi-material-ui/TrashCan';\nimport { DatasourceSpec } from '@perses-dev/spec';\nimport { DatasourceEditorForm, ValidationProvider } from '@perses-dev/plugin-system';\nimport { ReactElement, useState } from 'react';\nimport { useImmer } from 'use-immer';\nimport { Action, DatasourceDefinition } from '@perses-dev/client';\nimport { useDiscardChangesConfirmationDialog } from '../../context';\n\nexport function DatasourceEditor(props: {\n datasources: Record<string, DatasourceSpec>;\n onChange: (datasources: Record<string, DatasourceSpec>) => void;\n onCancel: () => void;\n}): ReactElement {\n const [datasources, setDatasources] = useImmer(props.datasources);\n const [datasourceFormAction, setDatasourceFormAction] = useState<Action>('update');\n const [datasourceEdit, setDatasourceEdit] = useState<DatasourceDefinition | null>(null);\n const defaultSpec: DatasourceSpec = {\n default: false,\n plugin: {\n // TODO: find a way to avoid assuming that the PrometheusDatasource plugin is installed\n kind: 'PrometheusDatasource',\n spec: {},\n },\n };\n\n const { openDiscardChangesConfirmationDialog, closeDiscardChangesConfirmationDialog } =\n useDiscardChangesConfirmationDialog();\n\n const handleCancel = (): void => {\n if (JSON.stringify(props.datasources) !== JSON.stringify(datasources)) {\n openDiscardChangesConfirmationDialog({\n onDiscardChanges: () => {\n closeDiscardChangesConfirmationDialog();\n props.onCancel();\n },\n onCancel: () => {\n closeDiscardChangesConfirmationDialog();\n },\n description:\n 'You have unapplied changes. Are you sure you want to discard these changes? Changes cannot be recovered.',\n });\n } else {\n props.onCancel();\n }\n };\n\n const removeDatasource = (name: string): void => {\n setDatasources((draft) => {\n delete draft[name];\n });\n };\n\n const addDatasource = (): void => {\n setDatasourceFormAction('create');\n setDatasourceEdit({\n name: 'NewDatasource',\n spec: defaultSpec,\n });\n };\n\n const editDatasource = (name: string): void => {\n setDatasourceFormAction('update');\n setDatasourceEdit({\n name: name,\n spec: datasources[name] ?? defaultSpec,\n });\n };\n\n return (\n <>\n {datasourceEdit ? (\n <ValidationProvider>\n <DatasourceEditorForm\n initialDatasourceDefinition={datasourceEdit}\n action={datasourceFormAction}\n isDraft={true}\n onActionChange={setDatasourceFormAction}\n onSave={(def: DatasourceDefinition) => {\n setDatasources((draft) => {\n delete draft[datasourceEdit.name]; // to tackle the case where datasource name has been changed\n draft[def.name] = def.spec;\n setDatasourceEdit(null);\n });\n }}\n onClose={() => {\n setDatasourceEdit(null);\n }}\n />\n </ValidationProvider>\n ) : (\n <>\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\">Edit Dashboard Datasources</Typography>\n <Stack direction=\"row\" spacing={1} marginLeft=\"auto\">\n <Button\n disabled={props.datasources === datasources}\n variant=\"contained\"\n onClick={() => {\n props.onChange(datasources);\n }}\n >\n Apply\n </Button>\n <Button color=\"secondary\" variant=\"outlined\" onClick={handleCancel}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <Box padding={2} sx={{ overflowY: 'scroll' }}>\n <Stack spacing={2}>\n <Stack spacing={2}>\n <TableContainer>\n <Table sx={{ minWidth: 650 }} aria-label=\"table of datasources\">\n <TableHead>\n <TableRow>\n <TableCell>Name</TableCell>\n <TableCell>Type</TableCell>\n <TableCell>Description</TableCell>\n <TableCell align=\"right\">Actions</TableCell>\n </TableRow>\n </TableHead>\n <TableBody>\n {Object.entries(datasources).map(([name, spec]) => {\n return (\n <TableRow key={name}>\n <TableCell component=\"th\" scope=\"row\" sx={{ fontWeight: 'bold' }}>\n {name}\n </TableCell>\n <TableCell>{spec.plugin.kind}</TableCell>\n <TableCell>{spec.display?.description ?? ''}</TableCell>\n <TableCell align=\"right\" sx={{ whiteSpace: 'nowrap' }}>\n <IconButton onClick={() => editDatasource(name)}>\n <PencilIcon />\n </IconButton>\n <IconButton onClick={() => removeDatasource(name)}>\n <TrashIcon />\n </IconButton>\n </TableCell>\n </TableRow>\n );\n })}\n </TableBody>\n </Table>\n </TableContainer>\n <Box display=\"flex\">\n <Button\n variant=\"contained\"\n startIcon={<AddIcon />}\n sx={{ marginLeft: 'auto' }}\n onClick={addDatasource}\n >\n Add Datasource\n </Button>\n </Box>\n </Stack>\n </Stack>\n </Box>\n </>\n )}\n </>\n );\n}\n"],"names":["Box","Button","IconButton","Stack","Table","TableBody","TableCell","TableContainer","TableHead","TableRow","Typography","AddIcon","PencilIcon","TrashIcon","DatasourceEditorForm","ValidationProvider","useState","useImmer","useDiscardChangesConfirmationDialog","DatasourceEditor","props","datasources","setDatasources","datasourceFormAction","setDatasourceFormAction","datasourceEdit","setDatasourceEdit","defaultSpec","default","plugin","kind","spec","openDiscardChangesConfirmationDialog","closeDiscardChangesConfirmationDialog","handleCancel","JSON","stringify","onDiscardChanges","onCancel","description","removeDatasource","name","draft","addDatasource","editDatasource","initialDatasourceDefinition","action","isDraft","onActionChange","onSave","def","onClose","sx","display","alignItems","padding","theme","spacing","borderBottom","palette","divider","variant","direction","marginLeft","disabled","onClick","onChange","color","overflowY","minWidth","aria-label","align","Object","entries","map","component","scope","fontWeight","whiteSpace","startIcon"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SACEA,GAAG,EACHC,MAAM,EACNC,UAAU,EACVC,KAAK,EACLC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,cAAc,EACdC,SAAS,EACTC,QAAQ,EACRC,UAAU,QACL,gBAAgB;AACvB,OAAOC,aAAa,uBAAuB;AAC3C,OAAOC,gBAAgB,yBAAyB;AAChD,OAAOC,eAAe,2BAA2B;AAEjD,SAASC,oBAAoB,EAAEC,kBAAkB,QAAQ,4BAA4B;AACrF,SAAuBC,QAAQ,QAAQ,QAAQ;AAC/C,SAASC,QAAQ,QAAQ,YAAY;AAErC,SAASC,mCAAmC,QAAQ,gBAAgB;AAEpE,OAAO,SAASC,iBAAiBC,KAIhC;IACC,MAAM,CAACC,aAAaC,eAAe,GAAGL,SAASG,MAAMC,WAAW;IAChE,MAAM,CAACE,sBAAsBC,wBAAwB,GAAGR,SAAiB;IACzE,MAAM,CAACS,gBAAgBC,kBAAkB,GAAGV,SAAsC;IAClF,MAAMW,cAA8B;QAClCC,SAAS;QACTC,QAAQ;YACN,uFAAuF;YACvFC,MAAM;YACNC,MAAM,CAAC;QACT;IACF;IAEA,MAAM,EAAEC,oCAAoC,EA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wCACZyC,IAAI;4CAAEW,YAAY;wCAAO;wCACzBE,SAAStB;kDACV;;;;;;;;;;AAWnB"}
@@ -1,4 +1,4 @@
1
- import { DashboardResource } from '../../model/DashboardResource';
1
+ import { DashboardResource } from '@perses-dev/client';
2
2
  type SerializedDashboard = {
3
3
  contentType: string;
4
4
  content: string;
@@ -1 +1 @@
1
- {"version":3,"file":"serializeDashboard.d.ts","sourceRoot":"","sources":["../../../src/components/DownloadButton/serializeDashboard.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAKlE,KAAK,mBAAmB,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAoDF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,KAAK,CAAC,EAAE,aAAa,GAAG,aAAa,GACpC,mBAAmB,CAOrB"}
1
+ {"version":3,"file":"serializeDashboard.d.ts","sourceRoot":"","sources":["../../../src/components/DownloadButton/serializeDashboard.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAMvD,KAAK,mBAAmB,GAAG;IACzB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAoDF,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,KAAK,CAAC,EAAE,aAAa,GAAG,aAAa,GACpC,mBAAmB,CAOrB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/DownloadButton/serializeDashboard.ts"],"sourcesContent":["// Copyright 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 { stringify } from 'yaml';\nimport { DashboardResource } from '../../model/DashboardResource';\n\n//TODO: Although the previous comment suggests the metadata not should not be used, I keep them. Need to be discussed.\n// Check git history to find prev comment\n\ntype SerializedDashboard = {\n contentType: string;\n content: string;\n};\n\nfunction serializeYaml(dashboard: DashboardResource, shape?: 'cr-v1alpha1' | 'cr-v1alpha2'): SerializedDashboard {\n let content: string;\n\n if (shape === 'cr-v1alpha1') {\n const name = dashboard.metadata.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');\n content = stringify(\n {\n apiVersion: 'perses.dev/v1alpha1',\n kind: 'PersesDashboard',\n metadata: {\n labels: {\n 'app.kubernetes.io/name': 'perses-dashboard',\n 'app.kubernetes.io/instance': name,\n 'app.kubernetes.io/part-of': 'perses-operator',\n },\n name,\n namespace: dashboard.metadata.project,\n },\n spec: dashboard.spec,\n },\n { schema: 'yaml-1.1' }\n );\n } else if (shape === 'cr-v1alpha2') {\n const name = dashboard.metadata.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');\n content = stringify(\n {\n apiVersion: 'perses.dev/v1alpha2',\n kind: 'PersesDashboard',\n metadata: {\n labels: {\n 'app.kubernetes.io/name': 'perses-dashboard',\n 'app.kubernetes.io/instance': name,\n 'app.kubernetes.io/part-of': 'perses-operator',\n },\n name,\n namespace: dashboard.metadata.project,\n },\n spec: {\n config: dashboard.spec,\n },\n },\n { schema: 'yaml-1.1' }\n );\n } else {\n content = stringify(dashboard, { schema: 'yaml-1.1' });\n }\n\n return { contentType: 'application/yaml', content };\n}\n\nexport function serializeDashboard(\n dashboard: DashboardResource,\n format: 'json' | 'yaml',\n shape?: 'cr-v1alpha1' | 'cr-v1alpha2'\n): SerializedDashboard {\n switch (format) {\n case 'json':\n return { contentType: 'application/json', content: JSON.stringify(dashboard, null, 2) };\n case 'yaml':\n return serializeYaml(dashboard, shape);\n }\n}\n"],"names":["stringify","serializeYaml","dashboard","shape","content","name","metadata","toLowerCase","replace","apiVersion","kind","labels","namespace","project","spec","schema","config","contentType","serializeDashboard","format","JSON"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,SAAS,QAAQ,OAAO;AAWjC,SAASC,cAAcC,SAA4B,EAAEC,KAAqC;IACxF,IAAIC;IAEJ,IAAID,UAAU,eAAe;QAC3B,MAAME,OAAOH,UAAUI,QAAQ,CAACD,IAAI,CAACE,WAAW,GAAGC,OAAO,CAAC,eAAe;QAC1EJ,UAAUJ,UACR;YACES,YAAY;YACZC,MAAM;YACNJ,UAAU;gBACRK,QAAQ;oBACN,0BAA0B;oBAC1B,8BAA8BN;oBAC9B,6BAA6B;gBAC/B;gBACAA;gBACAO,WAAWV,UAAUI,QAAQ,CAACO,OAAO;YACvC;YACAC,MAAMZ,UAAUY,IAAI;QACtB,GACA;YAAEC,QAAQ;QAAW;IAEzB,OAAO,IAAIZ,UAAU,eAAe;QAClC,MAAME,OAAOH,UAAUI,QAAQ,CAACD,IAAI,CAACE,WAAW,GAAGC,OAAO,CAAC,eAAe;QAC1EJ,UAAUJ,UACR;YACES,YAAY;YACZC,MAAM;YACNJ,UAAU;gBACRK,QAAQ;oBACN,0BAA0B;oBAC1B,8BAA8BN;oBAC9B,6BAA6B;gBAC/B;gBACAA;gBACAO,WAAWV,UAAUI,QAAQ,CAACO,OAAO;YACvC;YACAC,MAAM;gBACJE,QAAQd,UAAUY,IAAI;YACxB;QACF,GACA;YAAEC,QAAQ;QAAW;IAEzB,OAAO;QACLX,UAAUJ,UAAUE,WAAW;YAAEa,QAAQ;QAAW;IACtD;IAEA,OAAO;QAAEE,aAAa;QAAoBb;IAAQ;AACpD;AAEA,OAAO,SAASc,mBACdhB,SAA4B,EAC5BiB,MAAuB,EACvBhB,KAAqC;IAErC,OAAQgB;QACN,KAAK;YACH,OAAO;gBAAEF,aAAa;gBAAoBb,SAASgB,KAAKpB,SAAS,CAACE,WAAW,MAAM;YAAG;QACxF,KAAK;YACH,OAAOD,cAAcC,WAAWC;IACpC;AACF"}
1
+ {"version":3,"sources":["../../../src/components/DownloadButton/serializeDashboard.ts"],"sourcesContent":["// Copyright 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 { DashboardResource } from '@perses-dev/client';\nimport { stringify } from 'yaml';\n\n//TODO: Although the previous comment suggests the metadata not should not be used, I keep them. Need to be discussed.\n// Check git history to find prev comment\n\ntype SerializedDashboard = {\n contentType: string;\n content: string;\n};\n\nfunction serializeYaml(dashboard: DashboardResource, shape?: 'cr-v1alpha1' | 'cr-v1alpha2'): SerializedDashboard {\n let content: string;\n\n if (shape === 'cr-v1alpha1') {\n const name = dashboard.metadata.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');\n content = stringify(\n {\n apiVersion: 'perses.dev/v1alpha1',\n kind: 'PersesDashboard',\n metadata: {\n labels: {\n 'app.kubernetes.io/name': 'perses-dashboard',\n 'app.kubernetes.io/instance': name,\n 'app.kubernetes.io/part-of': 'perses-operator',\n },\n name,\n namespace: dashboard.metadata.project,\n },\n spec: dashboard.spec,\n },\n { schema: 'yaml-1.1' }\n );\n } else if (shape === 'cr-v1alpha2') {\n const name = dashboard.metadata.name.toLowerCase().replace(/[^a-z0-9-]/g, '-');\n content = stringify(\n {\n apiVersion: 'perses.dev/v1alpha2',\n kind: 'PersesDashboard',\n metadata: {\n labels: {\n 'app.kubernetes.io/name': 'perses-dashboard',\n 'app.kubernetes.io/instance': name,\n 'app.kubernetes.io/part-of': 'perses-operator',\n },\n name,\n namespace: dashboard.metadata.project,\n },\n spec: {\n config: dashboard.spec,\n },\n },\n { schema: 'yaml-1.1' }\n );\n } else {\n content = stringify(dashboard, { schema: 'yaml-1.1' });\n }\n\n return { contentType: 'application/yaml', content };\n}\n\nexport function serializeDashboard(\n dashboard: DashboardResource,\n format: 'json' | 'yaml',\n shape?: 'cr-v1alpha1' | 'cr-v1alpha2'\n): SerializedDashboard {\n switch (format) {\n case 'json':\n return { contentType: 'application/json', content: JSON.stringify(dashboard, null, 2) };\n case 'yaml':\n return serializeYaml(dashboard, shape);\n }\n}\n"],"names":["stringify","serializeYaml","dashboard","shape","content","name","metadata","toLowerCase","replace","apiVersion","kind","labels","namespace","project","spec","schema","config","contentType","serializeDashboard","format","JSON"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,SAAS,QAAQ,OAAO;AAUjC,SAASC,cAAcC,SAA4B,EAAEC,KAAqC;IACxF,IAAIC;IAEJ,IAAID,UAAU,eAAe;QAC3B,MAAME,OAAOH,UAAUI,QAAQ,CAACD,IAAI,CAACE,WAAW,GAAGC,OAAO,CAAC,eAAe;QAC1EJ,UAAUJ,UACR;YACES,YAAY;YACZC,MAAM;YACNJ,UAAU;gBACRK,QAAQ;oBACN,0BAA0B;oBAC1B,8BAA8BN;oBAC9B,6BAA6B;gBAC/B;gBACAA;gBACAO,WAAWV,UAAUI,QAAQ,CAACO,OAAO;YACvC;YACAC,MAAMZ,UAAUY,IAAI;QACtB,GACA;YAAEC,QAAQ;QAAW;IAEzB,OAAO,IAAIZ,UAAU,eAAe;QAClC,MAAME,OAAOH,UAAUI,QAAQ,CAACD,IAAI,CAACE,WAAW,GAAGC,OAAO,CAAC,eAAe;QAC1EJ,UAAUJ,UACR;YACES,YAAY;YACZC,MAAM;YACNJ,UAAU;gBACRK,QAAQ;oBACN,0BAA0B;oBAC1B,8BAA8BN;oBAC9B,6BAA6B;gBAC/B;gBACAA;gBACAO,WAAWV,UAAUI,QAAQ,CAACO,OAAO;YACvC;YACAC,MAAM;gBACJE,QAAQd,UAAUY,IAAI;YACxB;QACF,GACA;YAAEC,QAAQ;QAAW;IAEzB,OAAO;QACLX,UAAUJ,UAAUE,WAAW;YAAEa,QAAQ;QAAW;IACtD;IAEA,OAAO;QAAEE,aAAa;QAAoBb;IAAQ;AACpD;AAEA,OAAO,SAASc,mBACdhB,SAA4B,EAC5BiB,MAAuB,EACvBhB,KAAqC;IAErC,OAAQgB;QACN,KAAK;YACH,OAAO;gBAAEF,aAAa;gBAAoBb,SAASgB,KAAKpB,SAAS,CAACE,WAAW,MAAM;YAAG;QACxF,KAAK;YACH,OAAOD,cAAcC,WAAWC;IACpC;AACF"}
@@ -1,6 +1,6 @@
1
1
  import { ReactElement, ReactNode } from 'react';
2
2
  import type { BlockerFunction } from '@remix-run/router';
3
- import { DashboardResource } from '../../model';
3
+ import { DashboardResource } from '@perses-dev/client';
4
4
  export interface LeaveDialogProps {
5
5
  isBlocked: BlockerFunction | boolean;
6
6
  message: string;
@@ -1 +1 @@
1
- {"version":3,"file":"LeaveDialog.d.ts","sourceRoot":"","sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAQhD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,wBAAgB,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,gBAAgB,GAAG,YAAY,CA4B7E;AAKD,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACxC,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,SAAS,CAYZ"}
1
+ {"version":3,"file":"LeaveDialog.d.ts","sourceRoot":"","sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAG3D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAQvD,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,eAAe,GAAG,OAAO,CAAC;IACrC,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,wBAAgB,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,gBAAgB,GAAG,YAAY,CA4B7E;AAKD,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,iBAAiB,GAAG,SAAS,CAAC;IACxC,OAAO,EAAE,iBAAiB,CAAC;CAC5B,GAAG,SAAS,CAYZ"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"sourcesContent":["// Copyright 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, ReactNode, useEffect } from 'react';\nimport { useBlocker } from 'react-router-dom';\nimport { DiscardChangesConfirmationDialog } from '@perses-dev/components';\nimport type { BlockerFunction } from '@remix-run/router';\nimport { DashboardResource } from '../../model';\n\nconst handleRouteChange = (event: BeforeUnloadEvent): string => {\n event.preventDefault();\n event.returnValue = ''; // Required for Chrome\n return ''; // Required for other browsers\n};\n\nexport interface LeaveDialogProps {\n isBlocked: BlockerFunction | boolean;\n message: string;\n}\n\n/*\n * Prompt component uses the useBlocker hook to block react-router navigation when there are unsaved changes.\n * It also listens to the beforeunload event to show a browser confirmation dialog when the user tries to close the tab, refresh the page or change url manually.\n */\nexport function Prompt({ isBlocked, message }: LeaveDialogProps): ReactElement {\n const blocker = useBlocker(isBlocked);\n const isBlockedState = blocker.state === 'blocked';\n const isProceedingState = blocker.state === 'proceeding';\n\n useEffect(() => {\n if (isBlocked) {\n window.addEventListener('beforeunload', handleRouteChange);\n } else {\n window.removeEventListener('beforeunload', handleRouteChange);\n }\n\n return (): void => {\n window.removeEventListener('beforeunload', handleRouteChange);\n };\n }, [blocker, isBlocked, isBlockedState]);\n\n const handleDiscardChanges = (): void => blocker.proceed?.();\n const handleCancel = (): void => blocker.reset?.();\n\n return (\n <DiscardChangesConfirmationDialog\n description={message}\n isOpen={isBlockedState || isProceedingState}\n onDiscardChanges={handleDiscardChanges}\n onCancel={handleCancel}\n />\n );\n}\n\n/*\n * LeaveDialog prompts the user with a confirmation dialog when they attempt to leave the page with unsaved changes.\n */\nexport function LeaveDialog({\n original,\n current,\n}: {\n original: DashboardResource | undefined;\n current: DashboardResource;\n}): ReactNode {\n const handleIsBlocked: BlockerFunction = (ctx) => {\n if (JSON.stringify(original) !== JSON.stringify(current)) {\n // Only block navigation if the pathname is changing (=> ignore search params changes)\n if (ctx.currentLocation.pathname !== ctx.nextLocation.pathname) {\n return true;\n }\n }\n return false;\n };\n\n return <Prompt isBlocked={handleIsBlocked} message=\"You have unsaved changes, are you sure you want to leave?\" />;\n}\n"],"names":["useEffect","useBlocker","DiscardChangesConfirmationDialog","handleRouteChange","event","preventDefault","returnValue","Prompt","isBlocked","message","blocker","isBlockedState","state","isProceedingState","window","addEventListener","removeEventListener","handleDiscardChanges","proceed","handleCancel","reset","description","isOpen","onDiscardChanges","onCancel","LeaveDialog","original","current","handleIsBlocked","ctx","JSON","stringify","currentLocation","pathname","nextLocation"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAkCA,SAAS,QAAQ,QAAQ;AAC3D,SAASC,UAAU,QAAQ,mBAAmB;AAC9C,SAASC,gCAAgC,QAAQ,yBAAyB;AAI1E,MAAMC,oBAAoB,CAACC;IACzBA,MAAMC,cAAc;IACpBD,MAAME,WAAW,GAAG,IAAI,sBAAsB;IAC9C,OAAO,IAAI,8BAA8B;AAC3C;AAOA;;;CAGC,GACD,OAAO,SAASC,OAAO,EAAEC,SAAS,EAAEC,OAAO,EAAoB;IAC7D,MAAMC,UAAUT,WAAWO;IAC3B,MAAMG,iBAAiBD,QAAQE,KAAK,KAAK;IACzC,MAAMC,oBAAoBH,QAAQE,KAAK,KAAK;IAE5CZ,UAAU;QACR,IAAIQ,WAAW;YACbM,OAAOC,gBAAgB,CAAC,gBAAgBZ;QAC1C,OAAO;YACLW,OAAOE,mBAAmB,CAAC,gBAAgBb;QAC7C;QAEA,OAAO;YACLW,OAAOE,mBAAmB,CAAC,gBAAgBb;QAC7C;IACF,GAAG;QAACO;QAASF;QAAWG;KAAe;IAEvC,MAAMM,uBAAuB,IAAYP,QAAQQ,OAAO;IACxD,MAAMC,eAAe,IAAYT,QAAQU,KAAK;IAE9C,qBACE,KAAClB;QACCmB,aAAaZ;QACba,QAAQX,kBAAkBE;QAC1BU,kBAAkBN;QAClBO,UAAUL;;AAGhB;AAEA;;CAEC,GACD,OAAO,SAASM,YAAY,EAC1BC,QAAQ,EACRC,OAAO,EAIR;IACC,MAAMC,kBAAmC,CAACC;QACxC,IAAIC,KAAKC,SAAS,CAACL,cAAcI,KAAKC,SAAS,CAACJ,UAAU;YACxD,sFAAsF;YACtF,IAAIE,IAAIG,eAAe,CAACC,QAAQ,KAAKJ,IAAIK,YAAY,CAACD,QAAQ,EAAE;gBAC9D,OAAO;YACT;QACF;QACA,OAAO;IACT;IAEA,qBAAO,KAAC1B;QAAOC,WAAWoB;QAAiBnB,SAAQ;;AACrD"}
1
+ {"version":3,"sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"sourcesContent":["// Copyright 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, ReactNode, useEffect } from 'react';\nimport { useBlocker } from 'react-router-dom';\nimport { DiscardChangesConfirmationDialog } from '@perses-dev/components';\nimport type { BlockerFunction } from '@remix-run/router';\nimport { DashboardResource } from '@perses-dev/client';\n\nconst handleRouteChange = (event: BeforeUnloadEvent): string => {\n event.preventDefault();\n event.returnValue = ''; // Required for Chrome\n return ''; // Required for other browsers\n};\n\nexport interface LeaveDialogProps {\n isBlocked: BlockerFunction | boolean;\n message: string;\n}\n\n/*\n * Prompt component uses the useBlocker hook to block react-router navigation when there are unsaved changes.\n * It also listens to the beforeunload event to show a browser confirmation dialog when the user tries to close the tab, refresh the page or change url manually.\n */\nexport function Prompt({ isBlocked, message }: LeaveDialogProps): ReactElement {\n const blocker = useBlocker(isBlocked);\n const isBlockedState = blocker.state === 'blocked';\n const isProceedingState = blocker.state === 'proceeding';\n\n useEffect(() => {\n if (isBlocked) {\n window.addEventListener('beforeunload', handleRouteChange);\n } else {\n window.removeEventListener('beforeunload', handleRouteChange);\n }\n\n return (): void => {\n window.removeEventListener('beforeunload', handleRouteChange);\n };\n }, [blocker, isBlocked, isBlockedState]);\n\n const handleDiscardChanges = (): void => blocker.proceed?.();\n const handleCancel = (): void => blocker.reset?.();\n\n return (\n <DiscardChangesConfirmationDialog\n description={message}\n isOpen={isBlockedState || isProceedingState}\n onDiscardChanges={handleDiscardChanges}\n onCancel={handleCancel}\n />\n );\n}\n\n/*\n * LeaveDialog prompts the user with a confirmation dialog when they attempt to leave the page with unsaved changes.\n */\nexport function LeaveDialog({\n original,\n current,\n}: {\n original: DashboardResource | undefined;\n current: DashboardResource;\n}): ReactNode {\n const handleIsBlocked: BlockerFunction = (ctx) => {\n if (JSON.stringify(original) !== JSON.stringify(current)) {\n // Only block navigation if the pathname is changing (=> ignore search params changes)\n if (ctx.currentLocation.pathname !== ctx.nextLocation.pathname) {\n return true;\n }\n }\n return false;\n };\n\n return <Prompt isBlocked={handleIsBlocked} message=\"You have unsaved changes, are you sure you want to leave?\" />;\n}\n"],"names":["useEffect","useBlocker","DiscardChangesConfirmationDialog","handleRouteChange","event","preventDefault","returnValue","Prompt","isBlocked","message","blocker","isBlockedState","state","isProceedingState","window","addEventListener","removeEventListener","handleDiscardChanges","proceed","handleCancel","reset","description","isOpen","onDiscardChanges","onCancel","LeaveDialog","original","current","handleIsBlocked","ctx","JSON","stringify","currentLocation","pathname","nextLocation"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAk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ues } from '@perses-dev/spec';
3
- import { Action } from '@perses-dev/components';
3
+ import { Action } from '@perses-dev/client';
4
4
  export interface PanelEditorFormProps {
5
5
  initialValues: PanelEditorValues;
6
6
  initialAction: Action;
@@ -1 +1 @@
1
- {"version":3,"file":"PanelEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelEditorForm.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAoC,MAAM,OAAO,CAAC;AAEvE,OAAO,EAAmB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,EAIL,MAAM,EAGP,MAAM,wBAAwB,CAAC;AAShC,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA+OzE;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC"}
1
+ {"version":3,"file":"PanelEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelEditorForm.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAoC,MAAM,OAAO,CAAC;AAEvE,OAAO,EAAmB,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAWtE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAM5C,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAC5C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA+OzE;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PanelDrawer/PanelEditorForm.tsx"],"sourcesContent":["// Copyright 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 { PanelDefinition, PanelEditorValues } from '@perses-dev/spec';\nimport {\n DiscardChangesConfirmationDialog,\n ErrorAlert,\n ErrorBoundary,\n Action,\n getTitleAction,\n getSubmitText,\n} from '@perses-dev/components';\nimport { PluginKindSelect, usePluginEditor, useValidationSchemas } 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 panelKey?: string;\n onSave: (values: PanelEditorValues) => void;\n onClose: () => void;\n}\n\nexport function PanelEditorForm(props: PanelEditorFormProps): ReactElement {\n const { initialValues, initialAction, panelKey, 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 const currentValues = form.getValues();\n\n // Normalize display: if both name and description are undefined, set display to undefined\n const normalizeDisplay = (values: PanelEditorValues): PanelEditorValues => {\n if (\n values.panelDefinition.spec.display?.name === undefined &&\n values.panelDefinition.spec.display?.description === undefined\n ) {\n values.panelDefinition.spec.display = undefined;\n }\n return values;\n };\n\n const normalizedInitial = normalizeDisplay(JSON.parse(JSON.stringify(initialValues)));\n const normalizedCurrent = normalizeDisplay(JSON.parse(JSON.stringify(currentValues)));\n\n if (JSON.stringify(normalizedInitial) !== JSON.stringify(normalizedCurrent)) {\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 <Stack direction=\"row\" spacing={1} alignItems=\"center\">\n <Typography variant=\"h2\">{titleAction} Panel</Typography>\n {panelKey && <Typography variant=\"subtitle1\">(ID: {panelKey})</Typography>}\n </Stack>\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 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","getTitleAction","getSubmitText","PluginKindSelect","usePluginEditor","useValidationSchemas","Controller","FormProvider","useForm","useWatch","zodResolver","useListPanelGroups","PanelEditorProvider","usePanelEditor","PanelQueriesSharedControls","PanelEditorForm","props","initialValues","initialAction","panelKey","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","currentValues","getValues","normalizeDisplay","values","display","description","normalizedInitial","JSON","parse","stringify","normalizedCurrent","handlePanelDefinitionChange","nextPanelDefStr","nextPanelDef","pluginKind","pluginSpec","rememberCurrentSpecState","watchedName","watchedDescription","watchedPluginKind","handleSubmit","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","direction","variant","marginLeft","disabled","formState","isValid","onClick","color","id","panelEditorFormId","flex","overflowY","container","item","xs","render","field","fieldState","fullWidth","label","error","helperText","message","event","target","select","required","map","panelGroup","index","title","isLoading","onSelectionChange","FallbackComponent","onQueriesChange","q","onPluginSpecChange","onSpecChange","onJSONChange","isOpen","onCancel","onDiscardChanges"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAo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,CAACiE,MAAMnE,IAAI;gDACzBJ,aAAagF,iBAAiB,CAACT;4CACjC;;;;0CAMR,KAAC9G;gCAAcwH,mBAAmBzH;0CAChC,cAAA,KAACe;oCACCuC,SAASlB,KAAKkB,OAAO;oCACrBvB,QAAQA;oCACRP,iBAAiBA;oCACjBkG,iBAAiB,CAACC,IAAM/F,WAAW+F;oCACnCC,oBAAoB,CAAC5F;wCACnBQ,aAAaqF,YAAY,CAAC7F;oCAC5B;oCACA8F,cAAcxD;;;;;;8BAKtB,KAACvE;oBACCiE,aAAY;oBACZ+D,QAAQ9F;oBACR+F,UAAU;wBACR9F,uBAAuB;oBACzB;oBACA+F,kBAAkB;wBAChB/F,uBAAuB;wBACvBZ;oBACF;;;;;AAKV;AAEA;;CAEC,GACD,OAAO,MAAM2E,oBAAoB,oBAAoB"}
1
+ {"version":3,"sources":["../../../src/components/PanelDrawer/PanelEditorForm.tsx"],"sourcesContent":["// Copyright 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 { PanelDefinition, PanelEditorValues } from '@perses-dev/spec';\nimport {\n DiscardChangesConfirmationDialog,\n ErrorAlert,\n ErrorBoundary,\n getTitleAction,\n getSubmitText,\n} from '@perses-dev/components';\nimport { PluginKindSelect, usePluginEditor, useValidationSchemas } from '@perses-dev/plugin-system';\nimport { Controller, FormProvider, SubmitHandler, useForm, useWatch } from 'react-hook-form';\nimport { zodResolver } from '@hookform/resolvers/zod';\nimport { Action } from '@perses-dev/client';\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 panelKey?: string;\n onSave: (values: PanelEditorValues) => void;\n onClose: () => void;\n}\n\nexport function PanelEditorForm(props: PanelEditorFormProps): ReactElement {\n const { initialValues, initialAction, panelKey, 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 const currentValues = form.getValues();\n\n // Normalize display: if both name and description are undefined, set display to undefined\n const normalizeDisplay = (values: PanelEditorValues): PanelEditorValues => {\n if (\n values.panelDefinition.spec.display?.name === undefined &&\n values.panelDefinition.spec.display?.description === undefined\n ) {\n values.panelDefinition.spec.display = undefined;\n }\n return values;\n };\n\n const normalizedInitial = normalizeDisplay(JSON.parse(JSON.stringify(initialValues)));\n const normalizedCurrent = normalizeDisplay(JSON.parse(JSON.stringify(currentValues)));\n\n if (JSON.stringify(normalizedInitial) !== JSON.stringify(normalizedCurrent)) {\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 <Stack direction=\"row\" spacing={1} alignItems=\"center\">\n <Typography variant=\"h2\">{titleAction} Panel</Typography>\n {panelKey && <Typography variant=\"subtitle1\">(ID: {panelKey})</Typography>}\n </Stack>\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 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","getTitleAction","getSubmitText","PluginKindSelect","usePluginEditor","useValidationSchemas","Controller","FormProvider","useForm","useWatch","zodResolver","useListPanelGroups","PanelEditorProvider","usePanelEditor","PanelQueriesSharedControls","PanelEditorForm","props","initialValues","initialAction","panelKey","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","currentValues","getValues","normalizeDisplay","values","display","description","normalizedInitial","JSON","parse","stringify","normalizedCurrent","handlePanelDefinitionChange","nextPanelDefStr","nextPanelDef","pluginKind","pluginSpec","rememberCurrentSpecState","watchedName","watchedDescription","watchedPluginKind","handleSubmit","sx","alignItems","padding","theme","spacing","borderBottom","palette","divider","direction","variant","marginLeft","disabled","formState","isValid","onClick","color","id","panelEditorFormId","flex","overflowY","container","item","xs","render","field","fieldState","fullWidth","label","error","helperText","message","event","target","select","required","map","panelGroup","index","title","isLoading","onSelectionChange","FallbackComponent","onQueriesChange","q","onPluginSpecChange","onSpecChange","onJSONChange","isOpen","onCancel","onDiscardChanges"],"mappings":";AAAA,+BAA+B;AAC/B,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,SACEC,gCAAgC,EAChCC,UAAU,EACVC,aAAa,EACbC,cAAc,EACdC,aAAa,QACR,yBAAyB;AAChC,SAASC,gBAAgB,EAAEC,eAAe,EAAEC,oBAAoB,QAAQ,4BAA4B;AACpG,SAASC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,EAAEC,QAAQ,QAAQ,kBAAkB;AAC7F,SAASC,WAAW,QAAQ,0BAA0B;AAEtD,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,mBAAmB,QAAQ,wDAAwD;AAC5F,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,0BAA0B,QAAQ,+BAA+B;AAU1E,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAAEC,aAAa,EAAEC,aAAa,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,OAAO,EAAE,GAAGL;IACpE,MAAMM,cAAcX;IACpB,MAAM,EAAEY,eAAe,EAAEC,OAAO,EAAEC,cAAc,EAAEC,Q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EC,UAAU,EAAE,iBAC5B,KAACrG;4CACE,GAAGoG,KAAK;4CACT/D,aAAa;gDAAC;6CAAQ;4CACtByE,QAAQ;4CACRR,SAAS;4CACTC,OAAM;4CACNhB,UAAUnD,aAAa+E,SAAS;4CAChCX,OAAO,CAAC,CAACpE,aAAaoE,KAAK,IAAI,CAAC,CAACH,WAAWG,KAAK;4CACjDC,YAAYrE,aAAaoE,KAAK,EAAEE,WAAWL,WAAWG,KAAK,EAAEE;4CAC7DpE,OAAO;gDAAEG,MAAM;gDAASD,MAAMkC;4CAAkB;4CAChDhC,UAAU,CAACiE;gDACTP,MAAM1D,QAAQ,CAACiE,MAAMnE,IAAI;gDACzBJ,aAAagF,iBAAiB,CAACT;4CACjC;;;;0CAMR,KAAC9G;gCAAcwH,mBAAmBzH;0CAChC,cAAA,KAACe;oCACCuC,SAASlB,KAAKkB,OAAO;oCACrBvB,QAAQA;oCACRP,iBAAiBA;oCACjBkG,iBAAiB,CAACC,IAAM/F,WAAW+F;oCACnCC,oBAAoB,CAAC5F;wCACnBQ,aAAaqF,YAAY,CAAC7F;oCAC5B;oCACA8F,cAAcxD;;;;;;8BAKtB,KAACvE;oBACCiE,aAAY;oBACZ+D,QAAQ9F;oBACR+F,UAAU;wBACR9F,uBAAuB;oBACzB;oBACA+F,kBAAkB;wBAChB/F,uBAAuB;wBACvBZ;oBACF;;;;;AAKV;AAEA;;CAEC,GACD,OAAO,MAAM2E,oBAAoB,oBAAoB"}
@@ -1 +1 @@
1
- {"version":3,"file":"VariableEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAqB,MAAM,OAAO,CAAC;AAwBxD,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAWjF,OAAO,EAIL,aAAa,EAEd,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,0BAA0B,EAAE,MAAM,gCAAgC,CA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