@atlaskit/editor-synced-block-provider 3.8.0 → 3.9.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 +16 -0
- package/dist/cjs/clients/block-service/blockService.js +9 -5
- package/dist/cjs/hooks/useFetchSyncBlockTitle.js +13 -1
- package/dist/cjs/providers/block-service/blockServiceAPI.js +80 -63
- package/dist/cjs/providers/syncBlockProvider.js +28 -27
- package/dist/cjs/utils/resolveSyncBlockInstance.js +5 -1
- package/dist/es2019/clients/block-service/blockService.js +7 -4
- package/dist/es2019/hooks/useFetchSyncBlockTitle.js +15 -1
- package/dist/es2019/providers/block-service/blockServiceAPI.js +22 -12
- package/dist/es2019/providers/syncBlockProvider.js +11 -9
- package/dist/es2019/utils/resolveSyncBlockInstance.js +7 -2
- package/dist/esm/clients/block-service/blockService.js +9 -5
- package/dist/esm/hooks/useFetchSyncBlockTitle.js +13 -1
- package/dist/esm/providers/block-service/blockServiceAPI.js +78 -61
- package/dist/esm/providers/syncBlockProvider.js +28 -27
- package/dist/esm/utils/resolveSyncBlockInstance.js +5 -1
- package/dist/types/clients/block-service/blockService.d.ts +8 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/providers/block-service/blockServiceAPI.d.ts +3 -3
- package/dist/types/providers/types.d.ts +6 -2
- package/dist/types-ts4.5/clients/block-service/blockService.d.ts +8 -3
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +3 -3
- package/dist/types-ts4.5/providers/types.d.ts +6 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/editor-synced-block-provider
|
|
2
2
|
|
|
3
|
+
## 3.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`fe0f9c8de91c3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/fe0f9c8de91c3) -
|
|
8
|
+
The batch retrieve of the blocks must also send document ARI and also the local instance ID of the
|
|
9
|
+
reference blocks
|
|
10
|
+
|
|
11
|
+
## 3.8.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [`7b1f7ff1a2235`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/7b1f7ff1a2235) -
|
|
16
|
+
[ux] [EDITOR-4536] Update synced location dropdown UI
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 3.8.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
|
@@ -137,11 +137,11 @@ var BlockError = exports.BlockError = /*#__PURE__*/function (_Error) {
|
|
|
137
137
|
}( /*#__PURE__*/(0, _wrapNativeSuper2.default)(Error));
|
|
138
138
|
var getSyncedBlockContent = exports.getSyncedBlockContent = /*#__PURE__*/function () {
|
|
139
139
|
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(_ref2) {
|
|
140
|
-
var blockAri,
|
|
140
|
+
var blockAri, queryParams, response;
|
|
141
141
|
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
142
142
|
while (1) switch (_context2.prev = _context2.next) {
|
|
143
143
|
case 0:
|
|
144
|
-
blockAri = _ref2.blockAri
|
|
144
|
+
blockAri = _ref2.blockAri;
|
|
145
145
|
// Disable sending documentAri for now. We'll add it back if we find a way to update references that follows the save & refresh principle.
|
|
146
146
|
// Slack discussion here: https://atlassian.slack.com/archives/C09DZT1TBNW/p1767836775552099?thread_ts=1767836754.024889&cid=C09DZT1TBNW
|
|
147
147
|
// const queryParams = documentAri ? `?documentAri=${encodeURIComponent(documentAri)}` : '';
|
|
@@ -184,17 +184,21 @@ var getSyncedBlockContent = exports.getSyncedBlockContent = /*#__PURE__*/functio
|
|
|
184
184
|
*/
|
|
185
185
|
var batchRetrieveSyncedBlocks = exports.batchRetrieveSyncedBlocks = /*#__PURE__*/function () {
|
|
186
186
|
var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(_ref4) {
|
|
187
|
-
var
|
|
187
|
+
var blockIdentifiers, documentAri, response;
|
|
188
188
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
189
189
|
while (1) switch (_context3.prev = _context3.next) {
|
|
190
190
|
case 0:
|
|
191
|
-
|
|
191
|
+
blockIdentifiers = _ref4.blockIdentifiers, documentAri = _ref4.documentAri;
|
|
192
192
|
_context3.next = 3;
|
|
193
193
|
return (0, _retry.fetchWithRetry)("".concat(BLOCK_SERVICE_API_URL, "/block/batch-retrieve"), {
|
|
194
194
|
method: 'POST',
|
|
195
195
|
headers: COMMON_HEADERS,
|
|
196
196
|
body: JSON.stringify({
|
|
197
|
-
|
|
197
|
+
documentAri: documentAri,
|
|
198
|
+
blockIdentifiers: blockIdentifiers,
|
|
199
|
+
blockAris: blockIdentifiers.map(function (blockIdentifier) {
|
|
200
|
+
return blockIdentifier.blockAri;
|
|
201
|
+
})
|
|
198
202
|
})
|
|
199
203
|
});
|
|
200
204
|
case 3:
|
|
@@ -8,7 +8,19 @@ exports.useFetchSyncBlockTitle = void 0;
|
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var useFetchSyncBlockTitle = exports.useFetchSyncBlockTitle = function useFetchSyncBlockTitle(manager, syncBlockNode) {
|
|
11
|
-
|
|
11
|
+
// Initialize state from cache to prevent flickering during re-renders
|
|
12
|
+
var _useState = (0, _react.useState)(function () {
|
|
13
|
+
var _cachedData$data;
|
|
14
|
+
if (syncBlockNode.type.name !== 'syncBlock') {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
var resourceId = syncBlockNode.attrs.resourceId;
|
|
18
|
+
if (!resourceId) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
var cachedData = manager.referenceManager.getFromCache(resourceId);
|
|
22
|
+
return cachedData === null || cachedData === void 0 || (_cachedData$data = cachedData.data) === null || _cachedData$data === void 0 ? void 0 : _cachedData$data.sourceTitle;
|
|
23
|
+
}),
|
|
12
24
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
13
25
|
sourceTitle = _useState2[0],
|
|
14
26
|
setSourceTitle = _useState2[1];
|
|
@@ -17,7 +17,7 @@ var _ari = require("../../clients/block-service/ari");
|
|
|
17
17
|
var _blockService = require("../../clients/block-service/blockService");
|
|
18
18
|
var _types = require("../../common/types");
|
|
19
19
|
var _errorHandling = require("../../utils/errorHandling");
|
|
20
|
-
var
|
|
20
|
+
var _resourceId2 = require("../../utils/resourceId");
|
|
21
21
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
22
22
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
23
23
|
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; }
|
|
@@ -326,67 +326,84 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
326
326
|
|
|
327
327
|
/**
|
|
328
328
|
* Batch fetches multiple synced blocks by their resource IDs.
|
|
329
|
-
* @param
|
|
329
|
+
* @param blockNodeIdentifiers - Array of block node identifiers, containing block instance (local) ID + resource IDs to fetch
|
|
330
330
|
* @returns Array of SyncBlockInstance results
|
|
331
331
|
*/
|
|
332
332
|
}, {
|
|
333
333
|
key: "batchFetchData",
|
|
334
334
|
value: (function () {
|
|
335
|
-
var _batchFetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(
|
|
335
|
+
var _batchFetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(blockNodeIdentifiers) {
|
|
336
336
|
var _this2 = this;
|
|
337
|
-
var
|
|
337
|
+
var blockIdentifiers, validResourceIds, processedResourceIds, response, results, _iterator, _step, blockContentResponse, resourceId, value, syncedBlockData, _iterator2, _step2, errorResponse, _resourceId, _iterator3, _step3, blockNodeIdentifier;
|
|
338
338
|
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
339
339
|
while (1) switch (_context4.prev = _context4.next) {
|
|
340
340
|
case 0:
|
|
341
|
-
|
|
342
|
-
return
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
341
|
+
blockIdentifiers = blockNodeIdentifiers.map(function (blockIdentifier) {
|
|
342
|
+
return {
|
|
343
|
+
blockAri: (0, _ari.generateBlockAriFromReference)({
|
|
344
|
+
cloudId: _this2.cloudId,
|
|
345
|
+
resourceId: blockIdentifier.resourceId
|
|
346
|
+
}),
|
|
347
|
+
blockInstanceId: blockIdentifier.blockInstanceId
|
|
348
|
+
};
|
|
346
349
|
}); // Create a set of valid resourceIds for validation
|
|
347
|
-
validResourceIds = new Set(
|
|
350
|
+
validResourceIds = new Set(blockNodeIdentifiers.map(function (blockNodeIdentifier) {
|
|
351
|
+
return blockNodeIdentifier.resourceId;
|
|
352
|
+
})); // Track which resourceIds have been processed
|
|
348
353
|
processedResourceIds = new Set();
|
|
349
|
-
|
|
350
|
-
|
|
354
|
+
if (this.parentAri) {
|
|
355
|
+
_context4.next = 5;
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
return _context4.abrupt("return", blockNodeIdentifiers.map(function (blockNodeIdentifier) {
|
|
359
|
+
return {
|
|
360
|
+
error: _types.SyncBlockError.Errored,
|
|
361
|
+
resourceId: blockNodeIdentifier.resourceId
|
|
362
|
+
};
|
|
363
|
+
}));
|
|
364
|
+
case 5:
|
|
365
|
+
_context4.prev = 5;
|
|
366
|
+
_context4.next = 8;
|
|
351
367
|
return (0, _blockService.batchRetrieveSyncedBlocks)({
|
|
352
|
-
|
|
368
|
+
documentAri: this.parentAri,
|
|
369
|
+
blockIdentifiers: blockIdentifiers
|
|
353
370
|
});
|
|
354
|
-
case
|
|
371
|
+
case 8:
|
|
355
372
|
response = _context4.sent;
|
|
356
373
|
results = []; // Process successful blocks
|
|
357
374
|
if (!response.success) {
|
|
358
|
-
_context4.next =
|
|
375
|
+
_context4.next = 35;
|
|
359
376
|
break;
|
|
360
377
|
}
|
|
361
378
|
_iterator = _createForOfIteratorHelper(response.success);
|
|
362
|
-
_context4.prev =
|
|
379
|
+
_context4.prev = 12;
|
|
363
380
|
_iterator.s();
|
|
364
|
-
case
|
|
381
|
+
case 14:
|
|
365
382
|
if ((_step = _iterator.n()).done) {
|
|
366
|
-
_context4.next =
|
|
383
|
+
_context4.next = 27;
|
|
367
384
|
break;
|
|
368
385
|
}
|
|
369
386
|
blockContentResponse = _step.value;
|
|
370
387
|
// Extract resourceId from the returned blockAri
|
|
371
388
|
resourceId = this.extractResourceIdFromBlockAri(blockContentResponse.blockAri);
|
|
372
389
|
if (!(!resourceId || !validResourceIds.has(resourceId))) {
|
|
373
|
-
_context4.next =
|
|
390
|
+
_context4.next = 19;
|
|
374
391
|
break;
|
|
375
392
|
}
|
|
376
|
-
return _context4.abrupt("continue",
|
|
377
|
-
case
|
|
393
|
+
return _context4.abrupt("continue", 25);
|
|
394
|
+
case 19:
|
|
378
395
|
processedResourceIds.add(resourceId);
|
|
379
396
|
value = blockContentResponse.content;
|
|
380
397
|
if (value) {
|
|
381
|
-
_context4.next =
|
|
398
|
+
_context4.next = 24;
|
|
382
399
|
break;
|
|
383
400
|
}
|
|
384
401
|
results.push({
|
|
385
402
|
error: _types.SyncBlockError.NotFound,
|
|
386
403
|
resourceId: resourceId
|
|
387
404
|
});
|
|
388
|
-
return _context4.abrupt("continue",
|
|
389
|
-
case
|
|
405
|
+
return _context4.abrupt("continue", 25);
|
|
406
|
+
case 24:
|
|
390
407
|
try {
|
|
391
408
|
syncedBlockData = JSON.parse(value);
|
|
392
409
|
results.push({
|
|
@@ -405,71 +422,71 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
405
422
|
resourceId: resourceId
|
|
406
423
|
});
|
|
407
424
|
}
|
|
408
|
-
case 23:
|
|
409
|
-
_context4.next = 12;
|
|
410
|
-
break;
|
|
411
425
|
case 25:
|
|
412
|
-
_context4.next =
|
|
426
|
+
_context4.next = 14;
|
|
413
427
|
break;
|
|
414
428
|
case 27:
|
|
415
|
-
_context4.
|
|
416
|
-
|
|
429
|
+
_context4.next = 32;
|
|
430
|
+
break;
|
|
431
|
+
case 29:
|
|
432
|
+
_context4.prev = 29;
|
|
433
|
+
_context4.t0 = _context4["catch"](12);
|
|
417
434
|
_iterator.e(_context4.t0);
|
|
418
|
-
case
|
|
419
|
-
_context4.prev =
|
|
435
|
+
case 32:
|
|
436
|
+
_context4.prev = 32;
|
|
420
437
|
_iterator.f();
|
|
421
|
-
return _context4.finish(
|
|
422
|
-
case
|
|
438
|
+
return _context4.finish(32);
|
|
439
|
+
case 35:
|
|
423
440
|
if (!response.error) {
|
|
424
|
-
_context4.next =
|
|
441
|
+
_context4.next = 56;
|
|
425
442
|
break;
|
|
426
443
|
}
|
|
427
444
|
_iterator2 = _createForOfIteratorHelper(response.error);
|
|
428
|
-
_context4.prev =
|
|
445
|
+
_context4.prev = 37;
|
|
429
446
|
_iterator2.s();
|
|
430
|
-
case
|
|
447
|
+
case 39:
|
|
431
448
|
if ((_step2 = _iterator2.n()).done) {
|
|
432
|
-
_context4.next =
|
|
449
|
+
_context4.next = 48;
|
|
433
450
|
break;
|
|
434
451
|
}
|
|
435
452
|
errorResponse = _step2.value;
|
|
436
453
|
// Extract resourceId from the returned blockAri
|
|
437
454
|
_resourceId = this.extractResourceIdFromBlockAri(errorResponse.blockAri);
|
|
438
455
|
if (!(!_resourceId || !validResourceIds.has(_resourceId))) {
|
|
439
|
-
_context4.next =
|
|
456
|
+
_context4.next = 44;
|
|
440
457
|
break;
|
|
441
458
|
}
|
|
442
|
-
return _context4.abrupt("continue",
|
|
443
|
-
case
|
|
459
|
+
return _context4.abrupt("continue", 46);
|
|
460
|
+
case 44:
|
|
444
461
|
processedResourceIds.add(_resourceId);
|
|
445
462
|
results.push({
|
|
446
463
|
error: _types.SyncBlockError.Errored,
|
|
447
464
|
resourceId: _resourceId
|
|
448
465
|
});
|
|
449
|
-
case 44:
|
|
450
|
-
_context4.next = 37;
|
|
451
|
-
break;
|
|
452
466
|
case 46:
|
|
453
|
-
_context4.next =
|
|
467
|
+
_context4.next = 39;
|
|
454
468
|
break;
|
|
455
469
|
case 48:
|
|
456
|
-
_context4.
|
|
457
|
-
|
|
470
|
+
_context4.next = 53;
|
|
471
|
+
break;
|
|
472
|
+
case 50:
|
|
473
|
+
_context4.prev = 50;
|
|
474
|
+
_context4.t1 = _context4["catch"](37);
|
|
458
475
|
_iterator2.e(_context4.t1);
|
|
459
|
-
case
|
|
460
|
-
_context4.prev =
|
|
476
|
+
case 53:
|
|
477
|
+
_context4.prev = 53;
|
|
461
478
|
_iterator2.f();
|
|
462
|
-
return _context4.finish(
|
|
463
|
-
case
|
|
479
|
+
return _context4.finish(53);
|
|
480
|
+
case 56:
|
|
464
481
|
// Ensure all resourceIds have a result - return NotFound for any missing ones
|
|
465
|
-
_iterator3 = _createForOfIteratorHelper(
|
|
482
|
+
_iterator3 = _createForOfIteratorHelper(blockNodeIdentifiers);
|
|
466
483
|
try {
|
|
467
484
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
468
|
-
|
|
469
|
-
if (!processedResourceIds.has(
|
|
485
|
+
blockNodeIdentifier = _step3.value;
|
|
486
|
+
if (!processedResourceIds.has(blockNodeIdentifier.resourceId)) {
|
|
470
487
|
results.push({
|
|
471
488
|
error: _types.SyncBlockError.NotFound,
|
|
472
|
-
resourceId:
|
|
489
|
+
resourceId: blockNodeIdentifier.resourceId
|
|
473
490
|
});
|
|
474
491
|
}
|
|
475
492
|
}
|
|
@@ -479,20 +496,20 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
|
|
|
479
496
|
_iterator3.f();
|
|
480
497
|
}
|
|
481
498
|
return _context4.abrupt("return", results);
|
|
482
|
-
case
|
|
483
|
-
_context4.prev =
|
|
484
|
-
_context4.t2 = _context4["catch"](
|
|
485
|
-
return _context4.abrupt("return",
|
|
499
|
+
case 61:
|
|
500
|
+
_context4.prev = 61;
|
|
501
|
+
_context4.t2 = _context4["catch"](5);
|
|
502
|
+
return _context4.abrupt("return", blockNodeIdentifiers.map(function (blockNodeIdentifier) {
|
|
486
503
|
return {
|
|
487
504
|
error: _context4.t2 instanceof _blockService.BlockError ? mapBlockError(_context4.t2) : _types.SyncBlockError.Errored,
|
|
488
|
-
resourceId: resourceId
|
|
505
|
+
resourceId: blockNodeIdentifier.resourceId
|
|
489
506
|
};
|
|
490
507
|
}));
|
|
491
|
-
case
|
|
508
|
+
case 64:
|
|
492
509
|
case "end":
|
|
493
510
|
return _context4.stop();
|
|
494
511
|
}
|
|
495
|
-
}, _callee4, this, [[
|
|
512
|
+
}, _callee4, this, [[5, 61], [12, 29, 32, 35], [37, 50, 53, 56]]);
|
|
496
513
|
}));
|
|
497
514
|
function batchFetchData(_x4) {
|
|
498
515
|
return _batchFetchData.apply(this, arguments);
|
|
@@ -723,7 +740,7 @@ var BlockServiceADFWriteProvider = /*#__PURE__*/function () {
|
|
|
723
740
|
}, {
|
|
724
741
|
key: "generateResourceIdForReference",
|
|
725
742
|
value: function generateResourceIdForReference(sourceId) {
|
|
726
|
-
return (0,
|
|
743
|
+
return (0, _resourceId2.createResourceIdForReference)(this.product, this.parentId || '', sourceId);
|
|
727
744
|
}
|
|
728
745
|
}, {
|
|
729
746
|
key: "generateResourceId",
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.useMemoizedSyncedBlockProvider = exports.SyncBlockProvider = void 0;
|
|
8
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
10
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -88,49 +87,51 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
88
87
|
value: (function () {
|
|
89
88
|
var _fetchNodesData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(nodes) {
|
|
90
89
|
var _this2 = this;
|
|
91
|
-
var
|
|
90
|
+
var blockIdentifiers;
|
|
92
91
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
93
92
|
while (1) switch (_context.prev = _context.next) {
|
|
94
93
|
case 0:
|
|
95
|
-
|
|
96
|
-
return
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
94
|
+
blockIdentifiers = nodes.map(function (node) {
|
|
95
|
+
return {
|
|
96
|
+
resourceId: node.attrs.resourceId,
|
|
97
|
+
blockInstanceId: node.attrs.localId
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
if (!(blockIdentifiers.length === 0)) {
|
|
101
|
+
_context.next = 3;
|
|
101
102
|
break;
|
|
102
103
|
}
|
|
103
104
|
return _context.abrupt("return", []);
|
|
104
|
-
case
|
|
105
|
+
case 3:
|
|
105
106
|
if (!(0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding')) {
|
|
106
|
-
_context.next =
|
|
107
|
+
_context.next = 15;
|
|
107
108
|
break;
|
|
108
109
|
}
|
|
109
|
-
_context.prev =
|
|
110
|
-
_context.next =
|
|
111
|
-
return this.fetchProvider.batchFetchData(
|
|
112
|
-
case
|
|
110
|
+
_context.prev = 4;
|
|
111
|
+
_context.next = 7;
|
|
112
|
+
return this.fetchProvider.batchFetchData(blockIdentifiers);
|
|
113
|
+
case 7:
|
|
113
114
|
return _context.abrupt("return", _context.sent);
|
|
114
|
-
case
|
|
115
|
-
_context.prev =
|
|
116
|
-
_context.t0 = _context["catch"](
|
|
117
|
-
return _context.abrupt("return",
|
|
115
|
+
case 10:
|
|
116
|
+
_context.prev = 10;
|
|
117
|
+
_context.t0 = _context["catch"](4);
|
|
118
|
+
return _context.abrupt("return", blockIdentifiers.map(function (blockIdentifier) {
|
|
118
119
|
return {
|
|
119
120
|
error: _types.SyncBlockError.Errored,
|
|
120
|
-
resourceId: resourceId
|
|
121
|
+
resourceId: blockIdentifier.resourceId
|
|
121
122
|
};
|
|
122
123
|
}));
|
|
123
|
-
case
|
|
124
|
-
_context.next =
|
|
124
|
+
case 13:
|
|
125
|
+
_context.next = 16;
|
|
125
126
|
break;
|
|
126
|
-
case
|
|
127
|
-
return _context.abrupt("return", Promise.allSettled(
|
|
128
|
-
return _this2.fetchProvider.fetchData(resourceId).then(function (data) {
|
|
127
|
+
case 15:
|
|
128
|
+
return _context.abrupt("return", Promise.allSettled(blockIdentifiers.map(function (blockIdentifier) {
|
|
129
|
+
return _this2.fetchProvider.fetchData(blockIdentifier.resourceId).then(function (data) {
|
|
129
130
|
return data;
|
|
130
131
|
}, function () {
|
|
131
132
|
return {
|
|
132
133
|
error: _types.SyncBlockError.Errored,
|
|
133
|
-
resourceId: resourceId
|
|
134
|
+
resourceId: blockIdentifier.resourceId
|
|
134
135
|
};
|
|
135
136
|
});
|
|
136
137
|
})).then(function (results) {
|
|
@@ -140,11 +141,11 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
|
|
|
140
141
|
return result.value;
|
|
141
142
|
});
|
|
142
143
|
}));
|
|
143
|
-
case
|
|
144
|
+
case 16:
|
|
144
145
|
case "end":
|
|
145
146
|
return _context.stop();
|
|
146
147
|
}
|
|
147
|
-
}, _callee, this, [[
|
|
148
|
+
}, _callee, this, [[4, 10]]);
|
|
148
149
|
}));
|
|
149
150
|
function fetchNodesData(_x) {
|
|
150
151
|
return _fetchNodesData.apply(this, arguments);
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.resolveSyncBlockInstance = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
9
10
|
var _types = require("../common/types");
|
|
10
11
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
12
|
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) { (0, _defineProperty2.default)(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; }
|
|
@@ -20,7 +21,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
20
21
|
* @returns A merged SyncBlockInstance object.
|
|
21
22
|
*/
|
|
22
23
|
var resolveSyncBlockInstance = exports.resolveSyncBlockInstance = function resolveSyncBlockInstance(oldResult, newResult) {
|
|
23
|
-
var _newResult$data, _oldResult$data, _newResult$data2, _oldResult$data2;
|
|
24
|
+
var _newResult$data, _oldResult$data, _newResult$data2, _oldResult$data2, _newResult$data3, _oldResult$data3, _newResult$data4, _oldResult$data4;
|
|
24
25
|
// if the old result has no data, we simply return the new result
|
|
25
26
|
if (!oldResult.data) {
|
|
26
27
|
return newResult;
|
|
@@ -38,6 +39,9 @@ var resolveSyncBlockInstance = exports.resolveSyncBlockInstance = function resol
|
|
|
38
39
|
data: _objectSpread(_objectSpread({}, newResult.data), {}, {
|
|
39
40
|
sourceURL: ((_newResult$data = newResult.data) === null || _newResult$data === void 0 ? void 0 : _newResult$data.sourceURL) || ((_oldResult$data = oldResult.data) === null || _oldResult$data === void 0 ? void 0 : _oldResult$data.sourceURL) || undefined,
|
|
40
41
|
sourceTitle: ((_newResult$data2 = newResult.data) === null || _newResult$data2 === void 0 ? void 0 : _newResult$data2.sourceTitle) || ((_oldResult$data2 = oldResult.data) === null || _oldResult$data2 === void 0 ? void 0 : _oldResult$data2.sourceTitle) || undefined
|
|
42
|
+
}, (0, _platformFeatureFlags.fg)('platform_synced_block_dogfooding') && {
|
|
43
|
+
sourceSubType: ((_newResult$data3 = newResult.data) === null || _newResult$data3 === void 0 ? void 0 : _newResult$data3.sourceSubType) || ((_oldResult$data3 = oldResult.data) === null || _oldResult$data3 === void 0 ? void 0 : _oldResult$data3.sourceSubType) || undefined,
|
|
44
|
+
onSamePage: ((_newResult$data4 = newResult.data) === null || _newResult$data4 === void 0 ? void 0 : _newResult$data4.onSamePage) || ((_oldResult$data4 = oldResult.data) === null || _oldResult$data4 === void 0 ? void 0 : _oldResult$data4.onSamePage) || undefined
|
|
41
45
|
})
|
|
42
46
|
});
|
|
43
47
|
};
|
|
@@ -100,8 +100,8 @@ export class BlockError extends Error {
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
export const getSyncedBlockContent = async ({
|
|
103
|
-
blockAri
|
|
104
|
-
documentAri
|
|
103
|
+
blockAri
|
|
104
|
+
// documentAri,
|
|
105
105
|
}) => {
|
|
106
106
|
// Disable sending documentAri for now. We'll add it back if we find a way to update references that follows the save & refresh principle.
|
|
107
107
|
// Slack discussion here: https://atlassian.slack.com/archives/C09DZT1TBNW/p1767836775552099?thread_ts=1767836754.024889&cid=C09DZT1TBNW
|
|
@@ -126,13 +126,16 @@ export const getSyncedBlockContent = async ({
|
|
|
126
126
|
* @returns A promise containing arrays of successfully fetched blocks and any errors encountered
|
|
127
127
|
*/
|
|
128
128
|
export const batchRetrieveSyncedBlocks = async ({
|
|
129
|
-
|
|
129
|
+
blockIdentifiers,
|
|
130
|
+
documentAri
|
|
130
131
|
}) => {
|
|
131
132
|
const response = await fetchWithRetry(`${BLOCK_SERVICE_API_URL}/block/batch-retrieve`, {
|
|
132
133
|
method: 'POST',
|
|
133
134
|
headers: COMMON_HEADERS,
|
|
134
135
|
body: JSON.stringify({
|
|
135
|
-
|
|
136
|
+
documentAri,
|
|
137
|
+
blockIdentifiers,
|
|
138
|
+
blockAris: blockIdentifiers.map(blockIdentifier => blockIdentifier.blockAri)
|
|
136
139
|
})
|
|
137
140
|
});
|
|
138
141
|
if (!response.ok) {
|
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
import { useEffect, useState } from 'react';
|
|
2
2
|
export const useFetchSyncBlockTitle = (manager, syncBlockNode) => {
|
|
3
|
-
|
|
3
|
+
// Initialize state from cache to prevent flickering during re-renders
|
|
4
|
+
const [sourceTitle, setSourceTitle] = useState(() => {
|
|
5
|
+
var _cachedData$data;
|
|
6
|
+
if (syncBlockNode.type.name !== 'syncBlock') {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const {
|
|
10
|
+
resourceId
|
|
11
|
+
} = syncBlockNode.attrs;
|
|
12
|
+
if (!resourceId) {
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
const cachedData = manager.referenceManager.getFromCache(resourceId);
|
|
16
|
+
return cachedData === null || cachedData === void 0 ? void 0 : (_cachedData$data = cachedData.data) === null || _cachedData$data === void 0 ? void 0 : _cachedData$data.sourceTitle;
|
|
17
|
+
});
|
|
4
18
|
useEffect(() => {
|
|
5
19
|
const unsubscribe = manager.referenceManager.subscribeToSourceTitle(syncBlockNode, title => {
|
|
6
20
|
setSourceTitle(title);
|
|
@@ -236,23 +236,33 @@ class BlockServiceADFFetchProvider {
|
|
|
236
236
|
|
|
237
237
|
/**
|
|
238
238
|
* Batch fetches multiple synced blocks by their resource IDs.
|
|
239
|
-
* @param
|
|
239
|
+
* @param blockNodeIdentifiers - Array of block node identifiers, containing block instance (local) ID + resource IDs to fetch
|
|
240
240
|
* @returns Array of SyncBlockInstance results
|
|
241
241
|
*/
|
|
242
|
-
async batchFetchData(
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
async batchFetchData(blockNodeIdentifiers) {
|
|
243
|
+
const blockIdentifiers = blockNodeIdentifiers.map(blockIdentifier => ({
|
|
244
|
+
blockAri: generateBlockAriFromReference({
|
|
245
|
+
cloudId: this.cloudId,
|
|
246
|
+
resourceId: blockIdentifier.resourceId
|
|
247
|
+
}),
|
|
248
|
+
blockInstanceId: blockIdentifier.blockInstanceId
|
|
246
249
|
}));
|
|
247
250
|
|
|
248
251
|
// Create a set of valid resourceIds for validation
|
|
249
|
-
const validResourceIds = new Set(
|
|
252
|
+
const validResourceIds = new Set(blockNodeIdentifiers.map(blockNodeIdentifier => blockNodeIdentifier.resourceId));
|
|
250
253
|
|
|
251
254
|
// Track which resourceIds have been processed
|
|
252
255
|
const processedResourceIds = new Set();
|
|
256
|
+
if (!this.parentAri) {
|
|
257
|
+
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
258
|
+
error: SyncBlockError.Errored,
|
|
259
|
+
resourceId: blockNodeIdentifier.resourceId
|
|
260
|
+
}));
|
|
261
|
+
}
|
|
253
262
|
try {
|
|
254
263
|
const response = await batchRetrieveSyncedBlocks({
|
|
255
|
-
|
|
264
|
+
documentAri: this.parentAri,
|
|
265
|
+
blockIdentifiers
|
|
256
266
|
});
|
|
257
267
|
const results = [];
|
|
258
268
|
|
|
@@ -311,20 +321,20 @@ class BlockServiceADFFetchProvider {
|
|
|
311
321
|
}
|
|
312
322
|
|
|
313
323
|
// Ensure all resourceIds have a result - return NotFound for any missing ones
|
|
314
|
-
for (const
|
|
315
|
-
if (!processedResourceIds.has(resourceId)) {
|
|
324
|
+
for (const blockNodeIdentifier of blockNodeIdentifiers) {
|
|
325
|
+
if (!processedResourceIds.has(blockNodeIdentifier.resourceId)) {
|
|
316
326
|
results.push({
|
|
317
327
|
error: SyncBlockError.NotFound,
|
|
318
|
-
resourceId
|
|
328
|
+
resourceId: blockNodeIdentifier.resourceId
|
|
319
329
|
});
|
|
320
330
|
}
|
|
321
331
|
}
|
|
322
332
|
return results;
|
|
323
333
|
} catch (error) {
|
|
324
334
|
// If batch request fails, return error for all resourceIds
|
|
325
|
-
return
|
|
335
|
+
return blockNodeIdentifiers.map(blockNodeIdentifier => ({
|
|
326
336
|
error: error instanceof BlockError ? mapBlockError(error) : SyncBlockError.Errored,
|
|
327
|
-
resourceId
|
|
337
|
+
resourceId: blockNodeIdentifier.resourceId
|
|
328
338
|
}));
|
|
329
339
|
}
|
|
330
340
|
}
|
|
@@ -55,29 +55,31 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
|
|
|
55
55
|
* @returns Array of {resourceId?: string, error?: string}.
|
|
56
56
|
*/
|
|
57
57
|
async fetchNodesData(nodes) {
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
58
|
+
const blockIdentifiers = nodes.map(node => ({
|
|
59
|
+
resourceId: node.attrs.resourceId,
|
|
60
|
+
blockInstanceId: node.attrs.localId
|
|
61
|
+
}));
|
|
62
|
+
if (blockIdentifiers.length === 0) {
|
|
61
63
|
return [];
|
|
62
64
|
}
|
|
63
65
|
if (fg('platform_synced_block_dogfooding')) {
|
|
64
66
|
try {
|
|
65
|
-
return await this.fetchProvider.batchFetchData(
|
|
67
|
+
return await this.fetchProvider.batchFetchData(blockIdentifiers);
|
|
66
68
|
} catch {
|
|
67
69
|
// If batch fetch fails, return error for all resourceIds
|
|
68
|
-
return
|
|
70
|
+
return blockIdentifiers.map(blockIdentifier => ({
|
|
69
71
|
error: SyncBlockError.Errored,
|
|
70
|
-
resourceId
|
|
72
|
+
resourceId: blockIdentifier.resourceId
|
|
71
73
|
}));
|
|
72
74
|
}
|
|
73
75
|
} else {
|
|
74
|
-
return Promise.allSettled(
|
|
75
|
-
return this.fetchProvider.fetchData(resourceId).then(data => {
|
|
76
|
+
return Promise.allSettled(blockIdentifiers.map(blockIdentifier => {
|
|
77
|
+
return this.fetchProvider.fetchData(blockIdentifier.resourceId).then(data => {
|
|
76
78
|
return data;
|
|
77
79
|
}, () => {
|
|
78
80
|
return {
|
|
79
81
|
error: SyncBlockError.Errored,
|
|
80
|
-
resourceId
|
|
82
|
+
resourceId: blockIdentifier.resourceId
|
|
81
83
|
};
|
|
82
84
|
});
|
|
83
85
|
})).then(results => {
|