@atlaskit/smart-card 22.0.0 → 22.1.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 (78) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/extractors/block/index.js +6 -7
  3. package/dist/cjs/extractors/common/actions/extractPreviewAction.js +16 -27
  4. package/dist/cjs/state/analytics/useSmartLinkAnalytics.js +43 -0
  5. package/dist/cjs/state/hooks-external/useSmartLinkActions.js +5 -3
  6. package/dist/cjs/utils/analytics/analytics.js +2 -2
  7. package/dist/cjs/utils/mocks.js +28 -2
  8. package/dist/cjs/version.json +1 -1
  9. package/dist/cjs/view/BlockCard/actions/PreviewAction.js +2 -2
  10. package/dist/cjs/view/BlockCard/index.js +6 -5
  11. package/dist/cjs/view/CardWithUrl/component.js +2 -2
  12. package/dist/cjs/view/EmbedCard/index.js +3 -2
  13. package/dist/cjs/view/EmbedModal/components/analytics/index.js +100 -0
  14. package/dist/cjs/view/EmbedModal/components/analytics/types.js +5 -0
  15. package/dist/cjs/view/EmbedModal/components/size-experiment/index.js +5 -10
  16. package/dist/cjs/view/EmbedModal/index.js +54 -15
  17. package/dist/cjs/view/EmbedModal/types.js +9 -1
  18. package/dist/cjs/view/HoverCard/components/HoverCardComponent.js +2 -1
  19. package/dist/cjs/view/common/Modal.js +29 -4
  20. package/dist/cjs/view/common/ModalHeader.js +3 -2
  21. package/dist/es2019/extractors/block/index.js +6 -7
  22. package/dist/es2019/extractors/common/actions/extractPreviewAction.js +16 -18
  23. package/dist/es2019/state/analytics/useSmartLinkAnalytics.js +46 -3
  24. package/dist/es2019/state/hooks-external/useSmartLinkActions.js +5 -3
  25. package/dist/es2019/utils/analytics/analytics.js +1 -1
  26. package/dist/es2019/utils/mocks.js +26 -1
  27. package/dist/es2019/version.json +1 -1
  28. package/dist/es2019/view/BlockCard/actions/PreviewAction.js +3 -3
  29. package/dist/es2019/view/BlockCard/index.js +5 -4
  30. package/dist/es2019/view/CardWithUrl/component.js +2 -2
  31. package/dist/es2019/view/EmbedCard/index.js +3 -2
  32. package/dist/es2019/view/EmbedModal/components/analytics/index.js +80 -0
  33. package/dist/es2019/view/EmbedModal/components/analytics/types.js +1 -0
  34. package/dist/es2019/view/EmbedModal/components/size-experiment/index.js +5 -9
  35. package/dist/es2019/view/EmbedModal/index.js +46 -13
  36. package/dist/es2019/view/EmbedModal/types.js +6 -1
  37. package/dist/es2019/view/HoverCard/components/HoverCardComponent.js +2 -1
  38. package/dist/es2019/view/common/Modal.js +27 -6
  39. package/dist/es2019/view/common/ModalHeader.js +3 -2
  40. package/dist/esm/extractors/block/index.js +6 -7
  41. package/dist/esm/extractors/common/actions/extractPreviewAction.js +17 -27
  42. package/dist/esm/state/analytics/useSmartLinkAnalytics.js +45 -2
  43. package/dist/esm/state/hooks-external/useSmartLinkActions.js +5 -3
  44. package/dist/esm/utils/analytics/analytics.js +2 -2
  45. package/dist/esm/utils/mocks.js +25 -0
  46. package/dist/esm/version.json +1 -1
  47. package/dist/esm/view/BlockCard/actions/PreviewAction.js +3 -3
  48. package/dist/esm/view/BlockCard/index.js +5 -4
  49. package/dist/esm/view/CardWithUrl/component.js +2 -2
  50. package/dist/esm/view/EmbedCard/index.js +3 -2
  51. package/dist/esm/view/EmbedModal/components/analytics/index.js +82 -0
  52. package/dist/esm/view/EmbedModal/components/analytics/types.js +1 -0
  53. package/dist/esm/view/EmbedModal/components/size-experiment/index.js +5 -10
  54. package/dist/esm/view/EmbedModal/index.js +52 -15
  55. package/dist/esm/view/EmbedModal/types.js +6 -1
  56. package/dist/esm/view/HoverCard/components/HoverCardComponent.js +2 -1
  57. package/dist/esm/view/common/Modal.js +28 -6
  58. package/dist/esm/view/common/ModalHeader.js +3 -2
  59. package/dist/types/extractors/block/types.d.ts +4 -2
  60. package/dist/types/extractors/common/actions/extractPreviewAction.d.ts +7 -5
  61. package/dist/types/state/analytics/useSmartLinkAnalytics.d.ts +23 -1
  62. package/dist/types/state/hooks/useSmartLink.d.ts +9 -0
  63. package/dist/types/state/hooks-external/useSmartLinkActions.d.ts +6 -2
  64. package/dist/types/utils/mocks.d.ts +48 -0
  65. package/dist/types/utils/types.d.ts +3 -1
  66. package/dist/types/view/BlockCard/actions/PreviewAction.d.ts +4 -0
  67. package/dist/types/view/BlockCard/index.d.ts +2 -2
  68. package/dist/types/view/BlockCard/types.d.ts +4 -4
  69. package/dist/types/view/Card/index.d.ts +1 -1
  70. package/dist/types/view/EmbedCard/types.d.ts +2 -2
  71. package/dist/types/view/EmbedModal/components/analytics/index.d.ts +5 -0
  72. package/dist/types/view/EmbedModal/components/analytics/types.d.ts +6 -0
  73. package/dist/types/view/EmbedModal/components/size-experiment/index.d.ts +4 -3
  74. package/dist/types/view/EmbedModal/index.d.ts +3 -1
  75. package/dist/types/view/EmbedModal/types.d.ts +14 -4
  76. package/dist/types/view/common/Modal.d.ts +6 -8
  77. package/package.json +1 -1
  78. package/report.api.md +34 -2
