Skip to content

Commit

Permalink
fix(app-headless-cms): use raw API for bulk actions [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
Pavel910 committed May 13, 2024
1 parent b937697 commit a9012b4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React, { useMemo } from "react";
import { ReactComponent as DeleteIcon } from "@material-design-icons/svg/outlined/delete.svg";
import { observer } from "mobx-react-lite";
import { parseIdentifier } from "@webiny/utils/parseIdentifier";
import { useRecords } from "@webiny/app-aco";
import { ContentEntryListConfig } from "~/admin/config/contentEntries";
import { useContentEntry } from "~/admin/hooks";
import { useCms, useModel } from "~/admin/hooks";
import { getEntriesLabel } from "~/admin/components/ContentEntries/BulkActions/BulkActions";
import { parseIdentifier } from "@webiny/utils/parseIdentifier";

export const ActionDelete = observer(() => {
const { deleteEntry } = useContentEntry();
const { model } = useModel();
const { deleteEntry } = useCms();
const { removeRecordFromCache } = useRecords();

const { useWorker, useButtons, useDialog } = ContentEntryListConfig.Browser.BulkAction;
const { IconButton } = useButtons();
Expand All @@ -31,7 +34,7 @@ export const ActionDelete = observer(() => {
* By sending an entryId (id without #version), we are telling to the API to delete all revisions.
*/
const { id } = parseIdentifier(item.id);
const response = await deleteEntry({ id });
const response = await deleteEntry({ model, id });

if (typeof response !== "boolean") {
throw new Error(
Expand All @@ -40,6 +43,8 @@ export const ActionDelete = observer(() => {
);
}

removeRecordFromCache(id);

report.success({
title: `${item.meta.title}`,
message: "Entry successfully moved to trash."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React, { useMemo } from "react";
import { ReactComponent as PublishIcon } from "@material-design-icons/svg/outlined/publish.svg";
import { observer } from "mobx-react-lite";
import { ContentEntryListConfig } from "~/admin/config/contentEntries";
import { usePermission, useContentEntry } from "~/admin/hooks";
import { usePermission, useCms, useModel } from "~/admin/hooks";
import { getEntriesLabel } from "~/admin/components/ContentEntries/BulkActions/BulkActions";
import { useRecords } from "@webiny/app-aco";

export const ActionPublish = observer(() => {
const { model } = useModel();
const { canPublish } = usePermission();
const { publishEntryRevision } = useContentEntry();
const { publishEntryRevision } = useCms();
const { updateRecordInCache } = useRecords();

const { useWorker, useButtons, useDialog } = ContentEntryListConfig.Browser.BulkAction;
const { IconButton } = useButtons();
Expand All @@ -26,7 +29,7 @@ export const ActionPublish = observer(() => {
execute: async () => {
await worker.processInSeries(async ({ item, report }) => {
try {
const response = await publishEntryRevision({ id: item.id });
const response = await publishEntryRevision({ model, id: item.id });

const { error } = response;

Expand All @@ -36,6 +39,8 @@ export const ActionPublish = observer(() => {
);
}

updateRecordInCache(response.entry);

report.success({
title: `${item.meta.title}`,
message: "Entry successfully published."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import React, { useMemo } from "react";
import { ReactComponent as UnpublishIcon } from "@material-design-icons/svg/outlined/settings_backup_restore.svg";
import { observer } from "mobx-react-lite";
import { ContentEntryListConfig } from "~/admin/config/contentEntries";
import { useContentEntry, usePermission } from "~/admin/hooks";
import { useCms, useModel, usePermission } from "~/admin/hooks";
import { getEntriesLabel } from "~/admin/components/ContentEntries/BulkActions/BulkActions";
import { useRecords } from "@webiny/app-aco";

export const ActionUnpublish = observer(() => {
const { model } = useModel();
const { canUnpublish } = usePermission();
const { unpublishEntryRevision } = useContentEntry();
const { unpublishEntryRevision } = useCms();
const { updateRecordInCache } = useRecords();

const { useWorker, useButtons, useDialog } = ContentEntryListConfig.Browser.BulkAction;
const { IconButton } = useButtons();
Expand All @@ -27,6 +30,7 @@ export const ActionUnpublish = observer(() => {
await worker.processInSeries(async ({ item, report }) => {
try {
const response = await unpublishEntryRevision({
model,
id: item.id
});

Expand All @@ -38,6 +42,8 @@ export const ActionUnpublish = observer(() => {
);
}

updateRecordInCache(response.entry);

report.success({
title: `${item.meta.title}`,
message: "Entry successfully unpublished."
Expand Down

0 comments on commit a9012b4

Please sign in to comment.