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 3 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
11 changes: 2 additions & 9 deletions editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import './assets/stylesheets/main.scss';
import Layout from './edit-post/layout';
import { EditorProvider, ErrorBoundary } from './components';
import { initializeMetaBoxState } from './store/actions';
import { setupHearthbeat } from './utils/heartbeat';

export * from './components';
import store from './store'; // Registers the state tree
Expand All @@ -37,15 +38,6 @@ if ( dateSettings.timezone.string ) {
moment.tz.setDefault( 'WP' );
}

/**
* Configure heartbeat to refresh the wp-api nonce, keeping the editor authorization intact.
*/
window.jQuery( document ).on( 'heartbeat-tick', ( event, response ) => {
if ( response[ 'rest-nonce' ] ) {
window.wpApiSettings.nonce = response[ 'rest-nonce' ];
}
} );

/**
* Reinitializes the editor after the user chooses to reboot the editor after
* an unhandled error occurs, replacing previously mounted editor element using
Expand Down Expand Up @@ -83,6 +75,7 @@ export function recreateEditorInstance( target, settings ) {
export function createEditorInstance( id, post, settings ) {
const target = document.getElementById( id );
const reboot = recreateEditorInstance.bind( null, target, settings );
setupHearthbeat();

render(
<EditorProvider settings={ settings } post={ post }>
Expand Down
50 changes: 50 additions & 0 deletions editor/utils/heartbeat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export function setupHearthbeat() {
adamsilverstein marked this conversation as resolved.
Show resolved Hide resolved
/**
* Configure heartbeat to refresh the wp-api nonce, keeping the editor authorization intact.
*/
window.jQuery( document ).on( 'heartbeat-tick', ( event, response ) => {
if ( response[ 'rest-nonce' ] ) {
window.wpApiSettings.nonce = response[ 'rest-nonce' ];
}
} );

/**
* Configure Heartbeat post locks.
*
* Used to lock editing of an object by only one user at a time.
*
* When the user does not send a heartbeat in a heartbeat-time
* the user is no longer editing and another user can start editing.
*/
jQuery( document ).on( 'heartbeat-send.refresh-lock', function( e, data ) {
const lock = jQuery( '#active_post_lock' ).val(),
postId = jQuery( '#post_ID' ).val(),
send = {};

if ( ! postId ) {
return;
}

send.postId = postId;

if ( lock ) {
send.lock = lock;
}

data[ 'wp-refresh-post-lock' ] = send;
} );

// Refresh post locks: update the lock string or show the dialog if somebody has taken over editing.
jQuery( document ).on( 'heartbeat-tick.refresh-lock', function( e, data ) {
if ( data[ 'wp-refresh-post-lock' ] ) {
const received = data[ 'wp-refresh-post-lock' ];

if ( received.lock_error ) {
// @todo suspend autosaving
// @todo Show "editing taken over" message.
} else if ( received.new_lock ) {
jQuery( '#active_post_lock' ).val( received.new_lock );
}
}
} );
}