@webiny/app-scheduler 6.5.0-beta.11 → 6.5.0-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +16 -16
- package/presentation/scheduleDialog/ScheduleDialogPresenter.js +2 -1
- package/presentation/scheduleDialog/ScheduleDialogPresenter.js.map +1 -1
- package/presentation/scheduleDialog/ScheduleDialogPresenter.test.js +27 -1
- package/presentation/scheduleDialog/ScheduleDialogPresenter.test.js.map +1 -1
- package/presentation/scheduleDialog/abstractions.d.ts +4 -0
- package/presentation/scheduleDialog/abstractions.js.map +1 -1
- package/presentation/scheduleDialog/useScheduleDialog.js +15 -4
- package/presentation/scheduleDialog/useScheduleDialog.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/app-scheduler",
|
|
3
|
-
"version": "6.5.0-beta.
|
|
3
|
+
"version": "6.5.0-beta.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
@@ -16,32 +16,32 @@
|
|
|
16
16
|
"@emotion/react": "11.14.0",
|
|
17
17
|
"@emotion/styled": "11.14.1",
|
|
18
18
|
"@material-design-icons/svg": "0.14.15",
|
|
19
|
-
"@webiny/admin-ui": "6.5.0-beta.
|
|
20
|
-
"@webiny/app": "6.5.0-beta.
|
|
21
|
-
"@webiny/app-aco": "6.5.0-beta.
|
|
22
|
-
"@webiny/app-admin": "6.5.0-beta.
|
|
23
|
-
"@webiny/app-headless-cms-common": "6.5.0-beta.
|
|
24
|
-
"@webiny/feature": "6.5.0-beta.
|
|
25
|
-
"@webiny/form": "6.5.0-beta.
|
|
26
|
-
"@webiny/icons": "6.5.0-beta.
|
|
27
|
-
"@webiny/react-composition": "6.5.0-beta.
|
|
28
|
-
"@webiny/react-properties": "6.5.0-beta.
|
|
29
|
-
"@webiny/utils": "6.5.0-beta.
|
|
30
|
-
"@webiny/validation": "6.5.0-beta.
|
|
19
|
+
"@webiny/admin-ui": "6.5.0-beta.13",
|
|
20
|
+
"@webiny/app": "6.5.0-beta.13",
|
|
21
|
+
"@webiny/app-aco": "6.5.0-beta.13",
|
|
22
|
+
"@webiny/app-admin": "6.5.0-beta.13",
|
|
23
|
+
"@webiny/app-headless-cms-common": "6.5.0-beta.13",
|
|
24
|
+
"@webiny/feature": "6.5.0-beta.13",
|
|
25
|
+
"@webiny/form": "6.5.0-beta.13",
|
|
26
|
+
"@webiny/icons": "6.5.0-beta.13",
|
|
27
|
+
"@webiny/react-composition": "6.5.0-beta.13",
|
|
28
|
+
"@webiny/react-properties": "6.5.0-beta.13",
|
|
29
|
+
"@webiny/utils": "6.5.0-beta.13",
|
|
30
|
+
"@webiny/validation": "6.5.0-beta.13",
|
|
31
31
|
"lodash": "4.18.1",
|
|
32
32
|
"mobx": "7.0.6",
|
|
33
33
|
"mobx-react-lite": "5.1.0",
|
|
34
34
|
"react": "18.3.1",
|
|
35
35
|
"react-dom": "18.3.1",
|
|
36
|
-
"zod": "4.6.
|
|
36
|
+
"zod": "4.6.7"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@types/react": "18.3.31",
|
|
40
|
-
"@webiny/build-tools": "6.5.0-beta.
|
|
40
|
+
"@webiny/build-tools": "6.5.0-beta.13",
|
|
41
41
|
"@webiny/di": "1.1.0",
|
|
42
42
|
"rimraf": "6.1.3",
|
|
43
43
|
"typescript": "7.0.2",
|
|
44
|
-
"vitest": "5.0.
|
|
44
|
+
"vitest": "5.0.5"
|
|
45
45
|
},
|
|
46
46
|
"publishConfig": {
|
|
47
47
|
"access": "public"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/scheduleDialog/ScheduleDialogPresenter.js","sources":["../../../src/presentation/scheduleDialog/ScheduleDialogPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport { GetScheduledActionGateway } from \"~/features/getScheduledAction/abstractions.js\";\nimport { CancelScheduledActionGateway } from \"~/features/cancelScheduledAction/abstractions.js\";\nimport { SchedulePublishActionGateway } from \"~/features/schedulePublishAction/abstractions.js\";\nimport { ScheduleUnpublishActionGateway } from \"~/features/scheduleUnpublishAction/abstractions.js\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport type { SchedulerEntry } from \"~/types.js\";\nimport { DateFormatter } from \"@webiny/app-admin\";\nimport { formatUtcOffset } from \"@webiny/app-admin\";\nimport {\n ScheduleDialogPresenter as Abstraction,\n type IScheduleDialogPresenter,\n type IScheduleDialogPresenterViewModel,\n type IScheduleDialogRescheduling,\n type IScheduleDialogPresenterLoadParams,\n type IScheduleDialogPresenterScheduleParams,\n type IScheduleDialogPresenterCancelParams\n} from \"./abstractions.js\";\n\nclass ScheduleDialogPresenterImpl implements IScheduleDialogPresenter {\n private loading = false;\n private entry: SchedulerEntry | null = null;\n\n constructor(\n private readonly getGateway: GetScheduledActionGateway.Interface,\n private readonly cancelGateway: CancelScheduledActionGateway.Interface,\n private readonly publishGateway: SchedulePublishActionGateway.Interface,\n private readonly unpublishGateway: ScheduleUnpublishActionGateway.Interface,\n private readonly dateFormatter: DateFormatter.Interface\n ) {\n makeAutoObservable(this);\n }\n\n get vm(): IScheduleDialogPresenterViewModel {\n return {\n loading: this.loading,\n entry: this.entry,\n rescheduling: this.getRescheduling()\n };\n }\n\n private getRescheduling(): IScheduleDialogRescheduling | null {\n const entry = this.entry;\n if (!entry) {\n return null;\n }\n const scheduleOn = entry.publishOn || entry.unpublishOn;\n if (!scheduleOn) {\n return null;\n }\n const actionName =\n entry.actionType === ScheduleActionType.publish ? \"publish\" : \"unpublish\";\n return {\n actionName,\n scheduleOn: `${this.dateFormatter.format(scheduleOn)} (${formatUtcOffset()})`\n };\n }\n\n async load(params: IScheduleDialogPresenterLoadParams): Promise<void> {\n this.loading = true;\n\n try {\n const entry = await this.getGateway.execute(params);\n runInAction(() => {\n this.entry = entry;\n this.loading = false;\n });\n } catch {\n runInAction(() => {\n this.loading = false;\n });\n }\n }\n\n async schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void> {\n const { targetId, namespace, scheduleOn, actionType } = params;\n this.loading = true;\n\n try {\n switch (actionType) {\n case ScheduleActionType.publish:\n await this.publishGateway.execute({ namespace, targetId, scheduleOn });\n break;\n case ScheduleActionType.unpublish:\n await this.unpublishGateway.execute({ namespace, targetId, scheduleOn });\n break;\n default:\n throw new Error(`Unsupported action type \"${actionType}\".`);\n }\n runInAction(() => {\n this.entry = null;\n this.loading = false;\n });\n } catch (error) {\n runInAction(() => {\n this.loading = false;\n });\n // The caller shows a success toast and runs `onCompleted` when this resolves.\n throw error;\n }\n }\n\n async cancel(params: IScheduleDialogPresenterCancelParams): Promise<void> {\n this.loading = true;\n\n try {\n await this.cancelGateway.execute(params);\n runInAction(() => {\n this.entry = null;\n this.loading = false;\n });\n } catch (error) {\n runInAction(() => {\n this.loading = false;\n });\n throw error;\n }\n }\n\n reset(): void {\n this.entry = null;\n this.loading = false;\n }\n}\n\nexport const ScheduleDialogPresenter = Abstraction.createImplementation({\n implementation: ScheduleDialogPresenterImpl,\n dependencies: [\n GetScheduledActionGateway,\n CancelScheduledActionGateway,\n SchedulePublishActionGateway,\n ScheduleUnpublishActionGateway,\n DateFormatter\n ]\n});\n"],"names":["ScheduleDialogPresenterImpl","getGateway","cancelGateway","publishGateway","unpublishGateway","dateFormatter","makeAutoObservable","entry","scheduleOn","actionName","ScheduleActionType","formatUtcOffset","params","runInAction","targetId","namespace","actionType","Error","
|
|
1
|
+
{"version":3,"file":"presentation/scheduleDialog/ScheduleDialogPresenter.js","sources":["../../../src/presentation/scheduleDialog/ScheduleDialogPresenter.ts"],"sourcesContent":["import { makeAutoObservable, runInAction } from \"mobx\";\nimport { GetScheduledActionGateway } from \"~/features/getScheduledAction/abstractions.js\";\nimport { CancelScheduledActionGateway } from \"~/features/cancelScheduledAction/abstractions.js\";\nimport { SchedulePublishActionGateway } from \"~/features/schedulePublishAction/abstractions.js\";\nimport { ScheduleUnpublishActionGateway } from \"~/features/scheduleUnpublishAction/abstractions.js\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport type { SchedulerEntry } from \"~/types.js\";\nimport { DateFormatter } from \"@webiny/app-admin\";\nimport { formatUtcOffset } from \"@webiny/app-admin\";\nimport {\n ScheduleDialogPresenter as Abstraction,\n type IScheduleDialogPresenter,\n type IScheduleDialogPresenterViewModel,\n type IScheduleDialogRescheduling,\n type IScheduleDialogPresenterLoadParams,\n type IScheduleDialogPresenterScheduleParams,\n type IScheduleDialogPresenterCancelParams\n} from \"./abstractions.js\";\n\nclass ScheduleDialogPresenterImpl implements IScheduleDialogPresenter {\n private loading = false;\n private entry: SchedulerEntry | null = null;\n\n constructor(\n private readonly getGateway: GetScheduledActionGateway.Interface,\n private readonly cancelGateway: CancelScheduledActionGateway.Interface,\n private readonly publishGateway: SchedulePublishActionGateway.Interface,\n private readonly unpublishGateway: ScheduleUnpublishActionGateway.Interface,\n private readonly dateFormatter: DateFormatter.Interface\n ) {\n makeAutoObservable(this);\n }\n\n get vm(): IScheduleDialogPresenterViewModel {\n return {\n loading: this.loading,\n entry: this.entry,\n rescheduling: this.getRescheduling()\n };\n }\n\n private getRescheduling(): IScheduleDialogRescheduling | null {\n const entry = this.entry;\n if (!entry) {\n return null;\n }\n const scheduleOn = entry.publishOn || entry.unpublishOn;\n if (!scheduleOn) {\n return null;\n }\n const actionName =\n entry.actionType === ScheduleActionType.publish ? \"publish\" : \"unpublish\";\n return {\n actionName,\n scheduleOn: `${this.dateFormatter.format(scheduleOn)} (${formatUtcOffset()})`\n };\n }\n\n async load(params: IScheduleDialogPresenterLoadParams): Promise<void> {\n this.loading = true;\n\n try {\n const entry = await this.getGateway.execute(params);\n runInAction(() => {\n this.entry = entry;\n this.loading = false;\n });\n } catch (error) {\n runInAction(() => {\n this.loading = false;\n });\n throw error;\n }\n }\n\n async schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void> {\n const { targetId, namespace, scheduleOn, actionType } = params;\n this.loading = true;\n\n try {\n switch (actionType) {\n case ScheduleActionType.publish:\n await this.publishGateway.execute({ namespace, targetId, scheduleOn });\n break;\n case ScheduleActionType.unpublish:\n await this.unpublishGateway.execute({ namespace, targetId, scheduleOn });\n break;\n default:\n throw new Error(`Unsupported action type \"${actionType}\".`);\n }\n runInAction(() => {\n this.entry = null;\n this.loading = false;\n });\n } catch (error) {\n runInAction(() => {\n this.loading = false;\n });\n // The caller shows a success toast and runs `onCompleted` when this resolves.\n throw error;\n }\n }\n\n async cancel(params: IScheduleDialogPresenterCancelParams): Promise<void> {\n this.loading = true;\n\n try {\n await this.cancelGateway.execute(params);\n runInAction(() => {\n this.entry = null;\n this.loading = false;\n });\n } catch (error) {\n runInAction(() => {\n this.loading = false;\n });\n throw error;\n }\n }\n\n reset(): void {\n this.entry = null;\n this.loading = false;\n }\n}\n\nexport const ScheduleDialogPresenter = Abstraction.createImplementation({\n implementation: ScheduleDialogPresenterImpl,\n dependencies: [\n GetScheduledActionGateway,\n CancelScheduledActionGateway,\n SchedulePublishActionGateway,\n ScheduleUnpublishActionGateway,\n DateFormatter\n ]\n});\n"],"names":["ScheduleDialogPresenterImpl","getGateway","cancelGateway","publishGateway","unpublishGateway","dateFormatter","makeAutoObservable","entry","scheduleOn","actionName","ScheduleActionType","formatUtcOffset","params","runInAction","error","targetId","namespace","actionType","Error","ScheduleDialogPresenter","Abstraction","GetScheduledActionGateway","CancelScheduledActionGateway","SchedulePublishActionGateway","ScheduleUnpublishActionGateway","DateFormatter"],"mappings":";;;;;;;;AAmBA,MAAMA;IAIF,YACqBC,UAA+C,EAC/CC,aAAqD,EACrDC,cAAsD,EACtDC,gBAA0D,EAC1DC,aAAsC,CACzD;aALmBJ,UAAU,GAAVA;aACAC,aAAa,GAAbA;aACAC,cAAc,GAAdA;aACAC,gBAAgB,GAAhBA;aACAC,aAAa,GAAbA;aARb,OAAO,GAAG;aACV,KAAK,GAA0B;QASnCC,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;oBACI,MAAM,IAAIU,MAAM,CAAC,yBAAyB,EAAED,WAAW,EAAE,CAAC;YAClE;YACAJ,YAAY;gBACR,IAAI,CAAC,KAAK,GAAG;gBACb,IAAI,CAAC,OAAO,GAAG;YACnB;QACJ,EAAE,OAAOC,OAAO;YACZD,YAAY;gBACR,IAAI,CAAC,OAAO,GAAG;YACnB;YAEA,MAAMC;QACV;IACJ;IAEA,MAAM,OAAOF,MAA4C,EAAiB;QACtE,IAAI,CAAC,OAAO,GAAG;QAEf,IAAI;YACA,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAACA;YACjCC,YAAY;gBACR,IAAI,CAAC,KAAK,GAAG;gBACb,IAAI,CAAC,OAAO,GAAG;YACnB;QACJ,EAAE,OAAOC,OAAO;YACZD,YAAY;gBACR,IAAI,CAAC,OAAO,GAAG;YACnB;YACA,MAAMC;QACV;IACJ;IAEA,QAAc;QACV,IAAI,CAAC,KAAK,GAAG;QACb,IAAI,CAAC,OAAO,GAAG;IACnB;AACJ;AAEO,MAAMK,kDAA0BC,wBAAAA,oBAAgC,CAAC;IACpE,gBAAgBpB;IAChB,cAAc;QACVqB;QACAC;QACAC;QACAC;QACAC;KACH;AACL"}
|
|
@@ -17,7 +17,7 @@ const setup = (params)=>{
|
|
|
17
17
|
});
|
|
18
18
|
const container = new Container();
|
|
19
19
|
container.registerInstance(GetScheduledActionGateway, {
|
|
20
|
-
execute: vi.fn()
|
|
20
|
+
execute: params.getExecute ?? vi.fn()
|
|
21
21
|
});
|
|
22
22
|
container.registerInstance(CancelScheduledActionGateway, {
|
|
23
23
|
execute
|
|
@@ -72,6 +72,32 @@ describe("ScheduleDialogPresenter", ()=>{
|
|
|
72
72
|
})).resolves.toBeUndefined();
|
|
73
73
|
expect(presenter.vm.loading).toBe(false);
|
|
74
74
|
});
|
|
75
|
+
it("rejects when loading the scheduled action fails", async ()=>{
|
|
76
|
+
const presenter = setup({
|
|
77
|
+
fail: false,
|
|
78
|
+
getExecute: async ()=>{
|
|
79
|
+
throw new Error("Could not fetch scheduled action.");
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
await expect(presenter.load({
|
|
83
|
+
namespace: "cms/article",
|
|
84
|
+
id: "entry-1"
|
|
85
|
+
})).rejects.toThrow("Could not fetch scheduled action.");
|
|
86
|
+
expect(presenter.vm.loading).toBe(false);
|
|
87
|
+
expect(presenter.vm.entry).toBeNull();
|
|
88
|
+
});
|
|
89
|
+
it("resolves with no entry when nothing is scheduled", async ()=>{
|
|
90
|
+
const presenter = setup({
|
|
91
|
+
fail: false,
|
|
92
|
+
getExecute: async ()=>null
|
|
93
|
+
});
|
|
94
|
+
await expect(presenter.load({
|
|
95
|
+
namespace: "cms/article",
|
|
96
|
+
id: "entry-1"
|
|
97
|
+
})).resolves.toBeUndefined();
|
|
98
|
+
expect(presenter.vm.loading).toBe(false);
|
|
99
|
+
expect(presenter.vm.entry).toBeNull();
|
|
100
|
+
});
|
|
75
101
|
});
|
|
76
102
|
|
|
77
103
|
//# sourceMappingURL=ScheduleDialogPresenter.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/scheduleDialog/ScheduleDialogPresenter.test.js","sources":["../../../src/presentation/scheduleDialog/ScheduleDialogPresenter.test.ts"],"sourcesContent":["// @vitest-environment jsdom\nimport { describe, it, expect, vi } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { DateFormatter } from \"@webiny/app-admin\";\nimport { GetScheduledActionGateway } from \"~/features/getScheduledAction/abstractions.js\";\nimport { CancelScheduledActionGateway } from \"~/features/cancelScheduledAction/abstractions.js\";\nimport { SchedulePublishActionGateway } from \"~/features/schedulePublishAction/abstractions.js\";\nimport { ScheduleUnpublishActionGateway } from \"~/features/scheduleUnpublishAction/abstractions.js\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport { ScheduleDialogPresenter as Abstraction } from \"./abstractions.js\";\nimport { ScheduleDialogPresenter } from \"./ScheduleDialogPresenter.js\";\n\n/*\n * `useScheduleDialog` shows a success toast and runs `onCompleted` once `schedule()` or\n * `cancel()` resolves, and shows the error when they reject. So a failed action must reject,\n * and the dialog must not be left loading.\n */\nconst setup = (params: { fail: boolean }) => {\n const execute = vi.fn(async () => {\n if (params.fail) {\n throw new Error(\"Could not schedule the action.\");\n }\n return { item: {} };\n });\n\n const container = new Container();\n container.registerInstance(GetScheduledActionGateway, {
|
|
1
|
+
{"version":3,"file":"presentation/scheduleDialog/ScheduleDialogPresenter.test.js","sources":["../../../src/presentation/scheduleDialog/ScheduleDialogPresenter.test.ts"],"sourcesContent":["// @vitest-environment jsdom\nimport { describe, it, expect, vi } from \"vitest\";\nimport { Container } from \"@webiny/di\";\nimport { DateFormatter } from \"@webiny/app-admin\";\nimport { GetScheduledActionGateway } from \"~/features/getScheduledAction/abstractions.js\";\nimport { CancelScheduledActionGateway } from \"~/features/cancelScheduledAction/abstractions.js\";\nimport { SchedulePublishActionGateway } from \"~/features/schedulePublishAction/abstractions.js\";\nimport { ScheduleUnpublishActionGateway } from \"~/features/scheduleUnpublishAction/abstractions.js\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport { ScheduleDialogPresenter as Abstraction } from \"./abstractions.js\";\nimport { ScheduleDialogPresenter } from \"./ScheduleDialogPresenter.js\";\n\n/*\n * `useScheduleDialog` shows a success toast and runs `onCompleted` once `schedule()` or\n * `cancel()` resolves, and shows the error when they reject. So a failed action must reject,\n * and the dialog must not be left loading.\n */\nconst setup = (params: { fail: boolean; getExecute?: () => Promise<unknown> }) => {\n const execute = vi.fn(async () => {\n if (params.fail) {\n throw new Error(\"Could not schedule the action.\");\n }\n return { item: {} };\n });\n\n const container = new Container();\n container.registerInstance(GetScheduledActionGateway, {\n execute: params.getExecute ?? vi.fn()\n } as any);\n container.registerInstance(CancelScheduledActionGateway, { execute } as any);\n container.registerInstance(SchedulePublishActionGateway, { execute } as any);\n container.registerInstance(ScheduleUnpublishActionGateway, { execute } as any);\n container.registerInstance(DateFormatter, { format: () => \"\" } as any);\n container.register(ScheduleDialogPresenter);\n\n return container.resolve(Abstraction);\n};\n\nconst scheduleParams = (actionType: ScheduleActionType) => ({\n namespace: \"cms/article\",\n targetId: \"entry-1#0001\",\n scheduleOn: new Date(\"2030-01-01T10:00:00.000Z\"),\n actionType\n});\n\ndescribe(\"ScheduleDialogPresenter\", () => {\n it.each([ScheduleActionType.publish, ScheduleActionType.unpublish])(\n \"rejects when scheduling %s fails\",\n async actionType => {\n const presenter = setup({ fail: true });\n\n await expect(presenter.schedule(scheduleParams(actionType))).rejects.toThrow(\n \"Could not schedule the action.\"\n );\n expect(presenter.vm.loading).toBe(false);\n }\n );\n\n it(\"rejects when cancelling fails\", async () => {\n const presenter = setup({ fail: true });\n\n await expect(\n presenter.cancel({ id: \"action-1\", namespace: \"cms/article\" })\n ).rejects.toThrow(\"Could not schedule the action.\");\n expect(presenter.vm.loading).toBe(false);\n });\n\n it(\"resolves when scheduling and cancelling succeed\", async () => {\n const presenter = setup({ fail: false });\n\n await expect(\n presenter.schedule(scheduleParams(ScheduleActionType.publish))\n ).resolves.toBeUndefined();\n await expect(\n presenter.cancel({ id: \"action-1\", namespace: \"cms/article\" })\n ).resolves.toBeUndefined();\n expect(presenter.vm.loading).toBe(false);\n });\n\n /*\n * The dialog loads the existing schedule before it opens. A failed load used to leave the\n * entry empty, which reads as \"nothing scheduled\" and invites scheduling a duplicate.\n */\n it(\"rejects when loading the scheduled action fails\", async () => {\n const presenter = setup({\n fail: false,\n getExecute: async () => {\n throw new Error(\"Could not fetch scheduled action.\");\n }\n });\n\n await expect(presenter.load({ namespace: \"cms/article\", id: \"entry-1\" })).rejects.toThrow(\n \"Could not fetch scheduled action.\"\n );\n expect(presenter.vm.loading).toBe(false);\n expect(presenter.vm.entry).toBeNull();\n });\n\n it(\"resolves with no entry when nothing is scheduled\", async () => {\n const presenter = setup({ fail: false, getExecute: async () => null });\n\n await expect(\n presenter.load({ namespace: \"cms/article\", id: \"entry-1\" })\n ).resolves.toBeUndefined();\n expect(presenter.vm.loading).toBe(false);\n expect(presenter.vm.entry).toBeNull();\n });\n});\n"],"names":["setup","params","execute","vi","Error","container","Container","GetScheduledActionGateway","CancelScheduledActionGateway","SchedulePublishActionGateway","ScheduleUnpublishActionGateway","DateFormatter","ScheduleDialogPresenter","Abstraction","scheduleParams","actionType","Date","describe","it","ScheduleActionType","presenter","expect"],"mappings":";;;;;;;;;;AAiBA,MAAMA,QAAQ,CAACC;IACX,MAAMC,UAAUC,GAAG,EAAE,CAAC;QAClB,IAAIF,OAAO,IAAI,EACX,MAAM,IAAIG,MAAM;QAEpB,OAAO;YAAE,MAAM,CAAC;QAAE;IACtB;IAEA,MAAMC,YAAY,IAAIC;IACtBD,UAAU,gBAAgB,CAACE,2BAA2B;QAClD,SAASN,OAAO,UAAU,IAAIE,GAAG,EAAE;IACvC;IACAE,UAAU,gBAAgB,CAACG,8BAA8B;QAAEN;IAAQ;IACnEG,UAAU,gBAAgB,CAACI,8BAA8B;QAAEP;IAAQ;IACnEG,UAAU,gBAAgB,CAACK,gCAAgC;QAAER;IAAQ;IACrEG,UAAU,gBAAgB,CAACM,eAAe;QAAE,QAAQ,IAAM;IAAG;IAC7DN,UAAU,QAAQ,CAACO;IAEnB,OAAOP,UAAU,OAAO,CAACQ;AAC7B;AAEA,MAAMC,iBAAiB,CAACC,aAAoC;QACxD,WAAW;QACX,UAAU;QACV,YAAY,IAAIC,KAAK;QACrBD;IACJ;AAEAE,SAAS,2BAA2B;IAChCC,GAAG,IAAI,CAAC;QAACC,mBAAmB,OAAO;QAAEA,mBAAmB,SAAS;KAAC,EAC9D,oCACA,OAAMJ;QACF,MAAMK,YAAYpB,MAAM;YAAE,MAAM;QAAK;QAErC,MAAMqB,OAAOD,UAAU,QAAQ,CAACN,eAAeC,cAAc,OAAO,CAAC,OAAO,CACxE;QAEJM,OAAOD,UAAU,EAAE,CAAC,OAAO,EAAE,IAAI,CAAC;IACtC;IAGJF,GAAG,iCAAiC;QAChC,MAAME,YAAYpB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|
get vm(): IScheduleDialogPresenterViewModel;
|
|
27
|
+
/**
|
|
28
|
+
* Rejects when loading fails. Resolves with `vm.entry` set to null when nothing is scheduled, so
|
|
29
|
+
* the two can't be confused.
|
|
30
|
+
*/
|
|
27
31
|
load(params: IScheduleDialogPresenterLoadParams): Promise<void>;
|
|
28
32
|
/** Rejects when scheduling fails, so the caller can show the error. */
|
|
29
33
|
schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/scheduleDialog/abstractions.js","sources":["../../../src/presentation/scheduleDialog/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { ScheduleActionType, SchedulerEntry } from \"~/types.js\";\n\nexport interface IScheduleDialogRescheduling {\n actionName: string;\n scheduleOn: string;\n}\n\nexport interface IScheduleDialogPresenterViewModel {\n loading: boolean;\n entry: SchedulerEntry | null;\n rescheduling: IScheduleDialogRescheduling | null;\n}\n\nexport interface IScheduleDialogPresenterLoadParams {\n namespace: string;\n id: string;\n}\n\nexport interface IScheduleDialogPresenterScheduleParams {\n targetId: string;\n namespace: string;\n scheduleOn: Date;\n actionType: ScheduleActionType;\n}\n\nexport interface IScheduleDialogPresenterCancelParams {\n id: string;\n namespace: string;\n}\n\nexport interface IScheduleDialogPresenter {\n get vm(): IScheduleDialogPresenterViewModel;\n load(params: IScheduleDialogPresenterLoadParams): Promise<void>;\n /** Rejects when scheduling fails, so the caller can show the error. */\n schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void>;\n /** Rejects when cancelling fails, so the caller can show the error. */\n cancel(params: IScheduleDialogPresenterCancelParams): Promise<void>;\n reset(): void;\n}\n\nexport const ScheduleDialogPresenter = createAbstraction<IScheduleDialogPresenter>(\n \"Scheduler/ScheduleDialogPresenter\"\n);\n\nexport namespace ScheduleDialogPresenter {\n export type Interface = IScheduleDialogPresenter;\n}\n"],"names":["ScheduleDialogPresenter","createAbstraction"],"mappings":";
|
|
1
|
+
{"version":3,"file":"presentation/scheduleDialog/abstractions.js","sources":["../../../src/presentation/scheduleDialog/abstractions.ts"],"sourcesContent":["import { createAbstraction } from \"@webiny/feature/admin\";\nimport type { ScheduleActionType, SchedulerEntry } from \"~/types.js\";\n\nexport interface IScheduleDialogRescheduling {\n actionName: string;\n scheduleOn: string;\n}\n\nexport interface IScheduleDialogPresenterViewModel {\n loading: boolean;\n entry: SchedulerEntry | null;\n rescheduling: IScheduleDialogRescheduling | null;\n}\n\nexport interface IScheduleDialogPresenterLoadParams {\n namespace: string;\n id: string;\n}\n\nexport interface IScheduleDialogPresenterScheduleParams {\n targetId: string;\n namespace: string;\n scheduleOn: Date;\n actionType: ScheduleActionType;\n}\n\nexport interface IScheduleDialogPresenterCancelParams {\n id: string;\n namespace: string;\n}\n\nexport interface IScheduleDialogPresenter {\n get vm(): IScheduleDialogPresenterViewModel;\n /**\n * Rejects when loading fails. Resolves with `vm.entry` set to null when nothing is scheduled, so\n * the two can't be confused.\n */\n load(params: IScheduleDialogPresenterLoadParams): Promise<void>;\n /** Rejects when scheduling fails, so the caller can show the error. */\n schedule(params: IScheduleDialogPresenterScheduleParams): Promise<void>;\n /** Rejects when cancelling fails, so the caller can show the error. */\n cancel(params: IScheduleDialogPresenterCancelParams): Promise<void>;\n reset(): void;\n}\n\nexport const ScheduleDialogPresenter = createAbstraction<IScheduleDialogPresenter>(\n \"Scheduler/ScheduleDialogPresenter\"\n);\n\nexport namespace ScheduleDialogPresenter {\n export type Interface = IScheduleDialogPresenter;\n}\n"],"names":["ScheduleDialogPresenter","createAbstraction"],"mappings":";AA6CO,MAAMA,0BAA0BC,kBACnC"}
|
|
@@ -78,10 +78,21 @@ const useScheduleDialog = (props)=>{
|
|
|
78
78
|
presenter: presenter
|
|
79
79
|
}),
|
|
80
80
|
formData: async ()=>{
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
try {
|
|
82
|
+
await presenter.load({
|
|
83
|
+
namespace,
|
|
84
|
+
id: target.id
|
|
85
|
+
});
|
|
86
|
+
} catch (error) {
|
|
87
|
+
toast.showWarningToast({
|
|
88
|
+
title: error.message
|
|
89
|
+
});
|
|
90
|
+
if (dialogClose.current) {
|
|
91
|
+
dialogClose.current();
|
|
92
|
+
dialogClose.current = null;
|
|
93
|
+
}
|
|
94
|
+
return {};
|
|
95
|
+
}
|
|
85
96
|
const entry = presenter.vm.entry;
|
|
86
97
|
const scheduleOn = entry?.publishOn || entry?.unpublishOn;
|
|
87
98
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"presentation/scheduleDialog/useScheduleDialog.js","sources":["../../../src/presentation/scheduleDialog/useScheduleDialog.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useRef } from \"react\";\nimport { useContainer } from \"@webiny/app\";\nimport { useToast } from \"@webiny/admin-ui\";\nimport { useDialogs } from \"@webiny/app-admin\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport { ScheduleDialogPresenter } from \"./abstractions.js\";\nimport { FormComponent } from \"./components/FormComponent.js\";\nimport { CancelButtonComponent } from \"./components/CancelButtonComponent.js\";\n\nexport type ShowDialogParamsEntryStatus = \"published\" | \"unpublished\" | \"draft\" | string;\n\nexport interface IShowDialogParamsEntry {\n id: string;\n status: ShowDialogParamsEntryStatus;\n title: string;\n}\n\ninterface UseShowScheduleDialogResponse {\n showDialog: () => void;\n}\n\ninterface ScheduleFormData {\n scheduleOn?: string;\n}\n\ninterface IOnAcceptParams {\n scheduleOn: Date;\n actionType: ScheduleActionType;\n}\n\nexport interface IUseScheduleDialogProps {\n namespace: string;\n target: IShowDialogParamsEntry;\n /**\n * Called after a scheduled action is successfully created/updated or cancelled. Use it to\n * refresh anything that displays the scheduled state (e.g. list cells, form banners).\n */\n onCompleted?: () => void;\n}\n\nexport const useScheduleDialog = (\n props: IUseScheduleDialogProps\n): UseShowScheduleDialogResponse => {\n const { target, namespace, onCompleted } = props;\n const container = useContainer();\n const dialog = useDialogs();\n const toast = useToast();\n\n const presenter = useMemo(() => {\n return container.resolve(ScheduleDialogPresenter);\n }, [container]);\n\n const dialogClose = useRef<null | (() => void)>(() => {\n return;\n });\n\n const onAccept = useCallback(\n async (params: IOnAcceptParams) => {\n const { scheduleOn, actionType } = params;\n\n try {\n await presenter.schedule({\n targetId: target.id,\n namespace,\n scheduleOn,\n actionType\n });\n toast.showSuccessToast({\n title: `Scheduled ${actionType} action for \"${target.title}\"!`\n });\n onCompleted?.();\n } catch (error) {\n toast.showWarningToast({ title: error.message });\n console.error(error);\n }\n },\n [presenter.vm]\n );\n\n const onCancel = useCallback(async () => {\n const entry = presenter.vm.entry;\n if (!entry) {\n toast.showWarningToast({ title: `No scheduled action found for \"${target.title}\"!` });\n if (dialogClose.current) {\n dialogClose.current();\n dialogClose.current = null;\n }\n return;\n }\n\n if (dialogClose.current) {\n dialogClose.current();\n dialogClose.current = null;\n }\n\n try {\n await presenter.cancel({\n id: entry.id,\n namespace: entry.namespace\n });\n toast.showSuccessToast({\n title: `Canceled scheduled ${entry.actionType} on \"${entry.title}\"!`\n });\n onCompleted?.();\n } catch (error) {\n toast.showWarningToast({ title: error.message });\n }\n }, [presenter.vm]);\n\n const showDialog = async () => {\n const isPublished = target.status === \"published\";\n\n dialogClose.current = dialog.showDialog({\n title: `Schedule \"${target.title}\"`,\n content: <FormComponent presenter={presenter} />,\n formData: async () => {\n await presenter.load({ namespace, id: target.id });\n\n const entry = presenter.vm.entry;\n const scheduleOn = entry?.publishOn || entry?.unpublishOn;\n\n return { scheduleOn };\n },\n acceptLabel: isPublished ? \"Schedule Unpublish\" : \"Schedule Publish\",\n cancelLabel: \"Discard\",\n loadingLabel: \"Scheduling...\",\n dataLoadingLabel: \"Checking schedule...\",\n info: <CancelButtonComponent presenter={presenter} onCancel={onCancel} />,\n dismissible: false,\n onAccept: (data: Partial<ScheduleFormData>) => {\n if (!data.scheduleOn) {\n toast.showWarningToast({ title: `Missing \"Schedule On\" date!` });\n return;\n }\n let scheduleOn: Date;\n try {\n scheduleOn = new Date(data.scheduleOn);\n } catch (ex) {\n toast.showWarningToast({ title: `Invalid \"Schedule On\" date!` });\n console.error(ex);\n return;\n }\n\n const actionType = isPublished\n ? ScheduleActionType.unpublish\n : ScheduleActionType.publish;\n\n return onAccept({\n scheduleOn,\n actionType\n });\n }\n });\n };\n\n return {\n showDialog\n };\n};\n"],"names":["useScheduleDialog","props","target","namespace","onCompleted","container","useContainer","dialog","useDialogs","toast","useToast","presenter","useMemo","ScheduleDialogPresenter","dialogClose","useRef","onAccept","useCallback","params","scheduleOn","actionType","error","console","onCancel","entry","showDialog","isPublished","FormComponent","CancelButtonComponent","data","Date","ex","ScheduleActionType"],"mappings":";;;;;;;;AAwCO,MAAMA,oBAAoB,CAC7BC;IAEA,MAAM,EAAEC,MAAM,EAAEC,SAAS,EAAEC,WAAW,EAAE,GAAGH;IAC3C,MAAMI,YAAYC;IAClB,MAAMC,SAASC;IACf,MAAMC,QAAQC;IAEd,MAAMC,YAAYC,QAAQ,IACfP,UAAU,OAAO,CAACQ,0BAC1B;QAACR;KAAU;IAEd,MAAMS,cAAcC,OAA4B,KAEhD;IAEA,MAAMC,WAAWC,YACb,OAAOC;QACH,MAAM,EAAEC,UAAU,EAAEC,UAAU,EAAE,GAAGF;QAEnC,IAAI;YACA,MAAMP,UAAU,QAAQ,CAAC;gBACrB,UAAUT,OAAO,EAAE;gBACnBC;gBACAgB;gBACAC;YACJ;YACAX,MAAM,gBAAgB,CAAC;gBACnB,OAAO,CAAC,UAAU,EAAEW,WAAW,aAAa,EAAElB,OAAO,KAAK,CAAC,EAAE,CAAC;YAClE;YACAE;QACJ,EAAE,OAAOiB,OAAO;YACZZ,MAAM,gBAAgB,CAAC;gBAAE,OAAOY,MAAM,OAAO;YAAC;YAC9CC,QAAQ,KAAK,CAACD;QAClB;IACJ,GACA;QAACV,UAAU,EAAE;KAAC;IAGlB,MAAMY,WAAWN,YAAY;QACzB,MAAMO,QAAQb,UAAU,EAAE,CAAC,KAAK;QAChC,IAAI,CAACa,OAAO;YACRf,MAAM,gBAAgB,CAAC;gBAAE,OAAO,CAAC,+BAA+B,EAAEP,OAAO,KAAK,CAAC,EAAE,CAAC;YAAC;YACnF,IAAIY,YAAY,OAAO,EAAE;gBACrBA,YAAY,OAAO;gBACnBA,YAAY,OAAO,GAAG;YAC1B;YACA;QACJ;QAEA,IAAIA,YAAY,OAAO,EAAE;YACrBA,YAAY,OAAO;YACnBA,YAAY,OAAO,GAAG;QAC1B;QAEA,IAAI;YACA,MAAMH,UAAU,MAAM,CAAC;gBACnB,IAAIa,MAAM,EAAE;gBACZ,WAAWA,MAAM,SAAS;YAC9B;YACAf,MAAM,gBAAgB,CAAC;gBACnB,OAAO,CAAC,mBAAmB,EAAEe,MAAM,UAAU,CAAC,KAAK,EAAEA,MAAM,KAAK,CAAC,EAAE,CAAC;YACxE;YACApB;QACJ,EAAE,OAAOiB,OAAO;YACZZ,MAAM,gBAAgB,CAAC;gBAAE,OAAOY,MAAM,OAAO;YAAC;QAClD;IACJ,GAAG;QAACV,UAAU,EAAE;KAAC;IAEjB,MAAMc,aAAa;QACf,MAAMC,cAAcxB,AAAkB,gBAAlBA,OAAO,MAAM;QAEjCY,YAAY,OAAO,GAAGP,OAAO,UAAU,CAAC;YACpC,OAAO,CAAC,UAAU,EAAEL,OAAO,KAAK,CAAC,CAAC,CAAC;YACnC,SAAS,WAAT,GAAS,oBAACyB,eAAaA;gBAAC,WAAWhB;;YACnC,UAAU;gBACN,MAAMA,UAAU,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"presentation/scheduleDialog/useScheduleDialog.js","sources":["../../../src/presentation/scheduleDialog/useScheduleDialog.tsx"],"sourcesContent":["import React, { useCallback, useMemo, useRef } from \"react\";\nimport { useContainer } from \"@webiny/app\";\nimport { useToast } from \"@webiny/admin-ui\";\nimport { useDialogs } from \"@webiny/app-admin\";\nimport { ScheduleActionType } from \"~/types.js\";\nimport { ScheduleDialogPresenter } from \"./abstractions.js\";\nimport { FormComponent } from \"./components/FormComponent.js\";\nimport { CancelButtonComponent } from \"./components/CancelButtonComponent.js\";\n\nexport type ShowDialogParamsEntryStatus = \"published\" | \"unpublished\" | \"draft\" | string;\n\nexport interface IShowDialogParamsEntry {\n id: string;\n status: ShowDialogParamsEntryStatus;\n title: string;\n}\n\ninterface UseShowScheduleDialogResponse {\n showDialog: () => void;\n}\n\ninterface ScheduleFormData {\n scheduleOn?: string;\n}\n\ninterface IOnAcceptParams {\n scheduleOn: Date;\n actionType: ScheduleActionType;\n}\n\nexport interface IUseScheduleDialogProps {\n namespace: string;\n target: IShowDialogParamsEntry;\n /**\n * Called after a scheduled action is successfully created/updated or cancelled. Use it to\n * refresh anything that displays the scheduled state (e.g. list cells, form banners).\n */\n onCompleted?: () => void;\n}\n\nexport const useScheduleDialog = (\n props: IUseScheduleDialogProps\n): UseShowScheduleDialogResponse => {\n const { target, namespace, onCompleted } = props;\n const container = useContainer();\n const dialog = useDialogs();\n const toast = useToast();\n\n const presenter = useMemo(() => {\n return container.resolve(ScheduleDialogPresenter);\n }, [container]);\n\n const dialogClose = useRef<null | (() => void)>(() => {\n return;\n });\n\n const onAccept = useCallback(\n async (params: IOnAcceptParams) => {\n const { scheduleOn, actionType } = params;\n\n try {\n await presenter.schedule({\n targetId: target.id,\n namespace,\n scheduleOn,\n actionType\n });\n toast.showSuccessToast({\n title: `Scheduled ${actionType} action for \"${target.title}\"!`\n });\n onCompleted?.();\n } catch (error) {\n toast.showWarningToast({ title: error.message });\n console.error(error);\n }\n },\n [presenter.vm]\n );\n\n const onCancel = useCallback(async () => {\n const entry = presenter.vm.entry;\n if (!entry) {\n toast.showWarningToast({ title: `No scheduled action found for \"${target.title}\"!` });\n if (dialogClose.current) {\n dialogClose.current();\n dialogClose.current = null;\n }\n return;\n }\n\n if (dialogClose.current) {\n dialogClose.current();\n dialogClose.current = null;\n }\n\n try {\n await presenter.cancel({\n id: entry.id,\n namespace: entry.namespace\n });\n toast.showSuccessToast({\n title: `Canceled scheduled ${entry.actionType} on \"${entry.title}\"!`\n });\n onCompleted?.();\n } catch (error) {\n toast.showWarningToast({ title: error.message });\n }\n }, [presenter.vm]);\n\n const showDialog = async () => {\n const isPublished = target.status === \"published\";\n\n dialogClose.current = dialog.showDialog({\n title: `Schedule \"${target.title}\"`,\n content: <FormComponent presenter={presenter} />,\n formData: async () => {\n try {\n await presenter.load({ namespace, id: target.id });\n } catch (error) {\n /*\n * Without the current schedule the dialog can't tell a new action from a\n * duplicate, so show the error and close it instead of offering the form.\n */\n toast.showWarningToast({ title: error.message });\n if (dialogClose.current) {\n dialogClose.current();\n dialogClose.current = null;\n }\n return {};\n }\n\n const entry = presenter.vm.entry;\n const scheduleOn = entry?.publishOn || entry?.unpublishOn;\n\n return { scheduleOn };\n },\n acceptLabel: isPublished ? \"Schedule Unpublish\" : \"Schedule Publish\",\n cancelLabel: \"Discard\",\n loadingLabel: \"Scheduling...\",\n dataLoadingLabel: \"Checking schedule...\",\n info: <CancelButtonComponent presenter={presenter} onCancel={onCancel} />,\n dismissible: false,\n onAccept: (data: Partial<ScheduleFormData>) => {\n if (!data.scheduleOn) {\n toast.showWarningToast({ title: `Missing \"Schedule On\" date!` });\n return;\n }\n let scheduleOn: Date;\n try {\n scheduleOn = new Date(data.scheduleOn);\n } catch (ex) {\n toast.showWarningToast({ title: `Invalid \"Schedule On\" date!` });\n console.error(ex);\n return;\n }\n\n const actionType = isPublished\n ? ScheduleActionType.unpublish\n : ScheduleActionType.publish;\n\n return onAccept({\n scheduleOn,\n actionType\n });\n }\n });\n };\n\n return {\n showDialog\n };\n};\n"],"names":["useScheduleDialog","props","target","namespace","onCompleted","container","useContainer","dialog","useDialogs","toast","useToast","presenter","useMemo","ScheduleDialogPresenter","dialogClose","useRef","onAccept","useCallback","params","scheduleOn","actionType","error","console","onCancel","entry","showDialog","isPublished","FormComponent","CancelButtonComponent","data","Date","ex","ScheduleActionType"],"mappings":";;;;;;;;AAwCO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