@@ -14,10 +14,12 @@ manually passed to your custom components.
14
14
 
15
15
  For a complete guide on customization using the new compositional API, refer to the docs at
16
16
  https://atlassian.design/components/modal-dialog/examples#customizing-modal-dialog. */
17
- import React, { useState } from 'react';
18
- import ModalDialog, { ModalTransition, ModalBody } from '@atlaskit/modal-dialog';
17
+ import React, { useCallback, useRef, useState } from 'react';
18
+ import ModalDialog, { ModalBody, ModalTransition } from '@atlaskit/modal-dialog';
19
19
  import { Header } from './ModalHeader';
20
20
  import { getIframeSandboxAttribute } from '../../utils';
21
+ import withAnalytics from '../EmbedModal/components/analytics';
22
+ import { EmbedModalSize } from '../EmbedModal/types';
21
23
  const iframeStyles = {
22
24
  width: `100%`,
23
25
  height: 'calc(100vh - 248px)'
@@ -45,7 +47,7 @@ const Modal = ({
45
47
  providerName,
46
48
  metadata,
47
49
  icon,
48
- closeLabel,
50
+ closeLabel = 'Close Preview',
49
51
  iframeName,
50
52
  title,
51
53
  url,
@@ -56,16 +58,35 @@ const Modal = ({
56
58
  onDownloadActionClick
57
59
  }) => {
58
60
  let [isOpen, setIsOpen] = useState(showModal);
61
+ const openAt = useRef();
62
+ const handleOnOpenComplete = useCallback(() => {
63
+ openAt.current = Date.now();
64
+
65
+ if (onOpen) {
66
+ onOpen({
67
+ size: EmbedModalSize.Small
68
+ });
69
+ }
70
+ }, [onOpen]);
71
+ const handleOnCloseComplete = useCallback(() => {
72
+ if (onClose) {
73
+ const duration = openAt.current ? Date.now() - openAt.current : undefined;
74
+ onClose({
75
+ duration,
76
+ size: EmbedModalSize.Small
77
+ });
78
+ }
79
+ }, [onClose]);
59
80
  const sandbox = getIframeSandboxAttribute(isTrusted);
60
81
  return /*#__PURE__*/React.createElement(ModalTransition, null, isOpen && /*#__PURE__*/React.createElement(ModalDialog, {
61
82
  height: "100%",
62
83
  width: "large",
63
84
  testId: testId,
64
- onOpenComplete: onOpen,
85
+ onOpenComplete: handleOnOpenComplete,
65
86
  onClose: () => {
66
87
  setIsOpen(false);
67
88
  },
68
- onCloseComplete: onClose
89
+ onCloseComplete: handleOnCloseComplete
69
90
  }, /*#__PURE__*/React.createElement(Header, {
70
91
  providerName: providerName,
71
92
  icon: icon,
@@ -91,4 +112,4 @@ const Modal = ({
91
112
  }))));
92
113
  };
93
114
 
94
- export default ModalWithErrorBoundary;
115
+ export default withAnalytics(ModalWithErrorBoundary);
@@ -74,7 +74,7 @@ export const Header = ({
74
74
  testId: "preview-view-action",
75
75
  iconAfter: jsx(ShortcutIcon, {
76
76
  size: "small",
77
- label: "go to source"
77
+ label: ""
78
78
  }),
79
79
  onClick: onViewActionClick
80
80
  }, providerName ? jsx(F, null, jsx(FormattedMessage, messages.viewIn), " ", providerName) : jsx(FormattedMessage, messages.viewOriginal)), jsx(Button, {
@@ -82,6 +82,7 @@ export const Header = ({
82
82
  iconBefore: jsx(EditorCloseIcon, {
83
83
  label: label
84
84
  }),
85
- onClick: onClose
85
+ onClick: onClose,
86
+ testId: "preview-close-button"
86
87
  }))));
87
88
  };
@@ -37,14 +37,13 @@ var extractBlockDetails = function extractBlockDetails(jsonLd) {
37
37
 
38
38
  export var extractBlockActions = function extractBlockActions(props, jsonLd, opts, platform) {
39
39
  if (opts) {
40
- var featureFlags = opts.featureFlags,
41
- handleInvoke = opts.handleInvoke,
42
- handleAnalytics = opts.handleAnalytics,
43
- extensionKey = opts.extensionKey,
44
- source = opts.source,
45
- testId = opts.testId;
40
+ var handleInvoke = opts.handleInvoke;
46
41
  var actions = extractActions(jsonLd, handleInvoke);
47
- var previewAction = extractPreviewAction(extensionKey, props, jsonLd, handleInvoke, handleAnalytics, testId, platform, source, featureFlags); // The previewAction should always be the last action
42
+ var previewAction = extractPreviewAction(_objectSpread(_objectSpread({}, opts), {}, {
43
+ viewProps: props,
44
+ jsonLd: jsonLd,
45
+ platform: platform
46
+ })); // The previewAction should always be the last action
48
47
 
49
48
  if (previewAction) {
50
49
  actions.push(previewAction);
@@ -4,9 +4,8 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
4
4
 
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
6
 
7
- import { uiRenderSuccessEvent, uiRenderFailedEvent } from '../../../utils/analytics';
8
7
  import { extractDownloadUrl } from '../detail';
9
- import { extractProvider, extractPreview } from '@atlaskit/linking-common/extractors';
8
+ import { extractPreview, extractProvider } from '@atlaskit/linking-common/extractors';
10
9
  import { PreviewAction } from '../../../view/BlockCard';
11
10
 
12
11
  var getMetadataFromJsonLd = function getMetadataFromJsonLd(jsonLd, platform) {
@@ -51,16 +50,19 @@ var getInvokeOpts = function getInvokeOpts(key, action, source) {
51
50
  };
52
51
  };
53
52
 
54
- export var extractPreviewAction = function extractPreviewAction() {
55
- var extensionKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'empty-object-provider';
56
- var viewProps = arguments.length > 1 ? arguments[1] : undefined;
57
- var jsonLd = arguments.length > 2 ? arguments[2] : undefined;
58
- var handleInvoke = arguments.length > 3 ? arguments[3] : undefined;
59
- var handleAnalytics = arguments.length > 4 ? arguments[4] : undefined;
60
- var testId = arguments.length > 5 ? arguments[5] : undefined;
61
- var platform = arguments.length > 6 ? arguments[6] : undefined;
62
- var source = arguments.length > 7 ? arguments[7] : undefined;
63
- var featureFlags = arguments.length > 8 ? arguments[8] : undefined;
53
+ export var extractPreviewAction = function extractPreviewAction(_ref) {
54
+ var _ref$extensionKey = _ref.extensionKey,
55
+ extensionKey = _ref$extensionKey === void 0 ? 'empty-object-provider' : _ref$extensionKey,
56
+ viewProps = _ref.viewProps,
57
+ jsonLd = _ref.jsonLd,
58
+ handleInvoke = _ref.handleInvoke,
59
+ testId = _ref.testId,
60
+ platform = _ref.platform,
61
+ origin = _ref.origin,
62
+ _ref$source = _ref.source,
63
+ source = _ref$source === void 0 ? 'block' : _ref$source,
64
+ featureFlags = _ref.featureFlags,
65
+ analytics = _ref.analytics;
64
66
  // Extract metadata from view props & raw JSON-LD.
65
67
  var metadataFromJsonLd = getMetadataFromJsonLd(jsonLd, platform);
66
68
  var metadataFromViewProps = getMetadataFromResolvedProps(viewProps);
@@ -72,22 +74,10 @@ export var extractPreviewAction = function extractPreviewAction() {
72
74
  // Build action using instrumentation hooks.
73
75
  var key = extensionKey;
74
76
  var previewAction = PreviewAction(_objectSpread(_objectSpread({}, metadata), {}, {
77
+ analytics: analytics,
78
+ origin: origin,
75
79
  featureFlags: featureFlags,
76
80
  testId: testId,
77
- onOpen: function onOpen() {
78
- handleAnalytics(uiRenderSuccessEvent({
79
- display: 'preview',
80
- status: 'resolved',
81
- extensionKey: key
82
- }));
83
- },
84
- onOpenFailed: function onOpenFailed(error, errorInfo) {
85
- handleAnalytics(uiRenderFailedEvent({
86
- display: 'preview',
87
- error: error,
88
- errorInfo: errorInfo
89
- }));
90
- },
91
81
  onDownloadActionClick: function onDownloadActionClick() {
92
82
  handleInvoke(getInvokeOpts(key, 'DownloadAction'));
93
83
  },
@@ -97,7 +87,7 @@ export var extractPreviewAction = function extractPreviewAction() {
97
87
  })); // Setup props to go through proper Redux 'invocation' flow
98
88
  // for analytics, further state management if required in future.
99
89
 
100
- var previewActionProps = getInvokeOpts(key, 'PreviewAction', source !== null && source !== void 0 ? source : 'block'); // - Promise invoked by the action invocation handler; open preview.
90
+ var previewActionProps = getInvokeOpts(key, 'PreviewAction', source); // - Promise invoked by the action invocation handler; open preview.
101
91
 
102
92
  previewActionProps.action.promise = previewAction.promise; // - Promise invoked on click of `Preview` on block card; trigger above promise.
103
93
 
@@ -7,9 +7,9 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
7
7
 
8
8
  import { useMemo } from 'react';
9
9
  import { getUrl } from '@atlaskit/linking-common';
10
- import { uiAuthEvent, uiAuthAlternateAccountEvent, uiCardClickedEvent, uiActionClickedEvent, uiClosedAuthEvent, uiRenderSuccessEvent, uiRenderFailedEvent, uiHoverCardViewedEvent, uiHoverCardDismissedEvent, uiHoverCardOpenLinkClickedEvent, invokeSucceededEvent as _invokeSucceededEvent, invokeFailedEvent as _invokeFailedEvent, connectSucceededEvent as _connectSucceededEvent, connectFailedEvent as _connectFailedEvent, trackAppAccountConnected, screenAuthPopupEvent, instrumentEvent } from '../../utils/analytics';
10
+ import { connectFailedEvent as _connectFailedEvent, connectSucceededEvent as _connectSucceededEvent, context, instrumentEvent, invokeFailedEvent as _invokeFailedEvent, invokeSucceededEvent as _invokeSucceededEvent, screenAuthPopupEvent, trackAppAccountConnected, uiActionClickedEvent, uiAuthAlternateAccountEvent, uiAuthEvent, uiCardClickedEvent, uiClosedAuthEvent, uiHoverCardDismissedEvent, uiHoverCardOpenLinkClickedEvent, uiHoverCardViewedEvent, uiRenderFailedEvent, uiRenderSuccessEvent } from '../../utils/analytics';
11
11
  import { failUfoExperience, startUfoExperience, succeedUfoExperience } from './ufoExperiences';
12
- import { getDefinitionId, getExtensionKey, getResourceType, getSubproduct, getProduct } from '../helpers';
12
+ import { getDefinitionId, getExtensionKey, getProduct, getResourceType, getSubproduct } from '../helpers';
13
13
  import { useSmartLinkContext } from '@atlaskit/link-provider';
14
14
 
15
15
  var applyCommonAttributes = function applyCommonAttributes(event, commonAttributes) {
@@ -120,6 +120,21 @@ export var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, dispatchA
120
120
  }), commonAttributes));
121
121
  },
122
122
 
123
+ /**
124
+ * This fires an event that represents when a user
125
+ * click a button.
126
+ * @param data A partial analytics event payload
127
+ */
128
+ buttonClickedEvent: function buttonClickedEvent(data) {
129
+ return dispatchAnalytics(applyCommonAttributes({
130
+ action: 'clicked',
131
+ actionSubject: 'button',
132
+ actionSubjectId: data.actionSubjectId,
133
+ attributes: _objectSpread(_objectSpread({}, context), data.attributes),
134
+ eventType: 'ui'
135
+ }, commonAttributes));
136
+ },
137
+
123
138
  /**
124
139
  * This fires an event that represents when a user clicks on a Smart Link.
125
140
  * @param id The unique ID for this Smart Link.
@@ -251,6 +266,20 @@ export var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, dispatchA
251
266
  }), commonAttributes));
252
267
  },
253
268
 
269
+ /**
270
+ * This fires an event that represents when a user close a modal.
271
+ * @param data A partial analytics event payload
272
+ */
273
+ modalClosedEvent: function modalClosedEvent(data) {
274
+ return dispatchAnalytics(applyCommonAttributes({
275
+ action: 'closed',
276
+ actionSubject: 'modal',
277
+ actionSubjectId: data.actionSubjectId,
278
+ attributes: _objectSpread(_objectSpread({}, context), data.attributes),
279
+ eventType: 'ui'
280
+ }, commonAttributes));
281
+ },
282
+
254
283
  /**
255
284
  * This fires an event that represents when a Smart Link was rendered successfully.
256
285
  * Note: this fires even if the Smart Link request errored out.
@@ -615,6 +644,20 @@ export var useSmartLinkAnalytics = function useSmartLinkAnalytics(url, dispatchA
615
644
  destinationSubproduct: destinationSubproduct,
616
645
  location: location
617
646
  })), commonAttributes));
647
+ },
648
+
649
+ /**
650
+ * This fires an event that represents when a user view a modal.
651
+ * @param data A partial analytics event payload
652
+ */
653
+ modalViewedEvent: function modalViewedEvent(data) {
654
+ return dispatchAnalytics(applyCommonAttributes({
655
+ action: 'viewed',
656
+ actionSubject: data.name,
657
+ attributes: _objectSpread(_objectSpread({}, context), data.attributes),
658
+ eventType: 'screen',
659
+ name: data.name
660
+ }, commonAttributes));
618
661
  }
619
662
  };
620
663
  }, [commonAttributes, dispatchAnalytics]);
@@ -12,7 +12,8 @@ export function useSmartLinkActions(_ref) {
12
12
  appearance = _ref.appearance,
13
13
  analyticsHandler = _ref.analyticsHandler,
14
14
  _ref$platform = _ref.platform,
15
- platform = _ref$platform === void 0 ? 'web' : _ref$platform;
15
+ platform = _ref$platform === void 0 ? 'web' : _ref$platform,
16
+ origin = _ref.origin;
16
17
  var id = useMemo(function () {
17
18
  return uuid();
18
19
  }, []);
@@ -42,7 +43,8 @@ export function useSmartLinkActions(_ref) {
42
43
  handleInvoke: function handleInvoke(opts) {
43
44
  return linkActions.invoke(opts, appearance);
44
45
  },
45
- handleAnalytics: analyticsHandler,
46
+ analytics: linkAnalytics,
47
+ origin: origin,
46
48
  extensionKey: getExtensionKey(linkState.details),
47
49
  source: appearance
48
50
  }, undefined, platform);
@@ -59,6 +61,6 @@ export function useSmartLinkActions(_ref) {
59
61
  };
60
62
  });
61
63
  setActions(cardActions);
62
- }, [linkState, linkActions, analyticsHandler, appearance, platform, embedModalSize]);
64
+ }, [linkState, linkActions, linkAnalytics, appearance, platform, embedModalSize, origin]);
63
65
  return actions;
