Skip to content

Commit

Permalink
Edit Post: Replace store name string with exposed store definition (#…
Browse files Browse the repository at this point in the history
…27414)

* Exporting store definition

* Removing 'block-editor' references to the store name

* Removing 'block-directory' references to the store name

* Removing 'block-library' references to the store name

* Removing 'components' references to the store name

* Removing 'edit-post' references to the store name

* Removing 'editor' references to the store name

* Reverting changes that caused cyclic dependencies
Reverting commits that removed `"edit-post"` hardcoded store name on `"components"` and `"block-editor"` packages, due to cyclic dependencies, as referenced in #27414 (this commit will be used as baseline later).

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* Update packages/block-library/package.json

* Apply suggestions from code review

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
  • Loading branch information
rafaelgallani and gziolo authored Dec 17, 2020
1 parent 9162d90 commit c88866c
Show file tree
Hide file tree
Showing 49 changed files with 256 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { noop } from 'lodash';
* WordPress dependencies
*/
import { useDispatch } from '@wordpress/data';
import { store as editPostStore } from '@wordpress/edit-post';

/**
* Internal dependencies
Expand All @@ -16,7 +17,7 @@ import { store as blockDirectoryStore } from '../../store';

function DownloadableBlocksList( { items, onHover = noop, onSelect } ) {
const { installBlockType } = useDispatch( blockDirectoryStore );
const { setIsInserterOpened } = useDispatch( 'core/edit-post' );
const { setIsInserterOpened } = useDispatch( editPostStore );

if ( ! items.length ) {
return null;
Expand Down
12 changes: 12 additions & 0 deletions packages/edit-post/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,18 @@ _Parameters_
- _settings_ `?Object`: Editor settings object.
- _initialEdits_ `Object`: Programmatic edits to apply initially, to be considered as non-user-initiated (bypass for unsaved changes prompt).

<a name="store" href="#store">#</a> **store**

Store definition for the edit post namespace.

_Related_

- <https://github.com/WordPress/gutenberg/blob/master/packages/data/README.md#createReduxStore>

_Type_

- `Object`


<!-- END TOKEN(Autogenerated API docs) -->

Expand Down
13 changes: 9 additions & 4 deletions packages/edit-post/src/components/device-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { __ } from '@wordpress/i18n';
import { __experimentalPreviewOptions as PreviewOptions } from '@wordpress/block-editor';
import { useDispatch, useSelect } from '@wordpress/data';

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

export default function DevicePreview() {
const {
hasActiveMetaboxes,
Expand All @@ -16,18 +21,18 @@ export default function DevicePreview() {
deviceType,
} = useSelect(
( select ) => ( {
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
isSaving: select( editPostStore ).isSavingMetaBoxes(),
isPostSaveable: select( 'core/editor' ).isEditedPostSaveable(),
deviceType: select(
'core/edit-post'
editPostStore
).__experimentalGetPreviewDeviceType(),
} ),
[]
);
const {
__experimentalSetPreviewDeviceType: setPreviewDeviceType,
} = useDispatch( 'core/edit-post' );
} = useDispatch( editPostStore );

return (
<PreviewOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import { __ } from '@wordpress/i18n';
import { check } from '@wordpress/icons';
import { speak } from '@wordpress/a11y';

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

function FeatureToggle( {
onToggle,
isActive,
Expand Down Expand Up @@ -46,11 +51,11 @@ function FeatureToggle( {

export default compose( [
withSelect( ( select, { feature } ) => ( {
isActive: select( 'core/edit-post' ).isFeatureActive( feature ),
isActive: select( editPostStore ).isFeatureActive( feature ),
} ) ),
withDispatch( ( dispatch, ownProps ) => ( {
onToggle() {
dispatch( 'core/edit-post' ).toggleFeature( ownProps.feature );
dispatch( editPostStore ).toggleFeature( ownProps.feature );
},
} ) ),
] )( FeatureToggle );
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { wordpress } from '@wordpress/icons';

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

function FullscreenModeClose( { showTooltip, icon, href } ) {
const { isActive, isRequestingSiteIcon, postType, siteIconUrl } = useSelect(
( select ) => {
const { getCurrentPostType } = select( 'core/editor' );
const { isFeatureActive } = select( 'core/edit-post' );
const { isFeatureActive } = select( editPostStore );
const { isResolving } = select( 'core/data' );
const { getEntityRecord, getPostType } = select( 'core' );
const siteData =
Expand Down
17 changes: 9 additions & 8 deletions packages/edit-post/src/components/header/header-toolbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import { useRef } from '@wordpress/element';
* Internal dependencies
*/
import TemplateTitle from '../template-title';
import { store as editPostStore } from '../../../store';

