Skip to content

Commit

Permalink
Fix deprecated dependencies moved from @wordpress/edit-post to @wordp…
Browse files Browse the repository at this point in the history
…ress/editor
  • Loading branch information
renatho committed Jul 29, 2024
1 parent f13414e commit c594d47
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
*/
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';

/**
* Internal dependencies
*/
import SenseiIcon from '../../icons/logo-tree.svg';

if ( ! PluginPrePublishPanel ) {
PluginPrePublishPanel = DeprecatedPluginPrePublishPanel;
}

/**
* Course pre-publish panel.
*/
Expand Down
13 changes: 11 additions & 2 deletions assets/blocks/quiz/question-block/single-question.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 11 additions & 2 deletions assets/blocks/quiz/quiz-block/quiz-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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.
*
Expand Down
36 changes: 32 additions & 4 deletions assets/js/admin/course-settings-plugin-sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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 }`
);
}
Expand Down

0 comments on commit c594d47

Please sign in to comment.