@atlaskit/smart-card 22.4.0 → 23.0.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,17 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 23.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`3b30fc47274`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3b30fc47274) - Smart Link card state fix relating to an issue with returning old state if url changes to the one already present in the store.
8
+
9
+ ## 23.0.0
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 22.4.0
4
16
 
5
17
  ### Minor Changes
@@ -20,20 +20,22 @@ function useSmartCardState(url) {
20
20
  store = _useSmartLinkContext.store; // Initially, card state should be pending and 'empty'.
21
21
 
22
22
 
23
- var _useState = (0, _react.useState)((0, _linkingCommon.getUrl)(store, url)),
23
+ var newCardState = (0, _linkingCommon.getUrl)(store, url);
24
+
25
+ var _useState = (0, _react.useState)(newCardState),
24
26
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
25
- state = _useState2[0],
26
- setState = _useState2[1]; // Selector for initial and subsequent states.
27
+ setCardState = _useState2[1]; // Selector for initial and subsequent states.
27
28
 
28
29
 
29
30
  (0, _react.useEffect)(function () {
30
31
  var unsubscribe = store.subscribe(function () {
31
- setState((0, _linkingCommon.getUrl)(store, url));
32
+ // forcing re-renders when the store changes
33
+ setCardState((0, _linkingCommon.getUrl)(store, url));
32
34
  });
33
35
  return function () {
34
36
  return unsubscribe();
35
37
  };
36
- }, [url, store]); // State for use in view components.
38
+ }, [url, store]); // Returning fresh state for use in view components. Added as a part of the fix in EDM-4422.
37
39
 
38
- return state;
40
+ return newCardState;
39
41
  }
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.waitFor = exports.mocks = exports.mockContext = exports.mockAnalytics = exports.fakeResponse = exports.fakeFactory = void 0;
8
+ exports.waitFor = exports.mocks = exports.mockContext = exports.mockByUrl = exports.mockAnalytics = exports.fakeResponse = exports.fakeFactory = void 0;
9
9
 
10
10
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
11
 
@@ -33,6 +33,40 @@ var mockContext = {
33
33
  schema: 'http://schema.org/'
34
34
  };
35
35
  exports.mockContext = mockContext;
