Disable editing of trashed workflows

[MAILPOET-4417]
This commit is contained in:
David Remer
2022-08-17 11:38:52 +03:00
committed by Veljko V
parent 3dd37fa5b7
commit 2bec938336
2 changed files with 33 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ import {
FullscreenMode,
} from '@wordpress/interface';
import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
import { addQueryArgs } from '@wordpress/url';
import { Header } from './components/header';
import { InserterSidebar } from './components/inserter-sidebar';
import { KeyboardShortcuts } from './components/keyboard-shortcuts';
@@ -18,6 +19,7 @@ import { store, storeName } from './store';
import { initializeApi } from '../api';
import { initialize as initializeCoreIntegration } from '../integrations/core';
import { initialize as initializeMailPoetIntegration } from '../integrations/mailpoet';
import { MailPoet } from '../../mailpoet';
// See:
// https://github.com/WordPress/gutenberg/blob/9601a33e30ba41bac98579c8d822af63dd961488/packages/edit-post/src/components/layout/index.js
@@ -29,12 +31,14 @@ function Editor(): JSX.Element {
isInserterOpened,
isSidebarOpened,
showIconLabels,
workflow,
} = useSelect(
(select) => ({
isFullscreenActive: select(store).isFeatureActive('fullscreenMode'),
isInserterOpened: select(store).isInserterSidebarOpened(),
isSidebarOpened: select(store).isSidebarOpened(),
showIconLabels: select(store).isFeatureActive('showIconLabels'),
workflow: select(store).getWorkflowData(),
}),
[],
);
@@ -44,6 +48,12 @@ function Editor(): JSX.Element {
'show-icon-labels': showIconLabels,
});
if (workflow.status === 'trash') {
window.location.href = addQueryArgs(MailPoet.urls.automationListing, {
'mailpoet-had-been-deleted': workflow.id,
});
return null;
}
return (
<ShortcutProvider>
<SlotFillProvider>

View File

@@ -3,16 +3,32 @@ import { __ } from '@wordpress/i18n';
import { Notice } from '../../notices/notice';
export function WorkflowListingNotices(): JSX.Element {
const workflowHadBeenDeleted = parseInt(
getQueryArg(window.location.href, 'mailpoet-had-been-deleted') as string,
10,
);
const workflowDeleted = parseInt(
getQueryArg(window.location.href, 'mailpoet-workflow-deleted') as string,
10,
);
if (!workflowDeleted) {
return null;
if (workflowHadBeenDeleted) {
return (
<Notice type="error" closable timeout={false}>
<p>
{__(
'You cannot edit this automation because it is in the Trash.',
'mailpoet',
)}
</p>
</Notice>
);
}
return (
<Notice type="success" closable timeout={false}>
<p>{__('1 workflow moved to the Trash.', 'mailpoet')}</p>
</Notice>
);
if (workflowDeleted) {
return (
<Notice type="success" closable timeout={false}>
<p>{__('1 workflow moved to the Trash.', 'mailpoet')}</p>
</Notice>
);
}
return null;
}