@atlaskit/editor-plugin-card 0.9.1 → 0.9.2

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 (64) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/ui/DatasourceModal/ModalWithState.js +8 -3
  3. package/dist/cjs/ui/DatasourceModal/index.js +22 -6
  4. package/dist/cjs/ui/EditDatasourceButton.js +26 -64
  5. package/dist/cjs/ui/useFetchDatasourceInfo.js +86 -0
  6. package/dist/es2019/ui/DatasourceModal/ModalWithState.js +7 -3
  7. package/dist/es2019/ui/DatasourceModal/index.js +23 -6
  8. package/dist/es2019/ui/EditDatasourceButton.js +11 -15
  9. package/dist/es2019/ui/useFetchDatasourceInfo.js +45 -0
  10. package/dist/esm/ui/DatasourceModal/ModalWithState.js +8 -3
  11. package/dist/esm/ui/DatasourceModal/index.js +22 -6
  12. package/dist/esm/ui/EditDatasourceButton.js +18 -55
  13. package/dist/esm/ui/useFetchDatasourceInfo.js +78 -0
  14. package/dist/types/ui/DatasourceModal/index.d.ts +3 -1
  15. package/dist/types/ui/EditDatasourceButton.d.ts +1 -0
  16. package/dist/types/ui/useFetchDatasourceInfo.d.ts +14 -0
  17. package/dist/types-ts4.5/analytics/create-events-queue.d.ts +21 -0
  18. package/dist/types-ts4.5/analytics/events-from-tr.d.ts +19 -0
  19. package/dist/types-ts4.5/analytics/index.d.ts +2 -0
  20. package/dist/types-ts4.5/analytics/types.d.ts +66 -0
  21. package/dist/types-ts4.5/analytics/utils.d.ts +22 -0
  22. package/dist/types-ts4.5/datasourceErrorBoundary.d.ts +18 -0
  23. package/dist/types-ts4.5/index.d.ts +3 -0
  24. package/dist/types-ts4.5/messages.d.ts +22 -0
  25. package/dist/types-ts4.5/nodeviews/blockCard.d.ts +30 -0
  26. package/dist/types-ts4.5/nodeviews/datasource.d.ts +43 -0
  27. package/dist/types-ts4.5/nodeviews/embedCard.d.ts +46 -0
  28. package/dist/types-ts4.5/nodeviews/genericCard.d.ts +37 -0
  29. package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +23 -0
  30. package/dist/types-ts4.5/plugin.d.ts +29 -0
  31. package/dist/types-ts4.5/pm-plugins/actions.d.ts +22 -0
  32. package/dist/types-ts4.5/pm-plugins/doc.d.ts +27 -0
  33. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
  34. package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
  35. package/dist/types-ts4.5/pm-plugins/mountHyperlink.d.ts +5 -0
  36. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
  37. package/dist/types-ts4.5/pm-plugins/reducers.d.ts +3 -0
  38. package/dist/types-ts4.5/pm-plugins/shouldReplaceLink.d.ts +2 -0
  39. package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +8 -0
  40. package/dist/types-ts4.5/pm-plugins/util/state.d.ts +30 -0
  41. package/dist/types-ts4.5/toolbar.d.ts +9 -0
  42. package/dist/types-ts4.5/types.d.ts +133 -0
  43. package/dist/types-ts4.5/ui/CardContextProvider.d.ts +19 -0
  44. package/dist/types-ts4.5/ui/DatasourceModal/ModalWithState.d.ts +9 -0
  45. package/dist/types-ts4.5/ui/DatasourceModal/index.d.ts +13 -0
  46. package/dist/types-ts4.5/ui/EditDatasourceButton.d.ts +18 -0
  47. package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +41 -0
  48. package/dist/types-ts4.5/ui/EditorAnalyticsContext.d.ts +10 -0
  49. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +6 -0
  50. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +6 -0
  51. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/common.d.ts +20 -0
  52. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/index.d.ts +9 -0
  53. package/dist/types-ts4.5/ui/EditorSmartCardEvents.d.ts +5 -0
  54. package/dist/types-ts4.5/ui/HyperlinkToolbarAppearance.d.ts +32 -0
  55. package/dist/types-ts4.5/ui/LayoutButton/index.d.ts +9 -0
  56. package/dist/types-ts4.5/ui/LayoutButton/types.d.ts +19 -0
  57. package/dist/types-ts4.5/ui/LayoutButton/utils.d.ts +5 -0
  58. package/dist/types-ts4.5/ui/LinkToolbarAppearance.d.ts +29 -0
  59. package/dist/types-ts4.5/ui/ResizableEmbedCard.d.ts +61 -0
  60. package/dist/types-ts4.5/ui/ToolbarViewedEvent.d.ts +11 -0
  61. package/dist/types-ts4.5/ui/useFetchDatasourceInfo.d.ts +14 -0
  62. package/dist/types-ts4.5/utils.d.ts +19 -0
  63. package/package.json +4 -3
  64. package/tmp/api-report-tmp.d.ts +193 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 0.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#41405](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/41405) [`6619f042a24`](https://bitbucket.org/atlassian/atlassian-frontend/commits/6619f042a24) - [ux] Fix issue where any inline/block/embeds don't open up datasource modal with proper info
