@atlaskit/editor-synced-block-provider 2.10.5 → 2.10.6

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.
Files changed (34) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/cjs/clients/confluence/sourceInfo.js +3 -3
  3. package/dist/cjs/index.js +2 -2
  4. package/dist/cjs/providers/block-service/blockServiceAPI.js +0 -14
  5. package/dist/cjs/providers/confluence/confluenceContentAPI.js +0 -15
  6. package/dist/cjs/providers/syncBlockProvider.js +30 -40
  7. package/dist/cjs/store-manager/referenceSyncBlockStoreManager.js +54 -31
  8. package/dist/es2019/clients/confluence/sourceInfo.js +1 -1
  9. package/dist/es2019/index.js +1 -1
  10. package/dist/es2019/providers/block-service/blockServiceAPI.js +0 -12
  11. package/dist/es2019/providers/confluence/confluenceContentAPI.js +1 -14
  12. package/dist/es2019/providers/syncBlockProvider.js +30 -44
  13. package/dist/es2019/store-manager/referenceSyncBlockStoreManager.js +51 -30
  14. package/dist/esm/clients/confluence/sourceInfo.js +2 -2
  15. package/dist/esm/index.js +1 -1
  16. package/dist/esm/providers/block-service/blockServiceAPI.js +0 -14
  17. package/dist/esm/providers/confluence/confluenceContentAPI.js +1 -16
  18. package/dist/esm/providers/syncBlockProvider.js +31 -41
  19. package/dist/esm/store-manager/referenceSyncBlockStoreManager.js +54 -31
  20. package/dist/types/clients/confluence/sourceInfo.d.ts +1 -1
  21. package/dist/types/index.d.ts +2 -2
  22. package/dist/types/providers/block-service/blockServiceAPI.d.ts +2 -3
  23. package/dist/types/providers/confluence/confluenceContentAPI.d.ts +2 -3
  24. package/dist/types/providers/syncBlockProvider.d.ts +11 -9
  25. package/dist/types/providers/types.d.ts +8 -9
  26. package/dist/types/store-manager/referenceSyncBlockStoreManager.d.ts +2 -1
  27. package/dist/types-ts4.5/clients/confluence/sourceInfo.d.ts +1 -1
  28. package/dist/types-ts4.5/index.d.ts +2 -2
  29. package/dist/types-ts4.5/providers/block-service/blockServiceAPI.d.ts +2 -3
  30. package/dist/types-ts4.5/providers/confluence/confluenceContentAPI.d.ts +2 -3
  31. package/dist/types-ts4.5/providers/syncBlockProvider.d.ts +11 -9
  32. package/dist/types-ts4.5/providers/types.d.ts +8 -9
  33. package/dist/types-ts4.5/store-manager/referenceSyncBlockStoreManager.d.ts +2 -1
  34. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-synced-block-provider
2
2
 
3
+ ## 2.10.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [`23c24c4b7faff`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/23c24c4b7faff) -
8
+ EDITOR-3312 Make data handling product agnostic
9
+ - Updated dependencies
10
+
3
11
  ## 2.10.5
4
12
 
5
13
  ### Patch Changes
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
- exports.fetchConfluenceSourceInfo = void 0;
7
+ exports.fetchConfluencePageInfo = void 0;
8
8
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
9
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
10
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
@@ -68,7 +68,7 @@ var getConfluenceSourceInfo = /*#__PURE__*/function () {
68
68
  return _ref.apply(this, arguments);
69
69
  };
70
70
  }();
