PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
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 / objects.js

objects.js in ElasticPress 5.3.5, at assets/js/sync-ui/components/objects.js

87 lines 1.9 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 { RadioControl } from '@wordpress/components';
5 import { useState, 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 import Include from './include';
14 import Limits from './limits';
15 import Offset from './offset';
16
17 /**
18 * Delete checkbox component.
19 *
20 * @returns {WPElement} Sync page component.
21 */
22 export default () => {
23 const [selected, setSelected] = useState('all');
24
25 const { isSyncing } = useSync();
26 const { args, setArgs } = useSyncSettings();
27
28 /**
29 * Handle change to method for indexing objects.
30 *
31 * @param {string} value Selected method.
32 * @returns {void}
33 */
34 const onChange = (value) => {
35 let { include, lower_limit_object_id, offset, upper_limit_object_id } = args;
36
37 switch (value) {
38 case 'include':
39 offset = 0;
40 lower_limit_object_id = '';
41 upper_limit_object_id = '';
42 break;
43 case 'limits':
44 offset = 0;
45 include = [];
46 break;
47 default:
48 include = [];
49 lower_limit_object_id = '';
50 upper_limit_object_id = '';
51 break;
52 }
53
54 setArgs({ ...args, include, lower_limit_object_id, offset, upper_limit_object_id });
55 setSelected(value);
56 };
57
58 return (
59 <>
60 <RadioControl
61 className="ep-sync-advanced-control"
62 disabled={isSyncing}
63 label={__('Objects to sync', 'elasticpress')}
64 onChange={onChange}
65 options={[
66 {
67 label: 'All objects',
68 value: 'all',
69 },
70 {
71 label: __('Specific IDs', 'elasticpress'),
72 value: 'include',
73 },
74 {
75 label: __('A range of IDs', 'elasticpress'),
76 value: 'limits',
77 },
78 ]}
79 selected={selected}
80 />
81 {selected === 'all' ? <Offset /> : null}
82 {selected === 'include' ? <Include /> : null}
83 {selected === 'limits' ? <Limits /> : null}
84 </>
85 );
86 };
87