8
+
3
9
  ## 0.9.1
4
10
 
5
11
  ### Patch Changes
@@ -8,6 +8,7 @@ exports.default = void 0;
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  var _hooks = require("@atlaskit/editor-common/hooks");
10
10
  var _datasourceErrorBoundary = require("../../datasourceErrorBoundary");
11
+ var _CardContextProvider = require("../CardContextProvider");
11
12
  var _index = require("./index");
12
13
  var ModalWithState = function ModalWithState(_ref) {
13
14
  var api = _ref.api,
@@ -19,9 +20,13 @@ var ModalWithState = function ModalWithState(_ref) {
19
20
  }
20
21
  return /*#__PURE__*/_react.default.createElement(_datasourceErrorBoundary.DatasourceErrorBoundary, {
21
22
  view: editorView
22
- }, /*#__PURE__*/_react.default.createElement(_index.DatasourceModal, {
23
- view: editorView,
24
- modalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType
23
+ }, /*#__PURE__*/_react.default.createElement(_CardContextProvider.CardContextProvider, null, function (_ref2) {
24
+ var cardContext = _ref2.cardContext;
25
+ return /*#__PURE__*/_react.default.createElement(_index.DatasourceModal, {
26
+ view: editorView,
27
+ modalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType,
28
+ cardContext: cardContext
29
+ });
25
30
  }));
26
31
  };
27
32
  var _default = exports.default = ModalWithState;
@@ -13,17 +13,29 @@ var _state = require("@atlaskit/editor-prosemirror/state");
13
13
  var _linkDatasource = require("@atlaskit/link-datasource");
14
14
  var _actions = require("../../pm-plugins/actions");
15
15
  var _doc = require("../../pm-plugins/doc");
16
+ var _useFetchDatasourceInfo = require("../useFetchDatasourceInfo");
16
17
  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); }
17
18
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
18
19
  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; }
19
20
  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
21
  var DatasourceModal = exports.DatasourceModal = function DatasourceModal(_ref) {
22
+ var _existingNode$attrs, _existingNode$attrs2;
21
23
  var view = _ref.view,
22
- modalType = _ref.modalType;
24
+ modalType = _ref.modalType,
25
+ cardContext = _ref.cardContext;
23
26
  var dispatch = view.dispatch,
24
27
  state = view.state;
25
28
  var selection = state.selection;
26
29
  var existingNode = selection instanceof _state.NodeSelection ? selection.node : undefined;
30
+ var isRegularCardNode = !!(existingNode && !(existingNode !== null && existingNode !== void 0 && (_existingNode$attrs = existingNode.attrs) !== null && _existingNode$attrs !== void 0 && _existingNode$attrs.datasource));
31
+ var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
32
+ isRegularCardNode: isRegularCardNode,
33
+ url: existingNode === null || existingNode === void 0 ? void 0 : existingNode.attrs.url,
34
+ cardContext: cardContext,
35
+ nodeParameters: existingNode === null || existingNode === void 0 || (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 || (_existingNode$attrs2 = _existingNode$attrs2.datasource) === null || _existingNode$attrs2 === void 0 ? void 0 : _existingNode$attrs2.parameters
36
+ }),
37
+ parameters = _useFetchDatasourceIn.parameters,
38
+ ready = _useFetchDatasourceIn.ready;
27
39
  var onClose = (0, _react.useCallback)(function () {
28
40
  dispatch((0, _actions.hideDatasourceModal)(state.tr));
29
41
  }, [dispatch, state.tr]);
