@atlaskit/smart-card 26.21.0 → 26.22.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 +6 -0
  2. package/dist/cjs/state/actions/index.js +16 -52
  3. package/dist/cjs/state/analytics/useSmartLinkAnalytics.js +12 -11
  4. package/dist/cjs/state/hooks/use-invoke-client-action/index.js +78 -0
  5. package/dist/cjs/state/hooks/use-invoke-client-action/types.js +5 -0
  6. package/dist/cjs/utils/analytics/analytics.js +5 -9
  7. package/dist/cjs/utils/mocks.js +9 -4
  8. package/dist/cjs/view/BlockCard/actions/PreviewAction.js +6 -70
  9. package/dist/cjs/view/BlockCard/components/Action.js +1 -3
  10. package/dist/cjs/view/LinkUrl/index.js +1 -1
  11. package/dist/es2019/state/actions/index.js +10 -38
  12. package/dist/es2019/state/analytics/useSmartLinkAnalytics.js +12 -11
  13. package/dist/es2019/state/hooks/use-invoke-client-action/index.js +52 -0
  14. package/dist/es2019/state/hooks/use-invoke-client-action/types.js +1 -0
  15. package/dist/es2019/utils/analytics/analytics.js +5 -9
  16. package/dist/es2019/utils/mocks.js +9 -4
  17. package/dist/es2019/view/BlockCard/actions/PreviewAction.js +3 -44
  18. package/dist/es2019/view/BlockCard/components/Action.js +1 -1
  19. package/dist/es2019/view/LinkUrl/index.js +1 -1
  20. package/dist/esm/state/actions/index.js +16 -49
  21. package/dist/esm/state/analytics/useSmartLinkAnalytics.js +12 -11
  22. package/dist/esm/state/hooks/use-invoke-client-action/index.js +67 -0
  23. package/dist/esm/state/hooks/use-invoke-client-action/types.js +1 -0
  24. package/dist/esm/utils/analytics/analytics.js +5 -9
  25. package/dist/esm/utils/mocks.js +9 -4
  26. package/dist/esm/view/BlockCard/actions/PreviewAction.js +8 -65
  27. package/dist/esm/view/BlockCard/components/Action.js +1 -3
  28. package/dist/esm/view/LinkUrl/index.js +1 -1
  29. package/dist/types/state/analytics/useSmartLinkAnalytics.d.ts +3 -3
  30. package/dist/types/state/flexible-ui-context/index.d.ts +6 -6
  31. package/dist/types/state/hooks/use-invoke-client-action/index.d.ts +6 -0
  32. package/dist/types/state/hooks/use-invoke-client-action/types.d.ts +30 -0
  33. package/dist/types/state/hooks/useSmartLink.d.ts +3 -3
  34. package/dist/types/utils/analytics/types.d.ts +3 -3
  35. package/dist/types/utils/mocks.d.ts +3 -3
  36. package/dist/types/view/BlockCard/actions/PreviewAction.d.ts +0 -5
  37. package/dist/types/view/FlexibleCard/components/utils.d.ts +3 -3
  38. package/dist/types-ts4.5/state/analytics/useSmartLinkAnalytics.d.ts +3 -3
  39. package/dist/types-ts4.5/state/flexible-ui-context/index.d.ts +6 -6
  40. package/dist/types-ts4.5/state/hooks/use-invoke-client-action/index.d.ts +6 -0
  41. package/dist/types-ts4.5/state/hooks/use-invoke-client-action/types.d.ts +30 -0
  42. package/dist/types-ts4.5/state/hooks/useSmartLink.d.ts +3 -3
  43. package/dist/types-ts4.5/utils/analytics/types.d.ts +3 -3
  44. package/dist/types-ts4.5/utils/mocks.d.ts +3 -3
  45. package/dist/types-ts4.5/view/BlockCard/actions/PreviewAction.d.ts +0 -5
  46. package/dist/types-ts4.5/view/FlexibleCard/components/utils.d.ts +3 -3
  47. package/package.json +4 -3
  48. package/report.api.md +7 -7
  49. package/tmp/api-report-tmp.d.ts +6 -6
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 26.22.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`b3f9c544faa`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b3f9c544faa) - Refactor client action hook.
8
+
3
9
  ## 26.21.0
