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

Refactor certain modals to confirm_dialog module #18629

Merged
merged 3 commits into from Jun 9, 2021

Conversation

aryanshridhar
Copy link
Member

@aryanshridhar aryanshridhar commented May 27, 2021

Refactored multiple UI modals to use the confirm_dialog module. Essentially, converted the ones that presented the user with a simple 'Cancel'/'Confirm' type question.

These includes:

Maybe @sumanthvrao can have a look at it :)

</div>
<p>
{{#tr}}
Are you sure you want to resend the invitation to {{email}}?
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

We want the previous formatting to decorate the email address.

},
confirm_dialog.launch({
parent: modal_parent,
html_heading: $t_html({defaultMessage: "Resend invitation to {email}"}, {email}),
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

The heading might be better as just "Resend invitation", rather than showing the email address twice (here and in the body of the template).

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool! Will add a separate commit for it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe same goes for "Revoke invitation" as well ?

</div>
<p>
{{#tr}}
By deactivating <strong>{{username}}</strong> &lt;{{email}}&gt;, they will be logged out immediately.
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

The #*inline z-user syntax is important for the translation experience (and is why you're getting CI failures).

Please preserve that formatting of the translated strings.

@timabbott
Copy link
Sponsor Member

@aryanshridhar thanks for working on this! I'm excited about this cleanup, since it lets us delete a ton of duplicated HTML. Can you fix the issues I noted, and post before/after screenshots for every modal to confirm that they're all visually identical to before the migration. (I guess except for the one I suggested a small wording change to).

(BTW, is there something we could have documented better to explain why the z-link thing is important? E.g. maybe a modified error message?)

Once you have that (and have done a self-review to confirm this has the exact same logic as before; and/or any changes are clearly explained in the commit message or done in prep commits), it'd be great if you can post in #frontend and get a code review on it from another contributor.

@aryanshridhar aryanshridhar force-pushed the Add-ConfirmDialog branch 3 times, most recently from 909283a to e5b6ed8 Compare May 28, 2021 17:29
@aryanshridhar
Copy link
Member Author

Thanks @timabbott, Yea, I guess documenting the purpose of z-link would definitely help. Maybe within https://zulip.readthedocs.io/en/latest/translating/translating.html#frontend-translations ?

Screenshots:

Before

deactivate-user-master

After
user-deactivation

Before
delete-topic-master

After
delete_topic

Before
realm-deactivation-master

After
realm-deactivation

Before
resend-master

After
resend

Before
revoke-master

After
revoke

Before
stream-deactivation-master

After
stream-deactivation

Before
subs-master

After
subs

@timabbott
Copy link
Sponsor Member

The z-link thing is covered in the last section of this page: https://zulip.readthedocs.io/en/latest/translating/internationalization.html#frontend-translations; any idea what we could do to make it more likely you'd have noticed it?

@timabbott
Copy link
Sponsor Member

@sahil839 are you up for doing a review / QA pass on this?

stream_name,
count: principals.length,
});
$("#stream-creation").append(invites_warning_modal);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Any reason for changing the parent element of this modal?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a comment here.

$("#do_revoke_invite_button").off("click");
$("#do_revoke_invite_button").on("click", do_revoke_invite);
const modal_parent = $("#admin_invites_table");
const html_body = render_settings_revoke_invite_modal(ctx);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Here also, why the modal parent is changed. And if there is a reason we want to use this, we can simply remove the #revoke_invite_modal_holder element.

@sahil839
Copy link
Collaborator

I tested it locally and it works fine.
I am not sure whether the changes in parent elements are required are not and not sure how we decide the parent elements, but most of those changes look fine. But we should remove the elements that were being used as parent before if they are not required now.
Will wait for other suggestions for this.

@aryanshridhar
Copy link
Member Author

aryanshridhar commented May 31, 2021

I guess its better if I modify the parent elements as they were earlier since they were specifically designed for it. Thoughts @sahil839.
It's also valid that we can remove unnecessary elements if the current changes looks good.

@sahil839
Copy link
Collaborator

sahil839 commented Jun 1, 2021

There is no problem with current changes as they look and behave in the same way, but am just not sure how these parent elements are/were decided.

@timabbott
Copy link
Sponsor Member

I think it's worth removing unnecessary elements. We probably mostly want a policy around parent elements for modals to make that not a thing we need to think about; possibly there should just be a single fixed parent element for all modals in the app, since I don't see why it'd matter what their parent is.

<p>
{{#tr}}
By deactivating <z-user></z-user>, they will be logged out immediately.
{{#*inline "z-user"}}<strong>{{username}}</strong> &lt;{{email}}&gt;{{/inline}}
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

You appear to have removes some of the HTML here for styling the username and email; why?

As a sidenote, it's really harmful to have hidden functional changes like this that are not explained clearly in the commit message; only the most watchful reviewer will notice, and it can lead to significant bugs/regressions.

(The last 3 commits all have this issue with either the content or heading).

Copy link
Member Author

Choose a reason for hiding this comment

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

Umm, Apologies if I am missing something out here @timabbott.
By "HTML here for styling", I guess you meant the CSS classes like - user_name and email ?
If that's the case, the classes like user_name and email are added so that later they can be populated with respective usernames and email.
Looking at the browser inspector, they don't seem to be really adding any styling for the same.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, this comment contains the before/after screenshots within it.

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Ahh, great; I think the key thing here is that it's really important to explain that sort of reasoning in the commit message, because it's not at all obvious that this is what those are for (though in retrospect it totally makes sense).

confirm_dialog.launch({
parent: modal_parent,
html_heading: $t_html(
{defaultMessage: "Archive stream {stream}"},
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

The stream name here seems to not have the styling it had previously.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe similar comment here as the above one ?

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="{{t 'Close' }}"><span aria-hidden="true">&times;</span></button>
<h3 id="deactivate_realm_modal_label">
{{t "Deactivate organization" }} <span class="realm_name"></span>
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Did this realm_name spam display the realm name before this change?

I'm not sure we need it here (we definitely want it in the modal somewhere), but we shouldn't be accidentally changing it in this commit.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, the realm_name span didn't actually contain the realm name.
It's just a empty span added to the modal heading. (Not sure on why was it exactly added!)

Here's the relevant screenshot of browser inspector:
browser-inspector

Copy link
Sponsor Member

Choose a reason for hiding this comment

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

OK, this would have been a key detail to explain in the commit message.

Can you start a #design thread with that screenshot about where we should put the identity of the organization to deactivate? I do think we probably want to display it somewhere in that modal.

@timabbott
Copy link
Sponsor Member

I merged the first several commits as the series ending with 68111d9. Thanks @aryanshridhar! There may be a second pass of work worth doing of reading the code surrounding these for things that don't make sense; e.g. with the revoke_invite_modal, we seem to have duplicate ways of storing which things we're in the process of trying to revoke, the meta fields and the .confirm_dialog_yes_button attributes.

I'd expect us to just store those values in the closure rather in the DOM, i.e. the on_click function can call do_remoke_invite(invite_id, is_multiuse) without either of these storage methods.

@aryanshridhar
Copy link
Member Author

Cool! Working on it

@aryanshridhar
Copy link
Member Author

but am just not sure how these parent elements are/were decided.

@sahil839, I decided these parent elements by using browser inspector and figuring out the parent element for the relevant modal.

@aryanshridhar
Copy link
Member Author

Can you review it again @timabbott ?

…dule.

The "email" span in the old modal was not used for styling, just to
support updating the field visually.
…ule.

The stream_name CSS class in the heading before this change had no
functional effect.
…ule.

The realm_name field in the old modal was always empty.
@timabbott timabbott merged commit 281c7da into zulip:master Jun 9, 2021
@timabbott
Copy link
Sponsor Member

Merged, after extending the commit messages to explain that the CSS class spans that were removed were not functional. Thanks @aryanshridhar!

I think we still have a couple modals that can be migrated:

I'll start a #frontend thread about this soon, but we have a goal of moving everything out of templates/zerver/app.

I think it could also be a good followup to move all the confirm_dialog templates to static/templates/confirm_dialog/, similar to the static/templates/navbar_alerts/ directory we recently added, just from a codebase organization standpoint. Want to work on that next?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants