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

Enable post locking in Gutenberg #4217

Merged
merged 119 commits into from Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
119 commits
Select commit Hold shift + click to select a range
4f38c60
Enable post locking via the heartbeat api, following core
Dec 31, 2017
8578fc7
remove interval change
Dec 31, 2017
b370721
Docblock updates
Jan 1, 2018
940f338
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 6, 2018
18290b2
Merge branch 'master' of github.com:WordPress/gutenberg
Jul 6, 2018
aa301d2
Merge branch 'master' into feature/post-locking
Jul 6, 2018
fbf7d08
revert unintended changes
Jul 6, 2018
e387b39
remove nonce handling
Jul 6, 2018
3a3deb9
rename file & setup
Jul 6, 2018
6980a89
Ensure heartbeat interval is low enough to work for post locking
Jul 6, 2018
810119d
Unlock the post when the window is closed or exited.
Jul 6, 2018
c510e37
Fixes for eslint
Jul 6, 2018
a9d7922
Merge branch 'master' into feature/post-locking
Jul 26, 2018
60c6ccc
tabs not spaces
Jul 26, 2018
c611a7b
post locking WIP
Jul 27, 2018
7f35914
Merge branch 'master' of github.com:WordPress/gutenberg
Aug 1, 2018
ca38176
Merge branch 'master' into feature/post-locking
Aug 1, 2018
a5d1764
modal on load first pass
Aug 3, 2018
fd8e941
Merge branch 'master' of github.com:WordPress/gutenberg
Aug 3, 2018
3b500f9
Merge branch 'master' of github.com:WordPress/gutenberg
Aug 6, 2018
f4aa602
Merge branch 'master' into feature/post-locking
Aug 6, 2018
2c3aecc
Fixes for phpunit
Aug 6, 2018
68f2099
Enable a Modal showCloseIcon property
Aug 6, 2018
0905e1a
Add a post locked modal, first pass
Aug 6, 2018
f669682
Add an “isPostLocked” selector
Aug 6, 2018
5515ba1
Add a locked reducer
Aug 6, 2018
6fda398
action is ‘lockPost’ and takes a boolean
Aug 6, 2018
3157fc2
fixes for phpunit
Aug 6, 2018
413e75b
cleanup hearbeat post locking
Aug 6, 2018
d79f3ca
Show the post locked modal when the post is locked
Aug 6, 2018
825e0a5
spaces for phpcs
Aug 6, 2018
27f45dc
passed lock & user at initialization
Aug 7, 2018
5213a7c
Merge branch 'master' of github.com:WordPress/gutenberg
Aug 7, 2018
ca04b3d
Merge branch 'master' into feature/post-locking
Aug 7, 2018
d48e0f5
Merge branch 'master' of github.com:WordPress/gutenberg
Aug 8, 2018
9f8882d
Merge branch 'master' into feature/post-locking
Aug 8, 2018
ad0c4ae
update inline docs
Aug 8, 2018
c2e6d74
pass a unlocking lockNonce to settings if the post is locked
Aug 8, 2018
560222f
Lock modal actions, first pass; leverage existing PostPreviewButton
Aug 8, 2018
b5c1d48
Add some style
Aug 8, 2018
1514d06
improve modal string construction, nonce setup, linting fixes
Aug 8, 2018
ab79301
better setup, fix beforeunload
Aug 10, 2018
784d618
Merge branch 'master' of github.com:WordPress/gutenberg
Aug 10, 2018
c0a7b53
Merge branch 'master' into feature/post-locking
Aug 10, 2018
e5d10d9
Merge branch 'master' of github.com:WordPress/gutenberg
Aug 15, 2018
a8415e3
Merge branch 'master' into feature/post-locking
Aug 15, 2018
9b94b5d
Merge branch 'master' into feature/post-locking
Aug 17, 2018
3dfd55b
complete takeover action logic
Aug 19, 2018
434f9ff
update core data readme
Aug 19, 2018
836ba7a
Complete takeover action, reaction
Aug 19, 2018
28490b6
alignment for eslint
Aug 19, 2018
e37b9d5
Add the lock details to the lockPost dispatch
Aug 19, 2018
f168ed3
Ensure modal header can display an icon when passed its src
Aug 19, 2018
08f13e6
modal icon img styles
Aug 19, 2018
d7062a0
Improve post lock modal, improve all posts url construction
Aug 19, 2018
4efcff1
Add lockedDetails to the lockPost action
Aug 19, 2018
73c9bc5
add lockDetails to the locked reducer
Aug 19, 2018
d2a971e
new selector: getLockDetails
Aug 19, 2018
c15bddc
Add avatgar data for existing locks
Aug 19, 2018
30eb346
dispatch an autosave when the post is taken over
Aug 19, 2018
dcdcd5b
Merge branch 'master' of github.com:WordPress/gutenberg
Aug 20, 2018
4816d72
Merge branch 'master' into feature/post-locking
Aug 20, 2018
4d1437d
Fix for phpcs, also smaller gravatar size x2 display
Aug 20, 2018
c515d54
Add docs for getLockDetails
Aug 20, 2018
809a86b
improve post locking modal style to match designs
Aug 20, 2018
4436ec3
switch ajaxurl from global to editor settings
Aug 21, 2018
b674cf7
Don’t hide the modal title - display it above the existing content
Aug 21, 2018
31a5032
import { setupHearthbeatPostLocking } from '@wordpress/editor';
Aug 21, 2018
cc37e6a
complete move of setupHearthbeatPostLocking to editor package
Aug 21, 2018
6818df1
showCloseIcon -> isDismissable
Aug 21, 2018
2c1fcf0
post lock modal - switch to withSelect
Aug 21, 2018
7e2119e
Revert "post lock modal - switch to withSelect"
Aug 24, 2018
a7987b8
modal cleanup and withSelect rework
Aug 24, 2018
b9aac75
improve avatar image alignment
Aug 24, 2018
b7ff092
Use a href links instead of action handlers for buttons
Aug 24, 2018
0476023
no closing
Aug 24, 2018
ca9fa60
Try moving to editor package
Aug 24, 2018
95f5f5c
Revert "Try moving to editor package"
Aug 24, 2018
c03878f
remove inner buttons, not needed
Aug 24, 2018
7cdb082
clean up modal imports
Aug 26, 2018
42e45dc
improve heartbeat post locking setup
Aug 26, 2018
a0c57de
docs update
Aug 26, 2018
aad9b92
more docs cleanup
Aug 26, 2018
0534539
Fixes for phpcs
Aug 26, 2018
8d071c1
Remove specific Modal Header Icon
youknowriad Aug 29, 2018
5d767cb
Move the PostLockedModal to the editor module
youknowriad Aug 29, 2018
7e60a81
Styles cleaning for the post locked modal
youknowriad Aug 29, 2018
17803ec
Post Lock: Clarifying the lock state
youknowriad Aug 29, 2018
6f30da2
Move post locking setup to the post locked modal component
youknowriad Aug 29, 2018
52cb1e6
Remove unnecessary exposed function
youknowriad Aug 29, 2018
4b633d8
Merge branch 'master' of github.com:WordPress/gutenberg
Sep 5, 2018
8378bbe
Merge branch 'feature/post-locking' of github.com:WordPress/gutenberg…
Sep 5, 2018
f6bb6e9
Merge branch 'master' into feature/post-locking
Sep 5, 2018
e32ac81
cleanup after merge
Sep 5, 2018
72c15e3
Merge branch 'master' of github.com:WordPress/gutenberg
Sep 6, 2018
8090483
Merge branch 'master' into feature/post-locking
Sep 6, 2018
17a80e1
fixes for phpcs
Sep 6, 2018
9315785
docs cleanup
Sep 6, 2018
6744619
cleanup after merge
Sep 6, 2018
24d9aef
Adjust the modal display with latest language, formatting and post type
Sep 6, 2018
ef2a42c
spacing
Sep 6, 2018
dff9ec9
Merge branch 'master' of github.com:WordPress/gutenberg
Sep 8, 2018
5a7f787
Merge branch 'master' into feature/post-locking
Sep 8, 2018
93aa165
Merge branch 'master' into feature/post-locking
Sep 17, 2018
4f3e67d
restore heartbeat settings after merge
Sep 17, 2018
413458c
Merge remote-tracking branch 'origin/master' into feature/post-locking
youknowriad Sep 24, 2018
1f53d95
Add e2e tests for the post locking modal
youknowriad Sep 24, 2018
f6d5fc1
Revert "Add e2e tests for the post locking modal"
youknowriad Oct 3, 2018
d22b48b
Fix i18n of the post lock modal message and tweak docs
youknowriad Oct 3, 2018
10bd363
Merge remote-tracking branch 'origin/master' into feature/post-locking
youknowriad Oct 3, 2018
008872b
Try fixing the release post issue
youknowriad Oct 3, 2018
6afbc96
Merge branch 'master' of github.com:WordPress/gutenberg
Oct 4, 2018
3d84894
Merge branch 'feature/post-locking' of github.com:WordPress/gutenberg…
Oct 4, 2018
9611023
Merge branch 'master' into feature/post-locking
Oct 4, 2018
1fee125
include and use an unclock nonce
Oct 4, 2018
6bc1196
Remove the heartbeat interval tweak
youknowriad Oct 4, 2018
240f3e7
Code style and documentation tweaks
youknowriad Oct 4, 2018
719175b
i18n: Drop untranslatable `postType` interpolation.
mcsf Oct 4, 2018
f89696c
i18n: Separate strings for more versatile translation
mcsf Oct 4, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
74 changes: 74 additions & 0 deletions docs/data/data-core-editor.md
Expand Up @@ -321,6 +321,24 @@ unsaved status values.

