1
1
import React , { CSSProperties , FunctionComponent , useEffect , useState } from "react" ;
2
- import {
3
- PageSection ,
4
- PageSectionVariants
5
- } from "@patternfly/react-core" ;
2
+ import { Page , PageSection , PageSectionVariants } from "@patternfly/react-core" ;
6
3
import { ArtifactTypes , ContentTypes , Design , DesignContent } from "@models/designs" ;
7
4
import { DesignsService , useDesignsService } from "@services/useDesignsService.ts" ;
8
5
import { DownloadService , useDownloadService } from "@services/useDownloadService.ts" ;
@@ -18,9 +15,10 @@ import { ProtoEditor } from "@editors/ProtoEditor.tsx";
18
15
import { OpenApiEditor } from "@editors/OpenApiEditor.tsx" ;
19
16
import { AsyncApiEditor } from "@editors/AsyncApiEditor.tsx" ;
20
17
import { CompareModal , DeleteDesignModal , EditorContext , RenameData , RenameModal } from "@app/pages/components" ;
21
- import { useParams } from "react-router-dom" ;
18
+ import { unstable_usePrompt , useParams } from "react-router-dom" ;
22
19
import { IfNotLoading } from "@apicurio/common-ui-components" ;
23
20
import { AppNavigationService , useAppNavigation } from "@services/useAppNavigation.ts" ;
21
+ import { AppHeader } from "@app/components" ;
24
22
25
23
const sectionContextStyle : CSSProperties = {
26
24
borderBottom : "1px solid #ccc" ,
@@ -113,6 +111,12 @@ export const EditorPage: FunctionComponent<EditorPageProps> = () => {
113
111
}
114
112
} , [ isDirty ] ) ;
115
113
114
+ // Add a react router prompt that will be used when *navigating* but the editor is dirty
115
+ unstable_usePrompt ( {
116
+ message : "You have unsaved changes. Do you really want to navigate away and lose them?" ,
117
+ when : ( ) => isDirty
118
+ } ) ;
119
+
116
120
// Called when the user makes an edit in the editor.
117
121
const onEditorChange = ( value : any ) : void => {
118
122
setCurrentContent ( value ) ;
@@ -230,39 +234,41 @@ export const EditorPage: FunctionComponent<EditorPageProps> = () => {
230
234
} ;
231
235
232
236
return (
233
- < IfNotLoading isLoading = { isLoading } >
234
- < PageSection variant = { PageSectionVariants . light } id = "section-context" style = { sectionContextStyle } >
235
- < EditorContext
236
- design = { design as Design }
237
- dirty = { isDirty }
238
- onSave = { onSave }
239
- onFormat = { onFormat }
240
- onDelete = { onDelete }
237
+ < Page className = "pf-m-redhat-font" isManagedSidebar = { false } header = { < AppHeader /> } >
238
+ < IfNotLoading isLoading = { isLoading } >
239
+ < PageSection variant = { PageSectionVariants . light } id = "section-context" style = { sectionContextStyle } >
240
+ < EditorContext
241
+ design = { design as Design }
242
+ dirty = { isDirty }
243
+ onSave = { onSave }
244
+ onFormat = { onFormat }
245
+ onDelete = { onDelete }
246
+ onDownload = { onDownload }
247
+ onRename = { ( ) => setRenameModalOpen ( true ) }
248
+ onCompareContent = { onCompareContent }
249
+ artifactContent = { currentContent }
250
+ />
251
+ </ PageSection >
252
+ < PageSection variant = { PageSectionVariants . light } id = "section-editor" style = { sectionEditorStyle } >
253
+ < div className = "editor-parent" style = { editorParentStyle } children = { editor ( ) as any } />
254
+ </ PageSection >
255
+ < CompareModal isOpen = { isCompareModalOpen }
256
+ onClose = { closeCompareEditor }
257
+ before = { originalContent }
258
+ beforeName = { design ?. name || "" }
259
+ after = { currentContent }
260
+ afterName = { design ?. name || "" } />
261
+ < RenameModal design = { design }
262
+ isOpen = { isRenameModalOpen }
263
+ onRename = { doRenameDesign }
264
+ onCancel = { ( ) => setRenameModalOpen ( false ) } />
265
+ < DeleteDesignModal design = { design }
266
+ isOpen = { isDeleteModalOpen }
267
+ onDelete = { onDeleteDesignConfirmed }
241
268
onDownload = { onDownload }
242
- onRename = { ( ) => setRenameModalOpen ( true ) }
243
- onCompareContent = { onCompareContent }
244
- artifactContent = { currentContent }
245
- />
246
- </ PageSection >
247
- < PageSection variant = { PageSectionVariants . light } id = "section-editor" style = { sectionEditorStyle } >
248
- < div className = "editor-parent" style = { editorParentStyle } children = { editor ( ) as any } />
249
- </ PageSection >
250
- < CompareModal isOpen = { isCompareModalOpen }
251
- onClose = { closeCompareEditor }
252
- before = { originalContent }
253
- beforeName = { design ?. name || "" }
254
- after = { currentContent }
255
- afterName = { design ?. name || "" } />
256
- < RenameModal design = { design }
257
- isOpen = { isRenameModalOpen }
258
- onRename = { doRenameDesign }
259
- onCancel = { ( ) => setRenameModalOpen ( false ) } />
260
- < DeleteDesignModal design = { design }
261
- isOpen = { isDeleteModalOpen }
262
- onDelete = { onDeleteDesignConfirmed }
263
- onDownload = { onDownload }
264
- onCancel = { ( ) => setDeleteModalOpen ( false ) } />
265
- { /*<Prompt when={isDirty} message={ "You have unsaved changes. Do you really want to leave?" }/>*/ }
266
- </ IfNotLoading >
269
+ onCancel = { ( ) => setDeleteModalOpen ( false ) } />
270
+ { /*<Prompt when={isDirty} message={ "You have unsaved changes. Do you really want to leave?" }/>*/ }
271
+ </ IfNotLoading >
272
+ </ Page >
267
273
) ;
268
274
} ;
0 commit comments