PluginProbe
ElasticPress / 5.0.0
ElasticPress v5.0.0
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 / progress.js

progress.js in ElasticPress 5.0.0, at assets/js/sync-ui/components/progress.js

145 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * External dependencies.
3 */
4 import classnames from 'classnames';
5
6 /**
7 * WordPress dependencies.
8 */
9 import { Icon } from '@wordpress/components';
10 import { createInterpolateElement, useMemo, WPElement } from '@wordpress/element';
11 import { dateI18n } from '@wordpress/date';
12 import { __, sprintf } from '@wordpress/i18n';
13
14 /**
15 * Internal dependencies.
16 */
17 import { useSync } from '../../sync';
18 import sync from './icons/sync';
19
20 /**
21 * Sync button component.
22 *
23 * @returns {WPElement} Component.
24 */
25 export default () => {
26 const {
27 isCli,
28 isComplete,
29 isFailed,
30 isPaused,
31 itemsProcessed,
32 itemsTotal,
33 syncStartDateTime,
34 syncTrigger,
35 } = useSync();
36
37 /**
38 * Sync progress label.
39 */
40 const label = useMemo(
41 /**
42 * Determine appropriate sync status label.
43 *
44 * @returns {string} Sync progress label.
45 */
46 () => {
47 if (isFailed) {
48 return __('Sync failed', 'elasticpress');
49 }
50
51 if (isComplete) {
52 return __('Sync complete', 'elasticpress');
53 }
54
55 if (isPaused) {
56 return __('Sync paused', 'elasticpress');
57 }
58
59 if (isCli) {
60 return __('WP CLI sync in progress', 'elasticpress');
61 }
62
63 return __('Sync in progress', 'elasticpress');
64 },
65 [isCli, isComplete, isFailed, isPaused],
66 );
67
68 const now = itemsTotal ? Math.floor((itemsProcessed / itemsTotal) * 100) : 100;
69
70 const why = useMemo(() => {
71 if (isCli) {
72 /* translators: %1$s Sync start date and time. */
73 return __('Started manually from WP CLI at <time>%s</time>.', 'elasticpress');
74 }
75
76 switch (syncTrigger) {
77 case 'features':
78 /* translators: %1$s Sync start date and time. */
79 return __(
80 'Started automatically after a change to feature settings at <time>%s</time>.',
81 'elasticpress',
82 );
83 case 'install':
84 /* translators: %1$s Sync start date and time. */
85 return __(
86 'Started automatically after installing the ElasticPress plugin at <time>%s</time>.',
87 'elasticpress',
88 );
89 case 'manual':
90 /* translators: %1$s Sync start date and time. */
91 return __(
92 'Started manually from the Sync page at <time>%s</time>.',
93 'elasticpress',
94 );
95 case 'upgrade':
96 /* translators: %1$s Sync start date and time. */
97 return __(
98 'Started automatically after updating the ElasticPress plugin at <time>%s</time>.',
99 'elasticpress',
100 );
101 default:
102 /* translators: %1$s Sync start date and time. */
103 return __('Started on <time>%s</time>.', 'elasticpress');
104 }
105 }, [isCli, syncTrigger]);
106
107 return (
108 <div
109 className={classnames('ep-sync-progress', {
110 'ep-sync-progress--syncing': !isPaused && !isComplete && !isFailed,
111 })}
112 >
113 <Icon icon={sync} />
114 <div className="ep-sync-progress__details">
115 <strong>{label}</strong>
116 {syncStartDateTime
117 ? createInterpolateElement(
118 sprintf(why, dateI18n('g:ia l F jS, Y', syncStartDateTime)),
119 {
120 time: <time dateTime={dateI18n('c', syncStartDateTime)} />,
121 },
122 )
123 : null}
124 </div>
125 <div className="ep-sync-progress__progress-bar">
126 <div
127 aria-valuemax={100}
128 aria-valuemin={0}
129 aria-valuenow={now}
130 className={classnames('ep-sync-progress-bar', {
131 'ep-sync-progress-bar--complete': isComplete,
132 'ep-sync-progress-bar--failed': isFailed,
133 })}
134 role="progressbar"
135 >
136 <div
137 className="ep-sync-progress-bar__progress"
138 style={{ minWidth: `${now}%` }}
139 />
140 </div>
141 </div>
142 </div>
143 );
144 };
145