diff --git a/build/content-helper/editor-sidebar.asset.php b/build/content-helper/editor-sidebar.asset.php index 46be3f36ae..efc2208c99 100644 --- a/build/content-helper/editor-sidebar.asset.php +++ b/build/content-helper/editor-sidebar.asset.php @@ -1 +1 @@ - array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'b3915e4d8c96c21e0c53'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-dom-ready', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url', 'wp-wordcount'), 'version' => 'c9080d57a24fb01fef39'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index fabc46e236..04a31caee3 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -17,4 +17,4 @@ text:"".concat(c(t)," - ").concat((0,w.sprintf)((0,w.__)("%s%%","wp-parsely"),n. (0,w.__)("Multiple results were returned for the post %d by the Parse.ly API.","wp-parsely"),t),U.ParselyApiReturnedTooManyResults))]:[2,n[0]]}}))}))},t.prototype.fetchReferrerDataFromWpEndpoint=function(e,t,n){return On(this,void 0,void 0,(function(){return An(this,(function(r){switch(r.label){case 0:return[4,this.fetch({path:(0,we.addQueryArgs)("/wp-parsely/v2/stats/post/".concat(t,"/referrers"),Cn(Cn({},ft(e)),{itm_source:this.itmSource,total_views:n}))})];case 1:return[2,r.sent()]}}))}))},t}(_e),Rn=function(){return Rn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&e.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return t.sent(),[4,n(r-1)];case 2:return t.sent(),[3,4];case 3:a(e),i(!1),t.label=4;case 4:return[2]}}))}))})),[2]}))}))};return i(!0),n(1),function(){a(void 0)}}),[t]),(0,f.jsxs)("div",{className:"wp-parsely-performance-panel",children:[(0,f.jsx)(gn,{title:(0,w.__)("Performance Stats","wp-parsely"),icon:vn,dropdownChildren:function(e){var t=e.onClose;return(0,f.jsx)(Gn,{onClose:t})},children:(0,f.jsx)("div",{className:"panel-settings",children:(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:d.PerformanceStats.Period,prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Period:","wp-parsely")}),onChange:function(e){F(e,R)&&(v({PerformanceStats:Rn(Rn({},d.PerformanceStats),{Period:e})}),k.trackEvent("editor_sidebar_performance_period_changed",{period:e}))},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})})}),o?o.Message():(0,f.jsxs)(f.Fragment,{children:[Vn(d,"overview")&&(0,f.jsx)(En,{data:c,isLoading:r}),Vn(d,"categories")&&(0,f.jsx)(yn,{data:c,isLoading:r}),Vn(d,"referrers")&&(0,f.jsx)(Ln,{data:c,isLoading:r})]}),window.wpParselyPostUrl&&(0,f.jsx)(h.Button,{className:"wp-parsely-view-post",variant:"secondary",onClick:function(){k.trackEvent("editor_sidebar_view_post_pressed")},href:window.wpParselyPostUrl,rel:"noopener",target:"_blank",children:(0,w.__)("View this in Parse.ly","wp-parsely")})]})},zn=function(e){var t=e.period;return(0,f.jsx)(h.Panel,{children:(0,f.jsx)(Re,{children:(0,f.jsx)(Hn,{period:t})})})},Un=function(e){var t=e.filters,n=e.postData,r=function(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(r=Object.getOwnPropertySymbols(e);i=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Author","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Author)},options:s,value:t.author}),n.categories.length>=1&&(0,f.jsx)(h.ComboboxControl,{__next40pxDefaultSize:!0,allowReset:!0,placeholder:(0,w.__)("Section","wp-parsely"),onChange:function(e){return r.onFiltersChange(e,M.Section)},options:i,value:t.section}),n.tags.length>=1&&(0,f.jsx)(h.FormTokenField,{__experimentalShowHowTo:!1,__next40pxDefaultSize:!0,label:"",placeholder:(0,w.__)("Tags","wp-parsely"),onChange:function(e){return r.onFiltersChange(e.toString(),M.Tag)},value:t.tags,suggestions:n.tags,maxLength:5})]})},qn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M10 17.389H8.444A5.194 5.194 0 1 1 8.444 7H10v1.5H8.444a3.694 3.694 0 0 0 0 7.389H10v1.5ZM14 7h1.556a5.194 5.194 0 0 1 0 10.39H14v-1.5h1.556a3.694 3.694 0 0 0 0-7.39H14V7Zm-4.5 6h5v-1.5h-5V13Z"})}),Kn=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M5.625 5.5h9.75c.069 0 .125.056.125.125v9.75a.125.125 0 0 1-.125.125h-9.75a.125.125 0 0 1-.125-.125v-9.75c0-.069.056-.125.125-.125ZM4 5.625C4 4.728 4.728 4 5.625 4h9.75C16.273 4 17 4.728 17 5.625v9.75c0 .898-.727 1.625-1.625 1.625h-9.75A1.625 1.625 0 0 1 4 15.375v-9.75Zm14.5 11.656v-9H20v9C20 18.8 18.77 20 17.251 20H6.25v-1.5h11.001c.69 0 1.249-.528 1.249-1.219Z"})}),Zn=function(e){var t=e.size,n=void 0===t?40:t,r=e.color,i=void 0===r?"#cccccc":r;return(0,f.jsx)(f.Fragment,{children:(0,f.jsx)(h.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"3",height:n,viewBox:"0 0 1 ".concat(n),fill:"none",children:(0,f.jsx)(h.Rect,{width:"1",height:n,fill:i})})})};function Wn(e){var t=e.metric,n=e.post,r=e.avgEngagedIcon,i=e.viewsIcon;return"views"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Number of Views","wp-parsely")}),i,Gt(n.views.toString())]}):"avg_engaged"===t?(0,f.jsxs)("span",{className:"parsely-post-metric-data",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("Average Time","wp-parsely")}),r,n.avgEngaged]}):(0,f.jsx)("span",{className:"parsely-post-metric-data",children:"-"})}var Yn=function(e){var t,n,r=e.metric,i=e.post,s=e.postContent,o=(0,v.useDispatch)("core/notices").createNotice,a=s&&(t=s,n=Ae(i.rawUrl),new RegExp("]*href=[\"'](http://|https://)?.*".concat(n,".*[\"'][^>]*>"),"i").test(t));return(0,f.jsxs)("div",{className:"related-post-single","data-testid":"related-post-single",children:[(0,f.jsx)("div",{className:"related-post-title",children:(0,f.jsxs)("a",{href:i.url,target:"_blank",rel:"noreferrer",children:[(0,f.jsx)("span",{className:"screen-reader-text",children:(0,w.__)("View on website (opens new tab)","wp-parsely")}),i.title]})}),(0,f.jsx)("div",{className:"related-post-actions",children:(0,f.jsxs)("div",{className:"related-post-info",children:[(0,f.jsxs)("div",{children:[(0,f.jsx)("div",{className:"related-post-metric",children:(0,f.jsx)(Wn,{metric:r,post:i,viewsIcon:(0,f.jsx)(ie,{icon:Bt}),avgEngagedIcon:(0,f.jsx)(h.Dashicon,{icon:"clock",size:24})})}),a&&(0,f.jsx)("div",{className:"related-post-linked",children:(0,f.jsx)(h.Tooltip,{text:(0,w.__)("This post is linked in the content","wp-parsely"),children:(0,f.jsx)(ie,{icon:qn,size:24})})})]}),(0,f.jsx)(Zn,{}),(0,f.jsxs)("div",{children:[(0,f.jsx)(h.Button,{icon:Kn,iconSize:24,onClick:function(){navigator.clipboard.writeText(i.rawUrl).then((function(){o("success",(0,w.__)("URL copied to clipboard","wp-parsely"),{type:"snackbar"})}))},label:(0,w.__)("Copy URL to clipboard","wp-parsely")}),(0,f.jsx)(h.Button,{icon:(0,f.jsx)(j,{}),iconSize:18,href:i.dashUrl,target:"_blank",label:(0,w.__)("View in Parse.ly","wp-parsely")})]})]})})]})},$n=window.wp.coreData,Jn=function(){var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},e(t,n)};return function(t,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function __(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(__.prototype=n.prototype,new __)}}(),Xn=function(){return Xn=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&f.every(Number.isInteger)?null!==(n=l("taxonomy","category",{include:f,context:"view"}))&&void 0!==n?n:void 0:null,tagRecords:o=Array.isArray(h)&&h.length>0&&h.every(Number.isInteger)?null!==(r=l("taxonomy","post_tag",{include:h,context:"view"}))&&void 0!==r?r:void 0:null,isLoading:u("getEntityRecords",["root","user",{include:[d],context:"view"}])||u("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||u("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}]),hasResolved:(c("getEntityRecords",["root","user",{include:[d],context:"view"}])||null===i)&&(c("getEntityRecords",["taxonomy","category",{include:f,context:"view"}])||null===s)&&(c("getEntityRecords",["taxonomy","post_tag",{include:h,context:"view"}])||null===o)}}),[]);return(0,m.useEffect)((function(){var e=r.authorRecords,t=r.categoryRecords,i=r.tagRecords,s=r.isLoading;r.hasResolved&&!s&&n({authors:e,categories:t,tags:i,isReady:!0})}),[r]),t}(),c=l.authors,u=l.categories,p=l.tags,d=l.isReady,g=function(e){return!(!Array.isArray(e)||0===e.length)&&e.every((function(e){return"name"in e&&"id"in e&&"slug"in e&&"description"in e&&"link"in e}))};(0,m.useEffect)((function(){if(d){var e,t=function(e){return g(e)?e.map((function(e){return e.name})):[]};a({authors:t(c),categories:(e=u,g(e)?e.map((function(e){return{name:e.name,slug:e.slug}})):[]),tags:t(p)})}}),[c,u,p,d]);var y=(0,v.useSelect)((function(e){var t=e(ir),n=t.isLoading,r=t.getPosts,i=t.getFilters;return{firstRun:(0,t.isFirstRun)(),loading:n(),posts:r(),filters:i()}}),[]),b=y.firstRun,_=y.loading,x=y.posts,S=y.filters,j=(0,v.useDispatch)(ir),P=j.setFirstRun,T=j.setLoading,E=j.setPosts,L=j.setFilters,N=(0,m.useState)(),C=N[0],O=N[1],A=(0,m.useState)(void 0),D=A[0],H=A[1],z=(0,ne.useDebounce)(H,1e3);(0,v.useSelect)((function(e){if("undefined"==typeof jest){var t=e("core/editor").getEditedPostContent;z(t())}else z("Jest test is running")}),[z]);var U=function(e,t,n,r){return ar(void 0,void 0,void 0,(function(){return lr(this,(function(i){return T(!0),tr.getInstance().getRelatedPosts(e,t,n).then((function(e){E(e),T(!1)})).catch((function(i){return ar(void 0,void 0,void 0,(function(){return lr(this,(function(s){switch(s.label){case 0:return r>0&&i.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return s.sent(),[4,U(e,t,n,r-1)];case 2:return s.sent(),[3,4];case 3:T(!1),O(i),E([]),s.label=4;case 4:return[2]}}))}))})),[2]}))}))};return b&&(U(r,i,S,1),P(!1)),0===o.authors.length&&0===o.categories.length&&0===o.tags.length&&d?(0,f.jsx)("div",{className:"wp-parsely-related-posts",children:(0,f.jsx)("div",{className:"related-posts-body",children:(0,w.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,f.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,f.jsx)("div",{className:"related-posts-description",children:(0,w.__)("Find top-performing related posts.","wp-parsely")}),(0,f.jsxs)("div",{className:"related-posts-body",children:[(0,f.jsxs)("div",{className:"related-posts-settings",children:[(0,f.jsx)(h.SelectControl,{size:"__unstable-large",onChange:function(e){return function(e){if(F(e,B)){var i=e;n({RelatedPosts:or(or({},t.RelatedPosts),{Metric:i})}),k.trackEvent("related_posts_metric_changed",{metric:i}),U(r,i,S,1)}}(e)},prefix:(0,f.jsx)(h.__experimentalInputControlPrefixWrapper,{children:(0,w.__)("Metric:","wp-parsely")}),value:i,children:Object.values(B).map((function(e){return(0,f.jsx)("option",{value:e,children:G(e)},e)}))}),(0,f.jsx)(h.SelectControl,{size:"__unstable-large",value:r,prefix:(0,f.jsxs)(h.__experimentalInputControlPrefixWrapper,{children:[(0,w.__)("Period:","wp-parsely")," "]}),onChange:function(e){return function(e){if(F(e,R)){var r=e;n({RelatedPosts:or(or({},t.RelatedPosts),{Period:r})}),k.trackEvent("related_posts_period_changed",{period:r}),U(r,i,S,1)}}(e)},children:Object.values(R).map((function(e){return(0,f.jsx)("option",{value:e,children:V(e)},e)}))})]}),(0,f.jsx)(Un,{label:(0,w.__)("Filter by","wp-parsely"),filters:S,onFiltersChange:function(e,t){var n,s;if(null==e&&(e=""),M.Tag===t){var o=[];""!==e&&(o=e.split(",").map((function(e){return e.trim()}))),s=or(or({},S),{tags:o})}else s=or(or({},S),((n={})[t]=e,n));L(s),U(r,i,s,1)},postData:o}),(0,f.jsxs)("div",{className:"related-posts-wrapper",children:[C&&C.Message(),_&&(0,f.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,w.__)("Loading…","wp-parsely")}),!b&&!_&&!C&&0===x.length&&(0,f.jsx)("div",{className:"related-posts-empty",children:(0,w.__)("No related posts found.","wp-parsely")}),!_&&x.length>0&&(0,f.jsx)("div",{className:"related-posts-list",children:x.map((function(e){return(0,f.jsx)(Yn,{metric:i,post:e,postContent:D},e.id)}))})]})]})]})},ur=(0,f.jsx)(b.SVG,{viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",children:(0,f.jsx)(b.Path,{d:"M10.97 10.159a3.382 3.382 0 0 0-2.857.955l1.724 1.723-2.836 2.913L7 17h1.25l2.913-2.837 1.723 1.723a3.38 3.38 0 0 0 .606-.825c.33-.63.446-1.343.35-2.032L17 10.695 13.305 7l-2.334 3.159Z"})}),pr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"M18.3 11.7c-.6-.6-1.4-.9-2.3-.9H6.7l2.9-3.3-1.1-1-4.5 5L8.5 16l1-1-2.7-2.7H16c.5 0 .9.2 1.3.5 1 1 1 3.4 1 4.5v.3h1.5v-.2c0-1.5 0-4.3-1.5-5.7z"})}),dr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M12 5.5A2.25 2.25 0 0 0 9.878 7h4.244A2.251 2.251 0 0 0 12 5.5ZM12 4a3.751 3.751 0 0 0-3.675 3H5v1.5h1.27l.818 8.997a2.75 2.75 0 0 0 2.739 2.501h4.347a2.75 2.75 0 0 0 2.738-2.5L17.73 8.5H19V7h-3.325A3.751 3.751 0 0 0 12 4Zm4.224 4.5H7.776l.806 8.861a1.25 1.25 0 0 0 1.245 1.137h4.347a1.25 1.25 0 0 0 1.245-1.137l.805-8.861Z"})}),fr=(0,f.jsx)(b.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",children:(0,f.jsx)(b.Path,{d:"m21.5 9.1-6.6-6.6-4.2 5.6c-1.2-.1-2.4.1-3.6.7-.1 0-.1.1-.2.1-.5.3-.9.6-1.2.9l3.7 3.7-5.7 5.7v1.1h1.1l5.7-5.7 3.7 3.7c.4-.4.7-.8.9-1.2.1-.1.1-.2.2-.3.6-1.1.8-2.4.6-3.6l5.6-4.1zm-7.3 3.5.1.9c.1.9 0 1.8-.4 2.6l-6-6c.8-.4 1.7-.5 2.6-.4l.9.1L15 4.9 19.1 9l-4.9 3.6z"})}),hr=function(){return hr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]0?(0,f.jsx)("span",{className:"parsely-write-titles-text",children:(0,m.createInterpolateElement)( // translators: %1$s is the tone, %2$s is the persona. // translators: %1$s is the tone, %2$s is the persona. -(0,w.__)("We've generated a few titles based on the content of your post, written as a .","wp-parsely"),{tone:(0,f.jsx)("strong",{children:he(a)}),persona:(0,f.jsx)("strong",{children:le(u)})})}):(0,w.__)("Use Parse.ly AI to generate a title for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/title-suggestions/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Title Suggestions","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),i&&(0,f.jsx)(h.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return s(void 0)},status:"info",children:i.Message()}),void 0!==S&&(0,f.jsx)(_r,{title:S,type:sr.PostTitle,isOriginal:!0}),0<_.length&&(0,f.jsxs)(f.Fragment,{children:[b.length>0&&(0,f.jsx)(xr,{pinnedTitles:b,isOpen:!0}),y.length>0&&(0,f.jsx)(Sr,{suggestions:y,isOpen:!0,isLoading:g})]}),(0,f.jsx)(kr,{isLoading:g,onPersonaChange:function(e){C("Persona",e),p(e)},onSettingChange:C,onToneChange:function(e){C("Tone",e),l(e)},persona:t.TitleSuggestions.Persona,tone:t.TitleSuggestions.Tone}),(0,f.jsx)("div",{className:"title-suggestions-generate",children:(0,f.jsxs)(h.Button,{variant:"secondary",isBusy:g,disabled:g||"custom"===a||"custom"===u,onClick:function(){return Er(void 0,void 0,void 0,(function(){return Lr(this,(function(e){switch(e.label){case 0:return s(void 0),!1!==g?[3,2]:(k.trackEvent("title_suggestions_generate_pressed",{request_more:y.length>0,total_titles:y.length,total_pinned:y.filter((function(e){return e.isPinned})).length,tone:a,persona:u}),[4,(t=sr.PostTitle,n=O,r=a,i=u,Er(void 0,void 0,void 0,(function(){var e,o,a;return Lr(this,(function(l){switch(l.label){case 0:return[4,T(!0)];case 1:l.sent(),e=Pr.getInstance(),l.label=2;case 2:return l.trys.push([2,5,,6]),[4,e.generateTitles(n,3,r,i)];case 3:return o=l.sent(),[4,P(t,o)];case 4:return l.sent(),[3,6];case 5:return a=l.sent(),s(a),P(t,[]),[3,6];case 6:return[4,T(!1)];case 7:return l.sent(),[2]}}))})))]);case 1:e.sent(),e.label=2;case 2:return[2]}var t,n,r,i}))}))},children:[g&&(0,w.__)("Generating Titles…","wp-parsely"),!g&&_.length>0&&(0,w.__)("Generate More","wp-parsely"),!g&&0===_.length&&(0,w.__)("Generate Titles","wp-parsely")]})})]})})},Cr=function(){return Cr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&u&&r.TrafficBoost&&(0,f.jsxs)(h.Button,{className:"boost-engagement",href:"/wp-admin/admin.php?page=parsely-dashboard-page#/engagement-boost/".concat(l),rel:"noopener",target:"_blank",variant:"secondary",children:[(0,w.__)("Boost Engagement","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]})},Ar=function(){return Ar=Object.assign||function(e){for(var t,n=1,r=arguments.length;n titles based on the content of your post, written as a .","wp-parsely"),{tone:(0,f.jsx)("strong",{children:he(a)}),persona:(0,f.jsx)("strong",{children:le(u)})})}):(0,w.__)("Use Parse.ly AI to generate a title for your post.","wp-parsely"),(0,f.jsxs)(h.Button,{href:"https://docs.wpvip.com/parse-ly/wp-parsely-features/title-suggestions/",target:"_blank",variant:"link",children:[(0,w.__)("Learn more about Title Suggestions","wp-parsely"),(0,f.jsx)(ie,{icon:$,size:18,className:"parsely-external-link-icon"})]})]}),i&&(0,f.jsx)(h.Notice,{className:"wp-parsely-content-helper-error",onRemove:function(){return s(void 0)},status:"info",children:i.Message()}),void 0!==S&&(0,f.jsx)(_r,{title:S,type:sr.PostTitle,isOriginal:!0}),0<_.length&&(0,f.jsxs)(f.Fragment,{children:[b.length>0&&(0,f.jsx)(xr,{pinnedTitles:b,isOpen:!0}),y.length>0&&(0,f.jsx)(Sr,{suggestions:y,isOpen:!0,isLoading:g})]}),(0,f.jsx)(kr,{isLoading:g,onPersonaChange:function(e){C("Persona",e),p(e)},onSettingChange:C,onToneChange:function(e){C("Tone",e),l(e)},persona:t.TitleSuggestions.Persona,tone:t.TitleSuggestions.Tone}),(0,f.jsx)("div",{className:"title-suggestions-generate",children:(0,f.jsxs)(h.Button,{variant:"secondary",isBusy:g,disabled:g||"custom"===a||"custom"===u,onClick:function(){return Er(void 0,void 0,void 0,(function(){return Lr(this,(function(e){switch(e.label){case 0:return s(void 0),!1!==g?[3,2]:(k.trackEvent("title_suggestions_generate_pressed",{request_more:y.length>0,total_titles:y.length,total_pinned:y.filter((function(e){return e.isPinned})).length,tone:a,persona:u}),[4,(t=sr.PostTitle,n=O,r=a,i=u,Er(void 0,void 0,void 0,(function(){var e,o,a;return Lr(this,(function(l){switch(l.label){case 0:return[4,T(!0)];case 1:l.sent(),e=Pr.getInstance(),l.label=2;case 2:return l.trys.push([2,5,,6]),[4,e.generateTitles(n,3,r,i)];case 3:return o=l.sent(),[4,P(t,o)];case 4:return l.sent(),[3,6];case 5:return a=l.sent(),s(a),P(t,[]),[3,6];case 6:return[4,T(!1)];case 7:return l.sent(),[2]}}))})))]);case 1:e.sent(),e.label=2;case 2:return[2]}var t,n,r,i}))}))},children:[g&&(0,w.__)("Generating Titles…","wp-parsely"),!g&&_.length>0&&(0,w.__)("Generate More","wp-parsely"),!g&&0===_.length&&(0,w.__)("Generate Titles","wp-parsely")]})})]})})},Cr=function(){return Cr=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&u&&r.TrafficBoost&&(0,f.jsxs)(h.Button,{className:"boost-engagement",href:"/wp-admin/admin.php?page=parsely-dashboard-page#/engagement-boost/".concat(l),rel:"noopener",target:"_blank",variant:"secondary",children:[(0,w.__)("Boost Engagement","wp-parsely"),(0,f.jsx)(h.Icon,{icon:$,size:18,className:"parsely-external-link-icon"})]})]})})},Ar=function(){return Ar=Object.assign||function(e){for(var t,n=1,r=arguments.length;n - { permissions.TitleSuggestions && + + { permissions.TitleSuggestions && - - - + - } + } - { - permissions.ExcerptSuggestions && - - { - setSettings( { - ExcerptSuggestions: { - ...settings.ExcerptSuggestions, - Open: next, - }, - } ); - trackToggle( 'excerpt_suggestions', next ); - } } - > - + { + permissions.ExcerptSuggestions && + + { + setSettings( { + ExcerptSuggestions: { + ...settings.ExcerptSuggestions, + Open: next, + }, + } ); + trackToggle( 'excerpt_suggestions', next ); + } } + > - - - - } + + + } - { permissions.SmartLinking && + { permissions.SmartLinking && - - - + - } - - { - setSettings( { - RelatedPosts: { - ...settings.RelatedPosts, - Open: next, - }, - } ); - trackToggle( 'related_top_posts', next ); - } } - > - { - - - } - - { postId > 0 && isPostTrackable && permissions.TrafficBoost && - - } + + + + { postId > 0 && isPostTrackable && permissions.TrafficBoost && + + } + ); }; diff --git a/tests/e2e/specs/content-helper/top-bar-icon.spec.ts b/tests/e2e/specs/content-helper/top-bar-icon.spec.ts index e952234edf..7785232833 100644 --- a/tests/e2e/specs/content-helper/top-bar-icon.spec.ts +++ b/tests/e2e/specs/content-helper/top-bar-icon.spec.ts @@ -13,7 +13,7 @@ import { import { VALID_API_SECRET, VALID_SITE_ID, - setSidebarPanelExpanded, + getSidebarPanelOrTabMessage, setSiteKeys, } from '../../utils'; @@ -152,13 +152,10 @@ class Utils { await setSiteKeys( page, siteId, apiSecret ); await this.admin.createNewPost(); - // Click the top bar icon and // Expand the Related Posts panel. + // Click the top bar icon. await page.getByRole( 'button', { name: 'Parse.ly' } ).click(); - setSidebarPanelExpanded( page, 'Related Posts', true ); - return await page.locator( - '.wp-parsely-content-helper div.components-panel__body.is-opened ' + selector - ).textContent() ?? ''; + return getSidebarPanelOrTabMessage( page, selector ); } /** diff --git a/tests/e2e/utils.ts b/tests/e2e/utils.ts index 0e030729b8..18c9ef7f48 100644 --- a/tests/e2e/utils.ts +++ b/tests/e2e/utils.ts @@ -50,15 +50,56 @@ export const getRelatedPostsMessage = async ( admin: Admin, selector: string = '.content-helper-error-message' ): Promise => { const page = admin.page; - const contentHelperMessageSelector = '.wp-parsely-content-helper div.components-panel__body.is-opened ' + selector; await admin.createNewPost(); - // Show the Content Intelligence Sidebar and expand the Related Posts panel. + // Show the Content Intelligence Sidebar. await page.getByRole( 'button', { name: 'Parse.ly' } ).click(); - await setSidebarPanelExpanded( page, 'Related Posts', true ); - return await page.locator( contentHelperMessageSelector ).textContent() ?? ''; + return getSidebarPanelOrTabMessage( page, selector ); +}; + +/** + * Gets a message from the PCI Editor Sidebar, expanding the Related Posts + * panel when available, or reading the message from the tab level otherwise. + * + * When credentials are present, the Related Posts panel is visible and the + * message is found inside the opened panel body. When credentials are absent, + * the Related Posts panel is not rendered and the message appears at the tab + * level instead. + * + * @since 3.22.1 + * + * @param {Page} page The Page object of the calling function. + * @param {string} selector The selector from which to extract the message. + * + * @return {Promise} The message returned. + */ +export const getSidebarPanelOrTabMessage = async ( + page: Page, selector: string = '.content-helper-error-message' +): Promise => { + // Wait for the sidebar content to render. + await page.locator( '.wp-parsely-content-helper' ).waitFor( { state: 'visible' } ); + + const relatedPostsButton = page.getByRole( 'button', { name: 'Related Posts' } ); + const hasRelatedPostsPanel = ( await relatedPostsButton.count() ) > 0; + + // When credentials are absent, the Related Posts panel is not shown and + // the message appears at the tab level. + if ( hasRelatedPostsPanel ) { + await setSidebarPanelExpanded( page, 'Related Posts', true ); + const panelMessage = page.locator( + '.wp-parsely-content-helper div.components-panel__body.is-opened ' + selector + ); + await panelMessage.waitFor( { state: 'visible' } ); + + return ( await panelMessage.textContent() ) ?? ''; + } + + const tabMessage = page.locator( '.wp-parsely-content-helper ' + selector ); + await tabMessage.waitFor( { state: 'visible' } ); + + return ( await tabMessage.textContent() ) ?? ''; }; /**