Whether the post has been published.

### isEditedPostDateFloating

Returns whether the current post should be considered to have a "floating"
date (i.e. that it would publish "Immediately" rather than at a set time).

Unlike in the PHP backend, the REST API returns a full date string for posts
where the 0000-00-00T00:00:00 placeholder is present in the database. To
infer that a post is set to publish "Immediately" we check whether the date
and modified date are the same.

*Parameters*

* state: Editor state.

*Returns*

Whether the edited post has a floating date value.

### getBlockDependantsCacheBust

Returns a new reference when the inner blocks of a given block client ID
Expand Down Expand Up @@ -1241,6 +1259,54 @@ Returns the editor settings.

The editor settings object

### isPostLocked

Returns whether the post is locked.

*Parameters*

* state: Global application state.

*Returns*

Is locked.

### isPostLockTakeover

Returns whether the edition of the post has been taken over.

*Parameters*

* state: Global application state.

*Returns*

Is post lock takeover.

### getPostLockUser

Returns details about the post lock user.

*Parameters*

* state: Global application state.

*Returns*

A user object.

### getActivePostLock

Returns the active post lock.

*Parameters*

* state: Global application state.

*Returns*

The lock object.

### canUserUseUnfilteredHTML

Returns whether or not the user has the unfiltered_html capability.
Expand Down Expand Up @@ -1554,6 +1620,14 @@ Returns an action object used to remove a notice.

