| 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 |
|