@@ -44,11 +56,13 @@ var DatasourceModal = exports.DatasourceModal = function DatasourceModal(_ref) {
44
56
  }
45
57
  }, [existingNode, state, view]);
46
58
  if (modalType === 'jira') {
47
- var _existingNode$attrs, _tableView$properties;
48
- var _ref2 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs = existingNode.attrs) === null || _existingNode$attrs === void 0 ? void 0 : _existingNode$attrs.datasource) || {},
59
+ var _existingNode$attrs3, _tableView$properties;
60
+ if (!ready) {
61
+ return null;
62
+ }
63
+ var _ref2 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs3 = existingNode.attrs) === null || _existingNode$attrs3 === void 0 ? void 0 : _existingNode$attrs3.datasource) || {},
49
64
  _ref2$id = _ref2.id,
50
65
  datasourceId = _ref2$id === void 0 ? _linkDatasource.JIRA_LIST_OF_LINKS_DATASOURCE_ID : _ref2$id,
51
- parameters = _ref2.parameters,
52
66
  _ref2$views = _ref2.views,
53
67
  views = _ref2$views === void 0 ? [] : _ref2$views;
54
68
  var _ref3 = views,
@@ -61,6 +75,8 @@ var DatasourceModal = exports.DatasourceModal = function DatasourceModal(_ref) {
61
75
  "data-testid": "jira-config-modal"
62
76
  }, /*#__PURE__*/_react.default.createElement(_linkDatasource.JiraIssuesConfigModal, {
63
77
  datasourceId: datasourceId,
78
+ viewMode: isRegularCardNode ? 'count' : 'issue' // Want non-datasource cards to open in count view since they are in issue count view
79
+ ,
64
80
  visibleColumnKeys: visibleColumnKeys,
65
81
  parameters: parameters,
66
82
  onCancel: onClose,
@@ -68,8 +84,8 @@ var DatasourceModal = exports.DatasourceModal = function DatasourceModal(_ref) {
68
84
  }));
69
85
  }
70
86
  if (modalType === 'assets') {
71
- var _existingNode$attrs2, _tableView$properties2;
72
- var _ref5 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 ? void 0 : _existingNode$attrs2.datasource) || {},
87
+ var _existingNode$attrs4, _tableView$properties2;
88
+ var _ref5 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs4 = existingNode.attrs) === null || _existingNode$attrs4 === void 0 ? void 0 : _existingNode$attrs4.datasource) || {},
73
89
  _ref5$id = _ref5.id,
74
90
  _datasourceId = _ref5$id === void 0 ? _linkDatasource.ASSETS_LIST_OF_LINKS_DATASOURCE_ID : _ref5$id,
75
91
  _parameters = _ref5.parameters,
@@ -1,28 +1,27 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
3
  Object.defineProperty(exports, "__esModule", {
5
4
  value: true
6
5
  });
7
6
  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");
7
+ var _react = require("@emotion/react");
13
8
  var _messages = require("@atlaskit/editor-common/messages");
14
9
  var _ui = require("@atlaskit/editor-common/ui");
15
10
  var _utils = require("@atlaskit/editor-common/utils");
16
11
  var _actions = require("../pm-plugins/actions");
17
12
  var _CardContextProvider = require("./CardContextProvider");
13
+ var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
18
14
  /** @jsx jsx */
19
15
 
