Skip to content

Commit

Permalink
Editor: Move publish panel handling to editor store (#60340)
Browse files Browse the repository at this point in the history
Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
Co-authored-by: youknowriad <youknowriad@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
  • Loading branch information
4 people authored Apr 1, 2024
1 parent fc78ac9 commit 91ea8fa
Show file tree
Hide file tree
Showing 13 changed files with 149 additions and 41 deletions.
8 changes: 8 additions & 0 deletions docs/reference-guides/data/data-core-edit-post.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ _Returns_

### isPublishSidebarOpened

> **Deprecated**
Returns true if the publish sidebar is opened.

_Parameters_
Expand Down Expand Up @@ -350,6 +352,8 @@ _Returns_

### closePublishSidebar

> **Deprecated**
Returns an action object used in signalling that the user closed the publish sidebar.

_Returns_
Expand Down Expand Up @@ -408,6 +412,8 @@ _Returns_

### openPublishSidebar

> **Deprecated**
Returns an action object used in signalling that the user opened the publish sidebar.

_Returns_
Expand Down Expand Up @@ -532,6 +538,8 @@ _Parameters_

### togglePublishSidebar

> **Deprecated**
Returns an action object used in signalling that the user toggles the publish sidebar.

_Returns_
Expand Down
36 changes: 36 additions & 0 deletions docs/reference-guides/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,18 @@ _Returns_

- `boolean`: Whether the pre-publish panel should be shown or not.

### isPublishSidebarOpened

Returns true if the publish sidebar is opened.

_Parameters_

- _state_ `Object`: Global application state

_Returns_

- `boolean`: Whether the publish sidebar is open.

### isSavingNonPostEntityChanges

Returns true if non-post entities are currently being saved, or false otherwise.
Expand Down Expand Up @@ -1120,6 +1132,14 @@ _Related_

- clearSelectedBlock in core/block-editor store.

### closePublishSidebar

Returns an action object used in signalling that the user closed the publish sidebar.

_Returns_

- `Object`: Action object.

### createUndoLevel

> **Deprecated** Since WordPress 6.0
Expand Down Expand Up @@ -1273,6 +1293,14 @@ _Related_

- multiSelect in core/block-editor store.

### openPublishSidebar

Returns an action object used in signalling that the user opened the publish sidebar.

_Returns_

- `Object`: Action object

### receiveBlocks

_Related_
Expand Down Expand Up @@ -1522,6 +1550,14 @@ _Parameters_

- _panelName_ `string`: A string that identifies the panel to open or close.

### togglePublishSidebar

Returns an action object used in signalling that the user toggles the publish sidebar.

_Returns_

- `Object`: Action object

### toggleSelection

_Related_
Expand Down
2 changes: 1 addition & 1 deletion packages/data/src/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function resolveSelect( storeNameOrDescriptor, selectorName, ...args ) {
*
* // Action generator using dispatch
* export function* myAction() {
* yield controls.dispatch( 'core/edit-post', 'togglePublishSidebar' );
* yield controls.dispatch( 'core/editor', 'togglePublishSidebar' );
* // do some other things.
* }
* ```
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function Header( { setEntitiesSavedStatesCallback, initialPost } ) {
!! select( editorStore ).getEditorSettings()
.onNavigateToPreviousEntityRecord,
isPublishSidebarOpened:
select( editPostStore ).isPublishSidebarOpened(),
select( editorStore ).isPublishSidebarOpened(),
showIconLabels: getPreference( 'core', 'showIconLabels' ),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ import { useViewportMatch, compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
import { PostPublishButton, store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
*/
import { store as editPostStore } from '../../store';

export function PostPublishButtonOrToggle( {
forceIsDirty,
hasPublishAction,
Expand Down Expand Up @@ -85,12 +80,11 @@ export default compose(
isPublished: select( editorStore ).isCurrentPostPublished(),
isPublishSidebarEnabled:
select( editorStore ).isPublishSidebarEnabled(),
isPublishSidebarOpened:
select( editPostStore ).isPublishSidebarOpened(),
isPublishSidebarOpened: select( editorStore ).isPublishSidebarOpened(),
isScheduled: select( editorStore ).isCurrentPostScheduled(),
} ) ),
withDispatch( ( dispatch ) => {
const { togglePublishSidebar } = dispatch( editPostStore );
const { togglePublishSidebar } = dispatch( editorStore );
return {
togglePublishSidebar,
};
Expand Down
5 changes: 3 additions & 2 deletions packages/edit-post/src/components/layout/actions-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { useSelect, useDispatch } from '@wordpress/data';
import { Button, createSlotFill } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useCallback } from '@wordpress/element';

/**
* Internal dependencies
*/
Expand All @@ -27,15 +28,15 @@ export default function ActionsPanel( {
isEntitiesSavedStatesOpen,
} ) {
const { closePublishSidebar, togglePublishSidebar } =
useDispatch( editPostStore );
useDispatch( editorStore );
const {
publishSidebarOpened,
hasActiveMetaboxes,
hasNonPostEntityChanges,
} = useSelect(
( select ) => ( {
publishSidebarOpened:
select( editPostStore ).isPublishSidebarOpened(),
select( editorStore ).isPublishSidebarOpened(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
hasNonPostEntityChanges:
select( editorStore ).hasNonPostEntityChanges(),
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-post/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function Layout( { initialPost } ) {
sidebarIsOpened: !! (
select( interfaceStore ).getActiveComplementaryArea(
editPostStore.name
) || select( editPostStore ).isPublishSidebarOpened()
) || select( editorStore ).isPublishSidebarOpened()
),
isFullscreenActive:
select( editPostStore ).isFeatureActive( 'fullscreenMode' ),
Expand Down
39 changes: 27 additions & 12 deletions packages/edit-post/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,37 +78,52 @@ export const closeModal =
/**
* Returns an action object used in signalling that the user opened the publish
* sidebar.
* @deprecated
*
* @return {Object} Action object
*/
export function openPublishSidebar() {
return {
type: 'OPEN_PUBLISH_SIDEBAR',
export const openPublishSidebar =
() =>
( { registry } ) => {
deprecated( "dispatch( 'core/edit-post' ).openPublishSidebar", {
since: '6.6',
alternative: "dispatch( 'core/editor').openPublishSidebar",
} );
registry.dispatch( editorStore ).openPublishSidebar();
};
}

/**
* Returns an action object used in signalling that the user closed the
* publish sidebar.
* @deprecated
*
* @return {Object} Action object.
*/
export function closePublishSidebar() {
return {
type: 'CLOSE_PUBLISH_SIDEBAR',
export const closePublishSidebar =
() =>
( { registry } ) => {
deprecated( "dispatch( 'core/edit-post' ).closePublishSidebar", {
since: '6.6',
alternative: "dispatch( 'core/editor').closePublishSidebar",
} );
registry.dispatch( editorStore ).closePublishSidebar();
};
}

/**
* Returns an action object used in signalling that the user toggles the publish sidebar.
* @deprecated
*
* @return {Object} Action object
*/
export function togglePublishSidebar() {
return {
type: 'TOGGLE_PUBLISH_SIDEBAR',
export const togglePublishSidebar =
() =>
( { registry } ) => {
deprecated( "dispatch( 'core/edit-post' ).togglePublishSidebar", {
since: '6.6',
alternative: "dispatch( 'core/editor').togglePublishSidebar",
} );
registry.dispatch( editorStore ).togglePublishSidebar();
};
}

/**
* Returns an action object used to enable or disable a panel in the editor.
Expand Down
13 changes: 0 additions & 13 deletions packages/edit-post/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@
*/
import { combineReducers } from '@wordpress/data';

export function publishSidebarActive( state = false, action ) {
switch ( action.type ) {
case 'OPEN_PUBLISH_SIDEBAR':
return true;
case 'CLOSE_PUBLISH_SIDEBAR':
return false;
case 'TOGGLE_PUBLISH_SIDEBAR':
return ! state;
}
return state;
}

/**
* Reducer keeping track of the meta boxes isSaving state.
* A "true" value means the meta boxes saving request is in-flight.
Expand Down Expand Up @@ -103,5 +91,4 @@ const metaBoxes = combineReducers( {

export default combineReducers( {
metaBoxes,
publishSidebarActive,
} );
14 changes: 11 additions & 3 deletions packages/edit-post/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,21 @@ export const getHiddenBlockTypes = createRegistrySelector( ( select ) => () => {
/**
* Returns true if the publish sidebar is opened.
*
* @deprecated
*
* @param {Object} state Global application state
*
* @return {boolean} Whether the publish sidebar is open.
*/
export function isPublishSidebarOpened( state ) {
return state.publishSidebarActive;
}
export const isPublishSidebarOpened = createRegistrySelector(
( select ) => () => {
deprecated( `select( 'core/edit-post' ).isPublishSidebarOpened`, {
since: '6.6',
alternative: `select( 'core/editor' ).isPublishSidebarOpened`,
} );
return select( editorStore ).isPublishSidebarOpened();
}
);

/**
* Returns true if the given panel was programmatically removed, or false otherwise.
Expand Down
35 changes: 35 additions & 0 deletions packages/editor/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,41 @@ export const switchEditorMode =
}
};

/**
* Returns an action object used in signalling that the user opened the publish
* sidebar.
*
* @return {Object} Action object
*/
export function openPublishSidebar() {
return {
type: 'OPEN_PUBLISH_SIDEBAR',
};
}

/**
* Returns an action object used in signalling that the user closed the
* publish sidebar.
*
* @return {Object} Action object.
*/
export function closePublishSidebar() {
return {
type: 'CLOSE_PUBLISH_SIDEBAR',
};
}

/**
* Returns an action object used in signalling that the user toggles the publish sidebar.
*
* @return {Object} Action object
*/
export function togglePublishSidebar() {
return {
type: 'TOGGLE_PUBLISH_SIDEBAR',
};
}

/**
* Backward compatibility
*/
Expand Down
13 changes: 13 additions & 0 deletions packages/editor/src/store/reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@ export function listViewToggleRef( state = { current: null } ) {
return state;
}

export function publishSidebarActive( state = false, action ) {
switch ( action.type ) {
case 'OPEN_PUBLISH_SIDEBAR':
return true;
case 'CLOSE_PUBLISH_SIDEBAR':
return false;
case 'TOGGLE_PUBLISH_SIDEBAR':
return ! state;
}
return state;
}

export default combineReducers( {
postId,
postType,
Expand All @@ -377,4 +389,5 @@ export default combineReducers( {
blockInserterPanel,
listViewPanel,
listViewToggleRef,
publishSidebarActive,
} );
11 changes: 11 additions & 0 deletions packages/editor/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1788,3 +1788,14 @@ export const getPostTypeLabel = createRegistrySelector(
return postType?.labels?.singular_name;
}
);

/**
* Returns true if the publish sidebar is opened.
*
* @param {Object} state Global application state
*
* @return {boolean} Whether the publish sidebar is open.
*/
export function isPublishSidebarOpened( state ) {
return state.publishSidebarActive;
}

0 comments on commit 91ea8fa

Please sign in to comment.