@scaleflex/widget-progress-panel 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6160 -0
- package/LICENSE +21 -0
- package/README.md +242 -0
- package/lib/ProgressPanel.constants.js +56 -0
- package/lib/ProgressPanel.styled.js +151 -0
- package/lib/components/Activity.js +82 -0
- package/lib/components/ActivityActions.js +63 -0
- package/lib/components/ActivityCircularProgress/ActivityCircularProgress.styled.js +39 -0
- package/lib/components/ActivityCircularProgress/index.js +37 -0
- package/lib/components/ActivityStatus.js +51 -0
- package/lib/components/CancelButton.js +34 -0
- package/lib/components/ProgressPanel.js +67 -0
- package/lib/components/ProgressPanelHeader.js +78 -0
- package/lib/components/ProgressPanelItem.js +19 -0
- package/lib/components/RetryButton.js +36 -0
- package/lib/components/UploadDelayedNotification.js +26 -0
- package/lib/components/common/ProgressPanelFileIcon.js +40 -0
- package/lib/defaultLocale.js +50 -0
- package/lib/index.js +120 -0
- package/lib/progressPanel.slice.js +595 -0
- package/lib/utils/locallySavedActivities.js +64 -0
- package/package.json +33 -0
- package/types/index.d.ts +16 -0
|
@@ -0,0 +1,595 @@
|
|
|
1
|
+
var _excluded = ["id", "percentage"],
|
|
2
|
+
_excluded2 = ["retrigger", "progress"];
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
|
+
function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
|
|
5
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
7
|
+
function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
|
|
8
|
+
function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
|
|
9
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
10
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
11
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
12
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
13
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
14
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
17
|
+
import { createSelector, createSlice } from '@reduxjs/toolkit';
|
|
18
|
+
import throttle from 'lodash.throttle';
|
|
19
|
+
import createThunk from '@scaleflex/widget-utils/lib/createThunk';
|
|
20
|
+
import { PLUGINS_IDS, PROGRESS_PANEL_STATUS, PROGRESS_PANEL_ACTIVITY, ABORTED_ERROR } from '@scaleflex/widget-utils/lib/constants';
|
|
21
|
+
import asyncTimeout from '@scaleflex/widget-utils/lib/asyncTimeout';
|
|
22
|
+
import logErrorIfDevEnv from '@scaleflex/widget-utils/lib/logErrorIfDevEnv';
|
|
23
|
+
import calculateTotalEta from '@scaleflex/widget-core/lib/utils/calculateTotalEta';
|
|
24
|
+
import { Filerobot } from '@scaleflex/widget-core/lib';
|
|
25
|
+
import { pushToSavedActivities, removeSavedActivity } from './utils/locallySavedActivities';
|
|
26
|
+
var initialState = {
|
|
27
|
+
ids: [],
|
|
28
|
+
activities: {},
|
|
29
|
+
show: false,
|
|
30
|
+
isMinimized: false
|
|
31
|
+
};
|
|
32
|
+
var onActivityError = createThunk(function (_ref, thunkApi) {
|
|
33
|
+
var id = _ref.id;
|
|
34
|
+
var dispatch = thunkApi.dispatch,
|
|
35
|
+
getState = thunkApi.getState;
|
|
36
|
+
var activity = selectProgressPanelActivitiesById(getState(), id);
|
|
37
|
+
dispatch(progressPanelActivityUpdated({
|
|
38
|
+
id: id,
|
|
39
|
+
progress: _objectSpread(_objectSpread({}, activity.progress), {}, {
|
|
40
|
+
status: PROGRESS_PANEL_STATUS.ERROR
|
|
41
|
+
})
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
44
|
+
var onActivityProgressWithEvent = async function onActivityProgressWithEvent(_ref2) {
|
|
45
|
+
var activity = _ref2.activity,
|
|
46
|
+
onStartData = _ref2.onStartData,
|
|
47
|
+
activitySignal = _ref2.activitySignal,
|
|
48
|
+
onProgress = _ref2.onProgress,
|
|
49
|
+
onProgressTimeoutMs = _ref2.onProgressTimeoutMs,
|
|
50
|
+
thunkApi = _ref2.thunkApi;
|
|
51
|
+
var dispatch = thunkApi.dispatch,
|
|
52
|
+
extra = thunkApi.extra,
|
|
53
|
+
getState = thunkApi.getState;
|
|
54
|
+
var throttledProgress = throttle(function (_ref3) {
|
|
55
|
+
var _currentActivity$prog;
|
|
56
|
+
var id = _ref3.id,
|
|
57
|
+
percentage = _ref3.percentage,
|
|
58
|
+
rest = _objectWithoutProperties(_ref3, _excluded);
|
|
59
|
+
if (id !== activity.id) return;
|
|
60
|
+
var currentActivity = selectProgressPanelActivityById(getState(), id);
|
|
61
|
+
if (currentActivity && isProgressPanelActive((_currentActivity$prog = currentActivity.progress) === null || _currentActivity$prog === void 0 ? void 0 : _currentActivity$prog.status)) {
|
|
62
|
+
dispatch(progressPanelActivityUpdated({
|
|
63
|
+
id: activity.id,
|
|
64
|
+
progress: _objectSpread(_objectSpread({}, activity.progress), {}, {
|
|
65
|
+
percentage: percentage,
|
|
66
|
+
status: PROGRESS_PANEL_STATUS.PROGRESSING
|
|
67
|
+
}, rest)
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
}, onProgressTimeoutMs);
|
|
71
|
+
extra.filerobot.on('activity-progress', throttledProgress);
|
|
72
|
+
return await onProgress({
|
|
73
|
+
activity: activity,
|
|
74
|
+
onStartData: onStartData,
|
|
75
|
+
activitySignal: activitySignal
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
var _onActivityProgressRecursive = async function onActivityProgressRecursive(activityProgressParams) {
|
|
79
|
+
var _currentActivity$prog2;
|
|
80
|
+
var activity = activityProgressParams.activity,
|
|
81
|
+
onStartData = activityProgressParams.onStartData,
|
|
82
|
+
onProgress = activityProgressParams.onProgress,
|
|
83
|
+
onProgressTimeoutMs = activityProgressParams.onProgressTimeoutMs,
|
|
84
|
+
activitySignal = activityProgressParams.activitySignal,
|
|
85
|
+
thunkApi = activityProgressParams.thunkApi;
|
|
86
|
+
var dispatch = thunkApi.dispatch,
|
|
87
|
+
getState = thunkApi.getState;
|
|
88
|
+
var _ref4 = (await onProgress({
|
|
89
|
+
activity: activity,
|
|
90
|
+
onStartData: onStartData,
|
|
91
|
+
activitySignal: activitySignal
|
|
92
|
+
})) || {},
|
|
93
|
+
retrigger = _ref4.retrigger,
|
|
94
|
+
percentage = _ref4.progress,
|
|
95
|
+
otherProgressResults = _objectWithoutProperties(_ref4, _excluded2);
|
|
96
|
+
var currentActivity = selectProgressPanelActivityById(getState(), activity.id);
|
|
97
|
+
if (retrigger && currentActivity && isProgressPanelActive((_currentActivity$prog2 = currentActivity.progress) === null || _currentActivity$prog2 === void 0 ? void 0 : _currentActivity$prog2.status)) {
|
|
98
|
+
dispatch(progressPanelActivityUpdated({
|
|
99
|
+
id: activity.id,
|
|
100
|
+
progress: _objectSpread(_objectSpread(_objectSpread({}, otherProgressResults), activity.progress), {}, {
|
|
101
|
+
percentage: percentage,
|
|
102
|
+
status: PROGRESS_PANEL_STATUS.PROGRESSING
|
|
103
|
+
})
|
|
104
|
+
}));
|
|
105
|
+
await asyncTimeout(onProgressTimeoutMs);
|
|
106
|
+
return await _onActivityProgressRecursive(activityProgressParams);
|
|
107
|
+
}
|
|
108
|
+
return _objectSpread({
|
|
109
|
+
percentage: percentage
|
|
110
|
+
}, otherProgressResults);
|
|
111
|
+
};
|
|
112
|
+
var _removeActivity = createThunk(function (activity, thunkApi) {
|
|
113
|
+
var dispatch = thunkApi.dispatch,
|
|
114
|
+
getState = thunkApi.getState;
|
|
115
|
+
var activitiesIds = selectProgressPanelActivitiesIds(getState());
|
|
116
|
+
if (activitiesIds.length === 1) {
|
|
117
|
+
dispatch(resetPanel());
|
|
118
|
+
}
|
|
119
|
+
dispatch(progressPanelActivitiesRemoved([activity.id]));
|
|
120
|
+
});
|
|
121
|
+
var onActivityComplete = function onActivityComplete(_ref5) {
|
|
122
|
+
var activity = _ref5.activity,
|
|
123
|
+
dismissAddingOnProgressDataToState = _ref5.dismissAddingOnProgressDataToState,
|
|
124
|
+
onStartData = _ref5.onStartData,
|
|
125
|
+
onProgressData = _ref5.onProgressData,
|
|
126
|
+
onComplete = _ref5.onComplete,
|
|
127
|
+
thunkApi = _ref5.thunkApi,
|
|
128
|
+
isSaveableActivity = _ref5.isSaveableActivity;
|
|
129
|
+
var dispatch = thunkApi.dispatch,
|
|
130
|
+
getState = thunkApi.getState,
|
|
131
|
+
extra = thunkApi.extra;
|
|
132
|
+
var currentActivity = selectProgressPanelActivityById(getState(), activity.id);
|
|
133
|
+
if (isSaveableActivity && activity !== null && activity !== void 0 && activity.id) {
|
|
134
|
+
var _extra$filerobot$opts;
|
|
135
|
+
var token = (_extra$filerobot$opts = extra.filerobot.opts) === null || _extra$filerobot$opts === void 0 ? void 0 : _extra$filerobot$opts.container;
|
|
136
|
+
removeSavedActivity(token, activity.id);
|
|
137
|
+
}
|
|
138
|
+
if (currentActivity) {
|
|
139
|
+
dispatch(progressPanelActivityUpdated({
|
|
140
|
+
id: activity.id,
|
|
141
|
+
progress: _objectSpread(_objectSpread({}, activity.progress), {}, {
|
|
142
|
+
status: PROGRESS_PANEL_STATUS.COMPLETE,
|
|
143
|
+
percentage: 100
|
|
144
|
+
}),
|
|
145
|
+
onProgressData: dismissAddingOnProgressDataToState ? {} : onProgressData
|
|
146
|
+
}));
|
|
147
|
+
if (typeof onComplete === 'function') {
|
|
148
|
+
onComplete({
|
|
149
|
+
activity: activity,
|
|
150
|
+
onStartData: onStartData,
|
|
151
|
+
onProgressData: onProgressData,
|
|
152
|
+
removeActivity: function removeActivity() {
|
|
153
|
+
return dispatch(_removeActivity(activity));
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return _objectSpread(_objectSpread({
|
|
159
|
+
activity: activity
|
|
160
|
+
}, onStartData), onProgressData);
|
|
161
|
+
};
|
|
162
|
+
var onActivityCancel = createThunk(function (_ref6, thunkApi) {
|
|
163
|
+
var activity = _ref6.activity,
|
|
164
|
+
abort = _ref6.abort,
|
|
165
|
+
onCancel = _ref6.onCancel,
|
|
166
|
+
isSaveableActivity = _ref6.isSaveableActivity;
|
|
167
|
+
var dispatch = thunkApi.dispatch,
|
|
168
|
+
extra = thunkApi.extra,
|
|
169
|
+
getState = thunkApi.getState;
|
|
170
|
+
extra.filerobot.on('activity-cancel', function (_ref7) {
|
|
171
|
+
var id = _ref7.id;
|
|
172
|
+
var updatedActivity = selectProgressPanelActivitiesById(getState(), activity.id);
|
|
173
|
+
if (id !== activity.id) return;
|
|
174
|
+
abort();
|
|
175
|
+
if (typeof onCancel === 'function') {
|
|
176
|
+
onCancel({
|
|
177
|
+
activity: updatedActivity,
|
|
178
|
+
id: id
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
if (isSaveableActivity && id) {
|
|
182
|
+
var _extra$filerobot$opts2;
|
|
183
|
+
var token = (_extra$filerobot$opts2 = extra.filerobot.opts) === null || _extra$filerobot$opts2 === void 0 ? void 0 : _extra$filerobot$opts2.container;
|
|
184
|
+
removeSavedActivity(token, id);
|
|
185
|
+
}
|
|
186
|
+
dispatch(_removeActivity(activity));
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
var onActivityRetry = createThunk(function (_ref8, thunkApi) {
|
|
190
|
+
var activity = _ref8.activity,
|
|
191
|
+
onRetry = _ref8.onRetry,
|
|
192
|
+
isSaveableActivity = _ref8.isSaveableActivity;
|
|
193
|
+
var extra = thunkApi.extra;
|
|
194
|
+
extra.filerobot.on('activity-retry', function (_ref9) {
|
|
195
|
+
var id = _ref9.id;
|
|
196
|
+
if (id !== activity.id) return;
|
|
197
|
+
if (isSaveableActivity && id) {
|
|
198
|
+
var _extra$filerobot$opts3;
|
|
199
|
+
var token = (_extra$filerobot$opts3 = extra.filerobot.opts) === null || _extra$filerobot$opts3 === void 0 ? void 0 : _extra$filerobot$opts3.container;
|
|
200
|
+
removeSavedActivity(token, id);
|
|
201
|
+
}
|
|
202
|
+
onRetry({
|
|
203
|
+
activity: activity,
|
|
204
|
+
id: id
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
var restartActivity = createThunk(function (_ref10, thunkApi) {
|
|
209
|
+
var activity = _ref10.activity,
|
|
210
|
+
newActivity = _ref10.newActivity,
|
|
211
|
+
abort = _ref10.abort,
|
|
212
|
+
onCancel = _ref10.onCancel,
|
|
213
|
+
onRetry = _ref10.onRetry,
|
|
214
|
+
isSaveableActivity = _ref10.isSaveableActivity;
|
|
215
|
+
var dispatch = thunkApi.dispatch;
|
|
216
|
+
dispatch(progressPanelActivityUpdated(_objectSpread(_objectSpread({}, newActivity), {}, {
|
|
217
|
+
id: activity.id,
|
|
218
|
+
progress: _objectSpread(_objectSpread({}, activity.progress), {}, {
|
|
219
|
+
status: PROGRESS_PANEL_STATUS.PREPARING,
|
|
220
|
+
startedAt: Date.now(),
|
|
221
|
+
percentage: 0
|
|
222
|
+
})
|
|
223
|
+
})));
|
|
224
|
+
if (typeof onCancel === 'function') {
|
|
225
|
+
dispatch(onActivityCancel({
|
|
226
|
+
activity: activity,
|
|
227
|
+
abort: abort,
|
|
228
|
+
onCancel: onCancel,
|
|
229
|
+
isSaveableActivity: isSaveableActivity
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
if (typeof onRetry === 'function') {
|
|
233
|
+
dispatch(onActivityRetry({
|
|
234
|
+
activity: activity,
|
|
235
|
+
onRetry: onRetry,
|
|
236
|
+
isSaveableActivity: isSaveableActivity
|
|
237
|
+
}));
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
var triggerError = function triggerError(_ref11) {
|
|
241
|
+
var activity = _ref11.activity,
|
|
242
|
+
error = _ref11.error,
|
|
243
|
+
onError = _ref11.onError,
|
|
244
|
+
thunkApi = _ref11.thunkApi,
|
|
245
|
+
isSaveableActivity = _ref11.isSaveableActivity;
|
|
246
|
+
var dispatch = thunkApi.dispatch,
|
|
247
|
+
extra = thunkApi.extra;
|
|
248
|
+
if (isSaveableActivity && activity !== null && activity !== void 0 && activity.id) {
|
|
249
|
+
var _extra$filerobot$opts4;
|
|
250
|
+
var token = (_extra$filerobot$opts4 = extra.filerobot.opts) === null || _extra$filerobot$opts4 === void 0 ? void 0 : _extra$filerobot$opts4.container;
|
|
251
|
+
removeSavedActivity(token, activity.id);
|
|
252
|
+
}
|
|
253
|
+
if (typeof onError === 'function') {
|
|
254
|
+
onError(error);
|
|
255
|
+
}
|
|
256
|
+
if (error !== ABORTED_ERROR) {
|
|
257
|
+
dispatch(onActivityError({
|
|
258
|
+
id: activity.id,
|
|
259
|
+
error: error
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
var addExtraActivityListeners = function addExtraActivityListeners(_ref12) {
|
|
264
|
+
var activity = _ref12.activity,
|
|
265
|
+
onError = _ref12.onError,
|
|
266
|
+
thunkApi = _ref12.thunkApi;
|
|
267
|
+
var dispatch = thunkApi.dispatch,
|
|
268
|
+
getState = thunkApi.getState,
|
|
269
|
+
extra = thunkApi.extra;
|
|
270
|
+
extra.filerobot.on('activity-error', function (_ref13) {
|
|
271
|
+
var id = _ref13.id,
|
|
272
|
+
error = _ref13.error;
|
|
273
|
+
if (id !== activity.id) return;
|
|
274
|
+
triggerError({
|
|
275
|
+
activity: activity,
|
|
276
|
+
error: error,
|
|
277
|
+
onError: onError,
|
|
278
|
+
thunkApi: thunkApi
|
|
279
|
+
});
|
|
280
|
+
});
|
|
281
|
+
extra.filerobot.on('activity-update', function (_ref14) {
|
|
282
|
+
var id = _ref14.id,
|
|
283
|
+
_ref14$progress = _ref14.progress,
|
|
284
|
+
progress = _ref14$progress === void 0 ? {} : _ref14$progress;
|
|
285
|
+
if (id !== activity.id) return;
|
|
286
|
+
var currentActivity = selectProgressPanelActivityById(getState(), id);
|
|
287
|
+
dispatch(progressPanelActivityUpdated(_objectSpread(_objectSpread({}, currentActivity), {}, {
|
|
288
|
+
id: currentActivity.id,
|
|
289
|
+
progress: _objectSpread(_objectSpread({}, currentActivity.progress), progress)
|
|
290
|
+
})));
|
|
291
|
+
});
|
|
292
|
+
};
|
|
293
|
+
var addNewActivity = createThunk(function (_ref15, thunkApi) {
|
|
294
|
+
var activity = _ref15.activity,
|
|
295
|
+
abort = _ref15.abort,
|
|
296
|
+
onCancel = _ref15.onCancel,
|
|
297
|
+
onRetry = _ref15.onRetry,
|
|
298
|
+
onError = _ref15.onError,
|
|
299
|
+
isSaveableActivity = _ref15.isSaveableActivity;
|
|
300
|
+
var dispatch = thunkApi.dispatch;
|
|
301
|
+
dispatch(progressPanelActivitiesAdded(_defineProperty({}, activity.id, activity)));
|
|
302
|
+
addExtraActivityListeners({
|
|
303
|
+
activity: activity,
|
|
304
|
+
onError: onError,
|
|
305
|
+
thunkApi: thunkApi
|
|
306
|
+
});
|
|
307
|
+
dispatch(onActivityCancel({
|
|
308
|
+
activity: activity,
|
|
309
|
+
abort: abort,
|
|
310
|
+
onCancel: onCancel,
|
|
311
|
+
isSaveableActivity: isSaveableActivity
|
|
312
|
+
}));
|
|
313
|
+
if (typeof onRetry === 'function') {
|
|
314
|
+
dispatch(onActivityRetry({
|
|
315
|
+
activity: activity,
|
|
316
|
+
onRetry: onRetry,
|
|
317
|
+
isSaveableActivity: isSaveableActivity
|
|
318
|
+
}));
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// onActivitySave => for filtering/returning specific data part to be saved
|
|
323
|
+
export var addActivity = createThunk(async function (_ref16, thunkApi) {
|
|
324
|
+
var activity = _ref16.activity,
|
|
325
|
+
onStart = _ref16.onStart,
|
|
326
|
+
onError = _ref16.onError,
|
|
327
|
+
onCancel = _ref16.onCancel,
|
|
328
|
+
onProgress = _ref16.onProgress,
|
|
329
|
+
onComplete = _ref16.onComplete,
|
|
330
|
+
onRetry = _ref16.onRetry,
|
|
331
|
+
_ref16$options = _ref16.options,
|
|
332
|
+
options = _ref16$options === void 0 ? {} : _ref16$options,
|
|
333
|
+
onActivitySave = _ref16.onActivitySave,
|
|
334
|
+
isSaveableActivity = _ref16.isSaveableActivity;
|
|
335
|
+
var dispatch = thunkApi.dispatch,
|
|
336
|
+
getState = thunkApi.getState,
|
|
337
|
+
signal = thunkApi.signal,
|
|
338
|
+
abort = thunkApi.abort,
|
|
339
|
+
extra = thunkApi.extra;
|
|
340
|
+
var triggerProgressWithEvent = options.triggerProgressWithEvent,
|
|
341
|
+
_options$dismissAddin = options.dismissAddingOnProgressDataToState,
|
|
342
|
+
dismissAddingOnProgressDataToState = _options$dismissAddin === void 0 ? true : _options$dismissAddin,
|
|
343
|
+
_options$onProgressTi = options.onProgressTimeoutMs,
|
|
344
|
+
onProgressTimeoutMs = _options$onProgressTi === void 0 ? 1000 : _options$onProgressTi;
|
|
345
|
+
var currentActivity = selectProgressPanelActivityById(getState(), activity.id);
|
|
346
|
+
var showProgressPanel = selectShowProgressPanel(getState());
|
|
347
|
+
var tmpActivity = {};
|
|
348
|
+
if (currentActivity) {
|
|
349
|
+
// restart existing activity
|
|
350
|
+
tmpActivity = _objectSpread(_objectSpread({}, currentActivity), {}, {
|
|
351
|
+
name: activity.name
|
|
352
|
+
});
|
|
353
|
+
dispatch(restartActivity({
|
|
354
|
+
activity: tmpActivity,
|
|
355
|
+
newActivity: activity,
|
|
356
|
+
abort: abort,
|
|
357
|
+
onCancel: onCancel,
|
|
358
|
+
onRetry: onRetry,
|
|
359
|
+
isSaveableActivity: isSaveableActivity
|
|
360
|
+
}));
|
|
361
|
+
} else {
|
|
362
|
+
// create new activity
|
|
363
|
+
tmpActivity = activity;
|
|
364
|
+
dispatch(addNewActivity({
|
|
365
|
+
activity: tmpActivity,
|
|
366
|
+
abort: abort,
|
|
367
|
+
onCancel: onCancel,
|
|
368
|
+
onRetry: onRetry
|
|
369
|
+
}));
|
|
370
|
+
}
|
|
371
|
+
if (!showProgressPanel) {
|
|
372
|
+
extra.filerobot.emit('progressPanel-toggle', true);
|
|
373
|
+
}
|
|
374
|
+
try {
|
|
375
|
+
var onStartData;
|
|
376
|
+
if (typeof onStart === 'function') {
|
|
377
|
+
onStartData = onStart({
|
|
378
|
+
activity: tmpActivity,
|
|
379
|
+
activitySignal: signal
|
|
380
|
+
});
|
|
381
|
+
if (onStartData instanceof Promise) {
|
|
382
|
+
onStartData = await onStartData;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (isSaveableActivity) {
|
|
386
|
+
var _extra$filerobot$opts5;
|
|
387
|
+
var activityDataToSave = typeof onActivitySave === 'function' ? onActivitySave({
|
|
388
|
+
onStartData: onStartData,
|
|
389
|
+
activity: tmpActivity
|
|
390
|
+
}) : onStartData;
|
|
391
|
+
var token = (_extra$filerobot$opts5 = extra.filerobot.opts) === null || _extra$filerobot$opts5 === void 0 ? void 0 : _extra$filerobot$opts5.container;
|
|
392
|
+
if (!activityDataToSave || !tmpActivity) {
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
pushToSavedActivities(token, {
|
|
396
|
+
id: tmpActivity.id,
|
|
397
|
+
type: tmpActivity.type,
|
|
398
|
+
name: tmpActivity.name,
|
|
399
|
+
data: activityDataToSave
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
var onProgressData;
|
|
403
|
+
if (typeof onProgress === 'function') {
|
|
404
|
+
var onProgressAction = triggerProgressWithEvent ? onActivityProgressWithEvent : _onActivityProgressRecursive;
|
|
405
|
+
onProgressData = await onProgressAction({
|
|
406
|
+
activity: tmpActivity,
|
|
407
|
+
onStartData: onStartData,
|
|
408
|
+
onProgress: onProgress,
|
|
409
|
+
activitySignal: signal,
|
|
410
|
+
onProgressTimeoutMs: onProgressTimeoutMs,
|
|
411
|
+
thunkApi: thunkApi
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
return onActivityComplete({
|
|
415
|
+
activity: tmpActivity,
|
|
416
|
+
dismissAddingOnProgressDataToState: dismissAddingOnProgressDataToState,
|
|
417
|
+
onStartData: onStartData,
|
|
418
|
+
onProgressData: onProgressData,
|
|
419
|
+
onComplete: onComplete,
|
|
420
|
+
thunkApi: thunkApi,
|
|
421
|
+
isSaveableActivity: isSaveableActivity
|
|
422
|
+
});
|
|
423
|
+
} catch (error) {
|
|
424
|
+
logErrorIfDevEnv(error, extra.filerobot.opts.dev);
|
|
425
|
+
triggerError({
|
|
426
|
+
activity: activity,
|
|
427
|
+
error: error,
|
|
428
|
+
onError: onError,
|
|
429
|
+
thunkApi: thunkApi,
|
|
430
|
+
isSaveableActivity: isSaveableActivity
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
}, {
|
|
434
|
+
dismissGlobalAbort: true
|
|
435
|
+
});
|
|
436
|
+
export var resetPanel = createThunk(function (_, thunkApi) {
|
|
437
|
+
var dispatch = thunkApi.dispatch,
|
|
438
|
+
extra = thunkApi.extra;
|
|
439
|
+
dispatch(progressPanelClosed());
|
|
440
|
+
extra.filerobot.emit('activities-reset');
|
|
441
|
+
extra.filerobot.emit('progressPanel-toggle', false);
|
|
442
|
+
extra.filerobot.emit('progressPanel-minimize', false);
|
|
443
|
+
extra.filerobot.off('activity-error');
|
|
444
|
+
extra.filerobot.off('activity-update');
|
|
445
|
+
extra.filerobot.off('activity-cancel');
|
|
446
|
+
extra.filerobot.off('activity-retry');
|
|
447
|
+
extra.filerobot.off('activity-action');
|
|
448
|
+
extra.filerobot.off('activity-progress');
|
|
449
|
+
});
|
|
450
|
+
export var isProgressPanelActive = function isProgressPanelActive(status) {
|
|
451
|
+
return [PROGRESS_PANEL_STATUS.PAUSED, PROGRESS_PANEL_STATUS.PROGRESSING, PROGRESS_PANEL_STATUS.PREPARING].includes(status);
|
|
452
|
+
};
|
|
453
|
+
var progressPanelSlice = createSlice({
|
|
454
|
+
name: PLUGINS_IDS.PROGRESS_PANEL,
|
|
455
|
+
initialState: initialState,
|
|
456
|
+
reducers: {
|
|
457
|
+
progressPanelActivitiesAdded: function progressPanelActivitiesAdded(state, action) {
|
|
458
|
+
var newActivities = _objectSpread({}, action.payload);
|
|
459
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
460
|
+
ids: _toConsumableArray(new Set([].concat(_toConsumableArray(Object.keys(newActivities)), _toConsumableArray(state.ids)))),
|
|
461
|
+
activities: _objectSpread(_objectSpread({}, newActivities), state.activities),
|
|
462
|
+
show: true,
|
|
463
|
+
isMinimized: false
|
|
464
|
+
});
|
|
465
|
+
},
|
|
466
|
+
progressPanelActivityUpdated: function progressPanelActivityUpdated(state, action) {
|
|
467
|
+
var activityId = action.payload.id;
|
|
468
|
+
var updatedActivities = _objectSpread({}, state.activities);
|
|
469
|
+
updatedActivities[activityId] = _objectSpread(_objectSpread({}, state.activities[activityId]), action.payload);
|
|
470
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
471
|
+
activities: updatedActivities
|
|
472
|
+
});
|
|
473
|
+
},
|
|
474
|
+
progressPanelActivitiesReplaced: function progressPanelActivitiesReplaced(state, action) {
|
|
475
|
+
var activities = action.payload;
|
|
476
|
+
var newActivities = Array.isArray(activities) ? activities.reduce(function (activitiesByIds, activity) {
|
|
477
|
+
return _objectSpread(_objectSpread({}, activitiesByIds), {}, _defineProperty({}, activity.id, activity));
|
|
478
|
+
}, {}) : activities;
|
|
479
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
480
|
+
ids: Object.keys(newActivities),
|
|
481
|
+
activities: newActivities
|
|
482
|
+
});
|
|
483
|
+
},
|
|
484
|
+
progressPanelActivitiesRemoved: function progressPanelActivitiesRemoved(state, action) {
|
|
485
|
+
var removedActivitiesIds = action.payload || [];
|
|
486
|
+
var updatedActivities = _objectSpread({}, state.activities);
|
|
487
|
+
var updatedIds = state.ids;
|
|
488
|
+
removedActivitiesIds.forEach(function (activityId) {
|
|
489
|
+
updatedIds = updatedIds.filter(function (id) {
|
|
490
|
+
return id !== activityId;
|
|
491
|
+
});
|
|
492
|
+
delete updatedActivities[activityId];
|
|
493
|
+
});
|
|
494
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
495
|
+
ids: updatedIds,
|
|
496
|
+
activities: updatedActivities,
|
|
497
|
+
show: Object.keys(updatedActivities).length !== 0
|
|
498
|
+
});
|
|
499
|
+
},
|
|
500
|
+
progressPanelToggled: function progressPanelToggled(state, action) {
|
|
501
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
502
|
+
show: action.payload
|
|
503
|
+
});
|
|
504
|
+
},
|
|
505
|
+
progressPanelMinimized: function progressPanelMinimized(state, action) {
|
|
506
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
507
|
+
isMinimized: action.payload
|
|
508
|
+
});
|
|
509
|
+
},
|
|
510
|
+
progressPanelClosed: function progressPanelClosed() {
|
|
511
|
+
return initialState;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
var _progressPanelSlice$a = progressPanelSlice.actions,
|
|
516
|
+
progressPanelActivitiesAdded = _progressPanelSlice$a.progressPanelActivitiesAdded,
|
|
517
|
+
progressPanelActivityUpdated = _progressPanelSlice$a.progressPanelActivityUpdated,
|
|
518
|
+
progressPanelActivitiesReplaced = _progressPanelSlice$a.progressPanelActivitiesReplaced,
|
|
519
|
+
progressPanelActivitiesRemoved = _progressPanelSlice$a.progressPanelActivitiesRemoved,
|
|
520
|
+
progressPanelToggled = _progressPanelSlice$a.progressPanelToggled,
|
|
521
|
+
progressPanelMinimized = _progressPanelSlice$a.progressPanelMinimized,
|
|
522
|
+
progressPanelClosed = _progressPanelSlice$a.progressPanelClosed;
|
|
523
|
+
export { progressPanelActivitiesAdded, progressPanelActivityUpdated, progressPanelActivitiesReplaced, progressPanelActivitiesRemoved, progressPanelToggled, progressPanelMinimized, progressPanelClosed };
|
|
524
|
+
export var selectProgressPanelState = function selectProgressPanelState(state) {
|
|
525
|
+
return state[PLUGINS_IDS.PROGRESS_PANEL];
|
|
526
|
+
};
|
|
527
|
+
export var selectProgressPanelActivities = function selectProgressPanelActivities(state) {
|
|
528
|
+
return selectProgressPanelState(state).activities;
|
|
529
|
+
};
|
|
530
|
+
export var selectProgressPanelActivitiesIds = function selectProgressPanelActivitiesIds(state) {
|
|
531
|
+
return selectProgressPanelState(state).ids;
|
|
532
|
+
};
|
|
533
|
+
export var selectProgressPanelActivityById = function selectProgressPanelActivityById(state, activityId) {
|
|
534
|
+
return selectProgressPanelActivities(state)[activityId];
|
|
535
|
+
};
|
|
536
|
+
export var selectShowProgressPanel = function selectShowProgressPanel(state) {
|
|
537
|
+
return selectProgressPanelState(state).show;
|
|
538
|
+
};
|
|
539
|
+
export var selectIsProgressPanelMinimized = function selectIsProgressPanelMinimized(state) {
|
|
540
|
+
return selectProgressPanelState(state).isMinimized;
|
|
541
|
+
};
|
|
542
|
+
export var selectProgressPanelCount = function selectProgressPanelCount(state) {
|
|
543
|
+
return Object.keys(selectProgressPanelActivities(state)).length;
|
|
544
|
+
};
|
|
545
|
+
export var selectProgressPanelActivitiesById = createSelector([selectProgressPanelActivities, function (_state, activityId) {
|
|
546
|
+
return activityId;
|
|
547
|
+
}], function (activities, activityId) {
|
|
548
|
+
return activities[activityId] ? _objectSpread(_objectSpread({}, activities[activityId]), {}, {
|
|
549
|
+
data: Filerobot.uploadFilesData[activityId]
|
|
550
|
+
}) : undefined;
|
|
551
|
+
});
|
|
552
|
+
export var selectProgressPanelUploadingActivitiesIds = createSelector(selectProgressPanelActivities, selectProgressPanelActivitiesIds, function (activities, activitiesIds) {
|
|
553
|
+
return activitiesIds.filter(function (activityId) {
|
|
554
|
+
var _activity$progress;
|
|
555
|
+
var activity = activities[activityId];
|
|
556
|
+
return ((_activity$progress = activity.progress) === null || _activity$progress === void 0 ? void 0 : _activity$progress.type) === PROGRESS_PANEL_ACTIVITY.UPLOAD;
|
|
557
|
+
});
|
|
558
|
+
});
|
|
559
|
+
export var selectProgressPanelInProgressActivitiesIds = createSelector(selectProgressPanelActivities, selectProgressPanelActivitiesIds, function (activities, activitiesIds) {
|
|
560
|
+
return activitiesIds.filter(function (activityId) {
|
|
561
|
+
var _activity$progress2;
|
|
562
|
+
var activity = activities[activityId];
|
|
563
|
+
return isProgressPanelActive((_activity$progress2 = activity.progress) === null || _activity$progress2 === void 0 ? void 0 : _activity$progress2.status) && activity.progress.startedAt;
|
|
564
|
+
});
|
|
565
|
+
});
|
|
566
|
+
export var selectProgressPanelCompletedActivitiesIds = createSelector(selectProgressPanelActivities, selectProgressPanelActivitiesIds, function (activities, activitiesIds) {
|
|
567
|
+
return activitiesIds.filter(function (activityId) {
|
|
568
|
+
var _activity$progress3;
|
|
569
|
+
var activity = activities[activityId];
|
|
570
|
+
return ((_activity$progress3 = activity.progress) === null || _activity$progress3 === void 0 ? void 0 : _activity$progress3.status) === PROGRESS_PANEL_STATUS.COMPLETE;
|
|
571
|
+
});
|
|
572
|
+
});
|
|
573
|
+
export var selectProgressPanelDelayedActivitiesIds = createSelector(selectProgressPanelActivities, selectProgressPanelActivitiesIds, function (activities, activitiesIds) {
|
|
574
|
+
return activitiesIds.filter(function (activityId) {
|
|
575
|
+
var _activity$progress4;
|
|
576
|
+
var activity = activities[activityId];
|
|
577
|
+
return ((_activity$progress4 = activity.progress) === null || _activity$progress4 === void 0 ? void 0 : _activity$progress4.status) === PROGRESS_PANEL_STATUS.DELAYED;
|
|
578
|
+
});
|
|
579
|
+
});
|
|
580
|
+
export var selectProgressPanelFailedActivitiesIds = createSelector(selectProgressPanelActivities, selectProgressPanelActivitiesIds, function (activities, activitiesIds) {
|
|
581
|
+
return activitiesIds.filter(function (activityId) {
|
|
582
|
+
return activities[activityId].progress.status === PROGRESS_PANEL_STATUS.ERROR;
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
export var selectInProgressNotPaused = createSelector(selectProgressPanelActivities, selectProgressPanelInProgressActivitiesIds, function (activities, inProgressActivitiesIds) {
|
|
586
|
+
return inProgressActivitiesIds.filter(function (activityId) {
|
|
587
|
+
return activities[activityId].progress.status !== PROGRESS_PANEL_STATUS.PAUSED;
|
|
588
|
+
});
|
|
589
|
+
});
|
|
590
|
+
export var selectProgressPanelTotalEta = function selectProgressPanelTotalEta(state) {
|
|
591
|
+
return calculateTotalEta(selectInProgressNotPaused(state).map(function (activityId) {
|
|
592
|
+
return selectProgressPanelActivitiesById(state, activityId) || {};
|
|
593
|
+
}));
|
|
594
|
+
};
|
|
595
|
+
export default progressPanelSlice.reducer;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
|
+
var ACTIVITIES_STORAGE_KEY = 'activities';
|
|
8
|
+
export var getActivitiesStorageName = function getActivitiesStorageName(token) {
|
|
9
|
+
return "FMAW_".concat(token || '', "_").concat(ACTIVITIES_STORAGE_KEY);
|
|
10
|
+
};
|
|
11
|
+
export var getSavedActivities = function getSavedActivities(token) {
|
|
12
|
+
var _window;
|
|
13
|
+
if (!((_window = window) !== null && _window !== void 0 && _window.localStorage) || !token) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
try {
|
|
17
|
+
var loadedActivities = JSON.parse(window.localStorage.getItem(getActivitiesStorageName(token))) || [];
|
|
18
|
+
return loadedActivities;
|
|
19
|
+
} catch (_unused) {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
export var pushToSavedActivities = function pushToSavedActivities(token) {
|
|
24
|
+
var _window2;
|
|
25
|
+
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
26
|
+
id = _ref.id,
|
|
27
|
+
type = _ref.type,
|
|
28
|
+
name = _ref.name,
|
|
29
|
+
data = _ref.data;
|
|
30
|
+
if (!((_window2 = window) !== null && _window2 !== void 0 && _window2.localStorage) || !token || !id || !type || !data || Object.keys(data || {}).length === 0) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
var loadedActivities = getSavedActivities(token).filter(function (activity) {
|
|
34
|
+
return activity.id !== id;
|
|
35
|
+
});
|
|
36
|
+
var pushedActivity = _objectSpread(_objectSpread({
|
|
37
|
+
id: id,
|
|
38
|
+
type: type
|
|
39
|
+
}, name && {
|
|
40
|
+
name: name
|
|
41
|
+
}), {}, {
|
|
42
|
+
data: data
|
|
43
|
+
});
|
|
44
|
+
loadedActivities.push(pushedActivity);
|
|
45
|
+
window.localStorage.setItem(getActivitiesStorageName(token), JSON.stringify(loadedActivities));
|
|
46
|
+
return loadedActivities;
|
|
47
|
+
};
|
|
48
|
+
export var removeSavedActivity = function removeSavedActivity(token, id) {
|
|
49
|
+
var _window3;
|
|
50
|
+
if (!((_window3 = window) !== null && _window3 !== void 0 && _window3.localStorage) || !token || !id) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
var loadedActivities = getSavedActivities(token);
|
|
54
|
+
var newActivities = loadedActivities.filter(function () {
|
|
55
|
+
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
56
|
+
_id = _ref2.id;
|
|
57
|
+
return _id !== id;
|
|
58
|
+
});
|
|
59
|
+
if (newActivities.length === 0) {
|
|
60
|
+
window.localStorage.removeItem(getActivitiesStorageName(token));
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
window.localStorage.setItem(getActivitiesStorageName(token), JSON.stringify(newActivities));
|
|
64
|
+
};
|