-
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
JTE/PKFE-37 #62
Changes from 1 commit
45aa000
0946efb
4f9d1ec
5bce2c0
c2f13d1
35b02ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> | ||
); | ||
}; |
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'; | ||
|
@@ -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) { | ||
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> | ||
); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { EditorConfirmLeave } from '@/features/editor/components/editorView'; | ||
import { useWorkspaceContext } from '@/features/editor/hooks'; | ||
import { FileModel } from '@/features/editor/types'; | ||
import { useStatusContext } from '@/hooks'; | ||
import { Close as CloseIcon } from '@mui/icons-material'; | ||
import { alpha, Box, IconButton, Typography, useTheme } from '@mui/material'; | ||
import { useCallback, useState } from 'react'; | ||
|
||
/** | ||
* `FilebarGroupItem` is a functional component that represents an individual item in the file bar group. | ||
|
@@ -26,68 +28,86 @@ import { alpha, Box, IconButton, Typography, useTheme } from '@mui/material'; | |
export const FilebarGroupItem: React.FC<FileModel> = (file) => { | ||
const Theme = useTheme(); | ||
const Workspace = useWorkspaceContext(); | ||
const { blocked } = useStatusContext(); | ||
const { blocked, unsaved } = useStatusContext(); | ||
|
||
const { id, label } = file; | ||
|
||
const [isConfirmDialogOpen, setIsConfirmDialogOpen] = useState(false); | ||
const handleConfirm = useCallback(() => { | ||
Workspace.fileStateUpdate(file); | ||
Workspace.filesHistoryStateUpdate(file); | ||
setIsConfirmDialogOpen(false); | ||
}, [file, Workspace]); | ||
|
||
return ( | ||
<Box | ||
id={id} | ||
sx={{ | ||
height: '100%', | ||
pl: '1rem', | ||
pr: '0.5rem', | ||
bgcolor: Workspace.file.id === id ? Theme.palette.background.default : Theme.palette.action.selected, | ||
borderRadius: '0rem', | ||
':hover': { | ||
backgroundColor: | ||
Workspace.file.id === id | ||
? Theme.palette.background.default | ||
: blocked | ||
? Theme.palette.action.selected | ||
: alpha(Theme.palette.background.default, 0.5), | ||
}, | ||
cursor: blocked ? 'default' : 'pointer', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
gap: '0.5rem', | ||
}} | ||
onClick={() => { | ||
// Update the workspace to the selected file | ||
if (!blocked) { | ||
Workspace.fileStateUpdate(file); | ||
Workspace.filesHistoryStateUpdate(file); | ||
} | ||
}} | ||
> | ||
<Typography | ||
<> | ||
<Box | ||
id={id} | ||
sx={{ | ||
fontSize: 12, | ||
fontWeight: 'bold', | ||
textTransform: 'none', | ||
maxWidth: '10rem', | ||
overflow: 'hidden', | ||
textOverflow: 'ellipsis', | ||
whiteSpace: 'nowrap', | ||
}} | ||
> | ||
{label} | ||
</Typography> | ||
<IconButton | ||
size='small' | ||
disabled={blocked} | ||
onClick={(event) => { | ||
event.stopPropagation(); | ||
height: '100%', | ||
pl: '1rem', | ||
pr: '0.5rem', | ||
bgcolor: Workspace.file.id === id ? Theme.palette.background.default : Theme.palette.action.selected, | ||
borderRadius: '0rem', | ||
':hover': { | ||
backgroundColor: | ||
Workspace.file.id === id | ||
? Theme.palette.background.default | ||
: blocked | ||
? Theme.palette.action.selected | ||
: alpha(Theme.palette.background.default, 0.5), | ||
}, | ||
cursor: blocked ? 'default' : 'pointer', | ||
display: 'flex', | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
gap: '0.5rem', | ||
}} | ||
onMouseDown={(event) => { | ||
event.stopPropagation(); | ||
// Remove the file from the workspace | ||
Workspace.filesHistoryStateUpdate(undefined, file); | ||
onClick={() => { | ||
// Update the workspace to the selected file | ||
if (!blocked) { | ||
if (unsaved) { | ||
setIsConfirmDialogOpen(true); | ||
} else { | ||
Workspace.fileStateUpdate(file); | ||
Workspace.filesHistoryStateUpdate(file); | ||
} | ||
} | ||
}} | ||
> | ||
<CloseIcon sx={{ fontSize: 12, color: Theme.palette.text.primary }} /> | ||
</IconButton> | ||
</Box> | ||
<Typography | ||
sx={{ | ||
fontSize: 12, | ||
fontWeight: 'bold', | ||
textTransform: 'none', | ||
maxWidth: '10rem', | ||
overflow: 'hidden', | ||
textOverflow: 'ellipsis', | ||
whiteSpace: 'nowrap', | ||
}} | ||
> | ||
{label} | ||
</Typography> | ||
<IconButton | ||
size='small' | ||
disabled={blocked} | ||
onClick={(event) => { | ||
event.stopPropagation(); | ||
}} | ||
onMouseDown={(event) => { | ||
event.stopPropagation(); | ||
// Remove the file from the workspace | ||
Workspace.filesHistoryStateUpdate(undefined, file); | ||
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. If closing the current file which has edited cells, it should also prompt the confirmation about losing changes 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. Resolved! Great catch |
||
}} | ||
> | ||
<CloseIcon sx={{ fontSize: 12, color: Theme.palette.text.primary }} /> | ||
</IconButton> | ||
</Box> | ||
<EditorConfirmLeave | ||
isOpen={isConfirmDialogOpen} | ||
onClose={() => setIsConfirmDialogOpen(false)} | ||
onConfirm={handleConfirm} | ||
/> | ||
</> | ||
); | ||
}; |
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