From f03c6785b5e3b0fe5e84bcbb441c5e7e09b24cfe Mon Sep 17 00:00:00 2001 From: Alex Cicovic <23142906+acicovic@users.noreply.github.com> Date: Thu, 9 May 2024 12:35:46 +0300 Subject: [PATCH] Fix: Make PCH Related Posts filters work for non-admins --- build/content-helper/editor-sidebar.asset.php | 2 +- build/content-helper/editor-sidebar.js | 2 +- .../editor-sidebar/related-posts/component.tsx | 5 ++++- src/content-helper/editor-sidebar/related-posts/hooks.ts | 6 +++--- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/build/content-helper/editor-sidebar.asset.php b/build/content-helper/editor-sidebar.asset.php index 3df7b0ab1..2a3019a72 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-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'eb6c5ec223f3254dbe5a'); + array('react', 'wp-api-fetch', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-core-data', 'wp-data', 'wp-edit-post', 'wp-editor', 'wp-element', 'wp-hooks', 'wp-i18n', 'wp-plugins', 'wp-primitives', 'wp-url'), 'version' => 'a16d4a6df7ef859f50df'); diff --git a/build/content-helper/editor-sidebar.js b/build/content-helper/editor-sidebar.js index d73f6b243..6e56c1d8e 100644 --- a/build/content-helper/editor-sidebar.js +++ b/build/content-helper/editor-sidebar.js @@ -16,7 +16,7 @@ message:(0,c.sprintf)((0,c.__)('with tag "%1$s"',"wp-parsely"),n.value)};if(r.Se /* translators: %s: message such as "in category Foo" */ message:(0,c.sprintf)((0,c.__)('in section "%1$s"',"wp-parsely"),n.value)};if(r.Author===n.type)return{query:at({author:n.value},s), /* translators: %s: message such as "by author John" */ -message:(0,c.sprintf)((0,c.__)('by author "%1$s"',"wp-parsely"),n.value)};throw new J((0,c.__)("No valid filter type has been specified.","wp-parsely"),q.CannotFormulateApiQuery)},e}(),ut=function(){return ut=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&s[s.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!s||l[1]>s[0]&&l[1]0&&u.every(Number.isInteger)?null!==(n=o("taxonomy","category",{include:u}))&&void 0!==n?n:void 0:null,tags:a=Array.isArray(p)&&p.length>0&&p.every(Number.isInteger)?null!==(r=o("taxonomy","post_tag",{include:p}))&&void 0!==r?r:void 0:null,isReady:void 0!==s&&void 0!==i&&void 0!==a}}),[]);return{authors:e.authors,categories:e.categories,tags:e.tags,isReady:e.isReady}}(),m=v.authors,w=v.categories,_=v.tags,b=v.isReady;(0,o.useEffect)((function(){if(b){var e=function(e){return 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}))}(e)?e.map((function(e){return e.name})):[]};y({authors:e(m),categories:e(w),tags:e(_)})}}),[m,w,_,b]);var x=(0,o.useState)(!0),P=x[0],S=x[1],j=(0,o.useState)(),L=j[0],N=j[1],O=(0,o.useState)(),R=O[0],I=O[1],B=(0,o.useState)([]),M=B[0],D=B[1],V=(0,o.useState)({type:l.RelatedPosts.FilterBy,value:l.RelatedPosts.FilterValue}),F=V[0],G=V[1],H=(0,o.useState)(void 0),z=H[0],W=H[1],U=(0,A.useDebounce)(W,1e3);(0,a.useSelect)((function(e){var t=e("core/editor").getEditedPostContent;U(t())}),[U]);var Z=function(e,t){u({RelatedPosts:ut(ut({},l.RelatedPosts),{FilterBy:e,FilterValue:t})})};return(0,o.useEffect)((function(){var e,t,n=function(e){return pt(void 0,void 0,void 0,(function(){return dt(this,(function(t){return ct.getRelatedPosts(p,d,F).then((function(e){D(e.posts),I(e.message),S(!1)})).catch((function(t){return pt(void 0,void 0,void 0,(function(){return dt(this,(function(r){switch(r.label){case 0:return e>0&&t.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,n(e-1)];case 2:return r.sent(),[3,4];case 3:S(!1),N(t),r.label=4;case 4:return[2]}}))}))})),[2]}))}))},s=r.Author===F.type,i=r.Tag===F.type,a=r.Section===F.type,l=r.Unavailable===F.type,o=0===h.authors.length,c=0===h.tags.length,u=0===h.categories.length,f=i&&!h.tags.includes(F.value),g=a&&!h.categories.includes(F.value);return S(!0),l||i&&c||a&&u||s&&o?Object.values(h).every((function(e){return 0===e.length}))||G((e="",t=r.Unavailable,h.tags.length>=1?(t=r.Tag,e=h.tags[0]):h.categories.length>=1?(t=r.Section,e=h.categories[0]):h.authors.length>=1&&(t=r.Author,e=h.authors[0]),{type:t,value:e})):f?G({type:r.Tag,value:h.tags[0]}):g?G({type:r.Section,value:h.categories[0]}):n(1),function(){S(!1),D([]),I(""),N(void 0)}}),[p,d,F,h]),0===h.authors.length&&0===h.categories.length&&0===h.tags.length?(0,s.jsx)("div",{className:"wp-parsely-related-posts",children:(0,s.jsx)("div",{className:"related-posts-body",children:(0,c.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,s.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,s.jsx)("div",{className:"related-posts-description",children:(0,c.__)("Find top-performing related posts based on a key metric.","wp-parsely")}),(0,s.jsxs)("div",{className:"related-posts-body",children:[(0,s.jsxs)("div",{className:"related-posts-settings",children:[(0,s.jsx)(i.SelectControl,{size:"__unstable-large",onChange:function(e){var n;T(n=e,t)&&(u({RelatedPosts:ut(ut({},l.RelatedPosts),{Metric:n})}),g.trackEvent("related_posts_metric_changed",{metric:n}))},prefix:(0,s.jsx)(i.__experimentalInputControlPrefixWrapper,{children:(0,c.__)("Metric: ","wp-parsely")}),value:d,children:Object.values(t).map((function(e){return(0,s.jsx)("option",{value:e,children:C(e)},e)}))}),(0,s.jsx)(i.SelectControl,{size:"__unstable-large",value:p,prefix:(0,s.jsxs)(i.__experimentalInputControlPrefixWrapper,{children:[(0,c.__)("Period: ","wp-parsely")," "]}),onChange:function(t){return function(t){T(t,e)&&(u({RelatedPosts:ut(ut({},l.RelatedPosts),{Period:t})}),g.trackEvent("related_posts_period_changed",{period:t}))}(t)},children:Object.values(e).map((function(e){return(0,s.jsx)("option",{value:e,children:E(e)},e)}))})]}),(0,s.jsx)(Qe,{label:(0,c.__)("Filter by","wp-parsely"),filter:F,onFilterTypeChange:function(e){if(T(e,r)){var t="",n=e;r.Tag===n&&(t=h.tags[0]),r.Section===n&&(t=h.categories[0]),r.Author===n&&(t=h.authors[0]),""!==t&&(Z(n,t),G({type:n,value:t}),g.trackEvent("related_posts_filter_type_changed",{filter_type:n}))}},onFilterValueChange:function(e){"string"==typeof e&&(Z(F.type,e),G(ut(ut({},F),{value:e})))},postData:h}),(0,s.jsxs)("div",{className:"related-posts-wrapper",children:[(0,s.jsx)("div",{children:(0,s.jsx)("p",{className:"related-posts-descr","data-testid":"parsely-related-posts-descr",children:r.Tag===F.type?(0,c.sprintf)(/* translators: 1: tag name, 2: period */ +message:(0,c.sprintf)((0,c.__)('by author "%1$s"',"wp-parsely"),n.value)};throw new J((0,c.__)("No valid filter type has been specified.","wp-parsely"),q.CannotFormulateApiQuery)},e}(),ut=function(){return ut=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&s[s.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!s||l[1]>s[0]&&l[1]0&&u.every(Number.isInteger)?null!==(n=o("taxonomy","category",{include:u,context:"view"}))&&void 0!==n?n:void 0:null,tags:a=Array.isArray(p)&&p.length>0&&p.every(Number.isInteger)?null!==(r=o("taxonomy","post_tag",{include:p,context:"view"}))&&void 0!==r?r:void 0:null,isReady:void 0!==s&&void 0!==i&&void 0!==a}}),[]);return{authors:e.authors,categories:e.categories,tags:e.tags,isReady:e.isReady}}(),m=v.authors,w=v.categories,_=v.tags,b=v.isReady;(0,o.useEffect)((function(){if(b){var e=function(e){return 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}))}(e)?e.map((function(e){return e.name})):[]};y({authors:e(m),categories:e(w),tags:e(_)})}}),[m,w,_,b]);var x=(0,o.useState)(!0),P=x[0],S=x[1],j=(0,o.useState)(),L=j[0],N=j[1],O=(0,o.useState)(),R=O[0],I=O[1],B=(0,o.useState)([]),M=B[0],D=B[1],V=(0,o.useState)({type:l.RelatedPosts.FilterBy,value:l.RelatedPosts.FilterValue}),F=V[0],G=V[1],H=(0,o.useState)(void 0),z=H[0],W=H[1],U=(0,A.useDebounce)(W,1e3);(0,a.useSelect)((function(e){var t=e("core/editor").getEditedPostContent;U(t())}),[U]);var Z=function(e,t){u({RelatedPosts:ut(ut({},l.RelatedPosts),{FilterBy:e,FilterValue:t})})};return(0,o.useEffect)((function(){var e,t,n=function(e){return pt(void 0,void 0,void 0,(function(){return dt(this,(function(t){return ct.getRelatedPosts(p,d,F).then((function(e){D(e.posts),I(e.message),S(!1)})).catch((function(t){return pt(void 0,void 0,void 0,(function(){return dt(this,(function(r){switch(r.label){case 0:return e>0&&t.retryFetch?[4,new Promise((function(e){return setTimeout(e,500)}))]:[3,3];case 1:return r.sent(),[4,n(e-1)];case 2:return r.sent(),[3,4];case 3:S(!1),N(t),r.label=4;case 4:return[2]}}))}))})),[2]}))}))},s=r.Author===F.type,i=r.Tag===F.type,a=r.Section===F.type,l=r.Unavailable===F.type,o=0===h.authors.length,c=0===h.tags.length,u=0===h.categories.length,f=s&&!h.authors.includes(F.value),g=i&&!h.tags.includes(F.value),y=a&&!h.categories.includes(F.value);return S(!0),l||i&&c||a&&u||s&&o?Object.values(h).every((function(e){return 0===e.length}))||G((e="",t=r.Unavailable,h.tags.length>=1?(t=r.Tag,e=h.tags[0]):h.categories.length>=1?(t=r.Section,e=h.categories[0]):h.authors.length>=1&&(t=r.Author,e=h.authors[0]),{type:t,value:e})):g?G({type:r.Tag,value:h.tags[0]}):y?G({type:r.Section,value:h.categories[0]}):f?G({type:r.Author,value:h.authors[0]}):n(1),function(){S(!1),D([]),I(""),N(void 0)}}),[p,d,F,h]),0===h.authors.length&&0===h.categories.length&&0===h.tags.length&&b?(0,s.jsx)("div",{className:"wp-parsely-related-posts",children:(0,s.jsx)("div",{className:"related-posts-body",children:(0,c.__)("Error: No author, section, or tags could be found for this post.","wp-parsely")})}):(0,s.jsxs)("div",{className:"wp-parsely-related-posts",children:[(0,s.jsx)("div",{className:"related-posts-description",children:(0,c.__)("Find top-performing related posts based on a key metric.","wp-parsely")}),(0,s.jsxs)("div",{className:"related-posts-body",children:[(0,s.jsxs)("div",{className:"related-posts-settings",children:[(0,s.jsx)(i.SelectControl,{size:"__unstable-large",onChange:function(e){var n;T(n=e,t)&&(u({RelatedPosts:ut(ut({},l.RelatedPosts),{Metric:n})}),g.trackEvent("related_posts_metric_changed",{metric:n}))},prefix:(0,s.jsx)(i.__experimentalInputControlPrefixWrapper,{children:(0,c.__)("Metric: ","wp-parsely")}),value:d,children:Object.values(t).map((function(e){return(0,s.jsx)("option",{value:e,children:C(e)},e)}))}),(0,s.jsx)(i.SelectControl,{size:"__unstable-large",value:p,prefix:(0,s.jsxs)(i.__experimentalInputControlPrefixWrapper,{children:[(0,c.__)("Period: ","wp-parsely")," "]}),onChange:function(t){return function(t){T(t,e)&&(u({RelatedPosts:ut(ut({},l.RelatedPosts),{Period:t})}),g.trackEvent("related_posts_period_changed",{period:t}))}(t)},children:Object.values(e).map((function(e){return(0,s.jsx)("option",{value:e,children:E(e)},e)}))})]}),(0,s.jsx)(Qe,{label:(0,c.__)("Filter by","wp-parsely"),filter:F,onFilterTypeChange:function(e){if(T(e,r)){var t="",n=e;r.Tag===n&&(t=h.tags[0]),r.Section===n&&(t=h.categories[0]),r.Author===n&&(t=h.authors[0]),""!==t&&(Z(n,t),G({type:n,value:t}),g.trackEvent("related_posts_filter_type_changed",{filter_type:n}))}},onFilterValueChange:function(e){"string"==typeof e&&(Z(F.type,e),G(ut(ut({},F),{value:e})))},postData:h}),(0,s.jsxs)("div",{className:"related-posts-wrapper",children:[(0,s.jsx)("div",{children:(0,s.jsx)("p",{className:"related-posts-descr","data-testid":"parsely-related-posts-descr",children:r.Tag===F.type?(0,c.sprintf)(/* translators: 1: tag name, 2: period */ (0,c.__)("Top related posts with the “%1$s” tag in the %2$s.","wp-parsely"),F.value,E(p,!0)):r.Section===F.type?(0,c.sprintf)(/* translators: 1: section name, 2: period */ (0,c.__)("Top related posts in the “%1$s” section in the %2$s.","wp-parsely"),F.value,E(p,!0)):r.Author===F.type?(0,c.sprintf)(/* translators: 1: author name, 2: period */ (0,c.__)("Top related posts by %1$s in the %2$s.","wp-parsely"),F.value,E(p,!0)):null!=R?R:""})}),L&&L.Message(),P&&(0,s.jsx)("div",{className:"related-posts-loading-message","data-testid":"parsely-related-posts-loading-message",children:(0,c.__)("Loading…","wp-parsely")}),!P&&!L&&0===M.length&&(0,s.jsx)("div",{className:"related-posts-empty","data-testid":"parsely-related-posts-empty",children:(0,c.__)("No related posts found.","wp-parsely")}),!P&&M.length>0&&(0,s.jsx)("div",{className:"related-posts-list",children:M.map((function(e){return(0,s.jsx)(rt,{metric:d,post:e,postContent:z},e.id)}))})]})]})]})},gt=(0,u.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,u.createElement)(p.Path,{d:"m19 7-3-3-8.5 8.5-1 4 4-1L19 7Zm-7 11.5H5V20h7v-1.5Z"})),ht=function(){return(0,s.jsx)(i.SVG,{xmlns:"http://www.w3.org/2000/svg",width:"18",height:"18",viewBox:"0 0 18 18",fill:"none",children:(0,s.jsx)(i.Path,{fillRule:"evenodd",clipRule:"evenodd",d:"M13.5034 7.91642L9 12.0104L4.49662 7.91642L5.25337 7.08398L8.99999 10.49L12.7466 7.08398L13.5034 7.91642Z",fill:"#1E1E1E"})})},yt={journalist:{label:(0,c.__)("Journalist","wp-parsely")},editorialWriter:{label:(0,c.__)("Editorial Writer","wp-parsely")},investigativeReporter:{label:(0,c.__)("Investigative Reporter","wp-parsely")},techAnalyst:{label:(0,c.__)("Tech Analyst","wp-parsely")},businessAnalyst:{label:(0,c.__)("Business Analyst","wp-parsely")},culturalCommentator:{label:(0,c.__)("Cultural Commentator","wp-parsely")},scienceCorrespondent:{label:(0,c.__)("Science Correspondent","wp-parsely")},politicalAnalyst:{label:(0,c.__)("Political Analyst","wp-parsely")},healthWellnessAdvocate:{label:(0,c.__)("Health and Wellness Advocate","wp-parsely")},environmentalJournalist:{label:(0,c.__)("Environmental Journalist","wp-parsely")},custom:{label:(0,c.__)("Custom Persona","wp-parsely"),icon:gt}},vt=Object.keys(yt),mt=function(e){return"custom"===e||""===e?yt.custom.label:wt(e)?e:yt[e].label},wt=function(e){return!vt.includes(e)||"custom"===e},_t=function(e){var t=e.value,n=e.onChange,r=(0,o.useState)(""),a=r[0],l=r[1],u=(0,A.useDebounce)(n,500);return(0,s.jsx)("div",{className:"parsely-persona-selector-custom",children:(0,s.jsx)(i.TextControl,{value:a||t,placeholder:(0,c.__)("Enter a custom persona…","wp-parsely"),onChange:function(e){if(""===e)return n(""),void l("");e.length>32&&(e=e.slice(0,32)),u(e),l(e)}})})},bt=function(e){var t=e.persona,n=e.value,r=void 0===n?(0,c.__)("Select a persona…","wp-parsely"):n,a=e.label,l=void 0===a?(0,c.__)("Persona","wp-parsely"):a,o=e.onChange,u=e.onDropdownChange,p=e.disabled,d=void 0!==p&&p,f=e.allowCustom,g=void 0!==f&&f;return(0,s.jsxs)(i.Disabled,{isDisabled:d,children:[l&&(0,s.jsx)("div",{className:"wp-parsely-dropdown-label",children:l}),(0,s.jsx)(i.DropdownMenu,{label:(0,c.__)("Persona","wp-parsely"),className:"parsely-persona-selector-dropdown"+(d?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"parsely-persona-selector-label",children:wt(t)?yt.custom.label:r}),(0,s.jsx)(ht,{})]})},children:function(e){var n=e.onClose;return(0,s.jsx)(i.MenuGroup,{label:(0,c.__)("Persona","wp-parsely"),children:(0,s.jsx)(s.Fragment,{children:vt.map((function(e){if(!g&&"custom"===e)return null;var r=yt[e],a=e===t||wt(t)&&"custom"===e;return(0,s.jsxs)(i.MenuItem,{isSelected:a,className:a?"is-selected":"",role:"menuitemradio",onClick:function(){null==u||u(e),o(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-persona-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,s.jsx)(D,{icon:r.icon}),r.label]},e)}))})})}}),g&&wt(t)&&(0,s.jsx)(_t,{onChange:function(e){o(""!==e?e:"custom")},value:"custom"===t?"":t})]})},xt={neutral:{label:(0,c.__)("Neutral","wp-parsely")},formal:{label:(0,c.__)("Formal","wp-parsely")},humorous:{label:(0,c.__)("Humorous","wp-parsely")},confident:{label:(0,c.__)("Confident","wp-parsely")},provocative:{label:(0,c.__)("Provocative","wp-parsely")},serious:{label:(0,c.__)("Serious","wp-parsely")},inspirational:{label:(0,c.__)("Inspirational","wp-parsely")},skeptical:{label:(0,c.__)("Skeptical","wp-parsely")},conversational:{label:(0,c.__)("Conversational","wp-parsely")},analytical:{label:(0,c.__)("Analytical","wp-parsely")},custom:{label:(0,c.__)("Custom Tone","wp-parsely"),icon:gt}},Pt=Object.keys(xt),St=function(e){return"custom"===e||""===e?xt.custom.label:kt(e)?e:xt[e].label},kt=function(e){return!Pt.includes(e)||"custom"===e},jt=function(e){var t=e.value,n=e.onChange,r=(0,o.useState)(""),a=r[0],l=r[1],u=(0,A.useDebounce)(n,500);return(0,s.jsx)("div",{className:"parsely-tone-selector-custom",children:(0,s.jsx)(i.TextControl,{value:a||t,placeholder:(0,c.__)("Enter a custom tone","wp-parsely"),onChange:function(e){if(""===e)return n(""),void l("");e.length>32&&(e=e.slice(0,32)),u(e),l(e)}})})},Tt=function(e){var t=e.tone,n=e.value,r=void 0===n?(0,c.__)("Select a tone","wp-parsely"):n,a=e.label,l=void 0===a?(0,c.__)("Tone","wp-parsely"):a,o=e.onChange,u=e.onDropdownChange,p=e.disabled,d=void 0!==p&&p,f=e.allowCustom,g=void 0!==f&&f;return(0,s.jsxs)(i.Disabled,{isDisabled:d,children:[(0,s.jsx)("div",{className:"wp-parsely-dropdown-label",children:l}),(0,s.jsx)(i.DropdownMenu,{label:(0,c.__)("Tone","wp-parsely"),className:"parsely-tone-selector-dropdown"+(d?" is-disabled":""),popoverProps:{className:"wp-parsely-popover"},toggleProps:{children:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"parsely-tone-selector-label",children:kt(t)?xt.custom.label:r}),(0,s.jsx)(ht,{})]})},children:function(e){var n=e.onClose;return(0,s.jsx)(i.MenuGroup,{label:(0,c.__)("Select a tone","wp-parsely"),children:(0,s.jsx)(s.Fragment,{children:Pt.map((function(e){if(!g&&"custom"===e)return null;var r=xt[e],a=e===t||kt(t)&&"custom"===e;return(0,s.jsxs)(i.MenuItem,{isSelected:a,className:a?"is-selected":"",role:"menuitemradio",onClick:function(){null==u||u(e),o(e),n(),"custom"===e&&setTimeout((function(){var e=document.querySelector(".parsely-tone-selector-custom input");e&&e.focus()}),0)},children:[r.icon&&(0,s.jsx)(D,{icon:r.icon}),r.label]},e)}))})})}}),g&&kt(t)&&(0,s.jsx)(jt,{onChange:function(e){o(""!==e?e:"custom")},value:"custom"===t?"":t})]})},Et=(0,u.createElement)(p.SVG,{width:"24",height:"24",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg"},(0,u.createElement)(p.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"})),Ct=(0,u.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,u.createElement)(p.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"})),Lt=(0,u.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,u.createElement)(p.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"})),At=(0,u.createElement)(p.SVG,{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24"},(0,u.createElement)(p.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"})),Nt=function(){return Nt=Object.assign||function(e){for(var t,n=1,r=arguments.length;n0&&s[s.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!s||l[1]>s[0]&&l[1]0&&s[s.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!s||l[1]>s[0]&&l[1]0&&s[s.length-1])||6!==l[0]&&2!==l[0])){a=0;continue}if(3===l[0]&&(!s||l[1]>s[0]&&l[1]0?(0,s.jsx)("span",{className:"parsely-write-titles-text",children:(0,o.createInterpolateElement)( diff --git a/src/content-helper/editor-sidebar/related-posts/component.tsx b/src/content-helper/editor-sidebar/related-posts/component.tsx index 4ce88de3c..06c7cfdd7 100644 --- a/src/content-helper/editor-sidebar/related-posts/component.tsx +++ b/src/content-helper/editor-sidebar/related-posts/component.tsx @@ -294,6 +294,7 @@ export const RelatedPostsPanel = (): JSX.Element => { const noAuthorsExist = 0 === postData.authors.length; const noTagsExist = 0 === postData.tags.length; const noCategoriesExist = 0 === postData.categories.length; + const authorIsUnavailable = filterTypeIsAuthor && ! postData.authors.includes( filter.value ); const tagIsUnavailable = filterTypeIsTag && ! postData.tags.includes( filter.value ); const sectionIsUnavailable = filterTypeIsSection && ! postData.categories.includes( filter.value ); @@ -308,6 +309,8 @@ export const RelatedPostsPanel = (): JSX.Element => { setFilter( { type: PostFilterType.Tag, value: postData.tags[ 0 ] } ); } else if ( sectionIsUnavailable ) { setFilter( { type: PostFilterType.Section, value: postData.categories[ 0 ] } ); + } else if ( authorIsUnavailable ) { + setFilter( { type: PostFilterType.Author, value: postData.authors[ 0 ] } ); } else { fetchPosts( FETCH_RETRIES ); } @@ -376,7 +379,7 @@ export const RelatedPostsPanel = (): JSX.Element => { // No filter data could be retrieved. Prevent the component from rendering. if ( postData.authors.length === 0 && postData.categories.length === 0 && - postData.tags.length === 0 + postData.tags.length === 0 && isPostDataReady ) { return (
diff --git a/src/content-helper/editor-sidebar/related-posts/hooks.ts b/src/content-helper/editor-sidebar/related-posts/hooks.ts index c5cb96049..7a86fcc03 100644 --- a/src/content-helper/editor-sidebar/related-posts/hooks.ts +++ b/src/content-helper/editor-sidebar/related-posts/hooks.ts @@ -56,7 +56,7 @@ export function usePostData(): PostData { if ( Number.isInteger( authorId ) ) { authorRecords = getEntityRecords( - 'root', 'user', { include: [ authorId ] } + 'root', 'user', { include: [ authorId ], context: 'view' } ) ?? undefined; // Coalescing null to undefined } else { authorRecords = null; @@ -66,7 +66,7 @@ export function usePostData(): PostData { categoryIds.every( Number.isInteger ) ) { categoryRecords = getEntityRecords( - 'taxonomy', 'category', { include: categoryIds } + 'taxonomy', 'category', { include: categoryIds, context: 'view' } ) ?? undefined; // Coalescing null to undefined } else { categoryRecords = null; @@ -76,7 +76,7 @@ export function usePostData(): PostData { tagIds.every( Number.isInteger ) ) { tagRecords = getEntityRecords( - 'taxonomy', 'post_tag', { include: tagIds } + 'taxonomy', 'post_tag', { include: tagIds, context: 'view' } ) ?? undefined; // Coalescing null to undefined } else { tagRecords = null;