@atlaskit/smart-card 25.7.2 → 25.8.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 25.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`44b76af1d5f`](https://bitbucket.org/atlassian/atlassian-frontend/commits/44b76af1d5f) - Include additional attributes (`urlHash`, `display`, `id`) and resolved attributes for `link clicked` analytics events
8
+
9
+ ## 25.7.3
10
+
11
+ ### Patch Changes
12
+
13
+ - [`878dc4e5239`](https://bitbucket.org/atlassian/atlassian-frontend/commits/878dc4e5239) - Enable lozenge action by using showServerActions opt-in OR using feature flag useLozengeAction for experiment
14
+
3
15
  ## 25.7.2
4
16
 
5
17
  ### Patch Changes
@@ -58,7 +58,7 @@ var extractFlexibleUiContext = function extractFlexibleUiContext() {
58
58
  snippet: (0, _primitives.extractSummary)(data) || undefined,
59
59
  // Explicitly set here to remove an empty string
60
60
  sourceBranch: (0, _utils.extractSourceBranch)(data),
61
- state: (0, _extractState.default)(response, showLozengeAction && showServerActions, id),
61
+ state: (0, _extractState.default)(response, showLozengeAction || showServerActions, id),
62
62
  subscriberCount: (0, _utils.extractSubscriberCount)(data),
63
63
  targetBranch: (0, _utils.extractTargetBranch)(data),
64
64
  title: (0, _extractors.extractTitle)(data) || url,
@@ -25,13 +25,20 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
25
25
  connections = _useSmartLinkContext.connections;
26
26
  var getState = store.getState,
27
27
  dispatch = store.dispatch;
28
- var _ref = getState()[url] || {
29
- status: _constants.SmartLinkStatus.Pending,
30
- details: undefined
31
- },
32
- details = _ref.details,
33
- status = _ref.status,
34
- metadataStatus = _ref.metadataStatus;
28
+ var getSmartLinkState = (0, _react.useCallback)(function () {
29
+ var _getState$url;
30
+ var _ref = (_getState$url = getState()[url]) !== null && _getState$url !== void 0 ? _getState$url : {
31
+ status: _constants.SmartLinkStatus.Pending
32
+ },
33
+ details = _ref.details,
34
+ status = _ref.status,
35
+ metadataStatus = _ref.metadataStatus;
36
+ return {
37
+ details: details,
38
+ status: status,
39
+ metadataStatus: metadataStatus
40
+ };
41
+ }, [getState, url]);
35
42
  var setMetadataStatus = (0, _react.useCallback)(function (metadataStatus) {
36
43
  dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_UPDATE_METADATA_STATUS, {
37
44
  url: url
@@ -58,6 +65,8 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
58
65
  }, _callee);
59
66
  })), [id, resolveUrl, url]);
60
67
  var register = (0, _react.useCallback)(function () {
68
+ var _getSmartLinkState = getSmartLinkState(),
69
+ details = _getSmartLinkState.details;
61
70
  if (!details) {
62
71
  dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVING, {
63
72
  url: url
@@ -65,8 +74,10 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
65
74
  setMetadataStatus('pending');
66
75
  }
67
76
  return resolve();
68
- }, [details, resolve, dispatch, url, setMetadataStatus]);
77
+ }, [getSmartLinkState, resolve, dispatch, url, setMetadataStatus]);
69
78
  var reload = (0, _react.useCallback)(function () {
79
+ var _getSmartLinkState2 = getSmartLinkState(),
80
+ details = _getSmartLinkState2.details;
70
81
  var definitionId = (0, _helpers.getDefinitionId)(details);
71
82
  if (definitionId) {
72
83
  (0, _helpers.getByDefinitionId)(definitionId, getState()).map(function (url) {
@@ -75,15 +86,20 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
75
86
  } else {
76
87
  resolve(url, true);
77
88
  }
78
- }, [details, url, getState, resolve]);
89
+ }, [getSmartLinkState, url, getState, resolve]);
79
90
  var loadMetadata = (0, _react.useCallback)(function () {
91
+ var _getSmartLinkState3 = getSmartLinkState(),
92
+ metadataStatus = _getSmartLinkState3.metadataStatus;
80
93
  //metadataStatus will be undefined for SSR links only
81
94
  if (metadataStatus === undefined) {
82
95
  setMetadataStatus('pending');
83
96
  return resolve(url, false, true);
84
97
  }
85
- }, [metadataStatus, resolve, setMetadataStatus, url]);
98
+ }, [getSmartLinkState, resolve, setMetadataStatus, url]);
86
99
  var authorize = (0, _react.useCallback)(function (appearance) {
100
+ var _getSmartLinkState4 = getSmartLinkState(),
101
+ details = _getSmartLinkState4.details,
102
+ status = _getSmartLinkState4.status;
87
103
  var definitionId = (0, _helpers.getDefinitionId)(details);
88
104
  var extensionKey = (0, _helpers.getExtensionKey)(details);
89
105
  var services = (0, _helpers.getServices)(details);
@@ -135,7 +151,7 @@ var useSmartCardActions = function useSmartCardActions(id, url, analytics) {
135
151
  reload();
136
152
  });
137
153
  }
