Skip to content
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 8 commits into from
Apr 20, 2020

Conversation

nicolad
Copy link
Contributor

@nicolad nicolad commented Apr 17, 2020

Problem this Pull Request solves

How has this been tested

Peek 2020-04-17 16-40


Peek 2020-04-17 16-42

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",
Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

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

Comment on lines +11 to +15
svg {
height: var(--ee-border-radius-big);
margin: 0;
width: var(--ee-border-radius-big);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this better:

image

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

Comment on lines 13 to 15
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);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Member

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

Copy link
Contributor

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 😄

@nicolad nicolad force-pushed the EDTR/confirmation3 branch 3 times, most recently from f1e1011 to 0635953 Compare April 17, 2020 14:43
@nicolad
Copy link
Contributor Author

nicolad commented Apr 17, 2020

Got some tests which are failing only on Travis:

image


locally:

image


Copy link
Member

@tn3rb tn3rb left a 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

Comment on lines 36 to 41
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} />
Copy link
Member

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

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Comment on lines 13 to 15
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);
Copy link
Member

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',
Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thx, updated

Comment on lines +11 to +15
svg {
height: var(--ee-border-radius-big);
margin: 0;
width: var(--ee-border-radius-big);
}
Copy link
Member

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",
Copy link
Member

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

@nicolad nicolad force-pushed the EDTR/confirmation3 branch from ecf16fc to 9678923 Compare April 17, 2020 15:27
tn3rb
tn3rb previously approved these changes Apr 17, 2020
Copy link
Member

@tn3rb tn3rb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POIFECT 👌

Comment on lines 26 to 39
useEffect(() => {
canUseDOM && document.addEventListener('keydown', onEscape);

return () => {
canUseDOM && document.removeEventListener('keydown', onEscape);
};
Copy link
Contributor

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) {}

Copy link
Contributor Author

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);
Copy link
Contributor

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.

Suggested change
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);

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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();
Copy link
Contributor

@manzoorwanijk manzoorwanijk Apr 17, 2020

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 😄

Copy link
Contributor Author

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 😃

manzoorwanijk
manzoorwanijk previously approved these changes Apr 17, 2020
Copy link
Contributor

@manzoorwanijk manzoorwanijk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@@ -1,8 +0,0 @@
import './color-variables.css';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was getting this error:

image

Copy link
Contributor Author

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

@nicolad nicolad force-pushed the EDTR/confirmation3 branch 2 times, most recently from 5bb457c to 440bbe5 Compare April 20, 2020 10:40
Comment on lines 214 to 222
{
entry: {
'eventespresso-core-css-default': pathToEDTRv1 + 'components/ui/styles/themes/default/index.js',
},
module: moduleConfigWithJsAndCssRules,
watchOptions: {
poll: 1000,
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attempt #2 for:

image

@@ -38,7 +38,6 @@ describe('useFetchPrices', () => {

await waitForNextUpdate({ timeout }); // wait for response

expect(result.current.error).toBeDefined();
Copy link
Contributor Author

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

Copy link
Member

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?

Comment on lines 214 to 222
{
entry: {
'eventespresso-core-css-default': pathToEDTRv1 + 'components/ui/styles/themes/default/index.js',
},
module: moduleConfigWithJsAndCssRules,
watchOptions: {
poll: 1000,
},
},
Copy link
Contributor Author

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

@nicolad nicolad force-pushed the EDTR/confirmation3 branch 2 times, most recently from 5c84d5f to 06c6223 Compare April 20, 2020 11:03
@@ -95,6 +95,7 @@
},
"devDependencies": {
"@apollo/react-testing": "^3.1.4",
"@babel/compat-data": "^7.9.0",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this temporary, to make this failing pass:

image

Copy link
Contributor Author

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

@nicolad nicolad force-pushed the EDTR/confirmation3 branch from e0d01f5 to 36b06fc Compare April 20, 2020 11:17
@nicolad nicolad force-pushed the EDTR/confirmation3 branch from 36b06fc to 62dff69 Compare April 20, 2020 12:13
@nicolad nicolad requested a review from manzoorwanijk April 20, 2020 12:20
Copy link
Member

@tn3rb tn3rb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🌮🌮🌮🌮🌮

@nicolad nicolad merged commit 10ed7a0 into EDTR/master Apr 20, 2020
@nicolad nicolad deleted the EDTR/confirmation3 branch April 20, 2020 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants