@atlaskit/help 6.0.7 → 7.0.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 (32) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/components/Article/HelpArticle/index.js +6 -8
  3. package/dist/cjs/components/Article/index.js +2 -2
  4. package/dist/cjs/components/Help.js +3 -1
  5. package/dist/cjs/components/Search/SearchResults/index.js +8 -11
  6. package/dist/cjs/components/WhatsNew/WhatsNewButton/index.js +6 -8
  7. package/dist/cjs/components/WhatsNew/WhatsNewResults/WhatsNewResultsList/WhatsNewResultsList.js +1 -1
  8. package/dist/cjs/components/WhatsNew/WhatsNewResults/WhatsNewResultsList/index.js +6 -8
  9. package/dist/cjs/components/WhatsNew/WhatsNewResults/index.js +33 -6
  10. package/dist/cjs/components/contexts/navigationContext.js +111 -50
  11. package/dist/cjs/version.json +1 -1
  12. package/dist/es2019/components/Article/HelpArticle/index.js +6 -8
  13. package/dist/es2019/components/Search/SearchResults/index.js +6 -9
  14. package/dist/es2019/components/WhatsNew/WhatsNewButton/index.js +6 -8
  15. package/dist/es2019/components/WhatsNew/WhatsNewResults/WhatsNewResultsList/WhatsNewResultsList.js +1 -1
  16. package/dist/es2019/components/WhatsNew/WhatsNewResults/WhatsNewResultsList/index.js +6 -8
  17. package/dist/es2019/components/WhatsNew/WhatsNewResults/index.js +31 -5
  18. package/dist/es2019/components/contexts/navigationContext.js +99 -39
  19. package/dist/es2019/version.json +1 -1
  20. package/dist/esm/components/Article/HelpArticle/index.js +6 -8
  21. package/dist/esm/components/Article/index.js +2 -2
  22. package/dist/esm/components/Help.js +2 -1
  23. package/dist/esm/components/Search/SearchResults/index.js +8 -11
  24. package/dist/esm/components/WhatsNew/WhatsNewButton/index.js +6 -8
  25. package/dist/esm/components/WhatsNew/WhatsNewResults/WhatsNewResultsList/WhatsNewResultsList.js +1 -1
  26. package/dist/esm/components/WhatsNew/WhatsNewResults/WhatsNewResultsList/index.js +6 -8
  27. package/dist/esm/components/WhatsNew/WhatsNewResults/index.js +33 -7
  28. package/dist/esm/components/contexts/navigationContext.js +108 -50
  29. package/dist/esm/version.json +1 -1
  30. package/dist/types/components/contexts/navigationContext.d.ts +12 -7
  31. package/dist/types/model/Help.d.ts +8 -4
  32. package/package.json +5 -5
@@ -4,12 +4,15 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
5
5
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
6
6
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
7
+ var _excluded = ["body", "relatedArticles"],
8
+ _excluded2 = ["description"];
7
9
 
8
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
10
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
11
 
10
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
12
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
11
13
 
12
14
  import React, { useReducer, useEffect, useCallback, useMemo } from 'react';
15
+ import isEqual from 'lodash/isEqual';
13
16
  import { REQUEST_STATE } from '../../model/Requests';
14
17
  import { ARTICLE_TYPE } from '../../model/Help';
15
18
  import { createCtx } from '../../util/hooks/ctx';
@@ -19,6 +22,10 @@ import { useWhatsNewArticleContext } from './whatsNewArticleContext';
19
22
  import { useHomeContext } from './homeContext';
20
23
  import { useSearchContext } from './searchContext';
21
24
  import { useHeaderContext } from './headerContext';
25
+ var DEFAULT_ARTICLE_ID = {
26
+ id: '',
27
+ type: ARTICLE_TYPE.HELP_ARTICLE
28
+ };
22
29
 
23
30
  var _createCtx = createCtx(),
24
31
  _createCtx2 = _slicedToArray(_createCtx, 2),
@@ -56,6 +63,21 @@ var getSimpleHistory = function getSimpleHistory(history) {
56
63
  };
57
64
  });
58
65
  };