138
- }, [analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload, details, status]);
154
+ }, [getSmartLinkState, analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload]);
139
155
  var invoke = (0, _react.useCallback)( /*#__PURE__*/function () {
140
156
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(opts, appearance) {
141
157
  var key, action, source, markName, response;
@@ -8,6 +8,7 @@ Object.defineProperty(exports, "__esModule", {
8
8
  exports.default = void 0;
9
9
  var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
10
10
  var _react = require("react");
11
+ var _reactDom = require("react-dom");
11
12
  var _analytics = require("../../analytics");
12
13
  var _helpers = require("../../helpers");
13
14
  var _linkingCommon = require("@atlaskit/linking-common");
@@ -106,18 +107,26 @@ var useResolve = function useResolve() {
106
107
  return;
107
108
  }
108
109
 
109
- //if a link resolves normally, metadata will also always be resolved
110
- setMetadataStatus(resourceUrl, 'resolved');
111
- // Dispatch Analytics and resolved card action - including unauthorized states.
112
- if (isReloading) {
113
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RELOADING, {
114
- url: resourceUrl
115
- }, response));
116
- } else {
117
- dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
118
- url: resourceUrl
119
- }, response, undefined, undefined, isMetadataRequest));
120
- }
110
+ /**
111
+ * Using unstable_batchedUpdates because this store update happens async and trigers a rerender
112
+ * more info:
113
+ * https://github.com/facebook/react/blob/v18.2.0/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L113
114
+ * https://react-redux.js.org/api/batch
115
+ */
116
+ (0, _reactDom.unstable_batchedUpdates)(function () {
117
+ //if a link resolves normally, metadata will also always be resolved
118
+ setMetadataStatus(resourceUrl, 'resolved');
119
+ // Dispatch Analytics and resolved card action - including unauthorized states.
120
+ if (isReloading) {
121
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RELOADING, {
122
+ url: resourceUrl
123
+ }, response));
124
+ } else {
125
+ dispatch((0, _linkingCommon.cardAction)(_linkingCommon.ACTION_RESOLVED, {
126
+ url: resourceUrl
127
+ }, response, undefined, undefined, isMetadataRequest));
128
+ }
129
+ });
121
130
  }, [dispatch, handleResolvedLinkError, hasAuthFlowSupported, setMetadataStatus]);
122
131
  return (0, _react.useCallback)( /*#__PURE__*/function () {
123
132
  var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
@@ -0,0 +1,47 @@
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.SmartLinkAnalyticsContext = void 0;
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _analyticsNext = require("@atlaskit/analytics-next");
12
+ var _resolvedAttributes = require("@atlaskit/link-analytics/resolved-attributes");
13
+ var _flexible = require("../flexible");
14
+ var _constants = require("../../constants");
15
+ var _store = require("../../state/store");
16
+ 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
+ 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
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
+ 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) { (0, _defineProperty2.default)(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; }
20
+ var SmartLinkAnalyticsContext = function SmartLinkAnalyticsContext(_ref) {
21
+ var children = _ref.children,
22
+ url = _ref.url,
23
+ appearance = _ref.appearance,
24
+ id = _ref.id;
25
+ var _useSmartLinkState = (0, _store.useSmartCardState)(url),
26
+ details = _useSmartLinkState.details,
27
+ status = _useSmartLinkState.status;
28
+ var resolvedAttributes = (0, _resolvedAttributes.getResolvedAttributes)({
29
+ url: url
30
+ }, details, status);
31
+ var _getUrlAttributes = (0, _resolvedAttributes.getUrlAttributes)(url),
32
+ urlHash = _getUrlAttributes.urlHash;
33
+ var isFlexibleUi = (0, _react.useMemo)(function () {
34
+ return (0, _flexible.isFlexibleUiCard)(children);
35
+ }, [children]);
36
+ var display = isFlexibleUi ? _constants.CardDisplay.Flexible : appearance;
37
+ return /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsContext, {
38
+ data: {
39
+ attributes: _objectSpread(_objectSpread({}, resolvedAttributes), {}, {
40
+ urlHash: urlHash,
41
+ display: display,
42
+ id: id
43
+ })
44
+ }
45
+ }, children);
46
+ };
47
+ exports.SmartLinkAnalyticsContext = SmartLinkAnalyticsContext;
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "25.7.2",
3
+ "version": "25.8.0",
4
4
  "sideEffects": false
5
5
  }
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.CardWithUrlContent = CardWithUrlContent;
8
+ exports.CardWithUrlContent = void 0;
9
9
  var _react = _interopRequireWildcard(require("react"));
