-
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
Austenem/CAT-386 add confirmation window #3479
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
73f6ea3
finish modal implementation
austenem ae8cdb0
organize imports and separate helper function
austenem d7e3458
add changelog and remove hook call
austenem 9a7b9ee
cleanup
austenem 81f6fa0
remove template
austenem c983d54
implement review changes
austenem bf9ce9b
replace function calls
austenem 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
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 @@ | ||
- Add confirmation modal to the 'delete workspaces' button. |
91 changes: 91 additions & 0 deletions
91
.../js/components/workspaces/ConfirmDeleteWorkspacesDialog/ConfirmDeleteWorkspacesDialog.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,91 @@ | ||
import React, { useCallback } from 'react'; | ||
|
||
import Box from '@mui/material/Box'; | ||
import Stack from '@mui/material/Stack'; | ||
import Button from '@mui/material/Button'; | ||
import Dialog from '@mui/material/Dialog'; | ||
import DialogActions from '@mui/material/DialogActions'; | ||
import DialogContent from '@mui/material/DialogContent'; | ||
import DialogTitle from '@mui/material/DialogTitle'; | ||
import Divider from '@mui/material/Divider'; | ||
import IconButton from '@mui/material/IconButton'; | ||
|
||
import CloseRounded from '@mui/icons-material/CloseRounded'; | ||
|
||
import { useSnackbarActions } from 'js/shared-styles/snackbars'; | ||
import { SelectedItems } from 'js/hooks/useSelectItems'; | ||
import { generateCommaList } from 'js/helpers/functions'; | ||
|
||
import { MergedWorkspace } from '../types'; | ||
|
||
interface ConfirmDeleteWorkspacesDialogProps { | ||
dialogIsOpen: boolean; | ||
handleClose: () => void; | ||
handleDeleteWorkspace: (workspaceId: number) => Promise<void>; | ||
selectedWorkspaceIds: SelectedItems; | ||
workspacesList: MergedWorkspace[]; | ||
} | ||
export default function ConfirmDeleteWorkspacesDialog({ | ||
dialogIsOpen, | ||
handleClose, | ||
handleDeleteWorkspace, | ||
selectedWorkspaceIds, | ||
workspacesList, | ||
}: ConfirmDeleteWorkspacesDialogProps) { | ||
const { toastError, toastSuccess } = useSnackbarActions(); | ||
|
||
const selectedWorkspaceNames = Array.from(selectedWorkspaceIds).map((id) => { | ||
const workspace = workspacesList.find((w) => w.id === Number(id)); | ||
return workspace ? workspace.name : ''; | ||
}); | ||
|
||
const selectedWorkspaceNamesList = generateCommaList(selectedWorkspaceNames); | ||
|
||
const handleDeleteAndClose = useCallback(() => { | ||
const workspaceIds = [...selectedWorkspaceIds]; | ||
|
||
Promise.all(workspaceIds.map((workspaceId) => handleDeleteWorkspace(Number(workspaceId)))) | ||
.then(() => { | ||
toastSuccess(`Successfully deleted workspaces: ${selectedWorkspaceNamesList}`); | ||
selectedWorkspaceIds.clear(); | ||
}) | ||
.catch((e) => { | ||
toastError(`Error deleting workspaces: ${selectedWorkspaceNamesList}`); | ||
console.error(e); | ||
}); | ||
|
||
handleClose(); | ||
}, [handleDeleteWorkspace, selectedWorkspaceIds, selectedWorkspaceNamesList, handleClose, toastError, toastSuccess]); | ||
|
||
return ( | ||
<Dialog | ||
open={dialogIsOpen} | ||
onClose={handleClose} | ||
scroll="paper" | ||
aria-labelledby="delete-workspace-dialog" | ||
maxWidth="lg" | ||
> | ||
<Stack display="flex" flexDirection="row" justifyContent="space-between" marginRight={1}> | ||
<DialogTitle id="delete-workspace-dialog-title" variant="h3"> | ||
Delete Workspace | ||
{selectedWorkspaceIds.size > 1 ? 's' : ''} | ||
</DialogTitle> | ||
<Box alignContent="center"> | ||
<IconButton aria-label="Close" onClick={handleClose} size="large"> | ||
<CloseRounded /> | ||
</IconButton> | ||
</Box> | ||
</Stack> | ||
<DialogContent> | ||
You have selected to delete {selectedWorkspaceNamesList}. You cannot undo this action. | ||
</DialogContent> | ||
<Divider /> | ||
<DialogActions> | ||
<Button onClick={handleClose}>Cancel</Button> | ||
<Button onClick={handleDeleteAndClose} variant="contained" color="warning"> | ||
Delete | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
context/app/static/js/components/workspaces/ConfirmDeleteWorkspacesDialog/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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import ConfirmDeleteWorkspacesDialog from './ConfirmDeleteWorkspacesDialog'; | ||
|
||
export default ConfirmDeleteWorkspacesDialog; |
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
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
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.
Since this is meant for re-use, it would be nice to add a spec or two.
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.
I used JSDoc - if there's another preferred documentation format though, let me know!
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.
I was only asking for a test or two, but this is extra helpful!