71
- var fetchConfluenceSourceInfo = exports.fetchConfluenceSourceInfo = /*#__PURE__*/function () {
71
+ var fetchConfluencePageInfo = exports.fetchConfluencePageInfo = /*#__PURE__*/function () {
72
72
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(pageAri, localId) {
73
73
  var _response$data, _contentData$space, _getPageIdAndTypeFrom, pageType, response, contentData, title, url, _ref3, base;
74
74
  return _regenerator.default.wrap(function _callee2$(_context2) {
@@ -113,7 +113,7 @@ var fetchConfluenceSourceInfo = exports.fetchConfluenceSourceInfo = /*#__PURE__*
113
113
  }
114
114
  }, _callee2, null, [[0, 15]]);
115
115
  }));
116
- return function fetchConfluenceSourceInfo(_x2, _x3) {
116
+ return function fetchConfluencePageInfo(_x2, _x3) {
117
117
  return _ref2.apply(this, arguments);
118
118
  };
119
119
  }();
package/dist/cjs/index.js CHANGED
@@ -63,10 +63,10 @@ Object.defineProperty(exports, "createSyncBlockNode", {
63
63
  return _utils.createSyncBlockNode;
64
64
  }
65
65
  });
66
- Object.defineProperty(exports, "fetchConfluenceSourceInfo", {
66
+ Object.defineProperty(exports, "fetchConfluencePageInfo", {
67
67
  enumerable: true,
68
68
  get: function get() {
69
- return _sourceInfo.fetchConfluenceSourceInfo;
69
+ return _sourceInfo.fetchConfluencePageInfo;
70
70
  }
71
71
  });
72
72
  Object.defineProperty(exports, "getConfluencePageAri", {
@@ -96,20 +96,6 @@ var BlockServiceADFFetchProvider = /*#__PURE__*/function () {
96
96
  }
97
97
  return fetchData;
98
98
  }()
99
- }, {
100
- key: "retrieveSourceInfoFetchData",
101
- value: function retrieveSourceInfoFetchData(resourceId, pageARI) {
102
- var sourceLocalId;
103
- try {
104
- sourceLocalId = (0, _ari.getLocalIdFromBlockResourceId)(resourceId);
105
- } catch (error) {
106
- // EDITOR-1921: log analytic here, safe to continue
107
- }
108
- return {
109
- pageARI: pageARI,
110
- sourceLocalId: sourceLocalId
111
- };
112
- }
113
99
  }]);
114
100
  }();
115
101
  /**
@@ -146,21 +146,6 @@ var ConfluenceADFFetchProvider = /*#__PURE__*/function () {
146
146
  }
147
147
  return fetchData;
148
148
  }()
149
- }, {
150
- key: "retrieveSourceInfoFetchData",
151
- value: function retrieveSourceInfoFetchData(resourceId) {
152
- var pageARI = (0, _ari.getPageARIFromContentPropertyResourceId)(resourceId);
153
- var sourceLocalId;
154
- try {
155
- sourceLocalId = (0, _ari.getLocalIdFromConfluencePageAri)(resourceId);
156
- } catch (error) {
157
- // EDITOR-1921: log analytic here, safe to continue
158
- }
159
- return {
160
- pageARI: pageARI,
161
- sourceLocalId: sourceLocalId
162
- };
163
- }
164
149
  }]);
165
150
  }();
166
151
  /**
@@ -209,34 +209,28 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
209
209
  }
210
210
 
211
211
  /**
212
- * Retrieve the source info from the source id
212
+ * Fetch the source info from the source id
213
213
  *
214
- * @param node
214
+ * @param params
215
+ * @param params.sourceAri - The source ARI
216
+ * @param params.sourceProduct - The source product. e.g. 'confluence-page', 'jira-work-item'
215
217
  *
216
218
  * @returns The source info
217
219
  */
