@atlaskit/help 6.0.8 → 7.0.0

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 (28) hide show
  1. package/CHANGELOG.md +6 -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/index.js +6 -8
  8. package/dist/cjs/components/WhatsNew/WhatsNewResults/index.js +2 -2
  9. package/dist/cjs/components/contexts/navigationContext.js +110 -49
  10. package/dist/cjs/version.json +1 -1
  11. package/dist/es2019/components/Article/HelpArticle/index.js +6 -8
  12. package/dist/es2019/components/Search/SearchResults/index.js +6 -9
  13. package/dist/es2019/components/WhatsNew/WhatsNewButton/index.js +6 -8
  14. package/dist/es2019/components/WhatsNew/WhatsNewResults/WhatsNewResultsList/index.js +6 -8
  15. package/dist/es2019/components/contexts/navigationContext.js +98 -38
  16. package/dist/es2019/version.json +1 -1
  17. package/dist/esm/components/Article/HelpArticle/index.js +6 -8
  18. package/dist/esm/components/Article/index.js +2 -2
  19. package/dist/esm/components/Help.js +2 -1
  20. package/dist/esm/components/Search/SearchResults/index.js +8 -11
  21. package/dist/esm/components/WhatsNew/WhatsNewButton/index.js +6 -8
  22. package/dist/esm/components/WhatsNew/WhatsNewResults/WhatsNewResultsList/index.js +6 -8
  23. package/dist/esm/components/WhatsNew/WhatsNewResults/index.js +2 -2
  24. package/dist/esm/components/contexts/navigationContext.js +107 -49
  25. package/dist/esm/version.json +1 -1
  26. package/dist/types/components/contexts/navigationContext.d.ts +12 -7
  27. package/dist/types/model/Help.d.ts +8 -4
  28. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import React, { useReducer, useEffect, useCallback, useMemo } from 'react';
2
+ import isEqual from 'lodash/isEqual';
2
3
  import { REQUEST_STATE } from '../../model/Requests';
3
4
  import { ARTICLE_TYPE } from '../../model/Help';
4
5
  import { createCtx } from '../../util/hooks/ctx';
@@ -8,6 +9,10 @@ import { useWhatsNewArticleContext } from './whatsNewArticleContext';
8
9
  import { useHomeContext } from './homeContext';
9
10
  import { useSearchContext } from './searchContext';
10
11
  import { useHeaderContext } from './headerContext';
12
+ const DEFAULT_ARTICLE_ID = {
13
+ id: '',
14
+ type: ARTICLE_TYPE.HELP_ARTICLE
15
+ };
11
16
  export const [useNavigationContext, CtxProvider] = createCtx();
12
17
 
13
18
  const getNewHistoryItem = (id, type) => {
@@ -39,6 +44,21 @@ const getSimpleHistory = history => history.map(historyItem => {
39
44
  type
40
45
  };
41
46
  });
47
+ /**
48
+ * Get history data (list of IDs and UID)
49
+ */
50
+
51
+
52
+ const getHistoryData = history => history.map(historyItem => {
53
+ const {
54
+ id,
55
+ uid
56
+ } = historyItem;
57
+ return {
58
+ id,
59
+ uid
60
+ };
61
+ });
42
62
  /**
43
63
  * Get the last article in the history
44
64
  */
