2
2
* WordPress dependencies
3
3
*/
4
4
import { useSelect , useDispatch } from '@wordpress/data' ;
5
- // eslint-disable-next-line @wordpress/no-unsafe-wp-apis
6
- import { CheckboxControl } from '@wordpress/components' ;
5
+ import {
6
+ CheckboxControl ,
7
+ __experimentalInputControl as InputControl , // eslint-disable-line @wordpress/no-unsafe-wp-apis
8
+ } from '@wordpress/components' ;
7
9
import { __ , sprintf } from '@wordpress/i18n' ;
8
10
9
11
/**
10
12
* Internal dependencies
11
13
*/
12
14
import { SettingsRow } from '../settings-row' ;
13
15
import { STORE_NAME } from '../../data/store' ;
16
+ import { useTaxonomies } from '../../utils/utils' ;
14
17
15
18
/**
16
19
* Component for Term Cleanup feature settings.
@@ -25,6 +28,24 @@ export const TermCleanupSettings = () => {
25
28
select ( STORE_NAME ) . getFeatureSettings ( )
26
29
) ;
27
30
const { setFeatureSettings } = useDispatch ( STORE_NAME ) ;
31
+ const { taxonomies = [ ] } = useTaxonomies ( ) ;
32
+ const options =
33
+ taxonomies
34
+ ?. filter ( ( taxonomy ) => {
35
+ return taxonomy . visibility ?. publicly_queryable ;
36
+ } )
37
+ ?. map ( ( taxonomy ) => ( {
38
+ label : taxonomy . name ,
39
+ value : taxonomy . slug ,
40
+ } ) ) || [ ] ;
41
+ const features = { } ;
42
+
43
+ options ?. forEach ( ( taxonomy ) => {
44
+ features [ taxonomy . value ] = {
45
+ label : taxonomy . label ,
46
+ defaultThreshold : 75 ,
47
+ } ;
48
+ } ) ;
28
49
29
50
let description = sprintf (
30
51
// translators: %1$s: opening anchor tag, %2$s: closing anchor tag
@@ -35,6 +56,7 @@ export const TermCleanupSettings = () => {
35
56
'<a href="https://wordpress.org/plugins/elasticpress/" target="_blank">' ,
36
57
'</a>'
37
58
) ;
59
+
38
60
if ( window . classifAISettings ?. isEPinstalled ) {
39
61
description = __ (
40
62
'Use Elasticsearch for finding similar terms; this will speed up the process for finding similar terms.' ,
@@ -43,23 +65,64 @@ export const TermCleanupSettings = () => {
43
65
}
44
66
45
67
return (
46
- < SettingsRow
47
- label = { __ ( 'Use ElasticPress' , 'classifai' ) }
48
- description = { description }
49
- className = "settings-term-cleanup-use-ep"
50
- >
51
- < CheckboxControl
52
- id = "use_ep"
53
- key = "use_ep"
54
- checked = { featureSettings . use_ep }
55
- disabled = { ! window . classifAISettings ?. isEPinstalled }
68
+ < >
69
+ < SettingsRow
56
70
label = { __ ( 'Use ElasticPress' , 'classifai' ) }
57
- onChange = { ( value ) => {
58
- setFeatureSettings ( {
59
- use_ep : value ,
60
- } ) ;
61
- } }
62
- />
63
- </ SettingsRow >
71
+ description = { description }
72
+ className = "settings-term-cleanup-use-ep"
73
+ >
74
+ < CheckboxControl
75
+ id = "use_ep"
76
+ key = "use_ep"
77
+ checked = { featureSettings . use_ep }
78
+ disabled = { ! window . classifAISettings ?. isEPinstalled }
79
+ label = { __ ( 'Use ElasticPress' , 'classifai' ) }
80
+ onChange = { ( value ) => {
81
+ setFeatureSettings ( {
82
+ use_ep : value ,
83
+ } ) ;
84
+ } }
85
+ />
86
+ </ SettingsRow >
87
+ < >
88
+ { Object . keys ( features ) . map ( ( feature ) => {
89
+ const { defaultThreshold, label } = features [ feature ] ;
90
+ return (
91
+ < SettingsRow
92
+ key = { feature }
93
+ label = { label }
94
+ className = "settings-term-cleanup-taxonomies"
95
+ >
96
+ < CheckboxControl
97
+ id = { `${ feature } -enabled` }
98
+ label = { __ ( 'Enable' , 'classifai' ) }
99
+ value = { feature }
100
+ checked = { featureSettings [ feature ] }
101
+ onChange = { ( value ) => {
102
+ setFeatureSettings ( {
103
+ [ feature ] : value ? 1 : 0 ,
104
+ } ) ;
105
+ } }
106
+ />
107
+ < InputControl
108
+ id = { `${ feature } -threshold` }
109
+ label = { __ ( 'Threshold (%)' , 'classifai' ) }
110
+ type = "number"
111
+ value = {
112
+ featureSettings [
113
+ `${ feature } _threshold`
114
+ ] || defaultThreshold
115
+ }
116
+ onChange = { ( value ) => {
117
+ setFeatureSettings ( {
118
+ [ `${ feature } _threshold` ] : value ,
119
+ } ) ;
120
+ } }
121
+ />
122
+ </ SettingsRow >
123
+ ) ;
124
+ } ) }
125
+ </ >
126
+ </ >
64
127
) ;
65
128
} ;
0 commit comments