66
+ /**
67
+ * Get history data (list of IDs and UID)
68
+ */
69
+
70
+
71
+ var getHistoryData = function getHistoryData(history) {
72
+ return history.map(function (historyItem) {
73
+ var id = historyItem.id,
74
+ uid = historyItem.uid;
75
+ return {
76
+ id: id,
77
+ uid: uid
78
+ };
79
+ });
80
+ };
59
81
  /**
60
82
  * Get the last article in the history
61
83
  */
@@ -79,14 +101,14 @@ var getCurrentArticleItemSlim = function getCurrentArticleItemSlim(history) {
79
101
  var _ref = article,
80
102
  body = _ref.body,
81
103
  relatedArticles = _ref.relatedArticles,
82
- articleItemData = _objectWithoutProperties(_ref, ["body", "relatedArticles"]);
104
+ articleItemData = _objectWithoutProperties(_ref, _excluded);
83
105
 
84
106
  var currentArticleSlimData = articleItemData;
85
107
  return currentArticleSlimData;
86
108
  } else if (type === ARTICLE_TYPE.WHATS_NEW) {
87
109
  var _ref2 = article,
88
110
  description = _ref2.description,
89
- whatsNewArticleItemData = _objectWithoutProperties(_ref2, ["description"]);
111
+ whatsNewArticleItemData = _objectWithoutProperties(_ref2, _excluded2);
90
112
 
91
113
  var currentWhatsNewArticleSlimData = whatsNewArticleItemData;
92
114
  return currentWhatsNewArticleSlimData;
@@ -126,10 +148,26 @@ var navigationReducer = function navigationReducer(_ref3, action) {
126
148
 
127
149
  if (action.type === 'newArticle' && action.payload) {
128
150
  var newArticleId = action.payload;
151
+
152
+ if (isEqual(newArticleId, DEFAULT_ARTICLE_ID)) {
153
+ newState = {
154
+ articleId: newArticleId,
155
+ history: [],
156
+ view: VIEW.DEFAULT_CONTENT
157
+ };
158
+ } else {
159
+ newState = {
160
+ articleId: newArticleId,
161
+ history: [].concat(_toConsumableArray(currentHistory), [getNewHistoryItem(newArticleId.id, newArticleId.type)]),
162
+ view: getViewForArticleId(newArticleId)
163
+ };
164
+ }
165
+ } else if (action.type === 'addNewHistoryItem' && action.payload) {
166
+ var _newArticleId = action.payload;
129
167
  newState = {
130
- articleId: newArticleId,
131
- history: [].concat(_toConsumableArray(currentHistory), [getNewHistoryItem(newArticleId.id, newArticleId.type)]),
132
- view: getViewForArticleId(newArticleId)
168
+ articleId: currentArticleId,
169
+ history: [].concat(_toConsumableArray(currentHistory), [getNewHistoryItem(_newArticleId.id, _newArticleId.type)]),
170
+ view: getViewForArticleId(currentArticleId)
133
171
  };
134
172
  } else if (action.type === 'updateHistoryItem' && action.payload) {
135
173
  var HistoryItemUpdate = action.payload;
@@ -167,11 +205,11 @@ var navigationReducer = function navigationReducer(_ref3, action) {
167
205
  view: VIEW.DEFAULT_CONTENT
168
206
  };
169
207
  } else if (action.type === 'updateArticleId' && action.payload) {
170
- var _newArticleId = action.payload;
208
+ var _newArticleId2 = action.payload;
171
209
  newState = {
172
- articleId: _newArticleId,
210
+ articleId: _newArticleId2,
173
211
  history: currentHistory,
174
- view: getViewForArticleId(_newArticleId)
212
+ view: getViewForArticleId(_newArticleId2)
175
213
  };
176
214
  } else if (action.type === 'updateView' && action.payload) {
177
215
  var newView = action.payload;
@@ -186,15 +224,12 @@ var navigationReducer = function navigationReducer(_ref3, action) {
186
224
  };
187
225
 
188
226
  export var NavigationContextProvider = function NavigationContextProvider(_ref4) {
189
- var _ref4$articleId = _ref4.articleId,
190
- propsArticleId = _ref4$articleId === void 0 ? {
191
- id: '',
192
- type: ARTICLE_TYPE.HELP_ARTICLE
193
- } : _ref4$articleId,
194
- articleIdSetter = _ref4.articleIdSetter,
195
- _ref4$history = _ref4.history,
196
- propsHistory = _ref4$history === void 0 ? [] : _ref4$history,
197
- historySetter = _ref4.historySetter,
227
+ var _ref4$navigationData = _ref4.navigationData,
228
+ navigationData = _ref4$navigationData === void 0 ? {
229
+ articleId: DEFAULT_ARTICLE_ID,
230
+ history: []
231
+ } : _ref4$navigationData,
232
+ setNavigationData = _ref4.setNavigationData,
198
233
  children = _ref4.children;
199
234
 
200
235
  var _useHelpArticleContex = useHelpArticleContext(),
@@ -215,9 +250,12 @@ export var NavigationContextProvider = function NavigationContextProvider(_ref4)
215
250
  var _useHeaderContext = useHeaderContext(),
216
251
  onCloseButtonClick = _useHeaderContext.onCloseButtonClick;
217
252
 
253
+ var propsArticleId = navigationData.articleId,
254
+ propsHistory = navigationData.history;
255
+
218
256
  var _useReducer = useReducer(navigationReducer, {
219
257
  articleId: propsArticleId,
220
- history: propsHistory,
258
+ history: !isEqual(propsArticleId, DEFAULT_ARTICLE_ID) && propsHistory.length === 0 ? [getNewHistoryItem(propsArticleId.id, propsArticleId.type)] : propsHistory,
221
259
  view: VIEW.DEFAULT_CONTENT
222
260
  }),
223
261
  _useReducer2 = _slicedToArray(_useReducer, 2),
@@ -237,8 +275,6 @@ export var NavigationContextProvider = function NavigationContextProvider(_ref4)
237
275
  /**
238
276
  * - If default content isn't defined and the history only has one article,
239
277
  * we should not display the back button
240
- * - If the prop.article.setArticleId is not defined, we should also hide the back
241
- * button because we are not able to navigate though the history without it
242
278
  */
243
279
  if (currentHistory.length === 1 && !isDefaultContentDefined || currentView === VIEW.WHATS_NEW && !isDefaultContentDefined) {
244
280
  return false;
@@ -426,6 +462,12 @@ export var NavigationContextProvider = function NavigationContextProvider(_ref4)
426
462
  onCloseButtonClick(event, analyticsEvent);
427
463
  }
428
464
  }, [onCloseButtonClick]);
465
+ var onOpenArticle = useCallback(function (newArticleId) {
466
+ dispatchNavigationAction({
467
+ type: 'addNewHistoryItem',
468
+ payload: newArticleId
469
+ });
470
+ }, []);
429
471
  useEffect(function () {
430
472
  if (isSearchResultVisible) {
431
473
  dispatchNavigationAction({
@@ -435,43 +477,59 @@ export var NavigationContextProvider = function NavigationContextProvider(_ref4)
435
477
  }
436
478
  }, [isSearchResultVisible]);
437
479
  useEffect(function () {
438
- var simpleHistory = getSimpleHistory(currentHistory);
439
- historySetter && historySetter(simpleHistory);
440
- }, [historySetter, currentHistory]);
441
- useEffect(function () {
480
+ var lastHistoryItem = currentHistory.length > 0 ? _getCurrentArticle2(currentHistory) : getNewHistoryItem(DEFAULT_ARTICLE_ID.id, DEFAULT_ARTICLE_ID.type);
442
481
  /**
443
482
  * If the propsArticleId.id (host articleId) is different from currentArticleId.id (internal articleId)
444
- * it means the host updated propsArticleId and we need to use this new value to load a new article.
445
483
  * */
446
- if ((propsArticleId === null || propsArticleId === void 0 ? void 0 : propsArticleId.id) !== currentArticleId.id || (propsArticleId === null || propsArticleId === void 0 ? void 0 : propsArticleId.type) !== currentArticleId.type) {
447
- dispatchNavigationAction({
448
- type: 'newArticle',
449
- payload: propsArticleId
450
- });
451
- } else {
484
+
485
+ if (!isEqual(propsArticleId, currentArticleId)) {
452
486
  /**
453
- * If the propsArticleId.id (host articleId) is equal to currentArticleId.id (internal articleId)
454
- * and the id from the last history item is different from currentArticleId.id, it means the history
455
- * changed and we need to update the host articleId (propsArticleId) using 'articleIdSetter' and the local
456
- * history using the dispatchNavigationAction reducer
457
- * */
458
- var lastHistoryItem = currentHistory.length > 0 ? _getCurrentArticle2(currentHistory) : getNewHistoryItem('', ARTICLE_TYPE.HELP_ARTICLE);
459
-
460
- if (articleIdSetter && lastHistoryItem && (currentArticleId.id !== lastHistoryItem.id || currentArticleId.type !== lastHistoryItem.type)) {
487
+ * If propsArticleId and lastHistoryItem are the same, we just need to update the articleId
488
+ * because is out of sync
489
+ */
490
+ if (propsArticleId.id === lastHistoryItem.id && propsArticleId.type === lastHistoryItem.type) {
461
491
  dispatchNavigationAction({
462
492
  type: 'updateArticleId',
463
- payload: {
464
- id: lastHistoryItem.id,
465
- type: lastHistoryItem.type
466
- }
493
+ payload: propsArticleId
467
494
  });
468
- articleIdSetter({
469
- id: lastHistoryItem.id,
470
- type: lastHistoryItem.type
495
+ } else {
496
+ /**
497
+ * Otherwise we need to add a new article
498
+ */
499
+ dispatchNavigationAction({
500
+ type: 'newArticle',
501
+ payload: propsArticleId
471
502
  });
472
503
  }
504
+ } else {
505
+ // console.log('same articleId');
506
+ if (setNavigationData) {
507
+ var simpleHistory = getSimpleHistory(currentHistory);
508
+
509
+ if (currentArticleId.id !== lastHistoryItem.id || currentArticleId.type !== lastHistoryItem.type) {
510
+ /**
511
+ * If the propsArticleId.id (host articleId) is equal to currentArticleId.id (internal articleId)
512
+ * and the id from the last history item is different from currentArticleId.id, it means the history
513
+ * changed
514
+ * */
515
+ if (setNavigationData) {
516
+ setNavigationData({
517
+ articleId: {
518
+ id: lastHistoryItem.id,
519
+ type: lastHistoryItem.type
520
+ },
521
+ history: simpleHistory
522
+ });
523
+ }
524
+ } else if (!isEqual(getHistoryData(propsHistory), getHistoryData(currentHistory))) {
525
+ setNavigationData({
526
+ articleId: propsArticleId,
527
+ history: simpleHistory
528
+ });
529
+ }
530
+ }
473
531
  }
474
- }, [currentArticleId, propsArticleId, currentHistory, articleIdSetter]);
532
+ }, [currentArticleId, propsArticleId, currentHistory, setNavigationData, propsHistory]);
475
533
  useEffect(function () {
476
534
  var requestNewArticle = /*#__PURE__*/function () {
477
535
  var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(historyItem) {
@@ -517,7 +575,7 @@ export var NavigationContextProvider = function NavigationContextProvider(_ref4)
517
575
  value: {
518
576
  view: currentView,
519
577
  articleId: currentArticleId,
520
- setArticleId: articleIdSetter,
578
+ openArticle: onOpenArticle,
521
579
  history: currentHistory,
522
580
  getCurrentArticle: function getCurrentArticle() {
523
581
  return _getCurrentArticle2(currentHistory);
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/help",
3
- "version": "6.0.7",
3
+ "version": "7.0.2",
4
4
  "sideEffects": false
5
5
  }
@@ -5,14 +5,22 @@ import { WhatsNewArticleItem, WhatsNewArticle } from '../../model/WhatsNew';
5
5
  import { HistoryItem, articleId } from '../../model/Help';
6
6
  import { VIEW } from '../constants';
7
7
  declare type ViewType = keyof typeof VIEW;
8
- interface NavigationSharedInterface {
8
+ interface NavigationProviderInterface {
9
+ navigationData?: {
10
+ articleId: articleId;
11
+ history: HistoryItem[];
12
+ };
13
+ setNavigationData?(navigationData: {
14
+ articleId: articleId;
15
+ history: HistoryItem[];
16
+ }): void;
17
+ }
18
+ interface NavigationContextInterface {
9
19
  articleId?: articleId;
10
20
  history?: HistoryItem[];
11
21
  historySetter?(history: HistoryItem[]): void;
12
- }
13
- interface NavigationContextInterface extends NavigationSharedInterface {
14
22
  view: ViewType;
15
- setArticleId?(id: articleId): void;
23
+ openArticle(id: articleId): void;
16
24
  canNavigateBack: boolean;
17
25
  navigateBack?(): void;
18
26
  onGetArticle?(id: articleId): Promise<Article | WhatsNewArticle>;
@@ -23,9 +31,6 @@ interface NavigationContextInterface extends NavigationSharedInterface {
23
31
  isOverlayVisible: boolean;
24
32
  onClose?(event: React.MouseEvent<HTMLElement, MouseEvent>, analyticsEvent: UIAnalyticsEvent): void;
25
33
  }
26
- interface NavigationProviderInterface extends NavigationSharedInterface {
27
- articleIdSetter?(id: articleId): void;
28
- }
29
34
  export declare const useNavigationContext: () => NavigationContextInterface, CtxProvider: React.Provider<NavigationContextInterface | undefined>;
30
35
  export declare const NavigationContextProvider: React.FC<NavigationProviderInterface>;
31
36
  export {};
@@ -38,10 +38,14 @@ export interface Help {
38
38
  searchExternalUrl?: string;
39
39
  };
40
40
  navigation?: {
41
- articleId?: articleId;
42
- articleIdSetter?(id: articleId): void;
43
- history?: HistoryItem[];
44
- historySetter?(history: HistoryItem[]): void;
41
+ navigationData?: {
42
+ articleId: articleId;
43
+ history: HistoryItem[];
44
+ };
45
+ setNavigationData?(navigationData: {
46
+ articleId?: articleId;
47
+ history?: HistoryItem[];
48
+ }): void;
45
49
  };
46
50
  helpArticle?: {
47
51
  onGetHelpArticle?(articleId: articleId): Promise<Article>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/help",
3
- "version": "6.0.7",
3
+ "version": "7.0.2",
4
4
  "description": "A cross-product help component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -30,10 +30,10 @@
30
30
  "@atlaskit/analytics-next": "^8.0.0",
31
31
  "@atlaskit/button": "^16.1.0",
32
32
  "@atlaskit/checkbox": "^12.3.0",
33
- "@atlaskit/form": "^8.4.0",
33
+ "@atlaskit/form": "^8.5.0",
34
34
  "@atlaskit/help-article": "^4.0.0",
35
35
  "@atlaskit/help-layout": "^4.0.0",
36
- "@atlaskit/icon": "^21.9.0",
36
+ "@atlaskit/icon": "^21.10.0",
37
37
  "@atlaskit/item": "^12.0.0",
38
38
  "@atlaskit/notification-indicator": "^9.0.0",
39
39
  "@atlaskit/notification-log-client": "^6.0.0",
@@ -41,9 +41,9 @@
41
41
  "@atlaskit/section-message": "^6.1.0",
42
42
  "@atlaskit/select": "^15.0.0",
43
43
  "@atlaskit/spinner": "^15.1.0",
44
- "@atlaskit/textarea": "^4.2.0",
44
+ "@atlaskit/textarea": "^4.3.0",
45
45
  "@atlaskit/textfield": "^5.1.0",
46
- "@atlaskit/theme": "^12.0.0",
46
+ "@atlaskit/theme": "^12.1.0",
47
47
  "@atlaskit/tooltip": "^17.5.0",
48
48
  "@babel/runtime": "^7.0.0",
49
49
  "@emotion/core": "^10.0.9",