diff --git a/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/package.json b/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/package.json new file mode 100644 index 00000000..1a88654c --- /dev/null +++ b/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/package.json @@ -0,0 +1,14 @@ +{ + "name": "@demo/bulk-action-asynchronous", + "main": "src/index.tsx", + "version": "1.0.0", + "keywords": [ + "webiny-extension", + "webiny-extension-type:admin" + ], + "dependencies": { + "@webiny/app-headless-cms": "0.0.0", + "@material-design-icons/svg": "^0.14.3", + "react": "17.0.2" + } +} diff --git a/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/src/index.tsx b/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/src/index.tsx new file mode 100644 index 00000000..0c4014b0 --- /dev/null +++ b/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/src/index.tsx @@ -0,0 +1,76 @@ +import React from "react"; +import { ContentEntryListConfig } from "@webiny/app-headless-cms"; +import { ReactComponent as SyncIcon } from "@material-design-icons/svg/outlined/sync.svg + +const { BulkAction } = ContentEntryListConfig.Browser; +const { useWorker, useButtons, useDialog } = BulkAction; + +const ActionSync = () => { + const { IconButton } = useButtons(); + const worker = useWorker(); + const { showConfirmationDialog, showResultsDialog } = useDialog(); + + const openSyncDialog = () => + showConfirmationDialog({ + title: "Sync", + message: `You are about to sync the selected entries. Are you sure you want to continue?`, + loadingLabel: `Processing`, + execute: async () => { + await worker.processInSeries(async ({ item, report }) => { + try { + const response = await fetch( + "https://any.url.com", + { + method: "POST", + headers: { + "Content-Type": "application/json" + }, + body: JSON.stringify(item.id) + } + ); + + report.success({ + title: item.meta.title, + message: `Entry successfully synced, response status: ${response.status}` + }); + } catch (e) { + report.error({ + title: item.meta.title, + message: e.message + }); + } + }, 5); + + worker.resetItems(); + + showResultsDialog({ + results: worker.results, + title: "Sync", + message: "Operation completed, here below you find the complete report:" + }); + } + }); + + return ( + } + onAction={openSyncDialog} + label={"Sync"} + tooltipPlacement={"bottom"} + disabled={worker.isSelectedAll} + /> + ); +}; + +export const Extension = () => { + return ( + <> + + } + /> + + + ); +}; diff --git a/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/tsconfig.json b/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/tsconfig.json new file mode 100644 index 00000000..596e2cf7 --- /dev/null +++ b/headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src"] +}