64
66
  }
@@ -388,7 +388,7 @@ export var uiRenderFailedEvent = function uiRenderFailedEvent(_ref14) {
388
388
  actionSubject: 'smartLink',
389
389
  action: 'renderFailed',
390
390
  eventType: 'ui',
391
- attributes: {
391
+ attributes: _objectSpread(_objectSpread({}, context), {}, {
392
392
  error: error,
393
393
  errorInfo: errorInfo,
394
394
  display: display,
@@ -397,7 +397,7 @@ export var uiRenderFailedEvent = function uiRenderFailedEvent(_ref14) {
397
397
  destinationProduct: destinationProduct,
398
398
  destinationSubproduct: destinationSubproduct,
399
399
  location: location
400
- }
400
+ })
401
401
  };
402
402
  };
403
403
  export var uiHoverCardViewedEvent = function uiHoverCardViewedEvent(_ref15) {
@@ -121,6 +121,18 @@ export var mocks = {
121
121
  data: {
122
122
  status: 'CompletedStatus'
123
123
  }
124
+ },
125
+ analytics: {
126
+ status: 'resolved',
127
+ details: {
128
+ meta: {
129
+ definitionId: 'spaghetti-id',
130
+ key: 'spaghetti-key',
131
+ resourceType: 'spaghetti-resource',
132
+ subproduct: 'spaghetti-subproduct',
133
+ product: 'spaghetti-product'
134
+ }
135
+ }
124
136
  }
125
137
  };
126
138
  export var fakeResponse = function fakeResponse() {
@@ -232,4 +244,17 @@ export var waitFor = function waitFor() {
232
244
  return new Promise(function (res) {
233
245
  return setTimeout(res, time);
234
246
  });
247
+ };
248
+ export var mockAnalytics = {
249
+ ui: {
250
+ buttonClickedEvent: function buttonClickedEvent() {},
251
+ modalClosedEvent: function modalClosedEvent() {},
252
+ renderSuccessEvent: function renderSuccessEvent() {},
253
+ renderFailedEvent: function renderFailedEvent() {}
254
+ },
255
+ operational: {},
256
+ track: {},
257
+ screen: {
258
+ modalViewedEvent: function modalViewedEvent() {}
259
+ }
235
260
  };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "22.0.0",
3
+ "version": "22.1.0",
4
4
  "sideEffects": false
5
5
  }
@@ -12,7 +12,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
12
12
 
13
13
  import React from 'react';
14
14
  import ReactDOM from 'react-dom';
15
- import { IntlProvider, FormattedMessage } from 'react-intl-next';
15
+ import { FormattedMessage, IntlProvider } from 'react-intl-next';
16
16
  import { messages } from '../../../messages';
17
17
 
18
18
  /*
@@ -62,9 +62,9 @@ function _previewFunction() {
62
62
  ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
63
63
  locale: "en"
64
64
  }, /*#__PURE__*/React.createElement(Modal.default, _extends({}, rest, {
65
- onClose: function onClose() {
65
+ onClose: function onClose(context) {
66
66
  if (popupMountPoint) {
67
- _onClose();
67
+ _onClose(context);
68
68
 
69
69
  ReactDOM.unmountComponentAtNode(popupMountPoint);
70
70
  }
@@ -5,7 +5,6 @@ import { extractBlockProps } from '../../extractors/block';
5
5
  import { getEmptyJsonLd, getUnauthorizedJsonLd } from '../../utils/jsonld';
6
6
  import { extractRequestAccessContext } from '../../extractors/common/context';
7
7
  import { CardLinkView } from '../LinkView';
8
- export { default as PreviewAction } from './actions/PreviewAction';
9
8
  import { AuthorizeAction } from './actions/AuthorizeAction';
10
9
  import { ForbiddenAction } from './actions/ForbiddenAction';
11
10
  import { ResolvedView as BlockCardResolvedView } from './views/ResolvedView';
@@ -15,6 +14,7 @@ import { UnauthorizedView as BlockCardUnauthorisedView } from './views/Unauthori
15
14
  import { ForbiddenView as BlockCardForbiddenView } from './views/ForbiddenView';
16
15
  import { ErroredView as BlockCardErroredView } from './views/ErroredView';
17
16
  import { useFeatureFlag } from '@atlaskit/link-provider';
17
+ export { default as PreviewAction } from './actions/PreviewAction';
18
18
  export { ForbiddenAction, AuthorizeAction, BlockCardResolvedView, BlockCardResolvingView, BlockCardUnauthorisedView, BlockCardForbiddenView, BlockCardErroredView, BlockCardNotFoundView };
19
19
  export var BlockCard = function BlockCard(_ref) {
20
20
  var _details$meta, _forbiddenViewProps$c;
@@ -27,7 +27,6 @@ export var BlockCard = function BlockCard(_ref) {
27
27
  handleAuthorize = _ref.handleAuthorize,
28
28
  handleErrorRetry = _ref.handleErrorRetry,
29
29
  handleFrameClick = _ref.handleFrameClick,
30
- handleAnalytics = _ref.handleAnalytics,
31
30
  handleInvoke = _ref.handleInvoke,
32
31
  renderers = _ref.renderers,
33
32
  isSelected = _ref.isSelected,
@@ -35,7 +34,8 @@ export var BlockCard = function BlockCard(_ref) {
35
34
  onError = _ref.onError,
36
35
  testId = _ref.testId,
37
36
  showActions = _ref.showActions,
38
- platform = _ref.platform;
37
+ platform = _ref.platform,
38
+ analytics = _ref.analytics;
39
39
  // Actions do not have access to the react tree, so we need to obtain
40
40
  // feature flags here where we still can access SmartLinkContext context
41
41
  // and pass the flags down to the extractor. See PreviewAction.tsx for details.
@@ -46,8 +46,9 @@ export var BlockCard = function BlockCard(_ref) {
46
46
  var data = details && details.data || getEmptyJsonLd();
47
47
  var meta = details && details.meta;
48
48
  var extractorOpts = {
49
+ analytics: analytics,
50
+ origin: 'smartLinkCard',
49
51
  featureFlags: featureFlags,
50
- handleAnalytics: handleAnalytics,
51
52
  handleInvoke: handleInvoke,
52
53
  extensionKey: getExtensionKey(details)
53
54
  };
@@ -182,7 +182,7 @@ export function CardWithUrlContent(_ref) {
182
182
  handleErrorRetry: handleRetry,
183
183
  handleInvoke: handleInvoke,
184
184
  handleFrameClick: handleClickWrapper,
185
- handleAnalytics: dispatchAnalytics,
185
+ analytics: analytics,
186
186
  isSelected: isSelected,
187
187
  onResolve: onResolve,
188
188
  onError: onError,
@@ -200,7 +200,7 @@ export function CardWithUrlContent(_ref) {
200
200
  handleErrorRetry: handleRetry,
201
201
  handleFrameClick: handleClickWrapper,
202
202
  handleInvoke: handleInvoke,
203
- handleAnalytics: dispatchAnalytics,
203
+ analytics: analytics,
204
204
  isSelected: isSelected,
205
205
  isFrameVisible: isFrameVisible,
206
206
  platform: platform,
@@ -23,7 +23,7 @@ export var EmbedCard = /*#__PURE__*/React.forwardRef(function (_ref, iframeRef)
23
23
  handleAuthorize = _ref.handleAuthorize,
24
24
  handleErrorRetry = _ref.handleErrorRetry,
25
25
  handleFrameClick = _ref.handleFrameClick,
26
- handleAnalytics = _ref.handleAnalytics,
26
+ analytics = _ref.analytics,
27
27
  handleInvoke = _ref.handleInvoke,
28
28
  showActions = _ref.showActions,
29
29
  isSelected = _ref.isSelected,
@@ -77,7 +77,8 @@ export var EmbedCard = /*#__PURE__*/React.forwardRef(function (_ref, iframeRef)
77
77
  }
78
78
 
79
79
  var resolvedBlockViewProps = extractBlockProps(data, meta, {
80
- handleAnalytics: handleAnalytics,
80
+ analytics: analytics,
81
+ origin: 'smartLinkEmbed',
81
82
  handleInvoke: handleInvoke,
82
83
  extensionKey: getExtensionKey(details)
83
84
  });
@@ -0,0 +1,82 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import React, { useCallback } from 'react';
3
+ import { EmbedModalSize } from '../../types';
4
+
5
+ var getResizeFrom = function getResizeFrom(size) {
6
+ return size === EmbedModalSize.Small ? EmbedModalSize.Large : EmbedModalSize.Small;
7
+ };
8
+
9
+ var withAnalytics = function withAnalytics(Component) {
10
+ return function (props) {
11
+ var analytics = props.analytics,
12
+ onClose = props.onClose,
13
+ onOpen = props.onOpen,
14
+ onOpenFailed = props.onOpenFailed,
15
+ onResize = props.onResize,
16
+ origin = props.origin;
17
+ var handleOnOpen = useCallback(function (context) {
18
+ analytics.screen.modalViewedEvent({
19
+ name: 'embedPreviewModal',
20
+ attributes: {
21
+ origin: origin,
22
+ size: context.size
23
+ }
24
+ });
25
+ analytics.ui.renderSuccessEvent({
26
+ status: 'resolved',
27
+ display: 'preview'
28
+ });
29
+
30
+ if (onOpen) {
31
+ onOpen(context);
32
+ }
33
+ }, [analytics.screen, analytics.ui, onOpen, origin]);
34
+ var handleOnOpenFailed = useCallback(function (error, errorInfo) {
35
+ analytics.ui.renderFailedEvent({
36
+ display: 'preview',
37
+ error: error,
38
+ errorInfo: errorInfo
39
+ });
40
+
41
+ if (onOpenFailed) {
42
+ onOpenFailed(error, errorInfo);
43
+ }
44
+ }, [analytics.ui, onOpenFailed]);
45
+ var handleOnClose = useCallback(function (context) {
46
+ analytics.ui.modalClosedEvent({
47
+ actionSubjectId: 'embedPreview',
48
+ attributes: {
49
+ origin: origin,
50
+ previewTime: context.duration,
51
+ size: context.size
52
+ }
53
+ });
54
+
55
+ if (onClose) {
56
+ onClose(context);
57
+ }
58
+ }, [analytics.ui, onClose, origin]);
59
+ var handleOnResize = useCallback(function (context) {
60
+ analytics.ui.buttonClickedEvent({
61
+ actionSubjectId: 'embedPreviewResize',
62
+ attributes: {
63
+ newSize: context.size,
64
+ origin: origin,
65
+ previousSize: getResizeFrom(context.size)
66
+ }
67
+ });
68
+
69
+ if (onResize) {
70
+ onResize(context);
71
+ }
72
+ }, [analytics.ui, onResize, origin]);
73
+ return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
74
+ onClose: handleOnClose,
75
+ onOpen: handleOnOpen,
76
+ onOpenFailed: handleOnOpenFailed,
77
+ onResize: handleOnResize
78
+ }));
79
+ };
80
+ };
81
+
82
+ export default withAnalytics;
@@ -1,27 +1,22 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React from 'react';
3
3
  import Modal from '../../../common/Modal';
4
- import { MAX_MODAL_SIZE, MIN_MODAL_SIZE } from '../../constants';
4
+ import { EmbedModalSize } from '../../types';
5
5
 
6
6
  var withSizeExperiment = function withSizeExperiment(Component) {
7
7
  return function (props) {
8
8
  var _props$featureFlags = props.featureFlags,
9
- featureFlags = _props$featureFlags === void 0 ? {} : _props$featureFlags,
10
- _props$closeLabel = props.closeLabel,
11
- closeLabel = _props$closeLabel === void 0 ? 'Close Preview' : _props$closeLabel;
12
- var embedModalSize = featureFlags.embedModalSize; // Experiment
9
+ featureFlags = _props$featureFlags === void 0 ? {} : _props$featureFlags;
10
+ var size = featureFlags.embedModalSize; // Experiment
13
11
 
14
- if (embedModalSize === 'large' || embedModalSize === 'small') {
15
- var size = embedModalSize === 'large' ? MAX_MODAL_SIZE : MIN_MODAL_SIZE;
12
+ if (size === EmbedModalSize.Large || size === EmbedModalSize.Small) {
16
13
  return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
17
14
  size: size
18
15
  }));
19
16
  } // Control
20
17
 
21
18
 
22
- return /*#__PURE__*/React.createElement(Modal, _extends({}, props, {
23
- closeLabel: closeLabel
24
- }));
19
+ return /*#__PURE__*/React.createElement(Modal, props);
25
20
  };
26
21
  };
27
22