@@ -111,10 +131,28 @@ const navigationReducer = ({
111
131
  const {
112
132
  payload: newArticleId
113
133
  } = action;
134
+
135
+ if (isEqual(newArticleId, DEFAULT_ARTICLE_ID)) {
136
+ newState = {
137
+ articleId: newArticleId,
138
+ history: [],
139
+ view: VIEW.DEFAULT_CONTENT
140
+ };
141
+ } else {
142
+ newState = {
143
+ articleId: newArticleId,
144
+ history: [...currentHistory, getNewHistoryItem(newArticleId.id, newArticleId.type)],
145
+ view: getViewForArticleId(newArticleId)
146
+ };
147
+ }
148
+ } else if (action.type === 'addNewHistoryItem' && action.payload) {
149
+ const {
150
+ payload: newArticleId
151
+ } = action;
114
152
  newState = {
115
- articleId: newArticleId,
153
+ articleId: currentArticleId,
116
154
  history: [...currentHistory, getNewHistoryItem(newArticleId.id, newArticleId.type)],
117
- view: getViewForArticleId(newArticleId)
155
+ view: getViewForArticleId(currentArticleId)
118
156
  };
119
157
  } else if (action.type === 'updateHistoryItem' && action.payload) {
120
158
  const {
@@ -175,13 +213,11 @@ const navigationReducer = ({
175
213
  };
176
214
 
177
215
  export const NavigationContextProvider = ({
178
- articleId: propsArticleId = {
179
- id: '',
180
- type: ARTICLE_TYPE.HELP_ARTICLE
216
+ navigationData = {
217
+ articleId: DEFAULT_ARTICLE_ID,
218
+ history: []
181
219
  },
182
- articleIdSetter,
183
- history: propsHistory = [],
184
- historySetter,
220
+ setNavigationData,
185
221
  children
186
222
  }) => {
187
223
  const {
@@ -202,6 +238,10 @@ export const NavigationContextProvider = ({
202
238
  const {
203
239
  onCloseButtonClick
204
240
  } = useHeaderContext();
241
+ const {
242
+ articleId: propsArticleId,
243
+ history: propsHistory
244
+ } = navigationData;
205
245
  const [{
206
246
  articleId: currentArticleId,
207
247
  history: currentHistory,
@@ -221,8 +261,6 @@ export const NavigationContextProvider = ({
221
261
  /**
222
262
  * - If default content isn't defined and the history only has one article,
223
263
  * we should not display the back button
224
- * - If the prop.article.setArticleId is not defined, we should also hide the back
225
- * button because we are not able to navigate though the history without it
226
264
  */
227
265
  if (currentHistory.length === 1 && !isDefaultContentDefined || currentView === VIEW.WHATS_NEW && !isDefaultContentDefined) {
228
266
  return false;
@@ -339,6 +377,12 @@ export const NavigationContextProvider = ({
339
377
  onCloseButtonClick(event, analyticsEvent);
340
378
  }
341
379
  }, [onCloseButtonClick]);
380
+ const onOpenArticle = useCallback(newArticleId => {
381
+ dispatchNavigationAction({
382
+ type: 'addNewHistoryItem',
383
+ payload: newArticleId
384
+ });
385
+ }, []);
342
386
  useEffect(() => {
343
387
  if (isSearchResultVisible) {
344
388
  dispatchNavigationAction({
@@ -348,43 +392,59 @@ export const NavigationContextProvider = ({
348
392
  }
349
393
  }, [isSearchResultVisible]);
350
394
  useEffect(() => {
351
- const simpleHistory = getSimpleHistory(currentHistory);
352
- historySetter && historySetter(simpleHistory);
353
- }, [historySetter, currentHistory]);
354
- useEffect(() => {
395
+ const lastHistoryItem = currentHistory.length > 0 ? getCurrentArticle(currentHistory) : getNewHistoryItem(DEFAULT_ARTICLE_ID.id, DEFAULT_ARTICLE_ID.type);
355
396
  /**
356
397
  * If the propsArticleId.id (host articleId) is different from currentArticleId.id (internal articleId)
357
- * it means the host updated propsArticleId and we need to use this new value to load a new article.
358
398
  * */
359
- if ((propsArticleId === null || propsArticleId === void 0 ? void 0 : propsArticleId.id) !== currentArticleId.id || (propsArticleId === null || propsArticleId === void 0 ? void 0 : propsArticleId.type) !== currentArticleId.type) {
360
- dispatchNavigationAction({
361
- type: 'newArticle',
362
- payload: propsArticleId
363
- });
364
- } else {
399
+
400
+ if (!isEqual(propsArticleId, currentArticleId)) {
365
401
  /**
366
- * If the propsArticleId.id (host articleId) is equal to currentArticleId.id (internal articleId)
367
- * and the id from the last history item is different from currentArticleId.id, it means the history
368
- * changed and we need to update the host articleId (propsArticleId) using 'articleIdSetter' and the local
369
- * history using the dispatchNavigationAction reducer
370
- * */
371
- const lastHistoryItem = currentHistory.length > 0 ? getCurrentArticle(currentHistory) : getNewHistoryItem('', ARTICLE_TYPE.HELP_ARTICLE);
372
-
373
- if (articleIdSetter && lastHistoryItem && (currentArticleId.id !== lastHistoryItem.id || currentArticleId.type !== lastHistoryItem.type)) {
402
+ * If propsArticleId and lastHistoryItem are the same, we just need to update the articleId
403
+ * because is out of sync
404
+ */
405
+ if (propsArticleId.id === lastHistoryItem.id && propsArticleId.type === lastHistoryItem.type) {
374
406
  dispatchNavigationAction({
375
407
  type: 'updateArticleId',
376
- payload: {
377
- id: lastHistoryItem.id,
378
- type: lastHistoryItem.type
379
- }
408
+ payload: propsArticleId
380
409
  });
381
- articleIdSetter({
382
- id: lastHistoryItem.id,
383
- type: lastHistoryItem.type
410
+ } else {
411
+ /**
412
+ * Otherwise we need to add a new article
413
+ */
414
+ dispatchNavigationAction({
415
+ type: 'newArticle',
416
+ payload: propsArticleId
384
417
  });
385
418
  }
419
+ } else {
420
+ // console.log('same articleId');
421
+ if (setNavigationData) {
422
+ const simpleHistory = getSimpleHistory(currentHistory);
423
+
424
+ if (currentArticleId.id !== lastHistoryItem.id || currentArticleId.type !== lastHistoryItem.type) {
425
+ /**
426
+ * If the propsArticleId.id (host articleId) is equal to currentArticleId.id (internal articleId)
427
+ * and the id from the last history item is different from currentArticleId.id, it means the history
428
+ * changed
429
+ * */
430
+ if (setNavigationData) {
431
+ setNavigationData({
432
+ articleId: {
433
+ id: lastHistoryItem.id,
434
+ type: lastHistoryItem.type
435
+ },
436
+ history: simpleHistory
437
+ });
438
+ }
439
+ } else if (!isEqual(getHistoryData(propsHistory), getHistoryData(currentHistory))) {
440
+ setNavigationData({
441
+ articleId: propsArticleId,
442
+ history: simpleHistory
443
+ });
444
+ }
445
+ }
386
446
  }
387
- }, [currentArticleId, propsArticleId, currentHistory, articleIdSetter]);
447
+ }, [currentArticleId, propsArticleId, currentHistory, setNavigationData, propsHistory]);
388
448
  useEffect(() => {
389
449
  const requestNewArticle = async historyItem => {
390
450
  const historyItemUpdate = await fetchArticleData(historyItem);
@@ -408,7 +468,7 @@ export const NavigationContextProvider = ({
408
468
  value: {
409
469
  view: currentView,
410
470
  articleId: currentArticleId,
411
- setArticleId: articleIdSetter,
471
+ openArticle: onOpenArticle,
412
472
  history: currentHistory,
413
473
  getCurrentArticle: () => getCurrentArticle(currentHistory),
414
474
  getCurrentArticleItemData: () => getCurrentArticleItemSlim(currentHistory),
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/help",
3
- "version": "6.0.8",
3
+ "version": "7.0.0",
4
4
  "sideEffects": false
5
5
  }
@@ -14,7 +14,7 @@ export var HelpArticle = function HelpArticle(_ref) {
14
14
  isLoading = _ref.isLoading;
15
15
 
16
16
  var _useNavigationContext = useNavigationContext(),
17
- setArticleId = _useNavigationContext.setArticleId,
17
+ openArticle = _useNavigationContext.openArticle,
18
18
  getCurrentArticleItemData = _useNavigationContext.getCurrentArticleItemData;
19
19
 
20
20
  var _useHelpArticleContex = useHelpArticleContext(),
@@ -56,13 +56,11 @@ export var HelpArticle = function HelpArticle(_ref) {
56
56
  onRelatedArticlesListItemClick(event, analyticsEvent, articleData);
57
57
  }
58
58
 
59
- if (setArticleId) {
60
- setArticleId({
61
- id: articleData.id,
62
- type: ARTICLE_TYPE.HELP_ARTICLE
63
- });
64
- }
65
- }, [setArticleId, onRelatedArticlesListItemClick]);
59
+ openArticle({
60
+ id: articleData.id,
61
+ type: ARTICLE_TYPE.HELP_ARTICLE
62
+ });
63
+ }, [openArticle, onRelatedArticlesListItemClick]);
66
64
  var handleOnRelatedArticlesShowMoreClick = useCallback(function (event, analyticsEvent, isCollapsed) {
67
65
  analyticsEvent.payload.attributes = {
68
66
  componentName: 'Article',
@@ -1,9 +1,9 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
 
4
- 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; }
4
+ 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; }
5
5
 
6
- 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; }
6
+ 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; }
7
7
 
8
8
  import React, { useState, useLayoutEffect, useRef, useEffect, useCallback } from 'react';
9
9
  import { Transition } from 'react-transition-group';
@@ -5,6 +5,7 @@ import _createClass from "@babel/runtime/helpers/createClass";
5
5
  import _inherits from "@babel/runtime/helpers/inherits";
6
6
  import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
7
7
  import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
8
+ var _excluded = ["children", "footer"];
8
9
 
9
10
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
10
11
 
@@ -39,7 +40,7 @@ export var Help = /*#__PURE__*/function (_React$PureComponent) {
39
40
  var _this$props = this.props,
40
41
  children = _this$props.children,
41
42
  footer = _this$props.footer,
42
- rest = _objectWithoutProperties(_this$props, ["children", "footer"]);
43
+ rest = _objectWithoutProperties(_this$props, _excluded);
43
44
 
44
45
  return /*#__PURE__*/React.createElement(HeaderContextProvider, rest.header, /*#__PURE__*/React.createElement(HomeContextProvider, _extends({}, rest.home, {
45
46
  homeContent: children
@@ -1,8 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
 
3
- 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; }
3
+ 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; }
4
4
 
5
- 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; }
5
+ 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; }
6
6
 
7
7
  import React, { useCallback } from 'react';
8
8
  import { Transition } from 'react-transition-group';
@@ -50,19 +50,16 @@ export var SearchResults = function SearchResults() {
50
50
  onSearchExternalUrlClick = _useSearchContext.onSearchExternalUrlClick;
51
51
 
52
52
  var _useNavigationContext = useNavigationContext(),
53
- setArticleId = _useNavigationContext.setArticleId,
53
+ openArticle = _useNavigationContext.openArticle,
54
54
  view = _useNavigationContext.view;
55
55
 
56
56
  var handleOnSearchResultItemClick = useCallback(function (event, analyticsEvent, articleData) {
57
- if (setArticleId) {
58
- setArticleId({
59
- id: articleData.id,
60
- type: ARTICLE_TYPE.HELP_ARTICLE
61
- });
62
- }
63
-
57
+ openArticle({
58
+ id: articleData.id,
59
+ type: ARTICLE_TYPE.HELP_ARTICLE
60
+ });
64
61
  onSearchResultItemClick(event, analyticsEvent, articleData);
65
- }, [onSearchResultItemClick, setArticleId]);
62
+ }, [onSearchResultItemClick, openArticle]);
66
63
  return /*#__PURE__*/React.createElement(Transition, {
67
64
  in: view === VIEW.SEARCH && isSearchResultVisible,
68
65
  timeout: FADEIN_OVERLAY_TRANSITION_DURATION_MS
@@ -23,20 +23,18 @@ export var WhatsNewButton = function WhatsNewButton(_ref) {
23
23
  whatsNewGetNotificationProvider = _useWhatsNewArticleCo.whatsNewGetNotificationProvider;
24
24
 
25
25
  var _useNavigationContext = useNavigationContext(),
26
- setArticleId = _useNavigationContext.setArticleId;
26
+ openArticle = _useNavigationContext.openArticle;
27
27
 
28
28
  var handleOnButtonClick = useCallback(function (id, analytics, event) {
29
29
  if (onWhatsNewButtonClick) {
30
30
  onWhatsNewButtonClick(event, analytics);
31
31
  }
32
32
 
33
- if (setArticleId) {
34
- setArticleId({
35
- id: '',
36
- type: ARTICLE_TYPE.WHATS_NEW
37
- });
38
- }
39
- }, [onWhatsNewButtonClick, setArticleId]);
33
+ openArticle({
34
+ id: '',
35
+ type: ARTICLE_TYPE.WHATS_NEW
36
+ });
37
+ }, [onWhatsNewButtonClick, openArticle]);
40
38
  return /*#__PURE__*/React.createElement(HelpContentButton, {
41
39
  id: "whats-new",
42
40
  key: "whats-new",
@@ -31,7 +31,7 @@ var WhatsNewResultsList = function WhatsNewResultsList(_ref) {
31
31
  onShowMoreButtonClick = _ref.onShowMoreButtonClick;
32
32
 
33
33
  var _useNavigationContext = useNavigationContext(),
34
- setArticleId = _useNavigationContext.setArticleId;
34
+ openArticle = _useNavigationContext.openArticle;
35
35
 
36
36
  var handleShowMoreButtonClick = function handleShowMoreButtonClick(event, analyticsEvent) {
37
37
  if (onShowMoreButtonClick) {
@@ -40,17 +40,15 @@ var WhatsNewResultsList = function WhatsNewResultsList(_ref) {
40
40
  };
41
41
 
42
42
  var handleOnWhatsNewResultItemClick = useCallback(function (event, analyticsEvent, articleData) {
43
- if (setArticleId) {
44
- setArticleId({
45
- id: articleData.id,
46
- type: ARTICLE_TYPE.WHATS_NEW
47
- });
48
- }
43
+ openArticle({
44
+ id: articleData.id,
45
+ type: ARTICLE_TYPE.WHATS_NEW
46
+ });
49
47
 
50
48
  if (onWhatsNewResultItemClick) {
51
49
  onWhatsNewResultItemClick(event, analyticsEvent, articleData);
52
50
  }
53
- }, [onWhatsNewResultItemClick, setArticleId]);
51
+ }, [onWhatsNewResultItemClick, openArticle]);
54
52
  return whatsNewArticles && whatsNewArticles.length > 0 ? /*#__PURE__*/React.createElement(WhatsNewResultsListContainer, null, /*#__PURE__*/React.createElement(ThemeProvider, {
55
53
  theme: _defineProperty({}, itemThemeNamespace, ITEM_THEME)
56
54
  }, /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ArticlesList, {
@@ -1,9 +1,9 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
3
 
4
- 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; }
4
+ 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; }
5
5
 
6
- 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; }
6
+ 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; }
7
7
 
8
8
  import React, { useCallback, useState } from 'react';
9
9
  import { Transition } from 'react-transition-group';
@@ -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,6 +250,9 @@ 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
258
  history: propsHistory,
@@ -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);