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 / include.js

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

62 lines 1.4 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 { FormTokenField } 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, setArgs } = useSyncSettings();
22
23 /**
24 * Handle change to method for indexing objects.
25 *
26 * @param {string} include Selected IDs.
27 * @returns {void}
28 */
29 const onChange = (include) => {
30 setArgs({ ...args, include });
31 };
32
33 /**
34 * Sanitize IDs entered into the include field.
35 *
36 * The FormTokenField component requires string values, so return an empty
37 * string for non-numerical values.
38 *
39 * @param {string} value Value to transform.
40 * @returns {string} Transformed values.
41 */
42 const saveTransform = (value) => {
43 const transformedValue = parseInt(value, 10);
44
45 return transformedValue ? transformedValue.toString() : '';
46 };
47
48 return (
49 <div className="ep-sync-advanced-control">
50 <FormTokenField
51 disabled={isSyncing}
52 label={__('Object IDs', 'elasticpress')}
53 onChange={onChange}
54 saveTransform={saveTransform}
55 value={args.include}
56 __nextHasNoMarginBottom
57 __next40pxDefaultSize
58 />
59 </div>
60 );
61 };
62