@atlaskit/editor-synced-block-provider 3.28.0 → 3.28.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 +8 -0
- package/dist/cjs/clients/block-service/blockService.js +118 -310
- package/dist/cjs/clients/confluence/sourceInfo.js +1 -1
- package/dist/cjs/providers/block-service/blockServiceAPI.js +8 -18
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +20 -68
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +29 -84
- package/dist/cjs/store-manager/syncBlockStoreManager.js +1 -2
- package/dist/es2019/clients/block-service/blockService.js +119 -235
- package/dist/es2019/clients/confluence/sourceInfo.js +1 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +8 -18
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +34 -80
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +40 -90
- package/dist/es2019/store-manager/syncBlockStoreManager.js +1 -2
- package/dist/esm/clients/block-service/blockService.js +118 -310
- package/dist/esm/clients/confluence/sourceInfo.js +1 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +8 -18
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +20 -68
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +29 -84
- package/dist/esm/store-manager/syncBlockStoreManager.js +1 -2
- package/dist/types/clients/block-service/blockService.d.ts +3 -6
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +2 -5
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +0 -2
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +0 -14
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +3 -6
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +2 -5
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +0 -2
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +0 -14
- package/package.json +1 -4
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import isEqual from 'lodash/isEqual';
|
|
3
3
|
import rafSchedule from 'raf-schd';
|
|
4
|
-
import { isSSR } from '@atlaskit/editor-common/core-utils';
|
|
5
4
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
6
5
|
import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
|
|
7
6
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -54,12 +53,10 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
54
53
|
});
|
|
55
54
|
});
|
|
56
55
|
}));
|
|
57
|
-
this.syncBlockCache = new Map();
|
|
58
56
|
this.subscriptions = new Map();
|
|
59
57
|
this.titleSubscriptions = new Map();
|
|
60
58
|
this.dataProvider = dataProvider;
|
|
61
59
|
this.syncBlockFetchDataRequests = new Map();
|
|
62
|
-
this.syncBlockSourceInfoRequestsOld = new Map();
|
|
63
60
|
this.syncBlockSourceInfoRequests = new Map();
|
|
64
61
|
this.providerFactories = new Map();
|
|
65
62
|
this.pendingCacheDeletions = new Map();
|
|
@@ -176,16 +173,9 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
176
173
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
177
174
|
}
|
|
178
175
|
getInitialSyncBlockData(resourceId) {
|
|
179
|
-
var _this$
|
|
176
|
+
var _this$dataProvider, _this$dataProvider$ge;
|
|
180
177
|
const syncBlockNode = createSyncBlockNode('', resourceId);
|
|
181
|
-
|
|
182
|
-
var _this$dataProvider, _this$dataProvider$ge;
|
|
183
|
-
// In SSR, prefer data from data provider cache
|
|
184
|
-
// should not take from store manager cache as it may be in incomplete state
|
|
185
|
-
// will be unified to the same cache later.
|
|
186
|
-
return (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : (_this$dataProvider$ge = _this$dataProvider.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider$ge === void 0 ? void 0 : _this$dataProvider$ge.data;
|
|
187
|
-
}
|
|
188
|
-
return this.getFromCache(resourceId) || ((_this$dataProvider2 = this.dataProvider) === null || _this$dataProvider2 === void 0 ? void 0 : (_this$dataProvider2$g = _this$dataProvider2.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider2$g === void 0 ? void 0 : _this$dataProvider2$g.data);
|
|
178
|
+
return (_this$dataProvider = this.dataProvider) === null || _this$dataProvider === void 0 ? void 0 : (_this$dataProvider$ge = _this$dataProvider.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider$ge === void 0 ? void 0 : _this$dataProvider$ge.data;
|
|
189
179
|
}
|
|
190
180
|
|
|
191
181
|
/**
|
|
@@ -228,12 +218,12 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
228
218
|
* @param resourceId - The resource ID of the block to subscribe to
|
|
229
219
|
*/
|
|
230
220
|
setupGraphQLSubscription(resourceId) {
|
|
231
|
-
var _this$
|
|
221
|
+
var _this$dataProvider2;
|
|
232
222
|
// Don't set up duplicate subscriptions
|
|
233
223
|
if (this.graphqlSubscriptions.has(resourceId)) {
|
|
234
224
|
return;
|
|
235
225
|
}
|
|
236
|
-
if (!((_this$
|
|
226
|
+
if (!((_this$dataProvider2 = this.dataProvider) !== null && _this$dataProvider2 !== void 0 && _this$dataProvider2.subscribeToBlockUpdates)) {
|
|
237
227
|
return;
|
|
238
228
|
}
|
|
239
229
|
const unsubscribe = this.dataProvider.subscribeToBlockUpdates(resourceId, syncBlockInstance => {
|
|
@@ -362,9 +352,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
362
352
|
return Promise.resolve(undefined);
|
|
363
353
|
}
|
|
364
354
|
(_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start({});
|
|
365
|
-
|
|
366
|
-
// Only use unpublished endpoint if feature flag is enabled
|
|
367
|
-
const isUnpublished = fg('platform_synced_block_patch_1') && ((_existingSyncBlock$da = existingSyncBlock.data) === null || _existingSyncBlock$da === void 0 ? void 0 : _existingSyncBlock$da.status) === 'unpublished';
|
|
355
|
+
const isUnpublished = ((_existingSyncBlock$da = existingSyncBlock.data) === null || _existingSyncBlock$da === void 0 ? void 0 : _existingSyncBlock$da.status) === 'unpublished';
|
|
368
356
|
const sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent, true,
|
|
369
357
|
// hasAccess
|
|
370
358
|
'edit',
|
|
@@ -597,18 +585,13 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
597
585
|
resourceId
|
|
598
586
|
} = syncBlock;
|
|
599
587
|
if (resourceId) {
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
source: 'network'
|
|
608
|
-
});
|
|
609
|
-
} else {
|
|
610
|
-
this.syncBlockCache.set(resourceId, syncBlock);
|
|
611
|
-
}
|
|
588
|
+
var _this$dataProvider3;
|
|
589
|
+
(_this$dataProvider3 = this.dataProvider) === null || _this$dataProvider3 === void 0 ? void 0 : _this$dataProvider3.updateCache({
|
|
590
|
+
[resourceId]: syncBlock
|
|
591
|
+
}, {
|
|
592
|
+
strategy: 'merge',
|
|
593
|
+
source: 'network'
|
|
594
|
+
});
|
|
612
595
|
const callbacks = this.subscriptions.get(resourceId);
|
|
613
596
|
if (callbacks) {
|
|
614
597
|
Object.values(callbacks).forEach(callback => {
|
|
@@ -626,23 +609,13 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
626
609
|
}
|
|
627
610
|
}
|
|
628
611
|
getFromCache(resourceId) {
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
const syncBlockNode = createSyncBlockNode('', resourceId);
|
|
633
|
-
return (_this$dataProvider5 = this.dataProvider) === null || _this$dataProvider5 === void 0 ? void 0 : (_this$dataProvider5$g = _this$dataProvider5.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider5$g === void 0 ? void 0 : _this$dataProvider5$g.data;
|
|
634
|
-
}
|
|
635
|
-
return this.syncBlockCache.get(resourceId);
|
|
612
|
+
var _this$dataProvider4, _this$dataProvider4$g;
|
|
613
|
+
const syncBlockNode = createSyncBlockNode('', resourceId);
|
|
614
|
+
return (_this$dataProvider4 = this.dataProvider) === null || _this$dataProvider4 === void 0 ? void 0 : (_this$dataProvider4$g = _this$dataProvider4.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider4$g === void 0 ? void 0 : _this$dataProvider4$g.data;
|
|
636
615
|
}
|
|
637
616
|
deleteFromCache(resourceId) {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
// For dataProvider cache, we update with empty/deleted state
|
|
641
|
-
// The cache is managed per-node basis via resetCache if needed
|
|
642
|
-
// For now, we don't explicitly delete from dataProvider cache
|
|
643
|
-
// as the cache is meant to persist for cache-first-then-network strategy
|
|
644
|
-
(_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 ? void 0 : _this$dataProvider6.removeFromCache([resourceId]);
|
|
645
|
-
}
|
|
617
|
+
var _this$dataProvider5;
|
|
618
|
+
(_this$dataProvider5 = this.dataProvider) === null || _this$dataProvider5 === void 0 ? void 0 : _this$dataProvider5.removeFromCache([resourceId]);
|
|
646
619
|
this.providerFactories.delete(resourceId);
|
|
647
620
|
}
|
|
648
621
|
debouncedBatchedFetchSyncBlocks(resourceId) {
|
|
@@ -660,7 +633,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
660
633
|
}
|
|
661
634
|
}
|
|
662
635
|
subscribeToSyncBlock(resourceId, localId, callback) {
|
|
663
|
-
var _this$
|
|
636
|
+
var _this$dataProvider6, _this$dataProvider6$g;
|
|
664
637
|
// Cancel any pending cache deletion for this resourceId.
|
|
665
638
|
// This handles the case where a block is moved - the old component unmounts
|
|
666
639
|
// (scheduling deletion) but the new component mounts and subscribes before
|
|
@@ -689,23 +662,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
689
662
|
const syncBlockNode = createSyncBlockNode(localId, resourceId);
|
|
690
663
|
|
|
691
664
|
// call the callback immediately if we have cached data
|
|
692
|
-
const cachedData =
|
|
693
|
-
(_this$dataProvider7 = this.dataProvider) === null || _this$dataProvider7 === void 0 ? void 0 : (_this$dataProvider7$g = _this$dataProvider7.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider7$g === void 0 ? void 0 : _this$dataProvider7$g.data : isSSR() // in SSR, prefer data provider cache
|
|
694
|
-
? ((_this$dataProvider8 = this.dataProvider) === null || _this$dataProvider8 === void 0 ? void 0 : (_this$dataProvider8$g = _this$dataProvider8.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider8$g === void 0 ? void 0 : _this$dataProvider8$g.data) || this.getFromCache(resourceId) : this.getFromCache(resourceId) || ((_this$dataProvider9 = this.dataProvider) === null || _this$dataProvider9 === void 0 ? void 0 : (_this$dataProvider9$g = _this$dataProvider9.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider9$g === void 0 ? void 0 : _this$dataProvider9$g.data);
|
|
665
|
+
const cachedData = (_this$dataProvider6 = this.dataProvider) === null || _this$dataProvider6 === void 0 ? void 0 : (_this$dataProvider6$g = _this$dataProvider6.getNodeDataFromCache(syncBlockNode)) === null || _this$dataProvider6$g === void 0 ? void 0 : _this$dataProvider6$g.data;
|
|
695
666
|
if (cachedData) {
|
|
696
667
|
callback(cachedData);
|
|
697
668
|
} else {
|
|
698
|
-
|
|
699
|
-
this.debouncedBatchedFetchSyncBlocks(resourceId);
|
|
700
|
-
} else {
|
|
701
|
-
this.fetchSyncBlocksData([syncBlockNode]).catch(error => {
|
|
702
|
-
var _this$fireAnalyticsEv14;
|
|
703
|
-
logException(error, {
|
|
704
|
-
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
705
|
-
});
|
|
706
|
-
(_this$fireAnalyticsEv14 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv14 === void 0 ? void 0 : _this$fireAnalyticsEv14.call(this, fetchErrorPayload(error.message, resourceId));
|
|
707
|
-
});
|
|
708
|
-
}
|
|
669
|
+
this.debouncedBatchedFetchSyncBlocks(resourceId);
|
|
709
670
|
}
|
|
710
671
|
|
|
711
672
|
// Set up GraphQL subscription if real-time subscriptions are enabled
|
|
@@ -797,11 +758,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
797
758
|
}
|
|
798
759
|
return this.subscribeToSyncBlock(resourceId, localId, callback);
|
|
799
760
|
} catch (error) {
|
|
800
|
-
var _this$
|
|
761
|
+
var _this$fireAnalyticsEv14;
|
|
801
762
|
logException(error, {
|
|
802
763
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
803
764
|
});
|
|
804
|
-
(_this$
|
|
765
|
+
(_this$fireAnalyticsEv14 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv14 === void 0 ? void 0 : _this$fireAnalyticsEv14.call(this, fetchErrorPayload(error.message));
|
|
805
766
|
return () => {};
|
|
806
767
|
}
|
|
807
768
|
}
|
|
@@ -821,12 +782,12 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
821
782
|
}
|
|
822
783
|
getProviderFactory(resourceId) {
|
|
823
784
|
if (!this.dataProvider) {
|
|
824
|
-
var _this$
|
|
785
|
+
var _this$fireAnalyticsEv15;
|
|
825
786
|
const error = new Error('Data provider not set');
|
|
826
787
|
logException(error, {
|
|
827
788
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
828
789
|
});
|
|
829
|
-
(_this$
|
|
790
|
+
(_this$fireAnalyticsEv15 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv15 === void 0 ? void 0 : _this$fireAnalyticsEv15.call(this, fetchErrorPayload(error.message));
|
|
830
791
|
return undefined;
|
|
831
792
|
}
|
|
832
793
|
const {
|
|
@@ -856,11 +817,11 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
856
817
|
try {
|
|
857
818
|
this.retrieveDynamicProviders(resourceId, providerFactory, providerCreator);
|
|
858
819
|
} catch (error) {
|
|
859
|
-
var _this$
|
|
820
|
+
var _this$fireAnalyticsEv16;
|
|
860
821
|
logException(error, {
|
|
861
822
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
862
823
|
});
|
|
863
|
-
(_this$
|
|
824
|
+
(_this$fireAnalyticsEv16 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv16 === void 0 ? void 0 : _this$fireAnalyticsEv16.call(this, fetchErrorPayload(error.message, resourceId));
|
|
864
825
|
}
|
|
865
826
|
}
|
|
866
827
|
return providerFactory;
|
|
@@ -916,8 +877,8 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
916
877
|
return;
|
|
917
878
|
}
|
|
918
879
|
if (!syncBlock.data.sourceAri || !syncBlock.data.product) {
|
|
919
|
-
var _this$
|
|
920
|
-
(_this$
|
|
880
|
+
var _this$fireAnalyticsEv17;
|
|
881
|
+
(_this$fireAnalyticsEv17 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv17 === void 0 ? void 0 : _this$fireAnalyticsEv17.call(this, fetchErrorPayload('Sync block source ari or product not found'));
|
|
921
882
|
return;
|
|
922
883
|
}
|
|
923
884
|
const 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);
|
|
@@ -1035,15 +996,15 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
1035
996
|
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start();
|
|
1036
997
|
const updateResult = await this.dataProvider.updateReferenceData(blocks);
|
|
1037
998
|
if (!updateResult.success) {
|
|
1038
|
-
var _this$saveExperience2, _this$
|
|
999
|
+
var _this$saveExperience2, _this$fireAnalyticsEv18;
|
|
1039
1000
|
success = false;
|
|
1040
1001
|
(_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 ? void 0 : _this$saveExperience2.failure({
|
|
1041
1002
|
reason: updateResult.error || 'Failed to update reference synced blocks on the document'
|
|
1042
1003
|
});
|
|
1043
|
-
(_this$
|
|
1004
|
+
(_this$fireAnalyticsEv18 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv18 === void 0 ? void 0 : _this$fireAnalyticsEv18.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
|
|
1044
1005
|
}
|
|
1045
1006
|
} catch (error) {
|
|
1046
|
-
var _this$saveExperience3, _this$
|
|
1007
|
+
var _this$saveExperience3, _this$fireAnalyticsEv19;
|
|
1047
1008
|
success = false;
|
|
1048
1009
|
logException(error, {
|
|
1049
1010
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
@@ -1051,7 +1012,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
1051
1012
|
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 ? void 0 : _this$saveExperience3.failure({
|
|
1052
1013
|
reason: error.message
|
|
1053
1014
|
});
|
|
1054
|
-
(_this$
|
|
1015
|
+
(_this$fireAnalyticsEv19 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv19 === void 0 ? void 0 : _this$fireAnalyticsEv19.call(this, updateReferenceErrorPayload(error.message));
|
|
1055
1016
|
} finally {
|
|
1056
1017
|
if (!success) {
|
|
1057
1018
|
// set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
|
|
@@ -1082,7 +1043,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
1082
1043
|
return success;
|
|
1083
1044
|
}
|
|
1084
1045
|
destroy() {
|
|
1085
|
-
var _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo6;
|
|
1046
|
+
var _this$dataProvider7, _this$saveExperience5, _this$fetchExperience0, _this$fetchSourceInfo6;
|
|
1086
1047
|
// Cancel any queued flush to prevent it from running after destroy
|
|
1087
1048
|
if (this.queuedFlushTimeout) {
|
|
1088
1049
|
clearTimeout(this.queuedFlushTimeout);
|
|
@@ -1091,20 +1052,13 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
1091
1052
|
|
|
1092
1053
|
// Clean up all GraphQL subscriptions first
|
|
1093
1054
|
this.cleanupAllGraphQLSubscriptions();
|
|
1094
|
-
|
|
1095
|
-
var _this$dataProvider0;
|
|
1096
|
-
// Reset cache in dataProvider
|
|
1097
|
-
(_this$dataProvider0 = this.dataProvider) === null || _this$dataProvider0 === void 0 ? void 0 : _this$dataProvider0.resetCache();
|
|
1098
|
-
} else {
|
|
1099
|
-
this.syncBlockCache.clear();
|
|
1100
|
-
}
|
|
1055
|
+
(_this$dataProvider7 = this.dataProvider) === null || _this$dataProvider7 === void 0 ? void 0 : _this$dataProvider7.resetCache();
|
|
1101
1056
|
this.scheduledBatchFetch.cancel();
|
|
1102
1057
|
this.pendingFetchRequests.clear();
|
|
1103
1058
|
this.dataProvider = undefined;
|
|
1104
1059
|
this.subscriptions.clear();
|
|
1105
1060
|
this.titleSubscriptions.clear();
|
|
1106
1061
|
this.syncBlockFetchDataRequests.clear();
|
|
1107
|
-
this.syncBlockSourceInfoRequestsOld.clear();
|
|
1108
1062
|
this.syncBlockSourceInfoRequests.clear();
|
|
1109
1063
|
this.providerFactories.clear();
|
|
1110
1064
|
this.isRefreshingSubscriptions = false;
|
|
@@ -1,6 +1,5 @@
|
|
|
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';
|
|
4
3
|
import { SyncBlockError } from '../common/types';
|
|
5
4
|
import { updateErrorPayload, createErrorPayload, deleteErrorPayload, updateCacheErrorPayload, getSourceInfoErrorPayload, updateSuccessPayload, createSuccessPayload, deleteSuccessPayload, fetchReferencesErrorPayload } from '../utils/errorHandling';
|
|
6
5
|
import { getCreateSourceExperience, getDeleteSourceExperience, getSaveSourceExperience, getFetchSourceInfoExperience } from '../utils/experienceTracking';
|
|
@@ -80,7 +79,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
80
79
|
// - are waiting to be deleted to avoid nodes being re-created
|
|
81
80
|
// - haven't been updated since we last flushed
|
|
82
81
|
// - are still pending BE creation
|
|
83
|
-
if (!syncBlockData.pendingDeletion && syncBlockData.isDirty && !
|
|
82
|
+
if (!syncBlockData.pendingDeletion && syncBlockData.isDirty && !this.isPendingCreation(syncBlockData.resourceId)) {
|
|
84
83
|
bodiedSyncBlockNodes.push({
|
|
85
84
|
type: 'bodiedSyncBlock',
|
|
86
85
|
attrs: {
|
|
@@ -94,11 +93,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
94
93
|
// is still making changes, the new changes might not be saved if they all happen
|
|
95
94
|
// exactly at a time when the writeNodesData is being executed asynchronously.
|
|
96
95
|
syncBlockData.isDirty = false;
|
|
97
|
-
// When flushing, set status to 'active' so the block is published
|
|
98
|
-
const dataToFlush =
|
|
96
|
+
// When flushing, set status to 'active' so the block is published
|
|
97
|
+
const dataToFlush = {
|
|
99
98
|
...syncBlockData,
|
|
100
99
|
status: 'active'
|
|
101
|
-
}
|
|
100
|
+
};
|
|
102
101
|
bodiedSyncBlockData.push(dataToFlush);
|
|
103
102
|
}
|
|
104
103
|
});
|
|
@@ -147,66 +146,32 @@ export class SourceSyncBlockStoreManager {
|
|
|
147
146
|
return false;
|
|
148
147
|
}
|
|
149
148
|
}
|
|
150
|
-
|
|
151
|
-
// Remove this method and pendingResourceId when cleaning up platform_synced_block_patch_1
|
|
152
|
-
registerPendingCreation(resourceId) {
|
|
153
|
-
this.pendingResourceId = resourceId;
|
|
154
|
-
}
|
|
155
149
|
isPendingCreation(resourceId) {
|
|
156
150
|
return this.creationCompletionCallbacks.has(resourceId);
|
|
157
151
|
}
|
|
158
152
|
|
|
159
|
-
/**
|
|
160
|
-
* Register callback function (which inserts node, handles focus etc) to be used later when creation to backend succeed
|
|
161
|
-
*/
|
|
162
|
-
registerCreationCallback(callback) {
|
|
163
|
-
this.creationCallback = callback;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
153
|
/**
|
|
167
154
|
* Fires callback to insert node (if creation is successful) and clears pending creation data
|
|
168
155
|
* @param success
|
|
169
156
|
*/
|
|
170
157
|
commitPendingCreation(success, resourceId) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
onCompletion(success);
|
|
176
|
-
} else {
|
|
177
|
-
var _this$fireAnalyticsEv5;
|
|
178
|
-
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, createErrorPayload('creation complete callback missing', resourceId));
|
|
179
|
-
}
|
|
180
|
-
if (success) {
|
|
181
|
-
var _this$fireAnalyticsEv6;
|
|
182
|
-
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, createSuccessPayload(resourceId || ''));
|
|
183
|
-
} else {
|
|
184
|
-
var _this$fireAnalyticsEv7;
|
|
185
|
-
// Delete the node from cache if fail to create so it's not flushed to BE
|
|
186
|
-
this.syncBlockCache.delete(resourceId || '');
|
|
187
|
-
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, createErrorPayload('Fail to create bodied sync block', resourceId));
|
|
188
|
-
}
|
|
158
|
+
const onCompletion = this.creationCompletionCallbacks.get(resourceId);
|
|
159
|
+
if (onCompletion) {
|
|
160
|
+
this.creationCompletionCallbacks.delete(resourceId);
|
|
161
|
+
onCompletion(success);
|
|
189
162
|
} else {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
163
|
+
var _this$fireAnalyticsEv5;
|
|
164
|
+
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, createErrorPayload('creation complete callback missing', resourceId));
|
|
165
|
+
}
|
|
166
|
+
if (success) {
|
|
167
|
+
var _this$fireAnalyticsEv6;
|
|
168
|
+
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, createSuccessPayload(resourceId || ''));
|
|
169
|
+
} else {
|
|
170
|
+
var _this$fireAnalyticsEv7;
|
|
171
|
+
// Delete the node from cache if fail to create so it's not flushed to BE
|
|
172
|
+
this.syncBlockCache.delete(resourceId || '');
|
|
173
|
+
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, createErrorPayload('Fail to create bodied sync block', resourceId));
|
|
199
174
|
}
|
|
200
|
-
this.creationCallback = undefined;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
*
|
|
205
|
-
* @returns true if waiting for the result of saving new bodiedSyncBlock to backend
|
|
206
|
-
* Remove this method when cleaning up platform_synced_block_patch_1
|
|
207
|
-
*/
|
|
208
|
-
hasPendingCreation() {
|
|
209
|
-
return fg('platform_synced_block_patch_1') ? this.creationCompletionCallbacks.size > 0 : !!this.pendingResourceId;
|
|
210
175
|
}
|
|
211
176
|
registerConfirmationCallback(callback) {
|
|
212
177
|
this.confirmationCallback = callback;
|
|
@@ -249,9 +214,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
249
214
|
if (!this.dataProvider) {
|
|
250
215
|
throw new Error('Data provider not set');
|
|
251
216
|
}
|
|
252
|
-
|
|
253
|
-
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
254
|
-
}
|
|
217
|
+
this.creationCompletionCallbacks.set(resourceId, onCompletion);
|
|
255
218
|
(_this$createExperienc = this.createExperience) === null || _this$createExperienc === void 0 ? void 0 : _this$createExperienc.start({});
|
|
256
219
|
this.dataProvider.createNodeData({
|
|
257
220
|
content: [],
|
|
@@ -259,28 +222,20 @@ export class SourceSyncBlockStoreManager {
|
|
|
259
222
|
resourceId
|
|
260
223
|
}).then(result => {
|
|
261
224
|
const resourceId = result.resourceId || '';
|
|
262
|
-
if (resourceId &&
|
|
225
|
+
if (resourceId && !result.error) {
|
|
263
226
|
var _this$createExperienc2;
|
|
264
227
|
this.commitPendingCreation(true, resourceId);
|
|
265
228
|
(_this$createExperienc2 = this.createExperience) === null || _this$createExperienc2 === void 0 ? void 0 : _this$createExperienc2.success();
|
|
266
|
-
|
|
267
|
-
// Update the sync block data with the node data if it is provided
|
|
268
|
-
// to avoid any race conditions where the data could be missed during a render operation
|
|
269
|
-
if (!fg('platform_synced_block_patch_1')) {
|
|
270
|
-
if (nodeData) {
|
|
271
|
-
this.updateSyncBlockData(nodeData);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
229
|
} else {
|
|
275
|
-
var _this$createExperienc3, _this$
|
|
230
|
+
var _this$createExperienc3, _this$fireAnalyticsEv8;
|
|
276
231
|
this.commitPendingCreation(false, resourceId);
|
|
277
232
|
(_this$createExperienc3 = this.createExperience) === null || _this$createExperienc3 === void 0 ? void 0 : _this$createExperienc3.failure({
|
|
278
233
|
reason: result.error || 'Failed to create bodied sync block'
|
|
279
234
|
});
|
|
280
|
-
(_this$
|
|
235
|
+
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, createErrorPayload(result.error || 'Failed to create bodied sync block', resourceId));
|
|
281
236
|
}
|
|
282
237
|
}).catch(error => {
|
|
283
|
-
var _this$createExperienc4, _this$
|
|
238
|
+
var _this$createExperienc4, _this$fireAnalyticsEv9;
|
|
284
239
|
this.commitPendingCreation(false, resourceId);
|
|
285
240
|
logException(error, {
|
|
286
241
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
@@ -288,20 +243,17 @@ export class SourceSyncBlockStoreManager {
|
|
|
288
243
|
(_this$createExperienc4 = this.createExperience) === null || _this$createExperienc4 === void 0 ? void 0 : _this$createExperienc4.failure({
|
|
289
244
|
reason: error.message
|
|
290
245
|
});
|
|
291
|
-
(_this$
|
|
246
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, createErrorPayload(error.message, resourceId));
|
|
292
247
|
});
|
|
293
|
-
if (!fg('platform_synced_block_patch_1')) {
|
|
294
|
-
this.registerPendingCreation(resourceId);
|
|
295
|
-
}
|
|
296
248
|
} catch (error) {
|
|
297
|
-
var _this$
|
|
298
|
-
if (
|
|
249
|
+
var _this$fireAnalyticsEv0;
|
|
250
|
+
if (this.isPendingCreation(resourceId)) {
|
|
299
251
|
this.commitPendingCreation(false, resourceId);
|
|
300
252
|
}
|
|
301
253
|
logException(error, {
|
|
302
254
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
303
255
|
});
|
|
304
|
-
(_this$
|
|
256
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, createErrorPayload(error.message));
|
|
305
257
|
}
|
|
306
258
|
}
|
|
307
259
|
async delete(syncBlockIds, onDelete, onDeleteCompleted, reason) {
|
|
@@ -325,8 +277,8 @@ export class SourceSyncBlockStoreManager {
|
|
|
325
277
|
this.clearPendingDeletion();
|
|
326
278
|
(_this$deleteExperienc2 = this.deleteExperience) === null || _this$deleteExperienc2 === void 0 ? void 0 : _this$deleteExperienc2.success();
|
|
327
279
|
results.forEach(result => {
|
|
328
|
-
var _this$
|
|
329
|
-
(_this$
|
|
280
|
+
var _this$fireAnalyticsEv1;
|
|
281
|
+
(_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, deleteSuccessPayload(result.resourceId));
|
|
330
282
|
});
|
|
331
283
|
} else {
|
|
332
284
|
var _this$deleteExperienc3;
|
|
@@ -336,11 +288,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
336
288
|
(_this$deleteExperienc3 = this.deleteExperience) === null || _this$deleteExperienc3 === void 0 ? void 0 : _this$deleteExperienc3.failure();
|
|
337
289
|
results.forEach(result => {
|
|
338
290
|
if (result.success) {
|
|
339
|
-
var _this$
|
|
340
|
-
(_this$
|
|
291
|
+
var _this$fireAnalyticsEv10;
|
|
292
|
+
(_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, deleteSuccessPayload(result.resourceId));
|
|
341
293
|
} else {
|
|
342
|
-
var _this$
|
|
343
|
-
(_this$
|
|
294
|
+
var _this$fireAnalyticsEv11;
|
|
295
|
+
(_this$fireAnalyticsEv11 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv11 === void 0 ? void 0 : _this$fireAnalyticsEv11.call(this, deleteErrorPayload(result.error || 'Failed to delete synced block', result.resourceId));
|
|
344
296
|
}
|
|
345
297
|
});
|
|
346
298
|
}
|
|
@@ -348,9 +300,9 @@ export class SourceSyncBlockStoreManager {
|
|
|
348
300
|
return isDeleteSuccessful;
|
|
349
301
|
} catch (error) {
|
|
350
302
|
syncBlockIds.forEach(Ids => {
|
|
351
|
-
var _this$
|
|
303
|
+
var _this$fireAnalyticsEv12;
|
|
352
304
|
this.setPendingDeletion(Ids, false);
|
|
353
|
-
(_this$
|
|
305
|
+
(_this$fireAnalyticsEv12 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv12 === void 0 ? void 0 : _this$fireAnalyticsEv12.call(this, deleteErrorPayload(error.message, Ids.resourceId));
|
|
354
306
|
});
|
|
355
307
|
logException(error, {
|
|
356
308
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
@@ -431,11 +383,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
431
383
|
return sourceInfo;
|
|
432
384
|
});
|
|
433
385
|
} catch (error) {
|
|
434
|
-
var _this$
|
|
386
|
+
var _this$fireAnalyticsEv13;
|
|
435
387
|
logException(error, {
|
|
436
388
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
437
389
|
});
|
|
438
|
-
(_this$
|
|
390
|
+
(_this$fireAnalyticsEv13 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv13 === void 0 ? void 0 : _this$fireAnalyticsEv13.call(this, getSourceInfoErrorPayload(error.message));
|
|
439
391
|
return Promise.resolve(undefined);
|
|
440
392
|
}
|
|
441
393
|
}
|
|
@@ -446,11 +398,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
446
398
|
}
|
|
447
399
|
return this.dataProvider.fetchReferences(resourceId, true);
|
|
448
400
|
} catch (error) {
|
|
449
|
-
var _this$
|
|
401
|
+
var _this$fireAnalyticsEv14;
|
|
450
402
|
logException(error, {
|
|
451
403
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
452
404
|
});
|
|
453
|
-
(_this$
|
|
405
|
+
(_this$fireAnalyticsEv14 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv14 === void 0 ? void 0 : _this$fireAnalyticsEv14.call(this, fetchReferencesErrorPayload(error.message));
|
|
454
406
|
return Promise.resolve({
|
|
455
407
|
error: SyncBlockError.Errored
|
|
456
408
|
});
|
|
@@ -460,9 +412,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
460
412
|
var _this$saveExperience4, _this$createExperienc5, _this$deleteExperienc4, _this$fetchSourceInfo4;
|
|
461
413
|
this.syncBlockCache.clear();
|
|
462
414
|
this.confirmationCallback = undefined;
|
|
463
|
-
this.pendingResourceId = undefined;
|
|
464
415
|
this.creationCompletionCallbacks.clear();
|
|
465
|
-
this.creationCallback = undefined;
|
|
466
416
|
this.dataProvider = undefined;
|
|
467
417
|
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 ? void 0 : _this$saveExperience4.abort({
|
|
468
418
|
reason: 'editorDestroyed'
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { useMemo } from 'react';
|
|
2
2
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
3
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
import { getProductFromSourceAri } from '../clients/block-service/ari';
|
|
5
4
|
import { SyncBlockError } from '../common/types';
|
|
6
5
|
import { fetchReferencesErrorPayload } from '../utils/errorHandling';
|
|
@@ -20,7 +19,7 @@ export class SyncBlockStoreManager {
|
|
|
20
19
|
this.sourceSyncBlockStoreManager = new SourceSyncBlockStoreManager(dataProvider);
|
|
21
20
|
this.referenceSyncBlockStoreManager = new ReferenceSyncBlockStoreManager(dataProvider);
|
|
22
21
|
this.dataProvider = dataProvider;
|
|
23
|
-
this.referenceSyncBlockStoreManager.setRealTimeSubscriptionsEnabled(
|
|
22
|
+
this.referenceSyncBlockStoreManager.setRealTimeSubscriptionsEnabled(true);
|
|
24
23
|
}
|
|
25
24
|
async fetchReferencesSourceInfo(resourceId, blockInstanceId, isSourceSyncBlock) {
|
|
26
25
|
try {
|