Add translations for static elements to the filters (#4109)

* Support boolean static values

* Add intl for filters

* Add intl for filters
This commit is contained in:
Patryk Andrzejewski 2023-08-22 12:33:41 +02:00 committed by GitHub
parent 65106203f4
commit 86a3abdd5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 109 additions and 8 deletions

View file

@ -1524,6 +1524,9 @@
"context": "button", "context": "button",
"string": "SETUP END DATE" "string": "SETUP END DATE"
}, },
"9MGrEp": {
"string": "Is available"
},
"9Mro3c": { "9Mro3c": {
"context": "Transaction event status - pending", "context": "Transaction event status - pending",
"string": "Pending" "string": "Pending"
@ -2290,6 +2293,9 @@
"context": "change warehouse dialog warehouse list label", "context": "change warehouse dialog warehouse list label",
"string": "Warehouses A to Z" "string": "Warehouses A to Z"
}, },
"Eq3GFh": {
"string": "Is giftcard"
},
"ErNH3D": { "ErNH3D": {
"string": "Define where this attribute should be used in Saleor system" "string": "Define where this attribute should be used in Saleor system"
}, },
@ -3970,6 +3976,9 @@
"context": "table header name col label", "context": "table header name col label",
"string": "Name" "string": "Name"
}, },
"QHDtwH": {
"string": "Has category"
},
"QJG+d/": { "QJG+d/": {
"context": "staff added type order discount", "context": "staff added type order discount",
"string": "Staff added" "string": "Staff added"
@ -4057,6 +4066,9 @@
"context": "dialog content", "context": "dialog content",
"string": "Add a new address:" "string": "Add a new address:"
}, },
"QqnNUm": {
"string": "Visible in listing"
},
"QzseV7": { "QzseV7": {
"context": "dialog header", "context": "dialog header",
"string": "Delete Menu" "string": "Delete Menu"
@ -5896,6 +5908,9 @@
"dWK/Ck": { "dWK/Ck": {
"string": "Choose countries, you want voucher to be limited to, from the list below" "string": "Choose countries, you want voucher to be limited to, from the list below"
}, },
"da1ebU": {
"string": "Product type"
},
"dc5KWn": { "dc5KWn": {
"context": "products export type label", "context": "products export type label",
"string": "products" "string": "products"
@ -7022,6 +7037,9 @@
"context": "modal button upload", "context": "modal button upload",
"string": "Upload" "string": "Upload"
}, },
"mIRBuW": {
"string": "Is published"
},
"mIUNgR": { "mIUNgR": {
"context": "button", "context": "button",
"string": "Create shipping zone" "string": "Create shipping zone"

View file

@ -19,6 +19,10 @@ export class ExpressionValue {
public type: string, public type: string,
) {} ) {}
public setLabel(label: string) {
this.label = label;
}
public isEmpty() { public isEmpty() {
return this.value.length === 0 || this.label.length === 0; return this.value.length === 0 || this.label.length === 0;
} }

View file

@ -11,6 +11,7 @@ import { FilterContainer } from "./FilterElement";
import { LeftOperand } from "./LeftOperandsProvider"; import { LeftOperand } from "./LeftOperandsProvider";
import { useFiltersAreaTranslations } from "./messages"; import { useFiltersAreaTranslations } from "./messages";
import { useFilterContainer } from "./useFilterContainer"; import { useFilterContainer } from "./useFilterContainer";
import { useTranslate } from "./useTranslate";
import { ErrorEntry } from "./Validation"; import { ErrorEntry } from "./Validation";
interface FiltersAreaProps { interface FiltersAreaProps {
@ -28,6 +29,7 @@ export const FiltersArea: FC<FiltersAreaProps> = ({
}) => { }) => {
const { apiProvider, leftOperandsProvider } = useConditionalFilterContext(); const { apiProvider, leftOperandsProvider } = useConditionalFilterContext();
const translations = useFiltersAreaTranslations(); const translations = useFiltersAreaTranslations();
const { translateOperandOptions, translateSelectedOperands } = useTranslate();
const { const {
value, value,
@ -79,8 +81,8 @@ export const FiltersArea: FC<FiltersAreaProps> = ({
return ( return (
<_ExperimentalFilters <_ExperimentalFilters
leftOptions={leftOperandsProvider.operands} leftOptions={translateOperandOptions(leftOperandsProvider.operands)}
value={value as Array<string | Row>} value={translateSelectedOperands(value) as Array<string | Row>}
onChange={handleStateChange} onChange={handleStateChange}
error={errors} error={errors}
locale={translations.locale} locale={translations.locale}

View file

@ -52,31 +52,31 @@ export const STATIC_OPTIONS: LeftOperand[] = [
}, },
{ {
value: "isAvailable", value: "isAvailable",
label: "Is available", label: "IsAvailable",
type: "isAvailable", type: "isAvailable",
slug: "isAvailable", slug: "isAvailable",
}, },
{ {
value: "isPublished", value: "isPublished",
label: "Is published", label: "IsPublished",
type: "isPublished", type: "isPublished",
slug: "isPublished", slug: "isPublished",
}, },
{ {
value: "isVisibleInListing", value: "isVisibleInListing",
label: "Visible in listing", label: "VisibleInListing",
type: "isVisibleInListing", type: "isVisibleInListing",
slug: "isVisibleInListing", slug: "isVisibleInListing",
}, },
{ {
value: "hasCategory", value: "hasCategory",
label: "Has category", label: "HasCategory",
type: "hasCategory", type: "hasCategory",
slug: "hasCategory", slug: "hasCategory",
}, },
{ {
value: "giftCard", value: "giftCard",
label: "Is giftcard", label: "IsGiftcard",
type: "giftCard", type: "giftCard",
slug: "giftCard", slug: "giftCard",
}, },

View file

@ -0,0 +1,44 @@
import { defineMessages } from "react-intl";
export const leftOperatorsMessages = defineMessages({
Price: {
id: "b1zuN9",
defaultMessage: "Price",
},
Category: {
id: "ccXLVi",
defaultMessage: "Category",
},
Channel: {
id: "KeO51o",
defaultMessage: "Channel",
},
Collection: {
id: "phAZoj",
defaultMessage: "Collection",
},
ProductType: {
id: "da1ebU",
defaultMessage: "Product type",
},
IsAvailable: {
id: "9MGrEp",
defaultMessage: "Is available",
},
IsPublished: {
id: "mIRBuW",
defaultMessage: "Is published",
},
VisibleInListing: {
id: "QqnNUm",
defaultMessage: "Visible in listing",
},
HasCategory: {
id: "QHDtwH",
defaultMessage: "Has category",
},
IsGiftcard: {
id: "Eq3GFh",
defaultMessage: "Is giftcard",
},
});

View file

@ -0,0 +1,33 @@
import { useIntl } from "react-intl";
import { FilterContainer, FilterElement } from "./FilterElement";
import { leftOperatorsMessages } from "./intl";
import { LeftOperand } from "./LeftOperandsProvider";
type TranslationKeys = keyof typeof leftOperatorsMessages;
export const useTranslate = () => {
const intl = useIntl();
return {
translateOperandOptions: (operands: LeftOperand[]) =>
operands.map(el => ({
...el,
label: intl.formatMessage(
leftOperatorsMessages[el.label as TranslationKeys],
),
})),
translateSelectedOperands: (container: FilterContainer) =>
container.map(el => {
if (FilterElement.isCompatible(el)) {
el.value.setLabel(
intl.formatMessage(
leftOperatorsMessages[el.value.label as TranslationKeys],
),
);
}
return el;
}),
};
};