Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add product types translations

dominik-zeglen14ff179f5ca9
diff --git a/saleor/static/dashboard-next/translations/components/TranslationsEntitiesListPage/TranslationsEntitiesListPage.tsx b/saleor/static/dashboard-next/translations/components/TranslationsEntitiesListPage/TranslationsEntitiesListPage.tsx
index bbf298880a..8e441d8238 100644
--- a/saleor/static/dashboard-next/translations/components/TranslationsEntitiesListPage/TranslationsEntitiesListPage.tsx
+++ b/saleor/static/dashboard-next/translations/components/TranslationsEntitiesListPage/TranslationsEntitiesListPage.tsx
@@ -25,6 +25,7 @@ export interface TranslationsEntitiesFilters {
onSalesTabClick: () => void;
onVouchersTabClick: () => void;
onPagesTabClick: () => void;
+ onProductTypesTabClick: () => void;
}
export type TranslationsEntitiesListFilterTab = keyof typeof TranslatableEntities;
@@ -48,7 +49,8 @@ const TranslationsEntitiesListPage: React.StatelessComponent<
"products",
"sales",
"vouchers",
- "pages"
+ "pages",
+ "productTypes"
] as TranslationsEntitiesListFilterTab[]).indexOf(filters.current)}
>
<FilterTab
@@ -69,6 +71,10 @@ const TranslationsEntitiesListPage: React.StatelessComponent<
onClick={filters.onVouchersTabClick}
/>
<FilterTab label={i18n.t("Pages")} onClick={filters.onPagesTabClick} />
+ <FilterTab
+ label={i18n.t("Product Types")}
+ onClick={filters.onProductTypesTabClick}
+ />
</FilterTabs>
{children}
</Card>
diff --git a/saleor/static/dashboard-next/translations/components/TranslationsProductTypesPage/TranslationsProductTypesPage.tsx b/saleor/static/dashboard-next/translations/components/TranslationsProductTypesPage/TranslationsProductTypesPage.tsx
new file mode 100644
index 0000000000..970163379d
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/components/TranslationsProductTypesPage/TranslationsProductTypesPage.tsx
@@ -0,0 +1,149 @@
+import * as React from "react";
+
+import CardSpacer from "../../../components/CardSpacer";
+import { ConfirmButtonTransitionState } from "../../../components/ConfirmButton";
+import Container from "../../../components/Container";
+import PageHeader from "../../../components/PageHeader";
+import i18n from "../../../i18n";
+import { maybe } from "../../../misc";
+import { ProductTypeTranslationFragment } from "../../types/ProductTypeTranslationFragment";
+import TranslationFields from "../TranslationFields";
+
+export interface TranslationsProductTypesPageProps {
+ activeField: string;
+ disabled: boolean;
+ languageCode: string;
+ productType: ProductTypeTranslationFragment;
+ saveButtonState: ConfirmButtonTransitionState;
+ onEdit: (field: string) => void;
+ onSubmit: (field: string, data: string) => void;
+}
+
+export const fieldNames = {
+ attribute: "attribute",
+ value: "attributeValue"
+};
+
+const TranslationsProductTypesPage: React.StatelessComponent<
+ TranslationsProductTypesPageProps
+> = ({
+ activeField,
+ disabled,
+ languageCode,
+ productType,
+ saveButtonState,
+ onEdit,
+ onSubmit
+}) => (
+ <Container>
+ <PageHeader
+ title={i18n.t(
+ 'Translation Product Type "{{ productTypeName }}" - {{ languageCode }}',
+ {
+ context: "productType translation page title",
+ languageCode,
+ productTypeName: maybe(() => productType.name, "...")
+ }
+ )}
+ />
+ {maybe(() => productType.productAttributes, []).map(
+ (attribute, attributeIndex) => (
+ <>
+ <TranslationFields
+ activeField={activeField}
+ disabled={disabled}
+ initialState={true}
+ title={i18n.t("Product Attribute ({{ attributeName }})", {
+ attributeName: attribute.name
+ })}
+ fields={[
+ {
+ displayName: i18n.t("Attribute Name"),
+ name: fieldNames.attribute + ":" + attribute.id,
+ translation: maybe(() =>
+ attribute.translation ? attribute.translation.name : null
+ ),
+ type: "short" as "short",
+ value: maybe(() => attribute.name)
+ },
+ ...attribute.values.map(
+ (attributeValue, attributeValueIndex) => ({
+ displayName: i18n.t("Value {{ number }}", {
+ number: attributeValueIndex + 1
+ }),
+ name: fieldNames.value + ":" + attributeValue.id,
+ translation: maybe(() =>
+ attributeValue.translation
+ ? attributeValue.translation.name
+ : null
+ ),
+ type: "short" as "short",
+ value: maybe(() => attributeValue.name)
+ })
+ )
+ ]}
+ saveButtonState={saveButtonState}
+ onEdit={onEdit}
+ onSubmit={onSubmit}
+ />
+ {attributeIndex < productType.productAttributes.length - 1 && (
+ <CardSpacer />
+ )}
+ </>
+ )
+ )}
+ {
+ <>
+ <CardSpacer />
+ {maybe(() => productType.variantAttributes, []).map(
+ (attribute, attributeIndex) => (
+ <>
+ <TranslationFields
+ activeField={activeField}
+ disabled={disabled}
+ initialState={true}
+ title={i18n.t("Variant Attribute ({{ attributeName }})", {
+ attributeName: attribute.name
+ })}
+ fields={[
+ {
+ displayName: i18n.t("Attribute Name"),
+ name: fieldNames.attribute + ":" + attribute.id,
+ translation: maybe(() =>
+ attribute.translation ? attribute.translation.name : null
+ ),
+ type: "short" as "short",
+ value: maybe(() => attribute.name)
+ },
+ ...attribute.values.map(
+ (attributeValue, attributeValueIndex) => ({
+ displayName: i18n.t("Value {{ number }}", {
+ number: attributeValueIndex + 1
+ }),
+ name: fieldNames.value + ":" + attributeValue.id,
+ translation: maybe(() =>
+ attributeValue.translation
+ ? attributeValue.translation.name
+ : null
+ ),
+ type: "short" as "short",
+ value: maybe(() => attributeValue.name)
+ })
+ )
+ ]}
+ saveButtonState={saveButtonState}
+ onEdit={onEdit}
+ onSubmit={onSubmit}
+ />
+ {attributeIndex < productType.variantAttributes.length - 1 && (
+ <CardSpacer />
+ )}
+ </>
+ )
+ )}
+ </>
+ }
+ </Container>
+);
+TranslationsProductTypesPage.displayName = "TranslationsProductTypesPage";
+export default TranslationsProductTypesPage;
diff --git a/saleor/static/dashboard-next/translations/components/TranslationsProductTypesPage/index.ts b/saleor/static/dashboard-next/translations/components/TranslationsProductTypesPage/index.ts
new file mode 100644
index 0000000000..7da3b42043
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/components/TranslationsProductTypesPage/index.ts
@@ -0,0 +1,2 @@
+export { default } from "./TranslationsProductTypesPage";
+export * from "./TranslationsProductTypesPage";
diff --git a/saleor/static/dashboard-next/translations/index.tsx b/saleor/static/dashboard-next/translations/index.tsx
index bfb52a89a6..94a845f4e7 100644
--- a/saleor/static/dashboard-next/translations/index.tsx
+++ b/saleor/static/dashboard-next/translations/index.tsx
@@ -33,6 +33,9 @@ import TranslationsSaleComponent, {
import TranslationsVouchersComponent, {
TranslationsVouchersQueryParams
} from "./views/TranslationsVouchers";
+import TranslationsProductTypesComponent, {
+ TranslationsProductTypesQueryParams
+} from "./views/TranslationsProductTypes";
type TranslationsEntitiesRouteProps = RouteComponentProps<{
languageCode: string;
@@ -154,6 +157,22 @@ const TranslationsPages: React.FC<TranslationsEntityRouteProps> = ({
/>
);
};
+const TranslationsProductTypes: React.FC<TranslationsEntityRouteProps> = ({
+ location,
+ match
+}) => {
+ const qs = parseQs(location.search.substr(1));
+ const params: TranslationsProductTypesQueryParams = {
+ activeField: qs.activeField
+ };
+ return (
+ <TranslationsProductTypesComponent
+ id={decodeURIComponent(match.params.id)}
+ languageCode={LanguageCodeEnum[match.params.languageCode]}
+ params={params}
+ />
+ );
+};
const TranslationsRouter: React.FC = () => (
<>
@@ -223,6 +242,15 @@ const TranslationsRouter: React.FC = () => (
)}
component={TranslationsPages}
/>
+ <Route
+ exact
+ path={languageEntityPath(
+ ":languageCode",
+ TranslatableEntities.productTypes,
+ ":id"
+ )}
+ component={TranslationsProductTypes}
+ />
</Switch>
</>
);
diff --git a/saleor/static/dashboard-next/translations/mutations.ts b/saleor/static/dashboard-next/translations/mutations.ts
index 2836660904..149f72a50c 100644
--- a/saleor/static/dashboard-next/translations/mutations.ts
+++ b/saleor/static/dashboard-next/translations/mutations.ts
@@ -9,6 +9,14 @@ import {
saleTranslationFragment,
voucherTranslationFragment
} from "./queries";
+import {
+ UpdateAttributeTranslations,
+ UpdateAttributeTranslationsVariables
+} from "./types/UpdateAttributeTranslations";
+import {
+ UpdateAttributeValueTranslations,
+ UpdateAttributeValueTranslationsVariables
+} from "./types/UpdateAttributeValueTranslations";
import {
UpdateCategoryTranslations,
UpdateCategoryTranslationsVariables
@@ -171,3 +179,57 @@ export const TypedUpdateSaleTranslations = TypedMutation<
UpdateSaleTranslations,
UpdateSaleTranslationsVariables
>(updateSaleTranslations);
+
+const updateAttributeTranslations = gql`
+ mutation UpdateAttributeTranslations(
+ $id: ID!
+ $input: NameTranslationInput!
+ $language: LanguageCodeEnum!
+ ) {
+ attributeTranslate(id: $id, input: $input, languageCode: $language) {
+ errors {
+ field
+ message
+ }
+ attribute {
+ id
+ name
+ translation(languageCode: $language) {
+ id
+ name
+ }
+ }
+ }
+ }
+`;
+export const TypedUpdateAttributeTranslations = TypedMutation<
+ UpdateAttributeTranslations,
+ UpdateAttributeTranslationsVariables
+>(updateAttributeTranslations);
+
+const updateAttributeValueTranslations = gql`
+ mutation UpdateAttributeValueTranslations(
+ $id: ID!
+ $input: NameTranslationInput!
+ $language: LanguageCodeEnum!
+ ) {
+ attributeValueTranslate(id: $id, input: $input, languageCode: $language) {
+ errors {
+ field
+ message
+ }
+ attributeValue {
+ id
+ name
+ translation(languageCode: $language) {
+ id
+ name
+ }
+ }
+ }
+ }
+`;
+export const TypedUpdateAttributeValueTranslations = TypedMutation<
+ UpdateAttributeValueTranslations,
+ UpdateAttributeValueTranslationsVariables
+>(updateAttributeValueTranslations);
diff --git a/saleor/static/dashboard-next/translations/queries.ts b/saleor/static/dashboard-next/translations/queries.ts
index 5832a04149..b03e208c09 100644
--- a/saleor/static/dashboard-next/translations/queries.ts
+++ b/saleor/static/dashboard-next/translations/queries.ts
@@ -33,6 +33,14 @@ import {
ProductTranslations,
ProductTranslationsVariables
} from "./types/ProductTranslations";
+import {
+ ProductTypeTranslationDetails,
+ ProductTypeTranslationDetailsVariables
+} from "./types/ProductTypeTranslationDetails";
+import {
+ ProductTypeTranslations,
+ ProductTypeTranslationsVariables
+} from "./types/ProductTypeTranslations";
import {
SaleTranslationDetails,
SaleTranslationDetailsVariables
@@ -171,6 +179,34 @@ export const pageTranslationFragment = gql`
}
}
`;
+export const productTypeTranslationFragment = gql`
+ fragment AttributeTranslationFragment on Attribute {
+ id
+ name
+ translation(languageCode: $language) {
+ id
+ name
+ }
+ values {
+ id
+ name
+ translation(languageCode: $language) {
+ id
+ name
+ }
+ }
+ }
+ fragment ProductTypeTranslationFragment on ProductType {
+ id
+ name
+ productAttributes {
+ ...AttributeTranslationFragment
+ }
+ variantAttributes {
+ ...AttributeTranslationFragment
+ }
+ }
+`;
const categoryTranslations = gql`
${pageInfoFragment}
@@ -334,6 +370,33 @@ export const TypedSaleTranslations = TypedQuery<
SaleTranslationsVariables
>(saleTranslations);
+const productTypeTranslations = gql`
+ ${pageInfoFragment}
+ ${productTypeTranslationFragment}
+ query ProductTypeTranslations(
+ $language: LanguageCodeEnum!
+ $first: Int
+ $after: String
+ $last: Int
+ $before: String
+ ) {
+ productTypes(before: $before, after: $after, first: $first, last: $last) {
+ edges {
+ node {
+ ...ProductTypeTranslationFragment
+ }
+ }
+ pageInfo {
+ ...PageInfoFragment
+ }
+ }
+ }
+`;
+export const TypedProductTypeTranslations = TypedQuery<
+ ProductTypeTranslations,
+ ProductTypeTranslationsVariables
+>(productTypeTranslations);
+
const productTranslationDetails = gql`
${productTranslationFragment}
query ProductTranslationDetails($id: ID!, $language: LanguageCodeEnum!) {
@@ -411,3 +474,16 @@ export const TypedVoucherTranslationDetails = TypedQuery<
VoucherTranslationDetails,
VoucherTranslationDetailsVariables
>(voucherTranslationDetails);
+
+const productTypeTranslationDetails = gql`
+ ${productTypeTranslationFragment}
+ query ProductTypeTranslationDetails($id: ID!, $language: LanguageCodeEnum!) {
+ productType(id: $id) {
+ ...ProductTypeTranslationFragment
+ }
+ }
+`;
+export const TypedProductTypeTranslationDetails = TypedQuery<
+ ProductTypeTranslationDetails,
+ ProductTypeTranslationDetailsVariables
+>(productTypeTranslationDetails);
diff --git a/saleor/static/dashboard-next/translations/types/AttributeTranslationFragment.ts b/saleor/static/dashboard-next/translations/types/AttributeTranslationFragment.ts
new file mode 100644
index 0000000000..59d52d3a4e
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/types/AttributeTranslationFragment.ts
@@ -0,0 +1,34 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL fragment: AttributeTranslationFragment
+// ====================================================
+
+export interface AttributeTranslationFragment_translation {
+ __typename: "AttributeTranslation";
+ id: string;
+ name: string;
+}
+
+export interface AttributeTranslationFragment_values_translation {
+ __typename: "AttributeValueTranslation";
+ id: string;
+ name: string;
+}
+
+export interface AttributeTranslationFragment_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ translation: AttributeTranslationFragment_values_translation | null;
+}
+
+export interface AttributeTranslationFragment {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ translation: AttributeTranslationFragment_translation | null;
+ values: (AttributeTranslationFragment_values | null)[] | null;
+}
diff --git a/saleor/static/dashboard-next/translations/types/ProductTypeTranslationDetails.ts b/saleor/static/dashboard-next/translations/types/ProductTypeTranslationDetails.ts
new file mode 100644
index 0000000000..a74f26b32f
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/types/ProductTypeTranslationDetails.ts
@@ -0,0 +1,80 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { LanguageCodeEnum } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL query operation: ProductTypeTranslationDetails
+// ====================================================
+
+export interface ProductTypeTranslationDetails_productType_productAttributes_translation {
+ __typename: "AttributeTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslationDetails_productType_productAttributes_values_translation {
+ __typename: "AttributeValueTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslationDetails_productType_productAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslationDetails_productType_productAttributes_values_translation | null;
+}
+
+export interface ProductTypeTranslationDetails_productType_productAttributes {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslationDetails_productType_productAttributes_translation | null;
+ values: (ProductTypeTranslationDetails_productType_productAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeTranslationDetails_productType_variantAttributes_translation {
+ __typename: "AttributeTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslationDetails_productType_variantAttributes_values_translation {
+ __typename: "AttributeValueTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslationDetails_productType_variantAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslationDetails_productType_variantAttributes_values_translation | null;
+}
+
+export interface ProductTypeTranslationDetails_productType_variantAttributes {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslationDetails_productType_variantAttributes_translation | null;
+ values: (ProductTypeTranslationDetails_productType_variantAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeTranslationDetails_productType {
+ __typename: "ProductType";
+ id: string;
+ name: string;
+ productAttributes: (ProductTypeTranslationDetails_productType_productAttributes | null)[] | null;
+ variantAttributes: (ProductTypeTranslationDetails_productType_variantAttributes | null)[] | null;
+}
+
+export interface ProductTypeTranslationDetails {
+ productType: ProductTypeTranslationDetails_productType | null;
+}
+
+export interface ProductTypeTranslationDetailsVariables {
+ id: string;
+ language: LanguageCodeEnum;
+}
diff --git a/saleor/static/dashboard-next/translations/types/ProductTypeTranslationFragment.ts b/saleor/static/dashboard-next/translations/types/ProductTypeTranslationFragment.ts
new file mode 100644
index 0000000000..ac30567abd
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/types/ProductTypeTranslationFragment.ts
@@ -0,0 +1,69 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+// ====================================================
+// GraphQL fragment: ProductTypeTranslationFragment
+// ====================================================
+
+export interface ProductTypeTranslationFragment_productAttributes_translation {
+ __typename: "AttributeTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslationFragment_productAttributes_values_translation {
+ __typename: "AttributeValueTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslationFragment_productAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslationFragment_productAttributes_values_translation | null;
+}
+
+export interface ProductTypeTranslationFragment_productAttributes {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslationFragment_productAttributes_translation | null;
+ values: (ProductTypeTranslationFragment_productAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeTranslationFragment_variantAttributes_translation {
+ __typename: "AttributeTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslationFragment_variantAttributes_values_translation {
+ __typename: "AttributeValueTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslationFragment_variantAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslationFragment_variantAttributes_values_translation | null;
+}
+
+export interface ProductTypeTranslationFragment_variantAttributes {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslationFragment_variantAttributes_translation | null;
+ values: (ProductTypeTranslationFragment_variantAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeTranslationFragment {
+ __typename: "ProductType";
+ id: string;
+ name: string;
+ productAttributes: (ProductTypeTranslationFragment_productAttributes | null)[] | null;
+ variantAttributes: (ProductTypeTranslationFragment_variantAttributes | null)[] | null;
+}
diff --git a/saleor/static/dashboard-next/translations/types/ProductTypeTranslations.ts b/saleor/static/dashboard-next/translations/types/ProductTypeTranslations.ts
new file mode 100644
index 0000000000..17ba27fed8
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/types/ProductTypeTranslations.ts
@@ -0,0 +1,102 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { LanguageCodeEnum } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL query operation: ProductTypeTranslations
+// ====================================================
+
+export interface ProductTypeTranslations_productTypes_edges_node_productAttributes_translation {
+ __typename: "AttributeTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslations_productTypes_edges_node_productAttributes_values_translation {
+ __typename: "AttributeValueTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslations_productTypes_edges_node_productAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslations_productTypes_edges_node_productAttributes_values_translation | null;
+}
+
+export interface ProductTypeTranslations_productTypes_edges_node_productAttributes {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslations_productTypes_edges_node_productAttributes_translation | null;
+ values: (ProductTypeTranslations_productTypes_edges_node_productAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeTranslations_productTypes_edges_node_variantAttributes_translation {
+ __typename: "AttributeTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslations_productTypes_edges_node_variantAttributes_values_translation {
+ __typename: "AttributeValueTranslation";
+ id: string;
+ name: string;
+}
+
+export interface ProductTypeTranslations_productTypes_edges_node_variantAttributes_values {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslations_productTypes_edges_node_variantAttributes_values_translation | null;
+}
+
+export interface ProductTypeTranslations_productTypes_edges_node_variantAttributes {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ translation: ProductTypeTranslations_productTypes_edges_node_variantAttributes_translation | null;
+ values: (ProductTypeTranslations_productTypes_edges_node_variantAttributes_values | null)[] | null;
+}
+
+export interface ProductTypeTranslations_productTypes_edges_node {
+ __typename: "ProductType";
+ id: string;
+ name: string;
+ productAttributes: (ProductTypeTranslations_productTypes_edges_node_productAttributes | null)[] | null;
+ variantAttributes: (ProductTypeTranslations_productTypes_edges_node_variantAttributes | null)[] | null;
+}
+
+export interface ProductTypeTranslations_productTypes_edges {
+ __typename: "ProductTypeCountableEdge";
+ node: ProductTypeTranslations_productTypes_edges_node;
+}
+
+export interface ProductTypeTranslations_productTypes_pageInfo {
+ __typename: "PageInfo";
+ endCursor: string | null;
+ hasNextPage: boolean;
+ hasPreviousPage: boolean;
+ startCursor: string | null;
+}
+
+export interface ProductTypeTranslations_productTypes {
+ __typename: "ProductTypeCountableConnection";
+ edges: ProductTypeTranslations_productTypes_edges[];
+ pageInfo: ProductTypeTranslations_productTypes_pageInfo;
+}
+
+export interface ProductTypeTranslations {
+ productTypes: ProductTypeTranslations_productTypes | null;
+}
+
+export interface ProductTypeTranslationsVariables {
+ language: LanguageCodeEnum;
+ first?: number | null;
+ after?: string | null;
+ last?: number | null;
+ before?: string | null;
+}
diff --git a/saleor/static/dashboard-next/translations/types/UpdateAttributeTranslations.ts b/saleor/static/dashboard-next/translations/types/UpdateAttributeTranslations.ts
new file mode 100644
index 0000000000..1aae04d1b6
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/types/UpdateAttributeTranslations.ts
@@ -0,0 +1,44 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { NameTranslationInput, LanguageCodeEnum } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL mutation operation: UpdateAttributeTranslations
+// ====================================================
+
+export interface UpdateAttributeTranslations_attributeTranslate_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface UpdateAttributeTranslations_attributeTranslate_attribute_translation {
+ __typename: "AttributeTranslation";
+ id: string;
+ name: string;
+}
+
+export interface UpdateAttributeTranslations_attributeTranslate_attribute {
+ __typename: "Attribute";
+ id: string;
+ name: string | null;
+ translation: UpdateAttributeTranslations_attributeTranslate_attribute_translation | null;
+}
+
+export interface UpdateAttributeTranslations_attributeTranslate {
+ __typename: "AttributeTranslate";
+ errors: UpdateAttributeTranslations_attributeTranslate_errors[] | null;
+ attribute: UpdateAttributeTranslations_attributeTranslate_attribute | null;
+}
+
+export interface UpdateAttributeTranslations {
+ attributeTranslate: UpdateAttributeTranslations_attributeTranslate | null;
+}
+
+export interface UpdateAttributeTranslationsVariables {
+ id: string;
+ input: NameTranslationInput;
+ language: LanguageCodeEnum;
+}
diff --git a/saleor/static/dashboard-next/translations/types/UpdateAttributeValueTranslations.ts b/saleor/static/dashboard-next/translations/types/UpdateAttributeValueTranslations.ts
new file mode 100644
index 0000000000..b5c165008a
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/types/UpdateAttributeValueTranslations.ts
@@ -0,0 +1,44 @@
+/* tslint:disable */
+/* eslint-disable */
+// This file was automatically generated and should not be edited.
+
+import { NameTranslationInput, LanguageCodeEnum } from "./../../types/globalTypes";
+
+// ====================================================
+// GraphQL mutation operation: UpdateAttributeValueTranslations
+// ====================================================
+
+export interface UpdateAttributeValueTranslations_attributeValueTranslate_errors {
+ __typename: "Error";
+ field: string | null;
+ message: string | null;
+}
+
+export interface UpdateAttributeValueTranslations_attributeValueTranslate_attributeValue_translation {
+ __typename: "AttributeValueTranslation";
+ id: string;
+ name: string;
+}
+
+export interface UpdateAttributeValueTranslations_attributeValueTranslate_attributeValue {
+ __typename: "AttributeValue";
+ id: string;
+ name: string | null;
+ translation: UpdateAttributeValueTranslations_attributeValueTranslate_attributeValue_translation | null;
+}
+
+export interface UpdateAttributeValueTranslations_attributeValueTranslate {
+ __typename: "AttributeValueTranslate";
+ errors: UpdateAttributeValueTranslations_attributeValueTranslate_errors[] | null;
+ attributeValue: UpdateAttributeValueTranslations_attributeValueTranslate_attributeValue | null;
+}
+
+export interface UpdateAttributeValueTranslations {
+ attributeValueTranslate: UpdateAttributeValueTranslations_attributeValueTranslate | null;
+}
+
+export interface UpdateAttributeValueTranslationsVariables {
+ id: string;
+ input: NameTranslationInput;
+ language: LanguageCodeEnum;
+}
diff --git a/saleor/static/dashboard-next/translations/urls.ts b/saleor/static/dashboard-next/translations/urls.ts
index b50e3c3b1a..374698dab3 100644
--- a/saleor/static/dashboard-next/translations/urls.ts
+++ b/saleor/static/dashboard-next/translations/urls.ts
@@ -15,7 +15,8 @@ export enum TranslatableEntities {
collections = "collections",
sales = "sales",
vouchers = "vouchers",
- pages = "pages"
+ pages = "pages",
+ productTypes = "productTypes"
}
export const languageEntityPath = (
diff --git a/saleor/static/dashboard-next/translations/views/TranslationsEntities.tsx b/saleor/static/dashboard-next/translations/views/TranslationsEntities.tsx
index aba995ede6..be2b7cc5cf 100644
--- a/saleor/static/dashboard-next/translations/views/TranslationsEntities.tsx
+++ b/saleor/static/dashboard-next/translations/views/TranslationsEntities.tsx
@@ -16,6 +16,7 @@ import {
TypedCollectionTranslations,
TypedPageTranslations,
TypedProductTranslations,
+ TypedProductTypeTranslations,
TypedSaleTranslations,
TypedVoucherTranslations
} from "../queries";
@@ -76,6 +77,13 @@ const TranslationsEntities: React.FC<TranslationsEntitiesProps> = ({
tab: TranslatableEntities.pages
})
),
+ onProductTypesTabClick: () =>
+ navigate(
+ "?" +
+ stringifyQs({
+ tab: TranslatableEntities.productTypes
+ })
+ ),
onProductsTabClick: () =>
navigate(
"?" +
@@ -400,6 +408,80 @@ const TranslationsEntities: React.FC<TranslationsEntitiesProps> = ({
);
}}
</TypedPageTranslations>
+ ) : params.tab === "productTypes" ? (
+ <TypedProductTypeTranslations
+ variables={{ language: language as any, ...paginationState }}
+ >
+ {({ data, loading }) => {
+ const { loadNextPage, loadPreviousPage, pageInfo } = paginate(
+ maybe(() => data.productTypes.pageInfo),
+ paginationState,
+ params
+ );
+
+ return (
+ <TranslationsEntitiesList
+ disabled={loading}
+ entities={maybe(() =>
+ data.productTypes.edges
+ .map(edge => edge.node)
+ .map(node => ({
+ completion: {
+ current:
+ node.productAttributes && node.variantAttributes
+ ? maybe(() => node.productAttributes, []).reduce(
+ (acc, attr) =>
+ acc +
+ (attr.translation &&
+ attr.translation.name) !==
+ null
+ ? 1
+ : 0,
+ 0
+ ) +
+ maybe(() => node.variantAttributes, []).reduce(
+ (acc, attr) =>
+ acc +
+ (attr.translation &&
+ attr.translation.name) !==
+ null
+ ? 1
+ : 0,
+ 0
+ )
+ : 0,
+ max:
+ node.productAttributes && node.variantAttributes
+ ? node.productAttributes.reduce(
+ (acc, attr) => acc + attr.values.length,
+ 0
+ ) +
+ node.variantAttributes.reduce(
+ (acc, attr) => acc + attr.values.length,
+ 0
+ )
+ : 0
+ },
+ id: node.id,
+ name: node.name
+ }))
+ )}
+ onRowClick={id =>
+ navigate(
+ languageEntityUrl(
+ language,
+ TranslatableEntities.productTypes,
+ id
+ )
+ )
+ }
+ onNextPage={loadNextPage}
+ onPreviousPage={loadPreviousPage}
+ pageInfo={pageInfo}
+ />
+ );
+ }}
+ </TypedProductTypeTranslations>
) : null}
</TranslationsEntitiesListPage>
);
diff --git a/saleor/static/dashboard-next/translations/views/TranslationsProductTypes.tsx b/saleor/static/dashboard-next/translations/views/TranslationsProductTypes.tsx
new file mode 100644
index 0000000000..cc77790254
--- /dev/null
+++ b/saleor/static/dashboard-next/translations/views/TranslationsProductTypes.tsx
@@ -0,0 +1,148 @@
+import { stringify as stringifyQs } from "qs";
+import * as React from "react";
+
+import useNavigator from "../../hooks/useNavigator";
+import useNotifier from "../../hooks/useNotifier";
+import i18n from "../../i18n";
+import { getMutationState, maybe } from "../../misc";
+import {
+ LanguageCodeEnum,
+ NameTranslationInput
+} from "../../types/globalTypes";
+import TranslationsProductTypesPage, {
+ fieldNames
+} from "../components/TranslationsProductTypesPage";
+import {
+ TypedUpdateAttributeTranslations,
+ TypedUpdateAttributeValueTranslations
+} from "../mutations";
+import { TypedProductTypeTranslationDetails } from "../queries";
+import { UpdateAttributeTranslations } from "../types/UpdateAttributeTranslations";
+import { UpdateAttributeValueTranslations } from "../types/UpdateAttributeValueTranslations";
+
+export interface TranslationsProductTypesQueryParams {
+ activeField: string;
+}
+export interface TranslationsProductTypesProps {
+ id: string;
+ languageCode: LanguageCodeEnum;
+ params: TranslationsProductTypesQueryParams;
+}
+
+const TranslationsProductTypes: React.FC<TranslationsProductTypesProps> = ({
+ id,
+ languageCode,
+ params
+}) => {
+ const navigate = useNavigator();
+ const notify = useNotifier();
+
+ const onEdit = (field: string) =>
+ navigate(
+ "?" +
+ stringifyQs({
+ activeField: field
+ }),
+ true
+ );
+ const onAttributeUpdate = (data: UpdateAttributeTranslations) => {
+ if (data.attributeTranslate.errors.length === 0) {
+ notify({
+ text: i18n.t("Translation Saved")
+ });
+ navigate("?", true);
+ }
+ };
+ const onAttributeValueUpdate = (data: UpdateAttributeValueTranslations) => {
+ if (data.attributeValueTranslate.errors.length === 0) {
+ notify({
+ text: i18n.t("Translation Saved")
+ });
+ navigate("?", true);
+ }
+ };
+
+ return (
+ <TypedProductTypeTranslationDetails
+ variables={{ id, language: languageCode }}
+ >
+ {collectionTranslations => (
+ <TypedUpdateAttributeTranslations onCompleted={onAttributeUpdate}>
+ {(updateAttributeTranslations, updateAttributeTranslationsOpts) => (
+ <TypedUpdateAttributeValueTranslations
+ onCompleted={onAttributeValueUpdate}
+ >
+ {(
+ updateAttributeValueTranslations,
+ updateAttributeValueTranslationsOpts
+ ) => {
+ const handleSubmit = (field: string, data: string) => {
+ const input: NameTranslationInput = {};
+ const [fieldName, fieldId] = field.split(":");
+ if (fieldName === fieldNames.attribute) {
+ input.name = data;
+ updateAttributeTranslations({
+ variables: {
+ id: fieldId,
+ input,
+ language: languageCode
+ }
+ });
+ } else if (fieldName === fieldNames.value) {
+ input.name = data;
+ updateAttributeValueTranslations({
+ variables: {
+ id: fieldId,
+ input,
+ language: languageCode
+ }
+ });
+ }
+ };
+
+ const saveButtonState = getMutationState(
+ updateAttributeTranslationsOpts.called ||
+ updateAttributeTranslationsOpts.called,
+ updateAttributeTranslationsOpts.loading ||
+ updateAttributeTranslationsOpts.loading,
+ maybe(
+ () =>
+ updateAttributeTranslationsOpts.data.attributeTranslate
+ .errors,
+ []
+ ),
+ maybe(
+ () =>
+ updateAttributeValueTranslationsOpts.data
+ .attributeValueTranslate.errors,
+ []
+ )
+ );
+
+ return (
+ <TranslationsProductTypesPage
+ activeField={params.activeField}
+ disabled={
+ collectionTranslations.loading ||
+ updateAttributeTranslationsOpts.loading ||
+ updateAttributeValueTranslationsOpts.loading
+ }
+ languageCode={languageCode}
+ saveButtonState={saveButtonState}
+ onEdit={onEdit}
+ onSubmit={handleSubmit}
+ productType={maybe(
+ () => collectionTranslations.data.productType
+ )}
+ />
+ );
+ }}
+ </TypedUpdateAttributeValueTranslations>
+ )}
+ </TypedUpdateAttributeTranslations>
+ )}
+ </TypedProductTypeTranslationDetails>
+ );
+};
+TranslationsProductTypes.displayName = "TranslationsProductTypes";
+export default TranslationsProductTypes;