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 103 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions docs/data/data-core-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,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 post is locked.

*Parameters*

* state: Global application state.

*Returns*

Is locked.

### 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 @@ -1319,6 +1367,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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,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
Original file line number Diff line number Diff line change
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
14 changes: 13 additions & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @since 0.1.0
*/
function the_gutenberg_project() {
global $post_type_object;
global $post_type_object, $post;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a useless change.

?>
<div class="gutenberg">
<h1 class="screen-reader-text"><?php echo esc_html( $post_type_object->labels->edit_item ); ?></h1>
Expand Down Expand Up @@ -471,3 +471,15 @@ function gutenberg_add_admin_body_class( $classes ) {
// Default to is-fullscreen-mode to avoid jumps in the UI.
return "$classes gutenberg-editor-page is-fullscreen-mode";
}

/**
* Ensure heartbeat interval is low enough to work for post locking.
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
*
* @param array $settings Settings.
* @return array Filtered settings.
*/
function wp_heartbeat_settings_gutenberg( $settings ) {
$settings['interval'] = 15;
return $settings;
}
add_filter( 'heartbeat_settings', 'wp_heartbeat_settings_gutenberg' );
58 changes: 55 additions & 3 deletions lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,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 @@ -1444,7 +1490,13 @@ 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 ),
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
),
);

$post_autosave = get_autosave_newer_than_post_save( $post );
Expand All @@ -1471,8 +1523,8 @@ function gutenberg_editor_scripts_and_styles( $hook ) {
( function() {
var editorSettings = %s;
window._wpLoadGutenbergEditor = new Promise( function( resolve ) {
wp.domReady( function() {
resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, editorSettings, window._wpGutenbergDefaultPost ) );
wp.domReady( function() {
resolve( wp.editPost.initializeEditor( 'editor', "%s", %d, editorSettings, window._wpGutenbergDefaultPost ) );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, probably a useless change du to rebases?

} );
} );
} )();
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/modal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ If this property is added, it will determine whether the modal requests to close
- 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: `bool`
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
- Required: No
- Default: true

### className

If this property is added, it will an additional class name to the modal content `div`.
Expand Down
14 changes: 8 additions & 6 deletions packages/components/src/modal/header.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class Modal extends Component {
children,
aria,
instanceId,
isDismissable,
...otherProps
} = this.props;

Expand All @@ -143,10 +144,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 @@ -166,6 +169,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/src/components/index.js
Original file line number Diff line number Diff line change
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
Loading