PluginProbe
ElasticPress / 5.0.1
ElasticPress v5.0.1
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 / provider.js

provider.js in ElasticPress 5.0.1, at assets/js/sync-ui/provider.js

63 lines 1.5 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 { useDispatch } from '@wordpress/data';
5 import { createContext, useContext, useMemo, useState, WPElement } from '@wordpress/element';
6 import { store as noticeStore } from '@wordpress/notices';
7
8 /**
9 * Sync context.
10 */
11 const Context = createContext();
12
13 /**
14 * Sync settings provider.
15 *
16 * @param {object} props Component props.
17 * @param {boolean} props.autoIndex Whether to start an index automatically.
18 * @param {Function} props.children Component children
19 * @param {Array} props.indexables Indexables and their labels.
20 * @param {Array} props.postTypes Post types and their labels.
21 * @returns {WPElement}
22 */
23 export const SyncSettingsProvider = ({ autoIndex, children, indexables, postTypes }) => {
24 const { createNotice } = useDispatch(noticeStore);
25
26 const [args, setArgs] = useState({
27 include: [],
28 indexables: [],
29 lower_limit_object_id: null,
30 offset: 0,
31 put_mapping: false,
32 post_type: [],
33 upper_limit_object_id: null,
34 });
35
36 const [showLog, setShowLog] = useState(false);
37
38 const value = useMemo(
39 () => ({
40 args,
41 autoIndex,
42 createNotice,
43 indexables,
44 postTypes,
45 setArgs,
46 showLog,
47 setShowLog,
48 }),
49 [args, autoIndex, createNotice, indexables, postTypes, setArgs, showLog, setShowLog],
50 );
51
52 return <Context.Provider value={value}>{children}</Context.Provider>;
53 };
54
55 /**
56 * Use the API Search context.
57 *
58 * @returns {object} API Search Context.
59 */
60 export const useSyncSettings = () => {
61 return useContext(Context);
62 };
63