PluginProbe
ElasticPress / 5.0.0
ElasticPress v5.0.0
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
elasticpress / assets / js / sync-ui / components / indexables.js

indexables.js in ElasticPress 5.0.0, at assets/js/sync-ui/components/indexables.js

65 lines 1.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies.
3 */
4 import { CheckboxControl } from '@wordpress/components';
5 import { WPElement } from '@wordpress/element';
6 import { __ } from '@wordpress/i18n';
7
8 /**
9 * Internal dependencies.
10 */
11 import { useSync } from '../../sync';
12 import { useSyncSettings } from '../provider';
13
14 /**
15 * Delete checkbox component.
16 *
17 * @returns {WPElement} Sync page component.
18 */
19 export default () => {
20 const { isSyncing } = useSync();
21 const { args, indexables, setArgs } = useSyncSettings();
22
23 /**
24 * Handle changes to Indexable checkboxes.
25 *
26 * Sets the post types argument as empty if the Posts indexable is not
27 * being synced.
28 *
29 * @param {string} indexable Indexable.
30 * @param {boolean} checked Whether the Indexable is checked.
31 * @returns {void}
32 */
33 const onChange = (indexable, checked) => {
34 const indexables = args.indexables ? [...args.indexables] : [];
35
36 if (checked) {
37 indexables.push(indexable);
38 } else {
39 indexables.splice(indexables.indexOf(indexable), 1);
40 }
41
42 const post_type = !indexables.length || indexables.includes('post') ? args.post_type : [];
43
44 setArgs({ ...args, indexables, post_type });
45 };
46
47 return indexables.length > 1 ? (
48 <fieldset className="ep-sync-advanced-control">
49 <legend className="ep-sync-advanced-control__label">
50 {__('Content to sync', 'elasticpress')}
51 </legend>
52 {indexables.map(([indexable, label]) => (
53 <CheckboxControl
54 checked={args.indexables?.includes(indexable)}
55 disabled={isSyncing}
56 indeterminate={!args.indexables.length}
57 key={indexable}
58 label={label}
59 onChange={(checked) => onChange(indexable, checked)}
60 />
61 ))}
62 </fieldset>
63 ) : null;
64 };
65