1+ import { useBugConfirmDialog } from "@core/BugConfirmDialog" ;
12import BugForm from "@core/BugForm" ;
23import Editor from "@monaco-editor/react" ;
34import CodeIcon from "@mui/icons-material/Code" ;
4- import { Box , Button , Grid , IconButton } from "@mui/material" ;
5+ import { Button , Grid , IconButton } from "@mui/material" ;
6+ import Alert from "@mui/material/Alert" ;
57import AxiosPut from "@utils/AxiosPut" ;
68import { useAlert } from "@utils/Snackbar" ;
79import { useEffect , useState } from "react" ;
@@ -10,22 +12,26 @@ import { useNavigate } from "react-router-dom";
1012export default function BugConfigWrapper ( { children, config, handleSubmit = ( ) => { } } ) {
1113 const navigate = useNavigate ( ) ;
1214 const sendAlert = useAlert ( ) ;
15+ const { confirmDialog } = useBugConfirmDialog ( ) ;
1316
1417 const [ editorMode , setEditorMode ] = useState ( false ) ;
1518 const [ editorText , setEditorText ] = useState ( "" ) ;
1619 const [ editorJson , setEditorJson ] = useState ( config ) ;
1720 const [ jsonError , setJsonError ] = useState ( null ) ;
1821
19- // Initialize editor with current config
22+ // Track if the ID has been changed
23+ const [ idChanged , setIdChanged ] = useState ( false ) ;
24+ const originalId = config ?. id ;
25+
2026 useEffect ( ( ) => {
2127 const pretty = JSON . stringify ( config , null , 2 ) ;
2228 setEditorText ( pretty ) ;
2329 setEditorJson ( config ) ;
2430 setJsonError ( null ) ;
31+ setIdChanged ( false ) ; // reset ID change
2532 } , [ config ] ) ;
2633
2734 const onCancel = ( ) => navigate ( - 1 ) ;
28-
2935 const handleEditorMode = ( ) => setEditorMode ( ! editorMode ) ;
3036
3137 const handleEditorChange = ( value ) => {
@@ -34,11 +40,21 @@ export default function BugConfigWrapper({ children, config, handleSubmit = () =
3440 const parsed = JSON . parse ( value ) ;
3541 setEditorJson ( parsed ) ;
3642 setJsonError ( null ) ;
43+
44+ // Detect ID change
45+ setIdChanged ( parsed . id !== originalId ) ;
3746 } catch ( err ) {
3847 setJsonError ( err . message ) ;
3948 }
4049 } ;
4150
51+ const handleRevertId = ( ) => {
52+ const reverted = { ...editorJson , id : originalId } ;
53+ setEditorJson ( reverted ) ;
54+ setEditorText ( JSON . stringify ( reverted , null , 2 ) ) ;
55+ setIdChanged ( false ) ;
56+ } ;
57+
4258 const getBody = ( ) => {
4359 if ( editorMode ) {
4460 return (
@@ -57,7 +73,23 @@ export default function BugConfigWrapper({ children, config, handleSubmit = () =
5773 } }
5874 />
5975 { jsonError && (
60- < Box sx = { { color : "#f44336" , margin : 1 , marginBottom : 0 } } > Invalid JSON: { jsonError } </ Box >
76+ < Alert severity = "error" sx = { { marginTop : 1 } } >
77+ Invalid JSON: { jsonError }
78+ </ Alert >
79+ ) }
80+
81+ { idChanged && (
82+ < Alert
83+ severity = "warning"
84+ sx = { { marginTop : 1 } }
85+ action = {
86+ < Button color = "inherit" size = "small" onClick = { handleRevertId } >
87+ Restore
88+ </ Button >
89+ }
90+ >
91+ Panel ID has been changed. Restore original ID before saving.
92+ </ Alert >
6193 ) }
6294 </ >
6395 ) ;
@@ -79,9 +111,7 @@ export default function BugConfigWrapper({ children, config, handleSubmit = () =
79111 } ) ;
80112 navigate ( - 1 ) ;
81113 } else {
82- sendAlert ( `${ config ?. title } could not be updated.` , {
83- variant : "warning" ,
84- } ) ;
114+ sendAlert ( `${ config ?. title } could not be updated.` , { variant : "warning" } ) ;
85115 }
86116 } ;
87117
@@ -100,14 +130,12 @@ export default function BugConfigWrapper({ children, config, handleSubmit = () =
100130 < CodeIcon />
101131 </ IconButton >
102132 }
103- sx = { {
104- maxWidth : "800px" ,
105- } }
133+ sx = { { maxWidth : "800px" } }
106134 >
107135 < form onSubmit = { handleSubmit ( onSubmit ) } >
108136 < BugForm . Header onClose = { onCancel } > Configuration</ BugForm . Header >
109137
110- < BugForm . Body > { getBody ( ) } </ BugForm . Body >
138+ < BugForm . Body sx = { { paddingBottom : 0 } } > { getBody ( ) } </ BugForm . Body >
111139
112140 < BugForm . Actions >
113141 < Button variant = "contained" color = "secondary" disableElevation onClick = { onCancel } >
@@ -119,7 +147,7 @@ export default function BugConfigWrapper({ children, config, handleSubmit = () =
119147 variant = "contained"
120148 color = "primary"
121149 disableElevation
122- disabled = { editorMode && ! ! jsonError }
150+ disabled = { editorMode && ( ! ! jsonError || idChanged ) }
123151 onClick = { editorMode ? ( ) => onSubmit ( editorJson ) : undefined }
124152 >
125153 Save Changes
0 commit comments