@atlaskit/editor-synced-block-provider 3.5.5 → 3.6.0
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 +13 -0
- package/dist/cjs/clients/confluence/sourceInfo.js +77 -3
- package/dist/cjs/common/consts.js +7 -0
- package/dist/cjs/hooks/useFetchSyncBlockData.js +10 -2
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +218 -48
- package/dist/cjs/store-manager/sourceSyncBlockStoreManager.js +117 -34
- package/dist/cjs/utils/parseResourceId.js +38 -0
- package/dist/es2019/clients/confluence/sourceInfo.js +34 -1
- package/dist/es2019/common/consts.js +1 -0
- package/dist/es2019/hooks/useFetchSyncBlockData.js +10 -1
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +200 -24
- package/dist/es2019/store-manager/sourceSyncBlockStoreManager.js +85 -15
- package/dist/es2019/utils/parseResourceId.js +25 -0
- package/dist/esm/clients/confluence/sourceInfo.js +76 -2
- package/dist/esm/common/consts.js +1 -0
- package/dist/esm/hooks/useFetchSyncBlockData.js +10 -2
- package/dist/esm/index.js +1 -0
- package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +218 -48
- package/dist/esm/store-manager/sourceSyncBlockStoreManager.js +117 -34
- package/dist/esm/utils/parseResourceId.js +31 -0
- package/dist/types/clients/confluence/sourceInfo.d.ts +2 -0
- package/dist/types/common/consts.d.ts +1 -0
- package/dist/types/common/types.d.ts +2 -1
- package/dist/types/hooks/useFetchSyncBlockData.d.ts +6 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/providers/types.d.ts +1 -0
- package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +8 -0
- package/dist/types/store-manager/sourceSyncBlockStoreManager.d.ts +4 -0
- package/dist/types/utils/parseResourceId.d.ts +6 -0
- package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +2 -0
- package/dist/types-ts4.5/common/consts.d.ts +4 -0
- package/dist/types-ts4.5/common/types.d.ts +2 -1
- package/dist/types-ts4.5/hooks/useFetchSyncBlockData.d.ts +6 -1
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/providers/types.d.ts +1 -0
- package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +8 -0
- package/dist/types-ts4.5/store-manager/sourceSyncBlockStoreManager.d.ts +4 -0
- package/dist/types-ts4.5/utils/parseResourceId.d.ts +6 -0
- package/package.json +2 -2
|
@@ -6,6 +6,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
6
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
7
|
import { useCallback, useEffect, useState } from 'react';
|
|
8
8
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
9
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
10
|
import { SyncBlockError } from '../common/types';
|
|
10
11
|
import { fetchErrorPayload } from '../utils/errorHandling';
|
|
11
12
|
import { createSyncBlockNode } from '../utils/utils';
|
|
@@ -34,7 +35,7 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
|
|
|
34
35
|
isLoading = _useState2$.isLoading,
|
|
35
36
|
setFetchState = _useState2[1];
|
|
36
37
|
var reloadData = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
37
|
-
var syncBlockNode;
|
|
38
|
+
var syncBlockNode, _manager$referenceMan2;
|
|
38
39
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
39
40
|
while (1) switch (_context.prev = _context.next) {
|
|
40
41
|
case 0:
|
|
@@ -70,7 +71,13 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
|
|
|
70
71
|
logException(_context.t0, {
|
|
71
72
|
location: 'editor-synced-block-provider/useFetchSyncBlockData'
|
|
72
73
|
});
|
|
73
|
-
|
|
74
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
75
|
+
manager === null || manager === void 0 || (_manager$referenceMan2 = manager.referenceManager) === null || _manager$referenceMan2 === void 0 || (_manager$referenceMan2 = _manager$referenceMan2.fetchExperience) === null || _manager$referenceMan2 === void 0 || _manager$referenceMan2.failure({
|
|
76
|
+
reason: _context.t0.message
|
|
77
|
+
});
|
|
78
|
+
} else {
|
|
79
|
+
fireAnalyticsEvent === null || fireAnalyticsEvent === void 0 || fireAnalyticsEvent(fetchErrorPayload(_context.t0.message));
|
|
80
|
+
}
|
|
74
81
|
|
|
75
82
|
// Set error state if fetching fails
|
|
76
83
|
setFetchState({
|
|
@@ -106,6 +113,7 @@ export var useFetchSyncBlockData = function useFetchSyncBlockData(manager, resou
|
|
|
106
113
|
}, [localId, manager.referenceManager, resourceId]);
|
|
107
114
|
return {
|
|
108
115
|
isLoading: isLoading,
|
|
116
|
+
ssrProviders: resourceId ? manager.referenceManager.getSSRProviders(resourceId) : null,
|
|
109
117
|
providerFactory: manager.referenceManager.getProviderFactory(resourceId || ''),
|
|
110
118
|
reloadData: reloadData,
|
|
111
119
|
syncBlockInstance: syncBlockInstance
|
package/dist/esm/index.js
CHANGED
|
@@ -25,6 +25,7 @@ export { SyncBlockStoreManager, useMemoizedSyncBlockStoreManager } from './store
|
|
|
25
25
|
|
|
26
26
|
// utils
|
|
27
27
|
export { resolveSyncBlockInstance } from './utils/resolveSyncBlockInstance';
|
|
28
|
+
export { parseResourceId } from './utils/parseResourceId';
|
|
28
29
|
export { createSyncBlockNode, convertSyncBlockPMNodeToSyncBlockData, convertSyncBlockJSONNodeToSyncBlockNode, convertPMNodesToSyncBlockNodes, getContentIdAndProductFromResourceId } from './utils/utils';
|
|
29
30
|
export { fetchErrorPayload } from './utils/errorHandling';
|
|
30
31
|
export { fetchReferences } from './providers/block-service/blockServiceAPI';
|
|
@@ -11,8 +11,10 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
11
11
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
12
12
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
13
13
|
import { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
|
|
14
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
14
15
|
import { SyncBlockError } from '../common/types';
|
|
15
16
|
import { fetchErrorPayload, getSourceInfoErrorPayload, updateReferenceErrorPayload } from '../utils/errorHandling';
|
|
17
|
+
import { parseResourceId } from '../utils/parseResourceId';
|
|
16
18
|
import { resolveSyncBlockInstance } from '../utils/resolveSyncBlockInstance';
|
|
17
19
|
import { createSyncBlockNode } from '../utils/utils';
|
|
18
20
|
|
|
@@ -48,6 +50,16 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
48
50
|
value: function setFireAnalyticsEvent(fireAnalyticsEvent) {
|
|
49
51
|
this.fireAnalyticsEvent = fireAnalyticsEvent;
|
|
50
52
|
}
|
|
53
|
+
}, {
|
|
54
|
+
key: "setExperiences",
|
|
55
|
+
value: function setExperiences(fetchExperience, fetchSourceInfoExperience, saveExperience) {
|
|
56
|
+
// don't reset experiences after they have already been set
|
|
57
|
+
if (!this.fetchExperience || !this.fetchSourceInfoExperience || !this.saveExperience) {
|
|
58
|
+
this.fetchExperience = fetchExperience;
|
|
59
|
+
this.fetchSourceInfoExperience = fetchSourceInfoExperience;
|
|
60
|
+
this.saveExperience = saveExperience;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
51
63
|
}, {
|
|
52
64
|
key: "generateResourceIdForReference",
|
|
53
65
|
value: function generateResourceIdForReference(sourceId) {
|
|
@@ -77,7 +89,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
77
89
|
key: "refreshSubscriptions",
|
|
78
90
|
value: (function () {
|
|
79
91
|
var _refreshSubscriptions = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
80
|
-
var syncBlocks, _iterator, _step, _loop, _this$fireAnalyticsEv;
|
|
92
|
+
var syncBlocks, _iterator, _step, _loop, _this$fetchExperience, _this$fireAnalyticsEv;
|
|
81
93
|
return _regeneratorRuntime.wrap(function _callee$(_context2) {
|
|
82
94
|
while (1) switch (_context2.prev = _context2.next) {
|
|
83
95
|
case 0:
|
|
@@ -140,7 +152,13 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
140
152
|
logException(_context2.t2, {
|
|
141
153
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
142
154
|
});
|
|
143
|
-
|
|
155
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
156
|
+
(_this$fetchExperience = this.fetchExperience) === null || _this$fetchExperience === void 0 || _this$fetchExperience.failure({
|
|
157
|
+
reason: _context2.t2.message
|
|
158
|
+
});
|
|
159
|
+
} else {
|
|
160
|
+
(_this$fireAnalyticsEv = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv === void 0 || _this$fireAnalyticsEv.call(this, fetchErrorPayload(_context2.t2.message));
|
|
161
|
+
}
|
|
144
162
|
case 29:
|
|
145
163
|
_context2.prev = 29;
|
|
146
164
|
this.isRefreshingSubscriptions = false;
|
|
@@ -163,6 +181,11 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
163
181
|
try {
|
|
164
182
|
var _existingSyncBlock$da, _existingSyncBlock$da2;
|
|
165
183
|
if (!resourceId || !this.dataProvider) {
|
|
184
|
+
// make sure experience has been started before throwing error
|
|
185
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
186
|
+
var _this$fetchSourceInfo;
|
|
187
|
+
(_this$fetchSourceInfo = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo === void 0 || _this$fetchSourceInfo.start({});
|
|
188
|
+
}
|
|
166
189
|
throw new Error('Data provider or resourceId not set');
|
|
167
190
|
}
|
|
168
191
|
if (this.syncBlockSourceInfoRequests.get(resourceId)) {
|
|
@@ -170,6 +193,10 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
170
193
|
}
|
|
171
194
|
var existingSyncBlock = this.getFromCache(resourceId);
|
|
172
195
|
if (!existingSyncBlock) {
|
|
196
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
197
|
+
var _this$fetchSourceInfo2;
|
|
198
|
+
(_this$fetchSourceInfo2 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo2 === void 0 || _this$fetchSourceInfo2.start({});
|
|
199
|
+
}
|
|
173
200
|
throw new Error('No existing sync block to fetch source info for');
|
|
174
201
|
}
|
|
175
202
|
|
|
@@ -177,36 +204,80 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
177
204
|
if ((_existingSyncBlock$da = existingSyncBlock.data) !== null && _existingSyncBlock$da !== void 0 && _existingSyncBlock$da.sourceURL && (_existingSyncBlock$da2 = existingSyncBlock.data) !== null && _existingSyncBlock$da2 !== void 0 && _existingSyncBlock$da2.sourceTitle) {
|
|
178
205
|
return;
|
|
179
206
|
}
|
|
207
|
+
|
|
208
|
+
// only start experience if there is data to fetch
|
|
209
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
210
|
+
var _this$fetchSourceInfo3;
|
|
211
|
+
(_this$fetchSourceInfo3 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo3 === void 0 || _this$fetchSourceInfo3.start({});
|
|
212
|
+
}
|
|
180
213
|
var _ref = existingSyncBlock.data || {},
|
|
181
214
|
sourceAri = _ref.sourceAri,
|
|
182
215
|
product = _ref.product,
|
|
183
216
|
blockInstanceId = _ref.blockInstanceId;
|
|
184
217
|
if (!sourceAri || !product || !blockInstanceId) {
|
|
185
|
-
|
|
186
|
-
|
|
218
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
219
|
+
var _this$fetchSourceInfo4;
|
|
220
|
+
(_this$fetchSourceInfo4 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo4 === void 0 || _this$fetchSourceInfo4.failure({
|
|
221
|
+
reason: 'SourceAri, product or blockInstanceId missing'
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
var _this$fireAnalyticsEv2;
|
|
225
|
+
(_this$fireAnalyticsEv2 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv2 === void 0 || _this$fireAnalyticsEv2.call(this, getSourceInfoErrorPayload('SourceAri, product or blockInstanceId missing'));
|
|
226
|
+
}
|
|
187
227
|
return;
|
|
188
228
|
}
|
|
189
229
|
this.syncBlockSourceInfoRequests.set(resourceId, true);
|
|
190
230
|
this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product, this.fireAnalyticsEvent).then(function (sourceInfo) {
|
|
191
231
|
if (!sourceInfo) {
|
|
232
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
233
|
+
var _this$fetchSourceInfo5;
|
|
234
|
+
(_this$fetchSourceInfo5 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo5 === void 0 || _this$fetchSourceInfo5.failure({
|
|
235
|
+
reason: 'No source info returned'
|
|
236
|
+
});
|
|
237
|
+
}
|
|
192
238
|
return;
|
|
193
239
|
}
|
|
194
240
|
_this.updateCacheWithSourceInfo(resourceId, sourceInfo);
|
|
195
241
|
if (sourceInfo.title) {
|
|
196
242
|
_this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
|
|
197
243
|
}
|
|
244
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
245
|
+
if (sourceInfo.title && sourceInfo.url) {
|
|
246
|
+
var _this$fetchSourceInfo6;
|
|
247
|
+
(_this$fetchSourceInfo6 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo6 === void 0 || _this$fetchSourceInfo6.success();
|
|
248
|
+
} else {
|
|
249
|
+
var _this$fetchSourceInfo7;
|
|
250
|
+
(_this$fetchSourceInfo7 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo7 === void 0 || _this$fetchSourceInfo7.failure({
|
|
251
|
+
reason: 'Missing title or url'
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
198
255
|
}).catch(function (error) {
|
|
199
|
-
|
|
200
|
-
|
|
256
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
257
|
+
var _this$fetchSourceInfo8;
|
|
258
|
+
(_this$fetchSourceInfo8 = _this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo8 === void 0 || _this$fetchSourceInfo8.failure({
|
|
259
|
+
reason: error.message
|
|
260
|
+
});
|
|
261
|
+
} else {
|
|
262
|
+
var _this$fireAnalyticsEv3;
|
|
263
|
+
(_this$fireAnalyticsEv3 = _this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv3 === void 0 || _this$fireAnalyticsEv3.call(_this, getSourceInfoErrorPayload(error.message));
|
|
264
|
+
}
|
|
201
265
|
}).finally(function () {
|
|
202
266
|
_this.syncBlockSourceInfoRequests.delete(resourceId);
|
|
203
267
|
});
|
|
204
268
|
} catch (error) {
|
|
205
|
-
var _this$fireAnalyticsEv4;
|
|
206
269
|
logException(error, {
|
|
207
270
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
208
271
|
});
|
|
209
|
-
|
|
272
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
273
|
+
var _this$fetchSourceInfo9;
|
|
274
|
+
(_this$fetchSourceInfo9 = this.fetchSourceInfoExperience) === null || _this$fetchSourceInfo9 === void 0 || _this$fetchSourceInfo9.failure({
|
|
275
|
+
reason: error.message
|
|
276
|
+
});
|
|
277
|
+
} else {
|
|
278
|
+
var _this$fireAnalyticsEv4;
|
|
279
|
+
(_this$fireAnalyticsEv4 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv4 === void 0 || _this$fireAnalyticsEv4.call(this, getSourceInfoErrorPayload(error.message));
|
|
280
|
+
}
|
|
210
281
|
}
|
|
211
282
|
}
|
|
212
283
|
|
|
@@ -220,7 +291,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
220
291
|
value: (function () {
|
|
221
292
|
var _fetchSyncBlocksData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(syncBlockNodes) {
|
|
222
293
|
var _this2 = this;
|
|
223
|
-
var nodesToFetch, data, resolvedData;
|
|
294
|
+
var nodesToFetch, _this$fetchExperience2, data, resolvedData, successfulFetched, failedFetch, _this$fetchExperience3, _this$fetchExperience4;
|
|
224
295
|
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
225
296
|
while (1) switch (_context3.prev = _context3.next) {
|
|
226
297
|
case 0:
|
|
@@ -230,12 +301,6 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
230
301
|
}
|
|
231
302
|
return _context3.abrupt("return");
|
|
232
303
|
case 2:
|
|
233
|
-
if (this.dataProvider) {
|
|
234
|
-
_context3.next = 4;
|
|
235
|
-
break;
|
|
236
|
-
}
|
|
237
|
-
throw new Error('Data provider not set');
|
|
238
|
-
case 4:
|
|
239
304
|
// Don't fetch for not_found error since the source is already deleted
|
|
240
305
|
nodesToFetch = [];
|
|
241
306
|
syncBlockNodes.forEach(function (node) {
|
|
@@ -249,27 +314,45 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
249
314
|
nodesToFetch.push(node);
|
|
250
315
|
});
|
|
251
316
|
if (!(nodesToFetch.length === 0)) {
|
|
252
|
-
_context3.next =
|
|
317
|
+
_context3.next = 6;
|
|
253
318
|
break;
|
|
254
319
|
}
|
|
255
320
|
return _context3.abrupt("return");
|
|
256
|
-
case
|
|
321
|
+
case 6:
|
|
322
|
+
// only start fetch experience if there is data to fetch
|
|
323
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
324
|
+
(_this$fetchExperience2 = this.fetchExperience) === null || _this$fetchExperience2 === void 0 || _this$fetchExperience2.start({});
|
|
325
|
+
}
|
|
326
|
+
if (this.dataProvider) {
|
|
327
|
+
_context3.next = 9;
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
throw new Error('Data provider not set');
|
|
331
|
+
case 9:
|
|
257
332
|
nodesToFetch.forEach(function (node) {
|
|
258
333
|
_this2.syncBlockFetchDataRequests.set(node.attrs.resourceId, true);
|
|
259
334
|
});
|
|
260
|
-
_context3.next =
|
|
335
|
+
_context3.next = 12;
|
|
261
336
|
return this.dataProvider.fetchNodesData(nodesToFetch).finally(function () {
|
|
262
337
|
nodesToFetch.forEach(function (node) {
|
|
263
338
|
_this2.syncBlockFetchDataRequests.delete(node.attrs.resourceId);
|
|
264
339
|
});
|
|
265
340
|
});
|
|
266
|
-
case
|
|
341
|
+
case 12:
|
|
267
342
|
data = _context3.sent;
|
|
268
343
|
resolvedData = [];
|
|
344
|
+
successfulFetched = [];
|
|
345
|
+
failedFetch = [];
|
|
269
346
|
data.forEach(function (syncBlockInstance) {
|
|
270
347
|
if (!syncBlockInstance.resourceId) {
|
|
271
|
-
|
|
272
|
-
|
|
348
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
349
|
+
failedFetch.push({
|
|
350
|
+
reason: syncBlockInstance.error || 'Returned sync block instance does not have resource id'
|
|
351
|
+
});
|
|
352
|
+
} else {
|
|
353
|
+
var _this2$fireAnalyticsE;
|
|
354
|
+
(_this2$fireAnalyticsE = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE === void 0 || _this2$fireAnalyticsE.call(_this2, fetchErrorPayload(syncBlockInstance.error || 'Returned sync block instance does not have resource id'));
|
|
355
|
+
}
|
|
273
356
|
return;
|
|
274
357
|
}
|
|
275
358
|
var existingSyncBlock = _this2.getFromCache(syncBlockInstance.resourceId);
|
|
@@ -277,13 +360,39 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
277
360
|
_this2.updateCache(resolvedSyncBlockInstance);
|
|
278
361
|
resolvedData.push(resolvedSyncBlockInstance);
|
|
279
362
|
if (syncBlockInstance.error) {
|
|
280
|
-
|
|
281
|
-
|
|
363
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
364
|
+
failedFetch.push({
|
|
365
|
+
reason: syncBlockInstance.error,
|
|
366
|
+
resourceId: syncBlockInstance.resourceId
|
|
367
|
+
});
|
|
368
|
+
} else {
|
|
369
|
+
var _this2$fireAnalyticsE2;
|
|
370
|
+
(_this2$fireAnalyticsE2 = _this2.fireAnalyticsEvent) === null || _this2$fireAnalyticsE2 === void 0 || _this2$fireAnalyticsE2.call(_this2, fetchErrorPayload(syncBlockInstance.error));
|
|
371
|
+
}
|
|
282
372
|
return;
|
|
283
373
|
}
|
|
374
|
+
successfulFetched.push(syncBlockInstance.resourceId);
|
|
284
375
|
_this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
|
|
285
376
|
});
|
|
286
|
-
|
|
377
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
378
|
+
if (data.every(function (syncBlockInstance) {
|
|
379
|
+
return syncBlockInstance.resourceId && !syncBlockInstance.error;
|
|
380
|
+
})) {
|
|
381
|
+
(_this$fetchExperience3 = this.fetchExperience) === null || _this$fetchExperience3 === void 0 || _this$fetchExperience3.success({
|
|
382
|
+
metadata: {
|
|
383
|
+
successfulFetched: successfulFetched
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
} else {
|
|
387
|
+
(_this$fetchExperience4 = this.fetchExperience) === null || _this$fetchExperience4 === void 0 || _this$fetchExperience4.failure({
|
|
388
|
+
metadata: {
|
|
389
|
+
successfulFetched: successfulFetched,
|
|
390
|
+
failedFetch: failedFetch
|
|
391
|
+
}
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
case 18:
|
|
287
396
|
case "end":
|
|
288
397
|
return _context3.stop();
|
|
289
398
|
}
|
|
@@ -372,11 +481,18 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
372
481
|
callback(cachedData);
|
|
373
482
|
} else {
|
|
374
483
|
this.fetchSyncBlocksData([syncBlockNode]).catch(function (error) {
|
|
375
|
-
var _this3$fireAnalyticsE;
|
|
376
484
|
logException(error, {
|
|
377
485
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
378
486
|
});
|
|
379
|
-
|
|
487
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
488
|
+
var _this3$fetchExperienc;
|
|
489
|
+
(_this3$fetchExperienc = _this3.fetchExperience) === null || _this3$fetchExperienc === void 0 || _this3$fetchExperienc.failure({
|
|
490
|
+
reason: error.message
|
|
491
|
+
});
|
|
492
|
+
} else {
|
|
493
|
+
var _this3$fireAnalyticsE;
|
|
494
|
+
(_this3$fireAnalyticsE = _this3.fireAnalyticsEvent) === null || _this3$fireAnalyticsE === void 0 || _this3$fireAnalyticsE.call(_this3, fetchErrorPayload(error.message));
|
|
495
|
+
}
|
|
380
496
|
});
|
|
381
497
|
}
|
|
382
498
|
return function () {
|
|
@@ -528,6 +644,43 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
528
644
|
}
|
|
529
645
|
return providerFactory;
|
|
530
646
|
}
|
|
647
|
+
}, {
|
|
648
|
+
key: "getSSRProviders",
|
|
649
|
+
value: function getSSRProviders(resourceId) {
|
|
650
|
+
if (!fg('platform_synced_block_dogfooding')) {
|
|
651
|
+
return null;
|
|
652
|
+
}
|
|
653
|
+
if (!this.dataProvider) {
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
var _this$dataProvider$ge2 = this.dataProvider.getSyncedBlockRendererProviderOptions(),
|
|
657
|
+
providerCreator = _this$dataProvider$ge2.providerCreator;
|
|
658
|
+
if (!(providerCreator !== null && providerCreator !== void 0 && providerCreator.createSSRMediaProvider)) {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
var parsedResourceId = parseResourceId(resourceId);
|
|
662
|
+
if (!parsedResourceId) {
|
|
663
|
+
return null;
|
|
664
|
+
}
|
|
665
|
+
var contentId = parsedResourceId.contentId,
|
|
666
|
+
contentProduct = parsedResourceId.product;
|
|
667
|
+
try {
|
|
668
|
+
var mediaProvider = providerCreator.createSSRMediaProvider({
|
|
669
|
+
contentId: contentId,
|
|
670
|
+
contentProduct: contentProduct
|
|
671
|
+
});
|
|
672
|
+
if (mediaProvider) {
|
|
673
|
+
return {
|
|
674
|
+
media: mediaProvider
|
|
675
|
+
};
|
|
676
|
+
}
|
|
677
|
+
} catch (error) {
|
|
678
|
+
logException(error, {
|
|
679
|
+
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
return null;
|
|
683
|
+
}
|
|
531
684
|
}, {
|
|
532
685
|
key: "retrieveDynamicProviders",
|
|
533
686
|
value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
|
|
@@ -585,7 +738,7 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
585
738
|
key: "flush",
|
|
586
739
|
value: (function () {
|
|
587
740
|
var _flush = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
588
|
-
var success, blocks, updateResult, _this$fireAnalyticsEv9, _this$fireAnalyticsEv0;
|
|
741
|
+
var success, blocks, _this$saveExperience, updateResult, _this$saveExperience2, _this$fireAnalyticsEv9, _this$saveExperience3, _this$fireAnalyticsEv0, _this$saveExperience4;
|
|
589
742
|
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
590
743
|
while (1) switch (_context4.prev = _context4.next) {
|
|
591
744
|
case 0:
|
|
@@ -597,12 +750,6 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
597
750
|
case 2:
|
|
598
751
|
success = true;
|
|
599
752
|
_context4.prev = 3;
|
|
600
|
-
if (this.dataProvider) {
|
|
601
|
-
_context4.next = 6;
|
|
602
|
-
break;
|
|
603
|
-
}
|
|
604
|
-
throw new Error('Data provider not set');
|
|
605
|
-
case 6:
|
|
606
753
|
blocks = []; // Collect all reference synced blocks on the current document
|
|
607
754
|
Array.from(this.subscriptions.entries()).forEach(function (_ref2) {
|
|
608
755
|
var _ref3 = _slicedToArray(_ref2, 2),
|
|
@@ -616,50 +763,73 @@ export var ReferenceSyncBlockStoreManager = /*#__PURE__*/function () {
|
|
|
616
763
|
});
|
|
617
764
|
});
|
|
618
765
|
if (!(blocks.length === 0)) {
|
|
619
|
-
_context4.next =
|
|
766
|
+
_context4.next = 9;
|
|
620
767
|
break;
|
|
621
768
|
}
|
|
622
769
|
this.isCacheDirty = false;
|
|
623
770
|
return _context4.abrupt("return", true);
|
|
624
|
-
case
|
|
771
|
+
case 9:
|
|
772
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
773
|
+
(_this$saveExperience = this.saveExperience) === null || _this$saveExperience === void 0 || _this$saveExperience.start();
|
|
774
|
+
}
|
|
775
|
+
if (this.dataProvider) {
|
|
776
|
+
_context4.next = 12;
|
|
777
|
+
break;
|
|
778
|
+
}
|
|
779
|
+
throw new Error('Data provider not set');
|
|
780
|
+
case 12:
|
|
625
781
|
// reset isCacheDirty early to prevent race condition
|
|
626
782
|
// There is a race condition where if a user makes changes (create/delete) to a reference sync block
|
|
627
783
|
// on a live page and the reference sync block is being saved while the user
|
|
628
784
|
// is still making changes, the new changes might not be saved if they all happen
|
|
629
785
|
// exactly at a time when the updateReferenceData is being executed asynchronously.
|
|
630
786
|
this.isCacheDirty = false;
|
|
631
|
-
_context4.next =
|
|
787
|
+
_context4.next = 15;
|
|
632
788
|
return this.dataProvider.updateReferenceData(blocks);
|
|
633
|
-
case
|
|
789
|
+
case 15:
|
|
634
790
|
updateResult = _context4.sent;
|
|
635
791
|
if (!updateResult.success) {
|
|
636
792
|
success = false;
|
|
637
|
-
|
|
793
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
794
|
+
(_this$saveExperience2 = this.saveExperience) === null || _this$saveExperience2 === void 0 || _this$saveExperience2.failure({
|
|
795
|
+
reason: updateResult.error || 'Failed to update reference synced blocks on the document'
|
|
796
|
+
});
|
|
797
|
+
} else {
|
|
798
|
+
(_this$fireAnalyticsEv9 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv9 === void 0 || _this$fireAnalyticsEv9.call(this, updateReferenceErrorPayload(updateResult.error || 'Failed to update reference synced blocks on the document'));
|
|
799
|
+
}
|
|
638
800
|
}
|
|
639
|
-
_context4.next =
|
|
801
|
+
_context4.next = 24;
|
|
640
802
|
break;
|
|
641
|
-
case
|
|
642
|
-
_context4.prev =
|
|
803
|
+
case 19:
|
|
804
|
+
_context4.prev = 19;
|
|
643
805
|
_context4.t0 = _context4["catch"](3);
|
|
644
806
|
success = false;
|
|
645
807
|
logException(_context4.t0, {
|
|
646
808
|
location: 'editor-synced-block-provider/referenceSyncBlockStoreManager'
|
|
647
809
|
});
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
810
|
+
if (fg('platform_synced_block_dogfooding')) {
|
|
811
|
+
(_this$saveExperience3 = this.saveExperience) === null || _this$saveExperience3 === void 0 || _this$saveExperience3.failure({
|
|
812
|
+
reason: _context4.t0.message
|
|
813
|
+
});
|
|
814
|
+
} else {
|
|
815
|
+
(_this$fireAnalyticsEv0 = this.fireAnalyticsEvent) === null || _this$fireAnalyticsEv0 === void 0 || _this$fireAnalyticsEv0.call(this, updateReferenceErrorPayload(_context4.t0.message));
|
|
816
|
+
}
|
|
817
|
+
case 24:
|
|
818
|
+
_context4.prev = 24;
|
|
651
819
|
if (!success) {
|
|
652
820
|
// set isCacheDirty back to true for cases where it failed to update the reference synced blocks on the BE
|
|
653
821
|
this.isCacheDirty = true;
|
|
822
|
+
} else if (fg('platform_synced_block_dogfooding')) {
|
|
823
|
+
(_this$saveExperience4 = this.saveExperience) === null || _this$saveExperience4 === void 0 || _this$saveExperience4.success();
|
|
654
824
|
}
|
|
655
|
-
return _context4.finish(
|
|
656
|
-
case 26:
|
|
657
|
-
return _context4.abrupt("return", success);
|
|
825
|
+
return _context4.finish(24);
|
|
658
826
|
case 27:
|
|
827
|
+
return _context4.abrupt("return", success);
|
|
828
|
+
case 28:
|
|
659
829
|
case "end":
|
|
660
830
|
return _context4.stop();
|
|
661
831
|
}
|
|
662
|
-
}, _callee3, this, [[3,
|
|
832
|
+
}, _callee3, this, [[3, 19, 24, 27]]);
|
|
663
833
|
}));
|
|
664
834
|
function flush() {
|
|
665
835
|
return _flush.apply(this, arguments);
|