@atlaskit/smart-card 27.4.0 → 27.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/cjs/extractors/flexible/actions/extract-automation-action.js +13 -31
  3. package/dist/cjs/state/hooks/use-resolve/index.js +15 -120
  4. package/dist/cjs/state/hooks/use-response/index.js +132 -0
  5. package/dist/cjs/utils/analytics/analytics.js +1 -1
  6. package/dist/cjs/view/FlexibleCard/components/actions/automation-action/automation-manual-triggers/manual-triggers-modal/main.js +1 -1
  7. package/dist/cjs/view/FlexibleCard/components/actions/automation-action/index.js +14 -8
  8. package/dist/cjs/view/FlexibleCard/components/actions/automation-action/utils/index.js +19 -0
  9. package/dist/cjs/view/LinkUrl/index.js +1 -1
  10. package/dist/es2019/extractors/flexible/actions/extract-automation-action.js +13 -28
  11. package/dist/es2019/state/hooks/use-resolve/index.js +9 -112
  12. package/dist/es2019/state/hooks/use-response/index.js +126 -0
  13. package/dist/es2019/utils/analytics/analytics.js +1 -1
  14. package/dist/es2019/view/FlexibleCard/components/actions/automation-action/automation-manual-triggers/manual-triggers-modal/main.js +1 -1
  15. package/dist/es2019/view/FlexibleCard/components/actions/automation-action/index.js +16 -7
  16. package/dist/es2019/view/FlexibleCard/components/actions/automation-action/utils/index.js +13 -0
  17. package/dist/es2019/view/LinkUrl/index.js +1 -1
  18. package/dist/esm/extractors/flexible/actions/extract-automation-action.js +13 -30
  19. package/dist/esm/state/hooks/use-resolve/index.js +13 -118
  20. package/dist/esm/state/hooks/use-response/index.js +126 -0
  21. package/dist/esm/utils/analytics/analytics.js +1 -1
  22. package/dist/esm/view/FlexibleCard/components/actions/automation-action/automation-manual-triggers/manual-triggers-modal/main.js +1 -1
  23. package/dist/esm/view/FlexibleCard/components/actions/automation-action/index.js +14 -8
  24. package/dist/esm/view/FlexibleCard/components/actions/automation-action/utils/index.js +13 -0
  25. package/dist/esm/view/LinkUrl/index.js +1 -1
  26. package/dist/types/state/flexible-ui-context/types.d.ts +2 -3
  27. package/dist/types/state/hooks/use-response/index.d.ts +7 -0
  28. package/dist/types/view/FlexibleCard/components/actions/automation-action/automation-manual-triggers/manual-triggers-modal/sub-components/header/main.d.ts +1 -1
  29. package/dist/types/view/FlexibleCard/components/actions/automation-action/utils/index.d.ts +7 -0
  30. package/dist/types-ts4.5/state/flexible-ui-context/types.d.ts +2 -3
  31. package/dist/types-ts4.5/state/hooks/use-response/index.d.ts +7 -0
  32. package/dist/types-ts4.5/view/FlexibleCard/components/actions/automation-action/automation-manual-triggers/manual-triggers-modal/sub-components/header/main.d.ts +1 -1
  33. package/dist/types-ts4.5/view/FlexibleCard/components/actions/automation-action/utils/index.d.ts +7 -0
  34. package/package.json +3 -5