218
220
  }, {
219
- key: "retrieveSyncBlockSourceInfo",
220
- value: function retrieveSyncBlockSourceInfo(node) {
221
- // with content API, this is the concatenation of the page ARI and the block's localId.
222
- // with block service, this is the ARI of the block.
223
- // this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
224
- var resourceId = node.attrs.resourceId;
225
- var pageARI;
226
- var sourceLocalId;
227
- if (resourceId && typeof resourceId === 'string') {
228
- try {
229
- var fetchData = this.fetchProvider.retrieveSourceInfoFetchData(resourceId, this.sourceId);
230
- pageARI = fetchData.pageARI;
231
- sourceLocalId = fetchData.sourceLocalId;
232
- } catch (error) {
233
- return Promise.reject(error);
234
- }
221
+ key: "fetchSyncBlockSourceInfo",
222
+ value: function fetchSyncBlockSourceInfo(localId, sourceAri, sourceProduct) {
223
+ if (!sourceAri || !sourceProduct) {
224
+ return Promise.resolve(undefined);
225
+ }
226
+ switch (sourceProduct) {
227
+ case 'confluence-page':
228
+ return (0, _sourceInfo.fetchConfluencePageInfo)(sourceAri, localId);
229
+ case 'jira-work-item':
230
+ return Promise.reject(new Error('Jira work item source product not supported'));
231
+ default:
232
+ return Promise.reject(new Error("".concat(sourceProduct, " source product not supported")));
235
233
  }
236
-
237
- // TODO: EDITOR-3312 - based on the source sync block product,
238
- // execute fetchConfluenceSourceInfo or fetchJiraItemSourceInfo or similar...
239
- return pageARI ? (0, _sourceInfo.fetchConfluenceSourceInfo)(pageARI, sourceLocalId) : Promise.resolve(undefined);
240
234
  }
241
235
  }, {
242
236
  key: "generateResourceId",
@@ -258,32 +252,28 @@ var SyncBlockProvider = exports.SyncBlockProvider = /*#__PURE__*/function (_Sync
258
252
  /**
259
253
  * Retrieve the parent info for the sync block
260
254
  *
261
- * @param resourceId
262
- * @param syncBlockInstance
255
+ * @param sourceAri - The source ARI
256
+ * @param sourceProduct - The source product. e.g. 'confluence-page', 'jira-work-item'
263
257
  *
264
258
  * @returns The parent info for the sync block
265
259
  */
266
260
  }, {
267
261
  key: "retrieveSyncBlockParentInfo",
268
- value: function retrieveSyncBlockParentInfo(syncBlockInstance) {
269
- if (!syncBlockInstance || !syncBlockInstance.data) {
262
+ value: function retrieveSyncBlockParentInfo(sourceAri, sourceProduct) {
263
+ if (!sourceAri || !sourceProduct) {
270
264
  return undefined;
271
265
  }
272
- var _syncBlockInstance$da = syncBlockInstance.data,
273
- sourceAri = _syncBlockInstance$da.sourceAri,
274
- product = _syncBlockInstance$da.product;
275
- if (!sourceAri || !product) {
276
- return undefined;
266
+ switch (sourceProduct) {
267
+ case 'confluence-page':
268
+ return {
269
+ contentId: (0, _ari.getPageIdAndTypeFromConfluencePageAri)(sourceAri).id,
270
+ contentProduct: sourceProduct
271
+ };
272
+ case 'jira-work-item':
273
+ throw new Error('Jira work item source product not supported');
274
+ default:
275
+ throw new Error("".concat(sourceProduct, " source product not supported"));
277
276
  }
278
-
279
- // TODO: EDITOR-3312 - based on the source sync block product,
280
- // execute getPageIdAndTypeFromConfluencePageAri or getJiraItemIdAndTypeFromJiraItemAri or similar...
281
- var _getPageIdAndTypeFrom = (0, _ari.getPageIdAndTypeFromConfluencePageAri)(sourceAri),
282
- contentId = _getPageIdAndTypeFrom.id;
283
- return {
284
- contentId: contentId,
285
- contentProduct: product
286
- };
287
277
  }
288
278
  }]);
289
279
  }(_types2.SyncBlockDataProvider);
@@ -121,35 +121,45 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
121
121
  return refreshSubscriptions;
122
122
  }())
123
123
  }, {
124
- key: "retrieveSyncBlockSourceInfo",
125
- value: function retrieveSyncBlockSourceInfo(resourceId) {
126
- var _this = this;
124
+ key: "fetchSyncBlockSourceInfo",
125
+ value: function fetchSyncBlockSourceInfo(resourceId) {
126
+ var _existingSyncBlock$da,
127
+ _existingSyncBlock$da2,
128
+ _this = this;
127
129
  if (!resourceId || !this.dataProvider) {
128
130
  return;
129
131
  }
132
+ if (this.syncBlockURLRequests.get(resourceId)) {
133
+ return;
134
+ }
135
+ this.syncBlockURLRequests.set(resourceId, true);
136
+ var existingSyncBlock = this.getFromCache(resourceId);
137
+ if (!existingSyncBlock) {
138
+ return;
139
+ }
130
140
 
131
- // TODO: EDITOR-3312 - retrieve the source info based on the source sync block product
132
-
133
- // if the sync block is a reference block, we need to fetch the URL to the source
134
- // we could optimise this further by checking if the sync block is on the same page as the source
135
- if (!this.syncBlockURLRequests.get(resourceId)) {
136
- this.syncBlockURLRequests.set(resourceId, true);
137
- this.dataProvider.retrieveSyncBlockSourceInfo((0, _utils.createSyncBlockNode)('', resourceId)).then(function (sourceInfo) {
138
- var existingSyncBlock = _this.getFromCache(resourceId);
139
- if (existingSyncBlock && existingSyncBlock.data) {
140
- existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
141
- sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
142
- sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
143
- });
144
- _this.updateCache(existingSyncBlock);
145
- if (sourceInfo !== null && sourceInfo !== void 0 && sourceInfo.title) {
146
- _this.updateSourceTitleSubscriptions(existingSyncBlock.resourceId, sourceInfo.title);
147
- }
148
- }
149
- }).finally(function () {
150
- _this.syncBlockURLRequests.set(resourceId, false);
151
- });
141
+ // skip if source URL and title are already present
142
+ 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) {
143
+ return;
152
144
  }
145
+ var _ref = existingSyncBlock.data || {},
146
+ sourceAri = _ref.sourceAri,
147
+ product = _ref.product,
148
+ blockInstanceId = _ref.blockInstanceId;
149
+ if (!sourceAri || !product || !blockInstanceId) {
150
+ return;
151
+ }
152
+ this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product).then(function (sourceInfo) {
153
+ if (!sourceInfo) {
154
+ return;
155
+ }
156
+ _this.updateCacheWithSourceInfo(resourceId, sourceInfo);
157
+ if (sourceInfo.title) {
158
+ _this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
159
+ }
160
+ }).finally(function () {
161
+ _this.syncBlockURLRequests.delete(resourceId);
162
+ });
153
163
  }
