@atlaskit/smart-card 18.0.21 → 18.0.22

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,12 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 18.0.22
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8b9f08cbc1c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8b9f08cbc1c) - [ux] Default representation for Slack links was changed from 'block' to 'inline'
8
+ - [`f4811ca8c6a`](https://bitbucket.org/atlassian/atlassian-frontend/commits/f4811ca8c6a) - add provider based metadata to hover previews
9
+
3
10
  ## 18.0.21
4
11
 
5
12
  ### Patch Changes
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.extractMetadata = void 0;
7
+
8
+ var _constants = require("../../constants");
9
+
10
+ var elementNamesToItems = function elementNamesToItems(elementNames) {
11
+ return elementNames.filter(function (element) {
12
+ return element in _constants.ElementName;
13
+ }).map(function (elementName) {
14
+ return {
15
+ name: elementName,
16
+ testId: "".concat(elementName.toLowerCase(), "-metadata-element")
17
+ };
18
+ });
19
+ };
20
+
21
+ var extractMetadata = function extractMetadata(jsonLd) {
22
+ var _jsonLd$metadata, _metadata$primary, _metadata$secondary;
23
+
24
+ var metadata = (_jsonLd$metadata = jsonLd.metadata) !== null && _jsonLd$metadata !== void 0 ? _jsonLd$metadata : [];
25
+ return {
26
+ primary: elementNamesToItems((_metadata$primary = metadata.primary) !== null && _metadata$primary !== void 0 ? _metadata$primary : []),
27
+ secondary: elementNamesToItems((_metadata$secondary = metadata.secondary) !== null && _metadata$secondary !== void 0 ? _metadata$secondary : [])
28
+ };
29
+ };
30
+
31
+ exports.extractMetadata = extractMetadata;
@@ -23,10 +23,6 @@ var isJwmView = function isJwmView(url) {
23
23
  return url.match(/^https:\/\/.*?\/jira\/core\/projects\/[^\/]+?\/(timeline|calendar|list|board)\/?/);
24
24
  };
25
25
 
26
- var isSlackMessage = function isSlackMessage(url) {
27
- return url.match(/^https:\/\/.+?\.slack\.com\/archives\/[CG][A-Z0-9]+\/p[0-9]+(\?.*)?$/);
28
- };
29
-
30
26
  var Transformer = /*#__PURE__*/function () {
31
27
  function Transformer() {
32
28
  (0, _classCallCheck2.default)(this, Transformer);
@@ -68,8 +64,6 @@ var Transformer = /*#__PURE__*/function () {
68
64
  value: function toAdf(url, appearance) {
69
65
  if (isJiraRoadMap(url) || isPolarisView(url) || isJwmView(url)) {
70
66
  return this.buildEmbedAdf(url);
71
- } else if (isSlackMessage(url)) {
72
- return this.buildBlockAdf(url);
73
67
  } else {
74
68
  switch (appearance) {
75
69
  case 'inline':
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "18.0.21",
3
+ "version": "18.0.22",
4
4
  "sideEffects": false
5
5
  }
@@ -41,6 +41,10 @@ var _analytics2 = require("../../state/analytics");
41
41
 
42
42
  var _helpers = require("../../state/helpers");
43
43
 
44
+ var _extractMetadata = require("../../extractors/hover/extractMetadata");
45
+
46
+ var _utils = require("./utils");
47
+
44
48
  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); }
45
49
 
46
50
  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; }
@@ -134,7 +138,9 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
134
138
  };
135
139
  }, [url, definitionId, extensionKey, analytics]);
136
140
 
