From 7fd2eb2a2ccdf7164bf404a58f03e1505e4c1ec7 Mon Sep 17 00:00:00 2001 From: Dawid Date: Mon, 7 Nov 2022 13:20:58 +0100 Subject: [PATCH] Revert "Add names of attributes translations (#2433)" (#2531) This reverts commit 796383637c2ebb3177764e926821b455917d999f. --- introspection.json | 16 --- locale/defaultMessages.json | 8 +- schema.graphql | 3 - src/fragments/translations.ts | 98 +++++++++++------ src/graphql/hooks.generated.ts | 102 ++++++++++++------ src/graphql/typePolicies.generated.ts | 3 +- src/graphql/types.generated.ts | 28 ++--- .../TranslationFields/TranslationFields.tsx | 13 +-- .../TranslationsPagesPage.tsx | 32 ++++-- .../TranslationsProductVariantsPage.tsx | 26 +++-- .../TranslationsProductsPage.tsx | 32 ++++-- src/translations/types.ts | 10 +- src/translations/utils.ts | 42 +------- src/translations/views/TranslationsPages.tsx | 11 +- .../views/TranslationsProductVariants.tsx | 11 +- .../views/TranslationsProducts.tsx | 11 +- 16 files changed, 241 insertions(+), 205 deletions(-) diff --git a/introspection.json b/introspection.json index b1de3ccf5..ad30f825e 100644 --- a/introspection.json +++ b/introspection.json @@ -9357,22 +9357,6 @@ "isDeprecated": false, "deprecationReason": null }, - { - "name": "attribute", - "description": "Represents a value of an attribute.", - "args": [], - "type": { - "kind": "NON_NULL", - "name": null, - "ofType": { - "kind": "OBJECT", - "name": "AttributeTranslatableContent", - "ofType": null - } - }, - "isDeprecated": false, - "deprecationReason": null - }, { "name": "attributeValue", "description": "Represents a value of an attribute.", diff --git a/locale/defaultMessages.json b/locale/defaultMessages.json index 087ffeb75..4f531fa4a 100644 --- a/locale/defaultMessages.json +++ b/locale/defaultMessages.json @@ -3460,6 +3460,10 @@ "context": "window title", "string": "Create Product" }, + "PajjqE": { + "context": "attribute list", + "string": "Attribute {number}" + }, "PbQJY5": { "context": "section header", "string": "Saleor Apps" @@ -7878,10 +7882,6 @@ "context": "attribute type", "string": "Content Attribute" }, - "zgqPGF": { - "context": "attribute list", - "string": "Attribute {name}" - }, "zjHH6b": { "context": "sale start date", "string": "Started" diff --git a/schema.graphql b/schema.graphql index 67ec9bf52..83bc9a454 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1881,9 +1881,6 @@ type AttributeValueTranslatableContent implements Node { languageCode: LanguageCodeEnum! ): AttributeValueTranslation - """Represents an attribute.""" - attribute: Attribute! - """Represents a value of an attribute.""" attributeValue: AttributeValue @deprecated(reason: "This field will be removed in Saleor 4.0. Get model fields from the root level queries.") } diff --git a/src/fragments/translations.ts b/src/fragments/translations.ts index 8762dd3b8..f92eeb539 100644 --- a/src/fragments/translations.ts +++ b/src/fragments/translations.ts @@ -1,31 +1,5 @@ import { gql } from "@apollo/client"; -export const attributeValueTranslatableFragment = gql` - fragment AttributeValueTranslatable on AttributeValueTranslatableContent { - id - name - plainText - richText - attributeValue { - id - } - attribute { - id - name - } - translation(languageCode: $language) { - id - name - plainText - richText - language { - code - language - } - } - } -`; - export const categoryTranslationFragment = gql` fragment CategoryTranslation on CategoryTranslatableContent { translation(languageCode: $language) { @@ -90,7 +64,21 @@ export const productTranslationFragment = gql` } } attributeValues { - ...AttributeValueTranslatable + id + name + richText + attributeValue { + id + } + translation(languageCode: $language) { + id + name + richText + language { + code + language + } + } } } `; @@ -110,7 +98,21 @@ export const productVariantTranslationFragment = gql` } } attributeValues { - ...AttributeValueTranslatable + id + name + richText + attributeValue { + id + } + translation(languageCode: $language) { + id + name + richText + language { + code + language + } + } } } `; @@ -189,7 +191,21 @@ export const pageTranslationFragment = gql` } } attributeValues { - ...AttributeValueTranslatable + id + name + richText + attributeValue { + id + } + translation(languageCode: $language) { + id + name + richText + language { + code + language + } + } } } `; @@ -224,13 +240,11 @@ export const attributeChoicesTranslationFragment = gql` node { id name - plainText richText inputType translation(languageCode: $language) { id name - plainText richText } } @@ -277,6 +291,28 @@ export const attributeTranslationDetailsFragment = gql` } `; +export const attributeValueTranslatableContentFragment = gql` + fragment AttributeValueTranslatableContent on AttributeTranslatableContent { + translation(languageCode: $language) { + id + name + } + attribute { + id + name + inputType + choices( + first: $firstValues + after: $afterValues + last: $lastValues + before: $beforeValues + ) { + ...AttributeChoicesTranslation + } + } + } +`; + export const menuItemTranslationFragment = gql` fragment MenuItemTranslation on MenuItemTranslatableContent { translation(languageCode: $language) { diff --git a/src/graphql/hooks.generated.ts b/src/graphql/hooks.generated.ts index 217db68ab..a9965cc86 100644 --- a/src/graphql/hooks.generated.ts +++ b/src/graphql/hooks.generated.ts @@ -2437,31 +2437,6 @@ export const CollectionTranslationFragmentDoc = gql` } } `; -export const AttributeValueTranslatableFragmentDoc = gql` - fragment AttributeValueTranslatable on AttributeValueTranslatableContent { - id - name - plainText - richText - attributeValue { - id - } - attribute { - id - name - } - translation(languageCode: $language) { - id - name - plainText - richText - language { - code - language - } - } -} - `; export const ProductTranslationFragmentDoc = gql` fragment ProductTranslation on ProductTranslatableContent { product { @@ -2483,10 +2458,24 @@ export const ProductTranslationFragmentDoc = gql` } } attributeValues { - ...AttributeValueTranslatable + id + name + richText + attributeValue { + id + } + translation(languageCode: $language) { + id + name + richText + language { + code + language + } + } } } - ${AttributeValueTranslatableFragmentDoc}`; + `; export const ProductVariantTranslationFragmentDoc = gql` fragment ProductVariantTranslation on ProductVariantTranslatableContent { productVariant { @@ -2502,10 +2491,24 @@ export const ProductVariantTranslationFragmentDoc = gql` } } attributeValues { - ...AttributeValueTranslatable + id + name + richText + attributeValue { + id + } + translation(languageCode: $language) { + id + name + richText + language { + code + language + } + } } } - ${AttributeValueTranslatableFragmentDoc}`; + `; export const SaleTranslationFragmentDoc = gql` fragment SaleTranslation on SaleTranslatableContent { sale { @@ -2579,10 +2582,24 @@ export const PageTranslationFragmentDoc = gql` } } attributeValues { - ...AttributeValueTranslatable + id + name + richText + attributeValue { + id + } + translation(languageCode: $language) { + id + name + richText + language { + code + language + } + } } } - ${AttributeValueTranslatableFragmentDoc}`; + `; export const PageTranslatableFragmentDoc = gql` fragment PageTranslatable on PageTranslatableContent { id @@ -2628,13 +2645,11 @@ export const AttributeChoicesTranslationFragmentDoc = gql` node { id name - plainText richText inputType translation(languageCode: $language) { id name - plainText richText } } @@ -2663,6 +2678,27 @@ export const AttributeTranslationDetailsFragmentDoc = gql` } } ${AttributeChoicesTranslationFragmentDoc}`; +export const AttributeValueTranslatableContentFragmentDoc = gql` + fragment AttributeValueTranslatableContent on AttributeTranslatableContent { + translation(languageCode: $language) { + id + name + } + attribute { + id + name + inputType + choices( + first: $firstValues + after: $afterValues + last: $lastValues + before: $beforeValues + ) { + ...AttributeChoicesTranslation + } + } +} + ${AttributeChoicesTranslationFragmentDoc}`; export const MenuItemTranslationFragmentDoc = gql` fragment MenuItemTranslation on MenuItemTranslatableContent { translation(languageCode: $language) { diff --git a/src/graphql/typePolicies.generated.ts b/src/graphql/typePolicies.generated.ts index caee37889..a99063aa4 100644 --- a/src/graphql/typePolicies.generated.ts +++ b/src/graphql/typePolicies.generated.ts @@ -549,14 +549,13 @@ export type AttributeValueDeletedFieldPolicy = { recipient?: FieldPolicy | FieldReadFunction, attributeValue?: FieldPolicy | FieldReadFunction }; -export type AttributeValueTranslatableContentKeySpecifier = ('id' | 'name' | 'richText' | 'plainText' | 'translation' | 'attribute' | 'attributeValue' | AttributeValueTranslatableContentKeySpecifier)[]; +export type AttributeValueTranslatableContentKeySpecifier = ('id' | 'name' | 'richText' | 'plainText' | 'translation' | 'attributeValue' | AttributeValueTranslatableContentKeySpecifier)[]; export type AttributeValueTranslatableContentFieldPolicy = { id?: FieldPolicy | FieldReadFunction, name?: FieldPolicy | FieldReadFunction, richText?: FieldPolicy | FieldReadFunction, plainText?: FieldPolicy | FieldReadFunction, translation?: FieldPolicy | FieldReadFunction, - attribute?: FieldPolicy | FieldReadFunction, attributeValue?: FieldPolicy | FieldReadFunction }; export type AttributeValueTranslateKeySpecifier = ('translationErrors' | 'errors' | 'attributeValue' | AttributeValueTranslateKeySpecifier)[]; diff --git a/src/graphql/types.generated.ts b/src/graphql/types.generated.ts index 4d956befd..805a134fe 100644 --- a/src/graphql/types.generated.ts +++ b/src/graphql/types.generated.ts @@ -7215,15 +7215,13 @@ export type TaxTypeFragment = { __typename: 'TaxType', description: string | nul export type TimePeriodFragment = { __typename: 'TimePeriod', amount: number, type: TimePeriodTypeEnum }; -export type AttributeValueTranslatableFragment = { __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }; - export type CategoryTranslationFragment = { __typename: 'CategoryTranslatableContent', translation: { __typename: 'CategoryTranslation', id: string, description: any | null, name: string | null, seoDescription: string | null, seoTitle: string | null, language: { __typename: 'LanguageDisplay', language: string } } | null, category: { __typename: 'Category', id: string, name: string, description: any | null, seoDescription: string | null, seoTitle: string | null } | null }; export type CollectionTranslationFragment = { __typename: 'CollectionTranslatableContent', collection: { __typename: 'Collection', id: string, name: string, description: any | null, seoDescription: string | null, seoTitle: string | null } | null, translation: { __typename: 'CollectionTranslation', id: string, description: any | null, name: string | null, seoDescription: string | null, seoTitle: string | null, language: { __typename: 'LanguageDisplay', language: string } } | null }; -export type ProductTranslationFragment = { __typename: 'ProductTranslatableContent', product: { __typename: 'Product', id: string, name: string, description: any | null, seoDescription: string | null, seoTitle: string | null } | null, translation: { __typename: 'ProductTranslation', id: string, seoTitle: string | null, seoDescription: string | null, name: string | null, description: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> }; +export type ProductTranslationFragment = { __typename: 'ProductTranslatableContent', product: { __typename: 'Product', id: string, name: string, description: any | null, seoDescription: string | null, seoTitle: string | null } | null, translation: { __typename: 'ProductTranslation', id: string, seoTitle: string | null, seoDescription: string | null, name: string | null, description: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> }; -export type ProductVariantTranslationFragment = { __typename: 'ProductVariantTranslatableContent', name: string, productVariant: { __typename: 'ProductVariant', id: string } | null, translation: { __typename: 'ProductVariantTranslation', id: string, name: string, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> }; +export type ProductVariantTranslationFragment = { __typename: 'ProductVariantTranslatableContent', name: string, productVariant: { __typename: 'ProductVariant', id: string } | null, translation: { __typename: 'ProductVariantTranslation', id: string, name: string, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> }; export type SaleTranslationFragment = { __typename: 'SaleTranslatableContent', sale: { __typename: 'Sale', id: string, name: string } | null, translation: { __typename: 'SaleTranslation', id: string, name: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }; @@ -7231,15 +7229,17 @@ export type VoucherTranslationFragment = { __typename: 'VoucherTranslatableConte export type ShippingMethodTranslationFragment = { __typename: 'ShippingMethodTranslatableContent', id: string, name: string, description: any | null, shippingMethod: { __typename: 'ShippingMethodType', id: string } | null, translation: { __typename: 'ShippingMethodTranslation', id: string, name: string | null, description: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }; -export type PageTranslationFragment = { __typename: 'PageTranslatableContent', page: { __typename: 'Page', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string } | null, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> }; +export type PageTranslationFragment = { __typename: 'PageTranslatableContent', page: { __typename: 'Page', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string } | null, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> }; export type PageTranslatableFragment = { __typename: 'PageTranslatableContent', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }; -export type AttributeChoicesTranslationFragment = { __typename: 'AttributeValueCountableConnection', pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null }, edges: Array<{ __typename: 'AttributeValueCountableEdge', cursor: string, node: { __typename: 'AttributeValue', id: string, name: string | null, plainText: string | null, richText: any | null, inputType: AttributeInputTypeEnum | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null } | null } }> }; +export type AttributeChoicesTranslationFragment = { __typename: 'AttributeValueCountableConnection', pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null }, edges: Array<{ __typename: 'AttributeValueCountableEdge', cursor: string, node: { __typename: 'AttributeValue', id: string, name: string | null, richText: any | null, inputType: AttributeInputTypeEnum | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null } | null } }> }; export type AttributeTranslationFragment = { __typename: 'AttributeTranslatableContent', id: string, name: string, translation: { __typename: 'AttributeTranslation', id: string, name: string } | null, attribute: { __typename: 'Attribute', id: string, name: string | null, inputType: AttributeInputTypeEnum | null } | null }; -export type AttributeTranslationDetailsFragment = { __typename: 'AttributeTranslatableContent', translation: { __typename: 'AttributeTranslation', id: string, name: string } | null, attribute: { __typename: 'Attribute', id: string, name: string | null, inputType: AttributeInputTypeEnum | null, withChoices: boolean, choices: { __typename: 'AttributeValueCountableConnection', pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null }, edges: Array<{ __typename: 'AttributeValueCountableEdge', cursor: string, node: { __typename: 'AttributeValue', id: string, name: string | null, plainText: string | null, richText: any | null, inputType: AttributeInputTypeEnum | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null } | null } }> } | null } | null }; +export type AttributeTranslationDetailsFragment = { __typename: 'AttributeTranslatableContent', translation: { __typename: 'AttributeTranslation', id: string, name: string } | null, attribute: { __typename: 'Attribute', id: string, name: string | null, inputType: AttributeInputTypeEnum | null, withChoices: boolean, choices: { __typename: 'AttributeValueCountableConnection', pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null }, edges: Array<{ __typename: 'AttributeValueCountableEdge', cursor: string, node: { __typename: 'AttributeValue', id: string, name: string | null, richText: any | null, inputType: AttributeInputTypeEnum | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null } | null } }> } | null } | null }; + +export type AttributeValueTranslatableContentFragment = { __typename: 'AttributeTranslatableContent', translation: { __typename: 'AttributeTranslation', id: string, name: string } | null, attribute: { __typename: 'Attribute', id: string, name: string | null, inputType: AttributeInputTypeEnum | null, choices: { __typename: 'AttributeValueCountableConnection', pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null }, edges: Array<{ __typename: 'AttributeValueCountableEdge', cursor: string, node: { __typename: 'AttributeValue', id: string, name: string | null, richText: any | null, inputType: AttributeInputTypeEnum | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null } | null } }> } | null } | null }; export type MenuItemTranslationFragment = { __typename: 'MenuItemTranslatableContent', translation: { __typename: 'MenuItemTranslation', id: string, name: string, language: { __typename: 'LanguageDisplay', language: string } } | null, menuItem: { __typename: 'MenuItem', id: string, name: string } | null }; @@ -8836,7 +8836,7 @@ export type UpdatePageTranslationsMutationVariables = Exact<{ }>; -export type UpdatePageTranslationsMutation = { __typename: 'Mutation', pageTranslate: { __typename: 'PageTranslate', errors: Array<{ __typename: 'TranslationError', code: TranslationErrorCode, field: string | null, message: string | null }>, page: { __typename: 'PageTranslatableContent', page: { __typename: 'Page', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string } | null, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | null } | null }; +export type UpdatePageTranslationsMutation = { __typename: 'Mutation', pageTranslate: { __typename: 'PageTranslate', errors: Array<{ __typename: 'TranslationError', code: TranslationErrorCode, field: string | null, message: string | null }>, page: { __typename: 'PageTranslatableContent', page: { __typename: 'Page', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string } | null, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | null } | null }; export type UpdateVoucherTranslationsMutationVariables = Exact<{ id: Scalars['ID']; @@ -8923,7 +8923,7 @@ export type ProductTranslationsQueryVariables = Exact<{ }>; -export type ProductTranslationsQuery = { __typename: 'Query', translations: { __typename: 'TranslatableItemConnection', edges: Array<{ __typename: 'TranslatableItemEdge', node: { __typename: 'ProductTranslatableContent', product: { __typename: 'Product', id: string, name: string, description: any | null, seoDescription: string | null, seoTitle: string | null } | null, translation: { __typename: 'ProductTranslation', id: string, seoTitle: string | null, seoDescription: string | null, name: string | null, description: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent' } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } }>, pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null } } | null }; +export type ProductTranslationsQuery = { __typename: 'Query', translations: { __typename: 'TranslatableItemConnection', edges: Array<{ __typename: 'TranslatableItemEdge', node: { __typename: 'ProductTranslatableContent', product: { __typename: 'Product', id: string, name: string, description: any | null, seoDescription: string | null, seoTitle: string | null } | null, translation: { __typename: 'ProductTranslation', id: string, seoTitle: string | null, seoDescription: string | null, name: string | null, description: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent' } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } }>, pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null } } | null }; export type PageTranslationsQueryVariables = Exact<{ language: LanguageCodeEnum; @@ -8934,7 +8934,7 @@ export type PageTranslationsQueryVariables = Exact<{ }>; -export type PageTranslationsQuery = { __typename: 'Query', translations: { __typename: 'TranslatableItemConnection', edges: Array<{ __typename: 'TranslatableItemEdge', node: { __typename: 'ProductTranslatableContent' } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent', page: { __typename: 'Page', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string } | null, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } }>, pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null } } | null }; +export type PageTranslationsQuery = { __typename: 'Query', translations: { __typename: 'TranslatableItemConnection', edges: Array<{ __typename: 'TranslatableItemEdge', node: { __typename: 'ProductTranslatableContent' } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent', page: { __typename: 'Page', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string } | null, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } }>, pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null } } | null }; export type VoucherTranslationsQueryVariables = Exact<{ language: LanguageCodeEnum; @@ -8997,7 +8997,7 @@ export type ProductTranslationDetailsQueryVariables = Exact<{ }>; -export type ProductTranslationDetailsQuery = { __typename: 'Query', translation: { __typename: 'ProductTranslatableContent', product: { __typename: 'Product', id: string, name: string, description: any | null, seoDescription: string | null, seoTitle: string | null } | null, translation: { __typename: 'ProductTranslation', id: string, seoTitle: string | null, seoDescription: string | null, name: string | null, description: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent' } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } | null }; +export type ProductTranslationDetailsQuery = { __typename: 'Query', translation: { __typename: 'ProductTranslatableContent', product: { __typename: 'Product', id: string, name: string, description: any | null, seoDescription: string | null, seoTitle: string | null } | null, translation: { __typename: 'ProductTranslation', id: string, seoTitle: string | null, seoDescription: string | null, name: string | null, description: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent' } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } | null }; export type ProductVariantListQueryVariables = Exact<{ id: Scalars['ID']; @@ -9012,7 +9012,7 @@ export type ProductVariantTranslationDetailsQueryVariables = Exact<{ }>; -export type ProductVariantTranslationDetailsQuery = { __typename: 'Query', translation: { __typename: 'ProductTranslatableContent' } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent', name: string, productVariant: { __typename: 'ProductVariant', id: string } | null, translation: { __typename: 'ProductVariantTranslation', id: string, name: string, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'PageTranslatableContent' } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } | null }; +export type ProductVariantTranslationDetailsQuery = { __typename: 'Query', translation: { __typename: 'ProductTranslatableContent' } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent', name: string, productVariant: { __typename: 'ProductVariant', id: string } | null, translation: { __typename: 'ProductVariantTranslation', id: string, name: string, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'PageTranslatableContent' } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } | null }; export type CategoryTranslationDetailsQueryVariables = Exact<{ id: Scalars['ID']; @@ -9036,7 +9036,7 @@ export type PageTranslationDetailsQueryVariables = Exact<{ }>; -export type PageTranslationDetailsQuery = { __typename: 'Query', translation: { __typename: 'ProductTranslatableContent' } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent', page: { __typename: 'Page', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string } | null, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, plainText: string | null, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, attribute: { __typename: 'AttributeTranslatableContent', id: string, name: string }, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } | null }; +export type PageTranslationDetailsQuery = { __typename: 'Query', translation: { __typename: 'ProductTranslatableContent' } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent' } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent', page: { __typename: 'Page', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string } | null, translation: { __typename: 'PageTranslation', id: string, content: any | null, seoDescription: string | null, seoTitle: string | null, title: string | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null, attributeValues: Array<{ __typename: 'AttributeValueTranslatableContent', id: string, name: string, richText: any | null, attributeValue: { __typename: 'AttributeValue', id: string } | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null, language: { __typename: 'LanguageDisplay', code: LanguageCodeEnum, language: string } } | null }> } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } | null }; export type SaleTranslationDetailsQueryVariables = Exact<{ id: Scalars['ID']; @@ -9064,7 +9064,7 @@ export type AttributeTranslationDetailsQueryVariables = Exact<{ }>; -export type AttributeTranslationDetailsQuery = { __typename: 'Query', translation: { __typename: 'ProductTranslatableContent' } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent', translation: { __typename: 'AttributeTranslation', id: string, name: string } | null, attribute: { __typename: 'Attribute', id: string, name: string | null, inputType: AttributeInputTypeEnum | null, withChoices: boolean, choices: { __typename: 'AttributeValueCountableConnection', pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null }, edges: Array<{ __typename: 'AttributeValueCountableEdge', cursor: string, node: { __typename: 'AttributeValue', id: string, name: string | null, plainText: string | null, richText: any | null, inputType: AttributeInputTypeEnum | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, plainText: string | null, richText: any | null } | null } }> } | null } | null } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent' } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } | null }; +export type AttributeTranslationDetailsQuery = { __typename: 'Query', translation: { __typename: 'ProductTranslatableContent' } | { __typename: 'CollectionTranslatableContent' } | { __typename: 'CategoryTranslatableContent' } | { __typename: 'AttributeTranslatableContent', translation: { __typename: 'AttributeTranslation', id: string, name: string } | null, attribute: { __typename: 'Attribute', id: string, name: string | null, inputType: AttributeInputTypeEnum | null, withChoices: boolean, choices: { __typename: 'AttributeValueCountableConnection', pageInfo: { __typename: 'PageInfo', endCursor: string | null, hasNextPage: boolean, hasPreviousPage: boolean, startCursor: string | null }, edges: Array<{ __typename: 'AttributeValueCountableEdge', cursor: string, node: { __typename: 'AttributeValue', id: string, name: string | null, richText: any | null, inputType: AttributeInputTypeEnum | null, translation: { __typename: 'AttributeValueTranslation', id: string, name: string, richText: any | null } | null } }> } | null } | null } | { __typename: 'AttributeValueTranslatableContent' } | { __typename: 'ProductVariantTranslatableContent' } | { __typename: 'PageTranslatableContent' } | { __typename: 'ShippingMethodTranslatableContent' } | { __typename: 'SaleTranslatableContent' } | { __typename: 'VoucherTranslatableContent' } | { __typename: 'MenuItemTranslatableContent' } | null }; export type ShippingMethodTranslationDetailsQueryVariables = Exact<{ id: Scalars['ID']; diff --git a/src/translations/components/TranslationFields/TranslationFields.tsx b/src/translations/components/TranslationFields/TranslationFields.tsx index 2b99f7845..9a219400a 100644 --- a/src/translations/components/TranslationFields/TranslationFields.tsx +++ b/src/translations/components/TranslationFields/TranslationFields.tsx @@ -14,10 +14,7 @@ import { IconButton, makeStyles, } from "@saleor/macaw-ui"; -import { - TranslationField, - TranslationFieldType, -} from "@saleor/translations/types"; +import { TranslationField } from "@saleor/translations/types"; import { ListProps } from "@saleor/types"; import classNames from "classnames"; import React from "react"; @@ -181,7 +178,7 @@ const TranslationFields: React.FC = props => {
{field && field.value !== undefined ? ( - field.type === TranslationFieldType.SHORT ? ( + field.type === "short" ? ( = props => { onDiscard={onDiscard} onSubmit={undefined} /> - ) : field.type === TranslationFieldType.LONG ? ( + ) : field.type === "long" ? ( = props => {
{field && field.translation !== undefined ? ( - field.type === TranslationFieldType.SHORT ? ( + field.type === "short" ? ( = props => { onDiscard={onDiscard} onSubmit={data => onSubmit(field, data)} /> - ) : field.type === TranslationFieldType.LONG ? ( + ) : field.type === "long" ? ( = ({ }), name: PageTranslationInputFieldName.title, translation: data?.translation?.title || null, - type: "short", + type: "short" as "short", value: data?.page?.title, }, { @@ -96,7 +95,7 @@ const TranslationsPagesPage: React.FC = ({ }), name: PageTranslationInputFieldName.content, translation: data?.translation?.content || null, - type: "rich", + type: "rich" as "rich", value: data?.page?.content, }, ]} @@ -124,7 +123,7 @@ const TranslationsPagesPage: React.FC = ({ }), name: PageTranslationInputFieldName.seoTitle, translation: data?.translation?.seoTitle || null, - type: "short", + type: "short" as "short", value: data?.page?.seoTitle, }, { @@ -134,7 +133,7 @@ const TranslationsPagesPage: React.FC = ({ }), name: PageTranslationInputFieldName.seoDescription, translation: data?.translation?.seoDescription || null, - type: "long", + type: "long" as "long", value: data?.page?.seoDescription, }, ]} @@ -152,10 +151,25 @@ const TranslationsPagesPage: React.FC = ({ disabled={disabled} initialState={true} title={intl.formatMessage(commonMessages.translationAttributes)} - fields={mapAttributeValuesToTranslationFields( - data.attributeValues, - intl, - )} + fields={ + data.attributeValues.map((attrVal, i) => ({ + id: attrVal.attributeValue.id, + displayName: intl.formatMessage( + { + id: "PajjqE", + defaultMessage: "Attribute {number}", + description: "attribute list", + }, + { + number: i + 1, + }, + ), + name: attrVal?.name, + translation: attrVal?.translation?.richText || null, + type: "rich" as "rich", + value: attrVal?.richText, + })) || [] + } saveButtonState={saveButtonState} richTextResetKey={languageCode} onEdit={onEdit} diff --git a/src/translations/components/TranslationsProductVariantsPage/TranslationsProductVariantsPage.tsx b/src/translations/components/TranslationsProductVariantsPage/TranslationsProductVariantsPage.tsx index a742af5d8..9f57aad4d 100644 --- a/src/translations/components/TranslationsProductVariantsPage/TranslationsProductVariantsPage.tsx +++ b/src/translations/components/TranslationsProductVariantsPage/TranslationsProductVariantsPage.tsx @@ -18,7 +18,6 @@ import { productVariantUrl, TranslatableEntities, } from "@saleor/translations/urls"; -import { mapAttributeValuesToTranslationFields } from "@saleor/translations/utils"; import React from "react"; import { useIntl } from "react-intl"; @@ -99,7 +98,7 @@ const TranslationsProductsPage: React.FC = ({ }), name: TranslationInputFieldName.name, translation: data?.translation?.name || null, - type: "short", + type: "short" as "short", value: data?.name, }, ]} @@ -117,10 +116,25 @@ const TranslationsProductsPage: React.FC = ({ disabled={disabled} initialState={true} title={intl.formatMessage(commonMessages.translationAttributes)} - fields={mapAttributeValuesToTranslationFields( - data.attributeValues, - intl, - )} + fields={ + data.attributeValues.map((attrVal, i) => ({ + id: attrVal.attributeValue.id, + displayName: intl.formatMessage( + { + id: "PajjqE", + defaultMessage: "Attribute {number}", + description: "attribute list", + }, + { + number: i + 1, + }, + ), + name: attrVal?.name, + translation: attrVal?.translation?.richText || null, + type: "rich" as "rich", + value: attrVal?.richText, + })) || [] + } saveButtonState={saveButtonState} richTextResetKey={languageCode} onEdit={onEdit} diff --git a/src/translations/components/TranslationsProductsPage/TranslationsProductsPage.tsx b/src/translations/components/TranslationsProductsPage/TranslationsProductsPage.tsx index 887f5f79a..5bfc927c1 100644 --- a/src/translations/components/TranslationsProductsPage/TranslationsProductsPage.tsx +++ b/src/translations/components/TranslationsProductsPage/TranslationsProductsPage.tsx @@ -15,7 +15,6 @@ import { languageEntityUrl, TranslatableEntities, } from "@saleor/translations/urls"; -import { mapAttributeValuesToTranslationFields } from "@saleor/translations/utils"; import React from "react"; import { useIntl } from "react-intl"; @@ -98,7 +97,7 @@ const TranslationsProductsPage: React.FC = ({ }), name: TranslationInputFieldName.name, translation: data?.translation?.name || null, - type: "short", + type: "short" as "short", value: data?.product?.name, }, { @@ -108,7 +107,7 @@ const TranslationsProductsPage: React.FC = ({ }), name: TranslationInputFieldName.description, translation: data?.translation?.description || null, - type: "rich", + type: "rich" as "rich", value: data?.product?.description, }, ]} @@ -135,7 +134,7 @@ const TranslationsProductsPage: React.FC = ({ }), name: TranslationInputFieldName.seoTitle, translation: data?.translation?.seoTitle || null, - type: "short", + type: "short" as "short", value: data?.product?.seoTitle, }, { @@ -145,7 +144,7 @@ const TranslationsProductsPage: React.FC = ({ }), name: TranslationInputFieldName.seoDescription, translation: data?.translation?.seoDescription || null, - type: "long", + type: "long" as "long", value: data?.product?.seoDescription, }, ]} @@ -163,10 +162,25 @@ const TranslationsProductsPage: React.FC = ({ disabled={disabled} initialState={true} title={intl.formatMessage(commonMessages.translationAttributes)} - fields={mapAttributeValuesToTranslationFields( - data.attributeValues, - intl, - )} + fields={ + data.attributeValues.map((attrVal, i) => ({ + id: attrVal.attributeValue.id, + displayName: intl.formatMessage( + { + id: "PajjqE", + defaultMessage: "Attribute {number}", + description: "attribute list", + }, + { + number: i + 1, + }, + ), + name: attrVal?.name, + translation: attrVal?.translation?.richText || null, + type: "rich" as "rich", + value: attrVal?.richText, + })) || [] + } saveButtonState={saveButtonState} richTextResetKey={languageCode} onEdit={onEdit} diff --git a/src/translations/types.ts b/src/translations/types.ts index 7c0d87b41..82b6aefcf 100644 --- a/src/translations/types.ts +++ b/src/translations/types.ts @@ -19,20 +19,12 @@ export enum PageTranslationInputFieldName { richText = "richText", } -export const TranslationFieldType = { - SHORT: "short", - LONG: "long", - RICH: "rich", -} as const; - -export type TranslationFieldType = typeof TranslationFieldType[keyof typeof TranslationFieldType]; - export interface TranslationField { id?: string; displayName: string; name: T; translation: string; - type: TranslationFieldType; + type: "short" | "long" | "rich"; value: string; } diff --git a/src/translations/utils.ts b/src/translations/utils.ts index a2239744f..feed30376 100644 --- a/src/translations/utils.ts +++ b/src/translations/utils.ts @@ -1,13 +1,6 @@ import { OutputData } from "@editorjs/editorjs"; -import { - AttributeTranslationDetailsFragment, - AttributeValueTranslatableFragment, - AttributeValueTranslationInput, -} from "@saleor/graphql"; -import { - TranslationField, - TranslationFieldType, -} from "@saleor/translations/types"; +import { AttributeTranslationDetailsFragment } from "@saleor/graphql"; +import { TranslationField } from "@saleor/translations/types"; import { mapEdgesToItems } from "@saleor/utils/maps"; import { getParsedDataForJsonStringField } from "@saleor/utils/richText/misc"; import { IntlShape } from "react-intl"; @@ -59,34 +52,3 @@ export const getTranslationFields = ( }; }, ) || []; - -export const mapAttributeValuesToTranslationFields = ( - attributeValues: AttributeValueTranslatableFragment[], - intl: IntlShape, -) => - attributeValues.map(attrVal => ({ - id: attrVal.attributeValue.id, - displayName: intl.formatMessage( - { - id: "zgqPGF", - defaultMessage: "Attribute {name}", - description: "attribute list", - }, - { - name: attrVal.attribute.name, - }, - ), - name: attrVal.name, - translation: - attrVal.translation?.richText || attrVal.translation?.plainText || null, - type: attrVal.richText ? "rich" : "short", - value: attrVal.richText || attrVal.plainText, - })) || []; - -export const getAttributeValueTranslationsInputData = ( - type: TranslationFieldType, - data: OutputData | string, -): AttributeValueTranslationInput => - type === TranslationFieldType.RICH - ? { richText: JSON.stringify(data) } - : { plainText: data as string }; diff --git a/src/translations/views/TranslationsPages.tsx b/src/translations/views/TranslationsPages.tsx index ba6421fe0..2e77607cf 100644 --- a/src/translations/views/TranslationsPages.tsx +++ b/src/translations/views/TranslationsPages.tsx @@ -16,10 +16,7 @@ import { useIntl } from "react-intl"; import TranslationsPagesPage from "../components/TranslationsPagesPage"; import { PageTranslationInputFieldName, TranslationField } from "../types"; -import { - getAttributeValueTranslationsInputData, - getParsedTranslationInputData, -} from "../utils"; +import { getParsedTranslationInputData } from "../utils"; export interface TranslationsPagesQueryParams { activeField: string; @@ -99,14 +96,14 @@ const TranslationsPages: React.FC = ({ ); const handleAttributeValueSubmit = ( - { id, type }: TranslationField, - data: OutputData | string, + { id }: TranslationField, + data: OutputData, ) => extractMutationErrors( updateAttributeValueTranslations({ variables: { id, - input: getAttributeValueTranslationsInputData(type, data), + input: { richText: JSON.stringify(data) }, language: languageCode, }, }), diff --git a/src/translations/views/TranslationsProductVariants.tsx b/src/translations/views/TranslationsProductVariants.tsx index 9423f991f..79fe1d291 100644 --- a/src/translations/views/TranslationsProductVariants.tsx +++ b/src/translations/views/TranslationsProductVariants.tsx @@ -16,10 +16,7 @@ import { useIntl } from "react-intl"; import { extractMutationErrors, maybe } from "../../misc"; import TranslationsProductVariantsPage from "../components/TranslationsProductVariantsPage"; import { TranslationField, TranslationInputFieldName } from "../types"; -import { - getAttributeValueTranslationsInputData, - getParsedTranslationInputData, -} from "../utils"; +import { getParsedTranslationInputData } from "../utils"; export interface TranslationsProductVariantsQueryParams { activeField: string; @@ -101,14 +98,14 @@ const TranslationsProductVariants: React.FC = ); const handleAttributeValueSubmit = ( - { id, type }: TranslationField, - data: OutputData | string, + { id }: TranslationField, + data: OutputData, ) => extractMutationErrors( updateAttributeValueTranslations({ variables: { id, - input: getAttributeValueTranslationsInputData(type, data), + input: { richText: JSON.stringify(data) }, language: languageCode, }, }), diff --git a/src/translations/views/TranslationsProducts.tsx b/src/translations/views/TranslationsProducts.tsx index 3355aee74..438889360 100644 --- a/src/translations/views/TranslationsProducts.tsx +++ b/src/translations/views/TranslationsProducts.tsx @@ -16,10 +16,7 @@ import { useIntl } from "react-intl"; import { extractMutationErrors, maybe } from "../../misc"; import TranslationsProductsPage from "../components/TranslationsProductsPage"; import { TranslationField, TranslationInputFieldName } from "../types"; -import { - getAttributeValueTranslationsInputData, - getParsedTranslationInputData, -} from "../utils"; +import { getParsedTranslationInputData } from "../utils"; export interface TranslationsProductsQueryParams { activeField: string; @@ -99,14 +96,14 @@ const TranslationsProducts: React.FC = ({ ); const handleAttributeValueSubmit = ( - { id, type }: TranslationField, - data: OutputData | string, + { id }: TranslationField, + data: OutputData, ) => extractMutationErrors( updateAttributeValueTranslations({ variables: { id, - input: getAttributeValueTranslationsInputData(type, data), + input: { richText: JSON.stringify(data) }, language: languageCode, }, }),