@@ -4,107 +4,107 @@ import { useSelect } from '@wordpress/data';
44import { store as coreStore } from '@wordpress/core-data' ;
55
66const SectionSelector = ( {
7- value,
8- onChange,
9- label,
10- help,
11- taxonomy = 'wzkb_category' ,
12- includeEmptyLabel = '' ,
13- formatLabel,
14- className = '' ,
15- wrapperClass = '' ,
16- queryArgs = { } ,
17- filterTerm,
7+ value,
8+ onChange,
9+ label,
10+ help,
11+ taxonomy = 'wzkb_category' ,
12+ includeEmptyLabel = '' ,
13+ formatLabel,
14+ className = '' ,
15+ wrapperClass = '' ,
16+ queryArgs = { } ,
17+ filterTerm,
1818} ) => {
19- const { terms, hasResolved, error } = useSelect (
20- ( select ) => {
21- const query = {
22- per_page : - 1 ,
23- hide_empty : 1 ,
24- } ;
19+ const { terms, hasResolved, error } = useSelect (
20+ ( select ) => {
21+ const query = {
22+ per_page : - 1 ,
23+ hide_empty : 1 ,
24+ } ;
2525
26- const selectorArgs = [
27- 'taxonomy' ,
28- taxonomy ,
29- {
30- ...query ,
31- ...queryArgs ,
32- } ,
33- ] ;
26+ const selectorArgs = [
27+ 'taxonomy' ,
28+ taxonomy ,
29+ {
30+ ...query ,
31+ ...queryArgs ,
32+ } ,
33+ ] ;
3434
35- try {
36- return {
37- terms : select ( coreStore ) . getEntityRecords ( ...selectorArgs ) ,
38- hasResolved : select ( coreStore ) . hasFinishedResolution (
39- 'getEntityRecords' ,
40- selectorArgs
41- ) ,
42- error : null ,
43- } ;
44- } catch ( fetchError ) {
45- return {
46- terms : [ ] ,
47- hasResolved : true ,
48- error : fetchError ,
49- } ;
50- }
51- } ,
52- [ taxonomy ]
53- ) ;
35+ try {
36+ return {
37+ terms : select ( coreStore ) . getEntityRecords ( ...selectorArgs ) ,
38+ hasResolved : select ( coreStore ) . hasFinishedResolution (
39+ 'getEntityRecords' ,
40+ selectorArgs
41+ ) ,
42+ error : null ,
43+ } ;
44+ } catch ( fetchError ) {
45+ return {
46+ terms : [ ] ,
47+ hasResolved : true ,
48+ error : fetchError ,
49+ } ;
50+ }
51+ } ,
52+ [ taxonomy ]
53+ ) ;
5454
55- const defaultLabel = ( term ) => {
56- const baseLabel = `#${ term . id } - ${ term . name } ` ;
57- if ( 'wzkb_category' === taxonomy && term . kb_product ?. name ) {
58- return `${ baseLabel } (${ term . kb_product . name } )` ;
59- }
60- return baseLabel ;
61- } ;
55+ const defaultLabel = ( term ) => {
56+ const baseLabel = `#${ term . id } - ${ term . name } ` ;
57+ if ( 'wzkb_category' === taxonomy && term . kb_product ?. name ) {
58+ return `${ baseLabel } (${ term . kb_product . name } )` ;
59+ }
60+ return baseLabel ;
61+ } ;
6262
63- const filteredTerms =
64- typeof filterTerm === 'function' ? terms ?. filter ( filterTerm ) : terms ;
63+ const filteredTerms =
64+ typeof filterTerm === 'function' ? terms ?. filter ( filterTerm ) : terms ;
6565
66- const options =
67- filteredTerms ?. map ( ( term ) => ( {
68- label : ( formatLabel || defaultLabel ) ( term ) ,
69- value : term . id . toString ( ) ,
70- } ) ) || [ ] ;
66+ const options =
67+ filteredTerms ?. map ( ( term ) => ( {
68+ label : ( formatLabel || defaultLabel ) ( term ) ,
69+ value : term . id . toString ( ) ,
70+ } ) ) || [ ] ;
7171
72- if ( includeEmptyLabel ) {
73- options . unshift ( { value : '' , label : includeEmptyLabel } ) ;
74- }
72+ if ( includeEmptyLabel ) {
73+ options . unshift ( { value : '' , label : includeEmptyLabel } ) ;
74+ }
7575
76- const inputValue = value && value > 0 ? value . toString ( ) : '' ;
76+ const inputValue = value && value > 0 ? value . toString ( ) : '' ;
7777
78- return (
79- < >
80- { error && (
81- < Notice status = "error" isDismissible = { false } >
82- { __ (
83- 'Error loading categories. Please try again.' ,
84- 'knowledgebase'
85- ) }
86- </ Notice >
87- ) }
78+ return (
79+ < >
80+ { error && (
81+ < Notice status = "error" isDismissible = { false } >
82+ { __ (
83+ 'Error loading categories. Please try again.' ,
84+ 'knowledgebase'
85+ ) }
86+ </ Notice >
87+ ) }
8888
89- { ! hasResolved ? (
90- < Spinner />
91- ) : (
92- < div className = { wrapperClass } >
93- < ComboboxControl
94- className = { className }
95- label = { label }
96- value = { inputValue }
97- onChange = { ( selected ) =>
98- onChange ( parseInt ( selected , 10 ) || 0 )
99- }
100- options = { options }
101- placeholder = { includeEmptyLabel }
102- help = { help }
103- />
104- </ div >
105- ) }
106- </ >
107- ) ;
89+ { ! hasResolved ? (
90+ < Spinner />
91+ ) : (
92+ < div className = { wrapperClass } >
93+ < ComboboxControl
94+ className = { className }
95+ label = { label }
96+ value = { inputValue }
97+ onChange = { ( selected ) =>
98+ onChange ( parseInt ( selected , 10 ) || 0 )
99+ }
100+ options = { options }
101+ placeholder = { includeEmptyLabel }
102+ help = { help }
103+ />
104+ </ div >
105+ ) }
106+ </ >
107+ ) ;
108108} ;
109109
110110export default SectionSelector ;
0 commit comments