Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Show notification when a post a restored from trash #347

Merged
merged 4 commits into from Mar 3, 2017

Conversation

mohdsayed
Copy link
Contributor

Fixes #217

@mohdsayed
Copy link
Contributor Author

Ready for review.

@@ -846,6 +846,7 @@ public function enqueue_scripts() {
__( 'Customize Object Selector', 'customize-posts' )
)
),
'trashPostNotification' => __( 'This has been untrashed. If you publish changes now, this post will be published. Move back to trash to avoid this.' , 'customize-posts' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

It may not actually be published. If the post was a draft then it will be restored as a draft, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, how about changing it to this?
"This has been untrashed. If you publish changes now, its status will change to the selected status. Move back to trash to avoid this."

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's good.

@@ -32,6 +34,10 @@
panel.deferred.embedded.done(function() {
panel.setupPanelActions();
});

api.bind( 'saved', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will trigger even when updating a changeset draft via Customize Snapshots. Is that intended? If you want it to only run when the changeset is published as a whole, then I think you need to make sure that the changeset status is publish, like:

api.bind( 'saved', function( data ) {
    if ( 'publish' === data.changeset_status ) {
        panel.removeTrashNotifications();
    }
} );

This is adapted from https://github.com/xwp/wp-customize-featured-content-demo/blob/8bf4d6531adb029fbaf1e4bebb967e57989d5edd/js/featured-items-panel.js#L148-L153

Humm. But actually this code is also being used for purging the trashed items as well:

// Purge trashed posts and update client settings with saved values from server.
api.bind( 'saved', function( data ) {
if ( data.saved_post_setting_values ) {
component.updateSettingsQuietly( data.saved_post_setting_values );
}
component.purgeTrash();
} );

So maybe that other location in Customize Posts needs to be updated as well.

Or maybe this is all intended, to purge the trashed items upon saving an explicit draft as well as upon publishing, and if so you can ignore this comment 😄

Copy link
Contributor Author

@mohdsayed mohdsayed Mar 2, 2017

Choose a reason for hiding this comment

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

It was intended because if snapshot saves it as draft or any other status, it would eventually get published when they publish the snapshot, so the user should know this right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the way you have it is a better experience. If I hit Move to Trash, and then hit Save Draft, I pretty clearly don't want the trashed item around anymore and I'm unlikely to be wanting to undo it. So removing the trashed post sections upon explicit Save makes sense to me.

@westonruter westonruter added this to the Next Minor Release milestone Mar 3, 2017
} );

statusControl.setting.bind( function() {
statusControl.notifications.remove( panel.trashNotificationCode );
Copy link
Contributor

Choose a reason for hiding this comment

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

So this will remove the notification whenever a user makes a change to the setting? Probably should call statusControl.setting.unbind() to remove this function handler after it runs once, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point

message: api.Posts.data.l10n.trashPostNotification
} );

statusControl = api.control( postData.section.id + '[post_status]' );
Copy link
Contributor

Choose a reason for hiding this comment

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

It's unlikely, but this should probably check to see if statusControl exists (like you're doing in removeTrashNotifications below), and if not then short circuit.

statusControl = api.control( postData.section.id + '[post_status]' );
statusControl.deferred.embedded.done( function() {
statusControl.notifications.add( panel.trashNotificationCode, notification );
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious why the statusControl.deferred.embedded is needed here. The statusControl.notifications collection should exist from the moment that a control is initialized, so I don't think that you have to wait for embedding?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure, but right embedded is not required here.

@westonruter westonruter merged commit 621f875 into develop Mar 3, 2017
@westonruter westonruter deleted the enhancement/issue-217 branch March 3, 2017 21:25
@westonruter westonruter modified the milestones: Next Minor Release, 0.8.6 Jun 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants