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

Add names of attributes translations #2433

Merged
merged 6 commits into from
Nov 4, 2022

Conversation

orzechdev
Copy link
Contributor

@orzechdev orzechdev commented Oct 20, 2022

It introduces in translation views (product, variant and page translation views) the following:

  • replaced numbers with names of attributes,
  • added the possibility to translate plain text attributes (not only rich text).

Fixes #2400.

Backend: saleor/saleor#11028

Example to test: https://2400-add-names-of-attributes-translations.dashboard.saleor.rocks/translations/EL/products/UHJvZHVjdDo3Mg%3D%3D

PR intended to be tested with API branch: add-attribute-field-to-AttributeValueTranslatableContent-type

Screenshots

Screenshot 2022-10-24 at 17 59 10

Pull Request Checklist

  1. This code contains UI changes
  2. All visible strings are translated with proper context including data-formatting
  3. Attributes [data-test-id] are added for new elements
  4. Changes are mentioned in the changelog
  5. The changes are tested in different browsers and in light/dark mode

Test environment config

API_URI=https://add-attribute-field-to-attributevaluetranslatablecontent-type.api.saleor.rocks/graphql/
MARKETPLACE_URL=https://apps.saleor.io
SALEOR_APPS_ENDPOINT=https://apps.saleor.io/api/saleor-apps

Do you want to run more stable tests?

To run all tests, just select the stable checkbox. To speed up tests, increase the number of containers. Tests will be re-run only when the "run e2e" label is added.

  1. stable
  2. giftCard
  3. category
  4. collection
  5. attribute
  6. productType
  7. shipping
  8. customer
  9. permissions
  10. menuNavigation
  11. pages
  12. sales
  13. vouchers
  14. homePage
  15. login
  16. orders
  17. products
  18. app
  19. plugins
  20. translations
  21. navigation
  22. variants

CONTAINERS=1

@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations October 20, 2022 13:16 Inactive
@github-actions github-actions bot temporarily deployed to storybook 2400-add-names-of-attributes-translations October 20, 2022 13:16 Inactive
@orzechdev orzechdev force-pushed the 2400-add-names-of-attributes-translations branch from 898e0b7 to f862482 Compare October 24, 2022 11:35
@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations October 24, 2022 11:35 Inactive
@github-actions github-actions bot temporarily deployed to storybook 2400-add-names-of-attributes-translations October 24, 2022 11:35 Inactive
@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations October 24, 2022 16:44 Inactive
@github-actions github-actions bot temporarily deployed to storybook 2400-add-names-of-attributes-translations October 24, 2022 16:44 Inactive
@orzechdev orzechdev requested review from a team, andrzejewsky and krzysztofzuraw and removed request for a team October 24, 2022 16:52
@orzechdev orzechdev marked this pull request as ready for review October 24, 2022 16:55
Copy link
Member

@andrzejewsky andrzejewsky left a comment

Choose a reason for hiding this comment

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

Please try to avoid "as" assertions, if you cannot, please create a function with that but with returning expected type

null,
type: attrVal.richText
? ("rich" as "rich")
: ("short" as "short"),
Copy link
Member

Choose a reason for hiding this comment

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

Could you properly type this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, fixed

@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations October 25, 2022 13:30 Inactive
@github-actions github-actions bot temporarily deployed to storybook 2400-add-names-of-attributes-translations October 25, 2022 13:30 Inactive
krzysztofzuraw
krzysztofzuraw previously approved these changes Oct 27, 2022
andrzejewsky
andrzejewsky previously approved these changes Oct 27, 2022
Comment on lines 135 to 137
attrVal.translation?.richText ||
attrVal.translation?.plainText ||
null,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
attrVal.translation?.richText ||
attrVal.translation?.plainText ||
null,
attrVal.translation?.richText || attrVal.translation?.plainText

Copy link
Member

Choose a reason for hiding this comment

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

i think there is no need for additional null cast, but please double check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is, I checked it and it's not needed.

