| 1 |
!function(){"use strict";var e={5251:function(e,s,n){var t=n(9196),a=60103;if(s.Fragment=60107,"function"===typeof Symbol&&Symbol.for){var r=Symbol.for;a=r("react.element"),s.Fragment=r("react.fragment")}var i=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,c=Object.prototype.hasOwnProperty,l={key:!0,ref:!0,__self:!0,__source:!0};function o(e,s,n){var t,r={},o=null,d=null;for(t in void 0!==n&&(o=""+n),void 0!==s.key&&(o=""+s.key),void 0!==s.ref&&(d=s.ref),s)c.call(s,t)&&!l.hasOwnProperty(t)&&(r[t]=s[t]);if(e&&e.defaultProps)for(t in s=e.defaultProps)void 0===r[t]&&(r[t]=s[t]);return{$$typeof:a,type:e,key:o,ref:d,props:r,_owner:i.current}}s.jsx=o,s.jsxs=o},5893:function(e,s,n){e.exports=n(5251)},9196:function(e){e.exports=window.React}},s={};function n(t){var a=s[t];if(void 0!==a)return a.exports;var r=s[t]={exports:{}};return e[t](r,r.exports,n),r.exports}n.n=function(e){var s=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(s,{a:s}),s},n.d=function(e,s){for(var t in s)n.o(s,t)&&!n.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:s[t]})},n.o=function(e,s){return Object.prototype.hasOwnProperty.call(e,s)},function(){var e,s=new Uint8Array(16);function t(){if(!e&&!(e="undefined"!==typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!==typeof msCrypto&&"function"===typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto)))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return e(s)}var a=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;for(var r=function(e){return"string"===typeof e&&a.test(e)},i=[],c=0;c<256;++c)i.push((c+256).toString(16).substr(1));var l=function(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,n=(i[e[s+0]]+i[e[s+1]]+i[e[s+2]]+i[e[s+3]]+"-"+i[e[s+4]]+i[e[s+5]]+"-"+i[e[s+6]]+i[e[s+7]]+"-"+i[e[s+8]]+i[e[s+9]]+"-"+i[e[s+10]]+i[e[s+11]]+i[e[s+12]]+i[e[s+13]]+i[e[s+14]]+i[e[s+15]]).toLowerCase();if(!r(n))throw TypeError("Stringified UUID is invalid");return n};var o=function(e,s,n){var a=(e=e||{}).random||(e.rng||t)();if(a[6]=15&a[6]|64,a[8]=63&a[8]|128,s){n=n||0;for(var r=0;r<16;++r)s[n+r]=a[r];return s}return l(a)},d=window.wp.element,u=window.wp.i18n;const{auto_start_index:p,ajax_url:m,index_meta:y=null,is_epio:h,ep_last_sync_date:_=null,ep_last_sync_failed:g=!1,nonce:x}=window.epDash;var w=window.wp.apiFetch,f=n.n(w);const S=e=>{let s=0;return e.current_sync_item&&(s+=e.current_sync_item.found_items),s=e.sync_stack.reduce(((e,s)=>e+s.found_items),s),s+=e.totals.failed,s+=e.totals.skipped,s+=e.totals.synced,s},v=e=>{let s=0;return e.current_sync_item&&(s+=e.current_sync_item.failed,s+=e.current_sync_item.skipped,s+=e.current_sync_item.synced),s+=e.totals.failed,s+=e.totals.skipped,s+=e.totals.synced,s};var b=window.wp.components,j=window.wp.primitives;var C=(0,d.createElement)(j.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24"},(0,d.createElement)(j.Path,{d:"M10 2c4.42 0 8 3.58 8 8s-3.58 8-8 8-8-3.58-8-8 3.58-8 8-8zm1.13 9.38l.35-6.46H8.52l.35 6.46h2.26zm-.09 3.36c.24-.23.37-.55.37-.96 0-.42-.12-.74-.36-.97s-.59-.35-1.06-.35-.82.12-1.07.35-.37.55-.37.97c0 .41.13.73.38.96.26.23.61.34 1.06.34s.8-.11 1.05-.34z"}));var P=(0,d.createElement)(j.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"-2 -2 24 24"},(0,d.createElement)(j.Path,{d:"M10.2 3.28c3.53 0 6.43 2.61 6.92 6h2.08l-3.5 4-3.5-4h2.32c-.45-1.97-2.21-3.45-4.32-3.45-1.45 0-2.73.71-3.54 1.78L4.95 5.66C6.23 4.2 8.11 3.28 10.2 3.28zm-.4 13.44c-3.52 0-6.43-2.61-6.92-6H.8l3.5-4c1.17 1.33 2.33 2.67 3.5 4H5.48c.45 1.97 2.21 3.45 4.32 3.45 1.45 0 2.73-.71 3.54-1.78l1.71 1.95c-1.28 1.46-3.15 2.38-5.25 2.38z"})),D=n(5893),N=()=>(0,D.jsx)(j.SVG,{version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,D.jsx)(j.Path,{d:"M5 16v-12h3v12h-3zM12 4h3v12h-3v-12z"})}),k=()=>(0,D.jsx)(j.SVG,{version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,D.jsx)(j.Path,{d:"M5 4l10 6-10 6v-12z"})}),L=()=>(0,D.jsx)(j.SVG,{version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,D.jsx)(j.Path,{d:"M 4 16 L 4 4 L 16 4 L 16 16 L 4 16 Z"})}),T=({disabled:e,isPaused:s,isSyncing:n,onPause:t,onResume:a,onStop:r,onSync:i,showSync:c})=>(0,D.jsxs)("div",{className:"ep-sync-controls",children:[c&&!n?(0,D.jsx)("div",{className:"ep-sync-controls__sync",children:(0,D.jsx)(b.Button,{className:"ep-sync-button ep-sync-button--sync",disabled:e,icon:P,isPrimary:!0,onClick:i,children:(0,u.__)("Sync Now","elasticpress")})}):null,n?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("div",{className:"ep-sync-controls__pause-resume",children:s?(0,D.jsx)(b.Button,{className:"ep-sync-button ep-sync-button--resume",disabled:e,icon:k,isPrimary:!0,onClick:a,children:(0,u.__)("Resume","elasticpress")}):(0,D.jsx)(b.Button,{className:"ep-sync-button ep-sync-button--pause",disabled:e,icon:N,isPrimary:!0,onClick:t,children:(0,u.__)("Pause","elasticpress")})}),(0,D.jsx)("div",{className:"ep-sync-controls__stop",children:(0,D.jsx)(b.Button,{className:"ep-sync-button ep-sync-button--stop",icon:L,isSecondary:!0,onClick:r,children:(0,u.__)("Stop","elasticpress")})})]}):null,c?(0,D.jsx)("div",{className:"ep-sync-controls__learn-more",children:(0,D.jsx)(b.Button,{href:"https://elasticpress.zendesk.com/hc/en-us/articles/5205632443533",target:"_blank",variant:"link",children:(0,u.__)("Learn more","elasticpress")})}):null]}),E=({messages:e})=>(0,D.jsxs)("div",{className:"ep-sync-messages",children:[e.map(((e,s)=>(0,D.jsx)("div",{className:"ep-sync-messages__line-number",role:"presentation",children:s+1},`line-${e.id}`))),e.map((e=>(0,D.jsx)("div",{className:`ep-sync-messages__message ep-sync-messages__message--${e.status}`,children:e.message},`message-${e.id}`)))]}),I=({messages:e})=>{const[s,n]=(0,d.useState)(!1),t=e.filter((e=>"error"===e.status||"warning"===e.status)),a=[{messages:e,name:"full",title:(0,u.__)("Full Log","elasticpress")},{messages:t,name:"error",title:(0,u.sprintf)((0,u.__)("Errors (%d)","elasticpress"),t.length)}];return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(b.ToggleControl,{checked:s,onChange:e=>{n(e)},label:(0,u.__)("Show log","elasticpress")}),s?(0,D.jsx)(b.TabPanel,{tabs:a,children:({messages:e})=>(0,D.jsx)(E,{messages:e})}):null]})},R=window.wp.date,M=({dateTime:e,...s})=>(0,D.jsx)("time",{dateTime:(0,R.dateI18n)("c",e),...s,children:(0,R.dateI18n)("D, F d, Y H:i",e)}),F=({isComplete:e,current:s,total:n})=>{const t=n?Math.floor(s/n*100):100;return(0,D.jsx)("div",{"aria-valuemax":100,"aria-valuemin":0,"aria-valuenow":t,className:"ep-sync-progress-bar "+(e?"ep-sync-progress-bar--complete":""),role:"progressbar",children:(0,D.jsx)("div",{className:"ep-sync-progress-bar__progress",style:{minWidth:`${t}%`},children:`${t}%`})})},B=()=>(0,D.jsx)(j.SVG,{version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,D.jsx)(j.Path,{d:"M 7.543 17.501 L 10 15 L 10 16.25 C 11.216 16.25 12.405 15.884 13.416 15.197 C 14.427 14.509 15.213 13.531 15.679 12.389 C 16.144 11.246 16.264 9.988 16.027 8.775 C 15.788 7.561 15.201 6.448 14.34 5.573 L 16.072 3.804 C 16.875 4.615 17.512 5.582 17.946 6.645 C 18.38 7.709 18.603 8.85 18.601 10.002 C 18.601 14.834 14.751 18.75 10.002 18.75 L 10.001 18.75 L 10.001 20 L 7.543 17.501 Z M 1.399 10.001 C 1.406 5.171 5.253 1.256 10 1.25 L 10.001 1.25 L 10.001 0 L 12.458 2.501 L 10.001 5 L 10.001 3.75 L 9.999 3.75 C 8.784 3.75 7.595 4.117 6.584 4.804 C 5.574 5.493 4.786 6.469 4.321 7.612 C 3.856 8.756 3.735 10.013 3.974 11.227 C 4.211 12.439 4.798 13.552 5.659 14.427 L 3.928 16.197 C 3.126 15.39 2.489 14.429 2.055 13.369 C 1.62 12.309 1.398 11.172 1.399 10.025 L 1.399 9.999 L 1.399 10.002 L 1.399 10.001 Z"})}),O=({isCli:e,isComplete:s,isPaused:n,itemsProcessed:t,itemsTotal:a,dateTime:r})=>{const i=(0,d.useMemo)((()=>s?(0,u.__)("Sync complete","elasticpress"):n?(0,u.__)("Sync paused","elasticpress"):e?(0,u.__)("WP CLI sync in progress","elasticpress"):(0,u.__)("Sync in progress","elasticpress")),[e,s,n]);return(0,D.jsxs)("div",{className:"ep-sync-progress "+(n||s?"":"ep-sync-progress--syncing"),children:[(0,D.jsx)(b.Icon,{icon:B}),(0,D.jsxs)("div",{className:"ep-sync-progress__details",children:[(0,D.jsx)("strong",{children:i}),r?(0,D.jsxs)(D.Fragment,{children:[(0,u.__)("Started on","elasticpress")," ",(0,D.jsx)(M,{dateTime:(0,R.dateI18n)("c",r)})]}):null]}),(0,D.jsx)("div",{className:"ep-sync-progress__progress-bar",children:(0,D.jsx)(F,{current:t,isComplete:s,total:a})})]})},z=()=>(0,D.jsx)(j.SVG,{version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,D.jsx)(j.Path,{d:"M7.28 18c-0.15 0.020-0.26-0.020-0.41-0.070-0.56-0.19-0.83-0.79-0.66-1.35 0.17-0.55 1-3.040 1-3.58 0-0.53-0.75-1-1.35-1h-3c-0.6 0-1-0.4-1-1s2-7 2-7c0.17-0.39 0.55-1 1-1h9.14v9h-2.14c-0.41 0.41-3.3 4.71-3.58 5.27-0.21 0.41-0.6 0.68-1 0.73zM18 12h-2v-9h2v9z"})}),A=()=>(0,D.jsx)(j.SVG,{version:"1.1",xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",children:(0,D.jsx)(j.Path,{d:"M12.72 2c0.15-0.020 0.26 0.020 0.41 0.070 0.56 0.19 0.83 0.79 0.66 1.35-0.17 0.55-1 3.040-1 3.58 0 0.53 0.75 1 1.35 1h3c0.6 0 1 0.4 1 1s-2 7-2 7c-0.17 0.39-0.55 1-1 1h-9.14v-9h2.14c0.41-0.41 3.3-4.71 3.58-5.27 0.21-0.41 0.6-0.68 1-0.73zM2 8h2v9h-2v-9z"})}),V=({dateTime:e,isSuccess:s})=>(0,D.jsxs)("p",{className:"ep-sync-status "+(s?"ep-sync-status--success":"ep-sync-status--error"),children:[(0,D.jsx)(b.Icon,{icon:s?A:z}),(0,D.jsxs)("span",{className:"ep-sync-status__label",children:[s?(0,u.__)("Sync success on","elasticpress"):(0,u.__)("Sync unsuccessful on","elasticpress")," ",(0,D.jsx)(M,{dateTime:(0,R.dateI18n)("c",e),className:"ep-sync-status__time"})]})]}),W=({heading:e,introduction:s,isCli:n,isComplete:t,isDisabled:a,isPaused:r,isSyncing:i,itemsProcessed:c,itemsTotal:l,lastSyncDateTime:o,lastSyncFailed:d,logMessages:p,onDelete:m,onPause:y,onResume:h,onStop:_,onSync:g,showDelete:x,showLastSync:w,showProgress:f,showSync:S,syncStartDateTime:v,warningMessage:j})=>(0,D.jsxs)(D.Fragment,{children:[e?(0,D.jsx)("h2",{className:"ep-sync-heading",children:e}):null,(0,D.jsx)(b.Panel,{className:"ep-sync-panel",children:(0,D.jsxs)(b.PanelBody,{className:"ep-sync-panel__body",children:[(0,D.jsxs)("div",{className:"ep-sync-panel__description",children:[s?(0,D.jsx)("p",{className:"ep-sync-panel__introduction",children:s}):null,w&&o?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("h3",{className:"ep-sync-heading",children:(0,u.__)("Last Sync","elasticpress")}),(0,D.jsx)(V,{dateTime:o,isSuccess:!d})]}):null,x?(0,D.jsx)("p",{children:(0,D.jsx)(b.Button,{className:"ep-sync-button ep-sync-button--delete",disabled:a,isSecondary:!0,isDestructive:!0,onClick:m,children:(0,u.__)("Delete all Data and Start a Fresh Sync","elasticpress")})}):null]}),(0,D.jsx)("div",{className:"ep-sync-panel__controls",children:(0,D.jsx)(T,{disabled:a,isPaused:r,isSyncing:i,onPause:y,onResume:h,onStop:_,onSync:g,showSync:S})}),f?(0,D.jsx)("div",{className:"ep-sync-panel__row",children:(0,D.jsx)(O,{dateTime:v,isCli:n,isComplete:t,isPaused:r,itemsProcessed:c,itemsTotal:l})}):null,(0,D.jsx)("div",{className:"ep-sync-panel__row",children:(0,D.jsx)(I,{messages:p})}),j?(0,D.jsx)("div",{className:"ep-sync-panel__row",children:(0,D.jsxs)("p",{className:"ep-sync-warning",children:[(0,D.jsx)(b.Icon,{icon:C}),j]})}):null]})})]}),G=({isCli:e,isComplete:s,isDeleting:n,isEpio:t,isSyncing:a,log:r,...i})=>{const c=null===i.lastSyncDateTime;return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("h1",{className:"ep-sync-heading",children:(0,u.__)("Sync Settings","elasticpress")}),(0,D.jsx)(W,{introduction:c?(0,u.sprintf)((0,u.__)("Run a sync to index your existing content %s. Once syncing finishes, your site is officially supercharged.","elasticpress"),t?(0,u.__)("on ElasticPress.io","elasticpress"):(0,u.__)("in Elasticsearch","elasticpress")):(0,u.__)("If you are missing data in your search results or have recently added custom content types to your site, you should run a sync to reflect these changes.","elasticpress"),isComplete:s,isDisabled:a&&n||a&&e,isSyncing:a&&!n,logMessages:r.filter((e=>!e.isDeleting)),showLastSync:!0,showProgress:!n&&(a||s),showSync:!0,...i}),c?null:(0,D.jsx)(W,{heading:(0,u.__)("Delete All Data and Sync","elasticpress"),introduction:(0,u.__)("If you are still having issues with your search results, you may need to do a completely fresh sync.","elasticpress"),isComplete:s,isDisabled:a&&!n||a&&e,isSyncing:a&&n,logMessages:r.filter((e=>e.isDeleting)),showDelete:!0,showProgress:n&&(a||s),warningMessage:(0,u.__)("All indexed data on ElasticPress will be deleted without affecting anything on your WordPress website. This may take a few hours depending on the amount of content that needs to be synced and indexed. While this is happening, searches will use the default WordPress results","elasticpress"),...i})]})};const $=()=>{const{cancelIndex:e,index:s,indexStatus:n}=(()=>{const e=(0,d.useRef)(new AbortController),s=(0,d.useRef)(null),n=(0,d.useCallback)((e=>(s.current=f()(e).finally((()=>{s.current=null})),s.current)),[]);return{cancelIndex:(0,d.useCallback)((async()=>{e.current.abort(),e.current=new AbortController;const s=new FormData;s.append("action","ep_cancel_index"),s.append("nonce",x);const t={url:m,method:"POST",body:s,signal:e.current.signal};return n(t)}),[n]),index:(0,d.useCallback)((async s=>{e.current.abort(),e.current=new AbortController;const t=new FormData;t.append("action","ep_index"),t.append("put_mapping",s?1:0),t.append("nonce",x);const a={url:m,method:"POST",body:t,signal:e.current.signal};return n(a)}),[n]),indexStatus:(0,d.useCallback)((async()=>{e.current.abort(),e.current=new AbortController;const s=new FormData;s.append("action","ep_index_status"),s.append("nonce",x);const t={url:m,method:"POST",body:s,signal:e.current.signal};return n(t)}),[n])}})(),[t,a]=(0,d.useState)([]),[r,i]=(0,d.useState)({isComplete:!1,isDeleting:!1,isSyncing:!1,itemsProcessed:0,itemsTotal:100,lastSyncDateTime:_,lastSyncFailed:g,syncStartDateTime:null}),c=(0,d.useRef)(r),l=e=>{c.current={...c.current,...e},i((s=>({...s,...e})))},w=(0,d.useCallback)(((e,s)=>{const{isDeleting:n}=c.current,t=Array.isArray(e)?e:[e];for(const e of t)a((t=>[...t,{message:e,status:s,isDeleting:n,id:o()}]))}),[]),b=(0,d.useCallback)((e=>{l({isComplete:!0,isPaused:!1,isSyncing:!1,lastSyncDateTime:e.end_date_time,lastSyncFailed:e.failed>0}),document.querySelector('[data-ep-notice="no_sync"]')?.remove()}),[]),j=(0,d.useCallback)((e=>{"AbortError"!==e.name&&(e.message&&w(e.message,"error"),e.data?.message&&w(e.data.message,"error"),w((0,u.__)("Sync failed","elasticpress"),"error"),l({isSyncing:!1}))}),[w]),C=(0,d.useCallback)((()=>{const{isDeleting:e}=c.current,s=e?(0,u.sprintf)((0,u.__)("Your indexing process has been stopped by WP-CLI and your %s index could be missing content. To restart indexing, please click the Start button or use WP-CLI commands to perform the reindex. Please note that search results could be incorrect or incomplete until the reindex finishes.","elasticpress"),h?(0,u.__)("ElasticPress.io","elasticpress"):(0,u.__)("Elasticsearch","elasticpress")):(0,u.__)("Sync interrupted by WP-CLI command.","elasticpress");w(s,"info"),l({isSyncing:!1})}),[w]),P=(0,d.useCallback)((e=>{const s=!(null===c.current.lastSyncDateTime)&&e.put_mapping;l({isCli:"cli"===e.method,isComplete:!1,isDeleting:s,isSyncing:!0,itemsProcessed:v(e),itemsTotal:S(e),syncStartDateTime:e.start_date_time})}),[]),N=(0,d.useCallback)((e=>{const{isPaused:s,isSyncing:n}=c.current,{message:t,status:a,totals:r=[],index_meta:i}=e.data;return new Promise((e=>{n&&(t&&w(t,a),Array.isArray(r)?(P(i),i.should_interrupt_sync?C():s?w((0,u.__)("Sync paused","elasticpress"),"info"):e(i.method)):b(r))}))}),[b,P,C,w]),k=(0,d.useCallback)((()=>{n().then(N).then(k).catch(j)}),[n,j,N]),L=(0,d.useCallback)((e=>{s(e).then(N).then((s=>{"cli"===s?k():L(e)})).catch(j)}),[k,s,j,N]),T=(0,d.useCallback)((()=>{l({isComplete:!1,isPaused:!0,isSyncing:!0})}),[]),E=(0,d.useCallback)((()=>{l({isComplete:!1,isPaused:!1,isSyncing:!1}),e()}),[e]),I=(0,d.useCallback)((()=>{const{isDeleting:e,lastSyncDateTime:s}=c.current,n=null===s||e;l({isComplete:!1,isPaused:!1,isSyncing:!0}),L(n)}),[L]),R=(0,d.useCallback)((e=>{const{lastSyncDateTime:s}=c.current,n=null===s,t=n||e;l({isComplete:!1,isDeleting:!n&&e,isPaused:!1,isSyncing:!0}),l({itemsProcessed:0,syncStartDateTime:Date.now()}),L(t)}),[L]);return(0,d.useEffect)((()=>{if(window.history.replaceState({},document.title,document.location.pathname+document.location.search.replace(/&do_sync/,"")),y)return P(y),void("cli"===y.method?(k(),w((0,u.__)("WP CLI sync in progress","elasticpress"),"info")):(T(),w((0,u.__)("Sync paused","elasticpress"),"info")));p&&(R(!0),w((0,u.__)("Starting delete and sync…","elasticpress"),"info"))}),[k,P,w,T,R]),(0,D.jsx)(G,{isEpio:h,log:t,onDelete:async()=>{R(!0),w((0,u.__)("Starting delete and sync…","elasticpress"),"info")},onPause:()=>{T(),w((0,u.__)("Pausing sync…","elasticpress"),"info")},onResume:()=>{I(),w((0,u.__)("Resuming sync…","elasticpress"),"info")},onStop:()=>{E(),w((0,u.__)("Sync stopped","elasticpress"),"info")},onSync:async()=>{R(!1),w((0,u.__)("Starting sync…","elasticpress"),"info")},...r})};(0,d.render)((0,D.jsx)($,{}),document.getElementById("ep-sync"))}()}(); |