From c594d4793e379c40aa5f554d51428a8afd606652 Mon Sep 17 00:00:00 2001 From: Renatho De Carli Rosa Date: Mon, 29 Jul 2024 19:18:50 -0300 Subject: [PATCH] Fix deprecated dependencies moved from @wordpress/edit-post to @wordpress/editor --- .../course-pre-publish-panel.js | 7 +++- .../quiz/question-block/single-question.js | 13 +++++-- .../blocks/quiz/quiz-block/quiz-validation.js | 13 +++++-- .../admin/course-settings-plugin-sidebar.js | 36 ++++++++++++++++--- 4 files changed, 60 insertions(+), 9 deletions(-) diff --git a/assets/admin/course-pre-publish-panel/course-pre-publish-panel.js b/assets/admin/course-pre-publish-panel/course-pre-publish-panel.js index 1face149d0..796f3673bd 100644 --- a/assets/admin/course-pre-publish-panel/course-pre-publish-panel.js +++ b/assets/admin/course-pre-publish-panel/course-pre-publish-panel.js @@ -3,7 +3,8 @@ */ import { __ } from '@wordpress/i18n'; import { useEntityProp } from '@wordpress/core-data'; -import { PluginPrePublishPanel } from '@wordpress/edit-post'; +import { PluginPrePublishPanel as DeprecatedPluginPrePublishPanel } from '@wordpress/edit-post'; +import { PluginPrePublishPanel } from '@wordpress/editor'; import { ToggleControl } from '@wordpress/components'; /** @@ -11,6 +12,10 @@ import { ToggleControl } from '@wordpress/components'; */ import SenseiIcon from '../../icons/logo-tree.svg'; +if ( ! PluginPrePublishPanel ) { + PluginPrePublishPanel = DeprecatedPluginPrePublishPanel; +} + /** * Course pre-publish panel. */ diff --git a/assets/blocks/quiz/question-block/single-question.js b/assets/blocks/quiz/question-block/single-question.js index 57cfb6b0cb..d39c0fb4f2 100644 --- a/assets/blocks/quiz/question-block/single-question.js +++ b/assets/blocks/quiz/question-block/single-question.js @@ -5,15 +5,24 @@ import { Notice } from '@wordpress/components'; import { useCallback } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { - PluginPostStatusInfo, - PluginPrePublishPanel, + PluginPostStatusInfo as DeprecatedPluginPostStatusInfo, + PluginPrePublishPanel as DeprecatedPluginPrePublishPanel, } from '@wordpress/edit-post'; +import { PluginPostStatusInfo, PluginPrePublishPanel } from '@wordpress/editor'; /** * Internal dependencies */ import { Effect, usePostSavingEffect } from '../../../shared/helpers/blocks'; +if ( ! PluginPostStatusInfo ) { + PluginPostStatusInfo = DeprecatedPluginPostStatusInfo; +} + +if ( ! PluginPrePublishPanel ) { + PluginPrePublishPanel = DeprecatedPluginPrePublishPanel; +} + /** * Additional controls for a question block in the single question editor. * diff --git a/assets/blocks/quiz/quiz-block/quiz-validation.js b/assets/blocks/quiz/quiz-block/quiz-validation.js index 9d077ba0a1..1126b0c814 100644 --- a/assets/blocks/quiz/quiz-block/quiz-validation.js +++ b/assets/blocks/quiz/quiz-block/quiz-validation.js @@ -4,9 +4,10 @@ import { Notice } from '@wordpress/components'; import { useDispatch, useSelect } from '@wordpress/data'; import { - PluginPostStatusInfo, - PluginPrePublishPanel, + PluginPostStatusInfo as DeprecatedPluginPostStatusInfo, + PluginPrePublishPanel as DeprecatedPluginPrePublishPanel, } from '@wordpress/edit-post'; +import { PluginPostStatusInfo, PluginPrePublishPanel } from '@wordpress/editor'; import { useCallback } from '@wordpress/element'; import { __, _n, sprintf } from '@wordpress/i18n'; @@ -16,6 +17,14 @@ import { __, _n, sprintf } from '@wordpress/i18n'; import { BLOCK_META_STORE } from '../../../shared/blocks/block-metadata'; import { Effect, usePostSavingEffect } from '../../../shared/helpers/blocks'; +if ( ! PluginPostStatusInfo ) { + PluginPostStatusInfo = DeprecatedPluginPostStatusInfo; +} + +if ( ! PluginPrePublishPanel ) { + PluginPrePublishPanel = DeprecatedPluginPrePublishPanel; +} + /** * Notice about incomplete questions in the quiz. * diff --git a/assets/js/admin/course-settings-plugin-sidebar.js b/assets/js/admin/course-settings-plugin-sidebar.js index b64b5c9805..e438cd77f6 100644 --- a/assets/js/admin/course-settings-plugin-sidebar.js +++ b/assets/js/admin/course-settings-plugin-sidebar.js @@ -3,10 +3,17 @@ */ import { applyFilters } from '@wordpress/hooks'; import { + store as editPostStore, + PluginDocumentSettingPanel as DeprecatedPluginDocumentSettingPanel, + PluginSidebar as DeprecatedPluginSidebar, + PluginSidebarMoreMenuItem as DeprecatedPluginSidebarMoreMenuItem, +} from '@wordpress/edit-post'; +import { + store as editorStore, PluginDocumentSettingPanel, PluginSidebar, PluginSidebarMoreMenuItem, -} from '@wordpress/edit-post'; +} from '@wordpress/editor'; import { __ } from '@wordpress/i18n'; import { dispatch, useSelect } from '@wordpress/data'; import { Slot } from '@wordpress/components'; @@ -21,6 +28,18 @@ import CourseVideoSidebar from './course-video-sidebar'; import CourseGeneralSidebar from './course-general-sidebar'; import SenseiIcon from '../../icons/logo-tree.svg'; +if ( ! PluginDocumentSettingPanel ) { + PluginDocumentSettingPanel = DeprecatedPluginDocumentSettingPanel; +} + +if ( ! PluginSidebar ) { + PluginSidebar = DeprecatedPluginSidebar; +} + +if ( ! PluginSidebarMoreMenuItem ) { + PluginSidebarMoreMenuItem = DeprecatedPluginSidebarMoreMenuItem; +} + export const pluginSidebarHandle = 'sensei-lms-course-settings-sidebar'; export const pluginDocumentHandle = 'sensei-lms-document-settings-sidebar'; @@ -73,17 +92,26 @@ export const CourseSidebar = () => { export const SenseiSettingsDocumentSidebar = () => { const isSenseiEditorPanelOpen = useSelect( ( select ) => { - return select( 'core/edit-post' ).isEditorPanelOpened( + const isEditorPanelOpened = select( editorStore ).isEditorPanelOpened + ? select( editorStore ).isEditorPanelOpened + : select( editPostStore ).isEditorPanelOpened; + + return isEditorPanelOpened( `${ pluginDocumentHandle }/${ pluginDocumentHandle }` ); } ); if ( isSenseiEditorPanelOpen ) { + const toggleEditorPanelOpened = dispatch( editorStore ) + .toggleEditorPanelOpened + ? dispatch( editorStore ).toggleEditorPanelOpened + : dispatch( editPostStore ).toggleEditorPanelOpened; + // when 'Course Settings' is clicked, isSenseiEditorPanelOpen returns true, so we open the 'Course Settings' // plugin sidebar and then close the 'Sensei Settings' panel which sets isSenseiEditorPanelOpen back to false. - dispatch( 'core/edit-post' ).openGeneralSidebar( + dispatch( editPostStore ).openGeneralSidebar( `${ pluginSidebarHandle }/${ pluginSidebarHandle }` ); - dispatch( 'core/edit-post' ).toggleEditorPanelOpened( + toggleEditorPanelOpened( `${ pluginDocumentHandle }/${ pluginDocumentHandle }` ); }