-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update browse identifiers UI to support deletion
- Loading branch information
Showing
5 changed files
with
180 additions
and
10 deletions.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
gnomon/lib/client/jsx/components/confirmation-code-modal.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,46 @@ | ||
import React from 'react'; | ||
import Button from '@material-ui/core/Button'; | ||
import TextField from '@material-ui/core/TextField'; | ||
import Dialog from '@material-ui/core/Dialog'; | ||
import DialogActions from '@material-ui/core/DialogActions'; | ||
import DialogContent from '@material-ui/core/DialogContent'; | ||
import DialogContentText from '@material-ui/core/DialogContentText'; | ||
import DialogTitle from '@material-ui/core/DialogTitle'; | ||
|
||
export default function ConfirmationCodeModal({open, confirmation, confirmationError, onChange, onClose, onConfirm}:{ open: boolean, confirmation: string, onClose: Function, onConfirm: Function }) { | ||
return ( | ||
<Dialog | ||
open={open} | ||
onClose={onClose} | ||
aria-labelledby="message-modal-title" | ||
aria-describedby="message-modal-description" | ||
> | ||
<DialogTitle id="message-modal-title">Confirmation Required</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText id="message-modal-description"> | ||
{ confirmationError } | ||
</DialogContentText> | ||
<TextField | ||
autoFocus | ||
required | ||
margin="dense" | ||
name="confirmation" | ||
label="Confirmation" | ||
type="string" | ||
fullWidth | ||
variant="standard" | ||
onChange={ e => onChange(e.target.value) } | ||
value={ confirmation } | ||
/> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={onClose} color="primary" autoFocus> | ||
Close | ||
</Button> | ||
<Button onClick={onConfirm} color="primary" autoFocus> | ||
Confirm | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
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,30 @@ | ||
import React from 'react'; | ||
import Button from '@material-ui/core/Button'; | ||
import Dialog from '@material-ui/core/Dialog'; | ||
import DialogActions from '@material-ui/core/DialogActions'; | ||
import DialogContent from '@material-ui/core/DialogContent'; | ||
import DialogContentText from '@material-ui/core/DialogContentText'; | ||
import DialogTitle from '@material-ui/core/DialogTitle'; | ||
|
||
export default function MessageModal({open, title, message, onClose}:{ open: boolean, title: string, message: string, onClose: Function }) { | ||
return ( | ||
<Dialog | ||
open={open} | ||
onClose={onClose} | ||
aria-labelledby="message-modal-title" | ||
aria-describedby="message-modal-description" | ||
> | ||
<DialogTitle id="message-modal-title">{ title }</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText id="message-modal-description"> | ||
{ message } | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<Button onClick={onClose} color="primary" autoFocus> | ||
Close | ||
</Button> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
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
74 changes: 74 additions & 0 deletions
74
gnomon/lib/client/jsx/components/names-toolbar/delete-identifiers-button.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,74 @@ | ||
import React, { useState, useRef } from 'react'; | ||
import { useAppSelector as useSelector } from '../../hooks'; | ||
import DeleteOutlineOutlinedIcon from '@material-ui/icons/DeleteOutlineOutlined'; | ||
|
||
import { useDispatch } from '../../utils/redux'; | ||
import ToolbarButtonWithPopper from './toolbar-button-with-popper'; | ||
import ConfirmationPopper from '../confirmation-popper'; | ||
import MessageModal from '../message-modal'; | ||
import ConfirmationCodeModal from '../confirmation-code-modal'; | ||
import { json_get, json_post } from 'etna-js/utils/fetch'; | ||
import { magmaPath } from 'etna-js/api/magma_api'; | ||
|
||
|
||
|
||
const DeleteIdentifiersButton = ({ small, project_name, data, buttonText, className, refresh }: { small: boolean, className?: string, data: Array<any>, buttonText: string }) => { | ||
const [confirmation, setConfirmation] = useState(''); | ||
const [confirmationError, setConfirmationError] = useState(''); | ||
const [ message, setMessage ] = useState(''); | ||
const [ messageTitle, setMessageTitle ] = useState(''); | ||
|
||
const handleDelete = () => { | ||
json_post(magmaPath(`gnomon/${project_name}/delete`), | ||
{ identifiers: data.map(d => d.name), confirmation }).then( | ||
({success}) => { | ||
setMessage(success); | ||
setMessageTitle('Deleted Identifiers'); | ||
setConfirmation(''); | ||
refresh(); | ||
} | ||
).catch( | ||
(error) => error.then( | ||
({error}) => { | ||
setConfirmation(''); | ||
if (error.includes('confirmation')) setConfirmationError(error); | ||
else { | ||
setMessage(error.length > 100 ? `${error.substring(0,100)}...` : error); | ||
setMessageTitle('Deletion Failed'); | ||
} | ||
} | ||
) | ||
) | ||
}; | ||
|
||
return ( | ||
<React.Fragment> | ||
<ToolbarButtonWithPopper | ||
text={ buttonText } | ||
iconComponent={<DeleteOutlineOutlinedIcon />} | ||
variant={small ? 'compact' : 'full'} | ||
color="#FF0000" | ||
onClickOrPopperChange={handleDelete} | ||
disabled={data.length == 0} | ||
className={className} | ||
/> | ||
<ConfirmationCodeModal | ||
open={!!confirmationError} | ||
confirmationError={ confirmationError } | ||
confirmation={ confirmation } | ||
onChange={ setConfirmation } | ||
onClose={ () => { | ||
setConfirmationError(''); | ||
setConfirmation(''); | ||
} } | ||
onConfirm={ () => { | ||
setConfirmationError(''); | ||
handleDelete(); | ||
}} | ||
/> | ||
<MessageModal title={messageTitle} open={!!message} onClose={ () => setMessage('') } message={message}/> | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export default DeleteIdentifiersButton; |