@atlaskit/smart-card 26.10.0 → 26.11.1

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,18 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 26.11.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`b37a26be833`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b37a26be833) - Prevent LinkUrl from throwing error on validation
8
+
9
+ ## 26.11.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [`fdfe07831c7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/fdfe07831c7) - - Deprecate standalone hover card `onAuthorize` prop (no implementation)
14
+ - Hide auth tooltip on unauthenticated inline link with no auth flow (new design, behind feature flag)
15
+
3
16
  ## 26.10.0
4
17
 
5
18
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.10.0",
3
+ "version": "26.11.1",
4
4
  "sideEffects": false
5
5
  }
@@ -166,6 +166,8 @@ var Container = function Container(_ref3) {
166
166
  var context = (0, _react.useContext)(_flexibleUiContext.FlexibleUiContext);
167
167
  var childrenOptions = getChildrenOptions(children, context);
168
168
  var canShowHoverPreview = showHoverPreview && status === 'resolved';
169
+ // `retry` object contains action that can be performed on
170
+ // unresolved link (unauthorized, forbidden, not found, etc.)
169
171
  var canShowAuthTooltip = showAuthTooltip && status === 'unauthorized' && retry !== undefined;
170
172
  var container = (0, _react2.jsx)("div", {
171
173
  css: getContainerStyles(size, hideBackground, hideElevation, hidePadding, clickableContainer, childrenOptions),
@@ -100,7 +100,6 @@ var InlineCardUnauthorizedView = /*#__PURE__*/function (_React$Component) {
100
100
  if (onAuthorise && showAuthTooltip) {
101
101
  return /*#__PURE__*/_react.default.createElement(_HoverCard.HoverCard, {
102
102
  url: url,
103
- onAuthorize: onAuthorise,
104
103
  id: this.props.id
105
104
  }, inlineCardUnauthenticatedView);
106
105
  }
@@ -10,6 +10,13 @@ var _react = require("react");
10
10
  var _url = require("@atlaskit/linking-common/url");
11
11
  var _analyticsNext = require("@atlaskit/analytics-next");
12
12
  var _analytics = require("../../../../utils/analytics");
13
+ var toUrl = function toUrl(url, base) {
14
+ try {
15
+ return new URL(url, base);
16
+ } catch (_unused) {
17
+ return undefined;
18
+ }
19
+ };
13
20
  var useLinkWarningModal = function useLinkWarningModal() {
14
21
  var _useState = (0, _react.useState)(null),
15
22
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
@@ -57,8 +64,9 @@ var useLinkWarningModal = function useLinkWarningModal() {
57
64
  return true;
58
65
  }
59
66
  var anchorLinkRegex = new RegExp(/^#/im);
60
- var isAnchorLink = anchorLinkRegex.test(linkText);
61
- if (isAnchorLink) {
67
+ var isLinkTextAnchorLink = anchorLinkRegex.test(linkText);
68
+ var isAnchorLink = anchorLinkRegex.test(href);
69
+ if (isAnchorLink || isLinkTextAnchorLink) {
62
70
  return true;
63
71
  }
64
72
  var relativeLinkRegex = new RegExp(/^\//im);
@@ -66,8 +74,11 @@ var useLinkWarningModal = function useLinkWarningModal() {
66
74
  if (isRelativeHrefLink) {
67
75
  return true;
68
76
  }
69
- var hrefUrl = new URL(href, window.location.origin);
70
- var linkTextUrl = new URL(normalisedUrlFromLinkText, hrefUrl.origin);
77
+ var hrefUrl = toUrl(href, window.location.origin);
78
+ var linkTextUrl = toUrl(normalisedUrlFromLinkText, hrefUrl === null || hrefUrl === void 0 ? void 0 : hrefUrl.origin);
79
+ if (!hrefUrl || !linkTextUrl) {
80
+ return true;
81
+ }
71
82
  var httpProtocols = ['http:', 'https:'];
72
83
  var areProtocolsEquivalent;
73
84
  if (httpProtocols.includes(linkTextUrl.protocol) && httpProtocols.includes(hrefUrl.protocol)) {
@@ -81,6 +81,7 @@ var InlineCardUnauthorizedView = /*#__PURE__*/function (_React$Component) {
81
81
  var _this$props3 = this.props,
82
82
  url = _this$props3.url,
83
83
  icon = _this$props3.icon,
84
+ onAuthorise = _this$props3.onAuthorise,
84
85
  onClick = _this$props3.onClick,
85
86
  isSelected = _this$props3.isSelected,
86
87
  _this$props3$testId = _this$props3.testId,
@@ -98,10 +99,9 @@ var InlineCardUnauthorizedView = /*#__PURE__*/function (_React$Component) {
98
99
  onClick: onClick,
99
100
  titleColor: "var(--ds-text-subtle, ".concat(_colors.N500, ")")
100
101
  }), this.renderActionButton());
101
- if (showAuthTooltip) {
102
+ if (onAuthorise && showAuthTooltip) {
102
103
  return /*#__PURE__*/_react.default.createElement(_HoverCard.HoverCard, {
103
104
  url: url,
104
- onAuthorize: this.props.onAuthorise,
105
105
  id: this.props.id
106
106
  }, inlineCardUnauthenticatedView);
107
107
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.10.0",
3
+ "version": "26.11.1",
4
4
  "sideEffects": false
5
5
  }
@@ -187,6 +187,8 @@ const Container = ({
187
187
  const context = useContext(FlexibleUiContext);
188
188
  const childrenOptions = getChildrenOptions(children, context);
189
189
  const canShowHoverPreview = showHoverPreview && status === 'resolved';
190
+ // `retry` object contains action that can be performed on
191
+ // unresolved link (unauthorized, forbidden, not found, etc.)
190
192
  const canShowAuthTooltip = showAuthTooltip && status === 'unauthorized' && retry !== undefined;
191
193
  const container = jsx("div", {
192
194
  css: getContainerStyles(size, hideBackground, hideElevation, hidePadding, clickableContainer, childrenOptions),
@@ -76,7 +76,6 @@ export class InlineCardUnauthorizedView extends React.Component {
76
76
  if (onAuthorise && showAuthTooltip) {
77
77
  return /*#__PURE__*/React.createElement(HoverCard, {
78
78
  url: url,
79
- onAuthorize: onAuthorise,
80
79
  id: this.props.id
81
80
  }, inlineCardUnauthenticatedView);
82
81
  }
@@ -2,6 +2,13 @@ import { useState } from 'react';
2
2
  import { normalizeUrl } from '@atlaskit/linking-common/url';
3
3
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
4
4
  import { ANALYTICS_CHANNEL } from '../../../../utils/analytics';
5
+ const toUrl = (url, base) => {
6
+ try {
7
+ return new URL(url, base);
8
+ } catch {
9
+ return undefined;
10
+ }
11
+ };
5
12
  export const useLinkWarningModal = () => {
6
13
  const [unsafeLinkText, setUnsafeLinkText] = useState(null);
7
14
  const [url, setUrl] = useState(null);
@@ -41,8 +48,9 @@ export const useLinkWarningModal = () => {
41
48
  return true;
42
49
  }
43
50
  const anchorLinkRegex = new RegExp(/^#/im);
44
- const isAnchorLink = anchorLinkRegex.test(linkText);
45
- if (isAnchorLink) {
51
+ const isLinkTextAnchorLink = anchorLinkRegex.test(linkText);
52
+ const isAnchorLink = anchorLinkRegex.test(href);
53
+ if (isAnchorLink || isLinkTextAnchorLink) {
46
54
  return true;
47
55
  }
48
56
  const relativeLinkRegex = new RegExp(/^\//im);
@@ -50,8 +58,11 @@ export const useLinkWarningModal = () => {
50
58
  if (isRelativeHrefLink) {
51
59
  return true;
52
60
  }
53
- const hrefUrl = new URL(href, window.location.origin);
54
- const linkTextUrl = new URL(normalisedUrlFromLinkText, hrefUrl.origin);
61
+ const hrefUrl = toUrl(href, window.location.origin);
62
+ const linkTextUrl = toUrl(normalisedUrlFromLinkText, hrefUrl === null || hrefUrl === void 0 ? void 0 : hrefUrl.origin);
63
+ if (!hrefUrl || !linkTextUrl) {
64
+ return true;
65
+ }
55
66
  const httpProtocols = ['http:', 'https:'];
56
67
  let areProtocolsEquivalent;
57
68
  if (httpProtocols.includes(linkTextUrl.protocol) && httpProtocols.includes(hrefUrl.protocol)) {
@@ -58,6 +58,7 @@ export class InlineCardUnauthorizedView extends React.Component {
58
58
  const {
59
59
  url,
60
60
  icon,
61
+ onAuthorise,
61
62
  onClick,
62
63
  isSelected,
63
64
  testId = 'inline-card-unauthorized-view',
@@ -74,10 +75,9 @@ export class InlineCardUnauthorizedView extends React.Component {
74
75
  onClick: onClick,
75
76
  titleColor: `var(--ds-text-subtle, ${N500})`
76
77
  }), this.renderActionButton());
77
- if (showAuthTooltip) {
78
+ if (onAuthorise && showAuthTooltip) {
78
79
  return /*#__PURE__*/React.createElement(HoverCard, {
79
80
  url: url,
80
- onAuthorize: this.props.onAuthorise,
81
81
  id: this.props.id
82
82
  }, inlineCardUnauthenticatedView);
83
83
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.10.0",
3
+ "version": "26.11.1",
4
4
  "sideEffects": false
5
5
  }
@@ -155,6 +155,8 @@ var Container = function Container(_ref3) {
155
155
  var context = useContext(FlexibleUiContext);
156
156
  var childrenOptions = getChildrenOptions(children, context);
157
157
  var canShowHoverPreview = showHoverPreview && status === 'resolved';
158
+ // `retry` object contains action that can be performed on
159
+ // unresolved link (unauthorized, forbidden, not found, etc.)
158
160
  var canShowAuthTooltip = showAuthTooltip && status === 'unauthorized' && retry !== undefined;
159
161
  var container = jsx("div", {
160
162
  css: getContainerStyles(size, hideBackground, hideElevation, hidePadding, clickableContainer, childrenOptions),
@@ -93,7 +93,6 @@ export var InlineCardUnauthorizedView = /*#__PURE__*/function (_React$Component)
93
93
  if (onAuthorise && showAuthTooltip) {
94
94
  return /*#__PURE__*/React.createElement(HoverCard, {
95
95
  url: url,
96
- onAuthorize: onAuthorise,
97
96
  id: this.props.id
98
97
  }, inlineCardUnauthenticatedView);
99
98
  }
@@ -3,6 +3,13 @@ import { useState } from 'react';
3
3
  import { normalizeUrl } from '@atlaskit/linking-common/url';
4
4
  import { useAnalyticsEvents } from '@atlaskit/analytics-next';
5
5
  import { ANALYTICS_CHANNEL } from '../../../../utils/analytics';
6
+ var toUrl = function toUrl(url, base) {
7
+ try {
8
+ return new URL(url, base);
9
+ } catch (_unused) {
10
+ return undefined;
11
+ }
12
+ };
6
13
  export var useLinkWarningModal = function useLinkWarningModal() {
7
14
  var _useState = useState(null),
8
15
  _useState2 = _slicedToArray(_useState, 2),
@@ -50,8 +57,9 @@ export var useLinkWarningModal = function useLinkWarningModal() {
50
57
  return true;
51
58
  }
52
59
  var anchorLinkRegex = new RegExp(/^#/im);
53
- var isAnchorLink = anchorLinkRegex.test(linkText);
54
- if (isAnchorLink) {
60
+ var isLinkTextAnchorLink = anchorLinkRegex.test(linkText);
61
+ var isAnchorLink = anchorLinkRegex.test(href);
62
+ if (isAnchorLink || isLinkTextAnchorLink) {
55
63
  return true;
56
64
  }
57
65
  var relativeLinkRegex = new RegExp(/^\//im);
@@ -59,8 +67,11 @@ export var useLinkWarningModal = function useLinkWarningModal() {
59
67
  if (isRelativeHrefLink) {
60
68
  return true;
61
69
  }
62
- var hrefUrl = new URL(href, window.location.origin);
63
- var linkTextUrl = new URL(normalisedUrlFromLinkText, hrefUrl.origin);
70
+ var hrefUrl = toUrl(href, window.location.origin);
71
+ var linkTextUrl = toUrl(normalisedUrlFromLinkText, hrefUrl === null || hrefUrl === void 0 ? void 0 : hrefUrl.origin);
72
+ if (!hrefUrl || !linkTextUrl) {
73
+ return true;
74
+ }
64
75
  var httpProtocols = ['http:', 'https:'];
65
76
  var areProtocolsEquivalent;
66
77
  if (httpProtocols.includes(linkTextUrl.protocol) && httpProtocols.includes(hrefUrl.protocol)) {
@@ -74,6 +74,7 @@ export var InlineCardUnauthorizedView = /*#__PURE__*/function (_React$Component)
74
74
  var _this$props3 = this.props,
75
75
  url = _this$props3.url,
76
76
  icon = _this$props3.icon,
77
+ onAuthorise = _this$props3.onAuthorise,
77
78
  onClick = _this$props3.onClick,
78
79
  isSelected = _this$props3.isSelected,
79
80
  _this$props3$testId = _this$props3.testId,
@@ -91,10 +92,9 @@ export var InlineCardUnauthorizedView = /*#__PURE__*/function (_React$Component)
91
92
  onClick: onClick,
92
93
  titleColor: "var(--ds-text-subtle, ".concat(N500, ")")
93
94
  }), this.renderActionButton());
94
- if (showAuthTooltip) {
95
+ if (onAuthorise && showAuthTooltip) {
95
96
  return /*#__PURE__*/React.createElement(HoverCard, {
96
97
  url: url,
97
- onAuthorize: this.props.onAuthorise,
98
98
  id: this.props.id
99
99
  }, inlineCardUnauthenticatedView);
100
100
  }
@@ -22,6 +22,7 @@ export interface HoverCardProps extends WithAnalyticsEventsProps {
22
22
  children: ReactElement;
23
23
  /**
24
24
  * Function to be called when user is authorized to view a link.
25
+ * @deprecated See EDM-7411
25
26
  */
26
27
  onAuthorize?: () => void;
27
28
  /**
@@ -22,6 +22,7 @@ export interface HoverCardProps extends WithAnalyticsEventsProps {
22
22
  children: ReactElement;
23
23
  /**
24
24
  * Function to be called when user is authorized to view a link.
25
+ * @deprecated See EDM-7411
25
26
  */
26
27
  onAuthorize?: () => void;
27
28
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "26.10.0",
3
+ "version": "26.11.1",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -74,7 +74,7 @@
74
74
  "@af/visual-regression": "*",
75
75
  "@atlaskit/avatar": "^21.3.0",
76
76
  "@atlaskit/css-reset": "^6.5.0",
77
- "@atlaskit/link-test-helpers": "^4.2.0",
77
+ "@atlaskit/link-test-helpers": "^5.0.0",
78
78
  "@atlaskit/lozenge": "^11.4.0",
79
79
  "@atlaskit/media-integration-test-helpers": "^3.0.0",
80
80
  "@atlaskit/media-test-helpers": "^33.0.0",