-
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
Conversation
package.json
Outdated
@@ -74,6 +74,7 @@ | |||
"date-fns": "^2.11.1", | |||
"date-fns-tz": "^1.0.10", | |||
"emotion-theming": "^10.0.27", | |||
"exenv": "^1.2.2", |
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.
Added this since we are already using that indirectly via Chakra: https://github.com/chakra-ui/chakra-ui/blob/master/packages/chakra-ui/package.json#L31
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.
LOLZ I added a function with the exact same name for the toaster
it's likely the exact same logic too, since I think that package is a duplication of internal logic from React
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.
got tricked by chakra: https://github.com/chakra-ui/chakra-ui/blob/master/packages/chakra-ui/src/Modal/index.js#L22
but followed your approach, which is less dependent on external stuff
svg { | ||
height: var(--ee-border-radius-big); | ||
margin: 0; | ||
width: var(--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.
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 match 12px
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
title = sprintf(__('Ticket Assignment Manager for Datetime: %s - %s'), entity.dbId, entity.name); | ||
title = sprintf(__('Ticket Assignment Manager for Datetime: %s - %s'), String(entity.dbId), entity.name); | ||
} else if (assignmentType === 'forTicket') { | ||
title = sprintf(__('Ticket Assignment Manager for Ticket: %s - %s'), entity.dbId, entity.name); | ||
title = sprintf(__('Ticket Assignment Manager for Ticket: %s - %s'), String(entity.dbId), entity.name); |
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.
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.
crazy... never had that before
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 had that many times 😄
f1e1011
to
0635953
Compare
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.
AWESOME POSSUM
looks great... I did have a couple of minor enhancement requests
cancelButton={<ButtonAdapter buttonText={__('No')} ref={cancelRef} onClick={onClose} />} | ||
header={__('Are you sure you want to close this modal?')} | ||
isOpen={isOpen} | ||
leastDestructiveRef={cancelRef} | ||
okButton={ | ||
<ButtonAdapter buttonText={__('Yes')} variantColor='red' onClick={props.onClose} ml={3} /> |
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.
let's change all of these i18n strings into variables and then also add optional props for them with these as the defaults, ie:
const cancelBtnText = cancelButtonText ? cancelButtonText : __('No');
// etc
As well, let's change the header text to just be:
__('Are you sure you want to close this?')
as most non-devs won't understand what a modal 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.
as most non-devs won't understand what a modal is
good one, thx
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.
updated this, with a slightly changed approach, but with the same result;
thx for suggestion
title = sprintf(__('Ticket Assignment Manager for Datetime: %s - %s'), entity.dbId, entity.name); | ||
title = sprintf(__('Ticket Assignment Manager for Datetime: %s - %s'), String(entity.dbId), entity.name); | ||
} else if (assignmentType === 'forTicket') { | ||
title = sprintf(__('Ticket Assignment Manager for Ticket: %s - %s'), entity.dbId, entity.name); | ||
title = sprintf(__('Ticket Assignment Manager for Ticket: %s - %s'), String(entity.dbId), entity.name); |
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.
crazy... never had that before
import './styles.scss'; | ||
|
||
const modalCloseButtonProps: ButtonProps = { | ||
className: 'confirm-close', |
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.
plz namespace all class names, ie: ee-confirm-close
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.
thx, updated
svg { | ||
height: var(--ee-border-radius-big); | ||
margin: 0; | ||
width: var(--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
package.json
Outdated
@@ -74,6 +74,7 @@ | |||
"date-fns": "^2.11.1", | |||
"date-fns-tz": "^1.0.10", | |||
"emotion-theming": "^10.0.27", | |||
"exenv": "^1.2.2", |
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.
LOLZ I added a function with the exact same name for the toaster
it's likely the exact same logic too, since I think that package is a duplication of internal logic from React
ecf16fc
to
9678923
Compare
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.
POIFECT 👌
useEffect(() => { | ||
canUseDOM && document.addEventListener('keydown', onEscape); | ||
|
||
return () => { | ||
canUseDOM && document.removeEventListener('keydown', onEscape); | ||
}; |
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.
For clarity, better use if (canUseDOM) {}
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 followed the same example as in chakra: https://github.com/chakra-ui/chakra-ui/blob/master/packages/chakra-ui/src/Modal/index.js#L131
but if the clarity is an issue, then it's better to make it more explicit, thx for letting me know this 👍
@@ -10,9 +10,9 @@ const ModalContainer: React.FC<ModalContainerProps> = ({ isOpen, onClose, ...pro | |||
|
|||
let title = ''; | |||
if (assignmentType === 'forDate') { | |||
title = sprintf(__('Ticket Assignment Manager for Datetime: %s - %s'), entity.dbId, entity.name); | |||
title = sprintf(__('Ticket Assignment Manager for Datetime: %s - %s'), String(entity.dbId), entity.name); |
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.
Always better to use language constructs (which are faster) instead of calling functions. Although, it won't make a big difference here but still it's better.
title = sprintf(__('Ticket Assignment Manager for Datetime: %s - %s'), String(entity.dbId), entity.name); | |
title = sprintf(__('Ticket Assignment Manager for Datetime: %s - %s'), `${entity.dbId}`, entity.name); |
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 would prefer clear and clean code over minor performance optimization.
It's not the case here, but in order to know exactly what is the performance gain or loss, I'd have to measure both cases and see exact number. And, if I'd do that probably there wouldn't be very noticeable difference.
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.
However, let's take aside performance discussion.
I think there is a bit of the problem with sprintf
.
As I understand sprintf
is returning a string, then why I should care about these type coercions?
I think sprintf
should be smart enough to this and maybe other check and I should just pass whatever I want. If I pass undefined
or null
, ignore it, otherwise do your smart job and please don't bother me with type coercion.
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 love the DX classnames
have, I can pass whatever I want, it can be null
, object or string and then it's smart enough to figure out by itself what needs to be the result.
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.
At some point, maybe, we should create our own wrapper for sprintf
and make it a bit smarter.
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.
classnames
is awesome:
classNames('foo', 'bar'); // => 'foo bar'
classNames('foo', { bar: true }); // => 'foo bar'
classNames({ 'foo-bar': true }); // => 'foo-bar'
classNames({ 'foo-bar': false }); // => ''
classNames({ foo: true }, { bar: true }); // => 'foo bar'
classNames({ foo: true, bar: true }); // => 'foo bar'
// lots of arguments of various types
classNames('foo', { bar: true, duck: false }, 'baz', { quux: true }); // => 'foo bar baz quux'
// other falsy values are just ignored
classNames(null, false, 'bar', undefined, 0, 1, { baz: null }, ''); // => 'bar 1'
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 }) => keyCode === ESCAPE && onOpen(); |
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.
Not good for TS, try to set a non void
return type of the function to see the problem with that magical shortcut 😄
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.
agree, made it TS-friendly:
const onEscape = ({ keyCode }): void => {
if (keyCode === ESCAPE) {
onOpen();
}
};
was in one-liner mood before 😃
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.
LGTM 👍
e57a1d0
to
6548f1f
Compare
@@ -1,8 +0,0 @@ | |||
import './color-variables.css'; |
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.
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.
we have this in EDTR/refactor-master
in case we might need this, no need to keep this here
5bb457c
to
440bbe5
Compare
config/webpack.common.js
Outdated
{ | ||
entry: { | ||
'eventespresso-core-css-default': pathToEDTRv1 + 'components/ui/styles/themes/default/index.js', | ||
}, | ||
module: moduleConfigWithJsAndCssRules, | ||
watchOptions: { | ||
poll: 1000, | ||
}, | ||
}, |
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.
attempt #2 for:
@@ -38,7 +38,6 @@ describe('useFetchPrices', () => { | |||
|
|||
await waitForNextUpdate({ timeout }); // wait for response | |||
|
|||
expect(result.current.error).toBeDefined(); |
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.
locally I was getting error because of this line, weird
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.
@manzoorwanijk any ideas about this?
config/webpack.common.js
Outdated
{ | ||
entry: { | ||
'eventespresso-core-css-default': pathToEDTRv1 + 'components/ui/styles/themes/default/index.js', | ||
}, | ||
module: moduleConfigWithJsAndCssRules, | ||
watchOptions: { | ||
poll: 1000, | ||
}, | ||
}, |
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.
this file will completely/ safely removed in #2609
5c84d5f
to
06c6223
Compare
@@ -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 comment
The 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 comment
The 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
e0d01f5
to
36b06fc
Compare
36b06fc
to
62dff69
Compare
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.
Problem this Pull Request solves
ModalWithAlert
in app layer to add alert in error casesHow has this been tested