4
10
 
5
11
  ### Minor Changes
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -13,16 +12,16 @@ var _outboundAuthFlowClient = require("@atlaskit/outbound-auth-flow-client");
13
12
  var _linkProvider = require("@atlaskit/link-provider");
14
13
  var _linkingCommon = require("@atlaskit/linking-common");
15
14
  var _helpers = require("../helpers");
16
- var measure = _interopRequireWildcard(require("../../utils/performance"));
17
15
  var _constants = require("../../constants");
18
16
  var _useResolve = _interopRequireDefault(require("../hooks/use-resolve"));
19
- 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); }
20
- 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; }
17
+ var _useInvokeClientAction = _interopRequireDefault(require("../hooks/use-invoke-client-action"));
21
18
  var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
22
19
  var resolveUrl = (0, _useResolve.default)();
20
+ var invokeClientAction = (0, _useInvokeClientAction.default)({
21
+ analytics: analytics
22
+ });
23
23
  var _useSmartLinkContext = (0, _linkProvider.useSmartLinkContext)(),
24
- store = _useSmartLinkContext.store,
25
- connections = _useSmartLinkContext.connections;
24
+ store = _useSmartLinkContext.store;
26
25
  var getState = store.getState,
27
26
  dispatch = store.dispatch;
28
27
  var getSmartLinkState = (0, _react.useCallback)(function () {
@@ -152,70 +151,35 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
152
151
  }, [getSmartLinkState, analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload]);
153
152
  var invoke = (0, _react.useCallback)( /*#__PURE__*/function () {
154
153
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(opts, appearance) {
155
- var key, action, source, markName, response;
154
+ var key, action, source;
156
155
  return _regenerator.default.wrap(function _callee2$(_context2) {
157
156
  while (1) switch (_context2.prev = _context2.next) {
158
157
  case 0:
159
158
  key = opts.key, action = opts.action;
160
159
  source = opts.source || appearance;
161
- markName = "".concat(id, "-").concat(action.type); // Begin performance instrumentation.
162
- measure.mark(markName, 'pending');
163
- _context2.prev = 4;
164
- // Begin analytics instrumentation.
165
- analytics.ui.actionClickedEvent({
166
- id: id,
167
- extensionKey: key,
168
- actionType: action.type,
169
- display: source,
170
- invokeType: opts.type
171
- });
172
- // Invoke action - either client-side or server-side.
173
160
  if (!(opts.type === 'client')) {
174
- _context2.next = 12;
161
+ _context2.next = 6;
175
162
  break;
176
163
  }
177
- _context2.next = 9;
178
- return opts.action.promise();
179
- case 9:
180
- response = _context2.sent;
181
- _context2.next = 15;
182
- break;
183
- case 12:
184
- _context2.next = 14;
185
- return connections.client.postData(opts);
186
- case 14:
187
- response = _context2.sent;
188
- case 15:
189
- measure.mark(markName, 'resolved');
190
- analytics.operational.invokeSucceededEvent({
191
- id: id,
192
- extensionKey: key,
193
- actionType: action.type,
194
- display: source
195
- });
196
- return _context2.abrupt("return", response);
197
- case 20:
198
- _context2.prev = 20;
199
- _context2.t0 = _context2["catch"](4);
200
- measure.mark(markName, 'errored');
201
- analytics.operational.invokeFailedEvent({
202
- id: id,
203
- extensionKey: key,
164
+ _context2.next = 5;
165
+ return invokeClientAction({
166
+ actionFn: opts.action.promise,
204
167
  actionType: action.type,
205
168
  display: source,
206
- reason: _context2.t0.message
169
+ extensionKey: key
207
170
  });
208
- throw _context2.t0;
209
- case 25:
171
+ case 5:
172
+ return _context2.abrupt("return", _context2.sent);
173
+ case 6:
210
174
  case "end":
211
175
  return _context2.stop();
212
176
  }
213
- }, _callee2, null, [[4, 20]]);
177
+ }, _callee2);
214
178
  }));
215
179
  return function (_x, _x2) {
216
180
  return _ref3.apply(this, arguments);
217
181
  };
218
- }(), [id, analytics.ui, analytics.operational, connections.client]);
182
+ }(), [invokeClientAction]);
219
183
  return (0, _react.useMemo)(function () {
220
184
  return {
221
185
  register: register,
@@ -258,24 +258,25 @@ var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, _dispatchAnalyti
258
258
  * @returns
259
259
  */
260
260
  actionClickedEvent: function actionClickedEvent(_ref6) {
261
- var id = _ref6.id,
261
+ var experienceId = _ref6.id,
262
262
  actionType = _ref6.actionType,
263
263
  display = _ref6.display,
264
264
  invokeType = _ref6.invokeType,
265
- extensionKey = _ref6.extensionKey,
265
+ overrideExtensionKey = _ref6.extensionKey,
266
266
  definitionId = _ref6.definitionId,
267
267
  resourceType = _ref6.resourceType,
268
268
  destinationProduct = _ref6.destinationProduct,
269
269
  destinationSubproduct = _ref6.destinationSubproduct,
270
270
  location = _ref6.location;
271
- (0, _ufoExperiences.startUfoExperience)('smart-link-action-invocation', id, {
271
+ var extensionKey = overrideExtensionKey !== null && overrideExtensionKey !== void 0 ? overrideExtensionKey : extractedExtensionKey;
272
+ (0, _ufoExperiences.startUfoExperience)('smart-link-action-invocation', experienceId, {
272
273
  actionType: actionType,
273
274
  display: display,
274
275
  extensionKey: extensionKey,
275
276
  invokeType: invokeType
276
277
  });
277
278
  dispatchAnalytics(applyCommonAttributes((0, _analytics.uiActionClickedEvent)({
278
- id: id,
279
+ id: defaultId,
279
280
  actionType: actionType,
280
281
  display: display,
281
282
  extensionKey: extensionKey,
@@ -520,7 +521,7 @@ var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, _dispatchAnalyti
520
521
  return dispatchAnalytics(applyCommonAttributes((0, _analytics.uiSmartLinkStatusOpenPreviewButtonClicked)(), commonAttributes));
521
522
  }
522
523
  };
523
- }, [defaultId, commonAttributes, dispatchAnalytics]);
524
+ }, [dispatchAnalytics, commonAttributes, defaultId, extractedExtensionKey]);
524
525
 
525
526
  /** Contains all operational analytics events */
526
527
  var operational = (0, _react.useMemo)(function () {
@@ -533,7 +534,7 @@ var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, _dispatchAnalyti
533
534
  * @param display Whether the card was an Inline, Block, Embed or Flexible UI.
534
535
  */
535
536
  invokeSucceededEvent: function invokeSucceededEvent(_ref13) {
536
- var id = _ref13.id,
537
+ var experienceId = _ref13.id,
537
538
  actionType = _ref13.actionType,
538
539
  display = _ref13.display,
539
540
  extensionKey = _ref13.extensionKey,
@@ -542,9 +543,9 @@ var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, _dispatchAnalyti
542
543
  destinationProduct = _ref13.destinationProduct,
543
544
  destinationSubproduct = _ref13.destinationSubproduct,
544
545
  location = _ref13.location;
545
- (0, _ufoExperiences.succeedUfoExperience)('smart-link-action-invocation', id);
546
+ (0, _ufoExperiences.succeedUfoExperience)('smart-link-action-invocation', experienceId);
546
547
  dispatchAnalytics(applyCommonAttributes((0, _analytics.invokeSucceededEvent)({
547
- id: id,
548
+ id: defaultId,
548
549
  actionType: actionType,
549
550
  display: display,
550
551
  extensionKey: extensionKey,
@@ -564,7 +565,7 @@ var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, _dispatchAnalyti
564
565
  * @param reason The reason the invocation failed.
565
566
  */
566
567
  invokeFailedEvent: function invokeFailedEvent(_ref14) {
567
- var id = _ref14.id,
568
+ var experienceId = _ref14.id,
568
569
  actionType = _ref14.actionType,
569
570
  display = _ref14.display,
570
571
  reason = _ref14.reason,
@@ -574,9 +575,9 @@ var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, _dispatchAnalyti
574
575
  destinationProduct = _ref14.destinationProduct,
575
576
  destinationSubproduct = _ref14.destinationSubproduct,
576
577
  location = _ref14.location;
577
- (0, _ufoExperiences.failUfoExperience)('smart-link-action-invocation', id);
578
+ (0, _ufoExperiences.failUfoExperience)('smart-link-action-invocation', experienceId);
578
579
  dispatchAnalytics(applyCommonAttributes((0, _analytics.invokeFailedEvent)({
579
- id: id,
580
+ id: defaultId,
580
581
  actionType: actionType,
581
582
  display: display,
582
583
  reason: reason,
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
10
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
11
+ var _react = require("react");
12
+ var _uuid = _interopRequireDefault(require("uuid"));
13
+ var measure = _interopRequireWildcard(require("../../../utils/performance"));
14
+ 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); }
15
+ 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; }
16
+ /**
17
+ * Invoke client action such as preview, download and open link
18
+ */
19
+ var useInvokeClientAction = function useInvokeClientAction(_ref) {
20
+ var analytics = _ref.analytics;
21
+ return (0, _react.useCallback)( /*#__PURE__*/function () {
22
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref2) {
23
+ var actionType, actionFn, extensionKey, display, experienceId, markName, result, reason;
24
+ return _regenerator.default.wrap(function _callee$(_context) {
25
+ while (1) switch (_context.prev = _context.next) {
26
+ case 0:
27
+ actionType = _ref2.actionType, actionFn = _ref2.actionFn, extensionKey = _ref2.extensionKey, display = _ref2.display;
28
+ experienceId = (0, _uuid.default)(); // Begin performance instrumentation.
29
+ markName = "".concat(experienceId, "-").concat(actionType);
30
+ measure.mark(markName, 'pending');
31
+ _context.prev = 4;
32
+ // Begin analytics instrumentation.
33
+ analytics === null || analytics === void 0 ? void 0 : analytics.ui.actionClickedEvent({
34
+ id: experienceId,
35
+ extensionKey: extensionKey,
36
+ actionType: actionType,
37
+ display: display,
38
+ invokeType: 'client'
39
+ });
40
+
41
+ // Invoke action
42
+ _context.next = 8;
43
+ return actionFn();
44
+ case 8:
45
+ result = _context.sent;
46
+ measure.mark(markName, 'resolved');
47
+ analytics === null || analytics === void 0 ? void 0 : analytics.operational.invokeSucceededEvent({
48
+ id: experienceId,
49
+ extensionKey: extensionKey,
50
+ actionType: actionType,
51
+ display: display
52
+ });
53
+ return _context.abrupt("return", result);
54
+ case 14:
55
+ _context.prev = 14;
56
+ _context.t0 = _context["catch"](4);
57
+ measure.mark(markName, 'errored');
58
+ reason = typeof _context.t0 === 'string' ? _context.t0 : _context.t0 === null || _context.t0 === void 0 ? void 0 : _context.t0.message;
59
+ analytics === null || analytics === void 0 ? void 0 : analytics.operational.invokeFailedEvent({
60
+ id: experienceId,
61
+ extensionKey: extensionKey,
62
+ actionType: actionType,
63
+ display: display,
64
+ reason: reason
65
+ });
66
+ case 19:
67
+ case "end":
68
+ return _context.stop();
69
+ }
70
+ }, _callee, null, [[4, 14]]);
71
+ }));
72
+ return function (_x) {
73
+ return _ref3.apply(this, arguments);
74
+ };
75
+ }(), [analytics === null || analytics === void 0 ? void 0 : analytics.operational, analytics === null || analytics === void 0 ? void 0 : analytics.ui]);
76
+ };
77
+ var _default = useInvokeClientAction;
78
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -21,7 +21,7 @@ exports.ANALYTICS_CHANNEL = ANALYTICS_CHANNEL;
21
21
  var context = {
22
22
  componentName: 'smart-cards',
23
23
  packageName: "@atlaskit/smart-card",
24
- packageVersion: "26.21.0"
24
+ packageVersion: "26.22.0"
25
25
  };
26
26
  exports.context = context;
27
27
  var TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
@@ -128,9 +128,7 @@ var invokeSucceededEvent = function invokeSucceededEvent(_ref2) {
128
128
  destinationProduct = _ref2.destinationProduct,
129
129
  destinationSubproduct = _ref2.destinationSubproduct,
130
130
  location = _ref2.location;
131
- var measure = (0, _performance.getMeasure)(id, 'resolved') || {
132
- duration: undefined
133
- };
131
+ var measure = id ? (0, _performance.getMeasure)(id, 'resolved') : undefined;
134
132
  return {
135
133
  action: 'resolved',
136
134
  actionSubject: 'smartLinkAction',
@@ -144,7 +142,7 @@ var invokeSucceededEvent = function invokeSucceededEvent(_ref2) {
144
142
  destinationSubproduct: destinationSubproduct,
145
143
  location: location,
146
144
  extensionKey: extensionKey,
147
- duration: measure.duration
145
+ duration: measure === null || measure === void 0 ? void 0 : measure.duration
148
146
  })
149
147
  };
150
148
  };
@@ -159,9 +157,7 @@ var invokeFailedEvent = function invokeFailedEvent(_ref3) {
159
157
  destinationProduct = _ref3.destinationProduct,
160
158
  destinationSubproduct = _ref3.destinationSubproduct,
161
159
  location = _ref3.location;
162
- var measure = (0, _performance.getMeasure)(id, 'errored') || {
163
- duration: undefined
164
- };
160
+ var measure = id ? (0, _performance.getMeasure)(id, 'errored') : undefined;
165
161
  return {
166
162
  action: 'unresolved',
167
163
  actionSubject: 'smartLinkAction',
@@ -175,7 +171,7 @@ var invokeFailedEvent = function invokeFailedEvent(_ref3) {
175
171
  destinationProduct: destinationProduct,
176
172
  destinationSubproduct: destinationSubproduct,
177
173
  location: location,
178
- duration: measure.duration,
174
+ duration: measure === null || measure === void 0 ? void 0 : measure.duration,
179
175
  reason: reason
180
176
  })
181
177
  };
@@ -72,11 +72,12 @@ var mocks = {
72
72
  name: 'I love cheese',
73
73
  summary: 'Here is your serving of cheese: 🧀',
74
74
  'schema:potentialAction': {
75
- '@id': 'comment',
76
- '@type': 'CommentAction',
75
+ '@id': 'download',
76
+ '@type': 'DownloadAction',
77
77
  identifier: 'object-provider',
78
- name: 'Comment'
78
+ name: 'Download'
79
79
  },
80
+ 'atlassian:downloadUrl': 'https://some-download.url',
80
81
  preview: {
81
82
  href: 'https://www.ilovecheese.com'
82
83
  },
@@ -303,12 +304,16 @@ var waitFor = function waitFor() {
303
304
  exports.waitFor = waitFor;
304
305
  var mockAnalytics = {
305
306
  ui: {
307
+ actionClickedEvent: function actionClickedEvent() {},
306
308
  buttonClickedEvent: function buttonClickedEvent() {},
307
309
  modalClosedEvent: function modalClosedEvent() {},
308
310
  renderSuccessEvent: function renderSuccessEvent() {},
309
311
  renderFailedEvent: function renderFailedEvent() {}
310
312
  },
311
- operational: {},
313
+ operational: {
314
+ invokeSucceededEvent: function invokeSucceededEvent() {},
315
+ invokeFailedEvent: function invokeFailedEvent() {}
316
+ },
312
317
  track: {},
313
318
  screen: {
314
319
  modalViewedEvent: function modalViewedEvent() {}
@@ -1,97 +1,33 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
- exports.previewFunction = previewFunction;
10
- var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
12
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
13
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
14
- var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
15
10
  var _react = _interopRequireDefault(require("react"));
16
- var _reactDom = _interopRequireDefault(require("react-dom"));
17
11
  var _reactIntlNext = require("react-intl-next");
18
12
  var _messages = require("../../../messages");
19
- var _excluded = ["popupMountPointId", "onClose"],
20
- _excluded2 = ["details"];
21
- 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); }
22
- 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; }
13
+ var _utils = require("../../EmbedModal/utils");
14
+ var _excluded = ["details"];
23
15
  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; }
24
16
  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; }
25
- /*
26
- Explanatory note:
27
- Actions don't have access to the react tree of whatever is rendered them
28
- (and this concept is fraught inside editor anyway) so we want to ensure
29
- it is mounting to a new unique place. This function manages that, including
30
- creating an element if it doesn't exist, as well as tidying up the react tree
31
- (but not the element) upon closing the modal.
32
-
33
- This may strike you as really uncomfortable as you read it, so I wanted to note
34
- that a) this was discussed and agreed upon, and b) it's definitely odd, and if
35
- you find an elegant solution around this, you should definitely feel free to
36
- refactor it.
37
- */
38
- function previewFunction(_x) {
39
- return _previewFunction.apply(this, arguments);
40
- }
41
17
  /*
42
18
  Most of these are optional as we are being fault-tolerant
43
19
  However src, details, icon, title, and providerName are STRONGLY encouraged
44
20
  */
45
- function _previewFunction() {
46
- _previewFunction = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref) {
47
- var popupMountPointId, _onClose, rest, popupMountPoint, Modal;
48
- return _regenerator.default.wrap(function _callee$(_context) {
49
- while (1) switch (_context.prev = _context.next) {
50
- case 0:
51
- popupMountPointId = _ref.popupMountPointId, _onClose = _ref.onClose, rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
52
- popupMountPoint = document.getElementById(popupMountPointId);
53
- if (!popupMountPoint) {
54
- popupMountPoint = document.createElement('div');
55
- popupMountPoint.id = popupMountPointId;
56
- popupMountPoint.setAttribute('data-testid', 'preview-modal');
57
- document.body.appendChild(popupMountPoint);
58
- }
59
- _context.next = 5;
60
- return Promise.resolve().then(function () {
61
- return _interopRequireWildcard(require('../../EmbedModal'));
62
- });
63
- case 5:
64
- Modal = _context.sent;
65
- _reactDom.default.render( /*#__PURE__*/_react.default.createElement(_reactIntlNext.IntlProvider, {
66
- locale: "en"
67
- }, /*#__PURE__*/_react.default.createElement(Modal.default, (0, _extends2.default)({}, rest, {
68
- onClose: function onClose(context) {
69
- if (popupMountPoint) {
70
- _onClose(context);
71
- _reactDom.default.unmountComponentAtNode(popupMountPoint);
72
- }
73
- }
74
- }))), popupMountPoint);
75
- case 7:
76
- case "end":
77
- return _context.stop();
78
- }
79
- }, _callee);
80
- }));
81
- return _previewFunction.apply(this, arguments);
82
- }
83
- var _default = function _default(_ref2) {
84
- var details = _ref2.details,
85
- rest = (0, _objectWithoutProperties2.default)(_ref2, _excluded2);
21
+ var _default = function _default(_ref) {
22
+ var details = _ref.details,
23
+ rest = (0, _objectWithoutProperties2.default)(_ref, _excluded);
86
24
  return {
87
25
  id: 'preview-content',
88
26
  text: /*#__PURE__*/_react.default.createElement(_reactIntlNext.FormattedMessage, _messages.messages.preview_improved),
89
27
  promise: function promise() {
90
- return previewFunction(_objectSpread({
91
- popupMountPointId: 'twp-editor-preview-iframe',
28
+ return (0, _utils.openEmbedModal)(_objectSpread({
92
29
  providerName: 'Preview',
93
30
  showModal: true,
94
- iframeName: 'twp-editor-preview-iframe',
95
31
  onClose: function onClose() {}
96
32
  }, rest));
97
33
  }
@@ -36,11 +36,9 @@ var Action = function Action(_ref) {
36
36
  setState('loading');
37
37
  promise().then(function () {
38
38
  setState('success');
39
- setTimeout(function () {
40
- return setState('init');
41
- }, spinnerDelay);
42
39
  }).catch(function () {
43
40
  setState('failure');
41
+ }).finally(function () {
44
42
  setTimeout(function () {
45
43
  return setState('init');
46
44
  }, spinnerDelay);
@@ -18,7 +18,7 @@ var _excluded = ["href", "children", "checkSafety", "onClick", "testId"],
18
18
  _excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
19
19
  var PACKAGE_DATA = {
20
20
  packageName: "@atlaskit/smart-card",
21
- packageVersion: "26.21.0",
21
+ packageVersion: "26.22.0",
22
22
  componentName: 'linkUrl'
23
23
  };
24
24
  var Link = (0, _click.withLinkClickedEvent)('a');
@@ -3,14 +3,16 @@ import { auth } from '@atlaskit/outbound-auth-flow-client';
3
3
  import { useSmartLinkContext } from '@atlaskit/link-provider';
4
4
  import { ACTION_UPDATE_METADATA_STATUS, cardAction, ACTION_RESOLVING } from '@atlaskit/linking-common';
5
5
  import { getDefinitionId, getByDefinitionId, getServices, getExtensionKey } from '../helpers';
6
- import * as measure from '../../utils/performance';
7
6
  import { SmartLinkStatus } from '../../constants';
8
7
  import useResolve from '../hooks/use-resolve';
8
+ import useInvokeClientAction from '../hooks/use-invoke-client-action';
9
9
  export const useSmartCardActions = (id, url, analytics) => {
10
10
  const resolveUrl = useResolve();
11
+ const invokeClientAction = useInvokeClientAction({
12
+ analytics
13
+ });
11
14
  const {
12
- store,
13
- connections
15
+ store
14
16
  } = useSmartLinkContext();
15
17
  const {
16
18
  getState,
@@ -133,45 +135,15 @@ export const useSmartCardActions = (id, url, analytics) => {
133
135
  action
134
136
  } = opts;
135
137
  const source = opts.source || appearance;
136
- const markName = `${id}-${action.type}`;
137
- // Begin performance instrumentation.
138
- measure.mark(markName, 'pending');
139
- try {
140
- // Begin analytics instrumentation.
141
- analytics.ui.actionClickedEvent({
142
- id,
143
- extensionKey: key,
138
+ if (opts.type === 'client') {
139
+ return await invokeClientAction({
140
+ actionFn: opts.action.promise,
144
141
  actionType: action.type,
145
142
  display: source,
146
- invokeType: opts.type
143
+ extensionKey: key
147
144
  });
148
- // Invoke action - either client-side or server-side.
149
- let response;
150
- if (opts.type === 'client') {
151
- response = await opts.action.promise();
152
- } else {
153
- response = await connections.client.postData(opts);
154
- }
155
- measure.mark(markName, 'resolved');
156
- analytics.operational.invokeSucceededEvent({
157
- id,
158
- extensionKey: key,
159
- actionType: action.type,
160
- display: source
161
- });
162
- return response;
163
- } catch (err) {
164
- measure.mark(markName, 'errored');
165
- analytics.operational.invokeFailedEvent({
166
- id,
167
- extensionKey: key,
168
- actionType: action.type,
169
- display: source,
170
- reason: err.message
171
- });
172
- throw err;
173
145
  }
174
- }, [id, analytics.ui, analytics.operational, connections.client]);
146
+ }, [invokeClientAction]);
175
147
  return useMemo(() => ({
176
148
  register,
177
149
  reload,
@@ -239,25 +239,26 @@ export const useSmartLinkAnalytics = (url, _dispatchAnalytics, id, defaultLocati
239
239
  * @returns
240
240
  */
241
241
  actionClickedEvent: ({
242
- id,
242
+ id: experienceId,
243
243
  actionType,
244
244
  display,
245
245
  invokeType,
246
- extensionKey,
246
+ extensionKey: overrideExtensionKey,
247
247
  definitionId,
248
248
  resourceType,
249
249
  destinationProduct,
250
250
  destinationSubproduct,
251
251
  location
252
252
  }) => {
253
- startUfoExperience('smart-link-action-invocation', id, {
253
+ const extensionKey = overrideExtensionKey !== null && overrideExtensionKey !== void 0 ? overrideExtensionKey : extractedExtensionKey;
254
+ startUfoExperience('smart-link-action-invocation', experienceId, {
254
255
  actionType,
255
256
  display,
256
257
  extensionKey,
257
258
  invokeType
258
259
  });
259
260
  dispatchAnalytics(applyCommonAttributes(uiActionClickedEvent({
260
- id,
261
+ id: defaultId,
261
262
  actionType,
262
263
  display,
263
264
  extensionKey,
@@ -494,7 +495,7 @@ export const useSmartLinkAnalytics = (url, _dispatchAnalytics, id, defaultLocati
494
495
  * Fires an event that represent a click was performed on a Status Lozenge open preview button
495
496
  */
496
497
  smartLinkLozengeActionErrorOpenPreviewClickedEvent: () => dispatchAnalytics(applyCommonAttributes(uiSmartLinkStatusOpenPreviewButtonClicked(), commonAttributes))
497
- }), [defaultId, commonAttributes, dispatchAnalytics]);
498
+ }), [dispatchAnalytics, commonAttributes, defaultId, extractedExtensionKey]);
498
499
 
499
500
  /** Contains all operational analytics events */
500
501
  const operational = useMemo(() => ({
@@ -506,7 +507,7 @@ export const useSmartLinkAnalytics = (url, _dispatchAnalytics, id, defaultLocati
506
507
  * @param display Whether the card was an Inline, Block, Embed or Flexible UI.
507
508
  */
508
509
  invokeSucceededEvent: ({
509
- id,
510
+ id: experienceId,
510
511
  actionType,
511
512
  display,
512
513
  extensionKey,
@@ -516,9 +517,9 @@ export const useSmartLinkAnalytics = (url, _dispatchAnalytics, id, defaultLocati
516
517
  destinationSubproduct,
517
518
  location
518
519
  }) => {
519
- succeedUfoExperience('smart-link-action-invocation', id);
520
+ succeedUfoExperience('smart-link-action-invocation', experienceId);
520
521
  dispatchAnalytics(applyCommonAttributes(invokeSucceededEvent({
521
- id,
522
+ id: defaultId,
522
523
  actionType,
523
524
  display,
524
525
  extensionKey,
@@ -538,7 +539,7 @@ export const useSmartLinkAnalytics = (url, _dispatchAnalytics, id, defaultLocati
538
539
  * @param reason The reason the invocation failed.
539
540
  */
540
541
  invokeFailedEvent: ({
541
- id,
542
+ id: experienceId,
542
543
  actionType,
543
544
  display,
544
545
  reason,
@@ -549,9 +550,9 @@ export const useSmartLinkAnalytics = (url, _dispatchAnalytics, id, defaultLocati
549
550
  destinationSubproduct,
550
551
  location
551
552
  }) => {
552
- failUfoExperience('smart-link-action-invocation', id);
553
+ failUfoExperience('smart-link-action-invocation', experienceId);
553
554
  dispatchAnalytics(applyCommonAttributes(invokeFailedEvent({
554
- id,
555
+ id: defaultId,
555
556
  actionType,
556
557
  display,
557
558
  reason,