function HeaderToolbar() {
const inserterButton = useRef();
const { setIsInserterOpened } = useDispatch( 'core/edit-post' );
const { setIsInserterOpened } = useDispatch( editPostStore );
const {
hasFixedToolbar,
isInserterEnabled,
Expand All @@ -54,28 +55,28 @@ function HeaderToolbar() {
getBlockSelectionEnd,
} = select( 'core/block-editor' );
return {
hasFixedToolbar: select( 'core/edit-post' ).isFeatureActive(
hasFixedToolbar: select( editPostStore ).isFeatureActive(
'fixedToolbar'
),
// This setting (richEditingEnabled) should not live in the block editor's setting.
isInserterEnabled:
select( 'core/edit-post' ).getEditorMode() === 'visual' &&
select( editPostStore ).getEditorMode() === 'visual' &&
select( 'core/editor' ).getEditorSettings()
.richEditingEnabled &&
hasInserterItems(
getBlockRootClientId( getBlockSelectionEnd() )
),
isInserterOpened: select( 'core/edit-post' ).isInserterOpened(),
isInserterOpened: select( editPostStore ).isInserterOpened(),
isTextModeEnabled:
select( 'core/edit-post' ).getEditorMode() === 'text',
select( editPostStore ).getEditorMode() === 'text',
previewDeviceType: select(
'core/edit-post'
editPostStore
).__experimentalGetPreviewDeviceType(),
showIconLabels: select( 'core/edit-post' ).isFeatureActive(
showIconLabels: select( editPostStore ).isFeatureActive(
'showIconLabels'
),
isNavigationTool: select( 'core/block-editor' ).isNavigationMode(),
isTemplateMode: select( 'core/edit-post' ).isEditingTemplate(),
isTemplateMode: select( editPostStore ).isEditingTemplate(),
};
}, [] );
const isLargeViewport = useViewportMatch( 'medium' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
* Internal dependencies
*/
import styles from './style.scss';
import { store as editPostStore } from '../../../store';

function HeaderToolbar( {
hasRedo,
Expand Down Expand Up @@ -110,10 +111,9 @@ export default compose( [
hasUndo: select( 'core/editor' ).hasEditorUndo(),
// This setting (richEditingEnabled) should not live in the block editor's setting.
showInserter:
select( 'core/edit-post' ).getEditorMode() === 'visual' &&
select( editPostStore ).getEditorMode() === 'visual' &&
select( 'core/editor' ).getEditorSettings().richEditingEnabled,
isTextModeEnabled:
select( 'core/edit-post' ).getEditorMode() === 'text',
isTextModeEnabled: select( editPostStore ).getEditorMode() === 'text',
isRTL: select( 'core/block-editor' ).getSettings().isRTL,
} ) ),
withDispatch( ( dispatch ) => {
Expand Down
13 changes: 7 additions & 6 deletions packages/edit-post/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import PostPublishButtonOrToggle from './post-publish-button-or-toggle';
import { default as DevicePreview } from '../device-preview';
import MainDashboardButton from './main-dashboard-button';
import TemplateSaveButton from './template-save-button';
import { store as editPostStore } from '../../store';

function Header( { setEntitiesSavedStatesCallback } ) {
const {
Expand All @@ -32,18 +33,18 @@ function Header( { setEntitiesSavedStatesCallback } ) {
isEditingTemplate,
} = useSelect(
( select ) => ( {
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
isPublishSidebarOpened: select(
'core/edit-post'
editPostStore
).isPublishSidebarOpened(),
isSaving: select( 'core/edit-post' ).isSavingMetaBoxes(),
showIconLabels: select( 'core/edit-post' ).isFeatureActive(
isSaving: select( editPostStore ).isSavingMetaBoxes(),
showIconLabels: select( editPostStore ).isFeatureActive(
'showIconLabels'
),
hasReducedUI: select( 'core/edit-post' ).isFeatureActive(
hasReducedUI: select( editPostStore ).isFeatureActive(
'reducedUI'
),
isEditingTemplate: select( 'core/edit-post' ).isEditingTemplate(),
isEditingTemplate: select( editPostStore ).isEditingTemplate(),
} ),
[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { MenuItemsChoice, MenuGroup } from '@wordpress/components';
import { useSelect, useDispatch } from '@wordpress/data';
import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';

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

/**
* Set of available mode options.
*
Expand Down Expand Up @@ -37,11 +42,11 @@ function ModeSwitcher() {
.richEditingEnabled,
isCodeEditingEnabled: select( 'core/editor' ).getEditorSettings()
.codeEditingEnabled,
mode: select( 'core/edit-post' ).getEditorMode(),
mode: select( editPostStore ).getEditorMode(),
} ),
[]
);
const { switchEditorMode } = useDispatch( 'core/edit-post' );
const { switchEditorMode } = useDispatch( editPostStore );

if ( ! isRichEditingEnabled || ! isCodeEditingEnabled ) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { useViewportMatch, compose } from '@wordpress/compose';
import { withDispatch, withSelect } from '@wordpress/data';
import { PostPublishButton } from '@wordpress/editor';

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

export function PostPublishButtonOrToggle( {
forceIsDirty,
forceIsSaving,
Expand Down Expand Up @@ -90,12 +95,12 @@ export default compose(
'core/editor'
).isPublishSidebarEnabled(),
isPublishSidebarOpened: select(
'core/edit-post'
editPostStore
).isPublishSidebarOpened(),
isScheduled: select( 'core/editor' ).isCurrentPostScheduled(),
} ) ),
withDispatch( ( dispatch ) => {
const { togglePublishSidebar } = dispatch( 'core/edit-post' );
const { togglePublishSidebar } = dispatch( editPostStore );
return {
togglePublishSidebar,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { withDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { MenuItem } from '@wordpress/components';

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

export function PreferencesMenuItem( { openModal } ) {
return (
<MenuItem
Expand All @@ -18,7 +23,7 @@ export function PreferencesMenuItem( { openModal } ) {
}

export default withDispatch( ( dispatch ) => {
const { openModal } = dispatch( 'core/edit-post' );
const { openModal } = dispatch( editPostStore );

return {
openModal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { compose } from '@wordpress/compose';
import { textFormattingShortcuts } from './config';
import Shortcut from './shortcut';
import DynamicShortcut from './dynamic-shortcut';
import { store as editPostStore } from '../../store';

const MODAL_NAME = 'edit-post/keyboard-shortcut-help';

Expand Down Expand Up @@ -143,10 +144,10 @@ export function KeyboardShortcutHelpModal( { isModalActive, toggleModal } ) {

export default compose( [
withSelect( ( select ) => ( {
isModalActive: select( 'core/edit-post' ).isModalActive( MODAL_NAME ),
isModalActive: select( editPostStore ).isModalActive( MODAL_NAME ),
} ) ),
withDispatch( ( dispatch, { isModalActive } ) => {
const { openModal, closeModal } = dispatch( 'core/edit-post' );
const { openModal, closeModal } = dispatch( editPostStore );

return {
toggleModal: () =>
Expand Down
11 changes: 8 additions & 3 deletions packages/edit-post/src/components/keyboard-shortcuts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import {
} from '@wordpress/keyboard-shortcuts';
import { __ } from '@wordpress/i18n';

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

function KeyboardShortcuts() {
const {
getBlockSelectionStart,
Expand All @@ -21,8 +26,8 @@ function KeyboardShortcuts() {
return {
getBlockSelectionStart: select( 'core/block-editor' )
.getBlockSelectionStart,
getEditorMode: select( 'core/edit-post' ).getEditorMode,
isEditorSidebarOpened: select( 'core/edit-post' )
getEditorMode: select( editPostStore ).getEditorMode,
isEditorSidebarOpened: select( editPostStore )
.isEditorSidebarOpened,
richEditingEnabled: settings.richEditingEnabled,
codeEditingEnabled: settings.codeEditingEnabled,
Expand All @@ -34,7 +39,7 @@ function KeyboardShortcuts() {
openGeneralSidebar,
closeGeneralSidebar,
toggleFeature,
} = useDispatch( 'core/edit-post' );
} = useDispatch( editPostStore );
const { registerShortcut } = useDispatch( keyboardShortcutsStore );

useEffect( () => {
Expand Down
9 changes: 5 additions & 4 deletions packages/edit-post/src/components/layout/actions-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useCallback } from '@wordpress/element';
*/
import PluginPostPublishPanel from '../sidebar/plugin-post-publish-panel';
import PluginPrePublishPanel from '../sidebar/plugin-pre-publish-panel';
import { store as editPostStore } from '../../store';

const { Fill, Slot } = createSlotFill( 'ActionsPanel' );

Expand All @@ -22,7 +23,7 @@ export default function ActionsPanel( {
isEntitiesSavedStatesOpen,
} ) {
const { closePublishSidebar, togglePublishSidebar } = useDispatch(
'core/edit-post'
editPostStore
);
const {
publishSidebarOpened,
Expand All @@ -32,10 +33,10 @@ export default function ActionsPanel( {
} = useSelect( ( select ) => {
return {
publishSidebarOpened: select(
'core/edit-post'
editPostStore
).isPublishSidebarOpened(),
hasActiveMetaboxes: select( 'core/edit-post' ).hasMetaBoxes(),
isSavingMetaBoxes: select( 'core/edit-post' ).isSavingMetaBoxes(),
hasActiveMetaboxes: select( editPostStore ).hasMetaBoxes(),
isSavingMetaBoxes: select( editPostStore ).isSavingMetaBoxes(),
hasNonPostEntityChanges: select(
'core/editor'
).hasNonPostEntityChanges(),
Expand Down
Loading

0 comments on commit c88866c

Please sign in to comment.