@@ -0,0 +1,126 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { ACTION_ERROR, ACTION_ERROR_FALLBACK, ACTION_RELOADING, ACTION_RESOLVED, ACTION_UPDATE_METADATA_STATUS, APIError, cardAction, getStatus } from '@atlaskit/linking-common';
3
+ import { SmartLinkStatus } from '../../../constants';
4
+ import { getUnauthorizedJsonLd } from '../../../utils/jsonld';
5
+ import { ERROR_MESSAGE_FATAL, ERROR_MESSAGE_METADATA, ERROR_MESSAGE_OAUTH } from '../../actions/constants';
6
+ import { unstable_batchedUpdates } from 'react-dom';
7
+ import { useSmartLinkContext } from '@atlaskit/link-provider';
8
+ var useResponse = function useResponse() {
9
+ // Takes in the JSON-LD response and dispatch the resolved action for the card.
10
+ // It will dispatch a successful or error action
11
+ var _useSmartLinkContext = useSmartLinkContext(),
12
+ store = _useSmartLinkContext.store,
13
+ config = _useSmartLinkContext.config;
14
+ var getState = store.getState,
15
+ dispatch = store.dispatch;
16
+ var hasAuthFlowSupported = config.authFlow !== 'disabled';
17
+ var setMetadataStatus = useCallback(function (url, metadataStatus) {
18
+ dispatch(cardAction(ACTION_UPDATE_METADATA_STATUS, {
19
+ url: url
20
+ }, undefined, undefined, metadataStatus));
21
+ }, [dispatch]);
22
+ var handleResolvedLinkError = useCallback(function (url, error, response, isMetadataRequest) {
23
+ var _ref = getState()[url] || {
24
+ status: SmartLinkStatus.Pending,
25
+ details: undefined
26
+ },
27
+ details = _ref.details;
28
+ var hasData = !!(details && details.data);
29
+ // If metadata request then set metadata status, return and do not alter link status
30
+ if (isMetadataRequest) {
31
+ setMetadataStatus(url, 'errored');
32
+ return;
33
+ }
34
+ if (error.kind === 'fatal') {
35
+ // If there's no previous data in the store for this URL, then bail
36
+ // out and let the editor handle fallbacks (returns to a blue link).
37
+ if (!hasData && status !== 'resolved') {
38
+ dispatch(cardAction(ACTION_ERROR, {
39
+ url: url
40
+ }, details, error));
41
+ throw error;
42
+ }
43
+ // If we already have resolved data for this URL in the store, then
44
+ // simply fallback to the previous data.
45
+ if (hasData) {
46
+ dispatch(cardAction(ACTION_RESOLVED, {
47
+ url: url
48
+ }, details));
49
+ }
50
+ // Handle AuthErrors (user did not have access to resource) -
51
+ // Missing AAID in ASAP claims, or missing UserContext, or 403 from downstream
52
+ } else if (error.kind === 'auth') {
53
+ dispatch(cardAction(ACTION_RESOLVED, {
54
+ url: url
55
+ }, getUnauthorizedJsonLd()));
56
+ } else {
57
+ if (error.kind === 'fallback') {
58
+ // Fallback to blue link with smart link formatting. Not part of reliability.
59
+ dispatch(cardAction(ACTION_ERROR_FALLBACK, {
60
+ url: url
61
+ }, response, error));
62
+ } else {
63
+ // Fallback to blue link with smart link formatting. Part of reliability.
64
+ dispatch(cardAction(ACTION_ERROR, {
65
+ url: url
66
+ }, undefined, error));
67
+ }
68
+ }
69
+ }, [getState, setMetadataStatus, dispatch]);
70
+ var handleResolvedLinkSuccess = useCallback(function (resourceUrl, response, isReloading, isMetadataRequest) {
71
+ //if a link resolves normally, metadata will also always be resolved
72
+ setMetadataStatus(resourceUrl, 'resolved');
73
+ // Dispatch Analytics and resolved card action - including unauthorized states.
74
+ if (isReloading) {
75
+ dispatch(cardAction(ACTION_RELOADING, {
76
+ url: resourceUrl
77
+ }, response));
78
+ } else {
79
+ dispatch(cardAction(ACTION_RESOLVED, {
80
+ url: resourceUrl
81
+ }, response, undefined, undefined, isMetadataRequest));
82
+ }
83
+ }, [setMetadataStatus, dispatch]);
84
+ var handleResolvedLinkResponse = useCallback(function (resourceUrl, response) {
85
+ var isReloading = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
86
+ var isMetadataRequest = arguments.length > 3 ? arguments[3] : undefined;
87
+ var hostname = new URL(resourceUrl).hostname;
88
+ var nextStatus = response ? getStatus(response) : 'fatal';
89
+
90
+ // If we require authorization & do not have an authFlow available,
91
+ // throw an error and render as a normal blue link.
92
+ if ((nextStatus === 'unauthorized' || nextStatus === 'forbidden') && !hasAuthFlowSupported) {
93
+ handleResolvedLinkError(resourceUrl, new APIError('fallback', hostname, ERROR_MESSAGE_OAUTH), response, isMetadataRequest);
94
+ return;
95
+ }
96
+
97
+ // Handle any other errors
98
+ if (nextStatus === 'fatal') {
99
+ handleResolvedLinkError(resourceUrl, new APIError('fatal', hostname, ERROR_MESSAGE_FATAL), undefined, isMetadataRequest);
100
+ return;
101
+ }
102
+
103
+ // Handle errors of any other kind in the metadata request response
104
+ if (isMetadataRequest && nextStatus !== 'resolved') {
105
+ handleResolvedLinkError(resourceUrl, new APIError('error', hostname, ERROR_MESSAGE_METADATA), response, isMetadataRequest);
106
+ return;
107
+ }
108
+
109
+ /**
110
+ * Using unstable_batchedUpdates because this store update happens async and triggers a rerender
111
+ * more info:
112
+ * https://github.com/facebook/react/blob/v18.2.0/packages/use-sync-external-store/src/useSyncExternalStoreShimClient.js#L113
113
+ * https://react-redux.js.org/api/batch
114
+ */
115
+ unstable_batchedUpdates(function () {
116
+ handleResolvedLinkSuccess(resourceUrl, response, isReloading, isMetadataRequest);
117
+ });
118
+ }, [handleResolvedLinkError, handleResolvedLinkSuccess, hasAuthFlowSupported]);
119
+ return useMemo(function () {
120
+ return {
121
+ handleResolvedLinkError: handleResolvedLinkError,
122
+ handleResolvedLinkResponse: handleResolvedLinkResponse
123
+ };
124
+ }, [handleResolvedLinkError, handleResolvedLinkResponse]);
125
+ };
126
+ export default useResponse;
@@ -15,7 +15,7 @@ export var ANALYTICS_CHANNEL = 'media';
15
15
  export var context = {
16
16
  componentName: 'smart-cards',
17
17
  packageName: "@atlaskit/smart-card",
18
- packageVersion: "27.4.0"
18
+ packageVersion: "27.4.2"
19
19
  };
