-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JTE/PKFE-37 #62
Merged
Merged
JTE/PKFE-37 #62
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
45aa000
Added global unsaved status, implemented a popup before unsaved refre…
justinnas 0946efb
Added a dialog regarding unsaved changes
justinnas 4f9d1ec
Fixed a bug where a popup would appear when clicked on a folder
justinnas 5bce2c0
Fixed minor bugs, added confirmation dialog to tab close icon and fil…
justinnas c2f13d1
Bug fixes, added confirmation prompts to Rename and Export buttons
justinnas 35b02ce
Fixed a bug regarding closing other files when there are unsaved changes
justinnas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
app/front-end/src/features/editor/components/editorView/editorConfirmLeave.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { FileTreeItemContextMenuStyledDialog } from '@/features/editor/components/fileTreeView/fileTreeItem'; | ||
import { useStatusContext } from '@/hooks'; | ||
import { Close as CloseIcon } from '@mui/icons-material'; | ||
import { | ||
Box, | ||
Button, | ||
DialogActions, | ||
DialogContent, | ||
DialogTitle, | ||
Grid, | ||
IconButton, | ||
Typography, | ||
useTheme, | ||
} from '@mui/material'; | ||
import { useCallback } from 'react'; | ||
|
||
interface EditorConfirmLeaveDialogProps { | ||
onConfirm: () => void; | ||
isOpen: boolean; | ||
onClose: () => void; | ||
} | ||
|
||
export const EditorConfirmLeave: React.FC<EditorConfirmLeaveDialogProps> = ({ onConfirm, isOpen, onClose }) => { | ||
const { unsavedStateUpdate } = useStatusContext(); | ||
const Theme = useTheme(); | ||
|
||
const handleConfirm = useCallback(() => { | ||
unsavedStateUpdate(false); | ||
onConfirm(); | ||
onClose(); | ||
}, [onConfirm, onClose, unsavedStateUpdate]); | ||
|
||
return ( | ||
<FileTreeItemContextMenuStyledDialog open={isOpen} onClose={onClose}> | ||
<Grid container spacing={2} justifyContent='center' alignItems='center'> | ||
<Grid item xs={8}> | ||
<DialogTitle sx={{ color: Theme.palette.primary.main, pl: '1.5rem', pt: '1.5rem', fontWeight: '700' }}> | ||
Unsaved changes | ||
</DialogTitle> | ||
</Grid> | ||
<Grid item xs={4}> | ||
<Box display='flex' justifyContent='flex-end'> | ||
<IconButton | ||
aria-label='close' | ||
onClick={onClose} | ||
sx={{ | ||
color: Theme.palette.primary.main, | ||
mt: '0.5rem', | ||
mr: '1.5rem', | ||
}} | ||
> | ||
<CloseIcon /> | ||
</IconButton> | ||
</Box> | ||
</Grid> | ||
</Grid> | ||
<DialogContent sx={{ py: 0 }}> | ||
<Typography sx={{ color: Theme.palette.text.primary, fontSize: '1rem', mb: '1rem' }}> | ||
You have unsaved changes. If you continue, your <b>changes will be lost</b>. <br /> | ||
Do you wish to continue? | ||
</Typography> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={onClose}> | ||
<Typography sx={{ fontSize: '1rem', color: Theme.palette.text.secondary }}>Cancel</Typography> | ||
</Button> | ||
<Button | ||
onClick={handleConfirm} | ||
variant='outlined' | ||
sx={{ | ||
borderColor: Theme.palette.primary.main, | ||
':hover': { borderColor: Theme.palette.primary.main, bgcolor: Theme.palette.secondary.main }, | ||
'& .MuiTouchRipple-root': { | ||
color: Theme.palette.primary.main, | ||
}, | ||
}} | ||
> | ||
Continue | ||
</Button> | ||
</DialogActions> | ||
</FileTreeItemContextMenuStyledDialog> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
app/front-end/src/features/editor/components/editorView/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import { EditorConfirmLeave } from '@/features/editor/components/editorView'; | ||
import { FileTreeItemContextMenu, FileTreeItemLabel } from '@/features/editor/components/fileTreeView/fileTreeItem'; | ||
import { useWorkspaceContext } from '@/features/editor/hooks'; | ||
import { FileTypes } from '@/features/editor/types'; | ||
|
@@ -136,7 +137,7 @@ export const FileTreeItem = React.forwardRef(function CustomTreeItem( | |
icon = getIconFromFileType(item.fileType); | ||
} | ||
|
||
const { fileStateUpdate, filesHistoryStateUpdate } = useWorkspaceContext(); | ||
const { fileStateUpdate, filesHistoryStateUpdate, file } = useWorkspaceContext(); | ||
const { blocked } = useStatusContext(); | ||
const [contextMenu, setContextMenu] = useState<(EventTarget & HTMLDivElement) | null>(null); | ||
const [contextMenuPosition, setContextMenuPosition] = useState<{ top: number; left: number }>({ | ||
|
@@ -166,6 +167,13 @@ export const FileTreeItem = React.forwardRef(function CustomTreeItem( | |
setContextMenuPosition({ top: 0, left: 0 }); | ||
}; | ||
|
||
const [isConfirmDialogOpen, setIsConfirmDialogOpen] = useState(false); | ||
const { unsaved } = useStatusContext(); | ||
const handleConfirm = () => { | ||
handleClick(item.id, item.label, item.fileType); | ||
setIsConfirmDialogOpen(false); | ||
}; | ||
|
||
return ( | ||
<TreeItem2Provider itemId={itemId}> | ||
<StyledFileTreeItemRoot {...getRootProps(other)}> | ||
|
@@ -174,7 +182,11 @@ export const FileTreeItem = React.forwardRef(function CustomTreeItem( | |
onClick: (event) => { | ||
if (!blocked) { | ||
if (getContentProps().onClick) getContentProps().onClick(event); | ||
handleClick(item.id, item.label, item.fileType); | ||
if (unsaved) { | ||
if (item.fileType !== FileTypes.FOLDER && item.id !== file.id) setIsConfirmDialogOpen(true); | ||
} else { | ||
handleClick(item.id, item.label, item.fileType); | ||
} | ||
} | ||
}, | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also when using context menu actions such as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
|
@@ -204,6 +216,11 @@ export const FileTreeItem = React.forwardRef(function CustomTreeItem( | |
onClose={handleCloseContextMenu} | ||
/> | ||
{children && <TransitionComponent {...getGroupTransitionProps()} />} | ||
<EditorConfirmLeave | ||
isOpen={isConfirmDialogOpen} | ||
onClose={() => setIsConfirmDialogOpen(false)} | ||
onConfirm={handleConfirm} | ||
/> | ||
</StyledFileTreeItemRoot> | ||
</TreeItem2Provider> | ||
); | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also when moving to the next or previous page of the file, it should also prompt that changes may be lost.
The same principle should also be done with changing page size number.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved