@atlaskit/smart-card 25.9.1 → 25.9.3
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 +12 -0
- package/dist/cjs/extractors/flexible/extract-state.js +4 -1
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/view/EmbedModal/components/analytics/index.js +9 -9
- package/dist/cjs/view/EmbedModal/utils.js +111 -0
- package/dist/cjs/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -83
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/index.js +48 -25
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +6 -4
- package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js +2 -2
- package/dist/es2019/extractors/flexible/extract-state.js +4 -1
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/EmbedModal/components/analytics/index.js +9 -9
- package/dist/es2019/view/EmbedModal/utils.js +77 -0
- package/dist/es2019/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -56
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/index.js +30 -12
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +35 -5
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +9 -1
- package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js +2 -2
- package/dist/esm/extractors/flexible/extract-state.js +4 -1
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/EmbedModal/components/analytics/index.js +9 -9
- package/dist/esm/view/EmbedModal/utils.js +98 -0
- package/dist/esm/view/FlexibleCard/components/actions/action/preview-action/index.js +7 -78
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/index.js +49 -26
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js +37 -5
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.js +4 -3
- package/dist/esm/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js +2 -2
- package/dist/types/state/hooks/use-invoke/types.d.ts +5 -0
- package/dist/types/view/Card/types.d.ts +0 -2
- package/dist/types/view/EmbedModal/components/analytics/types.d.ts +1 -1
- package/dist/types/view/EmbedModal/utils.d.ts +10 -0
- package/dist/types/view/FlexibleCard/components/actions/action/preview-action/index.d.ts +1 -2
- package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/styled.d.ts +1 -0
- package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/types.d.ts +18 -0
- package/dist/types/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/types.d.ts +3 -2
- package/package.json +1 -1
package/dist/cjs/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js
CHANGED
|
@@ -22,9 +22,9 @@ var LozengeActionItem = function LozengeActionItem(_ref) {
|
|
|
22
22
|
// We want to show loading screen.
|
|
23
23
|
e.stopPropagation();
|
|
24
24
|
if (onClick) {
|
|
25
|
-
onClick(id);
|
|
25
|
+
onClick(id, text, appearance);
|
|
26
26
|
}
|
|
27
|
-
}, [id, onClick]);
|
|
27
|
+
}, [appearance, id, onClick, text]);
|
|
28
28
|
var handleMouseEnter = (0, _react.useCallback)(function (e) {
|
|
29
29
|
var _e$currentTarget, _e$currentTarget$firs;
|
|
30
30
|
(_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : (_e$currentTarget$firs = _e$currentTarget.firstElementChild) === null || _e$currentTarget$firs === void 0 ? void 0 : _e$currentTarget$firs.focus();
|
|
@@ -2,6 +2,7 @@ import { extractLozenge } from '../common/lozenge';
|
|
|
2
2
|
import { getExtensionKey } from '../../state/helpers';
|
|
3
3
|
import extractServerAction from './extract-server-action';
|
|
4
4
|
import { extractLink } from '@atlaskit/linking-common/extractors';
|
|
5
|
+
import { extractPreviewAction } from './actions/extract-preview-action';
|
|
5
6
|
const toInvokeRequest = (extensionKey, resourceIdentifiers, actionType, details) => {
|
|
6
7
|
if (!actionType) {
|
|
7
8
|
return;
|
|
@@ -29,9 +30,11 @@ const extractAction = (response, id) => {
|
|
|
29
30
|
}
|
|
30
31
|
const read = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataRetrieval = action.dataRetrievalAction) === null || _action$dataRetrieval === void 0 ? void 0 : _action$dataRetrieval.name);
|
|
31
32
|
const url = extractLink(data);
|
|
33
|
+
const previewData = response ? extractPreviewAction(response) : null;
|
|
32
34
|
const details = {
|
|
33
35
|
id,
|
|
34
|
-
url
|
|
36
|
+
url,
|
|
37
|
+
previewData
|
|
35
38
|
};
|
|
36
39
|
const update = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataUpdateAct = action.dataUpdateAction) === null || _action$dataUpdateAct === void 0 ? void 0 : _action$dataUpdateAct.name, details);
|
|
37
40
|
return read || update ? {
|
package/dist/es2019/version.json
CHANGED
|
@@ -13,23 +13,23 @@ const withAnalytics = Component => props => {
|
|
|
13
13
|
origin
|
|
14
14
|
} = props;
|
|
15
15
|
const handleOnOpen = useCallback(context => {
|
|
16
|
-
analytics.screen.modalViewedEvent({
|
|
16
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.screen.modalViewedEvent({
|
|
17
17
|
name: 'embedPreviewModal',
|
|
18
18
|
attributes: {
|
|
19
19
|
origin,
|
|
20
20
|
size: context.size
|
|
21
21
|
}
|
|
22
22
|
});
|
|
23
|
-
analytics.ui.renderSuccessEvent({
|
|
23
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderSuccessEvent({
|
|
24
24
|
status: 'resolved',
|
|
25
25
|
display: CardDisplay.EmbedPreview
|
|
26
26
|
});
|
|
27
27
|
if (onOpen) {
|
|
28
28
|
onOpen(context);
|
|
29
29
|
}
|
|
30
|
-
}, [analytics.screen, analytics.ui, onOpen, origin]);
|
|
30
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.screen, analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpen, origin]);
|
|
31
31
|
const handleOnOpenFailed = useCallback((error, errorInfo) => {
|
|
32
|
-
analytics.ui.renderFailedEvent({
|
|
32
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderFailedEvent({
|
|
33
33
|
display: CardDisplay.EmbedPreview,
|
|
34
34
|
error,
|
|
35
35
|
errorInfo
|
|
@@ -37,9 +37,9 @@ const withAnalytics = Component => props => {
|
|
|
37
37
|
if (onOpenFailed) {
|
|
38
38
|
onOpenFailed(error, errorInfo);
|
|
39
39
|
}
|
|
40
|
-
}, [analytics.ui, onOpenFailed]);
|
|
40
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpenFailed]);
|
|
41
41
|
const handleOnClose = useCallback(context => {
|
|
42
|
-
analytics.ui.modalClosedEvent({
|
|
42
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.modalClosedEvent({
|
|
43
43
|
actionSubjectId: 'embedPreview',
|
|
44
44
|
attributes: {
|
|
45
45
|
origin,
|
|
@@ -50,9 +50,9 @@ const withAnalytics = Component => props => {
|
|
|
50
50
|
if (onClose) {
|
|
51
51
|
onClose(context);
|
|
52
52
|
}
|
|
53
|
-
}, [analytics.ui, onClose, origin]);
|
|
53
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onClose, origin]);
|
|
54
54
|
const handleOnResize = useCallback(context => {
|
|
55
|
-
analytics.ui.buttonClickedEvent({
|
|
55
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.buttonClickedEvent({
|
|
56
56
|
actionSubjectId: 'embedPreviewResize',
|
|
57
57
|
attributes: {
|
|
58
58
|
newSize: context.size,
|
|
@@ -63,7 +63,7 @@ const withAnalytics = Component => props => {
|
|
|
63
63
|
if (onResize) {
|
|
64
64
|
onResize(context);
|
|
65
65
|
}
|
|
66
|
-
}, [analytics.ui, onResize, origin]);
|
|
66
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onResize, origin]);
|
|
67
67
|
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
|
|
68
68
|
onClose: handleOnClose,
|
|
69
69
|
onOpen: handleOnOpen,
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import ReactDOM from 'react-dom';
|
|
4
|
+
import { IntlProvider } from 'react-intl-next';
|
|
5
|
+
import Icon from '../FlexibleCard/components/elements/icon';
|
|
6
|
+
export const openPreviewModal = ({
|
|
7
|
+
analytics,
|
|
8
|
+
downloadUrl: download,
|
|
9
|
+
isSupportTheming,
|
|
10
|
+
linkIcon,
|
|
11
|
+
onClose = () => {},
|
|
12
|
+
providerName,
|
|
13
|
+
src,
|
|
14
|
+
title,
|
|
15
|
+
url
|
|
16
|
+
}) => {
|
|
17
|
+
const EmbedIcon = {
|
|
18
|
+
icon: /*#__PURE__*/React.createElement(Icon, linkIcon),
|
|
19
|
+
isFlexibleUi: true
|
|
20
|
+
};
|
|
21
|
+
return previewFunction({
|
|
22
|
+
popupMountPointId: 'twp-editor-preview-iframe',
|
|
23
|
+
showModal: true,
|
|
24
|
+
iframeName: 'twp-editor-preview-iframe',
|
|
25
|
+
onClose,
|
|
26
|
+
download,
|
|
27
|
+
icon: EmbedIcon,
|
|
28
|
+
providerName: providerName || 'Preview',
|
|
29
|
+
src,
|
|
30
|
+
title,
|
|
31
|
+
url,
|
|
32
|
+
analytics,
|
|
33
|
+
origin: 'smartLinkCard',
|
|
34
|
+
isSupportTheming
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/*
|
|
39
|
+
Explanatory note:
|
|
40
|
+
Actions don't have access to the react tree of whatever is rendered them
|
|
41
|
+
(and this concept is fraught inside editor anyway) so we want to ensure
|
|
42
|
+
it is mounting to a new unique place. This function manages that, including
|
|
43
|
+
creating an element if it doesn't exist, as well as tidying up the react tree
|
|
44
|
+
(but not the element) upon closing the modal.
|
|
45
|
+
|
|
46
|
+
This may strike you as really uncomfortable as you read it, so I wanted to note
|
|
47
|
+
that a) this was discussed and agreed upon, and b) it's definitely odd, and if
|
|
48
|
+
you find an elegant solution around this, you should definitely feel free to
|
|
49
|
+
refactor it.
|
|
50
|
+
*/
|
|
51
|
+
export async function previewFunction({
|
|
52
|
+
popupMountPointId,
|
|
53
|
+
onClose: onEmbedClose,
|
|
54
|
+
...rest
|
|
55
|
+
}) {
|
|
56
|
+
let popupMountPoint;
|
|
57
|
+
popupMountPoint = document.getElementById(popupMountPointId);
|
|
58
|
+
if (!popupMountPoint) {
|
|
59
|
+
popupMountPoint = document.createElement('div');
|
|
60
|
+
popupMountPoint.id = popupMountPointId;
|
|
61
|
+
popupMountPoint.setAttribute('data-testid', 'preview-modal');
|
|
62
|
+
document.body.appendChild(popupMountPoint);
|
|
63
|
+
}
|
|
64
|
+
let Modal = await import('./index');
|
|
65
|
+
ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
|
|
66
|
+
locale: "en"
|
|
67
|
+
}, /*#__PURE__*/React.createElement(Modal.default, _extends({}, rest, {
|
|
68
|
+
onClose: _context => {
|
|
69
|
+
if (popupMountPoint) {
|
|
70
|
+
ReactDOM.unmountComponentAtNode(popupMountPoint);
|
|
71
|
+
}
|
|
72
|
+
if (onEmbedClose) {
|
|
73
|
+
onEmbedClose(_context);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}))), popupMountPoint);
|
|
77
|
+
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import Action from '../index';
|
|
4
|
-
import ReactDOM from 'react-dom';
|
|
5
|
-
import { IntlProvider } from 'react-intl-next';
|
|
6
4
|
import { useFlexibleUiAnalyticsContext } from '../../../../../../state/flexible-ui-context';
|
|
7
5
|
import { useSmartLinkAnalytics } from '../../../../../../state';
|
|
8
|
-
import
|
|
6
|
+
import { openPreviewModal } from '../../../../../EmbedModal/utils';
|
|
9
7
|
const PreviewAction = props => {
|
|
10
8
|
const {
|
|
11
9
|
appearance,
|
|
@@ -22,25 +20,15 @@ const PreviewAction = props => {
|
|
|
22
20
|
} = props;
|
|
23
21
|
const defaultAnalytics = useSmartLinkAnalytics(url, () => {});
|
|
24
22
|
const analytics = useFlexibleUiAnalyticsContext() || defaultAnalytics;
|
|
25
|
-
const EmbedIcon = {
|
|
26
|
-
icon: /*#__PURE__*/React.createElement(Icon, linkIcon),
|
|
27
|
-
isFlexibleUi: true
|
|
28
|
-
};
|
|
29
23
|
if (src && url) {
|
|
30
|
-
const embedModal = () =>
|
|
31
|
-
popupMountPointId: 'twp-editor-preview-iframe',
|
|
32
|
-
showModal: true,
|
|
33
|
-
iframeName: 'twp-editor-preview-iframe',
|
|
34
|
-
onClose: () => {},
|
|
35
|
-
download: downloadUrl,
|
|
36
|
-
icon: EmbedIcon,
|
|
37
|
-
providerName: providerName || 'Preview',
|
|
38
|
-
src,
|
|
24
|
+
const embedModal = () => openPreviewModal({
|
|
39
25
|
title,
|
|
40
|
-
|
|
26
|
+
providerName,
|
|
27
|
+
downloadUrl,
|
|
28
|
+
isSupportTheming,
|
|
41
29
|
analytics,
|
|
42
|
-
|
|
43
|
-
|
|
30
|
+
linkIcon,
|
|
31
|
+
src
|
|
44
32
|
});
|
|
45
33
|
const action = {
|
|
46
34
|
...props,
|
|
@@ -60,41 +48,4 @@ const PreviewAction = props => {
|
|
|
60
48
|
return null;
|
|
61
49
|
}
|
|
62
50
|
};
|
|
63
|
-
|
|
64
|
-
/*
|
|
65
|
-
Explanatory note:
|
|
66
|
-
Actions don't have access to the react tree of whatever is rendered them
|
|
67
|
-
(and this concept is fraught inside editor anyway) so we want to ensure
|
|
68
|
-
it is mounting to a new unique place. This function manages that, including
|
|
69
|
-
creating an element if it doesn't exist, as well as tidying up the react tree
|
|
70
|
-
(but not the element) upon closing the modal.
|
|
71
|
-
|
|
72
|
-
This may strike you as really uncomfortable as you read it, so I wanted to note
|
|
73
|
-
that a) this was discussed and agreed upon, and b) it's definitely odd, and if
|
|
74
|
-
you find an elegant solution around this, you should definitely feel free to
|
|
75
|
-
refactor it.
|
|
76
|
-
*/
|
|
77
|
-
export async function previewFunction({
|
|
78
|
-
popupMountPointId,
|
|
79
|
-
...rest
|
|
80
|
-
}) {
|
|
81
|
-
let popupMountPoint;
|
|
82
|
-
popupMountPoint = document.getElementById(popupMountPointId);
|
|
83
|
-
if (!popupMountPoint) {
|
|
84
|
-
popupMountPoint = document.createElement('div');
|
|
85
|
-
popupMountPoint.id = popupMountPointId;
|
|
86
|
-
popupMountPoint.setAttribute('data-testid', 'preview-modal');
|
|
87
|
-
document.body.appendChild(popupMountPoint);
|
|
88
|
-
}
|
|
89
|
-
let Modal = await import('../../../../../EmbedModal');
|
|
90
|
-
ReactDOM.render( /*#__PURE__*/React.createElement(IntlProvider, {
|
|
91
|
-
locale: "en"
|
|
92
|
-
}, /*#__PURE__*/React.createElement(Modal.default, _extends({}, rest, {
|
|
93
|
-
onClose: _context => {
|
|
94
|
-
if (popupMountPoint) {
|
|
95
|
-
ReactDOM.unmountComponentAtNode(popupMountPoint);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}))), popupMountPoint);
|
|
99
|
-
}
|
|
100
51
|
export default PreviewAction;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
/** @jsx jsx */
|
|
3
3
|
import { jsx } from '@emotion/react';
|
|
4
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
4
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
5
|
import DropdownMenu, { DropdownItemGroup } from '@atlaskit/dropdown-menu';
|
|
6
6
|
import LozengeActionItem from './lozenge-action-item';
|
|
7
7
|
import LozengeActionTrigger from './lozenge-action-trigger';
|
|
@@ -24,13 +24,29 @@ const LozengeAction = ({
|
|
|
24
24
|
text,
|
|
25
25
|
zIndex
|
|
26
26
|
}) => {
|
|
27
|
+
var _action$update;
|
|
28
|
+
const [selected, setSelected] = useState({
|
|
29
|
+
appearance,
|
|
30
|
+
text
|
|
31
|
+
});
|
|
27
32
|
const [isLoaded, setIsLoaded] = useState(false);
|
|
28
33
|
const [isLoading, setIsLoading] = useState(false);
|
|
29
34
|
const [isOpen, setIsOpen] = useState(false);
|
|
30
35
|
const [items, setItems] = useState();
|
|
31
36
|
const [errorMessage, setErrorMessage] = useState();
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
setSelected({
|
|
39
|
+
text,
|
|
40
|
+
appearance
|
|
41
|
+
});
|
|
42
|
+
}, [text, appearance]);
|
|
32
43
|
const invoke = useInvoke();
|
|
33
44
|
const reload = useResolve();
|
|
45
|
+
const {
|
|
46
|
+
url,
|
|
47
|
+
id: linkId,
|
|
48
|
+
previewData
|
|
49
|
+
} = (action === null || action === void 0 ? void 0 : (_action$update = action.update) === null || _action$update === void 0 ? void 0 : _action$update.details) || {};
|
|
34
50
|
const handleOpenChange = useCallback(async args => {
|
|
35
51
|
setIsOpen(args.isOpen);
|
|
36
52
|
if (args.isOpen && !isLoaded && action !== null && action !== void 0 && action.read) {
|
|
@@ -56,25 +72,25 @@ const LozengeAction = ({
|
|
|
56
72
|
}
|
|
57
73
|
}, [action === null || action === void 0 ? void 0 : action.read, invoke, isLoaded, text]);
|
|
58
74
|
const trigger = useCallback(props => jsx(LozengeActionTrigger, _extends({}, props, {
|
|
59
|
-
appearance: appearance,
|
|
75
|
+
appearance: selected.appearance,
|
|
60
76
|
testId: testId,
|
|
61
|
-
text: text
|
|
62
|
-
})), [
|
|
63
|
-
const handleItemClick = useCallback(async id => {
|
|
77
|
+
text: selected.text
|
|
78
|
+
})), [testId, selected]);
|
|
79
|
+
const handleItemClick = useCallback(async (id, text, appearance) => {
|
|
64
80
|
try {
|
|
65
81
|
const updateAction = action === null || action === void 0 ? void 0 : action.update;
|
|
66
82
|
if (updateAction && id) {
|
|
67
83
|
setIsLoading(true);
|
|
68
84
|
const request = createStatusUpdateRequest(updateAction, id);
|
|
69
85
|
await invoke(request);
|
|
86
|
+
setSelected({
|
|
87
|
+
appearance,
|
|
88
|
+
text
|
|
89
|
+
});
|
|
70
90
|
setIsLoading(false);
|
|
71
91
|
setIsLoaded(false);
|
|
72
92
|
setIsOpen(false);
|
|
73
93
|
setItems([]);
|
|
74
|
-
const {
|
|
75
|
-
url,
|
|
76
|
-
id: linkId
|
|
77
|
-
} = updateAction.details || {};
|
|
78
94
|
if (url) {
|
|
79
95
|
await reload(url, true, undefined, linkId);
|
|
80
96
|
}
|
|
@@ -87,12 +103,14 @@ const LozengeAction = ({
|
|
|
87
103
|
setErrorMessage(LozengeActionErrorMessages.updateFailed);
|
|
88
104
|
}
|
|
89
105
|
}
|
|
90
|
-
}, [action === null || action === void 0 ? void 0 : action.update, invoke, reload]);
|
|
106
|
+
}, [action === null || action === void 0 ? void 0 : action.update, invoke, linkId, reload, url]);
|
|
91
107
|
const dropdownItemGroup = useMemo(() => {
|
|
92
108
|
if (errorMessage) {
|
|
93
109
|
return jsx(LozengeActionError, {
|
|
94
110
|
errorMessage: errorMessage,
|
|
95
|
-
testId: testId
|
|
111
|
+
testId: testId,
|
|
112
|
+
url: url,
|
|
113
|
+
previewData: previewData
|
|
96
114
|
});
|
|
97
115
|
}
|
|
98
116
|
if (items && items.length > 0) {
|
|
@@ -105,7 +123,7 @@ const LozengeAction = ({
|
|
|
105
123
|
testId: `${testId}-item-${idx}`
|
|
106
124
|
})))));
|
|
107
125
|
}
|
|
108
|
-
}, [errorMessage, handleItemClick, items, testId]);
|
|
126
|
+
}, [errorMessage, handleItemClick, items, previewData, testId, url]);
|
|
109
127
|
return jsx(DropdownMenu, {
|
|
110
128
|
isLoading: isLoading,
|
|
111
129
|
isOpen: isOpen,
|
package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-error/index.js
CHANGED
|
@@ -1,17 +1,41 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import { jsx } from '@emotion/react';
|
|
3
|
-
import { Fragment, useMemo } from 'react';
|
|
3
|
+
import { Fragment, useMemo, useCallback } from 'react';
|
|
4
|
+
import { FormattedMessage } from 'react-intl-next';
|
|
4
5
|
import { DropdownItem, DropdownItemGroup } from '@atlaskit/dropdown-menu';
|
|
5
6
|
import { R50, R500 } from '@atlaskit/theme/colors';
|
|
6
7
|
import ErrorIcon from '@atlaskit/icon/glyph/error';
|
|
7
|
-
import { dropdownItemGroupStyles, contentStyles, textStyles } from './styled';
|
|
8
|
+
import { dropdownItemGroupStyles, contentStyles, linkStyles, textStyles } from './styled';
|
|
8
9
|
import { getFormattedMessage } from '../../../utils';
|
|
10
|
+
import { messages } from '../../../../../../messages';
|
|
11
|
+
import { useFlexibleUiAnalyticsContext } from '../../../../../../state/flexible-ui-context';
|
|
12
|
+
import { openPreviewModal } from '../../../../../EmbedModal/utils';
|
|
13
|
+
import useResolve from '../../../../../../state/hooks/use-resolve';
|
|
9
14
|
const MAX_LINE_NUMBER = 8;
|
|
10
15
|
const LozengeActionError = ({
|
|
11
16
|
errorMessage,
|
|
12
17
|
testId,
|
|
13
|
-
maxLineNumber = MAX_LINE_NUMBER
|
|
18
|
+
maxLineNumber = MAX_LINE_NUMBER,
|
|
19
|
+
url,
|
|
20
|
+
previewData
|
|
14
21
|
}) => {
|
|
22
|
+
const reload = useResolve();
|
|
23
|
+
const analytics = useFlexibleUiAnalyticsContext();
|
|
24
|
+
const isPreviewAvailable = previewData && previewData.src !== undefined;
|
|
25
|
+
const handlePreviewClose = useCallback(() => {
|
|
26
|
+
if (url) {
|
|
27
|
+
reload(url, true);
|
|
28
|
+
}
|
|
29
|
+
}, [reload, url]);
|
|
30
|
+
const handlePreviewOpen = useCallback(() => {
|
|
31
|
+
if (isPreviewAvailable) {
|
|
32
|
+
return openPreviewModal({
|
|
33
|
+
...previewData,
|
|
34
|
+
analytics,
|
|
35
|
+
onClose: handlePreviewClose
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, [analytics, handlePreviewClose, isPreviewAvailable, previewData]);
|
|
15
39
|
const content = useMemo(() => {
|
|
16
40
|
return jsx(Fragment, null, jsx("div", {
|
|
17
41
|
css: contentStyles
|
|
@@ -24,8 +48,14 @@ const LozengeActionError = ({
|
|
|
24
48
|
}), jsx("span", {
|
|
25
49
|
css: textStyles(maxLineNumber),
|
|
26
50
|
"data-testid": `${testId}-error-message`
|
|
27
|
-
}, typeof errorMessage === 'string' ? errorMessage : getFormattedMessage(errorMessage)))
|
|
28
|
-
|
|
51
|
+
}, typeof errorMessage === 'string' ? errorMessage : getFormattedMessage(errorMessage))), isPreviewAvailable ? jsx("div", {
|
|
52
|
+
css: linkStyles
|
|
53
|
+
}, jsx("a", {
|
|
54
|
+
target: "_blank",
|
|
55
|
+
"data-testid": `${testId}-open-embed`,
|
|
56
|
+
onClick: handlePreviewOpen
|
|
57
|
+
}, jsx(FormattedMessage, messages.open_issue_in_jira))) : null);
|
|
58
|
+
}, [errorMessage, handlePreviewOpen, isPreviewAvailable, maxLineNumber, testId]);
|
|
29
59
|
return jsx("span", {
|
|
30
60
|
css: dropdownItemGroupStyles,
|
|
31
61
|
"data-testid": `${testId}-error-item-group`
|
|
@@ -23,7 +23,7 @@ const sharedBlockStyles = css`
|
|
|
23
23
|
export const contentStyles = css`
|
|
24
24
|
${sharedBlockStyles};
|
|
25
25
|
|
|
26
|
-
margin-top: 2px;
|
|
26
|
+
margin-top: ${"var(--ds-space-025, 2px)"};
|
|
27
27
|
align-items: flex-start;
|
|
28
28
|
|
|
29
29
|
> span,
|
|
@@ -34,6 +34,14 @@ export const contentStyles = css`
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
`;
|
|
37
|
+
export const linkStyles = css`
|
|
38
|
+
${sharedBlockStyles};
|
|
39
|
+
|
|
40
|
+
font-size: 0.875rem;
|
|
41
|
+
margin-top: 10px;
|
|
42
|
+
margin-left: ${"var(--ds-space-400, 32px)"};
|
|
43
|
+
margin-bottom: ${"var(--ds-space-025, 2px)"};
|
|
44
|
+
`;
|
|
37
45
|
export const textStyles = maxLines => css`
|
|
38
46
|
line-height: 1rem;
|
|
39
47
|
white-space: normal;
|
package/dist/es2019/view/FlexibleCard/components/common/lozenge-action/lozenge-action-item/index.js
CHANGED
|
@@ -13,9 +13,9 @@ const LozengeActionItem = ({
|
|
|
13
13
|
// We want to show loading screen.
|
|
14
14
|
e.stopPropagation();
|
|
15
15
|
if (onClick) {
|
|
16
|
-
onClick(id);
|
|
16
|
+
onClick(id, text, appearance);
|
|
17
17
|
}
|
|
18
|
-
}, [id, onClick]);
|
|
18
|
+
}, [appearance, id, onClick, text]);
|
|
19
19
|
const handleMouseEnter = useCallback(e => {
|
|
20
20
|
var _e$currentTarget, _e$currentTarget$firs;
|
|
21
21
|
(_e$currentTarget = e.currentTarget) === null || _e$currentTarget === void 0 ? void 0 : (_e$currentTarget$firs = _e$currentTarget.firstElementChild) === null || _e$currentTarget$firs === void 0 ? void 0 : _e$currentTarget$firs.focus();
|
|
@@ -5,6 +5,7 @@ import { extractLozenge } from '../common/lozenge';
|
|
|
5
5
|
import { getExtensionKey } from '../../state/helpers';
|
|
6
6
|
import extractServerAction from './extract-server-action';
|
|
7
7
|
import { extractLink } from '@atlaskit/linking-common/extractors';
|
|
8
|
+
import { extractPreviewAction } from './actions/extract-preview-action';
|
|
8
9
|
var toInvokeRequest = function toInvokeRequest(extensionKey, resourceIdentifiers, actionType, details) {
|
|
9
10
|
if (!actionType) {
|
|
10
11
|
return;
|
|
@@ -34,9 +35,11 @@ var extractAction = function extractAction(response, id) {
|
|
|
34
35
|
}
|
|
35
36
|
var read = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataRetrieval = action.dataRetrievalAction) === null || _action$dataRetrieval === void 0 ? void 0 : _action$dataRetrieval.name);
|
|
36
37
|
var url = extractLink(data);
|
|
38
|
+
var previewData = response ? extractPreviewAction(response) : null;
|
|
37
39
|
var details = {
|
|
38
40
|
id: id,
|
|
39
|
-
url: url
|
|
41
|
+
url: url,
|
|
42
|
+
previewData: previewData
|
|
40
43
|
};
|
|
41
44
|
var update = toInvokeRequest(extensionKey, action.resourceIdentifiers, (_action$dataUpdateAct = action.dataUpdateAction) === null || _action$dataUpdateAct === void 0 ? void 0 : _action$dataUpdateAct.name, details);
|
|
42
45
|
return read || update ? {
|
package/dist/esm/version.json
CHANGED
|
@@ -14,23 +14,23 @@ var withAnalytics = function withAnalytics(Component) {
|
|
|
14
14
|
onResize = props.onResize,
|
|
15
15
|
origin = props.origin;
|
|
16
16
|
var handleOnOpen = useCallback(function (context) {
|
|
17
|
-
analytics.screen.modalViewedEvent({
|
|
17
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.screen.modalViewedEvent({
|
|
18
18
|
name: 'embedPreviewModal',
|
|
19
19
|
attributes: {
|
|
20
20
|
origin: origin,
|
|
21
21
|
size: context.size
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
|
-
analytics.ui.renderSuccessEvent({
|
|
24
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderSuccessEvent({
|
|
25
25
|
status: 'resolved',
|
|
26
26
|
display: CardDisplay.EmbedPreview
|
|
27
27
|
});
|
|
28
28
|
if (onOpen) {
|
|
29
29
|
onOpen(context);
|
|
30
30
|
}
|
|
31
|
-
}, [analytics.screen, analytics.ui, onOpen, origin]);
|
|
31
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.screen, analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpen, origin]);
|
|
32
32
|
var handleOnOpenFailed = useCallback(function (error, errorInfo) {
|
|
33
|
-
analytics.ui.renderFailedEvent({
|
|
33
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.renderFailedEvent({
|
|
34
34
|
display: CardDisplay.EmbedPreview,
|
|
35
35
|
error: error,
|
|
36
36
|
errorInfo: errorInfo
|
|
@@ -38,9 +38,9 @@ var withAnalytics = function withAnalytics(Component) {
|
|
|
38
38
|
if (onOpenFailed) {
|
|
39
39
|
onOpenFailed(error, errorInfo);
|
|
40
40
|
}
|
|
41
|
-
}, [analytics.ui, onOpenFailed]);
|
|
41
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onOpenFailed]);
|
|
42
42
|
var handleOnClose = useCallback(function (context) {
|
|
43
|
-
analytics.ui.modalClosedEvent({
|
|
43
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.modalClosedEvent({
|
|
44
44
|
actionSubjectId: 'embedPreview',
|
|
45
45
|
attributes: {
|
|
46
46
|
origin: origin,
|
|
@@ -51,9 +51,9 @@ var withAnalytics = function withAnalytics(Component) {
|
|
|
51
51
|
if (onClose) {
|
|
52
52
|
onClose(context);
|
|
53
53
|
}
|
|
54
|
-
}, [analytics.ui, onClose, origin]);
|
|
54
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onClose, origin]);
|
|
55
55
|
var handleOnResize = useCallback(function (context) {
|
|
56
|
-
analytics.ui.buttonClickedEvent({
|
|
56
|
+
analytics === null || analytics === void 0 ? void 0 : analytics.ui.buttonClickedEvent({
|
|
57
57
|
actionSubjectId: 'embedPreviewResize',
|
|
58
58
|
attributes: {
|
|
59
59
|
newSize: context.size,
|
|
@@ -64,7 +64,7 @@ var withAnalytics = function withAnalytics(Component) {
|
|
|
64
64
|
if (onResize) {
|
|
65
65
|
onResize(context);
|
|
66
66
|
}
|
|
67
|
-
}, [analytics.ui, onResize, origin]);
|
|
67
|
+
}, [analytics === null || analytics === void 0 ? void 0 : analytics.ui, onResize, origin]);
|
|
68
68
|
return /*#__PURE__*/React.createElement(Component, _extends({}, props, {
|
|
69
69
|
onClose: handleOnClose,
|
|
70
70
|
onOpen: handleOnOpen,
|