Skip to content

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

Fix counters

dominik-zeglen07c03e10d336
diff --git a/saleor/static/dashboard-next/translations/views/TranslationsEntities.tsx b/saleor/static/dashboard-next/translations/views/TranslationsEntities.tsx
index be2b7cc5cf..e7a1bb1df4 100644
--- a/saleor/static/dashboard-next/translations/views/TranslationsEntities.tsx
+++ b/saleor/static/dashboard-next/translations/views/TranslationsEntities.tsx
@@ -20,6 +20,7 @@ import {
TypedSaleTranslations,
TypedVoucherTranslations
} from "../queries";
+import { AttributeTranslationFragment } from "../types/AttributeTranslationFragment";
import {
languageEntityUrl,
languageListUrl,
@@ -37,6 +38,23 @@ interface TranslationsEntitiesProps {
const PAGINATE_BY = 20;
+function sumTranslations(
+ acc: number,
+ attr: AttributeTranslationFragment
+): number {
+ const accAfterNameTranslation =
+ acc + (attr.translation && attr.translation.name !== null ? 1 : 0);
+ const count =
+ accAfterNameTranslation +
+ attr.values.reduce(
+ (acc2, attrValue) =>
+ acc2 +
+ (attrValue.translation && attrValue.translation.name !== null ? 1 : 0),
+ 0
+ );
+ return count;
+}
+
const TranslationsEntities: React.FC<TranslationsEntitiesProps> = ({
language,
params
@@ -430,23 +448,11 @@ const TranslationsEntities: React.FC<TranslationsEntitiesProps> = ({
current:
node.productAttributes && node.variantAttributes
? maybe(() => node.productAttributes, []).reduce(
- (acc, attr) =>
- acc +
- (attr.translation &&
- attr.translation.name) !==
- null
- ? 1
- : 0,
+ sumTranslations,
0
) +
maybe(() => node.variantAttributes, []).reduce(
- (acc, attr) =>
- acc +
- (attr.translation &&
- attr.translation.name) !==
- null
- ? 1
- : 0,
+ sumTranslations,
0
)
: 0,
@@ -454,11 +460,11 @@ const TranslationsEntities: React.FC<TranslationsEntitiesProps> = ({
node.productAttributes && node.variantAttributes
? node.productAttributes.reduce(
(acc, attr) => acc + attr.values.length,
- 0
+ node.productAttributes.length
) +
node.variantAttributes.reduce(
(acc, attr) => acc + attr.values.length,
- 0
+ node.variantAttributes.length
)
: 0
},