Skip to content
Snippets Groups Projects
Commit bd86687e authored by Erick Hitter's avatar Erick Hitter
Browse files

Begin purge button

parent 116d65f8
No related branches found
No related tags found
1 merge request!12Introduce native Gutenberg controls
Pipeline #3542 failed with stages
in 2 minutes and 38 seconds
......@@ -4,7 +4,7 @@ object-assign
(c) Sindre Sorhus
@license MIT
*/
var t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function o(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach((function(e){n[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}()?Object.assign:function(e,i){for(var c,a,u=o(e),s=1;s<arguments.length;s++){for(var p in c=Object(arguments[s]))r.call(c,p)&&(u[p]=c[p]);if(t){a=t(c);for(var f=0;f<a.length;f++)n.call(c,a[f])&&(u[a[f]]=c[a[f]])}}return u}},251:function(e,t,r){
var t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.prototype.propertyIsEnumerable;function o(e){if(null==e)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(e)}e.exports=function(){try{if(!Object.assign)return!1;var e=new String("abc");if(e[5]="de","5"===Object.getOwnPropertyNames(e)[0])return!1;for(var t={},r=0;r<10;r++)t["_"+String.fromCharCode(r)]=r;if("0123456789"!==Object.getOwnPropertyNames(t).map((function(e){return t[e]})).join(""))return!1;var n={};return"abcdefghijklmnopqrst".split("").forEach((function(e){n[e]=e})),"abcdefghijklmnopqrst"===Object.keys(Object.assign({},n)).join("")}catch(e){return!1}}()?Object.assign:function(e,i){for(var s,c,u=o(e),a=1;a<arguments.length;a++){for(var l in s=Object(arguments[a]))r.call(s,l)&&(u[l]=s[l]);if(t){c=t(s);for(var p=0;p<c.length;p++)n.call(s,c[p])&&(u[c[p]]=s[c[p]])}}return u}},251:function(e,t,r){
/** @license React v17.0.2
* react-jsx-runtime.production.min.js
*
......@@ -13,4 +13,4 @@ var t=Object.getOwnPropertySymbols,r=Object.prototype.hasOwnProperty,n=Object.pr
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
r(418);var n=r(804),o=60103;if(60107,"function"==typeof Symbol&&Symbol.for){var i=Symbol.for;o=i("react.element"),i("react.fragment")}var c=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,a=Object.prototype.hasOwnProperty,u={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,r){var n,i={},s=null,p=null;for(n in void 0!==r&&(s=""+r),void 0!==t.key&&(s=""+t.key),void 0!==t.ref&&(p=t.ref),t)a.call(t,n)&&!u.hasOwnProperty(n)&&(i[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===i[n]&&(i[n]=t[n]);return{$$typeof:o,type:e,key:s,ref:p,props:i,_owner:c.current}}t.jsx=s},893:function(e,t,r){e.exports=r(251)},804:function(e){e.exports=React},190:function(e){e.exports=wp.components},405:function(e){e.exports=wp.compose},440:function(e){e.exports=wp.data},451:function(e){e.exports=wp.editPost},194:function(e){e.exports=wp.i18n},415:function(e){e.exports=wp.plugins}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}!function(){var e=r(893);function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var n=r(190).TextControl,o=r(405).compose,i=r(440),c=i.withSelect,a=i.withDispatch,u=r(451).PluginDocumentSettingPanel,s=r(194).__,p=r(415).registerPlugin,f="_wp_rev_ctl_limit";p("plugin-document-setting-panel-demo",{render:o([c((function(e){return{limit:e("core/editor").getEditedPostAttribute("meta")[f]}})),a((function(e){return{update:function(r){e("core/editor").editPost({meta:t({},f,r)})}}}))])((function(t){var r=t.limit,o=t.update;return(0,e.jsx)(u,{name:"wp-revisions-control",title:s("WP Revisions Control","wp_revisions_control"),className:"wp-revisions-control",children:(0,e.jsx)(n,{label:s("Number of revisions to retain.","wp_revisions_control"),value:r,onChange:o})})})),icon:"backup"})}()}();
\ No newline at end of file
r(418);var n=r(804),o=60103;if(60107,"function"==typeof Symbol&&Symbol.for){var i=Symbol.for;o=i("react.element"),i("react.fragment")}var s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c=Object.prototype.hasOwnProperty,u={key:!0,ref:!0,__self:!0,__source:!0};function a(e,t,r){var n,i={},a=null,l=null;for(n in void 0!==r&&(a=""+r),void 0!==t.key&&(a=""+t.key),void 0!==t.ref&&(l=t.ref),t)c.call(t,n)&&!u.hasOwnProperty(n)&&(i[n]=t[n]);if(e&&e.defaultProps)for(n in t=e.defaultProps)void 0===i[n]&&(i[n]=t[n]);return{$$typeof:o,type:e,key:a,ref:l,props:i,_owner:s.current}}t.jsx=a,t.jsxs=a},893:function(e,t,r){e.exports=r(251)},804:function(e){e.exports=React},190:function(e){e.exports=wp.components},405:function(e){e.exports=wp.compose},440:function(e){e.exports=wp.data},451:function(e){e.exports=wp.editPost},194:function(e){e.exports=wp.i18n},415:function(e){e.exports=wp.plugins}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}!function(){var e=r(893);function t(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var n=r(190),o=n.Button,i=n.TextControl,s=r(405).compose,c=r(440),u=c.withSelect,a=c.withDispatch,l=r(451).PluginDocumentSettingPanel,p=r(194).__,f=r(415).registerPlugin,v="_wp_rev_ctl_limit",g="wp-revisions-control";f("plugin-document-setting-panel-demo",{render:s([u((function(e){var t=e("core/editor"),r=t.getCurrentPostRevisionsCount,n=t.getEditedPostAttribute,o=r(),i=n("meta")[v];return{limit:i,showPurgeButton:Boolean(i)&&o>parseInt(i)}})),a((function(e,r){var n=r.limit;return{manualPurge:function(){console.log("Purging!",n)},updateMeta:function(r){e("core/editor").editPost({meta:t({},v,r)})}}}))])((function(t){var r=t.limit,n=t.manualPurge,s=t.showPurgeButton,c=t.updateMeta;return(0,e.jsxs)(l,{name:g,title:p("WP Revisions Control","wp_revisions_control"),className:g,children:[(0,e.jsx)(i,{label:p("Number of revisions to retain:","wp_revisions_control"),help:p("Leave blank to keep all revisions.","wp_revisions_control"),value:r,onChange:c}),s&&(0,e.jsx)(o,{onClick:n,children:p("Purge excess revisions","wp_revisions_control")})]})})),icon:"backup"})}()}();
\ No newline at end of file
......@@ -3,10 +3,18 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"X-Generator: babel-plugin-makepot\n"
#: src/js/gutenberg.js:13
#: src/js/gutenberg.js:14
msgid "WP Revisions Control"
msgstr ""
#: src/js/gutenberg.js:17
msgid "Number of revisions to retain."
#: src/js/gutenberg.js:18
msgid "Number of revisions to retain:"
msgstr ""
#: src/js/gutenberg.js:19
msgid "Leave blank to keep all revisions."
msgstr ""
#: src/js/gutenberg.js:26
msgid "Purge excess revisions"
msgstr ""
\ No newline at end of file
......@@ -5,7 +5,7 @@ msgstr ""
"Project-Id-Version: WP Revisions Control 1.3\n"
"Report-Msgid-Bugs-To: "
"https://wordpress.org/support/plugin/wp-revisions-control\n"
"POT-Creation-Date: 2021-03-28 02:34:59+00:00\n"
"POT-Creation-Date: 2021-03-28 03:24:58+00:00\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
......
const { TextControl } = require( '@wordpress/components' );
const { Button, TextControl } = require( '@wordpress/components' );
const { compose } = require( '@wordpress/compose' );
const { withSelect, withDispatch } = require( '@wordpress/data' );
const { PluginDocumentSettingPanel } = require( '@wordpress/edit-post' );
......@@ -6,34 +6,58 @@ const { __ } = require( '@wordpress/i18n' );
const { registerPlugin } = require( '@wordpress/plugins' );
const metaKey = '_wp_rev_ctl_limit';
const slug = 'wp-revisions-control';
const Render = ( { limit, update } ) => (
const Render = ( { limit, manualPurge, showPurgeButton, updateMeta } ) => (
<PluginDocumentSettingPanel
name="wp-revisions-control"
name={ slug }
title={ __( 'WP Revisions Control', 'wp_revisions_control' ) }
className="wp-revisions-control"
className={ slug }
>
<TextControl
label={ __( 'Number of revisions to retain.', 'wp_revisions_control' ) }
label={ __( 'Number of revisions to retain:', 'wp_revisions_control' ) }
help={ __( 'Leave blank to keep all revisions.', 'wp_revisions_control' ) }
value={ limit }
onChange={ update }
onChange={ updateMeta }
/>
{ showPurgeButton && (
<Button onClick={ manualPurge }>
{ __( 'Purge excess revisions', 'wp_revisions_control' ) }
</Button>
) }
</PluginDocumentSettingPanel>
);
const RevisionsControl = compose(
[
withSelect( ( select ) => {
const limit = select( 'core/editor' ).getEditedPostAttribute(
const {
getCurrentPostRevisionsCount,
getEditedPostAttribute,
} = select( 'core/editor' );
const count = getCurrentPostRevisionsCount();
const limit = getEditedPostAttribute(
'meta'
)[ metaKey ];
const showPurgeButton = Boolean( limit )
&& count > parseInt( limit );
return {
limit,
showPurgeButton,
};
} ),
withDispatch( ( dispatch ) => {
const update = ( value ) => {
withDispatch( ( dispatch, { limit } ) => {
const manualPurge = () => {
// TODO: reuse the existing Ajax endpoint?
console.log( 'Purging!', limit );
};
const updateMeta = ( value ) => {
dispatch( 'core/editor' ).editPost( {
meta: {
[ metaKey ]: value,
......@@ -42,7 +66,8 @@ const RevisionsControl = compose(
};
return {
update,
manualPurge,
updateMeta,
};
} ),
]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment