Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor package: no-string-literals fix #32153

Merged
merged 2 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/editor/src/components/autosave-monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
import { Component } from '@wordpress/element';
import { compose } from '@wordpress/compose';
import { withSelect, withDispatch } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

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

/**
* AutosaveMonitor invokes `props.autosave()` within at most `interval` seconds after an unsaved change is detected.
Expand Down Expand Up @@ -82,14 +88,14 @@ export class AutosaveMonitor extends Component {

export default compose( [
withSelect( ( select, ownProps ) => {
const { getReferenceByDistinctEdits } = select( 'core' );
const { getReferenceByDistinctEdits } = select( coreStore );

const {
isEditedPostDirty,
isEditedPostAutosaveable,
isAutosavingPost,
getEditorSettings,
} = select( 'core/editor' );
} = select( editorStore );

const { interval = getEditorSettings().autosaveInterval } = ownProps;

Expand All @@ -103,7 +109,7 @@ export default compose( [
} ),
withDispatch( ( dispatch, ownProps ) => ( {
autosave() {
const { autosave = dispatch( 'core/editor' ).autosave } = ownProps;
const { autosave = dispatch( editorStore ).autosave } = ownProps;
autosave();
},
} ) ),
Expand Down
7 changes: 6 additions & 1 deletion packages/editor/src/components/character-count/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import { useSelect } from '@wordpress/data';
import { count as characterCount } from '@wordpress/wordcount';

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

export default function CharacterCount() {
const content = useSelect( ( select ) =>
select( 'core/editor' ).getEditedPostAttribute( 'content' )
select( editorStore ).getEditedPostAttribute( 'content' )
);

return characterCount( content, 'characters_including_spaces' );
Expand Down
6 changes: 4 additions & 2 deletions packages/editor/src/components/document-outline/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import { compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { create, getTextContent } from '@wordpress/rich-text';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import DocumentOutlineItem from './item';
import { store as editorStore } from '../../store';

/**
* Module constants
Expand Down Expand Up @@ -146,8 +148,8 @@ export const DocumentOutline = ( {
export default compose(
withSelect( ( select ) => {
const { getBlocks } = select( blockEditorStore );
const { getEditedPostAttribute } = select( 'core/editor' );
const { getPostType } = select( 'core' );
const { getEditedPostAttribute } = select( editorStore );
const { getPostType } = select( coreStore );
const postType = getPostType( getEditedPostAttribute( 'type' ) );

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { useCallback } from '@wordpress/element';
import { store as blockEditorStore } from '@wordpress/block-editor';
import { store as coreStore } from '@wordpress/core-data';

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

export default function EntityRecordItem( {
record,
Expand All @@ -16,7 +22,7 @@ export default function EntityRecordItem( {
const { name, kind, title, key } = record;
const parentBlockId = useSelect( ( select ) => {
// Get entity's blocks.
const { blocks = [] } = select( 'core' ).getEditedEntityRecord(
const { blocks = [] } = select( coreStore ).getEditedEntityRecord(
kind,
name,
key
Expand All @@ -36,12 +42,12 @@ export default function EntityRecordItem( {
return title;
}

const template = select( 'core' ).getEditedEntityRecord(
const template = select( coreStore ).getEditedEntityRecord(
kind,
name,
key
);
return select( 'core/editor' ).__experimentalGetTemplateInfo(
return select( editorStore ).__experimentalGetTemplateInfo(
template
).title;
},
Expand Down
7 changes: 6 additions & 1 deletion packages/editor/src/components/error-boundary/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { select } from '@wordpress/data';
import { Warning } from '@wordpress/block-editor';
import { useCopyToClipboard } from '@wordpress/compose';

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

function CopyButton( { text, children } ) {
const ref = useCopyToClipboard( text );
return (
Expand Down Expand Up @@ -45,7 +50,7 @@ class ErrorBoundary extends Component {
// (b) avoids the performance cost associated with unnecessary
// content serialization throughout the lifetime of a non-erroring
// application.
return select( 'core/editor' ).getEditedPostContent();
return select( editorStore ).getEditedPostContent();
} catch ( error ) {}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@ import { useShortcut } from '@wordpress/keyboard-shortcuts';
import { useDispatch, useSelect } from '@wordpress/data';
import { parse } from '@wordpress/blocks';

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

function SaveShortcut( { resetBlocksOnSave } ) {
const { resetEditorBlocks, savePost } = useDispatch( 'core/editor' );
const { resetEditorBlocks, savePost } = useDispatch( editorStore );
const { isEditedPostDirty, getPostEdits } = useSelect( ( select ) => {
const {
isEditedPostDirty: _isEditedPostDirty,
getPostEdits: _getPostEdits,
} = select( 'core/editor' );
} = select( editorStore );

return {
isEditedPostDirty: _isEditedPostDirty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import { BlockEditorKeyboardShortcuts } from '@wordpress/block-editor';
* Internal dependencies
*/
import SaveShortcut from './save-shortcut';
import { store as editorStore } from '../../store';

function VisualEditorGlobalKeyboardShortcuts() {
const { redo, undo } = useDispatch( 'core/editor' );
const { redo, undo } = useDispatch( editorStore );

useShortcut(
'core/editor/undo',
Expand Down
25 changes: 13 additions & 12 deletions packages/editor/src/components/local-autosave-monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { store as noticesStore } from '@wordpress/notices';
*/
import AutosaveMonitor from '../autosave-monitor';
import { localAutosaveGet, localAutosaveClear } from '../../store/controls';
import { store as editorStore } from '../../store';

const requestIdleCallback = window.requestIdleCallback
? window.requestIdleCallback
Expand Down Expand Up @@ -48,19 +49,19 @@ const hasSessionStorageSupport = once( () => {
function useAutosaveNotice() {
const { postId, isEditedPostNew, hasRemoteAutosave } = useSelect(
( select ) => ( {
postId: select( 'core/editor' ).getCurrentPostId(),
isEditedPostNew: select( 'core/editor' ).isEditedPostNew(),
getEditedPostAttribute: select( 'core/editor' )
postId: select( editorStore ).getCurrentPostId(),
isEditedPostNew: select( editorStore ).isEditedPostNew(),
getEditedPostAttribute: select( editorStore )
.getEditedPostAttribute,
hasRemoteAutosave: !! select( 'core/editor' ).getEditorSettings()
hasRemoteAutosave: !! select( editorStore ).getEditorSettings()
.autosave,
} ),
[]
);
const { getEditedPostAttribute } = useSelect( 'core/editor' );

const { createWarningNotice, removeNotice } = useDispatch( noticesStore );
const { editPost, resetEditorBlocks } = useDispatch( 'core/editor' );
const { editPost, resetEditorBlocks } = useDispatch( editorStore );

useEffect( () => {
let localAutosave = localAutosaveGet( postId, isEditedPostNew );
Expand Down Expand Up @@ -130,11 +131,11 @@ function useAutosavePurge() {
didError,
} = useSelect(
( select ) => ( {
postId: select( 'core/editor' ).getCurrentPostId(),
isEditedPostNew: select( 'core/editor' ).isEditedPostNew(),
isDirty: select( 'core/editor' ).isEditedPostDirty(),
isAutosaving: select( 'core/editor' ).isAutosavingPost(),
didError: select( 'core/editor' ).didPostSaveRequestFail(),
postId: select( editorStore ).getCurrentPostId(),
isEditedPostNew: select( editorStore ).isEditedPostNew(),
isDirty: select( editorStore ).isEditedPostDirty(),
isAutosaving: select( editorStore ).isAutosavingPost(),
didError: select( editorStore ).didPostSaveRequestFail(),
} ),
[]
);
Expand Down Expand Up @@ -166,7 +167,7 @@ function useAutosavePurge() {
}

function LocalAutosaveMonitor() {
const { autosave } = useDispatch( 'core/editor' );
const { autosave } = useDispatch( editorStore );
const deferedAutosave = useCallback( () => {
requestIdleCallback( () => autosave( { local: true } ) );
}, [] );
Expand All @@ -175,7 +176,7 @@ function LocalAutosaveMonitor() {

const { localAutosaveInterval } = useSelect(
( select ) => ( {
localAutosaveInterval: select( 'core/editor' ).getEditorSettings()
localAutosaveInterval: select( editorStore ).getEditorSettings()
.__experimentalLocalAutosaveInterval,
} ),
[]
Expand Down
7 changes: 3 additions & 4 deletions packages/editor/src/components/page-attributes/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { compose, withState } from '@wordpress/compose';
* Internal dependencies
*/
import PostTypeSupportCheck from '../post-type-support-check';
import { store as editorStore } from '../../store';

export const PageAttributesOrder = withState( {
orderInput: null,
Expand Down Expand Up @@ -60,14 +61,12 @@ function PageAttributesOrderWithChecks( props ) {
export default compose( [
withSelect( ( select ) => {
return {
order: select( 'core/editor' ).getEditedPostAttribute(
'menu_order'
),
order: select( editorStore ).getEditedPostAttribute( 'menu_order' ),
};
} ),
withDispatch( ( dispatch ) => ( {
onUpdateOrder( order ) {
dispatch( 'core/editor' ).editPost( {
dispatch( editorStore ).editPost( {
menu_order: order,
} );
},
Expand Down
8 changes: 5 additions & 3 deletions packages/editor/src/components/page-attributes/parent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import { ComboboxControl } from '@wordpress/components';
import { useState, useMemo } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import { buildTermsTree } from '../../utils/terms';
import { store as editorStore } from '../../store';

function getTitle( post ) {
return post?.title?.rendered
Expand All @@ -46,15 +48,15 @@ export const getItemPriority = ( name, searchValue ) => {
};

export function PageAttributesParent() {
const { editPost } = useDispatch( 'core/editor' );
const { editPost } = useDispatch( editorStore );
const [ fieldValue, setFieldValue ] = useState( false );
const { parentPost, parentPostId, items, postType } = useSelect(
( select ) => {
const { getPostType, getEntityRecords, getEntityRecord } = select(
'core'
coreStore
);
const { getCurrentPostId, getEditedPostAttribute } = select(
'core/editor'
editorStore
);
const postTypeSlug = getEditedPostAttribute( 'type' );
const pageId = getEditedPostAttribute( 'parent' );
Expand Down
8 changes: 5 additions & 3 deletions packages/editor/src/components/post-author/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { get } from 'lodash';
*/
import { withInstanceId, compose } from '@wordpress/compose';
import { withSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
*/
import PostTypeSupportCheck from '../post-type-support-check';
import { store as editorStore } from '../../store';

export function PostAuthorCheck( {
hasAssignAuthorAction,
Expand All @@ -32,15 +34,15 @@ export function PostAuthorCheck( {

export default compose( [
withSelect( ( select ) => {
const post = select( 'core/editor' ).getCurrentPost();
const post = select( editorStore ).getCurrentPost();
return {
hasAssignAuthorAction: get(
post,
[ '_links', 'wp:action-assign-author' ],
false
),
postType: select( 'core/editor' ).getCurrentPostType(),
authors: select( 'core' ).getAuthors(),
postType: select( editorStore ).getCurrentPostType(),
authors: select( coreStore ).getAuthors(),
};
} ),
withInstanceId,
Expand Down
12 changes: 9 additions & 3 deletions packages/editor/src/components/post-author/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ import { useState, useMemo, useEffect } from '@wordpress/element';
import { useSelect, useDispatch } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { ComboboxControl } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';

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

function PostAuthorCombobox() {
const [ fieldValue, setFieldValue ] = useState();

const { authorId, isLoading, authors, postAuthor } = useSelect(
( select ) => {
const { __unstableGetAuthor, getAuthors, isResolving } = select(
'core'
coreStore
);
const { getEditedPostAttribute } = select( 'core/editor' );
const { getEditedPostAttribute } = select( editorStore );
const author = __unstableGetAuthor(
getEditedPostAttribute( 'author' )
);
Expand All @@ -34,7 +40,7 @@ function PostAuthorCombobox() {
},
[ fieldValue ]
);
const { editPost } = useDispatch( 'core/editor' );
const { editPost } = useDispatch( editorStore );

const authorOptions = useMemo( () => {
const fetchedAuthors = ( authors ?? [] ).map( ( author ) => {
Expand Down
12 changes: 9 additions & 3 deletions packages/editor/src/components/post-author/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import { __ } from '@wordpress/i18n';
import { useSelect, useDispatch } from '@wordpress/data';
import { decodeEntities } from '@wordpress/html-entities';
import { SelectControl } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';

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

function PostAuthorSelect() {
const { editPost } = useDispatch( 'core/editor' );
const { editPost } = useDispatch( editorStore );
const { postAuthor, authors } = useSelect( ( select ) => {
const authorsFromAPI = select( 'core' ).getAuthors();
const authorsFromAPI = select( coreStore ).getAuthors();
return {
postAuthor: select( 'core/editor' ).getEditedPostAttribute(
postAuthor: select( editorStore ).getEditedPostAttribute(
'author'
),
authors: authorsFromAPI.map( ( author ) => ( {
Expand Down
Loading