Prevent displaying post editor welcome guide

This is rather an edge case when users open the email editor
before they have opened the post editor.
It also happens in acceptance tests.
[MAILPOET-5365]
This commit is contained in:
Rostislav Wolny
2023-08-16 16:19:04 +02:00
committed by Aschepikov
parent ffb644a936
commit 0585dd97ea
3 changed files with 40 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import { useEffect } from '@wordpress/element';
import { useSelect, dispatch } from '@wordpress/data';
import { store as editPostStore } from '@wordpress/edit-post';
// This custom hook disables the post editor welcome guide
export function useDisableWelcomeGuide() {
const { isWelcomeGuideActive } = useSelect((select) => ({
isWelcomeGuideActive: select(editPostStore).isFeatureActive(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// The isFeatureActive accepts an attribute but typescript thinks it doesn't
'welcomeGuide',
),
}));
useEffect(() => {
if (isWelcomeGuideActive) {
dispatch(editPostStore).toggleFeature('welcomeGuide');
}
}, [isWelcomeGuideActive]);
}

View File

@@ -3,6 +3,7 @@ import { useSelect, select as directSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';
import { NextButtonSlot } from './core/components/next_button_slot';
import { useDisableWelcomeGuide } from './core/hooks';
import { NextButton } from './integration/components/next_button';
import { MailPoetEmailData } from './types';
@@ -23,6 +24,9 @@ function Editor() {
) as MailPoetEmailData) ?? null,
}));
// We don't want to show the editor welcome guide as it is not relevant to emails
useDisableWelcomeGuide();
return (
<NextButtonSlot>
<NextButton newsletterId={mailpoetData?.id ?? null} />

View File

@@ -30,6 +30,21 @@ declare module '@wordpress/editor' {
}>;
}
// We need to use code/edit-post store but types are not available yet
declare module '@wordpress/edit-post' {
import * as editPostActions from '@wordpress/edit-post/store/actions';
import * as editPostSelectors from '@wordpress/edit-post/store/selectors';
import { StoreDescriptor as GenericStoreDescriptor } from '@wordpress/data/build-types/types';
export * from '@wordpress/edit-post/index';
export const store: { name: 'core/edit-post' } & GenericStoreDescriptor<{
reducer: () => unknown;
actions: typeof editPostActions;
selectors: typeof editPostSelectors;
}>;
}
// there are no @types/wordpress__interface yet
declare module '@wordpress/interface' {
import { StoreDescriptor } from '@wordpress/data/build-types/types';