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

Replace text angular editor with trix editor in About Us and Shopfront message fields #12734

Merged

Conversation

cillian
Copy link
Contributor

@cillian cillian commented Aug 2, 2024

What? Why?

The trix editor was added in #11140, this PR follows on from that and replaces the remaining instances of the text-angular editor.

What should we test?

  • Test the Trix editor is working for the following fields...
    • Enterprise Settings > About > About us
    • Enterprise Settings > Shop preferences > Shopfront message
    • Enterprise Settings > Shop preferences > Shopfront closed message
    • Enterprise Group Settings > About > About

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

Before

about-us-before

shop-messages-before

groups-about-us-before

After

about-us-after

shop-messages-after

groups-about-us-after

Note, in the above screenshots the trix fields are on new lines instead of being alongside the field label like they usually are. This is because there was a horizontal scrollbar if it was beside the field label, see:

shop-messages-after-with-horizontal-scollbar

I also added some wrapping to CSS to the trix editor button groups so they will automatically wrap and stop the horizontal scrollbar on smaller screens, although another solution might be to remove the whitespace to the right, see:

shop-messages-wrapping-after

@cillian cillian force-pushed the replace-text-angular-with-trix branch 2 times, most recently from b0567f7 to 837e187 Compare August 9, 2024 08:51
…ges and about fields for enterprises and enterprise groups
@cillian cillian force-pushed the replace-text-angular-with-trix branch from 837e187 to a6d3909 Compare August 9, 2024 09:37
@cillian cillian marked this pull request as ready for review August 9, 2024 09:44
app/models/enterprise.rb Outdated Show resolved Hide resolved
@@ -1,3 +1,7 @@
trix-toolbar .trix-button-row {
flex-wrap: wrap;
Copy link
Contributor Author

@cillian cillian Aug 9, 2024

Choose a reason for hiding this comment

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

Prevents horizontal scrollber on Trix button toolbar in smaller screens.

@rioug rioug self-requested a review August 12, 2024 01:16
@rioug rioug added the user facing changes Thes pull requests affect the user experience label Aug 12, 2024
Copy link
Collaborator

@rioug rioug left a comment

Choose a reason for hiding this comment

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

yeah less angular 🧹 ! Thanks @cillian 🙏

app/models/enterprise.rb Outdated Show resolved Hide resolved
Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great work, it looks much cleaner than before!
I like how you adapted to fit the extra Trix buttons in, and it means there's more space for the text area too.

I have a couple of comments that might be worth trying. Do they make sense?
If not, we can proceed as is.

app/models/enterprise.rb Outdated Show resolved Hide resolved
app/views/admin/enterprise_groups/_form_about.html.haml Outdated Show resolved Hide resolved
Comment on lines 3726 to 3752
trix:
attachFiles: "Attach Files"
bold: "Bold"
bullets: "Bullets"
byte: "Byte"
bytes: "Bytes"
captionPlaceholder: "Add a caption…"
code: "Code"
heading1: "Heading"
indent: "Increase Level"
italic: "Italic"
link: "Link"
numbers: "Numbers"
outdent: "Decrease Level"
quote: "Quote"
redo: "Redo"
remove: "Remove"
strike: "Strikethrough"
undo: "Undo"
unlink: "Unlink"
url: "URL"
urlPlaceholder: "Enter a URL…"
GB: "GB"
KB: "KB"
MB: "MB"
PB: "PB"
TB: "TB"
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding Trix translation keys.

These two old labels seem equivalent to new labels (I haven't checked though)

  • "Insert / edit link" -> "Link"
  • "Please enter a URL to insert" -> "Enter a URL…"

If so, I think it would help to use the old labels. That way, it will probably be easy for translators to copy the existing labels when adding translations for Trix. Does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, that's updated in 2d6ffc0 to use the old "Please enter a URL to insert" label.

The "Link" translation is used in two places at once so the "Insert / edit link" label is a bit more awkward, see...

link-translation

Comment on lines 62 to 85
Trix.config.lang[key] = translation;

// Set toolbar translations (Chrome)
this.#setTranslation(
`[data-trix-action="${this.#translationKeyToAttributeMappings(key)}"]`,
"title",
translation
);
this.#setTranslation(
`[data-trix-attribute="${this.#translationKeyToAttributeMappings(key)}"]`,
"title",
translation
);
}

