qpp-style 9.33.2 → 9.33.4

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.
@@ -1,7 +1,8 @@
1
1
  import React, { useState, useRef, useEffect } from 'react';
2
2
  import PropTypes from 'prop-types';
3
+ import axios from 'axios';
3
4
 
4
- import { sideNavExpandedStorage } from '../helpers';
5
+ import { setSideNavExpanded, isSideNavExpanded } from '../helpers';
5
6
  import { LevelOneContent } from '../Content';
6
7
  import {
7
8
  NavLinkContainer,
@@ -11,23 +12,45 @@ import {
11
12
  } from '../Links';
12
13
  import AnimationGroup from '../AnimationGroup/AnimationGroup';
13
14
  import { PracticeDetails, IndividualDetails } from '../Details';
14
- import ScoreChart from '../Chart';
15
15
  import SanitizedContent from '../../SanitizedContent';
16
16
  import * as SvgComponents from '../../../lib/SvgComponents.jsx';
17
17
  import CmsSwitchLink from '../Links/CmsSwitchLink';
18
- import axios from 'axios';
19
18
  import defaultMarkup from './default-markup';
20
19
 
20
+ // TODO: For an SSR version of the SideNavUI we would need to have
21
+ // the whole SideNav markup render on the server. Less reliance on
22
+ // window and document.
23
+ // We can have an API created where we send it certain parameters
24
+ // like items. All of the markup is then returned. The SideNav can
25
+ // just render the markup provided by the Frontend Server.
26
+ // The only code left behind would be triggers to respond to
27
+ // toggling the sidenav's expand state
28
+ // Things to consider when implmenting an SSR version:
29
+ // 1. any buttons will need event listeners to trigger actions.
30
+ // 2. we need a feature flag to roll this out since it will be
31
+ // a breaking change.
32
+ // 3. we may want to consider creating a web component since they
33
+ // are server friendly. https://css-tricks.com/using-web-components-with-next-or-any-ssr-framework/
34
+ // 4. If you do use web components be sure to come up with a
35
+ // strategy to register the web component before React loads
36
+ // the markup on the page. Then the web component renders
37
+ // immediately.
21
38
  const SideNavUI = ({
22
39
  config,
23
40
  isAltStyle,
41
+ isExpanded,
24
42
  items,
25
43
  onCollapsed,
26
44
  onExpanded,
27
- performanceYear,
28
45
  }) => {
29
- const [isExpandedState, setIsExpandedState] = useState(true);
30
- const [sideNavContent, setSideNavContent] = useState({});
46
+ const isExpandedPropSet = isExpanded !== undefined;
47
+ const [isExpandedState, setIsExpandedState] = useState(() => {
48
+ if (isExpandedPropSet) {
49
+ return isExpanded;
50
+ }
51
+ return isSideNavExpanded(window.document);
52
+ });
53
+ const [sideNavContent, setSideNavContent] = useState('<nav></nav>');
31
54
 
32
55
  const collapseRef = useRef(null);
33
56
 
@@ -38,7 +61,7 @@ const SideNavUI = ({
38
61
  };
39
62
 
40
63
  const expand = () => {
41
- sideNavExpandedStorage.toggle();
64
+ setSideNavExpanded(window.document, 'true');
42
65
  setIsExpandedState(true);
43
66
  changeExpandedClass('animation-group-exit', 'animation-group-enter');
44
67
  if (onExpanded) {
@@ -47,7 +70,7 @@ const SideNavUI = ({
47
70
  };
48
71
 
49
72
  const collapse = () => {
50
- sideNavExpandedStorage.toggle();
73
+ setSideNavExpanded(window.document, 'false');
51
74
  setIsExpandedState(false);
52
75
  changeExpandedClass('animation-group-enter', 'animation-group-exit');
53
76
  if (onCollapsed) {
@@ -60,6 +83,22 @@ const SideNavUI = ({
60
83
  };
61
84
 
62
85
  useEffect(() => {
86
+ // some applications use the isExpanded prop instead of reading the cookie
87
+ // this will ensure the application ignores the cookie
88
+ if (isExpandedPropSet) {
89
+ if (isExpanded) {
90
+ changeExpandedClass('animation-group-exit', 'animation-group-enter');
91
+ } else {
92
+ changeExpandedClass('animation-group-enter', 'animation-group-exit');
93
+ }
94
+ setIsExpandedState(isExpanded);
95
+ } else {
96
+ isSideNavExpanded(window.document);
97
+ }
98
+ }, [isExpanded, isExpandedPropSet]);
99
+
100
+ useEffect(() => {
101
+ const initialExpandedState = isSideNavExpanded(window.document);
63
102
  let cancelRequest = false;
64
103
  const { origin } = window.location;
65
104
  const isRunningLocally = origin.includes('localhost');
@@ -77,7 +116,24 @@ const SideNavUI = ({
77
116
  }
78
117
  }
79
118
  if (!cancelRequest) {
80
- setSideNavContent(sideNavMenuItems);
119
+ const realInitialState = isExpandedPropSet
120
+ ? isExpanded
121
+ : initialExpandedState;
122
+ if (realInitialState) {
123
+ setSideNavContent(sideNavMenuItems);
124
+ } else {
125
+ // TODO: we are replacing the class here because the server does not take into account the
126
+ // initial expand/collapse state of the sidenav.
127
+ // Once we have confirmation that everyone has installed this version of QPP-Style we can
128
+ // remove this if/else block (assuming the server has been updated to read the cookie and
129
+ // render the appropriate class for each link)
130
+ setSideNavContent(
131
+ sideNavMenuItems.replaceAll(
132
+ 'animation-group-enter',
133
+ 'animation-group-exit',
134
+ ),
135
+ );
136
+ }
81
137
  }
82
138
  }
83
139
  getSideNavConfig();
@@ -201,15 +257,6 @@ const SideNavUI = ({
201
257
  />
202
258
  </AnimationGroup>
203
259
  ),
204
- chart: (
205
- <AnimationGroup display={isExpandedState} key={key}>
206
- <ScoreChart
207
- chartData={item.chartData}
208
- linkCallback={linkCallback}
209
- performanceYear={performanceYear}
210
- />
211
- </AnimationGroup>
212
- ),
213
260
  switchLink: (
214
261
  <AnimationGroup display={isExpandedState} key={key}>
215
262
  <CmsSwitchLink
@@ -252,11 +299,6 @@ const SideNavUI = ({
252
299
  }
253
300
  };
254
301
 
255
- // Set side nav expanded state in localStorage on initial render
256
- useEffect(() => {
257
- sideNavExpandedStorage.init();
258
- }, []);
259
-
260
302
  const content = !items?.length ? (
261
303
  <LevelOneContent
262
304
  levelOneContent={sideNavContent}
@@ -290,27 +332,21 @@ const SideNavUI = ({
290
332
  };
291
333
 
292
334
  SideNavUI.propTypes = {
293
- currentLevel: PropTypes.number,
294
- onExpanded: PropTypes.func,
295
- onCollapsed: PropTypes.func,
296
- chartData: PropTypes.object,
297
335
  config: PropTypes.object,
298
- items: PropTypes.object,
299
336
  isAltStyle: PropTypes.bool,
300
- showReportingLinks: PropTypes.bool,
301
- performanceYear: PropTypes.string,
337
+ isExpanded: PropTypes.bool,
338
+ items: PropTypes.object,
339
+ onCollapsed: PropTypes.func,
340
+ onExpanded: PropTypes.func,
302
341
  };
303
342
 
304
343
  SideNavUI.defaultProps = {
305
- currentLevel: 1,
306
- onExpanded: () => {},
307
- onCollapsed: () => {},
308
- chartData: {},
309
344
  config: {},
310
- items: null,
311
345
  isAltStyle: false,
312
- showReportingLinks: false,
313
- performanceYear: '2017',
346
+ isExpanded: undefined,
347
+ items: null,
348
+ onCollapsed: () => {},
349
+ onExpanded: () => {},
314
350
  };
315
351
 
316
352
  export default SideNavUI;
@@ -347,34 +347,27 @@ const isImpersonationLink = (docCookie, linkLabel) => {
347
347
  };
348
348
 
349
349
  /**
350
- * Set SideNav expanded state as qpp_side_nav_expanded in localStorage
350
+ * Sets the qpp_side_nav_expanded cookie value
351
+ * @param {Document} document object
352
+ * @param {string} value
353
+ * @returns {void}
351
354
  */
352
- const sideNavExpandedStorage = {
353
- isNullOrUndefined: function () {
354
- const sideNavExpandedValue = localStorage.getItem('qpp_side_nav_expanded');
355
- return sideNavExpandedValue === null || sideNavExpandedValue === undefined;
356
- },
357
- init: function () {
358
- if (this.isNullOrUndefined()) {
359
- localStorage.setItem('qpp_side_nav_expanded', true);
360
- }
361
- },
362
- toggle: function () {
363
- const isSideNavExpanded = JSON.parse(
364
- localStorage.getItem('qpp_side_nav_expanded'),
365
- );
366
- if (!isSideNavExpanded) {
367
- localStorage.setItem('qpp_side_nav_expanded', true);
368
- } else {
369
- localStorage.setItem('qpp_side_nav_expanded', false);
370
- }
371
- },
372
- get: function () {
373
- return JSON.parse(localStorage.getItem('qpp_side_nav_expanded'));
374
- },
375
- remove: function () {
376
- localStorage.removeItem('qpp_side_nav_expanded');
377
- },
355
+ const setSideNavExpanded = (_document, value) => {
356
+ _document.cookie = cookie.serialize('qpp_side_nav_expanded', value);
357
+ };
358
+
359
+ /**
360
+ * Check if sidenav is expanded
361
+ * @param {Document} document object
362
+ * @returns {boolean}
363
+ */
364
+ const isSideNavExpanded = (_document) => {
365
+ const parsedCookies = cookie.parse(_document.cookie);
366
+ if (parsedCookies.qpp_side_nav_expanded === undefined) {
367
+ setSideNavExpanded(_document, 'true');
368
+ return true;
369
+ }
370
+ return parsedCookies.qpp_side_nav_expanded === 'true';
378
371
  };
379
372
 
380
373
  module.exports = {
@@ -397,5 +390,6 @@ module.exports = {
397
390
  isImpersonating,
398
391
  isImpersonationLink,
399
392
  loadSideNavContent,
400
- sideNavExpandedStorage,
393
+ setSideNavExpanded,
394
+ isSideNavExpanded,
401
395
  };
@@ -4,48 +4,26 @@ import { SideNavUI } from './UI';
4
4
 
5
5
  const SideNav = (options = {}) => {
6
6
  const {
7
- rootElement,
8
- onExpanded,
9
- onCollapsed,
10
- chartData,
11
- currentLevel,
12
7
  config,
13
- feedbackPerformanceYear,
14
- fbpPerformanceYear,
15
- showDevPreDfpLink,
16
- showPhysicianCompareLink,
17
- showFacilityBasedPreviewLink,
18
- showSelfNomination,
19
- showApmIncentivePaymentLink,
20
- items,
21
8
  isAltStyle,
22
- showReportsPortal,
23
- showTargetedReviewLink,
9
+ isExpanded,
10
+ items,
11
+ onCollapsed,
12
+ onExpanded,
13
+ rootElement,
24
14
  } = options;
25
15
 
26
- const { expand, collapse } = render(
16
+ return render(
27
17
  <SideNavUI
28
18
  onExpanded={onExpanded}
29
19
  onCollapsed={onCollapsed}
30
- chartData={chartData}
31
- currentLevel={currentLevel}
20
+ isExpanded={isExpanded}
32
21
  config={config}
33
- feedbackPerformanceYear={feedbackPerformanceYear}
34
- fbpPerformanceYear={fbpPerformanceYear}
35
- showDevPreDfpLink={showDevPreDfpLink}
36
- showPhysicianCompareLink={showPhysicianCompareLink}
37
- showFacilityBasedPreviewLink={showFacilityBasedPreviewLink}
38
- showSelfNomination={showSelfNomination}
39
- showApmIncentivePaymentLink={showApmIncentivePaymentLink}
40
22
  items={items}
41
23
  isAltStyle={isAltStyle}
42
- showReportsPortal={showReportsPortal}
43
- showTargetedReviewLink={showTargetedReviewLink}
44
24
  />,
45
25
  rootElement,
46
26
  );
47
-
48
- return { expand, collapse };
49
27
  };
50
28
 
51
29
  export default SideNav;