@atlaskit/editor-synced-block-provider 3.26.1 → 3.26.2
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 +8 -0
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +72 -33
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +85 -47
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +72 -33
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +8 -5
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +8 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 3.26.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`ab4e4e442ad49`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ab4e4e442ad49) -
|
|
8
|
+
[ux] [EDITOR-3694] Add loading state to bodiedSyncBlock for when saving new block to BE
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 3.26.1
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -11,6 +11,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
11
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
12
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
13
|
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
14
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
15
|
var _types = require("../common/types");
|
|
15
16
|
var _errorHandling = require("../utils/errorHandling");
|
|
16
17
|
var _experienceTracking = require("../utils/experienceTracking");
|
|
@@ -34,6 +35,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
34
35
|
});
|
|
35
36
|
this.dataProvider = dataProvider;
|
|
36
37
|
this.syncBlockCache = new Map();
|
|
38
|
+
this.creationCompletionCallbacks = new Map();
|
|
37
39
|
}
|
|
38
40
|
return (0, _createClass2.default)(SourceSyncBlockStoreManager, [{
|
|
39
41
|
key: "setFireAnalyticsEvent",
|
|
@@ -100,9 +102,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
100
102
|
bodiedSyncBlockNodes = [];
|
|
101
103
|
bodiedSyncBlockData = [];
|
|
102
104
|
Array.from(this.syncBlockCache.values()).forEach(function (syncBlockData) {
|
|
103
|
-
// Don't flush nodes that
|
|
104
|
-
//
|
|
105
|
-
|
|
105
|
+
// Don't flush nodes that
|
|
106
|
+
// - are waiting to be deleted to avoid nodes being re-created
|
|
107
|
+
// - haven't been updated since we last flushed
|
|
108
|
+
// - are still pending BE creation
|
|
109
|
+
if (!syncBlockData.pendingDeletion && syncBlockData.isDirty && !(_this2.isPendingCreation(syncBlockData.resourceId) && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_1'))) {
|
|
106
110
|
bodiedSyncBlockNodes.push({
|
|
107
111
|
type: 'bodiedSyncBlock',
|
|
108
112
|
attrs: {
|
|
@@ -190,12 +194,18 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
190
194
|
return _flush.apply(this, arguments);
|
|
191
195
|
}
|
|
192
196
|
return flush;
|
|
193
|
-
}()
|
|
197
|
+
}() // Remove this method and pendingResourceId when cleaning up platform_synced_block_patch_1
|
|
198
|
+
)
|
|
194
199
|
}, {
|
|
195
200
|
key: "registerPendingCreation",
|
|
196
201
|
value: function registerPendingCreation(resourceId) {
|
|
197
202
|
this.pendingResourceId = resourceId;
|
|
198
203
|
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "isPendingCreation",
|
|
206
|
+
value: function isPendingCreation(resourceId) {
|
|
207
|
+
return this.creationCompletionCallbacks.has(resourceId);
|
|
208
|
+
}
|
|
199
209
|
|
|
200
210
|
/**
|
|
201
211
|
* Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
|
|
@@ -212,27 +222,48 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
212
222
|
*/
|
|
213
223
|
}, {
|
|
214
224
|
key: "commitPendingCreation",
|
|
215
|
-
value: function commitPendingCreation(success) {
|
|
216
|
-
if (
|
|
217
|
-
var
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
225
|
+
value: function commitPendingCreation(success, resourceId) {
|
|
226
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
227
|
+
var onCompletion = this.creationCompletionCallbacks.get(resourceId);
|
|
228
|
+
if (onCompletion) {
|
|
229
|
+
this.creationCompletionCallbacks.delete(resourceId);
|
|
230
|
+
onCompletion(success);
|
|
231
|
+
} else {
|
|
232
|
+
var _this$fireAnalyticsEv3;
|
|
233
|
+
(_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, (0, _errorHandling.createErrorPayload)('creation complete callback missing', resourceId));
|
|
234
|
+
}
|
|
235
|
+
if (success) {
|
|
236
|
+
var _this$fireAnalyticsEv4;
|
|
237
|
+
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, (0, _errorHandling.createSuccessPayload)(resourceId || ''));
|
|
238
|
+
} else {
|
|
239
|
+
var _this$fireAnalyticsEv5;
|
|
240
|
+
// Delete the node from cache if fail to create so it's not flushed to BE
|
|
241
|
+
this.syncBlockCache.delete(resourceId || '');
|
|
242
|
+
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, (0, _errorHandling.createErrorPayload)('Fail to create bodied sync block', resourceId));
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
if (success && this.creationCallback) {
|
|
246
|
+
var _this$fireAnalyticsEv6;
|
|
247
|
+
this.creationCallback();
|
|
248
|
+
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, (0, _errorHandling.createSuccessPayload)(this.pendingResourceId || ''));
|
|
249
|
+
} else if (success && !this.creationCallback) {
|
|
250
|
+
var _this$fireAnalyticsEv7;
|
|
251
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, (0, _errorHandling.createErrorPayload)('creation callback missing', this.pendingResourceId));
|
|
252
|
+
}
|
|
253
|
+
this.pendingResourceId = undefined;
|
|
223
254
|
}
|
|
224
|
-
this.pendingResourceId = undefined;
|
|
225
255
|
this.creationCallback = undefined;
|
|
226
256
|
}
|
|
227
257
|
|
|
228
258
|
/**
|
|
229
259
|
*
|
|
230
260
|
* @returns true if waiting for the result of saving new bodiedSyncBlock to backend
|
|
261
|
+
* Remove this method when cleaning up platform_synced_block_patch_1
|
|
231
262
|
*/
|
|
232
263
|
}, {
|
|
233
264
|
key: "hasPendingCreation",
|
|
234
265
|
value: function hasPendingCreation() {
|
|
235
|
-
return !!this.pendingResourceId;
|
|
266
|
+
return (0, _platformFeatureFlags.fg)('platform_synced_block_patch_1') ? this.creationCompletionCallbacks.size > 0 : !!this.pendingResourceId;
|
|
236
267
|
}
|
|
237
268
|
}, {
|
|
238
269
|
key: "registerConfirmationCallback",
|
|
@@ -273,35 +304,40 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
273
304
|
*/
|
|
274
305
|
}, {
|
|
275
306
|
key: "createBodiedSyncBlockNode",
|
|
276
|
-
value: function createBodiedSyncBlockNode(attrs, nodeData) {
|
|
307
|
+
value: function createBodiedSyncBlockNode(attrs, onCompletion, nodeData) {
|
|
277
308
|
var _this4 = this;
|
|
309
|
+
var resourceId = attrs.resourceId,
|
|
310
|
+
blockInstanceId = attrs.localId;
|
|
278
311
|
try {
|
|
279
312
|
var _this$createExperienc;
|
|
280
313
|
if (!this.dataProvider) {
|
|
281
314
|
throw new Error('Data provider not set');
|
|
282
315
|
}
|
|
283
|
-
|
|
284
|
-
|
|
316
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
317
|
+
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
318
|
+
}
|
|
285
319
|
(_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 || _this$createExperienc.start({});
|
|
286
320
|
this.dataProvider.createNodeData({
|
|
287
321
|
content: [],
|
|
288
322
|
blockInstanceId: blockInstanceId,
|
|
289
323
|
resourceId: resourceId
|
|
290
324
|
}).then(function (result) {
|
|
291
|
-
var resourceId = result.resourceId;
|
|
292
|
-
if (resourceId) {
|
|
325
|
+
var resourceId = result.resourceId || '';
|
|
326
|
+
if (resourceId && (!(0, _platformFeatureFlags.fg)('platform_synced_block_patch_1') || !result.error)) {
|
|
293
327
|
var _this4$createExperien;
|
|
294
|
-
_this4.commitPendingCreation(true);
|
|
328
|
+
_this4.commitPendingCreation(true, resourceId);
|
|
295
329
|
(_this4$createExperien = _this4.createExperience) === null || _this4$createExperien === void 0 || _this4$createExperien.success();
|
|
296
330
|
|
|
297
331
|
// Update the sync block data with the node data if it is provided
|
|
298
332
|
// to avoid any race conditions where the data could be missed during a render operation
|
|
299
|
-
if (
|
|
300
|
-
|
|
333
|
+
if (!(0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
334
|
+
if (nodeData) {
|
|
335
|
+
_this4.updateSyncBlockData(nodeData);
|
|
336
|
+
}
|
|
301
337
|
}
|
|
302
338
|
} else {
|
|
303
339
|
var _this4$createExperien2, _this4$fireAnalyticsE;
|
|
304
|
-
_this4.commitPendingCreation(false);
|
|
340
|
+
_this4.commitPendingCreation(false, resourceId);
|
|
305
341
|
(_this4$createExperien2 = _this4.createExperience) === null || _this4$createExperien2 === void 0 || _this4$createExperien2.failure({
|
|
306
342
|
reason: result.error || 'Failed to create bodied sync block'
|
|
307
343
|
});
|
|
@@ -309,7 +345,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
309
345
|
}
|
|
310
346
|
}).catch(function (error) {
|
|
311
347
|
var _this4$createExperien3, _this4$fireAnalyticsE2;
|
|
312
|
-
_this4.commitPendingCreation(false);
|
|
348
|
+
_this4.commitPendingCreation(false, resourceId);
|
|
313
349
|
(0, _monitoring.logException)(error, {
|
|
314
350
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
315
351
|
});
|
|
@@ -318,16 +354,18 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
318
354
|
});
|
|
319
355
|
(_this4$fireAnalyticsE2 = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE2 === void 0 || _this4$fireAnalyticsE2.call(_this4, (0, _errorHandling.createErrorPayload)(error.message, resourceId));
|
|
320
356
|
});
|
|
321
|
-
|
|
357
|
+
if (!(0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
358
|
+
this.registerPendingCreation(resourceId);
|
|
359
|
+
}
|
|
322
360
|
} catch (error) {
|
|
323
|
-
var _this$
|
|
324
|
-
if (this.hasPendingCreation()) {
|
|
325
|
-
this.commitPendingCreation(false);
|
|
361
|
+
var _this$fireAnalyticsEv8;
|
|
362
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_1') ? this.isPendingCreation(resourceId) : this.hasPendingCreation()) {
|
|
363
|
+
this.commitPendingCreation(false, resourceId);
|
|
326
364
|
}
|
|
327
365
|
(0, _monitoring.logException)(error, {
|
|
328
366
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
329
367
|
});
|
|
330
|
-
(_this$
|
|
368
|
+
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 || _this$fireAnalyticsEv8.call(this, (0, _errorHandling.createErrorPayload)(error.message));
|
|
331
369
|
}
|
|
332
370
|
}
|
|
333
371
|
}, {
|
|
@@ -538,11 +576,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
538
576
|
return sourceInfo;
|
|
539
577
|
});
|
|
540
578
|
} catch (error) {
|
|
541
|
-
var _this$
|
|
579
|
+
var _this$fireAnalyticsEv9;
|
|
542
580
|
(0, _monitoring.logException)(error, {
|
|
543
581
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
544
582
|
});
|
|
545
|
-
(_this$
|
|
583
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 || _this$fireAnalyticsEv9.call(this, (0, _errorHandling.getSourceInfoErrorPayload)(error.message));
|
|
546
584
|
return Promise.resolve(undefined);
|
|
547
585
|
}
|
|
548
586
|
}
|
|
@@ -555,11 +593,11 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
555
593
|
}
|
|
556
594
|
return this.dataProvider.fetchReferences(resourceId, true);
|
|
557
595
|
} catch (error) {
|
|
558
|
-
var _this$
|
|
596
|
+
var _this$fireAnalyticsEv0;
|
|
559
597
|
(0, _monitoring.logException)(error, {
|
|
560
598
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
561
599
|
});
|
|
562
|
-
(_this$
|
|
600
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 || _this$fireAnalyticsEv0.call(this, (0, _errorHandling.fetchReferencesErrorPayload)(error.message));
|
|
563
601
|
return Promise.resolve({
|
|
564
602
|
error: _types.SyncBlockError.Errored
|
|
565
603
|
});
|
|
@@ -572,6 +610,7 @@ var SourceSyncBlockStoreManager = exports.SourceSyncBlockStoreManager = /*#__PUR
|
|
|
572
610
|
this.syncBlockCache.clear();
|
|
573
611
|
this.confirmationCallback = undefined;
|
|
574
612
|
this.pendingResourceId = undefined;
|
|
613
|
+
this.creationCompletionCallbacks.clear();
|
|
575
614
|
this.creationCallback = undefined;
|
|
576
615
|
this.dataProvider = undefined;
|
|
577
616
|
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 || _this$saveExperience4.abort({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
3
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
4
|
import { SyncBlockError } from '../common/types';
|
|
4
5
|
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload, fetchReferencesErrorPayload } from '../utils/errorHandling';
|
|
5
6
|
import { getCreateSourceExperience, getDeleteSourceExperience, getSaveSourceExperience, getFetchSourceInfoExperience } from '../utils/experienceTracking';
|
|
@@ -19,6 +20,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
19
20
|
});
|
|
20
21
|
this.dataProvider = dataProvider;
|
|
21
22
|
this.syncBlockCache = new Map();
|
|
23
|
+
this.creationCompletionCallbacks = new Map();
|
|
22
24
|
}
|
|
23
25
|
setFireAnalyticsEvent(fireAnalyticsEvent) {
|
|
24
26
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
@@ -74,9 +76,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
74
76
|
const bodiedSyncBlockNodes = [];
|
|
75
77
|
const bodiedSyncBlockData = [];
|
|
76
78
|
Array.from(this.syncBlockCache.values()).forEach(syncBlockData => {
|
|
77
|
-
// Don't flush nodes that
|
|
78
|
-
//
|
|
79
|
-
|
|
79
|
+
// Don't flush nodes that
|
|
80
|
+
// - are waiting to be deleted to avoid nodes being re-created
|
|
81
|
+
// - haven't been updated since we last flushed
|
|
82
|
+
// - are still pending BE creation
|
|
83
|
+
if (!syncBlockData.pendingDeletion && syncBlockData.isDirty && !(this.isPendingCreation(syncBlockData.resourceId) && fg('platform_synced_block_patch_1'))) {
|
|
80
84
|
bodiedSyncBlockNodes.push({
|
|
81
85
|
type: 'bodiedSyncBlock',
|
|
82
86
|
attrs: {
|
|
@@ -139,9 +143,14 @@ export class SourceSyncBlockStoreManager {
|
|
|
139
143
|
return false;
|
|
140
144
|
}
|
|
141
145
|
}
|
|
146
|
+
|
|
147
|
+
// Remove this method and pendingResourceId when cleaning up platform_synced_block_patch_1
|
|
142
148
|
registerPendingCreation(resourceId) {
|
|
143
149
|
this.pendingResourceId = resourceId;
|
|
144
150
|
}
|
|
151
|
+
isPendingCreation(resourceId) {
|
|
152
|
+
return this.creationCompletionCallbacks.has(resourceId);
|
|
153
|
+
}
|
|
145
154
|
|
|
146
155
|
/**
|
|
147
156
|
* Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
|
|
@@ -154,25 +163,46 @@ export class SourceSyncBlockStoreManager {
|
|
|
154
163
|
* Fires callback to insert node (if creation is successful) and clears pending creation data
|
|
155
164
|
* @param success
|
|
156
165
|
*/
|
|
157
|
-
commitPendingCreation(success) {
|
|
158
|
-
if (
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
166
|
+
commitPendingCreation(success, resourceId) {
|
|
167
|
+
if (fg('platform_synced_block_patch_1')) {
|
|
168
|
+
const onCompletion = this.creationCompletionCallbacks.get(resourceId);
|
|
169
|
+
if (onCompletion) {
|
|
170
|
+
this.creationCompletionCallbacks.delete(resourceId);
|
|
171
|
+
onCompletion(success);
|
|
172
|
+
} else {
|
|
173
|
+
var _this$fireAnalyticsEv5;
|
|
174
|
+
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, createErrorPayload('creation complete callback missing', resourceId));
|
|
175
|
+
}
|
|
176
|
+
if (success) {
|
|
177
|
+
var _this$fireAnalyticsEv6;
|
|
178
|
+
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, createSuccessPayload(resourceId || ''));
|
|
179
|
+
} else {
|
|
180
|
+
var _this$fireAnalyticsEv7;
|
|
181
|
+
// Delete the node from cache if fail to create so it's not flushed to BE
|
|
182
|
+
this.syncBlockCache.delete(resourceId || '');
|
|
183
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, createErrorPayload('Fail to create bodied sync block', resourceId));
|
|
184
|
+
}
|
|
185
|
+
} else {
|
|
186
|
+
if (success && this.creationCallback) {
|
|
187
|
+
var _this$fireAnalyticsEv8;
|
|
188
|
+
this.creationCallback();
|
|
189
|
+
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, createSuccessPayload(this.pendingResourceId || ''));
|
|
190
|
+
} else if (success && !this.creationCallback) {
|
|
191
|
+
var _this$fireAnalyticsEv9;
|
|
192
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, createErrorPayload('creation callback missing', this.pendingResourceId));
|
|
193
|
+
}
|
|
194
|
+
this.pendingResourceId = undefined;
|
|
165
195
|
}
|
|
166
|
-
this.pendingResourceId = undefined;
|
|
167
196
|
this.creationCallback = undefined;
|
|
168
197
|
}
|
|
169
198
|
|
|
170
199
|
/**
|
|
171
200
|
*
|
|
172
201
|
* @returns true if waiting for the result of saving new bodiedSyncBlock to backend
|
|
202
|
+
* Remove this method when cleaning up platform_synced_block_patch_1
|
|
173
203
|
*/
|
|
174
204
|
hasPendingCreation() {
|
|
175
|
-
return !!this.pendingResourceId;
|
|
205
|
+
return fg('platform_synced_block_patch_1') ? this.creationCompletionCallbacks.size > 0 : !!this.pendingResourceId;
|
|
176
206
|
}
|
|
177
207
|
registerConfirmationCallback(callback) {
|
|
178
208
|
this.confirmationCallback = callback;
|
|
@@ -205,62 +235,69 @@ export class SourceSyncBlockStoreManager {
|
|
|
205
235
|
* Create a bodiedSyncBlock node with empty content to backend
|
|
206
236
|
* @param attrs attributes Ids of the node
|
|
207
237
|
*/
|
|
208
|
-
createBodiedSyncBlockNode(attrs, nodeData) {
|
|
238
|
+
createBodiedSyncBlockNode(attrs, onCompletion, nodeData) {
|
|
239
|
+
const {
|
|
240
|
+
resourceId,
|
|
241
|
+
localId: blockInstanceId
|
|
242
|
+
} = attrs;
|
|
209
243
|
try {
|
|
210
244
|
var _this$createExperienc;
|
|
211
245
|
if (!this.dataProvider) {
|
|
212
246
|
throw new Error('Data provider not set');
|
|
213
247
|
}
|
|
214
|
-
|
|
215
|
-
resourceId,
|
|
216
|
-
|
|
217
|
-
} = attrs;
|
|
248
|
+
if (fg('platform_synced_block_patch_1')) {
|
|
249
|
+
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
250
|
+
}
|
|
218
251
|
(_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 ? void 0 : _this$createExperienc.start({});
|
|
219
252
|
this.dataProvider.createNodeData({
|
|
220
253
|
content: [],
|
|
221
254
|
blockInstanceId,
|
|
222
|
-
resourceId
|
|
255
|
+
resourceId
|
|
223
256
|
}).then(result => {
|
|
224
|
-
const resourceId = result.resourceId;
|
|
225
|
-
if (resourceId) {
|
|
257
|
+
const resourceId = result.resourceId || '';
|
|
258
|
+
if (resourceId && (!fg('platform_synced_block_patch_1') || !result.error)) {
|
|
226
259
|
var _this$createExperienc2;
|
|
227
|
-
this.commitPendingCreation(true);
|
|
260
|
+
this.commitPendingCreation(true, resourceId);
|
|
228
261
|
(_this$createExperienc2 = this.createExperience) === null || _this$createExperienc2 === void 0 ? void 0 : _this$createExperienc2.success();
|
|
229
262
|
|
|
230
263
|
// Update the sync block data with the node data if it is provided
|
|
231
264
|
// to avoid any race conditions where the data could be missed during a render operation
|
|
232
|
-
if (
|
|
233
|
-
|
|
265
|
+
if (!fg('platform_synced_block_patch_1')) {
|
|
266
|
+
if (nodeData) {
|
|
267
|
+
this.updateSyncBlockData(nodeData);
|
|
268
|
+
}
|
|
234
269
|
}
|
|
235
270
|
} else {
|
|
236
|
-
var _this$createExperienc3, _this$
|
|
237
|
-
this.commitPendingCreation(false);
|
|
271
|
+
var _this$createExperienc3, _this$fireAnalyticsEv0;
|
|
272
|
+
this.commitPendingCreation(false, resourceId);
|
|
238
273
|
(_this$createExperienc3 = this.createExperience) === null || _this$createExperienc3 === void 0 ? void 0 : _this$createExperienc3.failure({
|
|
239
274
|
reason: result.error || 'Failed to create bodied sync block'
|
|
240
275
|
});
|
|
241
|
-
(_this$
|
|
276
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, createErrorPayload(result.error || 'Failed to create bodied sync block', resourceId));
|
|
242
277
|
}
|
|
243
278
|
}).catch(error => {
|
|
244
|
-
var _this$createExperienc4, _this$
|
|
245
|
-
this.commitPendingCreation(false);
|
|
279
|
+
var _this$createExperienc4, _this$fireAnalyticsEv1;
|
|
280
|
+
this.commitPendingCreation(false, resourceId);
|
|
246
281
|
logException(error, {
|
|
247
282
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
248
283
|
});
|
|
249
284
|
(_this$createExperienc4 = this.createExperience) === null || _this$createExperienc4 === void 0 ? void 0 : _this$createExperienc4.failure({
|
|
250
285
|
reason: error.message
|
|
251
286
|
});
|
|
252
|
-
(_this$
|
|
287
|
+
(_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, createErrorPayload(error.message, resourceId));
|
|
253
288
|
});
|
|
254
|
-
|
|
289
|
+
if (!fg('platform_synced_block_patch_1')) {
|
|
290
|
+
this.registerPendingCreation(resourceId);
|
|
291
|
+
}
|
|
255
292
|
} catch (error) {
|
|
256
|
-
var _this$
|
|
257
|
-
if (this.hasPendingCreation()) {
|
|
258
|
-
this.commitPendingCreation(false);
|
|
293
|
+
var _this$fireAnalyticsEv10;
|
|
294
|
+
if (fg('platform_synced_block_patch_1') ? this.isPendingCreation(resourceId) : this.hasPendingCreation()) {
|
|
295
|
+
this.commitPendingCreation(false, resourceId);
|
|
259
296
|
}
|
|
260
297
|
logException(error, {
|
|
261
298
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
262
299
|
});
|
|
263
|
-
(_this$
|
|
300
|
+
(_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, createErrorPayload(error.message));
|
|
264
301
|
}
|
|
265
302
|
}
|
|
266
303
|
async delete(syncBlockIds, onDelete, onDeleteCompleted, reason) {
|
|
@@ -284,8 +321,8 @@ export class SourceSyncBlockStoreManager {
|
|
|
284
321
|
this.clearPendingDeletion();
|
|
285
322
|
(_this$deleteExperienc2 = this.deleteExperience) === null || _this$deleteExperienc2 === void 0 ? void 0 : _this$deleteExperienc2.success();
|
|
286
323
|
results.forEach(result => {
|
|
287
|
-
var _this$
|
|
288
|
-
(_this$
|
|
324
|
+
var _this$fireAnalyticsEv11;
|
|
325
|
+
(_this$fireAnalyticsEv11 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv11 === void 0 ? void 0 : _this$fireAnalyticsEv11.call(this, deleteSuccessPayload(result.resourceId));
|
|
289
326
|
});
|
|
290
327
|
} else {
|
|
291
328
|
var _this$deleteExperienc3;
|
|
@@ -295,11 +332,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
295
332
|
(_this$deleteExperienc3 = this.deleteExperience) === null || _this$deleteExperienc3 === void 0 ? void 0 : _this$deleteExperienc3.failure();
|
|
296
333
|
results.forEach(result => {
|
|
297
334
|
if (result.success) {
|
|
298
|
-
var _this$
|
|
299
|
-
(_this$
|
|
335
|
+
var _this$fireAnalyticsEv12;
|
|
336
|
+
(_this$fireAnalyticsEv12 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv12 === void 0 ? void 0 : _this$fireAnalyticsEv12.call(this, deleteSuccessPayload(result.resourceId));
|
|
300
337
|
} else {
|
|
301
|
-
var _this$
|
|
302
|
-
(_this$
|
|
338
|
+
var _this$fireAnalyticsEv13;
|
|
339
|
+
(_this$fireAnalyticsEv13 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv13 === void 0 ? void 0 : _this$fireAnalyticsEv13.call(this, deleteErrorPayload(result.error || 'Failed to delete synced block', result.resourceId));
|
|
303
340
|
}
|
|
304
341
|
});
|
|
305
342
|
}
|
|
@@ -307,9 +344,9 @@ export class SourceSyncBlockStoreManager {
|
|
|
307
344
|
return isDeleteSuccessful;
|
|
308
345
|
} catch (error) {
|
|
309
346
|
syncBlockIds.forEach(Ids => {
|
|
310
|
-
var _this$
|
|
347
|
+
var _this$fireAnalyticsEv14;
|
|
311
348
|
this.setPendingDeletion(Ids, false);
|
|
312
|
-
(_this$
|
|
349
|
+
(_this$fireAnalyticsEv14 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv14 === void 0 ? void 0 : _this$fireAnalyticsEv14.call(this, deleteErrorPayload(error.message, Ids.resourceId));
|
|
313
350
|
});
|
|
314
351
|
logException(error, {
|
|
315
352
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
@@ -390,11 +427,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
390
427
|
return sourceInfo;
|
|
391
428
|
});
|
|
392
429
|
} catch (error) {
|
|
393
|
-
var _this$
|
|
430
|
+
var _this$fireAnalyticsEv15;
|
|
394
431
|
logException(error, {
|
|
395
432
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
396
433
|
});
|
|
397
|
-
(_this$
|
|
434
|
+
(_this$fireAnalyticsEv15 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv15 === void 0 ? void 0 : _this$fireAnalyticsEv15.call(this, getSourceInfoErrorPayload(error.message));
|
|
398
435
|
return Promise.resolve(undefined);
|
|
399
436
|
}
|
|
400
437
|
}
|
|
@@ -405,11 +442,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
405
442
|
}
|
|
406
443
|
return this.dataProvider.fetchReferences(resourceId, true);
|
|
407
444
|
} catch (error) {
|
|
408
|
-
var _this$
|
|
445
|
+
var _this$fireAnalyticsEv16;
|
|
409
446
|
logException(error, {
|
|
410
447
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
411
448
|
});
|
|
412
|
-
(_this$
|
|
449
|
+
(_this$fireAnalyticsEv16 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv16 === void 0 ? void 0 : _this$fireAnalyticsEv16.call(this, fetchReferencesErrorPayload(error.message));
|
|
413
450
|
return Promise.resolve({
|
|
414
451
|
error: SyncBlockError.Errored
|
|
415
452
|
});
|
|
@@ -420,6 +457,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
420
457
|
this.syncBlockCache.clear();
|
|
421
458
|
this.confirmationCallback = undefined;
|
|
422
459
|
this.pendingResourceId = undefined;
|
|
460
|
+
this.creationCompletionCallbacks.clear();
|
|
423
461
|
this.creationCallback = undefined;
|
|
424
462
|
this.dataProvider = undefined;
|
|
425
463
|
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 ? void 0 : _this$saveExperience4.abort({
|
|
@@ -6,6 +6,7 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
|
6
6
|
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; }
|
|
7
7
|
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; }
|
|
8
8
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
9
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
10
|
import { SyncBlockError } from '../common/types';
|
|
10
11
|
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload, fetchReferencesErrorPayload } from '../utils/errorHandling';
|
|
11
12
|
import { getCreateSourceExperience, getDeleteSourceExperience, getSaveSourceExperience, getFetchSourceInfoExperience } from '../utils/experienceTracking';
|
|
@@ -27,6 +28,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
27
28
|
});
|
|
28
29
|
this.dataProvider = dataProvider;
|
|
29
30
|
this.syncBlockCache = new Map();
|
|
31
|
+
this.creationCompletionCallbacks = new Map();
|
|
30
32
|
}
|
|
31
33
|
return _createClass(SourceSyncBlockStoreManager, [{
|
|
32
34
|
key: "setFireAnalyticsEvent",
|
|
@@ -93,9 +95,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
93
95
|
bodiedSyncBlockNodes = [];
|
|
94
96
|
bodiedSyncBlockData = [];
|
|
95
97
|
Array.from(this.syncBlockCache.values()).forEach(function (syncBlockData) {
|
|
96
|
-
// Don't flush nodes that
|
|
97
|
-
//
|
|
98
|
-
|
|
98
|
+
// Don't flush nodes that
|
|
99
|
+
// - are waiting to be deleted to avoid nodes being re-created
|
|
100
|
+
// - haven't been updated since we last flushed
|
|
101
|
+
// - are still pending BE creation
|
|
102
|
+
if (!syncBlockData.pendingDeletion && syncBlockData.isDirty && !(_this2.isPendingCreation(syncBlockData.resourceId) && fg('platform_synced_block_patch_1'))) {
|
|
99
103
|
bodiedSyncBlockNodes.push({
|
|
100
104
|
type: 'bodiedSyncBlock',
|
|
101
105
|
attrs: {
|
|
@@ -183,12 +187,18 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
183
187
|
return _flush.apply(this, arguments);
|
|
184
188
|
}
|
|
185
189
|
return flush;
|
|
186
|
-
}()
|
|
190
|
+
}() // Remove this method and pendingResourceId when cleaning up platform_synced_block_patch_1
|
|
191
|
+
)
|
|
187
192
|
}, {
|
|
188
193
|
key: "registerPendingCreation",
|
|
189
194
|
value: function registerPendingCreation(resourceId) {
|
|
190
195
|
this.pendingResourceId = resourceId;
|
|
191
196
|
}
|
|
197
|
+
}, {
|
|
198
|
+
key: "isPendingCreation",
|
|
199
|
+
value: function isPendingCreation(resourceId) {
|
|
200
|
+
return this.creationCompletionCallbacks.has(resourceId);
|
|
201
|
+
}
|
|
192
202
|
|
|
193
203
|
/**
|
|
194
204
|
* Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
|
|
@@ -205,27 +215,48 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
205
215
|
*/
|
|
206
216
|
}, {
|
|
207
217
|
key: "commitPendingCreation",
|
|
208
|
-
value: function commitPendingCreation(success) {
|
|
209
|
-
if (
|
|
210
|
-
var
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
218
|
+
value: function commitPendingCreation(success, resourceId) {
|
|
219
|
+
if (fg('platform_synced_block_patch_1')) {
|
|
220
|
+
var onCompletion = this.creationCompletionCallbacks.get(resourceId);
|
|
221
|
+
if (onCompletion) {
|
|
222
|
+
this.creationCompletionCallbacks.delete(resourceId);
|
|
223
|
+
onCompletion(success);
|
|
224
|
+
} else {
|
|
225
|
+
var _this$fireAnalyticsEv3;
|
|
226
|
+
(_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, createErrorPayload('creation complete callback missing', resourceId));
|
|
227
|
+
}
|
|
228
|
+
if (success) {
|
|
229
|
+
var _this$fireAnalyticsEv4;
|
|
230
|
+
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, createSuccessPayload(resourceId || ''));
|
|
231
|
+
} else {
|
|
232
|
+
var _this$fireAnalyticsEv5;
|
|
233
|
+
// Delete the node from cache if fail to create so it's not flushed to BE
|
|
234
|
+
this.syncBlockCache.delete(resourceId || '');
|
|
235
|
+
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, createErrorPayload('Fail to create bodied sync block', resourceId));
|
|
236
|
+
}
|
|
237
|
+
} else {
|
|
238
|
+
if (success && this.creationCallback) {
|
|
239
|
+
var _this$fireAnalyticsEv6;
|
|
240
|
+
this.creationCallback();
|
|
241
|
+
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, createSuccessPayload(this.pendingResourceId || ''));
|
|
242
|
+
} else if (success && !this.creationCallback) {
|
|
243
|
+
var _this$fireAnalyticsEv7;
|
|
244
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, createErrorPayload('creation callback missing', this.pendingResourceId));
|
|
245
|
+
}
|
|
246
|
+
this.pendingResourceId = undefined;
|
|
216
247
|
}
|
|
217
|
-
this.pendingResourceId = undefined;
|
|
218
248
|
this.creationCallback = undefined;
|
|
219
249
|
}
|
|
220
250
|
|
|
221
251
|
/**
|
|
222
252
|
*
|
|
223
253
|
* @returns true if waiting for the result of saving new bodiedSyncBlock to backend
|
|
254
|
+
* Remove this method when cleaning up platform_synced_block_patch_1
|
|
224
255
|
*/
|
|
225
256
|
}, {
|
|
226
257
|
key: "hasPendingCreation",
|
|
227
258
|
value: function hasPendingCreation() {
|
|
228
|
-
return !!this.pendingResourceId;
|
|
259
|
+
return fg('platform_synced_block_patch_1') ? this.creationCompletionCallbacks.size > 0 : !!this.pendingResourceId;
|
|
229
260
|
}
|
|
230
261
|
}, {
|
|
231
262
|
key: "registerConfirmationCallback",
|
|
@@ -266,35 +297,40 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
266
297
|
*/
|
|
267
298
|
}, {
|
|
268
299
|
key: "createBodiedSyncBlockNode",
|
|
269
|
-
value: function createBodiedSyncBlockNode(attrs, nodeData) {
|
|
300
|
+
value: function createBodiedSyncBlockNode(attrs, onCompletion, nodeData) {
|
|
270
301
|
var _this4 = this;
|
|
302
|
+
var resourceId = attrs.resourceId,
|
|
303
|
+
blockInstanceId = attrs.localId;
|
|
271
304
|
try {
|
|
272
305
|
var _this$createExperienc;
|
|
273
306
|
if (!this.dataProvider) {
|
|
274
307
|
throw new Error('Data provider not set');
|
|
275
308
|
}
|
|
276
|
-
|
|
277
|
-
|
|
309
|
+
if (fg('platform_synced_block_patch_1')) {
|
|
310
|
+
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
311
|
+
}
|
|
278
312
|
(_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 || _this$createExperienc.start({});
|
|
279
313
|
this.dataProvider.createNodeData({
|
|
280
314
|
content: [],
|
|
281
315
|
blockInstanceId: blockInstanceId,
|
|
282
316
|
resourceId: resourceId
|
|
283
317
|
}).then(function (result) {
|
|
284
|
-
var resourceId = result.resourceId;
|
|
285
|
-
if (resourceId) {
|
|
318
|
+
var resourceId = result.resourceId || '';
|
|
319
|
+
if (resourceId && (!fg('platform_synced_block_patch_1') || !result.error)) {
|
|
286
320
|
var _this4$createExperien;
|
|
287
|
-
_this4.commitPendingCreation(true);
|
|
321
|
+
_this4.commitPendingCreation(true, resourceId);
|
|
288
322
|
(_this4$createExperien = _this4.createExperience) === null || _this4$createExperien === void 0 || _this4$createExperien.success();
|
|
289
323
|
|
|
290
324
|
// Update the sync block data with the node data if it is provided
|
|
291
325
|
// to avoid any race conditions where the data could be missed during a render operation
|
|
292
|
-
if (
|
|
293
|
-
|
|
326
|
+
if (!fg('platform_synced_block_patch_1')) {
|
|
327
|
+
if (nodeData) {
|
|
328
|
+
_this4.updateSyncBlockData(nodeData);
|
|
329
|
+
}
|
|
294
330
|
}
|
|
295
331
|
} else {
|
|
296
332
|
var _this4$createExperien2, _this4$fireAnalyticsE;
|
|
297
|
-
_this4.commitPendingCreation(false);
|
|
333
|
+
_this4.commitPendingCreation(false, resourceId);
|
|
298
334
|
(_this4$createExperien2 = _this4.createExperience) === null || _this4$createExperien2 === void 0 || _this4$createExperien2.failure({
|
|
299
335
|
reason: result.error || 'Failed to create bodied sync block'
|
|
300
336
|
});
|
|
@@ -302,7 +338,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
302
338
|
}
|
|
303
339
|
}).catch(function (error) {
|
|
304
340
|
var _this4$createExperien3, _this4$fireAnalyticsE2;
|
|
305
|
-
_this4.commitPendingCreation(false);
|
|
341
|
+
_this4.commitPendingCreation(false, resourceId);
|
|
306
342
|
logException(error, {
|
|
307
343
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
308
344
|
});
|
|
@@ -311,16 +347,18 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
311
347
|
});
|
|
312
348
|
(_this4$fireAnalyticsE2 = _this4.fireAnalyticsEvent) === null || _this4$fireAnalyticsE2 === void 0 || _this4$fireAnalyticsE2.call(_this4, createErrorPayload(error.message, resourceId));
|
|
313
349
|
});
|
|
314
|
-
|
|
350
|
+
if (!fg('platform_synced_block_patch_1')) {
|
|
351
|
+
this.registerPendingCreation(resourceId);
|
|
352
|
+
}
|
|
315
353
|
} catch (error) {
|
|
316
|
-
var _this$
|
|
317
|
-
if (this.hasPendingCreation()) {
|
|
318
|
-
this.commitPendingCreation(false);
|
|
354
|
+
var _this$fireAnalyticsEv8;
|
|
355
|
+
if (fg('platform_synced_block_patch_1') ? this.isPendingCreation(resourceId) : this.hasPendingCreation()) {
|
|
356
|
+
this.commitPendingCreation(false, resourceId);
|
|
319
357
|
}
|
|
320
358
|
logException(error, {
|
|
321
359
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
322
360
|
});
|
|
323
|
-
(_this$
|
|
361
|
+
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 || _this$fireAnalyticsEv8.call(this, createErrorPayload(error.message));
|
|
324
362
|
}
|
|
325
363
|
}
|
|
326
364
|
}, {
|
|
@@ -531,11 +569,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
531
569
|
return sourceInfo;
|
|
532
570
|
});
|
|
533
571
|
} catch (error) {
|
|
534
|
-
var _this$
|
|
572
|
+
var _this$fireAnalyticsEv9;
|
|
535
573
|
logException(error, {
|
|
536
574
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
537
575
|
});
|
|
538
|
-
(_this$
|
|
576
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 || _this$fireAnalyticsEv9.call(this, getSourceInfoErrorPayload(error.message));
|
|
539
577
|
return Promise.resolve(undefined);
|
|
540
578
|
}
|
|
541
579
|
}
|
|
@@ -548,11 +586,11 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
548
586
|
}
|
|
549
587
|
return this.dataProvider.fetchReferences(resourceId, true);
|
|
550
588
|
} catch (error) {
|
|
551
|
-
var _this$
|
|
589
|
+
var _this$fireAnalyticsEv0;
|
|
552
590
|
logException(error, {
|
|
553
591
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
554
592
|
});
|
|
555
|
-
(_this$
|
|
593
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 || _this$fireAnalyticsEv0.call(this, fetchReferencesErrorPayload(error.message));
|
|
556
594
|
return Promise.resolve({
|
|
557
595
|
error: SyncBlockError.Errored
|
|
558
596
|
});
|
|
@@ -565,6 +603,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
565
603
|
this.syncBlockCache.clear();
|
|
566
604
|
this.confirmationCallback = undefined;
|
|
567
605
|
this.pendingResourceId = undefined;
|
|
606
|
+
this.creationCompletionCallbacks.clear();
|
|
568
607
|
this.creationCallback = undefined;
|
|
569
608
|
this.dataProvider = undefined;
|
|
570
609
|
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 || _this$saveExperience4.abort({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import {
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import { type ResourceId, type SyncBlockAttrs, type BlockInstanceId, type DeletionReason, type ReferenceSyncBlockData } from '../common/types';
|
|
4
4
|
import type { SyncBlockDataProvider, SyncBlockSourceInfo } from '../providers/types';
|
|
5
5
|
export type ConfirmationCallback = (syncBlockIds: SyncBlockAttrs[], deleteReason: DeletionReason | undefined) => Promise<boolean>;
|
|
6
6
|
type OnDelete = () => void;
|
|
7
|
-
type
|
|
7
|
+
type OnCompletion = (success: boolean) => void;
|
|
8
8
|
type DestroyCallback = () => void;
|
|
9
9
|
export type CreationCallback = () => void;
|
|
10
10
|
export declare class SourceSyncBlockStoreManager {
|
|
@@ -15,6 +15,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
15
15
|
private deletionRetryInfo?;
|
|
16
16
|
private pendingResourceId?;
|
|
17
17
|
private creationCallback?;
|
|
18
|
+
private creationCompletionCallbacks;
|
|
18
19
|
private createExperience;
|
|
19
20
|
private saveExperience;
|
|
20
21
|
private deleteExperience;
|
|
@@ -34,6 +35,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
34
35
|
*/
|
|
35
36
|
flush(): Promise<boolean>;
|
|
36
37
|
registerPendingCreation(resourceId: ResourceId): void;
|
|
38
|
+
isPendingCreation(resourceId: ResourceId): boolean;
|
|
37
39
|
/**
|
|
38
40
|
* Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
|
|
39
41
|
*/
|
|
@@ -42,10 +44,11 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
42
44
|
* Fires callback to insert node (if creation is successful) and clears pending creation data
|
|
43
45
|
* @param success
|
|
44
46
|
*/
|
|
45
|
-
commitPendingCreation(success: boolean): void;
|
|
47
|
+
commitPendingCreation(success: boolean, resourceId: ResourceId): void;
|
|
46
48
|
/**
|
|
47
49
|
*
|
|
48
50
|
* @returns true if waiting for the result of saving new bodiedSyncBlock to backend
|
|
51
|
+
* Remove this method when cleaning up platform_synced_block_patch_1
|
|
49
52
|
*/
|
|
50
53
|
hasPendingCreation(): boolean;
|
|
51
54
|
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
@@ -58,7 +61,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
58
61
|
* Create a bodiedSyncBlock node with empty content to backend
|
|
59
62
|
* @param attrs attributes Ids of the node
|
|
60
63
|
*/
|
|
61
|
-
createBodiedSyncBlockNode(attrs: SyncBlockAttrs, nodeData?: PMNode): void;
|
|
64
|
+
createBodiedSyncBlockNode(attrs: SyncBlockAttrs, onCompletion: OnCompletion, nodeData?: PMNode): void;
|
|
62
65
|
private setPendingDeletion;
|
|
63
66
|
private delete;
|
|
64
67
|
isRetryingDeletion(): boolean;
|
|
@@ -71,7 +74,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
71
74
|
* @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
|
|
72
75
|
* @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
|
|
73
76
|
*/
|
|
74
|
-
deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], deletionReason: DeletionReason, onDelete: OnDelete, onDeleteCompleted:
|
|
77
|
+
deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], deletionReason: DeletionReason, onDelete: OnDelete, onDeleteCompleted: OnCompletion, destroyCallback: DestroyCallback): Promise<void>;
|
|
75
78
|
getSyncBlockSourceInfo(localId: BlockInstanceId): Promise<SyncBlockSourceInfo | undefined>;
|
|
76
79
|
fetchReferences(resourceId: string): Promise<ReferenceSyncBlockData>;
|
|
77
80
|
destroy(): void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type SyncBlockEventPayload } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import {
|
|
2
|
+
import type { Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import { type ResourceId, type SyncBlockAttrs, type BlockInstanceId, type DeletionReason, type ReferenceSyncBlockData } from '../common/types';
|
|
4
4
|
import type { SyncBlockDataProvider, SyncBlockSourceInfo } from '../providers/types';
|
|
5
5
|
export type ConfirmationCallback = (syncBlockIds: SyncBlockAttrs[], deleteReason: DeletionReason | undefined) => Promise<boolean>;
|
|
6
6
|
type OnDelete = () => void;
|
|
7
|
-
type
|
|
7
|
+
type OnCompletion = (success: boolean) => void;
|
|
8
8
|
type DestroyCallback = () => void;
|
|
9
9
|
export type CreationCallback = () => void;
|
|
10
10
|
export declare class SourceSyncBlockStoreManager {
|
|
@@ -15,6 +15,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
15
15
|
private deletionRetryInfo?;
|
|
16
16
|
private pendingResourceId?;
|
|
17
17
|
private creationCallback?;
|
|
18
|
+
private creationCompletionCallbacks;
|
|
18
19
|
private createExperience;
|
|
19
20
|
private saveExperience;
|
|
20
21
|
private deleteExperience;
|
|
@@ -34,6 +35,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
34
35
|
*/
|
|
35
36
|
flush(): Promise<boolean>;
|
|
36
37
|
registerPendingCreation(resourceId: ResourceId): void;
|
|
38
|
+
isPendingCreation(resourceId: ResourceId): boolean;
|
|
37
39
|
/**
|
|
38
40
|
* Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
|
|
39
41
|
*/
|
|
@@ -42,10 +44,11 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
42
44
|
* Fires callback to insert node (if creation is successful) and clears pending creation data
|
|
43
45
|
* @param success
|
|
44
46
|
*/
|
|
45
|
-
commitPendingCreation(success: boolean): void;
|
|
47
|
+
commitPendingCreation(success: boolean, resourceId: ResourceId): void;
|
|
46
48
|
/**
|
|
47
49
|
*
|
|
48
50
|
* @returns true if waiting for the result of saving new bodiedSyncBlock to backend
|
|
51
|
+
* Remove this method when cleaning up platform_synced_block_patch_1
|
|
49
52
|
*/
|
|
50
53
|
hasPendingCreation(): boolean;
|
|
51
54
|
registerConfirmationCallback(callback: ConfirmationCallback): () => void;
|
|
@@ -58,7 +61,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
58
61
|
* Create a bodiedSyncBlock node with empty content to backend
|
|
59
62
|
* @param attrs attributes Ids of the node
|
|
60
63
|
*/
|
|
61
|
-
createBodiedSyncBlockNode(attrs: SyncBlockAttrs, nodeData?: PMNode): void;
|
|
64
|
+
createBodiedSyncBlockNode(attrs: SyncBlockAttrs, onCompletion: OnCompletion, nodeData?: PMNode): void;
|
|
62
65
|
private setPendingDeletion;
|
|
63
66
|
private delete;
|
|
64
67
|
isRetryingDeletion(): boolean;
|
|
@@ -71,7 +74,7 @@ export declare class SourceSyncBlockStoreManager {
|
|
|
71
74
|
* @param onDeleteCompleted - The callback for after the deletion is saved to BE (whether successful or not)
|
|
72
75
|
* @param destroyCallback - The callback to clear any reference stored for deletion (regardless if deletion is completed or abort)
|
|
73
76
|
*/
|
|
74
|
-
deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], deletionReason: DeletionReason, onDelete: OnDelete, onDeleteCompleted:
|
|
77
|
+
deleteSyncBlocksWithConfirmation(syncBlockIds: SyncBlockAttrs[], deletionReason: DeletionReason, onDelete: OnDelete, onDeleteCompleted: OnCompletion, destroyCallback: DestroyCallback): Promise<void>;
|
|
75
78
|
getSyncBlockSourceInfo(localId: BlockInstanceId): Promise<SyncBlockSourceInfo | undefined>;
|
|
76
79
|
fetchReferences(resourceId: string): Promise<ReferenceSyncBlockData>;
|
|
77
80
|
destroy(): void;
|
package/package.json
CHANGED