PluginProbe
ElasticPress / 5.0.2
ElasticPress v5.0.2
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 / apps / sync.js

sync.js in ElasticPress 5.0.2, at assets/js/sync-ui/apps/sync.js

123 lines 3.3 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 { Panel, PanelBody } from '@wordpress/components';
5 import { useEffect, WPElement } from '@wordpress/element';
6 import { __, sprintf } from '@wordpress/i18n';
7
8 /**
9 * Internal dependencies.
10 */
11
12 import { useSettingsScreen } from '../../settings-screen';
13 import { useSync } from '../../sync';
14 import Controls from '../components/controls';
15 import Indexables from '../components/types';
16 import Log from '../components/log';
17 import Objects from '../components/objects';
18 import Progress from '../components/progress';
19 import PutMapping from '../components/put-mapping';
20 import SyncHistory from '../components/sync-history';
21 import { useSyncSettings } from '../provider';
22
23 /**
24 * Sync page component.
25 *
26 * @returns {WPElement} Sync page component.
27 */
28 export default () => {
29 const { createNotice } = useSettingsScreen();
30 const { isComplete, isEpio, isSyncing, logMessage, startSync, syncHistory, syncTrigger } =
31 useSync();
32 const { args, autoIndex } = useSyncSettings();
33
34 /**
35 * Handle a completed sync.
36 */
37 const onComplete = () => {
38 if (isComplete) {
39 createNotice('success', __('Sync completed.', 'elasticpress'));
40 }
41 };
42
43 /**
44 * Initialize.
45 *
46 * @returns {void}
47 */
48 const onInit = () => {
49 if (autoIndex) {
50 startSync({ put_mapping: true, trigger: syncTrigger });
51 logMessage(__('Starting delete and sync…', 'elasticpress'), 'info');
52 }
53 };
54
55 /**
56 * Handle clicking sync button.
57 *
58 * @param {Event} event Submit event.
59 * @returns {void}
60 */
61 const onSync = async (event) => {
62 event.preventDefault();
63
64 const { put_mapping } = args;
65
66 const putMapping = syncHistory.length ? put_mapping : true;
67 const syncArgs = { ...args, put_mapping: putMapping, trigger: 'manual' };
68
69 startSync(syncArgs);
70 logMessage(__('Starting sync…', 'elasticpress'), 'info');
71 };
72
73 useEffect(onComplete, [createNotice, isComplete]);
74 useEffect(onInit, [autoIndex, logMessage, startSync, syncTrigger]);
75
76 return (
77 <form onSubmit={onSync}>
78 <p>
79 {syncHistory.length
80 ? __(
81 'If you are missing data in your search results or have recently added custom content types to your site, you should run a sync to reflect these changes.',
82 'elasticpress',
83 )
84 : sprintf(
85 /* translators: %s: Index type. ElasticPress.io or Elasticsearch. */
86 __(
87 'Run a sync to index your existing content %s. Once syncing finishes, your site is officially supercharged.',
88 'elasticpress',
89 ),
90 isEpio
91 ? __('on ElasticPress.io', 'elasticpress')
92 : __('in Elasticsearch', 'elasticpress'),
93 )}
94 </p>
95 <Panel className="ep-sync-panel">
96 <PanelBody className="ep-sync-panel__controls">
97 {isSyncing || isComplete ? <Progress /> : null}
98 <Controls />
99 {syncHistory.length ? <PutMapping /> : null}
100 </PanelBody>
101 <PanelBody initialOpen={false} title="Log">
102 <Log />
103 </PanelBody>
104 {syncHistory.length ? (
105 <>
106 <PanelBody
107 className="ep-sync-panel__advanced"
108 initialOpen={false}
109 title={__('Advanced options', 'elasticpress')}
110 >
111 <Indexables />
112 <Objects />
113 </PanelBody>
114 <PanelBody title={__('Sync history', 'elasticpress')}>
115 <SyncHistory />
116 </PanelBody>
117 </>
118 ) : null}
119 </Panel>
120 </form>
121 );
122 };
123