Skip to content

Commit

Permalink
feat: add 5.41.x extension
Browse files Browse the repository at this point in the history
  • Loading branch information
leopuleo committed Oct 11, 2024
1 parent 07a626b commit 193f43a
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
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"
}
}
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>
</>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src"]
}

0 comments on commit 193f43a

Please sign in to comment.