// Set translations for link dialog (Chrome)
this.#setTranslation(`[data-trix-dialog="href"] input`,
"aria-label", I18n.t("js.trix.url"));
this.#setTranslation(`[data-trix-dialog="href"] input`,
"placeholder", I18n.t("js.trix.urlPlaceholder"));
this.#setTranslation('.trix-dialog--link input[data-trix-method="setAttribute"]',
"value", I18n.t("js.trix.link"));
this.#setTranslation('.trix-dialog--link input[data-trix-method="removeAttribute"]',
"value", I18n.t("js.trix.unlink"));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Trix.config.lang[key] = translation; only seems to work in Firefox for some reason. The translations have to be set more manually for Chrome.

Copy link
Member

Choose a reason for hiding this comment

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

That's interesting, and unfortunate because you have map quite a lot data.

According to this wiki, it suggests overwriting the lang config in one command.

Trix.config.lang = translation
https://github.com/basecamp/trix/wiki/I18n

But you tried that and it didn't work, so it would be worth raising an issue.
I had a look for issues and could only find one.
The final comment shows another method using Object.assign. I don't know if that would make a different, but perhaps it's worth trying.
basecamp/trix#874 (comment)

Copy link
Contributor Author

@cillian cillian Aug 23, 2024

Choose a reason for hiding this comment

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

Good find, fixed by 63c62ca and it works in Firefox and Chrome.

Comment on lines 2960 to 2977
trix:
bold: "Bold"
bullets: "Bullets"
code: "Code"
heading1: "Heading"
hr: "Horizontal rule"
indent: "Increase Level"
italic: "Italic"
link: "Link"
numbers: "Numbers"
outdent: "Decrease Level"
quote: "Quote"
redo: "Redo"
strike: "Strikethrough"
undo: "Undo"
unlink: "Unlink"
url: "URL"
urlPlaceholder: "Please enter a URL to insert"
Copy link
Member

Choose a reason for hiding this comment

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

Actually, these will already have the default loaded from en.yml

In general , we need to avoid changing any locale files other than the default, as described here:
https://github.com/openfoodfoundation/openfoodnetwork/wiki/Internationalisation-(i18n)#development

I have to admit, I don't know if this commit will be a problem or not, but I know it's not necessary so perhaps it's safest to remove it.

Comment on lines 62 to 85
Trix.config.lang[key] = translation;

// Set toolbar translations (Chrome)
this.#setTranslation(
`[data-trix-action="${this.#translationKeyToAttributeMappings(key)}"]`,
"title",
translation
);
this.#setTranslation(
`[data-trix-attribute="${this.#translationKeyToAttributeMappings(key)}"]`,
"title",
translation
);
}

// Set translations for link dialog (Chrome)
this.#setTranslation(`[data-trix-dialog="href"] input`,
"aria-label", I18n.t("js.trix.url"));
this.#setTranslation(`[data-trix-dialog="href"] input`,
"placeholder", I18n.t("js.trix.urlPlaceholder"));
this.#setTranslation('.trix-dialog--link input[data-trix-method="setAttribute"]',
"value", I18n.t("js.trix.link"));
this.#setTranslation('.trix-dialog--link input[data-trix-method="removeAttribute"]',
"value", I18n.t("js.trix.unlink"));
Copy link
Member

Choose a reason for hiding this comment

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

That's interesting, and unfortunate because you have map quite a lot data.

According to this wiki, it suggests overwriting the lang config in one command.

Trix.config.lang = translation
https://github.com/basecamp/trix/wiki/I18n

But you tried that and it didn't work, so it would be worth raising an issue.
I had a look for issues and could only find one.
The final comment shows another method using Object.assign. I don't know if that would make a different, but perhaps it's worth trying.
basecamp/trix#874 (comment)

Comment on lines 3328 to 3329
trix:
urlPlaceholder: "الرجاء إدخال عنوان URL لإدراجه"
Copy link
Member

Choose a reason for hiding this comment

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

Sorry I just meant to update it in en.yml. In general we should avoid changing other locale files directly. I'm unsure if adding new keys is a problem though.

Copy link
Member

Choose a reason for hiding this comment

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

@mkllnk can you help with a query here?
For convenience, Cillian has copied an existing translation to a new key (the existing translation was for angular editor, and there is an equivalent in the new trix editor). Do you know if it's ok, and if it's helpful to add new keys to the locale files?
Or should we remove this before merging?

Copy link
Member

Choose a reason for hiding this comment

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

We should remove this addition. Transifex will handle it. It recognises existing translations.

@dacook dacook requested a review from mkllnk August 20, 2024 01:46
Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Great work! Thank you.

We just need to revert he changes to the other locales. Otherwise this is great!

Comment on lines 1054 to 1055
shopfront_message_link_tooltip: "إدراج / تحرير الرابط"
shopfront_message_link_prompt: "الرجاء إدخال عنوان URL لإدراجه"
Copy link
Member

