-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
898e0b7
to
f862482
Compare
There was a problem hiding this 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"), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, fixed
attrVal.translation?.richText || | ||
attrVal.translation?.plainText || | ||
null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attrVal.translation?.richText || | |
attrVal.translation?.plainText || | |
null, | |
attrVal.translation?.richText || attrVal.translation?.plainText |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
translation: | ||
attrVal.translation?.richText || | ||
attrVal.translation?.plainText || | ||
null, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/translations/types.ts
Outdated
@@ -19,12 +19,14 @@ export enum PageTranslationInputFieldName { | |||
richText = "richText", | |||
} | |||
|
|||
export type TranslationFieldType = "short" | "long" | "rich"; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/
c50643c
src/translations/utils.ts
Outdated
type: TranslationFieldType, | ||
data: OutputData | string, | ||
): AttributeValueTranslationInput => | ||
type === "rich" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type === "rich" | |
type === TranslationFieldType.RICH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Fixed
@orzechdev Clicking on edit button is not working, when attributes do not have a translation yet. steps: Edit button not working, and you can see skeleton instead of |
0d20167
@szczecha fixed. |
It introduces in translation views (product, variant and page translation views) the following:
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
Pull Request Checklist
[data-test-id]
are added for new elementsTest 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.
CONTAINERS=1