-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/src/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ( | ||
<IconButton | ||
icon={<SyncIcon />} | ||
onAction={openSyncDialog} | ||
label={"Sync"} | ||
tooltipPlacement={"bottom"} | ||
disabled={worker.isSelectedAll} | ||
/> | ||
); | ||
}; | ||
|
||
export const Extension = () => { | ||
return ( | ||
<> | ||
<ContentEntryListConfig> | ||
<BulkAction | ||
name={"sync"} | ||
element={<ActionSync />} | ||
/> | ||
</ContentEntryListConfig> | ||
</> | ||
); | ||
}; |
4 changes: 4 additions & 0 deletions
4
headless-cms/bulk-action-asynchronous/5.41.x/extensions/admin/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src"] | ||
} |