20
- var buttonStyles = (0, _react2.css)({
16
+ var buttonStyles = (0, _react.css)({
21
17
  pointerEvents: 'auto'
22
18
  });
23
- var buttonWrapperStyles = (0, _react2.css)({
19
+ var buttonWrapperStyles = (0, _react.css)({
24
20
  display: 'flex'
25
21
  });
22
+
23
+ // Edit button in toolbar to open datasource modal. This button is shown for inline, block, and embed cards
24
+ // if they can resolve into a datasource.
26
25
  var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardContext(_ref) {
27
26
  var cardContext = _ref.cardContext,
28
27
  intl = _ref.intl,
@@ -30,49 +29,12 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
30
29
  url = _ref.url,
31
30
  editorView = _ref.editorView,
32
31
  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, _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 || (_cardContext$connecti = cardContext.connections) === null || _cardContext$connecti === void 0 || (_cardContext$connecti = _cardContext$connecti.client) === null || _cardContext$connecti === void 0 ? void 0 : _cardContext$connecti.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]);
32
+ var _useFetchDatasourceIn = (0, _useFetchDatasourceInfo.useFetchDatasourceInfo)({
33
+ isRegularCardNode: true,
34
+ url: url,
35
+ cardContext: cardContext
36
+ }),
37
+ datasourceId = _useFetchDatasourceIn.datasourceId;
76
38
  if (!datasourceId || !(0, _utils.canRenderDatasource)(datasourceId, false)) {
77
39
  return null;
78
40
  }
@@ -89,28 +51,28 @@ var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardC
89
51
  editorView.focus();
90
52
  }
91
53
  };
92
- return (0, _react2.jsx)("div", {
54
+ return (0, _react.jsx)("div", {
93
55
  css: buttonWrapperStyles
94
- }, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
56
+ }, (0, _react.jsx)(_ui.FloatingToolbarButton, {
95
57
  css: buttonStyles,
96
58
  title: intl.formatMessage(_messages.cardMessages.datasourceTitle),
97
- icon: (0, _react2.jsx)(_ui.SmallerEditIcon, null),
59
+ icon: (0, _react.jsx)(_ui.SmallerEditIcon, null),
98
60
  selected: false,
99
61
  onClick: function onClick() {
100
62
  return dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
101
63
  },
102
64
  testId: 'card-edit-datasource-button'
103
- }), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
65
+ }), (0, _react.jsx)(_ui.FloatingToolbarSeparator, null));
104
66
  };