36
+
37
+ var mockByUrl = function mockByUrl(url) {
38
+ return {
39
+ meta: {
40
+ visibility: 'public',
41
+ access: 'granted',
42
+ auth: [],
43
+ definitionId: 'd1',
44
+ key: 'object-provider'
45
+ },
46
+ data: {
47
+ '@context': {
48
+ '@vocab': 'https://www.w3.org/ns/activitystreams#',
49
+ atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
50
+ schema: 'http://schema.org/'
51
+ },
52
+ '@type': 'Object',
53
+ name: url,
54
+ summary: 'Here is your serving of cheese: 🧀',
55
+ 'schema:potentialAction': {
56
+ '@id': 'comment',
57
+ '@type': 'CommentAction',
58
+ identifier: 'object-provider',
59
+ name: 'Comment'
60
+ },
61
+ preview: {
62
+ href: 'https://www.ilovecheese.com'
63
+ },
64
+ url: url
65
+ }
66
+ };
67
+ };
68
+
69
+ exports.mockByUrl = mockByUrl;
36
70
  var mocks = {
37
71
  success: {
38
72
  meta: {
@@ -174,13 +208,13 @@ var fakeFactory = function fakeFactory(implementation, implementationPost, imple
174
208
  (0, _createClass2.default)(CustomClient, [{
175
209
  key: "fetchData",
176
210
  value: function () {
177
- var _fetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
211
+ var _fetchData = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(url) {
178
212
  return _regenerator.default.wrap(function _callee$(_context) {
179
213
  while (1) {
180
214
  switch (_context.prev = _context.next) {
181
215
  case 0:
182
216
  _context.next = 2;
183
- return implementation();
217
+ return implementation(url);
184
218
 
185
219
  case 2:
186
220
  return _context.abrupt("return", _context.sent);
@@ -193,7 +227,7 @@ var fakeFactory = function fakeFactory(implementation, implementationPost, imple
193
227
  }, _callee);
194
228
  }));
195
229
 
196
- function fetchData() {
230
+ function fetchData(_x) {
197
231
  return _fetchData.apply(this, arguments);
198
232
  }
199
233
 
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "22.4.0",
3
+ "version": "23.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -6,14 +6,16 @@ export function useSmartCardState(url) {
6
6
  store
7
7
  } = useSmartLinkContext(); // Initially, card state should be pending and 'empty'.
8
8
 
9
- const [state, setState] = useState(getUrl(store, url)); // Selector for initial and subsequent states.
9
+ const newCardState = getUrl(store, url);
10
+ const [, setCardState] = useState(newCardState); // Selector for initial and subsequent states.
10
11
 
11
12
  useEffect(() => {
12
13
  const unsubscribe = store.subscribe(() => {
13
- setState(getUrl(store, url));
14
+ // forcing re-renders when the store changes
15
+ setCardState(getUrl(store, url));
14
16
  });
15
17
  return () => unsubscribe();
16
- }, [url, store]); // State for use in view components.
18
+ }, [url, store]); // Returning fresh state for use in view components. Added as a part of the fix in EDM-4422.
17
19
 
18
- return state;
20
+ return newCardState;
19
21
  }
@@ -4,6 +4,37 @@ export const mockContext = {
4
4
  atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
5
5
  schema: 'http://schema.org/'
6
6
  };
7
+ export const mockByUrl = url => {
8
+ return {
9
+ meta: {
10
+ visibility: 'public',
11
+ access: 'granted',
12
+ auth: [],
13
+ definitionId: 'd1',
14
+ key: 'object-provider'
15
+ },
16
+ data: {
17
+ '@context': {
18
+ '@vocab': 'https://www.w3.org/ns/activitystreams#',
19
+ atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
20
+ schema: 'http://schema.org/'
21
+ },
22
+ '@type': 'Object',
23
+ name: url,
24
+ summary: 'Here is your serving of cheese: 🧀',
25
+ 'schema:potentialAction': {
26
+ '@id': 'comment',
27
+ '@type': 'CommentAction',
28
+ identifier: 'object-provider',
29
+ name: 'Comment'
30
+ },
31
+ preview: {
32
+ href: 'https://www.ilovecheese.com'
33
+ },
34
+ url: url
35
+ }
36
+ };
37
+ };
7
38
  export const mocks = {
8
39
  success: {
9
40
  meta: {
@@ -125,8 +156,8 @@ export const mocks = {
125
156
  };
126
157
  export const fakeResponse = () => Promise.resolve(mocks.success);
127
158
  export const fakeFactory = (implementation, implementationPost, implementationPrefetch) => class CustomClient extends CardClient {
128
- async fetchData() {
129
- return await implementation();
159
+ async fetchData(url) {
160
+ return await implementation(url);
130
161
  }
131
162
 
132
163
  async postData() {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "22.4.0",
3
+ "version": "23.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -7,20 +7,22 @@ export function useSmartCardState(url) {
7
7
  store = _useSmartLinkContext.store; // Initially, card state should be pending and 'empty'.
8
8
 
9
9
 
10
- var _useState = useState(getUrl(store, url)),
10
+ var newCardState = getUrl(store, url);
11
+
12
+ var _useState = useState(newCardState),
11
13
  _useState2 = _slicedToArray(_useState, 2),
12
- state = _useState2[0],
13
- setState = _useState2[1]; // Selector for initial and subsequent states.
14
+ setCardState = _useState2[1]; // Selector for initial and subsequent states.
14
15
 
15
16
 
16
17
  useEffect(function () {
17
18
  var unsubscribe = store.subscribe(function () {
18
- setState(getUrl(store, url));
19
+ // forcing re-renders when the store changes
20
+ setCardState(getUrl(store, url));
19
21
  });
20
22
  return function () {
21
23
  return unsubscribe();
22
24
  };
23
- }, [url, store]); // State for use in view components.
25
+ }, [url, store]); // Returning fresh state for use in view components. Added as a part of the fix in EDM-4422.
24
26
 
25
- return state;
27
+ return newCardState;
26
28
  }
@@ -16,6 +16,37 @@ export var mockContext = {
16
16
  atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
17
17
  schema: 'http://schema.org/'
18
18
  };
19
+ export var mockByUrl = function mockByUrl(url) {
20
+ return {
21
+ meta: {
22
+ visibility: 'public',
23
+ access: 'granted',
24
+ auth: [],
25
+ definitionId: 'd1',
26
+ key: 'object-provider'
27
+ },
28
+ data: {
29
+ '@context': {
30
+ '@vocab': 'https://www.w3.org/ns/activitystreams#',
31
+ atlassian: 'https://schema.atlassian.com/ns/vocabulary#',
32
+ schema: 'http://schema.org/'
33
+ },
34
+ '@type': 'Object',
35
+ name: url,
36
+ summary: 'Here is your serving of cheese: 🧀',
37
+ 'schema:potentialAction': {
38
+ '@id': 'comment',
39
+ '@type': 'CommentAction',
40
+ identifier: 'object-provider',
41
+ name: 'Comment'
42
+ },
43
+ preview: {
44
+ href: 'https://www.ilovecheese.com'
45
+ },
46
+ url: url
47
+ }
48
+ };
49
+ };
19
50
  export var mocks = {
20
51
  success: {
21
52
  meta: {
@@ -153,13 +184,13 @@ export var fakeFactory = function fakeFactory(implementation, implementationPost
153
184
  _createClass(CustomClient, [{
154
185
  key: "fetchData",
155
186
  value: function () {
156
- var _fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
187
+ var _fetchData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
157
188
  return _regeneratorRuntime.wrap(function _callee$(_context) {
158
189
  while (1) {
159
190
  switch (_context.prev = _context.next) {
160
191
  case 0:
161
192
  _context.next = 2;
162
- return implementation();
193
+ return implementation(url);
163
194
 
164
195
  case 2:
165
196
  return _context.abrupt("return", _context.sent);
@@ -172,7 +203,7 @@ export var fakeFactory = function fakeFactory(implementation, implementationPost
172
203
  }, _callee);
173
204
  }));
174
205
 
175
- function fetchData() {
206
+ function fetchData(_x) {
176
207
  return _fetchData.apply(this, arguments);
177
208
  }
178
209
 
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "22.4.0",
3
+ "version": "23.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -4,6 +4,7 @@ export declare const mockContext: {
4
4
  readonly atlassian: "https://schema.atlassian.com/ns/vocabulary#";
5
5
  readonly schema: "http://schema.org/";
6
6
  };
7
+ export declare const mockByUrl: (url: string) => JsonLd.Response<JsonLd.Data.BaseData>;
7
8
  export declare const mocks: {
8
9
  success: JsonLd.Response<JsonLd.Data.BaseData>;
9
10
  notFound: JsonLd.Response<JsonLd.Data.BaseData>;
@@ -4,6 +4,7 @@ export declare const mockContext: {
4
4
  readonly atlassian: "https://schema.atlassian.com/ns/vocabulary#";
5
5
  readonly schema: "http://schema.org/";
6
6
  };
7
+ export declare const mockByUrl: (url: string) => JsonLd.Response<JsonLd.Data.BaseData>;
7
8
  export declare const mocks: {
8
9
  success: JsonLd.Response<JsonLd.Data.BaseData>;
9
10
  notFound: JsonLd.Response<JsonLd.Data.BaseData>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "22.4.0",
3
+ "version": "23.0.1",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -15,7 +15,8 @@
15
15
  "typesVersions": {
16
16
  ">=4.0 <4.5": {
17
17
  "*": [
18
- "dist/types-ts4.0/*"
18
+ "dist/types-ts4.0/*",
19
+ "dist/types-ts4.0/index.d.ts"
19
20
  ]
20
21
  }
21
22
  },
@@ -65,7 +66,7 @@
65
66
  "uuid": "^3.1.0"
66
67
  },
67
68
  "peerDependencies": {
68
- "@atlaskit/link-provider": "^1.2.9",
69
+ "@atlaskit/link-provider": "^1.3.0",
69
70
  "react": "^16.8.0",
70
71
  "react-dom": "^16.8.0",
71
72
  "react-intl-next": "npm:react-intl@^5.18.1"
package/report.api.md CHANGED
@@ -1,4 +1,4 @@
1
- <!-- API Report Version: 2.2 -->
1
+ <!-- API Report Version: 2.3 -->
2
2
 
3
3
  ## API Report File for "@atlaskit/smart-card"
4
4