@atlaskit/editor-synced-block-provider 3.14.1 → 3.14.3
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 +22 -0
- package/dist/cjs/clients/block-service/blockService.js +21 -16
- package/dist/cjs/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/cjs/providers/block-service/blockServiceAPI.js +75 -36
- package/dist/cjs/providers/syncBlockProvider.js +10 -6
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +65 -26
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +68 -28
- package/dist/cjs/store-manager/syncBlockStoreManager.js +54 -23
- package/dist/cjs/utils/experienceTracking.js +18 -1
- package/dist/cjs/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/es2019/clients/block-service/blockService.js +10 -3
- package/dist/es2019/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +62 -23
- package/dist/es2019/providers/syncBlockProvider.js +8 -4
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +71 -36
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +55 -17
- package/dist/es2019/store-manager/syncBlockStoreManager.js +37 -3
- package/dist/es2019/utils/experienceTracking.js +17 -0
- package/dist/es2019/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/esm/clients/block-service/blockService.js +21 -16
- package/dist/esm/hooks/useFetchSyncBlockData.js +3 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +75 -36
- package/dist/esm/providers/syncBlockProvider.js +10 -6
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +65 -26
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +70 -30
- package/dist/esm/store-manager/syncBlockStoreManager.js +54 -23
- package/dist/esm/utils/experienceTracking.js +17 -0
- package/dist/esm/utils/resolveSyncBlockInstance.js +2 -1
- package/dist/types/clients/block-service/blockService.d.ts +7 -4
- package/dist/types/common/types.d.ts +4 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +6 -3
- package/dist/types/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types/providers/types.d.ts +8 -4
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +9 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +5 -3
- package/dist/types/store-manager/syncBlockStoreManager.d.ts +2 -0
- package/dist/types/utils/experienceTracking.d.ts +8 -0
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +7 -4
- package/dist/types-ts4.5/common/types.d.ts +4 -0
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +6 -3
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types-ts4.5/providers/types.d.ts +8 -4
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +9 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +5 -3
- package/dist/types-ts4.5/store-manager/syncBlockStoreManager.d.ts +2 -0
- package/dist/types-ts4.5/utils/experienceTracking.d.ts +8 -0
- package/package.json +2 -2
|
@@ -27,6 +27,10 @@ import { createSyncBlockNode } from '../utils/utils';
|
|
|
27
27
|
export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
28
28
|
// Listeners for subscription changes (used by React components to know when to update)
|
|
29
29
|
|
|
30
|
+
// Track newly added sync blocks (resourceIds that were just subscribed to without cached data)
|
|
31
|
+
|
|
32
|
+
// Callback to notify when an unpublished sync block is detected
|
|
33
|
+
|
|
30
34
|
function ReferenceSyncBlockStoreManager(dataProvider) {
|
|
31
35
|
_classCallCheck(this, ReferenceSyncBlockStoreManager);
|
|
32
36
|
// Keeps track of addition and deletion of reference synced blocks on the document
|
|
@@ -47,6 +51,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
47
51
|
this.pendingCacheDeletions = new Map();
|
|
48
52
|
this.graphqlSubscriptions = new Map();
|
|
49
53
|
this.subscriptionChangeListeners = new Set();
|
|
54
|
+
this.newlyAddedSyncBlocks = new Set();
|
|
50
55
|
}
|
|
51
56
|
|
|
52
57
|
/**
|
|
@@ -151,6 +156,22 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
151
156
|
this.fetchSourceInfoExperience = getFetchSourceInfoExperience(fireAnalyticsEvent);
|
|
152
157
|
this.saveExperience = getSaveReferenceExperience(fireAnalyticsEvent);
|
|
153
158
|
}
|
|
159
|
+
}, {
|
|
160
|
+
key: "setOnUnpublishedSyncBlockDetected",
|
|
161
|
+
value: function setOnUnpublishedSyncBlockDetected(callback) {
|
|
162
|
+
this.onUnpublishedSyncBlockDetected = callback;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* Mark a sync block as newly added to the document.
|
|
167
|
+
* This should be called when a sync block node is added via a transaction.
|
|
168
|
+
* @param resourceId - The resource ID of the newly added sync block
|
|
169
|
+
*/
|
|
170
|
+
}, {
|
|
171
|
+
key: "markAsNewlyAdded",
|
|
172
|
+
value: function markAsNewlyAdded(resourceId) {
|
|
173
|
+
this.newlyAddedSyncBlocks.add(resourceId);
|
|
174
|
+
}
|
|
154
175
|
}, {
|
|
155
176
|
key: "generateResourceIdForReference",
|
|
156
177
|
value: function generateResourceIdForReference(sourceId) {
|
|
@@ -306,13 +327,18 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
306
327
|
key: "handleGraphQLSubscriptionUpdate",
|
|
307
328
|
value: function handleGraphQLSubscriptionUpdate(syncBlockInstance) {
|
|
308
329
|
if (!syncBlockInstance.resourceId) {
|
|
309
|
-
|
|
330
|
+
throw new Error('Sync block instance provided to graphql subscription update missing resource id');
|
|
310
331
|
}
|
|
311
332
|
var existingSyncBlock = this.getFromCache(syncBlockInstance.resourceId);
|
|
312
333
|
var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
313
334
|
this.updateCache(resolvedSyncBlockInstance);
|
|
314
335
|
if (!syncBlockInstance.error) {
|
|
336
|
+
var _this$fireAnalyticsEv2, _syncBlockInstance$da, _syncBlockInstance$da2;
|
|
337
|
+
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, fetchSuccessPayload(syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.resourceId, syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da = syncBlockInstance.data) === null || _syncBlockInstance$da === void 0 ? void 0 : _syncBlockInstance$da.blockInstanceId, syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$da2 = syncBlockInstance.data) === null || _syncBlockInstance$da2 === void 0 ? void 0 : _syncBlockInstance$da2.product));
|
|
315
338
|
this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
339
|
+
} else {
|
|
340
|
+
var _this$fireAnalyticsEv3, _syncBlockInstance$er;
|
|
341
|
+
(_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(this, fetchErrorPayload((_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.type, syncBlockInstance.resourceId));
|
|
316
342
|
}
|
|
317
343
|
}
|
|
318
344
|
|
|
@@ -414,8 +440,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
414
440
|
}
|
|
415
441
|
}
|
|
416
442
|
if (!sourceAri || !product || !blockInstanceId) {
|
|
417
|
-
var _this$
|
|
418
|
-
(_this$
|
|
443
|
+
var _this$fireAnalyticsEv4;
|
|
444
|
+
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
|
|
419
445
|
return Promise.resolve(undefined);
|
|
420
446
|
}
|
|
421
447
|
if (fg('platform_synced_block_dogfooding')) {
|
|
@@ -474,11 +500,11 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
474
500
|
this.syncBlockSourceInfoRequestsOld.set(resourceId, true);
|
|
475
501
|
}
|
|
476
502
|
} catch (error) {
|
|
477
|
-
var _this$
|
|
503
|
+
var _this$fireAnalyticsEv5;
|
|
478
504
|
logException(error, {
|
|
479
505
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
480
506
|
});
|
|
481
|
-
(_this$
|
|
507
|
+
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 || _this$fireAnalyticsEv5.call(this, getSourceInfoErrorPayload(error.message, resourceId));
|
|
482
508
|
}
|
|
483
509
|
return Promise.resolve(undefined);
|
|
484
510
|
}
|
|
@@ -506,11 +532,12 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
506
532
|
// Don't fetch for not_found error since the source is already deleted
|
|
507
533
|
nodesToFetch = [];
|
|
508
534
|
syncBlockNodes.forEach(function (node) {
|
|
535
|
+
var _existingSyncBlock$er;
|
|
509
536
|
if (_this5.syncBlockFetchDataRequests.get(node.attrs.resourceId)) {
|
|
510
537
|
return;
|
|
511
538
|
}
|
|
512
539
|
var existingSyncBlock = _this5.getFromCache(node.attrs.resourceId);
|
|
513
|
-
if ((existingSyncBlock === null || existingSyncBlock === void 0 ? void 0 :
|
|
540
|
+
if ((existingSyncBlock === null || existingSyncBlock === void 0 || (_existingSyncBlock$er = existingSyncBlock.error) === null || _existingSyncBlock$er === void 0 ? void 0 : _existingSyncBlock$er.type) === SyncBlockError.NotFound) {
|
|
514
541
|
return;
|
|
515
542
|
}
|
|
516
543
|
nodesToFetch.push(node);
|
|
@@ -544,26 +571,38 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
544
571
|
hasUnexpectedError = false;
|
|
545
572
|
hasExpectedError = false;
|
|
546
573
|
data.forEach(function (syncBlockInstance) {
|
|
574
|
+
var _resolvedSyncBlockIns;
|
|
547
575
|
if (!syncBlockInstance.resourceId) {
|
|
548
|
-
var _this5$fireAnalyticsE;
|
|
549
|
-
(_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
|
|
576
|
+
var _this5$fireAnalyticsE, _syncBlockInstance$er2;
|
|
577
|
+
(_this5$fireAnalyticsE = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE === void 0 || _this5$fireAnalyticsE.call(_this5, fetchErrorPayload(((_syncBlockInstance$er2 = syncBlockInstance.error) === null || _syncBlockInstance$er2 === void 0 ? void 0 : _syncBlockInstance$er2.type) || 'Returned sync block instance does not have resource id'));
|
|
550
578
|
return;
|
|
551
579
|
}
|
|
552
580
|
var existingSyncBlock = _this5.getFromCache(syncBlockInstance.resourceId);
|
|
553
581
|
var resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
|
|
554
582
|
_this5.updateCache(resolvedSyncBlockInstance);
|
|
583
|
+
|
|
584
|
+
// Check if this is a newly added unpublished sync block and notify
|
|
585
|
+
// Only trigger for sync blocks that were just added (not refreshed or loaded on page init)
|
|
586
|
+
if (!syncBlockInstance.error && ((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) === null || _resolvedSyncBlockIns === void 0 ? void 0 : _resolvedSyncBlockIns.status) === 'unpublished' && _this5.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId) && _this5.onUnpublishedSyncBlockDetected && fg('platform_synced_block_dogfooding')) {
|
|
587
|
+
// Remove from newly added set after checking to prevent duplicate flags
|
|
588
|
+
_this5.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
|
|
589
|
+
_this5.onUnpublishedSyncBlockDetected(resolvedSyncBlockInstance.resourceId);
|
|
590
|
+
} else if (_this5.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId)) {
|
|
591
|
+
// Remove from newly added set even if not unpublished (to clean up)
|
|
592
|
+
_this5.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
|
|
593
|
+
}
|
|
555
594
|
if (syncBlockInstance.error) {
|
|
556
595
|
var _this5$fireAnalyticsE2;
|
|
557
|
-
(_this5$fireAnalyticsE2 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE2 === void 0 || _this5$fireAnalyticsE2.call(_this5, fetchErrorPayload(syncBlockInstance.error, syncBlockInstance.resourceId));
|
|
558
|
-
if (syncBlockInstance.error === SyncBlockError.NotFound || syncBlockInstance.error === SyncBlockError.Forbidden) {
|
|
596
|
+
(_this5$fireAnalyticsE2 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE2 === void 0 || _this5$fireAnalyticsE2.call(_this5, fetchErrorPayload(syncBlockInstance.error.type, syncBlockInstance.resourceId));
|
|
597
|
+
if (syncBlockInstance.error.type === SyncBlockError.NotFound || syncBlockInstance.error.type === SyncBlockError.Forbidden) {
|
|
559
598
|
hasExpectedError = true;
|
|
560
599
|
} else if (syncBlockInstance.error) {
|
|
561
600
|
hasUnexpectedError = true;
|
|
562
601
|
}
|
|
563
602
|
return;
|
|
564
603
|
} else if (fg('platform_synced_block_dogfooding')) {
|
|
565
|
-
var _this5$fireAnalyticsE3, _syncBlockInstance$
|
|
566
|
-
(_this5$fireAnalyticsE3 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE3 === void 0 || _this5$fireAnalyticsE3.call(_this5, fetchSuccessPayload(syncBlockInstance.resourceId, (_syncBlockInstance$
|
|
604
|
+
var _this5$fireAnalyticsE3, _syncBlockInstance$da3, _syncBlockInstance$da4;
|
|
605
|
+
(_this5$fireAnalyticsE3 = _this5.fireAnalyticsEvent) === null || _this5$fireAnalyticsE3 === void 0 || _this5$fireAnalyticsE3.call(_this5, fetchSuccessPayload(syncBlockInstance.resourceId, (_syncBlockInstance$da3 = syncBlockInstance.data) === null || _syncBlockInstance$da3 === void 0 ? void 0 : _syncBlockInstance$da3.blockInstanceId, (_syncBlockInstance$da4 = syncBlockInstance.data) === null || _syncBlockInstance$da4 === void 0 ? void 0 : _syncBlockInstance$da4.product));
|
|
567
606
|
}
|
|
568
607
|
_this5.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
569
608
|
});
|
|
@@ -774,11 +813,11 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
774
813
|
}
|
|
775
814
|
return this.subscribeToSyncBlock(resourceId, localId, callback);
|
|
776
815
|
} catch (error) {
|
|
777
|
-
var _this$
|
|
816
|
+
var _this$fireAnalyticsEv6;
|
|
778
817
|
logException(error, {
|
|
779
818
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
780
819
|
});
|
|
781
|
-
(_this$
|
|
820
|
+
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 || _this$fireAnalyticsEv6.call(this, fetchErrorPayload(error.message));
|
|
782
821
|
return function () {};
|
|
783
822
|
}
|
|
784
823
|
}
|
|
@@ -802,12 +841,12 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
802
841
|
key: "getProviderFactory",
|
|
803
842
|
value: function getProviderFactory(resourceId) {
|
|
804
843
|
if (!this.dataProvider) {
|
|
805
|
-
var _this$
|
|
844
|
+
var _this$fireAnalyticsEv7;
|
|
806
845
|
var error = new Error('Data provider not set');
|
|
807
846
|
logException(error, {
|
|
808
847
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
809
848
|
});
|
|
810
|
-
(_this$
|
|
849
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, fetchErrorPayload(error.message));
|
|
811
850
|
return undefined;
|
|
812
851
|
}
|
|
813
852
|
var _this$dataProvider$ge = this.dataProvider.getSyncedBlockRendererProviderOptions(),
|
|
@@ -836,11 +875,11 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
836
875
|
try {
|
|
837
876
|
this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
|
|
838
877
|
} catch (error) {
|
|
839
|
-
var _this$
|
|
878
|
+
var _this$fireAnalyticsEv8;
|
|
840
879
|
logException(error, {
|
|
841
880
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
842
881
|
});
|
|
843
|
-
(_this$
|
|
882
|
+
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 || _this$fireAnalyticsEv8.call(this, fetchErrorPayload(error.message, resourceId));
|
|
844
883
|
}
|
|
845
884
|
}
|
|
846
885
|
return providerFactory;
|
|
@@ -900,8 +939,8 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
900
939
|
return;
|
|
901
940
|
}
|
|
902
941
|
if (!syncBlock.data.sourceAri || !syncBlock.data.product) {
|
|
903
|
-
var _this$
|
|
904
|
-
(_this$
|
|
942
|
+
var _this$fireAnalyticsEv9;
|
|
943
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 || _this$fireAnalyticsEv9.call(this, fetchErrorPayload('Sync block source ari or product not found'));
|
|
905
944
|
return;
|
|
906
945
|
}
|
|
907
946
|
var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo((_syncBlock$data2 = syncBlock.data) === null || _syncBlock$data2 === void 0 ? void 0 : _syncBlock$data2.sourceAri, (_syncBlock$data3 = syncBlock.data) === null || _syncBlock$data3 === void 0 ? void 0 : _syncBlock$data3.product);
|
|
@@ -951,7 +990,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
951
990
|
key: "flush",
|
|
952
991
|
value: (function () {
|
|
953
992
|
var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
954
|
-
var success, blocks, _this$saveExperience, updateResult, _this$
|
|
993
|
+
var success, blocks, _this$saveExperience, updateResult, _this$fireAnalyticsEv0, _this$saveExperience2, _this$fireAnalyticsEv1, _this$saveExperience3, _this$saveExperience4;
|
|
955
994
|
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
956
995
|
while (1) switch (_context4.prev = _context4.next) {
|
|
957
996
|
case 0:
|
|
@@ -1012,7 +1051,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1012
1051
|
reason: updateResult.error || 'Failed to update reference synced blocks on the document'
|
|
1013
1052
|
});
|
|
1014
1053
|
}
|
|
1015
|
-
(_this$
|
|
1054
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 || _this$fireAnalyticsEv0.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
|
|
1016
1055
|
}
|
|
1017
1056
|
_context4.next = 26;
|
|
1018
1057
|
break;
|
|
@@ -1028,7 +1067,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1028
1067
|
reason: _context4.t0.message
|
|
1029
1068
|
});
|
|
1030
1069
|
}
|
|
1031
|
-
(_this$
|
|
1070
|
+
(_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 || _this$fireAnalyticsEv1.call(this, updateReferenceErrorPayload(_context4.t0.message));
|
|
1032
1071
|
case 26:
|
|
1033
1072
|
_context4.prev = 26;
|
|
1034
1073
|
if (!success) {
|
|
@@ -1073,13 +1112,13 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
1073
1112
|
});
|
|
1074
1113
|
this.providerFactories.clear();
|
|
1075
1114
|
(_this$saveExperience5 = this.saveExperience) === null || _this$saveExperience5 === void 0 || _this$saveExperience5.abort({
|
|
1076
|
-
reason: '
|
|
1115
|
+
reason: 'editorDestroyed'
|
|
1077
1116
|
});
|
|
1078
1117
|
(_this$fetchExperience5 = this.fetchExperience) === null || _this$fetchExperience5 === void 0 || _this$fetchExperience5.abort({
|
|
1079
|
-
reason: '
|
|
1118
|
+
reason: 'editorDestroyed'
|
|
1080
1119
|
});
|
|
1081
1120
|
(_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.abort({
|
|
1082
|
-
reason: '
|
|
1121
|
+
reason: 'editorDestroyed'
|
|
1083
1122
|
});
|
|
1084
1123
|
this.fireAnalyticsEvent = undefined;
|
|
1085
1124
|
}
|
|
@@ -8,8 +8,8 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
8
8
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
9
9
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
10
10
|
import { SyncBlockError } from '../common/types';
|
|
11
|
-
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload } from '../utils/errorHandling';
|
|
12
|
-
import { getCreateSourceExperience, getDeleteSourceExperience, getSaveSourceExperience } from '../utils/experienceTracking';
|
|
11
|
+
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload, fetchReferencesErrorPayload } from '../utils/errorHandling';
|
|
12
|
+
import { getCreateSourceExperience, getDeleteSourceExperience, getSaveSourceExperience, getFetchSourceInfoExperience } from '../utils/experienceTracking';
|
|
13
13
|
import { convertSyncBlockPMNodeToSyncBlockData } from '../utils/utils';
|
|
14
14
|
// A store manager responsible for the lifecycle and state management of source sync blocks in an editor instance.
|
|
15
15
|
// Designed to manage local in-memory state and synchronize with an external data provider.
|
|
@@ -36,6 +36,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
36
36
|
this.createExperience = getCreateSourceExperience(fireAnalyticsEvent);
|
|
37
37
|
this.saveExperience = getSaveSourceExperience(fireAnalyticsEvent);
|
|
38
38
|
this.deleteExperience = getDeleteSourceExperience(fireAnalyticsEvent);
|
|
39
|
+
this.fetchSourceInfoExperience = getFetchSourceInfoExperience(fireAnalyticsEvent);
|
|
39
40
|
}
|
|
40
41
|
}, {
|
|
41
42
|
key: "isSourceBlock",
|
|
@@ -128,10 +129,9 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
128
129
|
if (fg('platform_synced_block_dogfooding')) {
|
|
129
130
|
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start({});
|
|
130
131
|
}
|
|
131
|
-
;
|
|
132
|
-
_context.next = 12;
|
|
132
|
+
_context.next = 11;
|
|
133
133
|
return this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
134
|
-
case
|
|
134
|
+
case 11:
|
|
135
135
|
writeResults = _context.sent;
|
|
136
136
|
writeResults.forEach(function (result) {
|
|
137
137
|
// set isDirty to true for cases where it failed to save the sync block to the BE
|
|
@@ -145,7 +145,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
145
145
|
if (!writeResults.every(function (result) {
|
|
146
146
|
return result.resourceId && !result.error;
|
|
147
147
|
})) {
|
|
148
|
-
_context.next =
|
|
148
|
+
_context.next = 18;
|
|
149
149
|
break;
|
|
150
150
|
}
|
|
151
151
|
if (fg('platform_synced_block_dogfooding')) {
|
|
@@ -157,9 +157,8 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
157
157
|
}
|
|
158
158
|
});
|
|
159
159
|
}
|
|
160
|
-
;
|
|
161
160
|
return _context.abrupt("return", true);
|
|
162
|
-
case
|
|
161
|
+
case 18:
|
|
163
162
|
if (fg('platform_synced_block_dogfooding')) {
|
|
164
163
|
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure();
|
|
165
164
|
}
|
|
@@ -170,22 +169,22 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
170
169
|
(_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, updateErrorPayload(result.error || 'Failed to write data', result.resourceId));
|
|
171
170
|
});
|
|
172
171
|
return _context.abrupt("return", false);
|
|
173
|
-
case
|
|
174
|
-
_context.next =
|
|
172
|
+
case 21:
|
|
173
|
+
_context.next = 28;
|
|
175
174
|
break;
|
|
176
|
-
case
|
|
177
|
-
_context.prev =
|
|
175
|
+
case 23:
|
|
176
|
+
_context.prev = 23;
|
|
178
177
|
_context.t0 = _context["catch"](0);
|
|
179
178
|
logException(_context.t0, {
|
|
180
179
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
181
180
|
});
|
|
182
181
|
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, updateErrorPayload(_context.t0.message));
|
|
183
182
|
return _context.abrupt("return", false);
|
|
184
|
-
case
|
|
183
|
+
case 28:
|
|
185
184
|
case "end":
|
|
186
185
|
return _context.stop();
|
|
187
186
|
}
|
|
188
|
-
}, _callee, this, [[0,
|
|
187
|
+
}, _callee, this, [[0, 23]]);
|
|
189
188
|
}));
|
|
190
189
|
function flush() {
|
|
191
190
|
return _flush.apply(this, arguments);
|
|
@@ -338,7 +337,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
338
337
|
}, {
|
|
339
338
|
key: "delete",
|
|
340
339
|
value: function () {
|
|
341
|
-
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted) {
|
|
340
|
+
var _delete2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockIds, onDelete, onDeleteCompleted, reason) {
|
|
342
341
|
var _this5 = this;
|
|
343
342
|
var _this$deleteExperienc, results, callback, isDeleteSuccessful, _this$deleteExperienc2, _this$deleteExperienc3;
|
|
344
343
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
@@ -360,7 +359,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
360
359
|
_context2.next = 7;
|
|
361
360
|
return this.dataProvider.deleteNodesData(syncBlockIds.map(function (attrs) {
|
|
362
361
|
return attrs.resourceId;
|
|
363
|
-
}));
|
|
362
|
+
}), reason);
|
|
364
363
|
case 7:
|
|
365
364
|
results = _context2.sent;
|
|
366
365
|
isDeleteSuccessful = results.every(function (result) {
|
|
@@ -425,7 +424,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
425
424
|
}
|
|
426
425
|
}, _callee2, this, [[0, 15]]);
|
|
427
426
|
}));
|
|
428
|
-
function _delete(_x, _x2, _x3) {
|
|
427
|
+
function _delete(_x, _x2, _x3, _x4) {
|
|
429
428
|
return _delete2.apply(this, arguments);
|
|
430
429
|
}
|
|
431
430
|
return _delete;
|
|
@@ -439,7 +438,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
439
438
|
key: "retryDeletion",
|
|
440
439
|
value: function () {
|
|
441
440
|
var _retryDeletion = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
442
|
-
var _this$deletionRetryIn, syncBlockIds, onDelete, onDeleteCompleted;
|
|
441
|
+
var _this$deletionRetryIn, syncBlockIds, onDelete, onDeleteCompleted, deletionReason;
|
|
443
442
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
444
443
|
while (1) switch (_context3.prev = _context3.next) {
|
|
445
444
|
case 0:
|
|
@@ -449,13 +448,13 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
449
448
|
}
|
|
450
449
|
return _context3.abrupt("return", Promise.resolve());
|
|
451
450
|
case 2:
|
|
452
|
-
_this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted;
|
|
451
|
+
_this$deletionRetryIn = this.deletionRetryInfo, syncBlockIds = _this$deletionRetryIn.syncBlockIds, onDelete = _this$deletionRetryIn.onDelete, onDeleteCompleted = _this$deletionRetryIn.onDeleteCompleted, deletionReason = _this$deletionRetryIn.deletionReason;
|
|
453
452
|
if (!this.confirmationCallback) {
|
|
454
453
|
_context3.next = 6;
|
|
455
454
|
break;
|
|
456
455
|
}
|
|
457
456
|
_context3.next = 6;
|
|
458
|
-
return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
457
|
+
return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
459
458
|
case 6:
|
|
460
459
|
case "end":
|
|
461
460
|
return _context3.stop();
|
|
@@ -485,7 +484,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
485
484
|
}, {
|
|
486
485
|
key: "deleteSyncBlocksWithConfirmation",
|
|
487
486
|
value: (function () {
|
|
488
|
-
var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(syncBlockIds, onDelete, onDeleteCompleted, destroyCallback) {
|
|
487
|
+
var _deleteSyncBlocksWithConfirmation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(syncBlockIds, deletionReason, onDelete, onDeleteCompleted, destroyCallback) {
|
|
489
488
|
var confirmed, isDeleteSuccessful;
|
|
490
489
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
491
490
|
while (1) switch (_context4.prev = _context4.next) {
|
|
@@ -495,7 +494,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
495
494
|
break;
|
|
496
495
|
}
|
|
497
496
|
_context4.next = 3;
|
|
498
|
-
return this.confirmationCallback(syncBlockIds
|
|
497
|
+
return this.confirmationCallback(syncBlockIds, deletionReason);
|
|
499
498
|
case 3:
|
|
500
499
|
confirmed = _context4.sent;
|
|
501
500
|
if (!confirmed) {
|
|
@@ -503,7 +502,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
503
502
|
break;
|
|
504
503
|
}
|
|
505
504
|
_context4.next = 7;
|
|
506
|
-
return this.delete(syncBlockIds, onDelete, onDeleteCompleted);
|
|
505
|
+
return this.delete(syncBlockIds, onDelete, onDeleteCompleted, deletionReason);
|
|
507
506
|
case 7:
|
|
508
507
|
isDeleteSuccessful = _context4.sent;
|
|
509
508
|
if (!isDeleteSuccessful) {
|
|
@@ -512,7 +511,8 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
512
511
|
syncBlockIds: syncBlockIds,
|
|
513
512
|
onDelete: onDelete,
|
|
514
513
|
onDeleteCompleted: onDeleteCompleted,
|
|
515
|
-
destroyCallback: destroyCallback
|
|
514
|
+
destroyCallback: destroyCallback,
|
|
515
|
+
deletionReason: deletionReason
|
|
516
516
|
};
|
|
517
517
|
} else {
|
|
518
518
|
destroyCallback();
|
|
@@ -527,7 +527,7 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
527
527
|
}
|
|
528
528
|
}, _callee4, this);
|
|
529
529
|
}));
|
|
530
|
-
function deleteSyncBlocksWithConfirmation(
|
|
530
|
+
function deleteSyncBlocksWithConfirmation(_x5, _x6, _x7, _x8, _x9) {
|
|
531
531
|
return _deleteSyncBlocksWithConfirmation.apply(this, arguments);
|
|
532
532
|
}
|
|
533
533
|
return deleteSyncBlocksWithConfirmation;
|
|
@@ -535,11 +535,29 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
535
535
|
}, {
|
|
536
536
|
key: "getSyncBlockSourceInfo",
|
|
537
537
|
value: function getSyncBlockSourceInfo(localId) {
|
|
538
|
+
var _this6 = this;
|
|
538
539
|
try {
|
|
539
540
|
if (!this.dataProvider) {
|
|
540
541
|
throw new Error('Data provider not set');
|
|
541
542
|
}
|
|
542
|
-
|
|
543
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
544
|
+
var _this$fetchSourceInfo;
|
|
545
|
+
(_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start();
|
|
546
|
+
}
|
|
547
|
+
return this.dataProvider.fetchSyncBlockSourceInfo(localId, undefined, undefined, this.fireAnalyticsEvent).then(function (sourceInfo) {
|
|
548
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
549
|
+
if (!sourceInfo) {
|
|
550
|
+
var _this6$fetchSourceInf;
|
|
551
|
+
(_this6$fetchSourceInf = _this6.fetchSourceInfoExperience) === null || _this6$fetchSourceInf === void 0 || _this6$fetchSourceInf.failure({
|
|
552
|
+
reason: "No source info returned"
|
|
553
|
+
});
|
|
554
|
+
} else {
|
|
555
|
+
var _this6$fetchSourceInf2;
|
|
556
|
+
(_this6$fetchSourceInf2 = _this6.fetchSourceInfoExperience) === null || _this6$fetchSourceInf2 === void 0 || _this6$fetchSourceInf2.success();
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return sourceInfo;
|
|
560
|
+
});
|
|
543
561
|
} catch (error) {
|
|
544
562
|
var _this$fireAnalyticsEv6;
|
|
545
563
|
logException(error, {
|
|
@@ -549,23 +567,45 @@ export var SourceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
549
567
|
return Promise.resolve(undefined);
|
|
550
568
|
}
|
|
551
569
|
}
|
|
570
|
+
}, {
|
|
571
|
+
key: "fetchReferences",
|
|
572
|
+
value: function fetchReferences(resourceId) {
|
|
573
|
+
try {
|
|
574
|
+
if (!this.dataProvider) {
|
|
575
|
+
throw new Error('Data provider not set');
|
|
576
|
+
}
|
|
577
|
+
return this.dataProvider.fetchReferences(resourceId, true);
|
|
578
|
+
} catch (error) {
|
|
579
|
+
var _this$fireAnalyticsEv7;
|
|
580
|
+
logException(error, {
|
|
581
|
+
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
582
|
+
});
|
|
583
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 || _this$fireAnalyticsEv7.call(this, fetchReferencesErrorPayload(error.message));
|
|
584
|
+
return Promise.resolve({
|
|
585
|
+
error: SyncBlockError.Errored
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
}
|
|
552
589
|
}, {
|
|
553
590
|
key: "destroy",
|
|
554
591
|
value: function destroy() {
|
|
555
|
-
var _this$saveExperience4, _this$createExperienc2, _this$deleteExperienc4;
|
|
592
|
+
var _this$saveExperience4, _this$createExperienc2, _this$deleteExperienc4, _this$fetchSourceInfo2;
|
|
556
593
|
this.syncBlockCache.clear();
|
|
557
594
|
this.confirmationCallback = undefined;
|
|
558
595
|
this.pendingResourceId = undefined;
|
|
559
596
|
this.creationCallback = undefined;
|
|
560
597
|
this.dataProvider = undefined;
|
|
561
598
|
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 || _this$saveExperience4.abort({
|
|
562
|
-
reason: '
|
|
599
|
+
reason: 'editorDestroyed'
|
|
563
600
|
});
|
|
564
601
|
(_this$createExperienc2 = this.createExperience) === null || _this$createExperienc2 === void 0 || _this$createExperienc2.abort({
|
|
565
|
-
reason: '
|
|
602
|
+
reason: 'editorDestroyed'
|
|
566
603
|
});
|
|
567
604
|
(_this$deleteExperienc4 = this.deleteExperience) === null || _this$deleteExperienc4 === void 0 || _this$deleteExperienc4.abort({
|
|
568
|
-
reason: '
|
|
605
|
+
reason: 'editorDestroyed'
|
|
606
|
+
});
|
|
607
|
+
(_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.abort({
|
|
608
|
+
reason: 'editorDestroyed'
|
|
569
609
|
});
|
|
570
610
|
this.clearPendingDeletion();
|
|
571
611
|
}
|