10
10
  var _analyticsNext = require("@atlaskit/analytics-next");
11
11
  var _linkProvider = require("@atlaskit/link-provider");
@@ -20,9 +20,10 @@ var _flexible = require("../../utils/flexible");
20
20
  var _FlexibleCard = _interopRequireDefault(require("../FlexibleCard"));
21
21
  var _constants = require("../../constants");
22
22
  var _click = require("../../utils/analytics/click");
23
+ var _SmartLinkAnalyticsContext = require("../../utils/analytics/SmartLinkAnalyticsContext");
23
24
  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); }
24
25
  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; }
25
- function CardWithUrlContent(_ref) {
26
+ function Component(_ref) {
26
27
  var id = _ref.id,
27
28
  url = _ref.url,
28
29
  isSelected = _ref.isSelected,
@@ -267,4 +268,12 @@ function CardWithUrlContent(_ref) {
267
268
  onIframeFocus: onIframeFocus
268
269
  });
269
270
  }
270
- }
271
+ }
272
+ var CardWithUrlContent = function CardWithUrlContent(props) {
273
+ return /*#__PURE__*/_react.default.createElement(_SmartLinkAnalyticsContext.SmartLinkAnalyticsContext, {
274
+ url: props.url,
275
+ appearance: props.appearance,
276
+ id: props.id
277
+ }, /*#__PURE__*/_react.default.createElement(Component, props));
278
+ };
279
+ exports.CardWithUrlContent = CardWithUrlContent;
@@ -17,6 +17,7 @@ var _store = require("../../../state/store");
17
17
  var _HoverCardContent = _interopRequireDefault(require("../components/HoverCardContent"));
18
18
  var _styled = require("../styled");
19
19
  var _constants = require("../../../constants");
20
+ var _SmartLinkAnalyticsContext = require("../../../utils/analytics/SmartLinkAnalyticsContext");
20
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); }
21
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; }
22
23
  /** @jsx jsx */
@@ -24,6 +25,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
24
25
  var HoverCardComponent = function HoverCardComponent(_ref) {
25
26
  var children = _ref.children,
26
27
  url = _ref.url,
28
+ id = _ref.id,
27
29
  analyticsHandler = _ref.analyticsHandler,
28
30
  analytics = _ref.analytics,
29
31
  _ref$canOpen = _ref.canOpen,
@@ -133,7 +135,11 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
133
135
  }, [closeOnChildClick, hideCard]);
