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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

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
@@ -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 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 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. 😄

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: Test Ready 🧪
Development

Successfully merging this pull request may close these issues.

5 participants