Skip to content

Commit 825b49a

Browse files
authored
add seo fields to translation product update (#462)
* add seo fields * add seo fields
1 parent 92dc152 commit 825b49a

File tree

4 files changed

+139
-41
lines changed

4 files changed

+139
-41
lines changed

.changeset/yummy-socks-greet.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@saleor/app-sdk": patch
3+
---
4+
5+
Added missing seoName and seoDescriptiont to formPayload action

src/app-bridge/app-bridge.test.ts

Lines changed: 113 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import {
99
AppBridge,
1010
DashboardEventFactory,
1111
DispatchResponseEvent,
12+
FormPayloadProductEdit,
13+
FormPayloadProductTranslate,
1214
HandshakeEvent,
1315
ThemeEvent,
1416
} from ".";
@@ -330,7 +332,7 @@ describe("AppBridge", () => {
330332
it("Updates state with form context when form payload event is received", () => {
331333
expect(appBridge.getState().formContext).toEqual({});
332334

333-
const formPayload = {
335+
const formPayload: FormPayloadProductTranslate = {
334336
form: "product-translate" as const,
335337
productId: "product-123",
336338
translationLanguage: "es",
@@ -343,6 +345,27 @@ describe("AppBridge", () => {
343345
currentValue: "Original Product",
344346
type: "short-text" as const,
345347
},
348+
productDescription: {
349+
fieldName: "",
350+
originalValue: "",
351+
translatedValue: "",
352+
currentValue: "",
353+
type: "short-text",
354+
},
355+
seoName: {
356+
fieldName: "",
357+
originalValue: "",
358+
translatedValue: "",
359+
currentValue: "",
360+
type: "short-text",
361+
},
362+
seoDescription: {
363+
fieldName: "",
364+
originalValue: "",
365+
translatedValue: "",
366+
currentValue: "",
367+
type: "short-text",
368+
},
346369
},
347370
};
348371

@@ -373,7 +396,7 @@ describe("AppBridge", () => {
373396

374397
expect(callback).not.toHaveBeenCalled();
375398

376-
const formPayload = {
399+
const formPayload: FormPayloadProductTranslate = {
377400
form: "product-translate" as const,
378401
productId: "product-456",
379402
translationLanguage: "fr",
@@ -386,6 +409,27 @@ describe("AppBridge", () => {
386409
currentValue: "Description",
387410
type: "editorjs" as const,
388411
},
412+
productName: {
413+
fieldName: "",
414+
originalValue: "",
415+
translatedValue: "",
416+
currentValue: "",
417+
type: "short-text",
418+
},
419+
seoName: {
420+
fieldName: "",
421+
originalValue: "",
422+
translatedValue: "",
423+
currentValue: "",
424+
type: "short-text",
425+
},
426+
seoDescription: {
427+
fieldName: "",
428+
originalValue: "",
429+
translatedValue: "",
430+
currentValue: "",
431+
type: "short-text",
432+
},
389433
},
390434
};
391435

@@ -435,7 +479,7 @@ describe("AppBridge", () => {
435479
});
436480

437481
it("Updates form context with new fields when multiple form events are received", () => {
438-
const firstFormPayload = {
482+
const firstFormPayload: FormPayloadProductTranslate = {
439483
form: "product-translate" as const,
440484
productId: "product-1",
441485
translationLanguage: "es",
@@ -448,6 +492,27 @@ describe("AppBridge", () => {
448492
currentValue: "Product 1",
449493
type: "short-text" as const,
450494
},
495+
productDescription: {
496+
fieldName: "",
497+
originalValue: "",
498+
translatedValue: "",
499+
currentValue: "",
500+
type: "short-text",
501+
},
502+
seoName: {
503+
fieldName: "",
504+
originalValue: "",
505+
translatedValue: "",
506+
currentValue: "",
507+
type: "short-text",
508+
},
509+
seoDescription: {
510+
fieldName: "",
511+
originalValue: "",
512+
translatedValue: "",
513+
currentValue: "",
514+
type: "short-text",
515+
},
451516
},
452517
};
453518

@@ -461,7 +526,7 @@ describe("AppBridge", () => {
461526

462527
expect(appBridge.getState().formContext?.["product-translate"]?.productId).toBe("product-1");
463528

464-
const secondFormPayload = {
529+
const secondFormPayload: FormPayloadProductTranslate = {
465530
form: "product-translate" as const,
466531
productId: "product-2",
467532
translationLanguage: "fr",
@@ -474,6 +539,27 @@ describe("AppBridge", () => {
474539
currentValue: "Product 2",
475540
type: "short-text" as const,
476541
},
542+
productDescription: {
543+
fieldName: "",
544+
originalValue: "",
545+
translatedValue: "",
546+
currentValue: "",
547+
type: "short-text",
548+
},
549+
seoName: {
550+
fieldName: "",
551+
originalValue: "",
552+
translatedValue: "",
553+
currentValue: "",
554+
type: "short-text",
555+
},
556+
seoDescription: {
557+
fieldName: "",
558+
originalValue: "",
559+
translatedValue: "",
560+
currentValue: "",
561+
type: "short-text",
562+
},
477563
},
478564
};
479565

@@ -497,7 +583,7 @@ describe("AppBridge", () => {
497583
it("Stores multiple form contexts for different form types simultaneously", () => {
498584
expect(appBridge.getState().formContext).toEqual({});
499585

500-
const productTranslatePayload = {
586+
const productTranslatePayload: FormPayloadProductTranslate = {
501587
form: "product-translate" as const,
502588
productId: "product-123",
503589
translationLanguage: "es",
@@ -510,10 +596,31 @@ describe("AppBridge", () => {
510596
currentValue: "Original Product",
511597
type: "short-text" as const,
512598
},
599+
productDescription: {
600+
fieldName: "",
601+
originalValue: "",
602+
translatedValue: "",
603+
currentValue: "",
604+
type: "editorjs",
605+
},
606+
seoName: {
607+
fieldName: "",
608+
originalValue: "",
609+
translatedValue: "",
610+
currentValue: "",
611+
type: "short-text",
612+
},
613+
seoDescription: {
614+
fieldName: "",
615+
originalValue: "",
616+
translatedValue: "",
617+
currentValue: "",
618+
type: "editorjs",
619+
},
513620
},
514621
};
515622

516-
const productEditPayload = {
623+
const productEditPayload: FormPayloadProductEdit = {
517624
form: "product-edit" as const,
518625
productId: "product-456",
519626
fields: {

src/app-bridge/events.test.ts

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { describe, expect, it } from "vitest";
22

3+
import { FormPayloadProductTranslate } from "@/app-bridge/form-payload";
4+
35
import { DashboardEventFactory } from "./events";
46

57
describe("DashboardEventFactory", () => {
@@ -67,7 +69,7 @@ describe("DashboardEventFactory", () => {
6769
});
6870

6971
it("Creates form payload event for product translation", () => {
70-
const formPayload = {
72+
const formPayload: FormPayloadProductTranslate = {
7173
form: "product-translate" as const,
7274
productId: "product-123",
7375
translationLanguage: "es",
@@ -87,6 +89,20 @@ describe("DashboardEventFactory", () => {
8789
currentValue: "Original description",
8890
type: "editorjs" as const,
8991
},
92+
seoName: {
93+
fieldName: "",
94+
originalValue: "",
95+
translatedValue: "",
96+
currentValue: "",
97+
type: "short-text",
98+
},
99+
seoDescription: {
100+
fieldName: "",
101+
originalValue: "",
102+
translatedValue: "",
103+
currentValue: "",
104+
type: "short-text",
105+
},
90106
},
91107
};
92108

@@ -95,37 +111,4 @@ describe("DashboardEventFactory", () => {
95111
payload: formPayload,
96112
});
97113
});
98-
99-
it("Creates form payload event with all translation field types", () => {
100-
const formPayload = {
101-
form: "product-translate" as const,
102-
productId: "product-456",
103-
translationLanguage: "fr",
104-
currentLanguage: "en",
105-
fields: {
106-
shortTextField: {
107-
fieldName: "shortTextField",
108-
originalValue: "Short text",
109-
translatedValue: "Texte court",
110-
currentValue: "Short text",
111-
type: "short-text" as const,
112-
},
113-
editorField: {
114-
fieldName: "editorField",
115-
originalValue: "{\"blocks\": []}",
116-
translatedValue: "{\"blocks\": []}",
117-
currentValue: "{\"blocks\": []}",
118-
type: "editorjs" as const,
119-
},
120-
},
121-
};
122-
123-
const event = DashboardEventFactory.createFormEvent(formPayload);
124-
125-
expect(event.type).toBe("formPayload");
126-
if (event.payload.form === "product-translate") {
127-
expect(event.payload.fields.shortTextField.type).toBe("short-text");
128-
expect(event.payload.fields.editorField.type).toBe("editorjs");
129-
}
130-
});
131114
});

src/app-bridge/form-payload.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@ type TranslationField = {
3131
type TranslationPayloadBase = {
3232
translationLanguage: string;
3333
currentLanguage: string;
34-
fields: Record<string, TranslationField>;
3534
};
3635

3736
export type FormPayloadProductTranslate = TranslationPayloadBase &
3837
ProductPayloadBase & {
3938
form: "product-translate";
39+
fields: Record<
40+
"productName" | "productDescription" | "seoName" | "seoDescription",
41+
TranslationField
42+
>;
4043
};
4144

4245
export type FormPayloadUpdatePayloadProductTranslate = BaseFormPayloadUpdatePayload & {

0 commit comments

Comments
 (0)