From ee532668a15bc52dc2f025a103715b9ad9c08df3 Mon Sep 17 00:00:00 2001 From: Ajay D'Souza Date: Thu, 19 Dec 2024 21:33:50 +0000 Subject: [PATCH] Return messages if no section ID is set for the articles block --- includes/blocks/build/sections/index.asset.php | 2 +- includes/blocks/build/sections/index.js | 2 +- includes/blocks/class-blocks.php | 4 ++-- includes/blocks/src/sections/edit.js | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/includes/blocks/build/sections/index.asset.php b/includes/blocks/build/sections/index.asset.php index 9fbe136..543d524 100644 --- a/includes/blocks/build/sections/index.asset.php +++ b/includes/blocks/build/sections/index.asset.php @@ -1 +1 @@ - array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '8dcdb4c49c5937146313'); + array('react', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-core-data', 'wp-data', 'wp-i18n', 'wp-server-side-render'), 'version' => '57b585f3747e128385c5'); diff --git a/includes/blocks/build/sections/index.js b/includes/blocks/build/sections/index.js index 28aa497..21f71d6 100644 --- a/includes/blocks/build/sections/index.js +++ b/includes/blocks/build/sections/index.js @@ -1 +1 @@ -(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var l in n)e.o(n,l)&&!e.o(t,l)&&Object.defineProperty(t,l,{enumerable:!0,get:n[l]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,n=window.React,l=window.wp.i18n,o=window.wp.serverSideRender;var a=e.n(o);const r=window.wp.blockEditor,s=window.wp.data,i=window.wp.coreData,d=window.wp.components;(0,t.registerBlockType)("knowledgebase/sections",{edit:function({attributes:e,setAttributes:t}){const{termID:o,depth:c,beforeLiItem:w,afterLiItem:m}=e,b=(0,r.useBlockProps)(),{terms:g,hasResolved:p,error:u}=(0,s.useSelect)((e=>{const t=["taxonomy","wzkb_category",{per_page:-1}];try{return{terms:e(i.store).getEntityRecords(...t),hasResolved:e(i.store).hasFinishedResolution("getEntityRecords",t),error:null}}catch(e){return{terms:[],hasResolved:!0,error:e}}}),[]),_=g?.map((e=>({label:`${e.name} (#${e.id})`,value:e.id.toString()})))||[];return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(r.InspectorControls,null,u&&(0,n.createElement)(d.Notice,{status:"error",isDismissible:!1},(0,l.__)("Error loading categories. Please try again.","knowledgebase")),(0,n.createElement)(d.PanelBody,{title:(0,l.__)("Knowledge Base Sections Settings","knowledgebase"),initialOpen:!0},(0,n.createElement)(d.PanelRow,null,p?(0,n.createElement)(d.ComboboxControl,{label:(0,l.__)("Select Knowledge Base Section","knowledgebase"),value:o,onChange:e=>t({termID:e}),options:_,help:(0,l.__)("Search and select a knowledge base section","knowledgebase")}):(0,n.createElement)(d.Spinner,null)),(0,n.createElement)(d.PanelRow,null,(0,n.createElement)(d.TextControl,{label:(0,l.__)("Depth","knowledgebase"),value:c,type:"number",min:"0",onChange:e=>t({depth:e}),help:(0,l.__)("Enter the depth of sections to display (0 for all)","knowledgebase")})),(0,n.createElement)(d.PanelRow,null,(0,n.createElement)(d.TextControl,{label:(0,l.__)("Before list item","knowledgebase"),value:w,onChange:e=>t({beforeLiItem:e}),help:(0,l.__)("HTML/text to add before each list item","knowledgebase")})),(0,n.createElement)(d.PanelRow,null,(0,n.createElement)(d.TextControl,{label:(0,l.__)("After list item","knowledgebase"),value:m,onChange:e=>t({afterLiItem:e}),help:(0,l.__)("HTML/text to add after each list item","knowledgebase")})))),(0,n.createElement)("div",{...b},(0,n.createElement)(d.Disabled,null,(0,n.createElement)(a(),{block:"knowledgebase/sections",attributes:e}))))}})})(); \ No newline at end of file +(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var l in n)e.o(n,l)&&!e.o(t,l)&&Object.defineProperty(t,l,{enumerable:!0,get:n[l]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)};const t=window.wp.blocks,n=window.React,l=window.wp.i18n,o=window.wp.serverSideRender;var a=e.n(o);const r=window.wp.blockEditor,s=window.wp.data,i=window.wp.coreData,d=window.wp.components;(0,t.registerBlockType)("knowledgebase/sections",{edit:function({attributes:e,setAttributes:t}){const{termID:o,depth:c,beforeLiItem:w,afterLiItem:m}=e,b=(0,r.useBlockProps)(),{terms:p,hasResolved:g,error:u}=(0,s.useSelect)((e=>{const t=["taxonomy","wzkb_category",{per_page:-1,hide_empty:1}];try{return{terms:e(i.store).getEntityRecords(...t),hasResolved:e(i.store).hasFinishedResolution("getEntityRecords",t),error:null}}catch(e){return{terms:[],hasResolved:!0,error:e}}}),[]),_=p?.map((e=>({label:`${e.name} (#${e.id})`,value:e.id.toString()})))||[];return(0,n.createElement)(n.Fragment,null,(0,n.createElement)(r.InspectorControls,null,u&&(0,n.createElement)(d.Notice,{status:"error",isDismissible:!1},(0,l.__)("Error loading categories. Please try again.","knowledgebase")),(0,n.createElement)(d.PanelBody,{title:(0,l.__)("Knowledge Base Sections Settings","knowledgebase"),initialOpen:!0},(0,n.createElement)(d.PanelRow,null,g?(0,n.createElement)(d.ComboboxControl,{label:(0,l.__)("Select Knowledge Base Section","knowledgebase"),value:o,onChange:e=>t({termID:e}),options:_,help:(0,l.__)("Search and select a knowledge base section","knowledgebase")}):(0,n.createElement)(d.Spinner,null)),(0,n.createElement)(d.PanelRow,null,(0,n.createElement)(d.TextControl,{label:(0,l.__)("Depth","knowledgebase"),value:c,type:"number",min:"0",onChange:e=>t({depth:e}),help:(0,l.__)("Enter the depth of sections to display (0 for all)","knowledgebase")})),(0,n.createElement)(d.PanelRow,null,(0,n.createElement)(d.TextControl,{label:(0,l.__)("Before list item","knowledgebase"),value:w,onChange:e=>t({beforeLiItem:e}),help:(0,l.__)("HTML/text to add before each list item","knowledgebase")})),(0,n.createElement)(d.PanelRow,null,(0,n.createElement)(d.TextControl,{label:(0,l.__)("After list item","knowledgebase"),value:m,onChange:e=>t({afterLiItem:e}),help:(0,l.__)("HTML/text to add after each list item","knowledgebase")})))),(0,n.createElement)("div",{...b},(0,n.createElement)(d.Disabled,null,(0,n.createElement)(a(),{block:"knowledgebase/sections",attributes:e}))))}})})(); \ No newline at end of file diff --git a/includes/blocks/class-blocks.php b/includes/blocks/class-blocks.php index 17414fe..71c6cd5 100644 --- a/includes/blocks/class-blocks.php +++ b/includes/blocks/class-blocks.php @@ -155,13 +155,13 @@ public function render_articles_block( $attributes ) { $show_excerpt = isset( $attributes['show_excerpt'] ) ? (bool) $attributes['show_excerpt'] : false; if ( empty( $attributes['term_id'] ) ) { - return ''; + return __( 'Enter a section ID.', 'knowledgebase' ); } $term = get_term( (int) $attributes['term_id'], 'wzkb_category' ); if ( empty( $term ) || is_wp_error( $term ) ) { - return ''; + return __( 'Section not found.', 'knowledgebase' ); } $list_of_posts = Display::get_posts_by_term( diff --git a/includes/blocks/src/sections/edit.js b/includes/blocks/src/sections/edit.js index 770282f..96d0c32 100644 --- a/includes/blocks/src/sections/edit.js +++ b/includes/blocks/src/sections/edit.js @@ -22,7 +22,10 @@ export default function Edit({ attributes, setAttributes }) { const blockProps = useBlockProps(); const { terms, hasResolved, error } = useSelect((select) => { - const query = { per_page: -1 }; + const query = { + per_page: -1, + hide_empty: 1, + }; const selectorArgs = ['taxonomy', 'wzkb_category', query]; try {