-
Notifications
You must be signed in to change notification settings - Fork 87
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
Show alert upon closing modal via escape keypress; partially close #2613. #2704
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
41b5ff8
Adjusted closeButton; js_only.
nicolad 7ed6e49
Conflicts fixed.
nicolad 1dca460
Updated ModalWithAlert; js_only.
nicolad 9566001
Updated modalCloseButtonProps; js_only.
nicolad 3d59bbf
canUseDOM | js_only
nicolad 84c5bac
Updated onEscape; js_only.
nicolad 6548f1f
Updated ModalWithAlert; js_only.
nicolad 62dff69
Failing tests fix; js_only.
nicolad 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,3 @@ | ||
const canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement); | ||
|
||
export default canUseDOM; |
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 +1,2 @@ | ||
export { default as canUseDOM } from './canUseDOM'; | ||
export { default as getHTMLElementClientRect } from './getHTMLElementClientRect'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,3 @@ | ||
.ee-modal-form { | ||
max-width: 75rem !important; | ||
.confirm-close { | ||
display: inline-flex; | ||
position: absolute; | ||
top: 8px; | ||
right: 12px; | ||
min-width: auto; | ||
width: var(--ee-padding-big); | ||
height: var(--ee-padding-big); | ||
svg { | ||
margin: 0; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { useEffect } from 'react'; | ||
import { useDisclosure } from '@chakra-ui/core'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { canUseDOM } from '@appServices/utilities/dom'; | ||
import { ESCAPE } from '@wordpress/keycodes'; | ||
|
||
import { AlertDialog } from '@infraUI/display'; | ||
import { Button as ButtonAdapter } from '@infraUI/inputs'; | ||
import { Modal, ModalProps } from '@infraUI/layout/modal'; | ||
|
||
interface Props extends ModalProps { | ||
cancelBtnText?: string; | ||
header?: string; | ||
okBtnText?: string; | ||
showAlertOnEscape: boolean; | ||
} | ||
|
||
const ModalWithAlert: React.FC<Props> = ({ children, showAlertOnEscape, ...props }) => { | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const cancelRef = React.useRef(); | ||
const cancelBtnText = props.cancelBtnText || __('No'); | ||
const header = props.header || __('Are you sure you want to close this?'); | ||
const okBtnText = props.okBtnText || __('Yes'); | ||
const onEscape = ({ keyCode }): void => { | ||
if (keyCode === ESCAPE) { | ||
onOpen(); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (canUseDOM) { | ||
document.addEventListener('keydown', onEscape); | ||
} | ||
|
||
return () => { | ||
if (canUseDOM) { | ||
document.removeEventListener('keydown', onEscape); | ||
} | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<Modal {...props} closeOnEsc={!showAlertOnEscape}> | ||
{children} | ||
</Modal> | ||
{showAlertOnEscape && ( | ||
<AlertDialog | ||
cancelButton={<ButtonAdapter buttonText={cancelBtnText} ref={cancelRef} onClick={onClose} />} | ||
header={header} | ||
isOpen={isOpen} | ||
leastDestructiveRef={cancelRef} | ||
okButton={ | ||
<ButtonAdapter buttonText={okBtnText} variantColor='red' onClick={props.onClose} ml={3} /> | ||
} | ||
onClose={onClose} | ||
/> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ModalWithAlert; |
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 @@ | ||
export { default as ModalWithAlert } from './ModalWithAlert'; |
34 changes: 0 additions & 34 deletions
34
...main/eventEditor/ui/ticketAssignmentsManager/components/TicketAssignmentsManagerModal.tsx
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
.../ticketAssignmentsManager/components/TicketAssignmentsManagerModal/buttons/CloseModal.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,20 @@ | ||
import React, { useCallback } from 'react'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
import { ConfirmClose } from '@appDisplay/confirm'; | ||
import { modalCloseButtonProps } from '@infraUI/layout/modal'; | ||
import { useTAMContext } from '../../../context'; | ||
|
||
const CloseModal: React.FC = () => { | ||
const { dataState, onCloseModal } = useTAMContext(); | ||
|
||
const { hasOrphanEntities } = dataState; | ||
|
||
const hasErrors = hasOrphanEntities(); | ||
|
||
const onConfirm = useCallback(onCloseModal, [hasErrors]); | ||
|
||
return hasErrors ? <ConfirmClose buttonProps={modalCloseButtonProps} onConfirm={onConfirm} /> : null; | ||
}; | ||
|
||
export default React.memo(CloseModal); |
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
42 changes: 42 additions & 0 deletions
42
...ventEditor/ui/ticketAssignmentsManager/components/TicketAssignmentsManagerModal/index.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,42 @@ | ||
import React from 'react'; | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
import { ModalWithAlert } from '@appLayout/modal'; | ||
|
||
import CloseModalButton from './buttons/CloseModal'; | ||
import TicketAssignmentsManager from '../TicketAssignmentsManager'; | ||
import useCancelButtonProps from './buttons/useCancelButtonProps'; | ||
import useSubmitButtonProps from './buttons/useSubmitButtonProps'; | ||
import { useTAMContext } from '../../context'; | ||
|
||
import '../styles.scss'; | ||
|
||
const TicketAssignmentsManagerModal: React.FC = () => { | ||
const { | ||
dataState: { hasOrphanEntities }, | ||
onCloseModal, | ||
title, | ||
} = useTAMContext(); | ||
const cancelButtonProps = useCancelButtonProps(); | ||
const submitButtonProps = useSubmitButtonProps(); | ||
|
||
const hasErrors = hasOrphanEntities(); | ||
|
||
return ( | ||
<ModalWithAlert | ||
bodyClassName='ee-ticket-assignments-manager__body' | ||
cancelButtonProps={cancelButtonProps} | ||
className='ee-ticket-assignments-manager' | ||
closeButton={<CloseModalButton />} | ||
isOpen={true} | ||
onClose={onCloseModal} | ||
showAlertOnEscape={hasErrors} | ||
submitButtonProps={submitButtonProps} | ||
title={title || __('Ticket Assignment Manager')} | ||
> | ||
<TicketAssignmentsManager /> | ||
</ModalWithAlert> | ||
); | ||
}; | ||
|
||
export default TicketAssignmentsManagerModal; |
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 @@ | ||
export { default as Modal } from './Modal'; | ||
export { default as modalCloseButtonProps } from './modalCloseButtonProps'; | ||
|
||
export * from './types'; |
14 changes: 14 additions & 0 deletions
14
assets/src/infrastructure/ui/layout/modal/modalCloseButtonProps/index.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,14 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
import { ButtonProps } from '@infraUI/inputs'; | ||
import { Close } from '@appDisplay/icons'; | ||
|
||
import './styles.scss'; | ||
|
||
const modalCloseButtonProps: ButtonProps = { | ||
className: 'ee-confirm-close', | ||
icon: Close, | ||
variant: 'unstyled', | ||
}; | ||
|
||
export default modalCloseButtonProps; |
17 changes: 17 additions & 0 deletions
17
assets/src/infrastructure/ui/layout/modal/modalCloseButtonProps/styles.scss
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,17 @@ | ||
// this selector is used for specificity | ||
[role='alertdialog'] { | ||
.ee-confirm-close { | ||
display: inline-flex; | ||
position: absolute; | ||
top: 8px; | ||
right: 12px; | ||
min-width: auto; | ||
width: var(--ee-padding-big); | ||
height: var(--ee-padding-big); | ||
svg { | ||
height: var(--ee-border-radius-big); | ||
margin: 0; | ||
width: var(--ee-border-radius-big); | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -95,6 +95,7 @@ | |
}, | ||
"devDependencies": { | ||
"@apollo/react-testing": "^3.1.4", | ||
"@babel/compat-data": "^7.9.0", | ||
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. 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. As I wrote in another comment, this non-sense will be removed/ adjusted here: #2609 |
||
"@babel/core": "^7.9.0", | ||
"@babel/plugin-proposal-class-properties": "^7.8.3", | ||
"@babel/plugin-transform-runtime": "^7.9.0", | ||
|
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.
I like this better:
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 needed
--ee-border-radius-big
to match12px
which is the same dimension as in chakra.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.
Open to better variable names than
--ee-border-radius-big
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.
ya I'll most likely tweak things once everything is converted, but that doesn't look bad as is
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.
thanks