@atlaskit/editor-synced-block-provider 3.25.0 → 3.26.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 +21 -0
- package/dist/cjs/clients/block-service/blockService.js +98 -57
- package/dist/cjs/clients/confluence/sourceInfo.js +112 -69
- package/dist/cjs/hooks/useFetchSyncBlockData.js +5 -11
- package/dist/cjs/providers/block-service/blockServiceAPI.js +1 -1
- package/dist/cjs/providers/syncBlockProvider.js +34 -75
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +83 -124
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +59 -93
- package/dist/cjs/store-manager/syncBlockStoreManager.js +2 -4
- package/dist/cjs/utils/errorHandling.js +2 -5
- package/dist/cjs/utils/resolveSyncBlockInstance.js +1 -3
- package/dist/cjs/utils/utils.js +5 -6
- package/dist/es2019/clients/block-service/blockService.js +55 -19
- package/dist/es2019/clients/confluence/sourceInfo.js +51 -4
- package/dist/es2019/hooks/useFetchSyncBlockData.js +6 -12
- package/dist/es2019/providers/block-service/blockServiceAPI.js +1 -1
- package/dist/es2019/providers/syncBlockProvider.js +22 -54
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +73 -114
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +60 -92
- package/dist/es2019/store-manager/syncBlockStoreManager.js +2 -4
- package/dist/es2019/utils/errorHandling.js +1 -4
- package/dist/es2019/utils/resolveSyncBlockInstance.js +2 -5
- package/dist/es2019/utils/utils.js +5 -6
- package/dist/esm/clients/block-service/blockService.js +98 -57
- package/dist/esm/clients/confluence/sourceInfo.js +111 -68
- package/dist/esm/hooks/useFetchSyncBlockData.js +5 -11
- package/dist/esm/providers/block-service/blockServiceAPI.js +1 -1
- package/dist/esm/providers/syncBlockProvider.js +34 -75
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +83 -124
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +59 -93
- package/dist/esm/store-manager/syncBlockStoreManager.js +2 -4
- package/dist/esm/utils/errorHandling.js +2 -5
- package/dist/esm/utils/resolveSyncBlockInstance.js +1 -3
- package/dist/esm/utils/utils.js +5 -6
- package/dist/types/clients/confluence/sourceInfo.d.ts +1 -2
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +1 -1
- package/dist/types/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types/providers/types.d.ts +3 -3
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +1 -1
- package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +1 -2
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +1 -1
- package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +2 -2
- package/dist/types-ts4.5/providers/types.d.ts +3 -3
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +1 -1
- package/package.json +2 -5
|
@@ -171,7 +171,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
171
171
|
getInitialSyncBlockData(resourceId) {
|
|
172
172
|
var _this$dataProvider2, _this$dataProvider2$g;
|
|
173
173
|
const syncBlockNode = createSyncBlockNode('', resourceId);
|
|
174
|
-
if (isSSR()
|
|
174
|
+
if (isSSR() || fg('platform_synced_block_patch_1')) {
|
|
175
175
|
var _this$dataProvider, _this$dataProvider$ge;
|
|
176
176
|
// In SSR, prefer data from data provider cache
|
|
177
177
|
// should not take from store manager cache as it may be in incomplete state
|
|
@@ -317,16 +317,13 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
317
317
|
}
|
|
318
318
|
fetchSyncBlockSourceInfo(resourceId) {
|
|
319
319
|
try {
|
|
320
|
+
var _this$fetchSourceInfo, _existingSyncBlock$da;
|
|
320
321
|
if (!resourceId || !this.dataProvider) {
|
|
321
322
|
throw new Error('Data provider or resourceId not set');
|
|
322
323
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
return existingRequest;
|
|
327
|
-
}
|
|
328
|
-
} else if (this.syncBlockSourceInfoRequestsOld.get(resourceId)) {
|
|
329
|
-
return Promise.resolve(undefined);
|
|
324
|
+
const existingRequest = this.syncBlockSourceInfoRequests.get(resourceId);
|
|
325
|
+
if (existingRequest) {
|
|
326
|
+
return existingRequest;
|
|
330
327
|
}
|
|
331
328
|
const existingSyncBlock = this.getFromCache(resourceId);
|
|
332
329
|
if (!existingSyncBlock) {
|
|
@@ -343,79 +340,64 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
343
340
|
} = existingSyncBlock.data || {};
|
|
344
341
|
// skip if source URL and title are already present
|
|
345
342
|
if (sourceURL && sourceTitle) {
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
});
|
|
355
|
-
} else {
|
|
356
|
-
return Promise.resolve(undefined);
|
|
357
|
-
}
|
|
343
|
+
return Promise.resolve({
|
|
344
|
+
title: sourceTitle,
|
|
345
|
+
url: sourceURL,
|
|
346
|
+
subType: sourceSubType,
|
|
347
|
+
sourceAri: sourceAri || '',
|
|
348
|
+
onSameDocument,
|
|
349
|
+
productType: product
|
|
350
|
+
});
|
|
358
351
|
}
|
|
359
352
|
if (!sourceAri || !product || !blockInstanceId) {
|
|
360
353
|
var _this$fireAnalyticsEv8;
|
|
361
354
|
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing', resourceId));
|
|
362
355
|
return Promise.resolve(undefined);
|
|
363
356
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
const sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent
|
|
357
|
+
(_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start({});
|
|
358
|
+
|
|
359
|
+
// Only use unpublished endpoint if feature flag is enabled
|
|
360
|
+
const isUnpublished = fg('platform_synced_block_patch_1') && ((_existingSyncBlock$da = existingSyncBlock.data) === null || _existingSyncBlock$da === void 0 ? void 0 : _existingSyncBlock$da.status) === 'unpublished';
|
|
361
|
+
const sourceInfoPromise = this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent, true,
|
|
362
|
+
// hasAccess
|
|
363
|
+
'edit',
|
|
364
|
+
// urlType
|
|
365
|
+
isUnpublished).then(sourceInfo => {
|
|
369
366
|
if (!sourceInfo) {
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, getSourceInfoErrorPayload('No source info returned', resourceId));
|
|
376
|
-
}
|
|
367
|
+
var _this$fetchSourceInfo2, _this$fireAnalyticsEv9;
|
|
368
|
+
(_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 ? void 0 : _this$fetchSourceInfo2.failure({
|
|
369
|
+
reason: 'No source info returned'
|
|
370
|
+
});
|
|
371
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 ? void 0 : _this$fireAnalyticsEv9.call(this, getSourceInfoErrorPayload('No source info returned', resourceId));
|
|
377
372
|
return undefined;
|
|
378
373
|
}
|
|
379
374
|
this.updateCacheWithSourceInfo(resourceId, sourceInfo);
|
|
380
375
|
if (sourceInfo.title) {
|
|
381
376
|
this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
|
|
382
377
|
}
|
|
383
|
-
if (
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
reason: 'Missing title or url'
|
|
391
|
-
});
|
|
392
|
-
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, getSourceInfoErrorPayload('Missing title or url', resourceId));
|
|
393
|
-
}
|
|
394
|
-
return sourceInfo;
|
|
395
|
-
}
|
|
396
|
-
}).catch(error => {
|
|
397
|
-
var _this$fireAnalyticsEv1;
|
|
398
|
-
if (fg('platform_synced_block_dogfooding')) {
|
|
399
|
-
var _this$fetchSourceInfo5;
|
|
400
|
-
(_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 ? void 0 : _this$fetchSourceInfo5.failure({
|
|
401
|
-
reason: error.message
|
|
378
|
+
if (sourceInfo.title && sourceInfo.url) {
|
|
379
|
+
var _this$fetchSourceInfo3;
|
|
380
|
+
(_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 ? void 0 : _this$fetchSourceInfo3.success();
|
|
381
|
+
} else {
|
|
382
|
+
var _this$fetchSourceInfo4, _this$fireAnalyticsEv0;
|
|
383
|
+
(_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 ? void 0 : _this$fetchSourceInfo4.failure({
|
|
384
|
+
reason: 'Missing title or url'
|
|
402
385
|
});
|
|
386
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, getSourceInfoErrorPayload('Missing title or url', resourceId));
|
|
403
387
|
}
|
|
388
|
+
return sourceInfo;
|
|
389
|
+
}).catch(error => {
|
|
390
|
+
var _this$fetchSourceInfo5, _this$fireAnalyticsEv1;
|
|
391
|
+
(_this$fetchSourceInfo5 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 ? void 0 : _this$fetchSourceInfo5.failure({
|
|
392
|
+
reason: error.message
|
|
393
|
+
});
|
|
404
394
|
(_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, getSourceInfoErrorPayload(error.message, resourceId));
|
|
405
395
|
return undefined;
|
|
406
396
|
}).finally(() => {
|
|
407
|
-
|
|
408
|
-
this.syncBlockSourceInfoRequests.delete(resourceId);
|
|
409
|
-
} else {
|
|
410
|
-
this.syncBlockSourceInfoRequestsOld.delete(resourceId);
|
|
411
|
-
}
|
|
397
|
+
this.syncBlockSourceInfoRequests.delete(resourceId);
|
|
412
398
|
});
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return sourceInfoPromise;
|
|
416
|
-
} else {
|
|
417
|
-
this.syncBlockSourceInfoRequestsOld.set(resourceId, true);
|
|
418
|
-
}
|
|
399
|
+
this.syncBlockSourceInfoRequests.set(resourceId, sourceInfoPromise);
|
|
400
|
+
return sourceInfoPromise;
|
|
419
401
|
} catch (error) {
|
|
420
402
|
var _this$fireAnalyticsEv10;
|
|
421
403
|
logException(error, {
|
|
@@ -432,6 +414,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
432
414
|
* @returns The fetched sync block data results
|
|
433
415
|
*/
|
|
434
416
|
async fetchSyncBlocksData(syncBlockNodes) {
|
|
417
|
+
var _this$fetchExperience;
|
|
435
418
|
if (syncBlockNodes.length === 0) {
|
|
436
419
|
return;
|
|
437
420
|
}
|
|
@@ -458,10 +441,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
458
441
|
nodesToFetch.forEach(node => {
|
|
459
442
|
this.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
|
|
460
443
|
});
|
|
461
|
-
|
|
462
|
-
var _this$fetchExperience;
|
|
463
|
-
(_this$fetchExperience = this.fetchExperience) === null || _this$fetchExperience === void 0 ? void 0 : _this$fetchExperience.start({});
|
|
464
|
-
}
|
|
444
|
+
(_this$fetchExperience = this.fetchExperience) === null || _this$fetchExperience === void 0 ? void 0 : _this$fetchExperience.start({});
|
|
465
445
|
const data = await this.dataProvider.fetchNodesData(nodesToFetch).finally(() => {
|
|
466
446
|
nodesToFetch.forEach(node => {
|
|
467
447
|
this.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
|
|
@@ -482,7 +462,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
482
462
|
|
|
483
463
|
// Check if this is a newly added unpublished sync block and notify
|
|
484
464
|
// Only trigger for sync blocks that were just added (not refreshed or loaded on page init)
|
|
485
|
-
if (!syncBlockInstance.error && ((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) === null || _resolvedSyncBlockIns === void 0 ? void 0 : _resolvedSyncBlockIns.status) === 'unpublished' && this.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId) && this.onUnpublishedSyncBlockDetected
|
|
465
|
+
if (!syncBlockInstance.error && ((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) === null || _resolvedSyncBlockIns === void 0 ? void 0 : _resolvedSyncBlockIns.status) === 'unpublished' && this.newlyAddedSyncBlocks.has(syncBlockInstance.resourceId) && this.onUnpublishedSyncBlockDetected) {
|
|
486
466
|
// Remove from newly added set after checking to prevent duplicate flags
|
|
487
467
|
this.newlyAddedSyncBlocks.delete(syncBlockInstance.resourceId);
|
|
488
468
|
this.onUnpublishedSyncBlockDetected(resolvedSyncBlockInstance.resourceId);
|
|
@@ -499,7 +479,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
499
479
|
hasUnexpectedError = true;
|
|
500
480
|
}
|
|
501
481
|
return;
|
|
502
|
-
} else
|
|
482
|
+
} else {
|
|
503
483
|
const callbacks = this.subscriptions.get(syncBlockInstance.resourceId);
|
|
504
484
|
const localIds = callbacks ? Object.keys(callbacks) : [];
|
|
505
485
|
localIds.forEach(localId => {
|
|
@@ -509,21 +489,19 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
509
489
|
}
|
|
510
490
|
this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
511
491
|
});
|
|
512
|
-
if (
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
(_this$fetchExperience4 = this.fetchExperience) === null || _this$fetchExperience4 === void 0 ? void 0 : _this$fetchExperience4.success();
|
|
526
|
-
}
|
|
492
|
+
if (hasUnexpectedError) {
|
|
493
|
+
var _this$fetchExperience2;
|
|
494
|
+
(_this$fetchExperience2 = this.fetchExperience) === null || _this$fetchExperience2 === void 0 ? void 0 : _this$fetchExperience2.failure({
|
|
495
|
+
reason: 'Unexpected error during fetch'
|
|
496
|
+
});
|
|
497
|
+
} else if (hasExpectedError) {
|
|
498
|
+
var _this$fetchExperience3;
|
|
499
|
+
(_this$fetchExperience3 = this.fetchExperience) === null || _this$fetchExperience3 === void 0 ? void 0 : _this$fetchExperience3.abort({
|
|
500
|
+
reason: 'Expected error: NotFound or PermissionDenied'
|
|
501
|
+
});
|
|
502
|
+
} else {
|
|
503
|
+
var _this$fetchExperience4;
|
|
504
|
+
(_this$fetchExperience4 = this.fetchExperience) === null || _this$fetchExperience4 === void 0 ? void 0 : _this$fetchExperience4.success();
|
|
527
505
|
}
|
|
528
506
|
}
|
|
529
507
|
updateCacheWithSourceInfo(resourceId, sourceInfo) {
|
|
@@ -628,7 +606,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
628
606
|
|
|
629
607
|
// call the callback immediately if we have cached data
|
|
630
608
|
const cachedData = fg('platform_synced_block_patch_1') ? // When feature flag is enabled, use dataProvider cache only
|
|
631
|
-
(_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()
|
|
609
|
+
(_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
|
|
632
610
|
? ((_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);
|
|
633
611
|
if (cachedData) {
|
|
634
612
|
callback(cachedData);
|
|
@@ -804,9 +782,6 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
804
782
|
return providerFactory;
|
|
805
783
|
}
|
|
806
784
|
getSSRProviders(resourceId) {
|
|
807
|
-
if (!fg('platform_synced_block_dogfooding')) {
|
|
808
|
-
return null;
|
|
809
|
-
}
|
|
810
785
|
if (!this.dataProvider) {
|
|
811
786
|
return null;
|
|
812
787
|
}
|
|
@@ -912,6 +887,7 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
912
887
|
}
|
|
913
888
|
let success = true;
|
|
914
889
|
try {
|
|
890
|
+
var _this$saveExperience;
|
|
915
891
|
const blocks = [];
|
|
916
892
|
|
|
917
893
|
// Collect all reference synced blocks on the current document
|
|
@@ -923,14 +899,6 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
923
899
|
});
|
|
924
900
|
});
|
|
925
901
|
});
|
|
926
|
-
if (!fg('platform_synced_block_dogfooding')) {
|
|
927
|
-
// It's possible that the last reference block on the document was just deleted,
|
|
928
|
-
// we still want to write to BE to update reference count
|
|
929
|
-
if (blocks.length === 0) {
|
|
930
|
-
this.isCacheDirty = false;
|
|
931
|
-
return true;
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
902
|
if (!this.dataProvider) {
|
|
935
903
|
throw new Error('Data provider not set');
|
|
936
904
|
}
|
|
@@ -941,40 +909,31 @@ export class ReferenceSyncBlockStoreManager {
|
|
|
941
909
|
// is still making changes, the new changes might not be saved if they all happen
|
|
942
910
|
// exactly at a time when the updateReferenceData is being executed asynchronously.
|
|
943
911
|
this.isCacheDirty = false;
|
|
944
|
-
|
|
945
|
-
var _this$saveExperience;
|
|
946
|
-
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start();
|
|
947
|
-
}
|
|
912
|
+
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start();
|
|
948
913
|
const updateResult = await this.dataProvider.updateReferenceData(blocks);
|
|
949
914
|
if (!updateResult.success) {
|
|
950
|
-
var _this$fireAnalyticsEv19;
|
|
915
|
+
var _this$saveExperience2, _this$fireAnalyticsEv19;
|
|
951
916
|
success = false;
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
reason: updateResult.error || 'Failed to update reference synced blocks on the document'
|
|
956
|
-
});
|
|
957
|
-
}
|
|
917
|
+
(_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 ? void 0 : _this$saveExperience2.failure({
|
|
918
|
+
reason: updateResult.error || 'Failed to update reference synced blocks on the document'
|
|
919
|
+
});
|
|
958
920
|
(_this$fireAnalyticsEv19 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv19 === void 0 ? void 0 : _this$fireAnalyticsEv19.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
|
|
959
921
|
}
|
|
960
922
|
} catch (error) {
|
|
961
|
-
var _this$fireAnalyticsEv20;
|
|
923
|
+
var _this$saveExperience3, _this$fireAnalyticsEv20;
|
|
962
924
|
success = false;
|
|
963
925
|
logException(error, {
|
|
964
926
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
965
927
|
});
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
reason: error.message
|
|
970
|
-
});
|
|
971
|
-
}
|
|
928
|
+
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 ? void 0 : _this$saveExperience3.failure({
|
|
929
|
+
reason: error.message
|
|
930
|
+
});
|
|
972
931
|
(_this$fireAnalyticsEv20 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv20 === void 0 ? void 0 : _this$fireAnalyticsEv20.call(this, updateReferenceErrorPayload(error.message));
|
|
973
932
|
} finally {
|
|
974
933
|
if (!success) {
|
|
975
934
|
// set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
|
|
976
935
|
this.isCacheDirty = true;
|
|
977
|
-
} else
|
|
936
|
+
} else {
|
|
978
937
|
var _this$saveExperience4;
|
|
979
938
|
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 ? void 0 : _this$saveExperience4.success();
|
|
980
939
|
}
|
|
@@ -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';
|
|
@@ -71,6 +70,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
71
70
|
*/
|
|
72
71
|
async flush() {
|
|
73
72
|
try {
|
|
73
|
+
var _this$saveExperience;
|
|
74
74
|
const bodiedSyncBlockNodes = [];
|
|
75
75
|
const bodiedSyncBlockData = [];
|
|
76
76
|
Array.from(this.syncBlockCache.values()).forEach(syncBlockData => {
|
|
@@ -100,10 +100,7 @@ export class SourceSyncBlockStoreManager {
|
|
|
100
100
|
if (!this.dataProvider) {
|
|
101
101
|
throw new Error('Data provider not set');
|
|
102
102
|
}
|
|
103
|
-
|
|
104
|
-
var _this$saveExperience;
|
|
105
|
-
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start({});
|
|
106
|
-
}
|
|
103
|
+
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 ? void 0 : _this$saveExperience.start({});
|
|
107
104
|
const writeResults = await this.dataProvider.writeNodesData(bodiedSyncBlockNodes, bodiedSyncBlockData);
|
|
108
105
|
writeResults.forEach(result => {
|
|
109
106
|
// set isDirty to true for cases where it failed to save the sync block to the BE
|
|
@@ -115,22 +112,18 @@ export class SourceSyncBlockStoreManager {
|
|
|
115
112
|
}
|
|
116
113
|
});
|
|
117
114
|
if (writeResults.every(result => result.resourceId && !result.error)) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
});
|
|
127
|
-
}
|
|
115
|
+
var _this$saveExperience2;
|
|
116
|
+
(_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 ? void 0 : _this$saveExperience2.success();
|
|
117
|
+
writeResults.forEach(result => {
|
|
118
|
+
if (result.resourceId && !result.error) {
|
|
119
|
+
var _this$fireAnalyticsEv2;
|
|
120
|
+
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 ? void 0 : _this$fireAnalyticsEv2.call(this, updateSuccessPayload(result.resourceId, false));
|
|
121
|
+
}
|
|
122
|
+
});
|
|
128
123
|
return true;
|
|
129
124
|
} else {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 ? void 0 : _this$saveExperience3.failure();
|
|
133
|
-
}
|
|
125
|
+
var _this$saveExperience3;
|
|
126
|
+
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 ? void 0 : _this$saveExperience3.failure();
|
|
134
127
|
writeResults.filter(result => !result.resourceId || result.error).forEach(result => {
|
|
135
128
|
var _this$fireAnalyticsEv3;
|
|
136
129
|
(_this$fireAnalyticsEv3 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 ? void 0 : _this$fireAnalyticsEv3.call(this, updateErrorPayload(result.error || 'Failed to write data', result.resourceId));
|
|
@@ -163,12 +156,10 @@ export class SourceSyncBlockStoreManager {
|
|
|
163
156
|
*/
|
|
164
157
|
commitPendingCreation(success) {
|
|
165
158
|
if (success && this.creationCallback) {
|
|
159
|
+
var _this$fireAnalyticsEv5;
|
|
166
160
|
this.creationCallback();
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, createSuccessPayload(this.pendingResourceId || ''));
|
|
170
|
-
}
|
|
171
|
-
} else if (success && !this.creationCallback && fg('platform_synced_block_dogfooding')) {
|
|
161
|
+
(_this$fireAnalyticsEv5 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv5 === void 0 ? void 0 : _this$fireAnalyticsEv5.call(this, createSuccessPayload(this.pendingResourceId || ''));
|
|
162
|
+
} else if (success && !this.creationCallback) {
|
|
172
163
|
var _this$fireAnalyticsEv6;
|
|
173
164
|
(_this$fireAnalyticsEv6 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv6 === void 0 ? void 0 : _this$fireAnalyticsEv6.call(this, createErrorPayload('creation callback missing', this.pendingResourceId));
|
|
174
165
|
}
|
|
@@ -232,11 +223,9 @@ export class SourceSyncBlockStoreManager {
|
|
|
232
223
|
}).then(result => {
|
|
233
224
|
const resourceId = result.resourceId;
|
|
234
225
|
if (resourceId) {
|
|
226
|
+
var _this$createExperienc2;
|
|
235
227
|
this.commitPendingCreation(true);
|
|
236
|
-
|
|
237
|
-
var _this$createExperienc2;
|
|
238
|
-
(_this$createExperienc2 = this.createExperience) === null || _this$createExperienc2 === void 0 ? void 0 : _this$createExperienc2.success();
|
|
239
|
-
}
|
|
228
|
+
(_this$createExperienc2 = this.createExperience) === null || _this$createExperienc2 === void 0 ? void 0 : _this$createExperienc2.success();
|
|
240
229
|
|
|
241
230
|
// Update the sync block data with the node data if it is provided
|
|
242
231
|
// to avoid any race conditions where the data could be missed during a render operation
|
|
@@ -244,28 +233,22 @@ export class SourceSyncBlockStoreManager {
|
|
|
244
233
|
this.updateSyncBlockData(nodeData);
|
|
245
234
|
}
|
|
246
235
|
} else {
|
|
247
|
-
var _this$fireAnalyticsEv7;
|
|
236
|
+
var _this$createExperienc3, _this$fireAnalyticsEv7;
|
|
248
237
|
this.commitPendingCreation(false);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
reason: result.error || 'Failed to create bodied sync block'
|
|
253
|
-
});
|
|
254
|
-
}
|
|
238
|
+
(_this$createExperienc3 = this.createExperience) === null || _this$createExperienc3 === void 0 ? void 0 : _this$createExperienc3.failure({
|
|
239
|
+
reason: result.error || 'Failed to create bodied sync block'
|
|
240
|
+
});
|
|
255
241
|
(_this$fireAnalyticsEv7 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv7 === void 0 ? void 0 : _this$fireAnalyticsEv7.call(this, createErrorPayload(result.error || 'Failed to create bodied sync block', resourceId));
|
|
256
242
|
}
|
|
257
243
|
}).catch(error => {
|
|
258
|
-
var _this$fireAnalyticsEv8;
|
|
244
|
+
var _this$createExperienc4, _this$fireAnalyticsEv8;
|
|
259
245
|
this.commitPendingCreation(false);
|
|
260
246
|
logException(error, {
|
|
261
247
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
262
248
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
reason: error.message
|
|
267
|
-
});
|
|
268
|
-
}
|
|
249
|
+
(_this$createExperienc4 = this.createExperience) === null || _this$createExperienc4 === void 0 ? void 0 : _this$createExperienc4.failure({
|
|
250
|
+
reason: error.message
|
|
251
|
+
});
|
|
269
252
|
(_this$fireAnalyticsEv8 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv8 === void 0 ? void 0 : _this$fireAnalyticsEv8.call(this, createErrorPayload(error.message, resourceId));
|
|
270
253
|
});
|
|
271
254
|
this.registerPendingCreation(resourceId);
|
|
@@ -282,62 +265,51 @@ export class SourceSyncBlockStoreManager {
|
|
|
282
265
|
}
|
|
283
266
|
async delete(syncBlockIds, onDelete, onDeleteCompleted, reason) {
|
|
284
267
|
try {
|
|
268
|
+
var _this$deleteExperienc;
|
|
285
269
|
if (!this.dataProvider) {
|
|
286
270
|
throw new Error('Data provider not set');
|
|
287
271
|
}
|
|
288
272
|
syncBlockIds.forEach(Ids => {
|
|
289
273
|
this.setPendingDeletion(Ids, true);
|
|
290
274
|
});
|
|
291
|
-
|
|
292
|
-
var _this$deleteExperienc;
|
|
293
|
-
(_this$deleteExperienc = this.deleteExperience) === null || _this$deleteExperienc === void 0 ? void 0 : _this$deleteExperienc.start({});
|
|
294
|
-
}
|
|
275
|
+
(_this$deleteExperienc = this.deleteExperience) === null || _this$deleteExperienc === void 0 ? void 0 : _this$deleteExperienc.start({});
|
|
295
276
|
const results = await this.dataProvider.deleteNodesData(syncBlockIds.map(attrs => attrs.resourceId), reason);
|
|
296
277
|
let callback;
|
|
297
278
|
const isDeleteSuccessful = results.every(result => result.success);
|
|
298
279
|
onDeleteCompleted(isDeleteSuccessful);
|
|
299
280
|
if (isDeleteSuccessful) {
|
|
281
|
+
var _this$deleteExperienc2;
|
|
300
282
|
onDelete();
|
|
301
283
|
callback = Ids => this.syncBlockCache.delete(Ids.resourceId);
|
|
302
284
|
this.clearPendingDeletion();
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, deleteSuccessPayload(result.resourceId));
|
|
309
|
-
});
|
|
310
|
-
}
|
|
285
|
+
(_this$deleteExperienc2 = this.deleteExperience) === null || _this$deleteExperienc2 === void 0 ? void 0 : _this$deleteExperienc2.success();
|
|
286
|
+
results.forEach(result => {
|
|
287
|
+
var _this$fireAnalyticsEv0;
|
|
288
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 ? void 0 : _this$fireAnalyticsEv0.call(this, deleteSuccessPayload(result.resourceId));
|
|
289
|
+
});
|
|
311
290
|
} else {
|
|
291
|
+
var _this$deleteExperienc3;
|
|
312
292
|
callback = Ids => {
|
|
313
293
|
this.setPendingDeletion(Ids, false);
|
|
314
294
|
};
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
}
|
|
326
|
-
});
|
|
327
|
-
} else {
|
|
328
|
-
results.filter(result => result.resourceId === undefined).forEach(result => {
|
|
329
|
-
var _this$fireAnalyticsEv11;
|
|
330
|
-
(_this$fireAnalyticsEv11 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv11 === void 0 ? void 0 : _this$fireAnalyticsEv11.call(this, deleteErrorPayload(result.error || 'Failed to delete synced block'));
|
|
331
|
-
});
|
|
332
|
-
}
|
|
295
|
+
(_this$deleteExperienc3 = this.deleteExperience) === null || _this$deleteExperienc3 === void 0 ? void 0 : _this$deleteExperienc3.failure();
|
|
296
|
+
results.forEach(result => {
|
|
297
|
+
if (result.success) {
|
|
298
|
+
var _this$fireAnalyticsEv1;
|
|
299
|
+
(_this$fireAnalyticsEv1 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv1 === void 0 ? void 0 : _this$fireAnalyticsEv1.call(this, deleteSuccessPayload(result.resourceId));
|
|
300
|
+
} else {
|
|
301
|
+
var _this$fireAnalyticsEv10;
|
|
302
|
+
(_this$fireAnalyticsEv10 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv10 === void 0 ? void 0 : _this$fireAnalyticsEv10.call(this, deleteErrorPayload(result.error || 'Failed to delete synced block', result.resourceId));
|
|
303
|
+
}
|
|
304
|
+
});
|
|
333
305
|
}
|
|
334
306
|
syncBlockIds.forEach(callback);
|
|
335
307
|
return isDeleteSuccessful;
|
|
336
308
|
} catch (error) {
|
|
337
309
|
syncBlockIds.forEach(Ids => {
|
|
338
|
-
var _this$
|
|
310
|
+
var _this$fireAnalyticsEv11;
|
|
339
311
|
this.setPendingDeletion(Ids, false);
|
|
340
|
-
(_this$
|
|
312
|
+
(_this$fireAnalyticsEv11 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv11 === void 0 ? void 0 : _this$fireAnalyticsEv11.call(this, deleteErrorPayload(error.message, Ids.resourceId));
|
|
341
313
|
});
|
|
342
314
|
logException(error, {
|
|
343
315
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
@@ -400,33 +372,29 @@ export class SourceSyncBlockStoreManager {
|
|
|
400
372
|
}
|
|
401
373
|
getSyncBlockSourceInfo(localId) {
|
|
402
374
|
try {
|
|
375
|
+
var _this$fetchSourceInfo;
|
|
403
376
|
if (!this.dataProvider) {
|
|
404
377
|
throw new Error('Data provider not set');
|
|
405
378
|
}
|
|
406
|
-
|
|
407
|
-
var _this$fetchSourceInfo;
|
|
408
|
-
(_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start();
|
|
409
|
-
}
|
|
379
|
+
(_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 ? void 0 : _this$fetchSourceInfo.start();
|
|
410
380
|
return this.dataProvider.fetchSyncBlockSourceInfo(localId, undefined, undefined, this.fireAnalyticsEvent).then(sourceInfo => {
|
|
411
|
-
if (
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
(_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 ? void 0 : _this$fetchSourceInfo3.success();
|
|
420
|
-
}
|
|
381
|
+
if (!sourceInfo) {
|
|
382
|
+
var _this$fetchSourceInfo2;
|
|
383
|
+
(_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 ? void 0 : _this$fetchSourceInfo2.failure({
|
|
384
|
+
reason: 'No source info returned'
|
|
385
|
+
});
|
|
386
|
+
} else {
|
|
387
|
+
var _this$fetchSourceInfo3;
|
|
388
|
+
(_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 ? void 0 : _this$fetchSourceInfo3.success();
|
|
421
389
|
}
|
|
422
390
|
return sourceInfo;
|
|
423
391
|
});
|
|
424
392
|
} catch (error) {
|
|
425
|
-
var _this$
|
|
393
|
+
var _this$fireAnalyticsEv12;
|
|
426
394
|
logException(error, {
|
|
427
395
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
428
396
|
});
|
|
429
|
-
(_this$
|
|
397
|
+
(_this$fireAnalyticsEv12 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv12 === void 0 ? void 0 : _this$fireAnalyticsEv12.call(this, getSourceInfoErrorPayload(error.message));
|
|
430
398
|
return Promise.resolve(undefined);
|
|
431
399
|
}
|
|
432
400
|
}
|
|
@@ -437,11 +405,11 @@ export class SourceSyncBlockStoreManager {
|
|
|
437
405
|
}
|
|
438
406
|
return this.dataProvider.fetchReferences(resourceId, true);
|
|
439
407
|
} catch (error) {
|
|
440
|
-
var _this$
|
|
408
|
+
var _this$fireAnalyticsEv13;
|
|
441
409
|
logException(error, {
|
|
442
410
|
location: 'editor-synced-block-provider/sourceSyncBlockStoreManager'
|
|
443
411
|
});
|
|
444
|
-
(_this$
|
|
412
|
+
(_this$fireAnalyticsEv13 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv13 === void 0 ? void 0 : _this$fireAnalyticsEv13.call(this, fetchReferencesErrorPayload(error.message));
|
|
445
413
|
return Promise.resolve({
|
|
446
414
|
error: SyncBlockError.Errored
|
|
447
415
|
});
|
|
@@ -105,10 +105,8 @@ export class SyncBlockStoreManager {
|
|
|
105
105
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
106
106
|
this.referenceSyncBlockStoreManager.setFireAnalyticsEvent(fireAnalyticsEvent);
|
|
107
107
|
this.sourceSyncBlockStoreManager.setFireAnalyticsEvent(fireAnalyticsEvent);
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
this.fetchSourceInfoExperience = getFetchSourceInfoExperience(fireAnalyticsEvent);
|
|
111
|
-
}
|
|
108
|
+
this.fetchReferencesExperience = getFetchReferencesExperience(fireAnalyticsEvent);
|
|
109
|
+
this.fetchSourceInfoExperience = getFetchSourceInfoExperience(fireAnalyticsEvent);
|
|
112
110
|
}
|
|
113
111
|
get referenceManager() {
|
|
114
112
|
return this.referenceSyncBlockStoreManager;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, EVENT_TYPE, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
|
|
2
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
3
2
|
export const stringifyError = error => {
|
|
4
3
|
try {
|
|
5
4
|
return JSON.stringify(error);
|
|
@@ -12,13 +11,11 @@ export const getErrorPayload = (actionSubjectId, error, resourceId) => ({
|
|
|
12
11
|
actionSubject: ACTION_SUBJECT.SYNCED_BLOCK,
|
|
13
12
|
actionSubjectId,
|
|
14
13
|
eventType: EVENT_TYPE.OPERATIONAL,
|
|
15
|
-
attributes:
|
|
14
|
+
attributes: {
|
|
16
15
|
error,
|
|
17
16
|
...(resourceId && {
|
|
18
17
|
resourceId
|
|
19
18
|
})
|
|
20
|
-
} : {
|
|
21
|
-
error
|
|
22
19
|
}
|
|
23
20
|
});
|
|
24
21
|
export const fetchErrorPayload = (error, resourceId) => getErrorPayload(ACTION_SUBJECT_ID.SYNCED_BLOCK_FETCH, error, resourceId);
|