* id: The notice id.

### updatePostLock

Returns an action object used to lock the editor.

*Parameters*

* lock: Details about the post lock status, user, and nonce.

### fetchReusableBlocks

Returns an action object used to fetch a single reusable block or all
Expand Down
4 changes: 3 additions & 1 deletion edit-post/assets/stylesheets/main.scss
Expand Up @@ -86,7 +86,9 @@ body.gutenberg-editor-page {
}
}

.gutenberg {
.gutenberg,
// The modals are shown outside the .gutenberg wrapper, they need these styles
.components-modal__frame {
box-sizing: border-box;

*,
Expand Down
4 changes: 2 additions & 2 deletions edit-post/editor.js
Expand Up @@ -2,9 +2,8 @@
* WordPress dependencies
*/
import { withSelect } from '@wordpress/data';
import { EditorProvider, ErrorBoundary } from '@wordpress/editor';
import { EditorProvider, ErrorBoundary, PostLockedModal } from '@wordpress/editor';
import { StrictMode } from '@wordpress/element';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -39,6 +38,7 @@ function Editor( {
<ErrorBoundary onError={ onError }>
<Layout />
</ErrorBoundary>
<PostLockedModal />
</EditorProvider>
</StrictMode>
);
Expand Down
56 changes: 55 additions & 1 deletion lib/client-assets.php
Expand Up @@ -593,6 +593,7 @@ function gutenberg_register_scripts_and_styles() {
'wp-editor',
gutenberg_url( 'build/editor/index.js' ),
array(
'jquery',
'lodash',
'tinymce-latest-lists',
'wp-a11y',
Expand Down Expand Up @@ -1459,6 +1460,52 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
}
}

// Lock settings.
$user_id = wp_check_post_lock( $post->ID );
if ( $user_id ) {
/**
* Filters whether to show the post locked dialog.
*
* Returning a falsey value to the filter will short-circuit displaying the dialog.
*
* @since 3.6.0
*
* @param bool $display Whether to display the dialog. Default true.
* @param WP_Post $post Post object.
* @param WP_User|bool $user The user id currently editing the post.
*/
if ( apply_filters( 'show_post_locked_dialog', true, $post, $user_id ) ) {
$locked = true;
}

$user_details = null;
if ( $locked ) {
$user = get_userdata( $user_id );
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
$user_details = array(
'name' => $user->display_name,
);
$avatar = get_avatar( $user_id, 64 );
if ( $avatar ) {
if ( preg_match( "|src='([^']+)'|", $avatar, $matches ) ) {
$user_details['avatar'] = $matches[1];
}
}
}

$lock_details = array(
'isLocked' => $locked,
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
'user' => $user_details,
);
} else {

// Lock the post.
$active_post_lock = wp_set_post_lock( $post->ID );
$lock_details = array(
'isLocked' => false,
'activePostLock' => esc_attr( implode( ':', $active_post_lock ) ),
);
}

$editor_settings = array(
'alignWide' => $align_wide || ! empty( $gutenberg_theme_support[0]['wide-images'] ), // Backcompat. Use `align-wide` outside of `gutenberg` array.
'availableTemplates' => $available_templates,
Expand All @@ -1471,7 +1518,14 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
'autosaveInterval' => 10,
'maxUploadFileSize' => $max_upload_size,
'allowedMimeTypes' => get_allowed_mime_types(),
'styles' => $styles,
'postLock' => $lock_details,

// Ideally, we'd remove this and rely on a REST API endpoint.
'postLockUtils' => array(
'nonce' => wp_create_nonce( 'lock-post_' . $post->ID ),
'unlockNonce' => wp_create_nonce( 'update-post_' . $post->ID ),
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
),
);

$post_autosave = get_autosave_newer_than_post_save( $post );
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions packages/components/src/modal/README.md
Expand Up @@ -24,7 +24,7 @@ const MyModal = withState( {
<Button isDefault onClick={ () => setState( { isOpen: false } ) }>
My custom close button
</Button>
</Modal>
</Modal>
: null }
</div>
) );
Expand Down Expand Up @@ -77,23 +77,31 @@ If this property is added, it will be added to the modal content `div` as `aria-

If this property is true, it will focus the first tabbable element rendered in the modal.

- Type: `bool`
- Type: `boolean`
- Required: No
- Default: true

### shouldCloseOnEsc

If this property is added, it will determine whether the modal requests to close when the escape key is pressed.
If this property is added, it will determine whether the modal requests to close when the escape key is pressed.

- Type: `bool`
- Type: `boolean`
- Required: No
- Default: true

### shouldCloseOnClickOutside

If this property is added, it will determine whether the modal requests to close when a mouse click occurs outside of the modal content.

- Type: `bool`
- Type: `boolean`
- Required: No
- Default: true

### isDismissable

If this property is set to false, the modal will not display a close icon and cannot be dismissed.

- Type: `boolean`
- Required: No
- Default: true

Expand Down
14 changes: 8 additions & 6 deletions packages/components/src/modal/header.js
Expand Up @@ -8,7 +8,7 @@ import { __ } from '@wordpress/i18n';
*/
import IconButton from '../icon-button';

const ModalHeader = ( { icon, title, onClose, closeLabel, headingId } ) => {
const ModalHeader = ( { icon, title, onClose, closeLabel, headingId, isDismissable } ) => {
const label = closeLabel ? closeLabel : __( 'Close dialog' );

return (
Expand All @@ -28,11 +28,13 @@ const ModalHeader = ( { icon, title, onClose, closeLabel, headingId } ) => {
</h1>
}
</div>
<IconButton
onClick={ onClose }
icon="no-alt"
label={ label }
/>
{ isDismissable &&
<IconButton
onClick={ onClose }
icon="no-alt"
label={ label }
/>
}
</div>
);
};
Expand Down
6 changes: 5 additions & 1 deletion packages/components/src/modal/index.js
Expand Up @@ -126,6 +126,7 @@ class Modal extends Component {
children,
aria,
instanceId,
isDismissable,
...otherProps
} = this.props;

Expand Down Expand Up @@ -154,10 +155,12 @@ class Modal extends Component {
{ ...otherProps } >
<ModalHeader
closeLabel={ closeButtonLabel }
isDismissable={ isDismissable }
onClose={ onRequestClose }
title={ title }
headingId={ headingId }
icon={ icon } />
icon={ icon }
/>
<div
className={ 'components-modal__content' }>
{ children }
Expand All @@ -178,6 +181,7 @@ Modal.defaultProps = {
focusOnMount: true,
shouldCloseOnEsc: true,
shouldCloseOnClickOutside: true,
isDismissable: true,
/* accessibility */
aria: {
labelledby: null,
Expand Down
1 change: 1 addition & 0 deletions packages/editor/package.json
Expand Up @@ -46,6 +46,7 @@
"classnames": "^2.2.5",
"dom-scroll-into-view": "^1.2.1",
"inherits": "^2.0.3",
"jquery": "^3.3.1",
"lodash": "^4.17.10",
"memize": "^1.0.5",
"react-autosize-textarea": "^3.0.2",
Expand Down
1 change: 1 addition & 0 deletions packages/editor/src/components/index.js
Expand Up @@ -48,6 +48,7 @@ export { default as PostFormat } from './post-format';
export { default as PostFormatCheck } from './post-format/check';
export { default as PostLastRevision } from './post-last-revision';
export { default as PostLastRevisionCheck } from './post-last-revision/check';
export { default as PostLockedModal } from './post-locked-modal';
export { default as PostPendingStatus } from './post-pending-status';
export { default as PostPendingStatusCheck } from './post-pending-status/check';
export { default as PostPingbacks } from './post-pingbacks';
Expand Down