20
20
  export var TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
21
21
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -42,7 +42,7 @@ export var AutomationModal = function AutomationModal(_ref) {
42
42
  emptyStateDescription: emptyStateDescription,
43
43
  emptyStateAdminDescription: emptyStateAdminDescription,
44
44
  onRuleInvocationSuccess: onClose,
45
- onRuleInvocationLifecycleDone: function onRuleInvocationLifecycleDone() {
45
+ onRuleInvocationFailure: function onRuleInvocationFailure() {
46
46
  return setSelectedRule(undefined);
47
47
  }
48
48
  }, function () {
@@ -7,6 +7,7 @@ import { useFlexibleUiContext } from '../../../../../state/flexible-ui-context';
7
7
  import { useSmartLinkModal } from '../../../../../state/modal';
8
8
  import { ActionName } from '../../../../../constants';
9
9
  import { messages } from '../../../../../messages';
10
+ import { getModalContent } from './utils';
10
11
  var AutomationModal = /*#__PURE__*/lazy(function () {
11
12
  return import( /* webpackChunkName: "@atlaskit-internal_smart-card-automation-modal" */'./automation-manual-triggers/manual-triggers-modal');
12
13
  });
@@ -15,19 +16,23 @@ var AutomationAction = function AutomationAction(props) {
15
16
  var _useIntl = useIntl(),
16
17
  formatMessage = _useIntl.formatMessage;
17
18
  var modal = useSmartLinkModal();
19
+ var onClickCallback = props.onClick;
18
20
  var context = useFlexibleUiContext();
19
21
  var automationActionData = context === null || context === void 0 || (_context$actions = context.actions) === null || _context$actions === void 0 ? void 0 : _context$actions[ActionName.AutomationAction];
20
22
  var automationActionOnClick = useCallback(function (automationActionData) {
21
- var baseAutomationUrl = automationActionData.baseAutomationUrl,
23
+ var product = automationActionData.product,
24
+ resourceType = automationActionData.resourceType,
25
+ baseAutomationUrl = automationActionData.baseAutomationUrl,
22
26
  objectAri = automationActionData.objectAri,
23
27
  siteAri = automationActionData.siteAri,
24
28
  canManageAutomation = automationActionData.canManageAutomation,
25
29
  analyticsSource = automationActionData.analyticsSource,
26
- modalTitle = automationActionData.modalTitle,
27
- modalDescription = automationActionData.modalDescription,
28
30
  objectName = automationActionData.objectName;
29
- var automationModalTitle = /*#__PURE__*/React.createElement(FormattedMessage, modalTitle);
30
- var automationModalDescription = /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, modalDescription, {
31
+ var _ref = getModalContent(product, resourceType) || {},
32
+ modalTitle = _ref.modalTitle,
33
+ modalDescription = _ref.modalDescription;
34
+ var automationModalTitle = modalTitle ? /*#__PURE__*/React.createElement(FormattedMessage, modalTitle) : undefined;
35
+ var automationModalDescription = modalDescription ? /*#__PURE__*/React.createElement(FormattedMessage, _extends({}, modalDescription, {
31
36
  values: {
32
37
  name: objectName,
33
38
  b: function b(chunks) {
@@ -35,7 +40,7 @@ var AutomationAction = function AutomationAction(props) {
35
40
  },
36
41
  br: /*#__PURE__*/React.createElement("br", null)
37
42
  }
38
- }));
43
+ })) : undefined;
39
44
  modal.open( /*#__PURE__*/React.createElement(AutomationModal, {
40
45
  baseAutomationUrl: baseAutomationUrl,
41
46
  objectAri: objectAri,
@@ -48,7 +53,8 @@ var AutomationAction = function AutomationAction(props) {
48
53
  return modal.close();
49
54
  }
50
55
  }));
51
- }, [modal]);
56
+ onClickCallback === null || onClickCallback === void 0 || onClickCallback();
57
+ }, [modal, onClickCallback]);
52
58
  if (!automationActionData) {
53
59
  return null;
54
60
  }
