@atlaskit/editor-plugin-card 0.5.11 → 0.7.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/analytics/events-from-tr.js +1 -0
  3. package/dist/cjs/nodeviews/blockCard.js +20 -0
  4. package/dist/cjs/pm-plugins/doc.js +42 -28
  5. package/dist/cjs/toolbar.js +24 -6
  6. package/dist/cjs/ui/DatasourceModal/index.js +1 -1
  7. package/dist/cjs/ui/EditDatasourceButton.js +144 -0
  8. package/dist/cjs/ui/EditLinkToolbar.js +4 -27
  9. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +141 -19
  10. package/dist/es2019/analytics/events-from-tr.js +1 -0
  11. package/dist/es2019/nodeviews/blockCard.js +15 -0
  12. package/dist/es2019/pm-plugins/doc.js +36 -22
  13. package/dist/es2019/toolbar.js +22 -6
  14. package/dist/es2019/ui/DatasourceModal/index.js +2 -2
  15. package/dist/es2019/ui/EditDatasourceButton.js +101 -0
  16. package/dist/es2019/ui/EditLinkToolbar.js +1 -23
  17. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +146 -13
  18. package/dist/esm/analytics/events-from-tr.js +1 -0
  19. package/dist/esm/nodeviews/blockCard.js +20 -0
  20. package/dist/esm/pm-plugins/doc.js +40 -26
  21. package/dist/esm/toolbar.js +24 -6
  22. package/dist/esm/ui/DatasourceModal/index.js +2 -2
  23. package/dist/esm/ui/EditDatasourceButton.js +134 -0
  24. package/dist/esm/ui/EditLinkToolbar.js +1 -23
  25. package/dist/esm/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +141 -19
  26. package/dist/types/analytics/events-from-tr.d.ts +2 -2
  27. package/dist/types/analytics/types.d.ts +1 -1
  28. package/dist/types/nodeviews/blockCard.d.ts +5 -1
  29. package/dist/types/pm-plugins/doc.d.ts +9 -8
  30. package/dist/types/ui/DatasourceModal/index.d.ts +3 -3
  31. package/dist/types/ui/EditDatasourceButton.d.ts +17 -0
  32. package/dist/types/ui/EditLinkToolbar.d.ts +0 -1
  33. package/dist/types/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +1 -1
  34. package/dist/types-ts4.5/analytics/events-from-tr.d.ts +2 -2
  35. package/dist/types-ts4.5/analytics/types.d.ts +1 -1
  36. package/dist/types-ts4.5/nodeviews/blockCard.d.ts +5 -1
  37. package/dist/types-ts4.5/pm-plugins/doc.d.ts +9 -8
  38. package/dist/types-ts4.5/ui/DatasourceModal/index.d.ts +3 -3
  39. package/dist/types-ts4.5/ui/EditDatasourceButton.d.ts +17 -0
  40. package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +0 -1
  41. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +1 -1
  42. package/package.json +4 -4
  43. package/report.api.md +1 -1
  44. package/tmp/api-report-tmp.d.ts +1 -1
  45. package/dist/cjs/ui/SmallerEditIcon.js +0 -22
  46. package/dist/es2019/ui/SmallerEditIcon.js +0 -14
  47. package/dist/esm/ui/SmallerEditIcon.js +0 -14
  48. package/dist/types/ui/SmallerEditIcon.d.ts +0 -3
  49. package/dist/types-ts4.5/ui/SmallerEditIcon.d.ts +0 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`50b3bf73ed3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/50b3bf73ed3) - [ux] Add edit datasource button to toolbar for cards which can resolve into datasources
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+
13
+ ## 0.6.0
14
+
15
+ ### Minor Changes
16
+
17
+ - [`8b8a309cb62`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8b8a309cb62) - Added datasource analytic CRUD events
18
+
19
+ ### Patch Changes
20
+
21
+ - Updated dependencies
22
+
3
23
  ## 0.5.11
4
24
 
5
25
  ### Patch Changes
@@ -140,6 +140,7 @@ var findChanged = function findChanged(tr, state) {
140
140
  if (!isUpdate) {
141
141
  var _getLinkMetadataFromT = (0, _card.getLinkMetadataFromTransaction)(tr),
142
142
  inputMethod = _getLinkMetadataFromT.inputMethod;
143
+
143
144
  /**
144
145
  * If there is no identifiable input method, and the links inserted and removed appear to be the same,
145
146
  * then this transaction likely is not intended to be consided to be the insertion and removal of links
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.BlockCardComponent = exports.BlockCard = void 0;
8
+ var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
8
9
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
10
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
11
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
@@ -144,6 +145,25 @@ var BlockCard = /*#__PURE__*/function (_ReactNodeView) {
144
145
  }
145
146
  return domRef;
146
147
  }
148
+
149
+ // Need this function to check if the datasource attribute was added or not to a blockCard.
150
+ // If so, we return false so we can get the node to re-render properly as a datasource node instead.
151
+ // Otherwise, the node view will still consider the node as a blockCard and render a regular blockCard.
152
+ }, {
153
+ key: "validUpdate",
154
+ value: function validUpdate(currentNode, newNode) {
155
+ var _currentNode$attrs, _newNode$attrs;
156
+ var isCurrentNodeBlockCard = !((_currentNode$attrs = currentNode.attrs) !== null && _currentNode$attrs !== void 0 && _currentNode$attrs.datasource);
157
+ var isNewNodeDatasource = (_newNode$attrs = newNode.attrs) === null || _newNode$attrs === void 0 ? void 0 : _newNode$attrs.datasource;
158
+
159
+ // need to return falsy to update node
160
+ return !(isCurrentNodeBlockCard && isNewNodeDatasource);
161
+ }
162
+ }, {
163
+ key: "update",
164
+ value: function update(node, decorations, _innerDecorations) {
165
+ return (0, _get2.default)((0, _getPrototypeOf2.default)(BlockCard.prototype), "update", this).call(this, node, decorations, _innerDecorations, this.validUpdate);
166
+ }
147
167
  }, {
148
168
  key: "render",
149
169
  value: function render() {
@@ -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.updateExistingDatasource = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.convertHyperlinkToSmartCard = exports.changeSelectedCardToText = exports.changeSelectedCardToLinkFallback = exports.changeSelectedCardToLink = void 0;
7
+ exports.updateCardFromDatasourceModal = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.convertHyperlinkToSmartCard = exports.changeSelectedCardToText = exports.changeSelectedCardToLinkFallback = exports.changeSelectedCardToLink = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
@@ -428,45 +428,55 @@ var getLinkNodeType = function getLinkNodeType(appearance, linkNodes) {
428
428
  }
429
429
  };
430
430
 
431
- // Apply an update to a datasource (aka blockCard) node
431
+ // Apply an update made from the datasource edit modal to a card
432
432
  exports.getLinkNodeType = getLinkNodeType;
433
- var updateExistingDatasource = function updateExistingDatasource(state, node, newAdf, view) {
433
+ var updateCardFromDatasourceModal = function updateCardFromDatasourceModal(state, node, newAdf, view, sourceEvent) {
434
434
  var tr = state.tr,
435
435
  from = state.selection.from,
436
436
  schemaNodes = state.schema.nodes;
437
-
438
- // datasource to datasource
439
- if (newAdf.type === 'blockCard' && newAdf.attrs.datasource && node.attrs.datasource) {
440
- var _ref3, _ref6, _newViews$properties, _oldViews$properties, _newAdf$attrs, _node$attrs;
441
- var _ref = (_ref3 = newAdf.attrs.datasource.views) !== null && _ref3 !== void 0 ? _ref3 : [],
442
- _ref2 = (0, _slicedToArray2.default)(_ref, 1),
443
- newViews = _ref2[0];
444
- var _ref4 = (_ref6 = node.attrs.datasource.views) !== null && _ref6 !== void 0 ? _ref6 : [],
445
- _ref5 = (0, _slicedToArray2.default)(_ref4, 1),
446
- oldViews = _ref5[0];
447
- var newColumnKeys = newViews === null || newViews === void 0 ? void 0 : (_newViews$properties = newViews.properties) === null || _newViews$properties === void 0 ? void 0 : _newViews$properties.columns.map(function (column) {
448
- return column.key;
449
- });
450
- var oldColumnKeys = oldViews === null || oldViews === void 0 ? void 0 : (_oldViews$properties = oldViews.properties) === null || _oldViews$properties === void 0 ? void 0 : _oldViews$properties.columns.map(function (column) {
451
- return column.key;
452
- });
453
- var isColumnChange = !(0, _isEqual.default)(oldColumnKeys, newColumnKeys);
454
- var isUrlChange = ((_newAdf$attrs = newAdf.attrs) === null || _newAdf$attrs === void 0 ? void 0 : _newAdf$attrs.url) !== ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url);
455
- if (isColumnChange || isUrlChange) {
456
- tr.setNodeMarkup(from, schemaNodes.blockCard, _objectSpread(_objectSpread({}, node.attrs), newAdf.attrs));
457
- (0, _card.addLinkMetadata)(state.selection, tr, {
458
- action: _analytics.ACTION.UPDATED
437
+ if (newAdf.type === 'blockCard') {
438
+ var _node$attrs, _newAdf$attrs;
439
+ if ((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.datasource && (_newAdf$attrs = newAdf.attrs) !== null && _newAdf$attrs !== void 0 && _newAdf$attrs.datasource) {
440
+ var _ref3, _ref6, _newViews$properties, _oldViews$properties, _newAdf$attrs2, _node$attrs2;
441
+ // datasource to datasource
442
+ var _ref = (_ref3 = newAdf.attrs.datasource.views) !== null && _ref3 !== void 0 ? _ref3 : [],
443
+ _ref2 = (0, _slicedToArray2.default)(_ref, 1),
444
+ newViews = _ref2[0];
445
+ var _ref4 = (_ref6 = node.attrs.datasource.views) !== null && _ref6 !== void 0 ? _ref6 : [],
446
+ _ref5 = (0, _slicedToArray2.default)(_ref4, 1),
447
+ oldViews = _ref5[0];
448
+ var newColumnKeys = newViews === null || newViews === void 0 ? void 0 : (_newViews$properties = newViews.properties) === null || _newViews$properties === void 0 ? void 0 : _newViews$properties.columns.map(function (column) {
449
+ return column.key;
459
450
  });
451
+ var oldColumnKeys = oldViews === null || oldViews === void 0 ? void 0 : (_oldViews$properties = oldViews.properties) === null || _oldViews$properties === void 0 ? void 0 : _oldViews$properties.columns.map(function (column) {
452
+ return column.key;
453
+ });
454
+ var isColumnChange = !(0, _isEqual.default)(oldColumnKeys, newColumnKeys);
455
+ var isUrlChange = ((_newAdf$attrs2 = newAdf.attrs) === null || _newAdf$attrs2 === void 0 ? void 0 : _newAdf$attrs2.url) !== ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.url);
456
+ if (isColumnChange || isUrlChange) {
457
+ tr.setNodeMarkup(from, schemaNodes.blockCard, _objectSpread(_objectSpread({}, node.attrs), newAdf.attrs));
458
+ (0, _card.addLinkMetadata)(state.selection, tr, {
459
+ action: _analytics.ACTION.UPDATED,
460
+ sourceEvent: sourceEvent
461
+ });
462
+ }
463
+ } else {
464
+ // inline or blockCard to datasource
465
+ tr.setNodeMarkup(from, schemaNodes.blockCard, newAdf.attrs);
460
466
  }
461
467
  } else if (newAdf.type === 'inlineCard') {
462
- // datasource to inline
468
+ // card type to inlineCard
463
469
  tr.setNodeMarkup(from, schemaNodes.inlineCard, newAdf.attrs);
470
+ (0, _card.addLinkMetadata)(state.selection, tr, {
471
+ action: _analytics.ACTION.UPDATED,
472
+ sourceEvent: sourceEvent
473
+ });
464
474
  }
465
475
  (0, _actions.hideDatasourceModal)(tr);
466
476
  view.dispatch(tr.scrollIntoView());
467
477
  };
468
- exports.updateExistingDatasource = updateExistingDatasource;
469
- var insertDatasource = function insertDatasource(state, adf, view) {
478
+ exports.updateCardFromDatasourceModal = updateCardFromDatasourceModal;
479
+ var insertDatasource = function insertDatasource(state, adf, view, sourceEvent) {
470
480
  var tr = state.tr,
471
481
  from = state.selection.from,
472
482
  schemaNodes = state.schema.nodes;
@@ -478,6 +488,10 @@ var insertDatasource = function insertDatasource(state, adf, view) {
478
488
  // this will allow us to deal with insertions from multiple paths in a more consistent way
479
489
  newNode && tr.insert(from, newNode);
480
490
  (0, _actions.hideDatasourceModal)(tr);
491
+ (0, _card.addLinkMetadata)(state.selection, tr, {
492
+ action: _analytics.ACTION.INSERTED,
493
+ sourceEvent: sourceEvent
494
+ });
481
495
  view.dispatch(tr.scrollIntoView());
482
496
  };
483
497
  exports.insertDatasource = insertDatasource;
@@ -14,6 +14,7 @@ var _analytics = require("@atlaskit/editor-common/analytics");
14
14
  var _card = require("@atlaskit/editor-common/card");
15
15
  var _messages = _interopRequireWildcard(require("@atlaskit/editor-common/messages"));
16
16
  var _styles = require("@atlaskit/editor-common/styles");
17
+ var _ui = require("@atlaskit/editor-common/ui");
17
18
  var _utils = require("@atlaskit/editor-common/utils");
18
19
  var _state = require("@atlaskit/editor-prosemirror/state");
19
20
  var _utils2 = require("@atlaskit/editor-prosemirror/utils");
@@ -24,9 +25,9 @@ var _shortcut = _interopRequireDefault(require("@atlaskit/icon/glyph/shortcut"))
24
25
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
25
26
  var _doc = require("./pm-plugins/doc");
26
27
  var _main = require("./pm-plugins/main");
28
+ var _EditDatasourceButton = require("./ui/EditDatasourceButton");
27
29
  var _EditLinkToolbar = require("./ui/EditLinkToolbar");
28
30
  var _LinkToolbarAppearance = require("./ui/LinkToolbarAppearance");
29
- var _SmallerEditIcon = require("./ui/SmallerEditIcon");
30
31
  var _ToolbarViewedEvent = require("./ui/ToolbarViewedEvent");
31
32
  var _utils3 = require("./utils");
32
33
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -231,7 +232,7 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
231
232
  pluginInjectionApi: pluginInjectionApi
232
233
  })];
233
234
  } else if (shouldRenderDatasourceToolbar) {
234
- return getDatasourceButtonGroup(state, metadata, intl, editorAnalyticsApi, node, hoverDecoration);
235
+ return getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, node.attrs.datasource.id);
235
236
  } else {
236
237
  var inlineCard = state.schema.nodes.inlineCard;
237
238
  var toolbarItems = [{
@@ -288,7 +289,8 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
288
289
  toolbarItems.unshift.apply(toolbarItems, (0, _toConsumableArray2.default)(alignmentOptions));
289
290
  }
290
291
  var allowBlockCards = cardOptions.allowBlockCards,
291
- allowEmbeds = cardOptions.allowEmbeds;
292
+ allowEmbeds = cardOptions.allowEmbeds,
293
+ allowDatasource = cardOptions.allowDatasource;
292
294
 
293
295
  // This code will be executed only for appearances such as "inline", "block" & "embed"
294
296
  // For url appearance, please see HyperlinkToolbarAppearanceProps
@@ -315,6 +317,22 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
315
317
  type: 'separator'
316
318
  }]));
317
319
  }
320
+ var shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource;
321
+ if (shouldShowDatasourceEditButton) {
322
+ toolbarItems.unshift({
323
+ type: 'custom',
324
+ fallback: [],
325
+ render: function render(editorView) {
326
+ return /*#__PURE__*/_react.default.createElement(_EditDatasourceButton.EditDatasourceButton, {
327
+ intl: intl,
328
+ editorAnalyticsApi: editorAnalyticsApi,
329
+ url: url,
330
+ editorView: editorView,
331
+ editorState: state
332
+ });
333
+ }
334
+ });
335
+ }
318
336
  return toolbarItems;
319
337
  }
320
338
  };
@@ -343,16 +361,16 @@ var getSettingsButtonGroup = function getSettingsButtonGroup(state, featureFlags
343
361
  type: 'separator'
344
362
  }] : [];
345
363
  };
346
- var getDatasourceButtonGroup = function getDatasourceButtonGroup(state, metadata, intl, editorAnalyticsApi, node, hoverDecoration) {
364
+ var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, datasourceId) {
347
365
  var _node$attrs3;
348
366
  var toolbarItems = [{
349
367
  id: 'editor.edit.datasource',
350
368
  type: 'button',
351
- icon: _SmallerEditIcon.SmallerEditIcon,
369
+ icon: _ui.SmallerEditIcon,
352
370
  metadata: metadata,
353
371
  className: 'datasource-edit',
354
372
  title: intl.formatMessage(_messages.linkToolbarMessages.editDatasource),
355
- onClick: (0, _EditLinkToolbar.editDatasource)(node, editorAnalyticsApi),
373
+ onClick: (0, _EditDatasourceButton.editDatasource)(datasourceId, editorAnalyticsApi),
356
374
  testId: 'datasource-edit-button'
357
375
  }];
358
376
  if (node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.url) {
@@ -26,7 +26,7 @@ var DatasourceModal = function DatasourceModal(_ref) {
26
26
  }, [dispatch, state.tr]);
27
27
  var onInsert = (0, _react.useCallback)(function (newAdf) {
28
28
  if (existingNode) {
29
- (0, _doc.updateExistingDatasource)(state, existingNode, newAdf, view);
29
+ (0, _doc.updateCardFromDatasourceModal)(state, existingNode, newAdf, view);
30
30
  } else {
31
31
  (0, _doc.insertDatasource)(state, newAdf, view);
32
32
  }
@@ -0,0 +1,144 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.editDatasource = exports.EditDatasourceButton = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
+ var _react = require("react");
12
+ var _react2 = require("@emotion/react");
13
+ var _messages = require("@atlaskit/editor-common/messages");
14
+ var _ui = require("@atlaskit/editor-common/ui");
15
+ var _utils = require("@atlaskit/editor-common/utils");
16
+ var _actions = require("../pm-plugins/actions");
17
+ var _CardContextProvider = require("./CardContextProvider");
18
+ /** @jsx jsx */
19
+
20
+ var buttonStyles = (0, _react2.css)({
21
+ pointerEvents: 'auto'
22
+ });
23
+ var buttonWrapperStyles = (0, _react2.css)({
24
+ display: 'flex'
25
+ });
26
+ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardContext(_ref) {
27
+ var cardContext = _ref.cardContext,
28
+ intl = _ref.intl,
29
+ editorAnalyticsApi = _ref.editorAnalyticsApi,
30
+ url = _ref.url,
31
+ editorView = _ref.editorView,
32
+ editorState = _ref.editorState;
33
+ var _useState = (0, _react.useState)(null),
34
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
35
+ datasourceId = _useState2[0],
36
+ setDatasourceId = _useState2[1];
37
+ (0, _react.useEffect)(function () {
38
+ var fetchDatasource = /*#__PURE__*/function () {
39
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
40
+ var _cardContext$connecti, _cardContext$connecti2, _datasources$, response, datasources;
41
+ return _regenerator.default.wrap(function _callee$(_context) {
42
+ while (1) switch (_context.prev = _context.next) {
43
+ case 0:
44
+ _context.prev = 0;
45
+ _context.t0 = url && cardContext;
46
+ if (!_context.t0) {
47
+ _context.next = 6;
48
+ break;
49
+ }
50
+ _context.next = 5;
51
+ return cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$connecti = cardContext.connections) === null || _cardContext$connecti === void 0 ? void 0 : (_cardContext$connecti2 = _cardContext$connecti.client) === null || _cardContext$connecti2 === void 0 ? void 0 : _cardContext$connecti2.fetchData(url);
52
+ case 5:
53
+ _context.t0 = _context.sent;
54
+ case 6:
55
+ response = _context.t0;
56
+ datasources = response && response.datasources || [];
57
+ setDatasourceId(((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id) || null);
58
+ _context.next = 14;
59
+ break;
60
+ case 11:
61
+ _context.prev = 11;
62
+ _context.t1 = _context["catch"](0);
63
+ setDatasourceId(null);
64
+ case 14:
65
+ case "end":
66
+ return _context.stop();
67
+ }
68
+ }, _callee, null, [[0, 11]]);
69
+ }));
70
+ return function fetchDatasource() {
71
+ return _ref2.apply(this, arguments);
72
+ };
73
+ }();
74
+ void fetchDatasource();
75
+ }, [cardContext, url]);
76
+ if (!datasourceId || !(0, _utils.canRenderDatasource)(datasourceId, false)) {
77
+ return null;
78
+ }
79
+ if (url) {
80
+ var _cardContext$store, _urlState$error;
81
+ var urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
82
+ if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
83
+ return null;
84
+ }
85
+ }
86
+ var dispatchCommand = function dispatchCommand(fn) {
87
+ fn && fn(editorState, editorView && editorView.dispatch);
88
+ if (editorView && !editorView.hasFocus()) {
89
+ editorView.focus();
90
+ }
91
+ };
92
+ return (0, _react2.jsx)("div", {
93
+ css: buttonWrapperStyles
94
+ }, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
95
+ css: buttonStyles,
96
+ title: intl.formatMessage(_messages.cardMessages.datasourceTitle),
97
+ icon: (0, _react2.jsx)(_ui.SmallerEditIcon, null),
98
+ selected: false,
99
+ onClick: function onClick() {
100
+ return dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
101
+ },
102
+ testId: 'card-edit-datasource-button'
103
+ }), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
104
+ };
105
+ var EditDatasourceButton = function EditDatasourceButton(_ref3) {
106
+ var intl = _ref3.intl,
107
+ editorAnalyticsApi = _ref3.editorAnalyticsApi,
108
+ url = _ref3.url,
109
+ editorView = _ref3.editorView,
110
+ editorState = _ref3.editorState;
111
+ return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref4) {
112
+ var cardContext = _ref4.cardContext;
113
+ return (0, _react2.jsx)(EditDatasourceButtonWithCardContext, {
114
+ url: url,
115
+ intl: intl,
116
+ editorAnalyticsApi: editorAnalyticsApi,
117
+ editorView: editorView,
118
+ editorState: editorState,
119
+ cardContext: cardContext
120
+ });
121
+ });
122
+ };
123
+ exports.EditDatasourceButton = EditDatasourceButton;
124
+ var editDatasource = function editDatasource(datasourceId, editorAnalyticsApi) {
125
+ return function (state, dispatch) {
126
+ var datasourceType = (0, _utils.getDatasourceType)(datasourceId);
127
+ if (dispatch && datasourceType) {
128
+ var tr = state.tr;
129
+ (0, _actions.showDatasourceModal)(datasourceType)(tr);
130
+ // editorAnalyticsApi?.attachAnalyticsEvent(
131
+ // buildEditLinkPayload(
132
+ // type as
133
+ // | ACTION_SUBJECT_ID.CARD_INLINE
134
+ // | ACTION_SUBJECT_ID.CARD_BLOCK
135
+ // | ACTION_SUBJECT_ID.EMBEDS,
136
+ // ),
137
+ // )(tr);
138
+ dispatch(tr);
139
+ return true;
140
+ }
141
+ return false;
142
+ };
143
+ };
144
+ exports.editDatasource = editDatasource;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.EditLinkToolbar = void 0;
8
8
  exports.HyperlinkAddToolbarWithState = HyperlinkAddToolbarWithState;
9
- exports.editLinkToolbarConfig = exports.editLink = exports.editDatasource = exports.buildEditLinkToolbar = void 0;
9
+ exports.editLinkToolbarConfig = exports.editLink = exports.buildEditLinkToolbar = void 0;
10
10
  var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
11
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
12
  var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
@@ -19,11 +19,10 @@ var _hooks = require("@atlaskit/editor-common/hooks");
19
19
  var _link = require("@atlaskit/editor-common/link");
20
20
  var _messages = require("@atlaskit/editor-common/messages");
21
21
  var _ui = require("@atlaskit/editor-common/ui");
22
- var _utils = require("@atlaskit/editor-common/utils");
23
22
  var _state = require("@atlaskit/editor-prosemirror/state");
24
23
  var _actions = require("../pm-plugins/actions");
25
24
  var _doc = require("../pm-plugins/doc");
26
- var _utils2 = require("../utils");
25
+ var _utils = require("../utils");
27
26
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
28
27
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
29
28
  function HyperlinkAddToolbarWithState(_ref) {
@@ -176,7 +175,7 @@ var buildEditLinkToolbar = function buildEditLinkToolbar(_ref2) {
176
175
  if (!view || !providerFactory) {
177
176
  return null;
178
177
  }
179
- var displayInfo = (0, _utils2.displayInfoForCard)(node, (0, _utils2.findCardInfo)(view.state));
178
+ var displayInfo = (0, _utils.displayInfoForCard)(node, (0, _utils.findCardInfo)(view.state));
180
179
  return /*#__PURE__*/_react.default.createElement(EditLinkToolbar, {
181
180
  pluginInjectionApi: pluginInjectionApi,
182
181
  key: idx,
@@ -219,26 +218,4 @@ var editLinkToolbarConfig = function editLinkToolbarConfig(showLinkingToolbar, l
219
218
  forcePlacement: true
220
219
  } : {};
221
220
  };
222
- exports.editLinkToolbarConfig = editLinkToolbarConfig;
223
- var editDatasource = function editDatasource(node, editorAnalyticsApi) {
224
- return function (state, dispatch) {
225
- var _node$attrs;
226
- var modalType = (0, _utils.getDatasourceType)((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource.id);
227
- if (dispatch && modalType) {
228
- var tr = state.tr;
229
- (0, _actions.showDatasourceModal)(modalType)(tr);
230
- // editorAnalyticsApi?.attachAnalyticsEvent(
231
- // buildEditLinkPayload(
232
- // type as
233
- // | ACTION_SUBJECT_ID.CARD_INLINE
234
- // | ACTION_SUBJECT_ID.CARD_BLOCK
235
- // | ACTION_SUBJECT_ID.EMBEDS,
236
- // ),
237
- // )(tr);
238
- dispatch(tr);
239
- return true;
240
- }
241
- return false;
242
- };
243
- };
244
- exports.editDatasource = editDatasource;
221
+ exports.editLinkToolbarConfig = editLinkToolbarConfig;
@@ -6,39 +6,161 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.DatasourceEventsBinding = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
9
10
  var _react = require("react");
11
+ var _analyticsNext = require("@atlaskit/analytics-next");
12
+ var _linkAnalytics = require("@atlaskit/link-analytics");
10
13
  var _types = require("../../analytics/types");
14
+ var _common = require("./common");
15
+ var _excluded = ["node", "nodeContext"],
16
+ _excluded2 = ["node", "nodeContext"],
17
+ _excluded3 = ["node", "nodeContext"];
18
+ function getDatasourceDisplay(datasourceAttrs) {
19
+ var _datasourceAttrs$data;
20
+ return (_datasourceAttrs$data = datasourceAttrs.datasource.views[0]) === null || _datasourceAttrs$data === void 0 ? void 0 : _datasourceAttrs$data.type;
21
+ }
22
+ function getDisplayedColumnCount(datasourceAttrs) {
23
+ var _datasourceAttrs$data2, _datasourceAttrs$data3, _datasourceAttrs$data4, _datasourceAttrs$data5;
24
+ return (_datasourceAttrs$data2 = (_datasourceAttrs$data3 = datasourceAttrs.datasource.views[0]) === null || _datasourceAttrs$data3 === void 0 ? void 0 : (_datasourceAttrs$data4 = _datasourceAttrs$data3.properties) === null || _datasourceAttrs$data4 === void 0 ? void 0 : (_datasourceAttrs$data5 = _datasourceAttrs$data4.columns) === null || _datasourceAttrs$data5 === void 0 ? void 0 : _datasourceAttrs$data5.length) !== null && _datasourceAttrs$data2 !== void 0 ? _datasourceAttrs$data2 : 0;
25
+ }
26
+ function getSearchMethod(creationMethod, metadata) {
27
+ if (creationMethod === 'editor_paste' || creationMethod === 'editor_type') {
28
+ return '';
29
+ }
30
+ var sourceEvent = metadata.sourceEvent;
31
+ if (sourceEvent instanceof _analyticsNext.UIAnalyticsEvent) {
32
+ var event = sourceEvent;
33
+ return event.payload.searchMethod;
34
+ }
35
+ return 'unknown';
36
+ }
37
+ function getAnalyticAttributesFromNode(datasourceAttrs, metadata) {
38
+ var url = datasourceAttrs.url,
39
+ _datasourceAttrs$data6 = datasourceAttrs.datasource,
40
+ datasourceId = _datasourceAttrs$data6.id,
41
+ parameters = _datasourceAttrs$data6.parameters;
42
+ var display = getDatasourceDisplay(datasourceAttrs);
43
+ var inputMethod = '';
44
+ var actions = [];
45
+ if (metadata.inputMethod) {
46
+ var _getMethod;
47
+ inputMethod = (_getMethod = (0, _common.getMethod)({
48
+ inputMethod: metadata.inputMethod
49
+ })) !== null && _getMethod !== void 0 ? _getMethod : '';
50
+ } else if (metadata.sourceEvent instanceof _analyticsNext.UIAnalyticsEvent) {
51
+ inputMethod = metadata.sourceEvent.payload.inputMethod;
52
+ actions = metadata.sourceEvent.payload.actions;
53
+ }
54
+ var displayedColumnCount = getDisplayedColumnCount(datasourceAttrs);
55
+ var searchMethod = getSearchMethod(inputMethod, metadata);
56
+ return {
57
+ actions: actions,
58
+ inputMethod: inputMethod,
59
+ datasourceId: datasourceId,
60
+ display: display,
61
+ displayedColumnCount: displayedColumnCount,
62
+ parameters: parameters,
63
+ searchMethod: searchMethod,
64
+ url: url
65
+ };
66
+ }
67
+
11
68
  /**
12
69
  * Subscribes to the events occuring in the card
13
70
  * plugin and fires analytics events accordingly
14
71
  */
15
72
  var DatasourceEventsBinding = function DatasourceEventsBinding(_ref) {
16
73
  var cardPluginEvents = _ref.cardPluginEvents;
74
+ var _useDatasourceLifecyc = (0, _linkAnalytics.useDatasourceLifecycleAnalytics)(),
75
+ datasourceCreated = _useDatasourceLifecyc.datasourceCreated,
76
+ datasourceUpdated = _useDatasourceLifecyc.datasourceUpdated,
77
+ datasourceDeleted = _useDatasourceLifecyc.datasourceDeleted;
17
78
  var eventHandlers = (0, _react.useMemo)(function () {
18
- var _ref2;
19
- return _ref2 = {}, (0, _defineProperty2.default)(_ref2, _types.EVENT.CREATED, function (metadata) {
20
- // TODO Impl as part of https://product-fabric.atlassian.net/browse/EDM-7072
21
- // eslint-disable-next-line no-console
22
- console.log('CREATED', metadata.node, metadata.nodeContext);
23
- }), (0, _defineProperty2.default)(_ref2, _types.EVENT.UPDATED, function (metadata) {
24
- // TODO Impl as part of https://product-fabric.atlassian.net/browse/EDM-7072
25
- // eslint-disable-next-line no-console
26
- console.log('UPDATED', metadata.node, metadata.nodeContext);
27
- }), (0, _defineProperty2.default)(_ref2, _types.EVENT.DELETED, function (metadata) {
28
- // TODO Impl as part of https://product-fabric.atlassian.net/browse/EDM-7072
29
- // eslint-disable-next-line no-console
30
- console.log('DELETED', metadata.node, metadata.nodeContext);
31
- }), _ref2;
32
- }, []);
79
+ var _ref5;
80
+ return _ref5 = {}, (0, _defineProperty2.default)(_ref5, _types.EVENT.CREATED, function (_ref2) {
81
+ var node = _ref2.node,
82
+ nodeContext = _ref2.nodeContext,
83
+ metadata = (0, _objectWithoutProperties2.default)(_ref2, _excluded);
84
+ var attributes = getAnalyticAttributesFromNode(node.attrs, metadata);
85
+ var actions = attributes.actions,
86
+ inputMethod = attributes.inputMethod,
87
+ datasourceId = attributes.datasourceId,
88
+ display = attributes.display,
89
+ displayedColumnCount = attributes.displayedColumnCount,
90
+ parameters = attributes.parameters,
91
+ searchMethod = attributes.searchMethod,
92
+ url = attributes.url;
93
+ datasourceCreated({
94
+ datasourceId: datasourceId,
95
+ parameters: parameters,
96
+ url: url
97
+ }, null, {
98
+ actions: actions,
99
+ creationMethod: inputMethod,
100
+ display: display,
101
+ displayedColumnCount: displayedColumnCount,
102
+ nodeContext: nodeContext,
103
+ searchMethod: searchMethod
104
+ });
105
+ }), (0, _defineProperty2.default)(_ref5, _types.EVENT.UPDATED, function (_ref3) {
106
+ var node = _ref3.node,
107
+ nodeContext = _ref3.nodeContext,
108
+ metadata = (0, _objectWithoutProperties2.default)(_ref3, _excluded2);
109
+ var attributes = getAnalyticAttributesFromNode(node.attrs, metadata);
110
+ var actions = attributes.actions,
111
+ datasourceId = attributes.datasourceId,
112
+ display = attributes.display,
113
+ displayedColumnCount = attributes.displayedColumnCount,
114
+ inputMethod = attributes.inputMethod,
115
+ parameters = attributes.parameters,
116
+ searchMethod = attributes.searchMethod,
117
+ url = attributes.url;
118
+ datasourceUpdated({
119
+ datasourceId: datasourceId,
120
+ parameters: parameters,
121
+ url: url
122
+ }, null, {
123
+ actions: actions,
124
+ display: display,
125
+ displayedColumnCount: displayedColumnCount,
126
+ nodeContext: nodeContext,
127
+ searchMethod: searchMethod,
128
+ updateMethod: inputMethod
129
+ });
130
+ }), (0, _defineProperty2.default)(_ref5, _types.EVENT.DELETED, function (_ref4) {
131
+ var node = _ref4.node,
132
+ nodeContext = _ref4.nodeContext,
133
+ metadata = (0, _objectWithoutProperties2.default)(_ref4, _excluded3);
134
+ var attributes = getAnalyticAttributesFromNode(node.attrs, metadata);
135
+ var datasourceId = attributes.datasourceId,
136
+ display = attributes.display,
137
+ displayedColumnCount = attributes.displayedColumnCount,
138
+ inputMethod = attributes.inputMethod,
139
+ parameters = attributes.parameters,
140
+ searchMethod = attributes.searchMethod,
141
+ url = attributes.url;
142
+ datasourceDeleted({
143
+ datasourceId: datasourceId,
144
+ parameters: parameters,
145
+ url: url
146
+ }, null, {
147
+ deleteMethod: inputMethod,
148
+ display: display,
149
+ displayedColumnCount: displayedColumnCount,
150
+ nodeContext: nodeContext,
151
+ searchMethod: searchMethod
152
+ });
153
+ }), _ref5;
154
+ }, [datasourceCreated, datasourceUpdated, datasourceDeleted]);
33
155
 
34
156
  /**
35
157
  * Subscribe to datasource events
36
158
  */
37
159
  (0, _react.useEffect)(function () {
38
- var unsubscribe = cardPluginEvents.subscribe(function (_ref3) {
39
- var event = _ref3.event,
40
- subject = _ref3.subject,
41
- data = _ref3.data;
160
+ var unsubscribe = cardPluginEvents.subscribe(function (_ref6) {
161
+ var event = _ref6.event,
162
+ subject = _ref6.subject,
163
+ data = _ref6.data;
42
164
  if (subject === _types.EVENT_SUBJECT.DATASOURCE) {
43
165
  eventHandlers[event](data);
44
166
  }
@@ -123,6 +123,7 @@ export const findChanged = (tr, state) => {
123
123
  const {
124
124
  inputMethod
125
125
  } = getLinkMetadataFromTransaction(tr);
126
+
126
127
  /**
127
128
  * If there is no identifiable input method, and the links inserted and removed appear to be the same,
128
129
  * then this transaction likely is not intended to be consided to be the insertion and removal of links