105
- var EditDatasourceButton = exports.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, {
67
+ var EditDatasourceButton = exports.EditDatasourceButton = function EditDatasourceButton(_ref2) {
68
+ var intl = _ref2.intl,
69
+ editorAnalyticsApi = _ref2.editorAnalyticsApi,
70
+ url = _ref2.url,
71
+ editorView = _ref2.editorView,
72
+ editorState = _ref2.editorState;
73
+ return (0, _react.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref3) {
74
+ var cardContext = _ref3.cardContext;
75
+ return (0, _react.jsx)(EditDatasourceButtonWithCardContext, {
114
76
  url: url,
115
77
  intl: intl,
116
78
  editorAnalyticsApi: editorAnalyticsApi,
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useFetchDatasourceInfo = 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
+ /** @jsx jsx */
13
+
14
+ var useFetchDatasourceInfo = exports.useFetchDatasourceInfo = function useFetchDatasourceInfo(_ref) {
15
+ var isRegularCardNode = _ref.isRegularCardNode,
16
+ url = _ref.url,
17
+ cardContext = _ref.cardContext,
18
+ nodeParameters = _ref.nodeParameters;
19
+ var _useState = (0, _react.useState)(undefined),
20
+ _useState2 = (0, _slicedToArray2.default)(_useState, 2),
21
+ datasourceId = _useState2[0],
22
+ setDatasourceId = _useState2[1];
23
+ var _useState3 = (0, _react.useState)(nodeParameters),
24
+ _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
25
+ parameters = _useState4[0],
26
+ setParameters = _useState4[1];
27
+ // Since fetchData() is async, using this ready check to see if we have the parameters before passing it to the modal.
28
+ // Only non-datasource nodes will be not ready initially since we need to fetch data.
29
+ var _useState5 = (0, _react.useState)(!isRegularCardNode),
30
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
31
+ ready = _useState6[0],
32
+ setReady = _useState6[1];
33
+ (0, _react.useEffect)(function () {
34
+ var fetchDatasource = /*#__PURE__*/function () {
35
+ var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
36
+ var _cardContext$connecti, _datasources$, _datasources$2, response, datasources;
37
+ return _regenerator.default.wrap(function _callee$(_context) {
38
+ while (1) switch (_context.prev = _context.next) {
39
+ case 0:
40
+ _context.prev = 0;
41
+ if (!(!url || !cardContext)) {
42
+ _context.next = 4;
43
+ break;
44
+ }
45
+ // Don't block rendering of modal of somehow we don't get these two args --> just open with empty params
46
+ setReady(true);
47
+ return _context.abrupt("return");
48
+ case 4:
49
+ _context.next = 6;
50
+ return cardContext === null || cardContext === void 0 || (_cardContext$connecti = cardContext.connections) === null || _cardContext$connecti === void 0 || (_cardContext$connecti = _cardContext$connecti.client) === null || _cardContext$connecti === void 0 ? void 0 : _cardContext$connecti.fetchData(url);
51
+ case 6:
52
+ response = _context.sent;
53
+ datasources = response && response.datasources || [];
54
+ setDatasourceId((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id);
55
+ setParameters((_datasources$2 = datasources[0]) === null || _datasources$2 === void 0 ? void 0 : _datasources$2.parameters);
56
+ setReady(true);
57
+ _context.next = 18;
58
+ break;
59
+ case 13:
60
+ _context.prev = 13;
61
+ _context.t0 = _context["catch"](0);
62
+ setDatasourceId(undefined);
63
+ setParameters(undefined);
64
+ // If fetch somehow errors, still set ready as true so we don't block the rendering of the modal.
65
+ // It will just open with empty params.
66
+ setReady(true);
67
+ case 18:
68
+ case "end":
69
+ return _context.stop();
70
+ }
71
+ }, _callee, null, [[0, 13]]);
72
+ }));
73
+ return function fetchDatasource() {
74
+ return _ref2.apply(this, arguments);
75
+ };
76
+ }();
77
+ if (isRegularCardNode) {
78
+ void fetchDatasource();
79
+ }
80
+ }, [isRegularCardNode, cardContext, url]);
81
+ return {
82
+ datasourceId: datasourceId,
83
+ parameters: parameters,
84
+ ready: ready
85
+ };
86
+ };
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
3
  import { DatasourceErrorBoundary } from '../../datasourceErrorBoundary';
4
+ import { CardContextProvider } from '../CardContextProvider';
4
5
  import { DatasourceModal } from './index';
5
6
  const ModalWithState = ({
6
7
  api,
@@ -14,9 +15,12 @@ const ModalWithState = ({
14
15
  }
15
16
  return /*#__PURE__*/React.createElement(DatasourceErrorBoundary, {
16
17
  view: editorView
17
- }, /*#__PURE__*/React.createElement(DatasourceModal, {
18
+ }, /*#__PURE__*/React.createElement(CardContextProvider, null, ({
19
+ cardContext
20
+ }) => /*#__PURE__*/React.createElement(DatasourceModal, {
18
21
  view: editorView,
19
- modalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType
20
- }));
22
+ modalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType,
23
+ cardContext: cardContext
24
+ })));
21
25
  };
22
26
  export default ModalWithState;
@@ -3,10 +3,13 @@ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
3
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
4
4
  import { hideDatasourceModal } from '../../pm-plugins/actions';
5
5
  import { insertDatasource, updateCardFromDatasourceModal } from '../../pm-plugins/doc';
6
+ import { useFetchDatasourceInfo } from '../useFetchDatasourceInfo';
6
7
  export const DatasourceModal = ({
7
8
  view,
8
- modalType
9
+ modalType,
10
+ cardContext
9
11
  }) => {
12
+ var _existingNode$attrs, _existingNode$attrs2, _existingNode$attrs2$;
10
13
  const {
11
14
  dispatch,
12
15
  state
@@ -15,6 +18,16 @@ export const DatasourceModal = ({
15
18
  selection
16
19
  } = state;
17
20
  const existingNode = selection instanceof NodeSelection ? selection.node : undefined;
21
+ const isRegularCardNode = !!(existingNode && !(existingNode !== null && existingNode !== void 0 && (_existingNode$attrs = existingNode.attrs) !== null && _existingNode$attrs !== void 0 && _existingNode$attrs.datasource));
22
+ const {
23
+ parameters,
24
+ ready
25
+ } = useFetchDatasourceInfo({
26
+ isRegularCardNode,
27
+ url: existingNode === null || existingNode === void 0 ? void 0 : existingNode.attrs.url,
28
+ cardContext,
29
+ nodeParameters: existingNode === null || existingNode === void 0 ? void 0 : (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 ? void 0 : (_existingNode$attrs2$ = _existingNode$attrs2.datasource) === null || _existingNode$attrs2$ === void 0 ? void 0 : _existingNode$attrs2$.parameters
30
+ });
18
31
  const onClose = useCallback(() => {
19
32
  dispatch(hideDatasourceModal(state.tr));
20
33
  }, [dispatch, state.tr]);
@@ -35,18 +48,22 @@ export const DatasourceModal = ({
35
48
  }
36
49
  }, [existingNode, state, view]);
37
50
  if (modalType === 'jira') {
38
- var _existingNode$attrs, _tableView$properties;
51
+ var _existingNode$attrs3, _tableView$properties;
52
+ if (!ready) {
53
+ return null;
54
+ }
39
55
  const {
40
56
  id: datasourceId = JIRA_LIST_OF_LINKS_DATASOURCE_ID,
41
- parameters,
42
57
  views = []
43
- } = (existingNode === null || existingNode === void 0 ? void 0 : (_existingNode$attrs = existingNode.attrs) === null || _existingNode$attrs === void 0 ? void 0 : _existingNode$attrs.datasource) || {};
58
+ } = (existingNode === null || existingNode === void 0 ? void 0 : (_existingNode$attrs3 = existingNode.attrs) === null || _existingNode$attrs3 === void 0 ? void 0 : _existingNode$attrs3.datasource) || {};
44
59
  const [tableView] = views;
45
60
  const visibleColumnKeys = tableView === null || tableView === void 0 ? void 0 : (_tableView$properties = tableView.properties) === null || _tableView$properties === void 0 ? void 0 : _tableView$properties.columns.map(column => column.key);
46
61
  return /*#__PURE__*/React.createElement("div", {
47
62
  "data-testid": "jira-config-modal"
48
63
  }, /*#__PURE__*/React.createElement(JiraIssuesConfigModal, {
49
64
  datasourceId: datasourceId,
65
+ viewMode: isRegularCardNode ? 'count' : 'issue' // Want non-datasource cards to open in count view since they are in issue count view
66
+ ,
50
67
  visibleColumnKeys: visibleColumnKeys,
51
68
  parameters: parameters,
52
69
  onCancel: onClose,
@@ -54,12 +71,12 @@ export const DatasourceModal = ({
54
71
  }));
55
72
  }
56
73
  if (modalType === 'assets') {
57
- var _existingNode$attrs2, _tableView$properties2;
74
+ var _existingNode$attrs4, _tableView$properties2;
58
75
  const {
59
76
  id: datasourceId = ASSETS_LIST_OF_LINKS_DATASOURCE_ID,
60
77
  parameters,
61
78
  views = []
62
- } = (existingNode === null || existingNode === void 0 ? void 0 : (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 ? void 0 : _existingNode$attrs2.datasource) || {};
79
+ } = (existingNode === null || existingNode === void 0 ? void 0 : (_existingNode$attrs4 = existingNode.attrs) === null || _existingNode$attrs4 === void 0 ? void 0 : _existingNode$attrs4.datasource) || {};
63
80
  const [tableView] = views;
64
81
  const visibleColumnKeys = tableView === null || tableView === void 0 ? void 0 : (_tableView$properties2 = tableView.properties) === null || _tableView$properties2 === void 0 ? void 0 : _tableView$properties2.columns.map(column => column.key);
65
82
  return /*#__PURE__*/React.createElement("div", {
@@ -1,17 +1,20 @@
1
1
  /** @jsx jsx */
2
- import { useEffect, useState } from 'react';
3
2
  import { css, jsx } from '@emotion/react';
4
3
  import { cardMessages as messages } from '@atlaskit/editor-common/messages';
5
4
  import { FloatingToolbarButton as Button, FloatingToolbarSeparator as Separator, SmallerEditIcon } from '@atlaskit/editor-common/ui';
6
5
  import { canRenderDatasource, getDatasourceType } from '@atlaskit/editor-common/utils';
7
6
  import { showDatasourceModal } from '../pm-plugins/actions';
8
7
  import { CardContextProvider } from './CardContextProvider';
8
+ import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
9
9
  const buttonStyles = css({
10
10
  pointerEvents: 'auto'
11
11
  });
12
12
  const buttonWrapperStyles = css({
13
13
  display: 'flex'
14
14
  });
15
+
16
+ // Edit button in toolbar to open datasource modal. This button is shown for inline, block, and embed cards
17
+ // if they can resolve into a datasource.
15
18
  const EditDatasourceButtonWithCardContext = ({
16
19
  cardContext,
17
20
  intl,
@@ -20,20 +23,13 @@ const EditDatasourceButtonWithCardContext = ({
20
23
  editorView,
21
24
  editorState
22
25
  }) => {
23
- const [datasourceId, setDatasourceId] = useState(null);
24
- useEffect(() => {
25
- const fetchDatasource = async () => {
26
- try {
27
- var _cardContext$connecti, _cardContext$connecti2, _datasources$;
28
- const response = url && cardContext && (await (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)));
29
- const datasources = response && response.datasources || [];
30
- setDatasourceId(((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id) || null);
31
- } catch (e) {
32
- setDatasourceId(null);
33
- }
34
- };
35
- void fetchDatasource();
36
- }, [cardContext, url]);
26
+ const {
27
+ datasourceId
28
+ } = useFetchDatasourceInfo({
29
+ isRegularCardNode: true,
30
+ url,
31
+ cardContext
32
+ });
37
33
  if (!datasourceId || !canRenderDatasource(datasourceId, false)) {
38
34
  return null;
39
35
  }
@@ -0,0 +1,45 @@
1
+ /** @jsx jsx */
2
+ import { useEffect, useState } from 'react';
3
+ export const useFetchDatasourceInfo = ({
4
+ isRegularCardNode,
5
+ url,
6
+ cardContext,
7
+ nodeParameters
8
+ }) => {
9
+ const [datasourceId, setDatasourceId] = useState(undefined);
10
+ const [parameters, setParameters] = useState(nodeParameters);
11
+ // Since fetchData() is async, using this ready check to see if we have the parameters before passing it to the modal.
12
+ // Only non-datasource nodes will be not ready initially since we need to fetch data.
13
+ const [ready, setReady] = useState(!isRegularCardNode);
14
+ useEffect(() => {
15
+ const fetchDatasource = async () => {
16
+ try {
17
+ var _cardContext$connecti, _cardContext$connecti2, _datasources$, _datasources$2;
18
+ if (!url || !cardContext) {
19
+ // Don't block rendering of modal of somehow we don't get these two args --> just open with empty params
20
+ setReady(true);
21
+ return;
22
+ }
23
+ const response = await (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));
24
+ const datasources = response && response.datasources || [];
25
+ setDatasourceId((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id);
26
+ setParameters((_datasources$2 = datasources[0]) === null || _datasources$2 === void 0 ? void 0 : _datasources$2.parameters);
27
+ setReady(true);
28
+ } catch (e) {
29
+ setDatasourceId(undefined);
30
+ setParameters(undefined);
31
+ // If fetch somehow errors, still set ready as true so we don't block the rendering of the modal.
32
+ // It will just open with empty params.
33
+ setReady(true);
34
+ }
35
+ };
36
+ if (isRegularCardNode) {
37
+ void fetchDatasource();
38
+ }
39
+ }, [isRegularCardNode, cardContext, url]);
40
+ return {
41
+ datasourceId,
42
+ parameters,
43
+ ready
44
+ };
45
+ };
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
3
  import { DatasourceErrorBoundary } from '../../datasourceErrorBoundary';
4
+ import { CardContextProvider } from '../CardContextProvider';
4
5
  import { DatasourceModal } from './index';
5
6
  var ModalWithState = function ModalWithState(_ref) {
6
7
  var api = _ref.api,
@@ -12,9 +13,13 @@ var ModalWithState = function ModalWithState(_ref) {
12
13
  }
13
14
  return /*#__PURE__*/React.createElement(DatasourceErrorBoundary, {
14
15
  view: editorView
15
- }, /*#__PURE__*/React.createElement(DatasourceModal, {
16
- view: editorView,
17
- modalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType
16
+ }, /*#__PURE__*/React.createElement(CardContextProvider, null, function (_ref2) {
17
+ var cardContext = _ref2.cardContext;
18
+ return /*#__PURE__*/React.createElement(DatasourceModal, {
19
+ view: editorView,
20
+ modalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType,
21
+ cardContext: cardContext
22
+ });
18
23
  }));
19
24
  };
20
25
  export default ModalWithState;
@@ -7,13 +7,25 @@ import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
7
7
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
8
8
  import { hideDatasourceModal } from '../../pm-plugins/actions';
9
9
  import { insertDatasource, updateCardFromDatasourceModal } from '../../pm-plugins/doc';
10
+ import { useFetchDatasourceInfo } from '../useFetchDatasourceInfo';
10
11
  export var DatasourceModal = function DatasourceModal(_ref) {
12
+ var _existingNode$attrs, _existingNode$attrs2;
11
13
  var view = _ref.view,
12
- modalType = _ref.modalType;
14
+ modalType = _ref.modalType,
15
+ cardContext = _ref.cardContext;
13
16
  var dispatch = view.dispatch,
14
17
  state = view.state;
15
18
  var selection = state.selection;
16
19
  var existingNode = selection instanceof NodeSelection ? selection.node : undefined;
20
+ var isRegularCardNode = !!(existingNode && !(existingNode !== null && existingNode !== void 0 && (_existingNode$attrs = existingNode.attrs) !== null && _existingNode$attrs !== void 0 && _existingNode$attrs.datasource));
21
+ var _useFetchDatasourceIn = useFetchDatasourceInfo({
22
+ isRegularCardNode: isRegularCardNode,
23
+ url: existingNode === null || existingNode === void 0 ? void 0 : existingNode.attrs.url,
24
+ cardContext: cardContext,
25
+ nodeParameters: existingNode === null || existingNode === void 0 || (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 || (_existingNode$attrs2 = _existingNode$attrs2.datasource) === null || _existingNode$attrs2 === void 0 ? void 0 : _existingNode$attrs2.parameters
26
+ }),
27
+ parameters = _useFetchDatasourceIn.parameters,
28
+ ready = _useFetchDatasourceIn.ready;
17
29
  var onClose = useCallback(function () {
18
30
  dispatch(hideDatasourceModal(state.tr));
19
31
  }, [dispatch, state.tr]);
@@ -34,11 +46,13 @@ export var DatasourceModal = function DatasourceModal(_ref) {
34
46
  }
35
47
  }, [existingNode, state, view]);
36
48
  if (modalType === 'jira') {
37
- var _existingNode$attrs, _tableView$properties;
38
- var _ref2 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs = existingNode.attrs) === null || _existingNode$attrs === void 0 ? void 0 : _existingNode$attrs.datasource) || {},
49
+ var _existingNode$attrs3, _tableView$properties;
50
+ if (!ready) {
51
+ return null;
52
+ }
53
+ var _ref2 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs3 = existingNode.attrs) === null || _existingNode$attrs3 === void 0 ? void 0 : _existingNode$attrs3.datasource) || {},
39
54
  _ref2$id = _ref2.id,
40
55
  datasourceId = _ref2$id === void 0 ? JIRA_LIST_OF_LINKS_DATASOURCE_ID : _ref2$id,
41
- parameters = _ref2.parameters,
42
56
  _ref2$views = _ref2.views,
43
57
  views = _ref2$views === void 0 ? [] : _ref2$views;
44
58
  var _ref3 = views,
@@ -51,6 +65,8 @@ export var DatasourceModal = function DatasourceModal(_ref) {
51
65
  "data-testid": "jira-config-modal"
52
66
  }, /*#__PURE__*/React.createElement(JiraIssuesConfigModal, {
53
67
  datasourceId: datasourceId,
68
+ viewMode: isRegularCardNode ? 'count' : 'issue' // Want non-datasource cards to open in count view since they are in issue count view
69
+ ,
54
70
  visibleColumnKeys: visibleColumnKeys,
55
71
  parameters: parameters,
56
72
  onCancel: onClose,
@@ -58,8 +74,8 @@ export var DatasourceModal = function DatasourceModal(_ref) {
58
74
  }));
59
75
  }
60
76
  if (modalType === 'assets') {
61
- var _existingNode$attrs2, _tableView$properties2;
62
- var _ref5 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 ? void 0 : _existingNode$attrs2.datasource) || {},
77
+ var _existingNode$attrs4, _tableView$properties2;
78
+ var _ref5 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs4 = existingNode.attrs) === null || _existingNode$attrs4 === void 0 ? void 0 : _existingNode$attrs4.datasource) || {},
63
79
  _ref5$id = _ref5.id,
64
80
  _datasourceId = _ref5$id === void 0 ? ASSETS_LIST_OF_LINKS_DATASOURCE_ID : _ref5$id,
65
81
  _parameters = _ref5.parameters,