137
- var cardComponent = function cardComponent() {
141
+ var CardComponent = function CardComponent() {
142
+ //TODO: EDM-3224 deleted simulated and use real JsonLd
143
+ var metadataElements = (0, _extractMetadata.extractMetadata)((0, _utils.getSimulatedMetadata)(extensionKey));
138
144
  return (0, _core.jsx)("div", {
139
145
  onMouseEnter: initShowCard,
140
146
  onMouseLeave: initHideCard,
@@ -148,6 +154,9 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
148
154
  }
149
155
  }, (0, _core.jsx)(_blocks.TitleBlock, {
150
156
  actions: [openAction]
157
+ }), (0, _core.jsx)(_blocks.MetadataBlock, {
158
+ primary: metadataElements.primary,
159
+ secondary: metadataElements.secondary
151
160
  }), (0, _core.jsx)(_blocks.SnippetBlock, null), (0, _core.jsx)(_blocks.FooterBlock, {
152
161
  actions: smartlinkActions
153
162
  })));
@@ -161,7 +170,7 @@ var HoverCardComponent = function HoverCardComponent(_ref) {
161
170
  isOpen: isOpen,
162
171
  onClose: onClose,
163
172
  placement: "bottom-start",
164
- content: cardComponent,
173
+ content: CardComponent,
165
174
  trigger: function trigger(triggerProps) {
166
175
  return (0, _core.jsx)("span", (0, _extends2.default)({}, triggerProps, {
167
176
  onMouseEnter: initShowCard,
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getSimulatedMetadata = void 0;
7
+
8
+ var getSimulatedMetadata = function getSimulatedMetadata(extensionKey) {
9
+ switch (extensionKey) {
10
+ case 'confluence-object-provider':
11
+ return {
12
+ metadata: {
13
+ primary: ['AuthorGroup', 'CreatedBy', 'CommentCount', 'ReactCount'],
14
+ secondary: []
15
+ }
16
+ };
17
+
18
+ case 'jira-object-provider':
19
+ return {
20
+ metadata: {
21
+ primary: ['AuthorGroup', 'State', 'Priority'],
22
+ secondary: []
23
+ }
24
+ };
25
+
26
+ default:
27
+ return {
28
+ metadata: {
29
+ primary: ['ModifiedOn'],
30
+ secondary: []
31
+ }
32
+ };
33
+ }
34
+ };
35
+
36
+ exports.getSimulatedMetadata = getSimulatedMetadata;
@@ -0,0 +1,18 @@
1
+ import { ElementName } from '../../constants';
2
+
3
+ const elementNamesToItems = elementNames => {
4
+ return elementNames.filter(element => element in ElementName).map(elementName => ({
5
+ name: elementName,
6
+ testId: `${elementName.toLowerCase()}-metadata-element`
7
+ }));
8
+ };
9
+
10
+ export const extractMetadata = jsonLd => {
11
+ var _jsonLd$metadata, _metadata$primary, _metadata$secondary;
12
+
13
+ const metadata = (_jsonLd$metadata = jsonLd.metadata) !== null && _jsonLd$metadata !== void 0 ? _jsonLd$metadata : [];
14
+ return {
15
+ primary: elementNamesToItems((_metadata$primary = metadata.primary) !== null && _metadata$primary !== void 0 ? _metadata$primary : []),
16
+ secondary: elementNamesToItems((_metadata$secondary = metadata.secondary) !== null && _metadata$secondary !== void 0 ? _metadata$secondary : [])
17
+ };
18
+ };
@@ -4,8 +4,6 @@ const isPolarisView = url => url.match(/^https:\/\/.*?\/jira\/polaris\/projects\
4
4
 
5
5
  const isJwmView = url => url.match(/^https:\/\/.*?\/jira\/core\/projects\/[^\/]+?\/(timeline|calendar|list|board)\/?/);
6
6
 
7
- const isSlackMessage = url => url.match(/^https:\/\/.+?\.slack\.com\/archives\/[CG][A-Z0-9]+\/p[0-9]+(\?.*)?$/);
8
-
9
7
  export class Transformer {
10
8
  buildInlineAdf(url) {
11
9
  return {
@@ -38,8 +36,6 @@ export class Transformer {
38
36
  toAdf(url, appearance) {
39
37
  if (isJiraRoadMap(url) || isPolarisView(url) || isJwmView(url)) {
40
38
  return this.buildEmbedAdf(url);
41
- } else if (isSlackMessage(url)) {
42
- return this.buildBlockAdf(url);
43
39
  } else {
44
40
  switch (appearance) {
45
41
  case 'inline':
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "18.0.21",
3
+ "version": "18.0.22",
4
4
  "sideEffects": false
5
5
  }
@@ -3,7 +3,7 @@ import _extends from "@babel/runtime/helpers/extends";
3
3
  /** @jsx jsx */
4
4
  import { jsx } from '@emotion/core';
5
5
  import React, { useCallback, useRef, useMemo } from 'react';
6
- import { TitleBlock, SnippetBlock, FooterBlock } from '../FlexibleCard/components/blocks';
6
+ import { TitleBlock, SnippetBlock, FooterBlock, MetadataBlock } from '../FlexibleCard/components/blocks';
7
7
  import { Card } from '../Card';
8
8
  import Popup from '@atlaskit/popup';
9
9
  import { SmartLinkSize, ActionName } from '../../constants';
@@ -15,6 +15,8 @@ import { fireSmartLinkEvent } from '../../utils/analytics';
15
15
  import { useSmartCardState as useLinkState } from '../../state/store';
16
16
  import { useSmartLinkAnalytics } from '../../state/analytics';
17
17
  import { getExtensionKey, getDefinitionId } from '../../state/helpers';
18
+ import { extractMetadata } from '../../extractors/hover/extractMetadata';
19
+ import { getSimulatedMetadata } from './utils';
18
20
  export const HoverCardComponent = ({
19
21
  children,
20
22
  url,
@@ -89,22 +91,29 @@ export const HoverCardComponent = ({
89
91
  };
90
92
  }, [url, definitionId, extensionKey, analytics]);
91
93
 
92
- const cardComponent = () => jsx("div", {
93
- onMouseEnter: initShowCard,
94
- onMouseLeave: initHideCard,
95
- css: HoverCardContainer
96
- }, jsx(Card, {
97
- appearance: "block",
98
- url: url,
99
- ui: {
100
- hideElevation: true,
101
- size: SmartLinkSize.Large
102
- }
103
- }, jsx(TitleBlock, {
104
- actions: [openAction]
105
- }), jsx(SnippetBlock, null), jsx(FooterBlock, {
106
- actions: smartlinkActions
107
- })));
94
+ const CardComponent = () => {
95
+ //TODO: EDM-3224 deleted simulated and use real JsonLd
96
+ const metadataElements = extractMetadata(getSimulatedMetadata(extensionKey));
97
+ return jsx("div", {
98
+ onMouseEnter: initShowCard,
99
+ onMouseLeave: initHideCard,
100
+ css: HoverCardContainer
101
+ }, jsx(Card, {
102
+ appearance: "block",
103
+ url: url,
104
+ ui: {
105
+ hideElevation: true,
106
+ size: SmartLinkSize.Large
107
+ }
108
+ }, jsx(TitleBlock, {
109
+ actions: [openAction]
110
+ }), jsx(MetadataBlock, {
111
+ primary: metadataElements.primary,
112
+ secondary: metadataElements.secondary
113
+ }), jsx(SnippetBlock, null), jsx(FooterBlock, {
114
+ actions: smartlinkActions
115
+ })));
116
+ };
108
117
 
109
118
  const onClose = useCallback(() => setIsOpen(false), []);
110
119
  return jsx(Popup, {
@@ -112,7 +121,7 @@ export const HoverCardComponent = ({
112
121
  isOpen: isOpen,
113
122
  onClose: onClose,
114
123
  placement: "bottom-start",
115
- content: cardComponent,
124
+ content: CardComponent,
116
125
  trigger: triggerProps => jsx("span", _extends({}, triggerProps, {
117
126
  onMouseEnter: initShowCard,
118
127
  onMouseLeave: initHideCard
@@ -0,0 +1,27 @@
1
+ export const getSimulatedMetadata = extensionKey => {
2
+ switch (extensionKey) {
3
+ case 'confluence-object-provider':
4
+ return {
5
+ metadata: {
6
+ primary: ['AuthorGroup', 'CreatedBy', 'CommentCount', 'ReactCount'],
7
+ secondary: []
8
+ }
9
+ };
10
+
11
+ case 'jira-object-provider':
12
+ return {
13
+ metadata: {
14
+ primary: ['AuthorGroup', 'State', 'Priority'],
15
+ secondary: []
16
+ }
17
+ };
18
+
19
+ default:
20
+ return {
21
+ metadata: {
22
+ primary: ['ModifiedOn'],
23
+ secondary: []
24
+ }
25
+ };
26
+ }
27
+ };
@@ -0,0 +1,22 @@
1
+ import { ElementName } from '../../constants';
2
+
3
+ var elementNamesToItems = function elementNamesToItems(elementNames) {
4
+ return elementNames.filter(function (element) {
5
+ return element in ElementName;
6
+ }).map(function (elementName) {
7
+ return {
8
+ name: elementName,
9
+ testId: "".concat(elementName.toLowerCase(), "-metadata-element")
10
+ };
11
+ });
12
+ };
13
+
14
+ export var extractMetadata = function extractMetadata(jsonLd) {
15
+ var _jsonLd$metadata, _metadata$primary, _metadata$secondary;
16
+
17
+ var metadata = (_jsonLd$metadata = jsonLd.metadata) !== null && _jsonLd$metadata !== void 0 ? _jsonLd$metadata : [];
18
+ return {
19
+ primary: elementNamesToItems((_metadata$primary = metadata.primary) !== null && _metadata$primary !== void 0 ? _metadata$primary : []),
20
+ secondary: elementNamesToItems((_metadata$secondary = metadata.secondary) !== null && _metadata$secondary !== void 0 ? _metadata$secondary : [])
21
+ };
22
+ };
@@ -13,10 +13,6 @@ var isJwmView = function isJwmView(url) {
13
13
  return url.match(/^https:\/\/.*?\/jira\/core\/projects\/[^\/]+?\/(timeline|calendar|list|board)\/?/);
14
14
  };
15
15
 
16
- var isSlackMessage = function isSlackMessage(url) {
17
- return url.match(/^https:\/\/.+?\.slack\.com\/archives\/[CG][A-Z0-9]+\/p[0-9]+(\?.*)?$/);
18
- };
19
-
20
16
  export var Transformer = /*#__PURE__*/function () {
21
17
  function Transformer() {
22
18
  _classCallCheck(this, Transformer);
@@ -58,8 +54,6 @@ export var Transformer = /*#__PURE__*/function () {
58
54
  value: function toAdf(url, appearance) {
59
55
  if (isJiraRoadMap(url) || isPolarisView(url) || isJwmView(url)) {
60
56
  return this.buildEmbedAdf(url);
61
- } else if (isSlackMessage(url)) {
62
- return this.buildBlockAdf(url);
63
57
  } else {
64
58
  switch (appearance) {
65
59
  case 'inline':
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "18.0.21",
3
+ "version": "18.0.22",
4
4
  "sideEffects": false
5
5
  }
@@ -4,7 +4,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  /** @jsx jsx */
5
5
  import { jsx } from '@emotion/core';
6
6
  import React, { useCallback, useRef, useMemo } from 'react';
7
- import { TitleBlock, SnippetBlock, FooterBlock } from '../FlexibleCard/components/blocks';
7
+ import { TitleBlock, SnippetBlock, FooterBlock, MetadataBlock } from '../FlexibleCard/components/blocks';
8
8
  import { Card } from '../Card';
9
9
  import Popup from '@atlaskit/popup';
10
10
  import { SmartLinkSize, ActionName } from '../../constants';
@@ -16,6 +16,8 @@ import { fireSmartLinkEvent } from '../../utils/analytics';
16
16
  import { useSmartCardState as useLinkState } from '../../state/store';
17
17
  import { useSmartLinkAnalytics } from '../../state/analytics';
18
18
  import { getExtensionKey, getDefinitionId } from '../../state/helpers';
19
+ import { extractMetadata } from '../../extractors/hover/extractMetadata';
20
+ import { getSimulatedMetadata } from './utils';
19
21
  export var HoverCardComponent = function HoverCardComponent(_ref) {
20
22
  var children = _ref.children,
21
23
  url = _ref.url,
@@ -104,7 +106,9 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
104
106
  };
105
107
  }, [url, definitionId, extensionKey, analytics]);
106
108
 
107
- var cardComponent = function cardComponent() {
109
+ var CardComponent = function CardComponent() {
110
+ //TODO: EDM-3224 deleted simulated and use real JsonLd
111
+ var metadataElements = extractMetadata(getSimulatedMetadata(extensionKey));
108
112
  return jsx("div", {
109
113
  onMouseEnter: initShowCard,
110
114
  onMouseLeave: initHideCard,
@@ -118,6 +122,9 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
118
122
  }
119
123
  }, jsx(TitleBlock, {
120
124
  actions: [openAction]
125
+ }), jsx(MetadataBlock, {
126
+ primary: metadataElements.primary,
127
+ secondary: metadataElements.secondary
121
128
  }), jsx(SnippetBlock, null), jsx(FooterBlock, {
122
129
  actions: smartlinkActions
123
130
  })));
@@ -131,7 +138,7 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
131
138
  isOpen: isOpen,
132
139
  onClose: onClose,
133
140
  placement: "bottom-start",
134
- content: cardComponent,
141
+ content: CardComponent,
135
142
  trigger: function trigger(triggerProps) {
136
143
  return jsx("span", _extends({}, triggerProps, {
137
144
  onMouseEnter: initShowCard,
@@ -0,0 +1,27 @@
1
+ export var getSimulatedMetadata = function getSimulatedMetadata(extensionKey) {
2
+ switch (extensionKey) {
3
+ case 'confluence-object-provider':
4
+ return {
5
+ metadata: {
6
+ primary: ['AuthorGroup', 'CreatedBy', 'CommentCount', 'ReactCount'],
7
+ secondary: []
8
+ }
9
+ };
10
+
11
+ case 'jira-object-provider':
12
+ return {
13
+ metadata: {
14
+ primary: ['AuthorGroup', 'State', 'Priority'],
15
+ secondary: []
16
+ }
17
+ };
18
+
19
+ default:
20
+ return {
21
+ metadata: {
22
+ primary: ['ModifiedOn'],
23
+ secondary: []
24
+ }
25
+ };
26
+ }
27
+ };
@@ -0,0 +1,3 @@
1
+ import { MetadataOptions } from '../../view/HoverCard/types';
2
+ import { JsonLd } from 'json-ld-types';
3
+ export declare const extractMetadata: (jsonLd: JsonLd.Primitives.Property<any>) => MetadataOptions;
@@ -1,6 +1,11 @@
1
1
  import { WithAnalyticsEventsProps } from '@atlaskit/analytics-next';
2
+ import { ElementItem } from '../FlexibleCard/components/blocks/types';
2
3
  export interface HoverCardProps extends WithAnalyticsEventsProps {
3
4
  url: string;
4
5
  }
5
6
  export declare type PreviewDisplay = 'card' | 'embed';
6
7
  export declare type PreviewInvokeMethod = 'keyboard' | 'mouse_hover' | 'mouse_click';
8
+ export interface MetadataOptions {
9
+ primary: Array<ElementItem>;
10
+ secondary: Array<ElementItem>;
11
+ }
@@ -0,0 +1,2 @@
1
+ import { JsonLd } from 'json-ld-types';
2
+ export declare const getSimulatedMetadata: (extensionKey: string) => JsonLd.Primitives.Property<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "18.0.21",
3
+ "version": "18.0.22",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"