| 1 |
/** |
| 2 |
* WordPress dependencies. |
| 3 |
*/ |
| 4 |
import { Flex, FlexItem, TextControl } 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 changing the lower limit. |
| 25 |
* |
| 26 |
* @param {string} value Selected lower ID. |
| 27 |
* @returns {void} |
| 28 |
*/ |
| 29 |
const onChangeLower = (value) => { |
| 30 |
const lower_limit_object_id = value ? Math.max(0, value) : value; |
| 31 |
|
| 32 |
setArgs({ ...args, lower_limit_object_id }); |
| 33 |
}; |
| 34 |
|
| 35 |
/** |
| 36 |
* Handle changing the upper limit. |
| 37 |
* |
| 38 |
* @param {string} value Selected upper ID. |
| 39 |
* @returns {void} |
| 40 |
*/ |
| 41 |
const onChangeUpper = (value) => { |
| 42 |
const upper_limit_object_id = value ? Math.max(0, value) : value; |
| 43 |
|
| 44 |
setArgs({ ...args, upper_limit_object_id }); |
| 45 |
}; |
| 46 |
|
| 47 |
return ( |
| 48 |
<Flex className="ep-sync-advanced-control" justify="start"> |
| 49 |
<FlexItem grow="2"> |
| 50 |
<TextControl |
| 51 |
disabled={isSyncing} |
| 52 |
help={__('Sync objects with an ID of this number or higher.', 'elasticpress')} |
| 53 |
label={__('Lower object ID', 'elasticpress')} |
| 54 |
max={args.upper_limit_object_id} |
| 55 |
min="0" |
| 56 |
onChange={onChangeLower} |
| 57 |
type="number" |
| 58 |
value={args.lower_limit_object_id} |
| 59 |
/> |
| 60 |
</FlexItem> |
| 61 |
<FlexItem grow="2"> |
| 62 |
<TextControl |
| 63 |
disabled={isSyncing} |
| 64 |
help={__('Sync objects with an ID of this number or lower.', 'elasticpress')} |
| 65 |
label={__('Higher object ID', 'elasticpress')} |
| 66 |
min={args.lower_limit_object_id} |
| 67 |
onChange={onChangeUpper} |
| 68 |
type="number" |
| 69 |
value={args.upper_limit_object_id} |
| 70 |
/> |
| 71 |
</FlexItem> |
| 72 |
</Flex> |
| 73 |
); |
| 74 |
}; |
| 75 |
|