154
164
 
155
165
  /**
@@ -200,7 +210,6 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
200
210
  case 11:
201
211
  resolvedData = [];
202
212
  data.forEach(function (syncBlockInstance) {
203
- var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
204
213
  if (!syncBlockInstance.resourceId) {
205
214
  return;
206
215
  }
@@ -213,11 +222,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
213
222
  var resolvedSyncBlockInstance = existingSyncBlock ? (0, _resolveSyncBlockInstance.resolveSyncBlockInstance)(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
214
223
  _this2.updateCache(resolvedSyncBlockInstance);
215
224
  resolvedData.push(resolvedSyncBlockInstance);
216
-
217
- // fetch source URL and title if not already present
218
- if ((!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) || !((_resolvedSyncBlockIns2 = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns2 !== void 0 && _resolvedSyncBlockIns2.sourceTitle)) && resolvedSyncBlockInstance.resourceId) {
219
- _this2.retrieveSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
220
- }
225
+ _this2.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
221
226
  });
222
227
  return _context3.abrupt("return", [].concat(resolvedData, blocksWithNotFoundError));
223
228
  case 14:
@@ -231,6 +236,19 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
231
236
  }
232
237
  return fetchSyncBlocksData;
233
238
  }())
239
+ }, {
240
+ key: "updateCacheWithSourceInfo",
241
+ value: function updateCacheWithSourceInfo(resourceId, sourceInfo) {
242
+ var existingSyncBlock = this.getFromCache(resourceId);
243
+ if (existingSyncBlock && existingSyncBlock.data) {
244
+ existingSyncBlock.data.sourceURL = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
245
+ existingSyncBlock.data = _objectSpread(_objectSpread({}, existingSyncBlock.data), {}, {
246
+ sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
247
+ sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
248
+ });
249
+ this.updateCache(existingSyncBlock);
250
+ }
251
+ }
234
252
  }, {
235
253
  key: "updateCache",
236
254
  value: function updateCache(syncBlock) {
@@ -386,6 +404,7 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
386
404
  }, {
387
405
  key: "retrieveDynamicProviders",
388
406
  value: function retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
407
+ var _syncBlock$data2, _syncBlock$data3, _syncBlock$data4, _syncBlock$data5;
389
408
  if (!this.dataProvider) {
390
409
  return;
391
410
  }
@@ -394,7 +413,11 @@ var ReferenceSyncBlockStoreManager = exports.ReferenceSyncBlockStoreManager = /*
394
413
  if (hasMediaProvider && hasEmojiProvider) {
395
414
  return;
396
415
  }
397
- var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
416
+ var syncBlock = this.getFromCache(resourceId);
417
+ if (!syncBlock || !((_syncBlock$data2 = syncBlock.data) !== null && _syncBlock$data2 !== void 0 && _syncBlock$data2.sourceAri) || !((_syncBlock$data3 = syncBlock.data) !== null && _syncBlock$data3 !== void 0 && _syncBlock$data3.product)) {
418
+ return;
419
+ }
420
+ var parentInfo = this.dataProvider.retrieveSyncBlockParentInfo((_syncBlock$data4 = syncBlock.data) === null || _syncBlock$data4 === void 0 ? void 0 : _syncBlock$data4.sourceAri, (_syncBlock$data5 = syncBlock.data) === null || _syncBlock$data5 === void 0 ? void 0 : _syncBlock$data5.product);
398
421
  if (!parentInfo) {
399
422
  return;
400
423
  }
@@ -52,7 +52,7 @@ const getConfluenceSourceInfo = async ari => {
52
52
  }
53
53
  return await response.json();
54
54
  };
55
- export const fetchConfluenceSourceInfo = async (pageAri, localId) => {
55
+ export const fetchConfluencePageInfo = async (pageAri, localId) => {
56
56
  try {
57
57
  var _response$data, _response$data$conten, _response$data$conten2, _contentData$space;
58
58
  const {
@@ -15,7 +15,7 @@ export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromCo
15
15
  // providers
16
16
  export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
17
17
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
18
- export { fetchConfluenceSourceInfo } from './clients/confluence/sourceInfo';
18
+ export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
19
19
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
20
20
  // store managers
21
21
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';
@@ -56,18 +56,6 @@ class BlockServiceADFFetchProvider {
56
56
  };
57
57
  }
58
58
  }
59
- retrieveSourceInfoFetchData(resourceId, pageARI) {
60
- let sourceLocalId;
61
- try {
62
- sourceLocalId = getLocalIdFromBlockResourceId(resourceId);
63
- } catch (error) {
64
- // EDITOR-1921: log analytic here, safe to continue
65
- }
66
- return {
67
- pageARI,
68
- sourceLocalId
69
- };
70
- }
71
59
  }
72
60
 
73
61
  /**
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { useMemo } from 'react';
3
- import { getConfluencePageAri, getPageARIFromContentPropertyResourceId, getLocalIdFromConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from '../../clients/confluence/ari';
3
+ import { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageIdAndTypeFromConfluencePageAri, resourceIdFromConfluencePageSourceIdAndLocalId } from '../../clients/confluence/ari';
4
4
  import { getContentProperty, createContentProperty, updateContentProperty, deleteContentProperty } from '../../clients/confluence/contentProperty';
5
5
  import { isBlogPageType } from '../../clients/confluence/utils';
6
6
  import { SyncBlockError } from '../../common/types';
@@ -108,19 +108,6 @@ class ConfluenceADFFetchProvider {
108
108
  };
109
109
  }
110
110
  }
111
- retrieveSourceInfoFetchData(resourceId) {
112
- const pageARI = getPageARIFromContentPropertyResourceId(resourceId);
113
- let sourceLocalId;
114
- try {
115
- sourceLocalId = getLocalIdFromConfluencePageAri(resourceId);
116
- } catch (error) {
117
- // EDITOR-1921: log analytic here, safe to continue
118
- }
119
- return {
120
- pageARI,
121
- sourceLocalId
122
- };
123
- }
124
111
  }
125
112
 
126
113
  /**
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { useMemo } from 'react';
3
3
  import { getPageIdAndTypeFromConfluencePageAri } from '../clients/confluence/ari';
4
- import { fetchConfluenceSourceInfo } from '../clients/confluence/sourceInfo';
4
+ import { fetchConfluencePageInfo } from '../clients/confluence/sourceInfo';
5
5
  import { SyncBlockError } from '../common/types';
6
6
  import { SyncBlockDataProvider } from '../providers/types';
7
7
  export class SyncBlockProvider extends SyncBlockDataProvider {
@@ -131,34 +131,26 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
131
131
  }
132
132
 
133
133
  /**
134
- * Retrieve the source info from the source id
134
+ * Fetch the source info from the source id
135
135
  *
136
- * @param node
136
+ * @param params
137
+ * @param params.sourceAri - The source ARI
138
+ * @param params.sourceProduct - The source product. e.g. 'confluence-page', 'jira-work-item'
137
139
  *
138
140
  * @returns The source info
139
141
  */