Comment on lines 180 to 183
translation:
attrVal.translation?.richText ||
attrVal.translation?.plainText ||
null,
Copy link
Member

Choose a reason for hiding this comment

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

so, you repeat the same logic, a function perhaps, and reuse it?

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, I added a function for it.

@@ -19,12 +19,14 @@ export enum PageTranslationInputFieldName {
richText = "richText",
}

export type TranslationFieldType = "short" | "long" | "rich";
Copy link
Member

Choose a reason for hiding this comment

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

for comparisons (because you do them later) perhaps is better to have enums (but we don't use them), so a constant object?

const TranslationFieldType = {
  SHORT: 'short',
  LONG: 'long',
  RICH: 'rich'
} as const

Copy link
Member

Choose a reason for hiding this comment

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

then type === TranslationFieldType.RICH, and values type: typeof Object.values(TranslationFieldType)

Copy link
Contributor Author

@orzechdev orzechdev Nov 2, 2022

Choose a reason for hiding this comment

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

Sure, might be better with constant object, I've changed it to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for further reference, there was discussion few months ago, about enums that we would prefer string literals and constant object with strings as you proposed in your comment. Enums have some drawbacks, may not be really type-safe, introduce excessive code into bundle size or require importing them in every moment we use them https://fettblog.eu/tidy-typescript-avoid-enums/

@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations November 2, 2022 13:28 Inactive
@github-actions github-actions bot temporarily deployed to storybook 2400-add-names-of-attributes-translations November 2, 2022 13:28 Inactive
type: TranslationFieldType,
data: OutputData | string,
): AttributeValueTranslationInput =>
type === "rich"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
type === "rich"
type === TranslationFieldType.RICH

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Fixed

@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations November 2, 2022 14:18 Inactive
@github-actions github-actions bot temporarily deployed to storybook 2400-add-names-of-attributes-translations November 2, 2022 14:18 Inactive
@orzechdev orzechdev added the bug Something isn't working label Nov 2, 2022
andrzejewsky
andrzejewsky previously approved these changes Nov 3, 2022
krzysztofzuraw
krzysztofzuraw previously approved these changes Nov 3, 2022
@szczecha
Copy link
Member

szczecha commented Nov 3, 2022

@orzechdev Clicking on edit button is not working, when attributes do not have a translation yet.

steps:
Open the link to the translation provided in this PR https://2400-add-names-of-attributes-translations.dashboard.saleor.rocks/translations/EL/products/UHJvZHVjdDo3Mg%3D%3D
Change language
Try to edit translations for attributes
image

Edit button not working, and you can see skeleton instead of No translation yet text

@orzechdev
Copy link
Contributor Author

@szczecha fixed.
@andrzejewsky There is a component TranslationFields which expects explicitly only undefined to show skeleton. Rich text although displays skeleton based on disabled, but other fields not. So I left null explicitly in translation: attrVal.translation?.richText || attrVal.translation?.plainText || null, to leave skeleton working as it was before.

@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations November 3, 2022 14:53 Inactive
@github-actions github-actions bot had a problem deploying to storybook 2400-add-names-of-attributes-translations November 3, 2022 14:53 Failure
@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations November 3, 2022 15:30 Inactive
@github-actions github-actions bot temporarily deployed to storybook 2400-add-names-of-attributes-translations November 3, 2022 15:30 Inactive
@orzechdev orzechdev merged commit 7963836 into main Nov 4, 2022
@orzechdev orzechdev deleted the 2400-add-names-of-attributes-translations branch November 4, 2022 10:11
orzechdev added a commit that referenced this pull request Nov 4, 2022
orzechdev added a commit that referenced this pull request Nov 7, 2022
@orzechdev orzechdev restored the 2400-add-names-of-attributes-translations branch November 7, 2022 12:21
@github-actions github-actions bot temporarily deployed to 2400-add-names-of-attributes-translations November 15, 2022 16:00 Inactive
@github-actions github-actions bot temporarily deployed to storybook 2400-add-names-of-attributes-translations November 15, 2022 16:00 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Product attributes in translations should be named
4 participants