Skip to content

Commit e0c96b1

Browse files
committed
Add the taxonomy settings
1 parent ba2992a commit e0c96b1

File tree

1 file changed

+82
-19
lines changed

1 file changed

+82
-19
lines changed

src/js/settings/components/feature-additional-settings/term-cleanup.js

Lines changed: 82 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@
22
* WordPress dependencies
33
*/
44
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';
79
import { __, sprintf } from '@wordpress/i18n';
810

911
/**
1012
* Internal dependencies
1113
*/
1214
import { SettingsRow } from '../settings-row';
1315
import { STORE_NAME } from '../../data/store';
16+
import { useTaxonomies } from '../../utils/utils';
1417

1518
/**
1619
* Component for Term Cleanup feature settings.
@@ -25,6 +28,24 @@ export const TermCleanupSettings = () => {
2528
select( STORE_NAME ).getFeatureSettings()
2629
);
2730
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+
} );
2849

2950
let description = sprintf(
3051
// translators: %1$s: opening anchor tag, %2$s: closing anchor tag
@@ -35,6 +56,7 @@ export const TermCleanupSettings = () => {
3556
'<a href="https://wordpress.org/plugins/elasticpress/" target="_blank">',
3657
'</a>'
3758
);
59+
3860
if ( window.classifAISettings?.isEPinstalled ) {
3961
description = __(
4062
'Use Elasticsearch for finding similar terms; this will speed up the process for finding similar terms.',
@@ -43,23 +65,64 @@ export const TermCleanupSettings = () => {
4365
}
4466

4567
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
5670
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+
</>
64127
);
65128
};

0 commit comments

Comments
 (0)