134
136
  var content = (0, _react2.useCallback)(function (_ref2) {
135
137
  var update = _ref2.update;
136
- return (0, _react.jsx)(_HoverCardContent.default, {
138
+ return (0, _react.jsx)(_SmartLinkAnalyticsContext.SmartLinkAnalyticsContext, {
139
+ url: url,
140
+ appearance: _constants.CardDisplay.HoverCardPreview,
141
+ id: id
142
+ }, (0, _react.jsx)(_HoverCardContent.default, {
137
143
  onMouseEnter: initShowCard,
138
144
  onMouseLeave: initHideCard,
139
145
  analytics: analytics,
@@ -143,9 +149,10 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
143
149
  onResolve: update,
144
150
  renderers: renderers,
145
151
  showServerActions: showServerActions,
146
- url: url
147
- });
148
- }, [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url]);
152
+ url: url,
153
+ id: id
154
+ }));
155
+ }, [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url, id]);
149
156
  var trigger = (0, _react2.useCallback)(function (triggerProps) {
150
157
  return (0, _react.jsx)("span", {
151
158
  ref: parentSpan
@@ -51,7 +51,7 @@ const extractFlexibleUiContext = ({
51
51
  snippet: extractSummary(data) || undefined,
52
52
  // Explicitly set here to remove an empty string
53
53
  sourceBranch: extractSourceBranch(data),
54
- state: extractState(response, showLozengeAction && showServerActions, id),
54
+ state: extractState(response, showLozengeAction || showServerActions, id),
55
55
  subscriberCount: extractSubscriberCount(data),
56
56
  targetBranch: extractTargetBranch(data),
57
57
  title: extractTitle(data) || url,
@@ -16,14 +16,21 @@ export const useSmartCardActions = (id, url, analytics) => {
16
16
  getState,
17
17
  dispatch
18
18
  } = store;
19
- const {
20
- details,
21
- status,
22
- metadataStatus
23
- } = getState()[url] || {
24
- status: SmartLinkStatus.Pending,
25
- details: undefined
26
- };
19
+ const getSmartLinkState = useCallback(() => {
20
+ var _getState$url;
21
+ const {
22
+ details,
23
+ status,
24
+ metadataStatus
25
+ } = (_getState$url = getState()[url]) !== null && _getState$url !== void 0 ? _getState$url : {
26
+ status: SmartLinkStatus.Pending
27
+ };
28
+ return {
29
+ details,
30
+ status,
31
+ metadataStatus
32
+ };
33
+ }, [getState, url]);
27
34
  const setMetadataStatus = useCallback(metadataStatus => {
28
35
  dispatch(cardAction(ACTION_UPDATE_METADATA_STATUS, {
29
36
  url
@@ -31,6 +38,9 @@ export const useSmartCardActions = (id, url, analytics) => {
31
38
  }, [dispatch, url]);
32
39
  const resolve = useCallback(async (resourceUrl = url, isReloading = false, isMetadataRequest = false) => resolveUrl(resourceUrl, isReloading, isMetadataRequest, id), [id, resolveUrl, url]);
33
40
  const register = useCallback(() => {
41
+ const {
42
+ details
43
+ } = getSmartLinkState();
34
44
  if (!details) {
35
45
  dispatch(cardAction(ACTION_RESOLVING, {
36
46
  url
@@ -38,23 +48,33 @@ export const useSmartCardActions = (id, url, analytics) => {
38
48
  setMetadataStatus('pending');
39
49
  }
40
50
  return resolve();
41
- }, [details, resolve, dispatch, url, setMetadataStatus]);
51
+ }, [getSmartLinkState, resolve, dispatch, url, setMetadataStatus]);
42
52
  const reload = useCallback(() => {
53
+ const {
54
+ details
55
+ } = getSmartLinkState();
43
56
  const definitionId = getDefinitionId(details);
44
57
  if (definitionId) {
45
58
  getByDefinitionId(definitionId, getState()).map(url => resolve(url, true));
46
59
  } else {
47
60
  resolve(url, true);
48
61
  }
49
- }, [details, url, getState, resolve]);
62
+ }, [getSmartLinkState, url, getState, resolve]);
50
63
  const loadMetadata = useCallback(() => {
64
+ const {
65
+ metadataStatus
66
+ } = getSmartLinkState();
51
67
  //metadataStatus will be undefined for SSR links only
52
68
  if (metadataStatus === undefined) {
53
69
  setMetadataStatus('pending');
54
70
  return resolve(url, false, true);
55
71
  }
56
- }, [metadataStatus, resolve, setMetadataStatus, url]);
72
+ }, [getSmartLinkState, resolve, setMetadataStatus, url]);
57
73
  const authorize = useCallback(appearance => {
74
+ const {
75
+ details,
76
+ status
77
+ } = getSmartLinkState();
58
78
  const definitionId = getDefinitionId(details);
59
79
  const extensionKey = getExtensionKey(details);
60
80
  const services = getServices(details);
@@ -106,7 +126,7 @@ export const useSmartCardActions = (id, url, analytics) => {
106
126
  reload();
107
127
  });
108
128
  }
109
- }, [analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload, details, status]);
129
+ }, [getSmartLinkState, analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload]);
110
130
  const invoke = useCallback(async (opts, appearance) => {
111
131
  const {
112
132
  key,
@@ -1,4 +1,5 @@
1
1
  import { useCallback } from 'react';
2
+ import { unstable_batchedUpdates } from 'react-dom';
2
3
  import { addMetadataToExperience } from '../../analytics';
3
4
  import { getStatus } from '../../helpers';
4
5
  import { ACTION_ERROR, ACTION_ERROR_FALLBACK, ACTION_RELOADING, ACTION_RESOLVED, ACTION_UPDATE_METADATA_STATUS, APIError, cardAction } from '@atlaskit/linking-common';
@@ -98,18 +99,26 @@ const useResolve = () => {
98
99
  return;
99
100
  }
100
101
 
101
- //if a link resolves normally, metadata will also always be resolved
102
- setMetadataStatus(resourceUrl, 'resolved');
103
- // Dispatch Analytics and resolved card action - including unauthorized states.
104
- if (isReloading) {
105
- dispatch(cardAction(ACTION_RELOADING, {
106
- url: resourceUrl
107
- }, response));
108
- } else {
109
- dispatch(cardAction(ACTION_RESOLVED, {
110
- url: resourceUrl
111
- }, response, undefined, undefined, isMetadataRequest));
112
- }
102
+ /**
103
+ * Using unstable_batchedUpdates because this store update happens async and trigers a rerender
104
+ * more info:
105
+ * https://github.com/facebook/react/blob/v18.2.0/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L113
106
+ * https://react-redux.js.org/api/batch
107
+ */
108
+ unstable_batchedUpdates(() => {
109
+ //if a link resolves normally, metadata will also always be resolved
110
+ setMetadataStatus(resourceUrl, 'resolved');
111
+ // Dispatch Analytics and resolved card action - including unauthorized states.
112
+ if (isReloading) {
113
+ dispatch(cardAction(ACTION_RELOADING, {
114
+ url: resourceUrl
115
+ }, response));
116
+ } else {
117
+ dispatch(cardAction(ACTION_RESOLVED, {
118
+ url: resourceUrl
119
+ }, response, undefined, undefined, isMetadataRequest));
120
+ }
121
+ });
113
122
  }, [dispatch, handleResolvedLinkError, hasAuthFlowSupported, setMetadataStatus]);
114
123
  return useCallback(async (url, isReloading = false, isMetadataRequest = false, id = '') => {
115
124
  const {
@@ -0,0 +1,35 @@
1
+ import React, { useMemo } from 'react';
2
+ import { AnalyticsContext } from '@atlaskit/analytics-next';
3
+ import { getResolvedAttributes, getUrlAttributes } from '@atlaskit/link-analytics/resolved-attributes';
4
+ import { isFlexibleUiCard } from '../flexible';
5
+ import { CardDisplay } from '../../constants';
6
+ import { useSmartCardState as useSmartLinkState } from '../../state/store';
7
+ export const SmartLinkAnalyticsContext = ({
8
+ children,
9
+ url,
10
+ appearance,
11
+ id
12
+ }) => {
13
+ const {
14
+ details,
15
+ status
16
+ } = useSmartLinkState(url);
17
+ const resolvedAttributes = getResolvedAttributes({
18
+ url
19
+ }, details, status);
20
+ const {
21
+ urlHash
22
+ } = getUrlAttributes(url);
23
+ const isFlexibleUi = useMemo(() => isFlexibleUiCard(children), [children]);
24
+ const display = isFlexibleUi ? CardDisplay.Flexible : appearance;
25
+ return /*#__PURE__*/React.createElement(AnalyticsContext, {
26
+ data: {
27
+ attributes: {
28
+ ...resolvedAttributes,
29
+ urlHash,
30
+ display,
31
+ id
32
+ }
33
+ }
34
+ }, children);
35
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "25.7.2",
3
+ "version": "25.8.0",
4
4
  "sideEffects": false
5
5
  }
@@ -12,7 +12,8 @@ import { isFlexibleUiCard } from '../../utils/flexible';
12
12
  import FlexibleCard from '../FlexibleCard';
13
13
  import { CardDisplay } from '../../constants';
14
14
  import { fireLinkClickedEvent } from '../../utils/analytics/click';
15
- export function CardWithUrlContent({
15
+ import { SmartLinkAnalyticsContext } from '../../utils/analytics/SmartLinkAnalyticsContext';
16
+ function Component({
16
17
  id,
17
18
  url,
18
19
  isSelected,
@@ -254,4 +255,9 @@ export function CardWithUrlContent({
254
255
  onIframeFocus: onIframeFocus
255
256
  });
256
257
  }
257
- }
258
+ }
259
+ export const CardWithUrlContent = props => /*#__PURE__*/React.createElement(SmartLinkAnalyticsContext, {
260
+ url: props.url,
261
+ appearance: props.appearance,
262
+ id: props.id
263
+ }, /*#__PURE__*/React.createElement(Component, props));
@@ -9,9 +9,11 @@ import { useSmartCardState as useLinkState } from '../../../state/store';
9
9
  import HoverCardContent from '../components/HoverCardContent';
10
10
  import { CARD_GAP_PX, HOVER_CARD_Z_INDEX } from '../styled';
11
11
  import { CardDisplay } from '../../../constants';
12
+ import { SmartLinkAnalyticsContext } from '../../../utils/analytics/SmartLinkAnalyticsContext';
12
13
  export const HoverCardComponent = ({
13
14
  children,
14
15
  url,
16
+ id,
15
17
  analyticsHandler,
16
18
  analytics,
17
19
  canOpen = true,
@@ -112,7 +114,11 @@ export const HoverCardComponent = ({
112
114
  }, [closeOnChildClick, hideCard]);
113
115
  const content = useCallback(({
114
116
  update
115
- }) => jsx(HoverCardContent, {
117
+ }) => jsx(SmartLinkAnalyticsContext, {
118
+ url: url,
119
+ appearance: CardDisplay.HoverCardPreview,
120
+ id: id
121
+ }, jsx(HoverCardContent, {
116
122
  onMouseEnter: initShowCard,
117
123
  onMouseLeave: initHideCard,
118
124
  analytics: analytics,
@@ -122,8 +128,9 @@ export const HoverCardComponent = ({
122
128
  onResolve: update,
123
129
  renderers: renderers,
124
130
  showServerActions: showServerActions,
125
- url: url
126
- }), [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url]);
131
+ url: url,
132
+ id: id
133
+ })), [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url, id]);
127
134
  const trigger = useCallback(triggerProps => jsx("span", {
128
135
  ref: parentSpan
129
136
  }, jsx("span", _extends({}, triggerProps, {
@@ -51,7 +51,7 @@ var extractFlexibleUiContext = function extractFlexibleUiContext() {
51
51
  snippet: extractSummary(data) || undefined,
52
52
  // Explicitly set here to remove an empty string
53
53
  sourceBranch: extractSourceBranch(data),
54
- state: extractState(response, showLozengeAction && showServerActions, id),
54
+ state: extractState(response, showLozengeAction || showServerActions, id),
55
55
  subscriberCount: extractSubscriberCount(data),
56
56
  targetBranch: extractTargetBranch(data),
57
57
  title: extractTitle(data) || url,
@@ -16,13 +16,20 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
16
16
  connections = _useSmartLinkContext.connections;
17
17
  var getState = store.getState,
18
18
  dispatch = store.dispatch;
19
- var _ref = getState()[url] || {
20
- status: SmartLinkStatus.Pending,
21
- details: undefined
22
- },
23
- details = _ref.details,
24
- status = _ref.status,
25
- metadataStatus = _ref.metadataStatus;
19
+ var getSmartLinkState = useCallback(function () {
20
+ var _getState$url;
21
+ var _ref = (_getState$url = getState()[url]) !== null && _getState$url !== void 0 ? _getState$url : {
22
+ status: SmartLinkStatus.Pending
23
+ },
24
+ details = _ref.details,
25
+ status = _ref.status,
26
+ metadataStatus = _ref.metadataStatus;
27
+ return {
28
+ details: details,
29
+ status: status,
30
+ metadataStatus: metadataStatus
31
+ };
32
+ }, [getState, url]);
26
33
  var setMetadataStatus = useCallback(function (metadataStatus) {
27
34
  dispatch(cardAction(ACTION_UPDATE_METADATA_STATUS, {
28
35
  url: url
@@ -49,6 +56,8 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
49
56
  }, _callee);
50
57
  })), [id, resolveUrl, url]);
51
58
  var register = useCallback(function () {
59
+ var _getSmartLinkState = getSmartLinkState(),
60
+ details = _getSmartLinkState.details;
52
61
  if (!details) {
53
62
  dispatch(cardAction(ACTION_RESOLVING, {
54
63
  url: url
@@ -56,8 +65,10 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
56
65
  setMetadataStatus('pending');
57
66
  }
58
67
  return resolve();
59
- }, [details, resolve, dispatch, url, setMetadataStatus]);
68
+ }, [getSmartLinkState, resolve, dispatch, url, setMetadataStatus]);
60
69
  var reload = useCallback(function () {
70
+ var _getSmartLinkState2 = getSmartLinkState(),
71
+ details = _getSmartLinkState2.details;
61
72
  var definitionId = getDefinitionId(details);
62
73
  if (definitionId) {
63
74
  getByDefinitionId(definitionId, getState()).map(function (url) {
@@ -66,15 +77,20 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
66
77
  } else {
67
78
  resolve(url, true);
68
79
  }
69
- }, [details, url, getState, resolve]);
80
+ }, [getSmartLinkState, url, getState, resolve]);
70
81
  var loadMetadata = useCallback(function () {
82
+ var _getSmartLinkState3 = getSmartLinkState(),
83
+ metadataStatus = _getSmartLinkState3.metadataStatus;
71
84
  //metadataStatus will be undefined for SSR links only
72
85
  if (metadataStatus === undefined) {
73
86
  setMetadataStatus('pending');
74
87
  return resolve(url, false, true);
75
88
  }
76
- }, [metadataStatus, resolve, setMetadataStatus, url]);
89
+ }, [getSmartLinkState, resolve, setMetadataStatus, url]);
77
90
  var authorize = useCallback(function (appearance) {
91
+ var _getSmartLinkState4 = getSmartLinkState(),
92
+ details = _getSmartLinkState4.details,
93
+ status = _getSmartLinkState4.status;
78
94
  var definitionId = getDefinitionId(details);
79
95
  var extensionKey = getExtensionKey(details);
80
96
  var services = getServices(details);
@@ -126,7 +142,7 @@ export var useSmartCardActions = function useSmartCardActions(id, url, analytics
126
142
  reload();
127
143
  });
128
144
  }
129
- }, [analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload, details, status]);
145
+ }, [getSmartLinkState, analytics.ui, analytics.screen, analytics.track, analytics.operational, id, reload]);
130
146
  var invoke = useCallback( /*#__PURE__*/function () {
131
147
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(opts, appearance) {
132
148
  var key, action, source, markName, response;
@@ -2,6 +2,7 @@ import _typeof from "@babel/runtime/helpers/typeof";
2
2
  import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
3
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
4
4
  import { useCallback } from 'react';
5
+ import { unstable_batchedUpdates } from 'react-dom';
5
6
  import { addMetadataToExperience } from '../../analytics';
6
7
  import { getStatus } from '../../helpers';
7
8
  import { ACTION_ERROR, ACTION_ERROR_FALLBACK, ACTION_RELOADING, ACTION_RESOLVED, ACTION_UPDATE_METADATA_STATUS, APIError, cardAction } from '@atlaskit/linking-common';
@@ -99,18 +100,26 @@ var useResolve = function useResolve() {
99
100
  return;
100
101
  }
101
102
 
102
- //if a link resolves normally, metadata will also always be resolved
103
- setMetadataStatus(resourceUrl, 'resolved');
104
- // Dispatch Analytics and resolved card action - including unauthorized states.
105
- if (isReloading) {
106
- dispatch(cardAction(ACTION_RELOADING, {
107
- url: resourceUrl
108
- }, response));
109
- } else {
110
- dispatch(cardAction(ACTION_RESOLVED, {
111
- url: resourceUrl
112
- }, response, undefined, undefined, isMetadataRequest));
113
- }
103
+ /**
104
+ * Using unstable_batchedUpdates because this store update happens async and trigers a rerender
105
+ * more info:
106
+ * https://github.com/facebook/react/blob/v18.2.0/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L113
107
+ * https://react-redux.js.org/api/batch
108
+ */
109
+ unstable_batchedUpdates(function () {
110
+ //if a link resolves normally, metadata will also always be resolved
111
+ setMetadataStatus(resourceUrl, 'resolved');
112
+ // Dispatch Analytics and resolved card action - including unauthorized states.
113
+ if (isReloading) {
114
+ dispatch(cardAction(ACTION_RELOADING, {
115
+ url: resourceUrl
116
+ }, response));
117
+ } else {
118
+ dispatch(cardAction(ACTION_RESOLVED, {
119
+ url: resourceUrl
120
+ }, response, undefined, undefined, isMetadataRequest));
121
+ }
122
+ });
114
123
  }, [dispatch, handleResolvedLinkError, hasAuthFlowSupported, setMetadataStatus]);
115
124
  return useCallback( /*#__PURE__*/function () {
116
125
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
@@ -0,0 +1,36 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ 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; }
4
+ import React, { useMemo } from 'react';
5
+ import { AnalyticsContext } from '@atlaskit/analytics-next';
6
+ import { getResolvedAttributes, getUrlAttributes } from '@atlaskit/link-analytics/resolved-attributes';
7
+ import { isFlexibleUiCard } from '../flexible';
8
+ import { CardDisplay } from '../../constants';
9
+ import { useSmartCardState as useSmartLinkState } from '../../state/store';
10
+ export var SmartLinkAnalyticsContext = function SmartLinkAnalyticsContext(_ref) {
11
+ var children = _ref.children,
12
+ url = _ref.url,
13
+ appearance = _ref.appearance,
14
+ id = _ref.id;
15
+ var _useSmartLinkState = useSmartLinkState(url),
16
+ details = _useSmartLinkState.details,
17
+ status = _useSmartLinkState.status;
18
+ var resolvedAttributes = getResolvedAttributes({
19
+ url: url
20
+ }, details, status);
21
+ var _getUrlAttributes = getUrlAttributes(url),
22
+ urlHash = _getUrlAttributes.urlHash;
23
+ var isFlexibleUi = useMemo(function () {
24
+ return isFlexibleUiCard(children);
25
+ }, [children]);
26
+ var display = isFlexibleUi ? CardDisplay.Flexible : appearance;
27
+ return /*#__PURE__*/React.createElement(AnalyticsContext, {
28
+ data: {
29
+ attributes: _objectSpread(_objectSpread({}, resolvedAttributes), {}, {
30
+ urlHash: urlHash,
31
+ display: display,
32
+ id: id
33
+ })
34
+ }
35
+ }, children);
36
+ };
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "25.7.2",
3
+ "version": "25.8.0",
4
4
  "sideEffects": false
5
5
  }
@@ -12,7 +12,8 @@ import { isFlexibleUiCard } from '../../utils/flexible';
12
12
  import FlexibleCard from '../FlexibleCard';
13
13
  import { CardDisplay } from '../../constants';
14
14
  import { fireLinkClickedEvent } from '../../utils/analytics/click';
15
- export function CardWithUrlContent(_ref) {
15
+ import { SmartLinkAnalyticsContext } from '../../utils/analytics/SmartLinkAnalyticsContext';
16
+ function Component(_ref) {
16
17
  var id = _ref.id,
17
18
  url = _ref.url,
18
19
  isSelected = _ref.isSelected,
@@ -257,4 +258,11 @@ export function CardWithUrlContent(_ref) {
257
258
  onIframeFocus: onIframeFocus
258
259
  });
259
260
  }
260
- }
261
+ }
262
+ export var CardWithUrlContent = function CardWithUrlContent(props) {
263
+ return /*#__PURE__*/React.createElement(SmartLinkAnalyticsContext, {
264
+ url: props.url,
265
+ appearance: props.appearance,
266
+ id: props.id
267
+ }, /*#__PURE__*/React.createElement(Component, props));
268
+ };
@@ -10,9 +10,11 @@ import { useSmartCardState as useLinkState } from '../../../state/store';
10
10
  import HoverCardContent from '../components/HoverCardContent';
11
11
  import { CARD_GAP_PX, HOVER_CARD_Z_INDEX } from '../styled';
12
12
  import { CardDisplay } from '../../../constants';
13
+ import { SmartLinkAnalyticsContext } from '../../../utils/analytics/SmartLinkAnalyticsContext';
13
14
  export var HoverCardComponent = function HoverCardComponent(_ref) {
14
15
  var children = _ref.children,
15
16
  url = _ref.url,
17
+ id = _ref.id,
16
18
  analyticsHandler = _ref.analyticsHandler,
17
19
  analytics = _ref.analytics,
18
20
  _ref$canOpen = _ref.canOpen,
@@ -122,7 +124,11 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
122
124
  }, [closeOnChildClick, hideCard]);
123
125
  var content = useCallback(function (_ref2) {
124
126
  var update = _ref2.update;
125
- return jsx(HoverCardContent, {
127
+ return jsx(SmartLinkAnalyticsContext, {
128
+ url: url,
129
+ appearance: CardDisplay.HoverCardPreview,
130
+ id: id
131
+ }, jsx(HoverCardContent, {
126
132
  onMouseEnter: initShowCard,
127
133
  onMouseLeave: initHideCard,
128
134
  analytics: analytics,
@@ -132,9 +138,10 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
132
138
  onResolve: update,
133
139
  renderers: renderers,
134
140
  showServerActions: showServerActions,
135
- url: url
136
- });
137
- }, [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url]);
141
+ url: url,
142
+ id: id
143
+ }));
144
+ }, [analytics, initHideCard, initShowCard, filteredActions, linkState, onActionClick, renderers, showServerActions, url, id]);
138
145
  var trigger = useCallback(function (triggerProps) {
139
146
  return jsx("span", {
140
147
  ref: parentSpan
@@ -0,0 +1,9 @@
1
+ import { FC } from 'react';
2
+ import { CardInnerAppearance } from '../../view/Card/types';
3
+ declare type SmartLinkAnalyticsContextProps = {
4
+ url: string;
5
+ appearance: CardInnerAppearance;
6
+ id: string | undefined;
7
+ };
8
+ export declare const SmartLinkAnalyticsContext: FC<SmartLinkAnalyticsContextProps>;
9
+ export {};
@@ -1,3 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  import { CardWithUrlContentProps } from './types';
3
- export declare function CardWithUrlContent({ id, url, isSelected, isFrameVisible, frameStyle, platform, onClick, appearance, dispatchAnalytics, onResolve, onError, testId, showActions, showServerActions: showServerActionsProp, inheritDimensions, embedIframeRef, embedIframeUrlType, inlinePreloaderStyle, ui, children, showHoverPreview, showAuthTooltip: showAuthTooltipProp, analyticsEvents, }: CardWithUrlContentProps): JSX.Element;
3
+ export declare const CardWithUrlContent: (props: CardWithUrlContentProps) => JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "25.7.2",
3
+ "version": "25.8.0",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -33,6 +33,7 @@
33
33
  "@atlaskit/icon-object": "^6.2.0",
34
34
  "@atlaskit/icon-priority": "^6.3.0",
35
35
  "@atlaskit/in-product-testing": "^0.1.0",
36
+ "@atlaskit/link-analytics": "^7.0.5",
36
37
  "@atlaskit/link-client-extension": "^0.5.0",
37
38
  "@atlaskit/linking-common": "^2.6.0",
38
39
  "@atlaskit/linking-types": "^1.3.0",