140
- retrieveSyncBlockSourceInfo(node) {
141
- // with content API, this is the concatenation of the page ARI and the block's localId.
142
- // with block service, this is the ARI of the block.
143
- // this can be cleaned up from the specific providers and placed here after platform_synced_blocks_block_service_provider
144
- const {
145
- resourceId
146
- } = node.attrs;
147
- let pageARI;
148
- let sourceLocalId;
149
- if (resourceId && typeof resourceId === 'string') {
150
- try {
151
- const fetchData = this.fetchProvider.retrieveSourceInfoFetchData(resourceId, this.sourceId);
152
- pageARI = fetchData.pageARI;
153
- sourceLocalId = fetchData.sourceLocalId;
154
- } catch (error) {
155
- return Promise.reject(error);
156
- }
142
+ fetchSyncBlockSourceInfo(localId, sourceAri, sourceProduct) {
143
+ if (!sourceAri || !sourceProduct) {
144
+ return Promise.resolve(undefined);
145
+ }
146
+ switch (sourceProduct) {
147
+ case 'confluence-page':
148
+ return fetchConfluencePageInfo(sourceAri, localId);
149
+ case 'jira-work-item':
150
+ return Promise.reject(new Error('Jira work item source product not supported'));
151
+ default:
152
+ return Promise.reject(new Error(`${sourceProduct} source product not supported`));
157
153
  }
158
-
159
- // TODO: EDITOR-3312 - based on the source sync block product,
160
- // execute fetchConfluenceSourceInfo or fetchJiraItemSourceInfo or similar...
161
- return pageARI ? fetchConfluenceSourceInfo(pageARI, sourceLocalId) : Promise.resolve(undefined);
162
154
  }
163
155
  generateResourceId(sourceId, localId) {
164
156
  return this.writeProvider.generateResourceId(sourceId, localId);
@@ -176,32 +168,26 @@ export class SyncBlockProvider extends SyncBlockDataProvider {
176
168
  /**
177
169
  * Retrieve the parent info for the sync block
178
170
  *
179
- * @param resourceId
180
- * @param syncBlockInstance
171
+ * @param sourceAri - The source ARI
172
+ * @param sourceProduct - The source product. e.g. 'confluence-page', 'jira-work-item'
181
173
  *
182
174
  * @returns The parent info for the sync block
183
175
  */
184
- retrieveSyncBlockParentInfo(syncBlockInstance) {
185
- if (!syncBlockInstance || !syncBlockInstance.data) {
176
+ retrieveSyncBlockParentInfo(sourceAri, sourceProduct) {
177
+ if (!sourceAri || !sourceProduct) {
186
178
  return undefined;
187
179
  }
188
- const {
189
- sourceAri,
190
- product
191
- } = syncBlockInstance.data;
192
- if (!sourceAri || !product) {
193
- return undefined;
180
+ switch (sourceProduct) {
181
+ case 'confluence-page':
182
+ return {
183
+ contentId: getPageIdAndTypeFromConfluencePageAri(sourceAri).id,
184
+ contentProduct: sourceProduct
185
+ };
186
+ case 'jira-work-item':
187
+ throw new Error('Jira work item source product not supported');
188
+ default:
189
+ throw new Error(`${sourceProduct} source product not supported`);
194
190
  }
195
-
196
- // TODO: EDITOR-3312 - based on the source sync block product,
197
- // execute getPageIdAndTypeFromConfluencePageAri or getJiraItemIdAndTypeFromJiraItemAri or similar...
198
- const {
199
- id: contentId
200
- } = getPageIdAndTypeFromConfluencePageAri(sourceAri);
201
- return {
202
- contentId,
203
- contentProduct: product
204
- };
205
191
  }
206
192
  }
207
193
  export const useMemoizedSyncedBlockProvider = (fetchProvider, writeProvider, sourceId, providerOptions) => {
@@ -45,34 +45,43 @@ export class ReferenceSyncBlockStoreManager {
45
45
  this.isRefreshingSubscriptions = false;
46
46
  }
47
47
  }
48
- retrieveSyncBlockSourceInfo(resourceId) {
48
+ fetchSyncBlockSourceInfo(resourceId) {
49
+ var _existingSyncBlock$da, _existingSyncBlock$da2;
49
50
  if (!resourceId || !this.dataProvider) {
50
51
  return;
51
52
  }
53
+ if (this.syncBlockURLRequests.get(resourceId)) {
54
+ return;
55
+ }
56
+ this.syncBlockURLRequests.set(resourceId, true);
57
+ const existingSyncBlock = this.getFromCache(resourceId);
58
+ if (!existingSyncBlock) {
59
+ return;
60
+ }
52
61
 
53
- // TODO: EDITOR-3312 - retrieve the source info based on the source sync block product
54
-
55
- // if the sync block is a reference block, we need to fetch the URL to the source
56
- // we could optimise this further by checking if the sync block is on the same page as the source
57
- if (!this.syncBlockURLRequests.get(resourceId)) {
58
- this.syncBlockURLRequests.set(resourceId, true);
59
- this.dataProvider.retrieveSyncBlockSourceInfo(createSyncBlockNode('', resourceId)).then(sourceInfo => {
60
- const existingSyncBlock = this.getFromCache(resourceId);
61
- if (existingSyncBlock && existingSyncBlock.data) {
62
- existingSyncBlock.data = {
63
- ...existingSyncBlock.data,
64
- sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
65
- sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
66
- };
67
- this.updateCache(existingSyncBlock);
68
- if (sourceInfo !== null && sourceInfo !== void 0 && sourceInfo.title) {
69
- this.updateSourceTitleSubscriptions(existingSyncBlock.resourceId, sourceInfo.title);
70
- }
71
- }
72
- }).finally(() => {
73
- this.syncBlockURLRequests.set(resourceId, false);
74
- });
62
+ // skip if source URL and title are already present
63
+ 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) {
64
+ return;
65
+ }
66
+ const {
67
+ sourceAri,
68
+ product,
69
+ blockInstanceId
70
+ } = existingSyncBlock.data || {};
71
+ if (!sourceAri || !product || !blockInstanceId) {
72
+ return;
75
73
  }
74
+ this.dataProvider.fetchSyncBlockSourceInfo(blockInstanceId, sourceAri, product).then(sourceInfo => {
75
+ if (!sourceInfo) {
76
+ return;
77
+ }
78
+ this.updateCacheWithSourceInfo(resourceId, sourceInfo);
79
+ if (sourceInfo.title) {
80
+ this.updateSourceTitleSubscriptions(resourceId, sourceInfo.title);
81
+ }
82
+ }).finally(() => {
83
+ this.syncBlockURLRequests.delete(resourceId);
84
+ });
76
85
  }
77
86
 
78
87
  /**
@@ -105,7 +114,6 @@ export class ReferenceSyncBlockStoreManager {
105
114
  }
106
115
  const resolvedData = [];
107
116
  data.forEach(syncBlockInstance => {
108
- var _resolvedSyncBlockIns, _resolvedSyncBlockIns2;
109
117
  if (!syncBlockInstance.resourceId) {
110
118
  return;
111
119
  }
@@ -118,14 +126,22 @@ export class ReferenceSyncBlockStoreManager {
118
126
  const resolvedSyncBlockInstance = existingSyncBlock ? resolveSyncBlockInstance(existingSyncBlock, syncBlockInstance) : syncBlockInstance;
119
127
  this.updateCache(resolvedSyncBlockInstance);
120
128
  resolvedData.push(resolvedSyncBlockInstance);
121
-
122
- // fetch source URL and title if not already present
123
- if ((!((_resolvedSyncBlockIns = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns !== void 0 && _resolvedSyncBlockIns.sourceURL) || !((_resolvedSyncBlockIns2 = resolvedSyncBlockInstance.data) !== null && _resolvedSyncBlockIns2 !== void 0 && _resolvedSyncBlockIns2.sourceTitle)) && resolvedSyncBlockInstance.resourceId) {
124
- this.retrieveSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
125
- }
129
+ this.fetchSyncBlockSourceInfo(resolvedSyncBlockInstance.resourceId);
126
130
  });
127
131
  return [...resolvedData, ...blocksWithNotFoundError];
128
132
  }
133
+ updateCacheWithSourceInfo(resourceId, sourceInfo) {
134
+ const existingSyncBlock = this.getFromCache(resourceId);
135
+ if (existingSyncBlock && existingSyncBlock.data) {
136
+ existingSyncBlock.data.sourceURL = sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url;
137
+ existingSyncBlock.data = {
138
+ ...existingSyncBlock.data,
139
+ sourceURL: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.url,
140
+ sourceTitle: sourceInfo === null || sourceInfo === void 0 ? void 0 : sourceInfo.title
141
+ };
142
+ this.updateCache(existingSyncBlock);
143
+ }
144
+ }
129
145
  updateCache(syncBlock) {
130
146
  const {
131
147
  resourceId
@@ -270,6 +286,7 @@ export class ReferenceSyncBlockStoreManager {
270
286
  return providerFactory;
271
287
  }
272
288
  retrieveDynamicProviders(resourceId, providerFactory, providerCreator) {
289
+ var _syncBlock$data2, _syncBlock$data3, _syncBlock$data4, _syncBlock$data5;
273
290
  if (!this.dataProvider) {
274
291
  return;
275
292
  }
@@ -278,7 +295,11 @@ export class ReferenceSyncBlockStoreManager {
278
295
  if (hasMediaProvider && hasEmojiProvider) {
279
296
  return;
280
297
  }
281
- const parentInfo = this.dataProvider.retrieveSyncBlockParentInfo(this.syncBlockCache.get(resourceId));
298
+ const syncBlock = this.getFromCache(resourceId);
299
+ if (!syncBlock || !((_syncBlock$data2 = syncBlock.data) !== null && _syncBlock$data2 !== void 0 && _syncBlock$data2.sourceAri) || !((_syncBlock$data3 = syncBlock.data) !== null && _syncBlock$data3 !== void 0 && _syncBlock$data3.product)) {
300
+ return;
301
+ }
302
+ const parentInfo = this.dataProvider.retrieveSyncBlockParentInfo((_syncBlock$data4 = syncBlock.data) === null || _syncBlock$data4 === void 0 ? void 0 : _syncBlock$data4.sourceAri, (_syncBlock$data5 = syncBlock.data) === null || _syncBlock$data5 === void 0 ? void 0 : _syncBlock$data5.product);
282
303
  if (!parentInfo) {
283
304
  return;
284
305
  }
@@ -63,7 +63,7 @@ var getConfluenceSourceInfo = /*#__PURE__*/function () {
63
63
  return _ref.apply(this, arguments);
64
64
  };
65
65
  }();
66
- export var fetchConfluenceSourceInfo = /*#__PURE__*/function () {
66
+ export var fetchConfluencePageInfo = /*#__PURE__*/function () {
67
67
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(pageAri, localId) {
68
68
  var _response$data, _contentData$space, _getPageIdAndTypeFrom, pageType, response, contentData, title, url, _ref3, base;
69
69
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
@@ -108,7 +108,7 @@ export var fetchConfluenceSourceInfo = /*#__PURE__*/function () {
108
108
  }
109
109
  }, _callee2, null, [[0, 15]]);
110
110
  }));
111
- return function fetchConfluenceSourceInfo(_x2, _x3) {
111
+ return function fetchConfluencePageInfo(_x2, _x3) {
112
112
  return _ref2.apply(this, arguments);
113
113
  };
114
114
  }();
package/dist/esm/index.js CHANGED
@@ -15,7 +15,7 @@ export { getConfluencePageAri, getLocalIdFromConfluencePageAri, getPageARIFromCo
15
15
  // providers
16
16
  export { useMemoizedBlockServiceAPIProviders } from './providers/block-service/blockServiceAPI';
17
17
  export { createContentAPIProvidersWithDefaultKey, useMemoizedContentAPIProviders } from './providers/confluence/confluenceContentAPI';
18
- export { fetchConfluenceSourceInfo } from './clients/confluence/sourceInfo';
18
+ export { fetchConfluencePageInfo } from './clients/confluence/sourceInfo';
19
19
  export { SyncBlockProvider as SyncedBlockProvider, useMemoizedSyncedBlockProvider } from './providers/syncBlockProvider';
20
20
  // store managers
21
21
  export { ReferenceSyncBlockStoreManager } from './store-manager/referenceSyncBlockStoreManager';