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

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 (178) 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 +9 -67
  4. package/dist/cjs/components/GridLayout/GridLayout.js +1 -1
  5. package/dist/cjs/components/LeaveDialog/LeaveDialog.js +10 -1
  6. package/dist/cjs/components/Panel/Panel.js +4 -3
  7. package/dist/cjs/components/Panel/PanelHeader.js +1 -9
  8. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +186 -183
  9. package/dist/cjs/components/PanelDrawer/PanelPreview.js +3 -0
  10. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +6 -21
  11. package/dist/cjs/components/QueryViewerDialog/QueryViewerDialog.js +121 -0
  12. package/dist/cjs/components/QueryViewerDialog/index.js +30 -0
  13. package/dist/cjs/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +18 -6
  14. package/dist/cjs/components/SaveDashboardButton/SaveDashboardButton.js +11 -6
  15. package/dist/cjs/components/Variables/ListVariableListBox.js +201 -0
  16. package/dist/cjs/components/Variables/Variable.js +164 -72
  17. package/dist/cjs/components/Variables/VariableList.js +2 -2
  18. package/dist/cjs/components/Variables/index.js +1 -0
  19. package/dist/cjs/components/index.js +2 -1
  20. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +1 -1
  21. package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +1 -1
  22. package/dist/cjs/context/DashboardProvider/duplicate-panel-slice.js +1 -1
  23. package/dist/cjs/context/DashboardProvider/index.js +1 -1
  24. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +1 -1
  25. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +1 -7
  26. package/dist/cjs/context/DashboardProvider/view-panel-slice.js +1 -1
  27. package/dist/cjs/context/DatasourceStoreProvider.js +3 -4
  28. package/dist/cjs/context/PanelEditorProvider/PanelEditorProvider.js +49 -0
  29. package/dist/cjs/context/PanelEditorProvider/index.js +23 -0
  30. package/dist/cjs/context/VariableProvider/VariableProvider.js +1 -1
  31. package/dist/cjs/context/VariableProvider/hydrationUtils.js +1 -1
  32. package/dist/cjs/context/VariableProvider/index.js +1 -1
  33. package/dist/cjs/context/VariableProvider/utils.js +1 -1
  34. package/dist/cjs/context/index.js +1 -0
  35. package/dist/cjs/context/useDashboard.js +1 -1
  36. package/dist/cjs/utils/panelUtils.js +1 -1
  37. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.d.ts.map +1 -1
  38. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js +0 -2
  39. package/dist/components/DashboardStickyToolbar/DashboardStickyToolbar.js.map +1 -1
  40. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
  41. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js +5 -15
  42. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
  43. package/dist/components/GridLayout/GridItemContent.d.ts +1 -1
  44. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  45. package/dist/components/GridLayout/GridItemContent.js +10 -68
  46. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  47. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  48. package/dist/components/GridLayout/GridLayout.js +1 -1
  49. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  50. package/dist/components/GridLayout/Row.d.ts +2 -2
  51. package/dist/components/GridLayout/Row.d.ts.map +1 -1
  52. package/dist/components/GridLayout/Row.js.map +1 -1
  53. package/dist/components/LeaveDialog/LeaveDialog.d.ts +2 -1
  54. package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -1
  55. package/dist/components/LeaveDialog/LeaveDialog.js +10 -1
  56. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -1
  57. package/dist/components/Panel/Panel.d.ts +1 -2
  58. package/dist/components/Panel/Panel.d.ts.map +1 -1
  59. package/dist/components/Panel/Panel.js +5 -4
  60. package/dist/components/Panel/Panel.js.map +1 -1
  61. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  62. package/dist/components/Panel/PanelHeader.js +2 -10
  63. package/dist/components/Panel/PanelHeader.js.map +1 -1
  64. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  65. package/dist/components/PanelDrawer/PanelEditorForm.js +186 -183
  66. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  67. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  68. package/dist/components/PanelDrawer/PanelPreview.js +4 -1
  69. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  70. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  71. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +5 -15
  72. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  73. package/dist/components/QueryViewerDialog/QueryViewerDialog.d.ts +9 -0
  74. package/dist/components/QueryViewerDialog/QueryViewerDialog.d.ts.map +1 -0
  75. package/dist/components/QueryViewerDialog/QueryViewerDialog.js +72 -0
  76. package/dist/components/QueryViewerDialog/QueryViewerDialog.js.map +1 -0
  77. package/dist/components/QueryViewerDialog/index.d.ts +2 -0
  78. package/dist/components/QueryViewerDialog/index.d.ts.map +1 -0
  79. package/dist/components/QueryViewerDialog/index.js +15 -0
  80. package/dist/components/QueryViewerDialog/index.js.map +1 -0
  81. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.d.ts.map +1 -1
  82. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js +19 -7
  83. package/dist/components/SaveChangesConfirmationDialog/SaveChangesConfirmationDialog.js.map +1 -1
  84. package/dist/components/SaveDashboardButton/SaveDashboardButton.d.ts.map +1 -1
  85. package/dist/components/SaveDashboardButton/SaveDashboardButton.js +11 -6
  86. package/dist/components/SaveDashboardButton/SaveDashboardButton.js.map +1 -1
  87. package/dist/components/Variables/EditVariablesButton.d.ts.map +1 -1
  88. package/dist/components/Variables/EditVariablesButton.js.map +1 -1
  89. package/dist/components/Variables/ListVariableListBox.d.ts +16 -0
  90. package/dist/components/Variables/ListVariableListBox.d.ts.map +1 -0
  91. package/dist/components/Variables/ListVariableListBox.js +141 -0
  92. package/dist/components/Variables/ListVariableListBox.js.map +1 -0
  93. package/dist/components/Variables/Variable.d.ts.map +1 -1
  94. package/dist/components/Variables/Variable.js +168 -75
  95. package/dist/components/Variables/Variable.js.map +1 -1
  96. package/dist/components/Variables/VariableEditor.d.ts +1 -2
  97. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  98. package/dist/components/Variables/VariableEditor.js.map +1 -1
  99. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  100. package/dist/components/Variables/VariableList.js +2 -2
  101. package/dist/components/Variables/VariableList.js.map +1 -1
  102. package/dist/components/Variables/index.d.ts +1 -0
  103. package/dist/components/Variables/index.d.ts.map +1 -1
  104. package/dist/components/Variables/index.js +1 -0
  105. package/dist/components/Variables/index.js.map +1 -1
  106. package/dist/components/index.d.ts +2 -1
  107. package/dist/components/index.d.ts.map +1 -1
  108. package/dist/components/index.js +2 -1
  109. package/dist/components/index.js.map +1 -1
  110. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -2
  111. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  112. package/dist/context/DashboardProvider/dashboard-provider-api.js +1 -1
  113. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  114. package/dist/context/DashboardProvider/delete-panel-slice.d.ts +2 -1
  115. package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -1
  116. package/dist/context/DashboardProvider/delete-panel-slice.js +1 -1
  117. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -1
  118. package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts +2 -1
  119. package/dist/context/DashboardProvider/duplicate-panel-slice.d.ts.map +1 -1
  120. package/dist/context/DashboardProvider/duplicate-panel-slice.js +1 -1
  121. package/dist/context/DashboardProvider/duplicate-panel-slice.js.map +1 -1
  122. package/dist/context/DashboardProvider/index.d.ts +0 -1
  123. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  124. package/dist/context/DashboardProvider/index.js +1 -1
  125. package/dist/context/DashboardProvider/index.js.map +1 -1
  126. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +2 -2
  127. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  128. package/dist/context/DashboardProvider/panel-editor-slice.js +1 -1
  129. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  130. package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -24
  131. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  132. package/dist/context/DashboardProvider/panel-group-slice.js +1 -6
  133. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  134. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts +2 -1
  135. package/dist/context/DashboardProvider/save-changes-dialog-slice.d.ts.map +1 -1
  136. package/dist/context/DashboardProvider/save-changes-dialog-slice.js.map +1 -1
  137. package/dist/context/DashboardProvider/view-panel-slice.d.ts +1 -1
  138. package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
  139. package/dist/context/DashboardProvider/view-panel-slice.js +1 -1
  140. package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
  141. package/dist/context/DatasourceStoreProvider.d.ts +1 -17
  142. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  143. package/dist/context/DatasourceStoreProvider.js +2 -3
  144. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  145. package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts +13 -0
  146. package/dist/context/PanelEditorProvider/PanelEditorProvider.d.ts.map +1 -0
  147. package/dist/context/PanelEditorProvider/PanelEditorProvider.js +33 -0
  148. package/dist/context/PanelEditorProvider/PanelEditorProvider.js.map +1 -0
  149. package/dist/context/PanelEditorProvider/index.d.ts +3 -0
  150. package/dist/context/PanelEditorProvider/index.d.ts.map +1 -0
  151. package/dist/context/PanelEditorProvider/index.js +16 -0
  152. package/dist/context/PanelEditorProvider/index.js.map +1 -0
  153. package/dist/context/VariableProvider/VariableProvider.d.ts +1 -10
  154. package/dist/context/VariableProvider/VariableProvider.d.ts.map +1 -1
  155. package/dist/context/VariableProvider/VariableProvider.js +1 -1
  156. package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
  157. package/dist/context/VariableProvider/hydrationUtils.d.ts +1 -2
  158. package/dist/context/VariableProvider/hydrationUtils.d.ts.map +1 -1
  159. package/dist/context/VariableProvider/hydrationUtils.js +1 -1
  160. package/dist/context/VariableProvider/hydrationUtils.js.map +1 -1
  161. package/dist/context/VariableProvider/index.js +1 -1
  162. package/dist/context/VariableProvider/index.js.map +1 -1
  163. package/dist/context/VariableProvider/utils.d.ts +1 -2
  164. package/dist/context/VariableProvider/utils.d.ts.map +1 -1
  165. package/dist/context/VariableProvider/utils.js +1 -1
  166. package/dist/context/VariableProvider/utils.js.map +1 -1
  167. package/dist/context/index.d.ts +1 -0
  168. package/dist/context/index.d.ts.map +1 -1
  169. package/dist/context/index.js +1 -0
  170. package/dist/context/index.js.map +1 -1
  171. package/dist/context/useDashboard.d.ts.map +1 -1
  172. package/dist/context/useDashboard.js +1 -1
  173. package/dist/context/useDashboard.js.map +1 -1
  174. package/dist/utils/panelUtils.d.ts +1 -2
  175. package/dist/utils/panelUtils.d.ts.map +1 -1
  176. package/dist/utils/panelUtils.js +1 -1
  177. package/dist/utils/panelUtils.js.map +1 -1
  178. package/package.json +5 -5
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/Panel/PanelHeader.tsx"],"sourcesContent":["// Copyright 2025 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 { CardHeader, CardHeaderProps, Stack, Typography, Tooltip } from '@mui/material';\nimport { combineSx } from '@perses-dev/components';\nimport { Link } from '@perses-dev/core';\nimport { QueryData, useReplaceVariablesInString } from '@perses-dev/plugin-system';\nimport { ReactElement, ReactNode, useEffect, useRef, useState } from 'react';\nimport { HEADER_ACTIONS_CONTAINER_NAME } from '../../constants';\nimport { PanelActions, PanelActionsProps } from './PanelActions';\nimport { PanelOptions } from './Panel';\n\ntype OmittedProps = 'children' | 'action' | 'title' | 'disableTypography';\n\nexport interface PanelHeaderProps extends Omit<CardHeaderProps, OmittedProps> {\n id: string;\n title: string;\n description?: string;\n links?: Link[];\n extra?: ReactNode;\n queryResults: QueryData[];\n viewQueriesHandler?: PanelActionsProps['viewQueriesHandler'];\n readHandlers?: PanelActionsProps['readHandlers'];\n editHandlers?: PanelActionsProps['editHandlers'];\n pluginActions?: ReactNode[]; // Add pluginActions prop\n showIcons: PanelOptions['showIcons'];\n dimension?: { width: number };\n}\n\nexport function PanelHeader({\n id,\n title: rawTitle,\n description: rawDescription,\n links,\n queryResults,\n readHandlers,\n editHandlers,\n sx,\n extra,\n pluginActions,\n showIcons,\n viewQueriesHandler,\n dimension,\n ...rest\n}: PanelHeaderProps): ReactElement {\n const titleElementId = `${id}-title`;\n const descriptionTooltipId = `${id}-description`;\n\n const title = useReplaceVariablesInString(rawTitle) as string;\n const description = useReplaceVariablesInString(rawDescription);\n\n const textRef = useRef<HTMLDivElement>(null);\n const [isEllipsisActive, setIsEllipsisActive] = useState(false);\n\n useEffect(() => {\n if (textRef.current && dimension?.width) {\n setIsEllipsisActive(textRef.current.scrollWidth > textRef.current.clientWidth);\n }\n }, [title, dimension?.width]);\n\n return (\n <CardHeader\n id={id}\n component=\"header\"\n aria-labelledby={titleElementId}\n aria-describedby={descriptionTooltipId}\n disableTypography\n title={\n <Stack direction=\"row\" alignItems=\"center\" height=\"var(--panel-header-height, 30px)\">\n <Tooltip title={title} disableHoverListener={!isEllipsisActive}>\n <Typography\n id={titleElementId}\n variant=\"subtitle1\"\n ref={textRef}\n sx={{\n // `minHeight` guarantees that the header has the correct height\n // when there is no title (i.e. in the preview)\n lineHeight: '24px',\n minHeight: '26px',\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n {title}\n </Typography>\n </Tooltip>\n <PanelActions\n title={title}\n description={description}\n descriptionTooltipId={descriptionTooltipId}\n links={links}\n readHandlers={readHandlers}\n editHandlers={editHandlers}\n viewQueriesHandler={viewQueriesHandler}\n extra={extra}\n queryResults={queryResults}\n pluginActions={pluginActions}\n showIcons={showIcons}\n />\n </Stack>\n }\n sx={combineSx(\n (theme) => ({\n containerType: 'inline-size',\n containerName: HEADER_ACTIONS_CONTAINER_NAME,\n padding: theme.spacing(1),\n borderBottom: `solid 1px ${theme.palette.divider}`,\n '.MuiCardHeader-content': {\n overflow: 'hidden',\n },\n }),\n sx\n )}\n {...rest}\n />\n );\n}\n"],"names":["CardHeader","Stack","Typography","Tooltip","combineSx","useReplaceVariablesInString","useEffect","useRef","useState","HEADER_ACTIONS_CONTAINER_NAME","PanelActions","PanelHeader","id","title","rawTitle","description","rawDescription","links","queryResults","readHandlers","editHandlers","sx","extra","pluginActions","showIcons","viewQueriesHandler","dimension","rest","titleElementId","descriptionTooltipId","textRef","isEllipsisActive","setIsEllipsisActive","current","width","scrollWidth","clientWidth","component","aria-labelledby","aria-describedby","disableTypography","direction","alignItems","height","disableHoverListener","variant","ref","lineHeight","minHeight","whiteSpace","overflow","textOverflow","theme","containerType","containerName","padding","spacing","borderB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MAACZ;YAAMwC,WAAU;YAAMC,YAAW;YAASC,QAAO;;8BAChD,KAACxC;oBAAQU,OAAOA;oBAAO+B,sBAAsB,CAACb;8BAC5C,cAAA,KAAC7B;wBACCU,IAAIgB;wBACJiB,SAAQ;wBACRC,KAAKhB;wBACLT,IAAI;4BACF,gEAAgE;4BAChE,+CAA+C;4BAC/C0B,YAAY;4BACZC,WAAW;4BACXC,YAAY;4BACZC,UAAU;4BACVC,cAAc;wBAChB;kCAECtC;;;8BAGL,KAACH;oBACCG,OAAOA;oBACPE,aAAaA;oBACbc,sBAAsBA;oBACtBZ,OAAOA;oBACPE,cAAcA;oBACdC,cAAcA;oBACdK,oBAAoBA;oBACpBH,OAAOA;oBACPJ,cAAcA;oBACdK,eAAeA;oBACfC,WAAWA;;;;QAIjBH,IAAIjB,UACF,CAACgD,QAAW,CAAA;gBACVC,eAAe;gBACfC,eAAe7C;gBACf8C,SAASH,MAAMI,OAAO,CAAC;gBACvBC,cAAc,CAAC,UAAU,EAAEL,MAAMM,OAAO,CAACC,OAAO,EAAE;gBAClD,0BAA0B;oBACxBT,UAAU;gBACZ;YACF,CAAA,GACA7B;QAED,GAAGM,IAAI;;AAGd"}
1
+ {"version":3,"sources":["../../../src/components/Panel/PanelHeader.tsx"],"sourcesContent":["// Copyright 2025 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 { CardHeader, CardHeaderProps, Stack, Typography, Tooltip } from '@mui/material';\nimport { combineSx } from '@perses-dev/components';\nimport { Link } from '@perses-dev/core';\nimport { QueryData, useReplaceVariablesInString } from '@perses-dev/plugin-system';\nimport { ReactElement, ReactNode, useRef } from 'react';\nimport { HEADER_ACTIONS_CONTAINER_NAME } from '../../constants';\nimport { PanelActions, PanelActionsProps } from './PanelActions';\nimport { PanelOptions } from './Panel';\n\ntype OmittedProps = 'children' | 'action' | 'title' | 'disableTypography';\n\nexport interface PanelHeaderProps extends Omit<CardHeaderProps, OmittedProps> {\n id: string;\n title: string;\n description?: string;\n links?: Link[];\n extra?: ReactNode;\n queryResults: QueryData[];\n viewQueriesHandler?: PanelActionsProps['viewQueriesHandler'];\n readHandlers?: PanelActionsProps['readHandlers'];\n editHandlers?: PanelActionsProps['editHandlers'];\n pluginActions?: ReactNode[]; // Add pluginActions prop\n showIcons: PanelOptions['showIcons'];\n dimension?: { width: number };\n}\n\nexport function PanelHeader({\n id,\n title: rawTitle,\n description: rawDescription,\n links,\n queryResults,\n readHandlers,\n editHandlers,\n sx,\n extra,\n pluginActions,\n showIcons,\n viewQueriesHandler,\n dimension,\n ...rest\n}: PanelHeaderProps): ReactElement {\n const titleElementId = `${id}-title`;\n const descriptionTooltipId = `${id}-description`;\n\n const title = useReplaceVariablesInString(rawTitle) as string;\n const description = useReplaceVariablesInString(rawDescription);\n\n const textRef = useRef<HTMLDivElement>(null);\n\n const isEllipsisActive =\n textRef.current && dimension?.width ? textRef.current.scrollWidth > textRef.current.clientWidth : false;\n\n return (\n <CardHeader\n id={id}\n component=\"header\"\n aria-labelledby={titleElementId}\n aria-describedby={descriptionTooltipId}\n disableTypography\n title={\n <Stack direction=\"row\" alignItems=\"center\" height=\"var(--panel-header-height, 30px)\">\n <Tooltip title={title} disableHoverListener={!isEllipsisActive}>\n <Typography\n id={titleElementId}\n variant=\"subtitle1\"\n ref={textRef}\n sx={{\n // `minHeight` guarantees that the header has the correct height\n // when there is no title (i.e. in the preview)\n lineHeight: '24px',\n minHeight: '26px',\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n {title}\n </Typography>\n </Tooltip>\n <PanelActions\n title={title}\n description={description}\n descriptionTooltipId={descriptionTooltipId}\n links={links}\n readHandlers={readHandlers}\n editHandlers={editHandlers}\n viewQueriesHandler={viewQueriesHandler}\n extra={extra}\n queryResults={queryResults}\n pluginActions={pluginActions}\n showIcons={showIcons}\n />\n </Stack>\n }\n sx={combineSx(\n (theme) => ({\n containerType: 'inline-size',\n containerName: HEADER_ACTIONS_CONTAINER_NAME,\n padding: theme.spacing(1),\n borderBottom: `solid 1px ${theme.palette.divider}`,\n '.MuiCardHeader-content': {\n overflow: 'hidden',\n },\n }),\n sx\n )}\n {...rest}\n />\n );\n}\n"],"names":["CardHeader","Stack","Typography","Tooltip","combineSx","useReplaceVariablesInString","useRef","HEADER_ACTIONS_CONTAINER_NAME","PanelActions","PanelHeader","id","title","rawTitle","description","rawDescription","links","queryResults","readHandlers","editHandlers","sx","extra","pluginActions","showIcons","viewQueriesHandler","dimension","rest","titleElementId","descriptionTooltipId","textRef","isEllipsisActive","current","width","scrollWidth","clientWidth","component","aria-labelledby","aria-describedby","disableTypography","direction","alignItems","height","disableHoverListener","variant","ref","lineHeight","minHeight","whiteSpace","overflow","textOverflow","theme","containerType","containerName","padding","spacing","borderBottom","palette","divider"],"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,SAASA,UAAU,EAAmBC,KAAK,EAAEC,UAAU,EAAEC,OAAO,QAAQ,gBAAgB;AACxF,SAASC,SAAS,QAAQ,yBAAyB;AAEnD,SAAoBC,2BAA2B,QAAQ,4BAA4B;AACnF,SAAkCC,MAAM,QAAQ,QAAQ;AACxD,SAASC,6BAA6B,QAAQ,kBAAkB;AAChE,SAASC,YAAY,QAA2B,iBAAiB;AAoBjE,OAAO,SAASC,YAAY,EAC1BC,EAAE,EACFC,OAAOC,QAAQ,EACfC,aAAaC,cA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D,0BAA0B;oBACxBT,UAAU;gBACZ;YACF,CAAA,GACA5B;QAED,GAAGM,IAAI;;AAGd"}
@@ -1 +1 @@
1
- {"version":3,"file":"PanelEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelEditorForm.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAA4C,MAAM,OAAO,CAAC;AAE/E,OAAO,EAAE,MAAM,EAA+C,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAoB1G,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,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,EAA4C,MAAM,OAAO,CAAC;AAE/E,OAAO,EAAE,MAAM,EAA+C,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAqB1G,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,iBAAiB,CAAC;IACjC,aAAa,EAAE,MAAM,CAAC;IACtB,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,CAkPzE;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,sBAAsB,CAAC"}
@@ -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;AAC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,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,QAAQ,QAAQ;AAC/E,SAASC,GAAG,EAAEC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAC1F,SAAiBC,0BAA0B,QAA4C,mBAAmB;AAC1G,SAASC,gCAAgC,EAAEC,UAAU,EAAEC,aAAa,QAAQ,yBAAyB;AACrG,SACEC,gBAAgB,EAChBC,eAAe,EACfC,eAAe,EACfC,cAAc,EACdC,aAAa,EACbC,oBAAoB,EAEpBC,iBAAiB,EACjBC,kBAAkB,EAClBC,mBAAmB,QACd,4BAA4B;AACnC,SAASC,UAAU,EAAEC,YAAY,EAAiBC,OAAO,EAAEC,QAAQ,QAAQ,kBAAkB;AAC7F,SAASC,WAAW,QAAQ,0BAA0B;AACtD,SAASC,YAAY,EAAEC,kBAAkB,QAAQ,gBAAgB;AACjE,SAASC,mBAAmB,QAAQ,wDAAwD;AAC5F,SAASC,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,cAAc,QAAQ,mBAAmB;AASlD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAAEC,aAAa,EAAEC,aAA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AAM;gDACNjB,UAAU/C,aAAa2E,SAAS;gDAChCV,OAAO,CAAC,CAACjE,aAAaiE,KAAK,IAAI,CAAC,CAACJ,WAAWI,KAAK;gDACjDC,YAAYlE,aAAaiE,KAAK,EAAEE,WAAWN,WAAWI,KAAK,EAAEE;gDAC7DjE,OAAO;oDAAEE,MAAM;oDAASP,MAAMiC;gDAAkB;gDAChDzB,UAAU,CAAC+D;oDACTR,MAAMvD,QAAQ,CAAC+D,MAAMvE,IAAI;oDACzBG,aAAa4E,iBAAiB,CAACR;gDACjC;;;;8CAMR,MAAC7H;oCAAKkH,IAAI;oCAACC,IAAI;;sDACb,KAAC/G;4CAAWiG,SAAQ;4CAAKiC,cAAc;sDAAG;;sDAG1C,KAAC9H;4CAAc+H,mBAAmBhI;sDAChC,cAAA,KAACmB;gDAAaU,iBAAiBA;;;;;8CAGnC,KAACpC;oCAAKkH,IAAI;oCAACC,IAAI;8CACb,cAAA,KAAC3G;wCAAc+H,mBAAmBhI;kDAChC,cAAA,KAACI;4CACC6H,KAAKtG;4CACLoC,SAAStB,KAAKsB,OAAO;4CACrBlC,iBAAiBA;4CACjBqG,cAAc3D;4CACd4D,iBAAiB,CAACC;gDAChBnG,WAAWmG;4CACb;4CACAC,oBAAoB,CAAChG;gDACnBa,aAAaoF,YAAY,CAACjG;4CAC5B;;;;;;;kCAMV,KAACtC;wBACCwI,aAAY;wBACZC,QAAQlG;wBACRmG,UAAU;4BACRlG,uBAAuB;wBACzB;wBACAmG,kBAAkB;4BAChBnG,uBAAuB;4BACvBb;wBACF;;;;;;AAMZ;AAEA;;CAEC,GACD,OAAO,MAAM6E,oBAAoB,oBAAoB"}
@@ -1 +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":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAuBA,UAAU,EAAEC,MAAM,QAAQ,QAAQ;AACzD,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,mBAAmB,EAAEC,SAAS,EAAEC,kBAAkB,QAAQ,4BAA4B;AAE/F,SAASC,KAAK,QAAQ,WAAW;AACjC,SAASC,kBAAkB,QAAQ,gBAAgB;AAEnD,MAAMC,uBAAuB;AAC7B,MAAMC,8BAA8B;AAEpC,OAAO,SAASC,aAAa,EAAEC,eAAe,EAA8C;IAC1F,MAAMC,SAASX,OAAuB;IACtC,IAAIY,QAAQJ;IAEZ,MAAMK,qBAAqBd,WAAWO;IAEtC,IAAIK,OAAOG,OAAO,KAAK,MAAM;QAC3BF,QAAQD,OAAOG,OAAO,CAACC,qBAAqB,GAAGH,KAAK;QACpDC,oBAAoBG,SAASC,uBAAuBL;IACtD;IAEA,MAAMM,kBAAkBd,mBAAmBQ;IAE3C,MAAM,EAAEO,MAAMC,MAAM,EAAEC,SAAS,EAAE,GAAGlB,UAAU,SAASO,gBAAgBY,IAAI,CAACF,MAAM,CAACG,IAAI;IACvF,IAAIF,WAAW;QACb,OAAO;IACT;IAEA,IAAIX,gBAAgBY,IAAI,CAACF,MAAM,CAACG,IAAI,KAAK,IAAI;QAC3C,OAAO;IACT;IAEA,MAAMC,UAAUd,gBAAgBY,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,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"}