@@ -62,7 +68,7 @@ var AutomationAction = function AutomationAction(props) {
62
68
  }),
63
69
  testId: "smart-action-automation-action",
64
70
  tooltipMessage: automationActionTooltip
65
- }, automationActionData, props, {
71
+ }, props, {
66
72
  onClick: function onClick() {
67
73
  return automationActionOnClick(automationActionData);
68
74
  }
@@ -0,0 +1,13 @@
1
+ import { messages } from '../../../../../../messages';
2
+ export var getModalContent = function getModalContent(product, resourceType) {
3
+ var _modalContentMap$prod;
4
+ var modalContentMap = {
5
+ 'confluence': {
6
+ 'page': {
7
+ modalTitle: messages.automation_action_confluence_page_modal_title,
8
+ modalDescription: messages.automation_action_confluence_page_modal_description
9
+ }
10
+ }
11
+ };
12
+ return modalContentMap === null || modalContentMap === void 0 || (_modalContentMap$prod = modalContentMap[product]) === null || _modalContentMap$prod === void 0 ? void 0 : _modalContentMap$prod[resourceType];
13
+ };
@@ -10,7 +10,7 @@ import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-m
10
10
  import LinkWarningModal from './LinkWarningModal';
11
11
  var PACKAGE_DATA = {
12
12
  packageName: "@atlaskit/smart-card",
13
- packageVersion: "27.4.0",
13
+ packageVersion: "27.4.2",
14
14
  componentName: 'linkUrl'
15
15
  };
16
16
  var Link = withLinkClickedEvent('a');
@@ -5,7 +5,6 @@ import { type InvokeRequestWithCardDetails } from '../hooks/use-invoke/types';
5
5
  import type { CardInnerAppearance } from '../../view/Card/types';
6
6
  import type { AnalyticsFacade } from '../analytics';
7
7
  import type { ProductType } from '@atlaskit/linking-common';
8
- import { type MessageDescriptor } from 'react-intl-next';
9
8
  /**
10
9
  * This provides the data that will be used by Smart Links Flexible UI to populate it's
11
10
  * underlying elements.
@@ -275,14 +274,14 @@ export type AISummaryActionData = {
275
274
  url: string;
276
275
  };
277
276
  export type AutomationActionData = {
277
+ product: string;
278
+ resourceType: string;
278
279
  baseAutomationUrl: string;
279
280
  objectAri: any;
280
281
  siteAri: any;
281
282
  canManageAutomation: boolean;
282
283
  analyticsSource: string;
283
284
  objectName?: string;
284
- modalTitle: MessageDescriptor;
285
- modalDescription: MessageDescriptor;
286
285
  };
287
286
  export type ViewRelatedLinksActionData = {
288
287
  url: string;
@@ -0,0 +1,7 @@
1
+ import { APIError } from '@atlaskit/linking-common';
2
+ import { type JsonLd } from 'json-ld-types';
3
+ declare const useResponse: () => {
4
+ handleResolvedLinkError: (url: string, error: APIError, response?: JsonLd.Response, isMetadataRequest?: boolean) => void;
5
+ handleResolvedLinkResponse: (resourceUrl: string, response: JsonLd.Response, isReloading?: any, isMetadataRequest?: boolean) => void;
6
+ };
7
+ export default useResponse;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  type AutomationModalHeaderProps = {
3
- modalTitle: React.ReactNode;
3
+ modalTitle?: React.ReactNode;
4
4
  modalDescription?: React.ReactNode;
5
5
  };
6
6
  export declare const AutomationModalHeader: ({ modalTitle, modalDescription, }: AutomationModalHeaderProps) => JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { type MessageDescriptor } from "react-intl-next";
2
+ type ModalContent = {
3
+ modalTitle: MessageDescriptor;
4
+ modalDescription: MessageDescriptor;
5
+ };
6
+ export declare const getModalContent: (product: string, resourceType: string) => ModalContent | undefined;
7
+ export {};
@@ -5,7 +5,6 @@ import { type InvokeRequestWithCardDetails } from '../hooks/use-invoke/types';
5
5
  import type { CardInnerAppearance } from '../../view/Card/types';
6
6
  import type { AnalyticsFacade } from '../analytics';
7
7
  import type { ProductType } from '@atlaskit/linking-common';
8
- import { type MessageDescriptor } from 'react-intl-next';
9
8
  /**
10
9
  * This provides the data that will be used by Smart Links Flexible UI to populate it's
11
10
  * underlying elements.
@@ -275,14 +274,14 @@ export type AISummaryActionData = {
275
274
  url: string;
276
275
  };
277
276
  export type AutomationActionData = {
277
+ product: string;
278
+ resourceType: string;
278
279
  baseAutomationUrl: string;
279
280
  objectAri: any;
280
281
  siteAri: any;
281
282
  canManageAutomation: boolean;
282
283
  analyticsSource: string;
283
284
  objectName?: string;
284
- modalTitle: MessageDescriptor;
285
- modalDescription: MessageDescriptor;
286
285
  };
287
286
  export type ViewRelatedLinksActionData = {
288
287
  url: string;
@@ -0,0 +1,7 @@
1
+ import { APIError } from '@atlaskit/linking-common';
2
+ import { type JsonLd } from 'json-ld-types';
3
+ declare const useResponse: () => {
4
+ handleResolvedLinkError: (url: string, error: APIError, response?: JsonLd.Response, isMetadataRequest?: boolean) => void;
5
+ handleResolvedLinkResponse: (resourceUrl: string, response: JsonLd.Response, isReloading?: any, isMetadataRequest?: boolean) => void;
6
+ };
7
+ export default useResponse;
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  type AutomationModalHeaderProps = {
3
- modalTitle: React.ReactNode;
3
+ modalTitle?: React.ReactNode;
4
4
  modalDescription?: React.ReactNode;
5
5
  };
6
6
  export declare const AutomationModalHeader: ({ modalTitle, modalDescription, }: AutomationModalHeaderProps) => JSX.Element;
@@ -0,0 +1,7 @@
1
+ import { type MessageDescriptor } from "react-intl-next";
2
+ type ModalContent = {
3
+ modalTitle: MessageDescriptor;
4
+ modalDescription: MessageDescriptor;
5
+ };
6
+ export declare const getModalContent: (product: string, resourceType: string) => ModalContent | undefined;
7
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "27.4.0",
3
+ "version": "27.4.2",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -55,7 +55,7 @@
55
55
  "@atlaskit/outbound-auth-flow-client": "^3.4.0",
56
56
  "@atlaskit/platform-feature-flags": "^0.2.1",
57
57
  "@atlaskit/popup": "^1.17.0",
58
- "@atlaskit/primitives": "^6.3.0",
58
+ "@atlaskit/primitives": "^6.4.0",
59
59
  "@atlaskit/section-message": "^6.5.0",
60
60
  "@atlaskit/select": "^17.10.0",
61
61
  "@atlaskit/spinner": "^16.1.0",
@@ -97,7 +97,6 @@
97
97
  "@atlaskit/ssr": "*",
98
98
  "@atlaskit/visual-regression": "*",
99
99
  "@atlassian/analytics-tooling": "*",
100
- "@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
101
100
  "@atlassian/feature-flags-test-utils": "^0.2.0",
102
101
  "@testing-library/dom": "^8.17.1",
103
102
  "@testing-library/jest-dom": "^5.16.5",
@@ -192,6 +191,5 @@
192
191
  "platform.linking-platform.smart-card.enable-view-related-urls-action": {
193
192
  "type": "boolean"
194
193
  }
195
- },
196
- "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.1"
194
+ }
197
195
  }