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

View File

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