Choose a reason for hiding this comment

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

Please remove all changes to locales other than en.yml.

Copy link
Contributor Author

@cillian cillian Aug 23, 2024

Choose a reason for hiding this comment

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

👍 Fixed by dd51755 and 9895116

Comment on lines 3328 to 3329
trix:
urlPlaceholder: "الرجاء إدخال عنوان URL لإدراجه"
Copy link
Member

Choose a reason for hiding this comment

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

We should remove this addition. Transifex will handle it. It recognises existing translations.

@cillian
Copy link
Contributor Author

cillian commented Aug 23, 2024

Thanks. I have reverted those changes to non en locale files now and simplified how the Trix translations are set, let me know if you want me to squash the commits.

Copy link
Member

@dacook dacook left a comment

Choose a reason for hiding this comment

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

Great, all ready to test!

@drummer83
Copy link
Contributor

@cillian Github is saying there are changes requested. Could you please have a look? I assume it's been addressed already?

Copy link
Member

@mkllnk mkllnk left a comment

Choose a reason for hiding this comment

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

Github is saying there are changes requested.

Github was waiting for my review. But the other approvals should have been enough. Anyway, you get may approval, too. 😄

@drummer83 drummer83 self-assigned this Sep 21, 2024
@drummer83 drummer83 added the pr-staged-au staging.openfoodnetwork.org.au label Sep 27, 2024
@drummer83
Copy link
Contributor

Hi @cillian
Sorry, there's a conflict here. Could you please have a look?
Thanks!

@drummer83 drummer83 removed the pr-staged-au staging.openfoodnetwork.org.au label Sep 27, 2024
@drummer83 drummer83 removed their assignment Sep 27, 2024
@drummer83
Copy link
Contributor

For future testing I have documented the "before" state already.

  • Already existing Trix editor for White Label Custom Tab Content:
    image

  • Same on narrow screens (scroll bar and still truncated buttons):
    image

  • Old editor for Home and Shopfront Closed message with test content using all available options:
    image

  • What it looks like in the shopfront:
    image

@cillian
Copy link
Contributor Author

cillian commented Sep 27, 2024

Thanks @drummer83 I have fixed that conflict now.

For reference, it was this...

  # Remove any unsupported HTML.
<<<<<<< HEAD
  def long_description
    HtmlSanitizer.sanitize_and_enforce_link_target_blank(super)
  end

  # Remove any unsupported HTML.
=======
>>>>>>> master
  def long_description=(html)
    super(HtmlSanitizer.sanitize_and_enforce_link_target_blank(html))
  end

To fix it I removed the #long_description method like what was done in d061fe8 because the enforcing of target="_blank" will be added to links when assigning the long_description= attribute. Before this PR all links already had target="_blank" on them because that was the default behaviour of the old angular text editor.

@drummer83 drummer83 self-assigned this Sep 29, 2024
@drummer83 drummer83 added the pr-staged-au staging.openfoodnetwork.org.au label Sep 29, 2024
@drummer83
Copy link
Contributor

Hi @cillian,
Thanks for working on this one! Here are my test results after staging.

After staging the PR

  • Shopfront display remains unchanged.
  • Back office editor is updated and styling is adapted to newly available options (One header only, no underline, ...).
    grafik

After staging the PR and updating the content

  • Shopfront display is adapted to use newly available options.
    grafik
  • Behavior on narrow screens is much better now.
    grafik

I find it surprising to see, that it's enough to edit any of the content to have the new styles applied to all of the occurences. It's no problem, maybe even an advantage looking at consistency. I assume this happens because when clicking Update, all of the tabs are saved and not just the tab I'm looking at.

Summary

  • Styling changes in the shop front due to different styling options in the new editor.
  • This is not critical, because all information is still available.
  • Small screens are much better supported.
  • No problems found.

We can merge this one, but the branch is out of date and I can't rebase due to a conflict. I will move this to Ready To Go but add the feedback needed label to have someone else have a look at it. Maybe @filipefurtad0 or @sigmundpetersen could have a look? 🙏

Thanks again Cillian! 🚀

@drummer83 drummer83 added feedback-needed and removed pr-staged-au staging.openfoodnetwork.org.au labels Sep 29, 2024
@sigmundpetersen
Copy link
Contributor

Merging is blocked because reapproval is needed after Cillian resolved the last conflict.
Maybe @mkllnk or @rioug could have a quick look when coming back to work and merge if everything looks Ok 👍

@rioug rioug merged commit 91f2ca9 into openfoodfoundation:master Sep 29, 2024
55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
user facing changes Thes pull requests affect the user experience
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants