qpp-style 9.10.1 → 9.11.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.
@@ -4,7 +4,7 @@ import axios from 'axios';
4
4
  import CloseIcon from '@material-ui/icons/Close';
5
5
 
6
6
  import { TextButton } from '../Button';
7
- import { deleteImpersonatedUser } from '../../session/logout';
7
+ import { deleteImpersonatedUser, revertQppHasAuthsCookie } from '../../session/logout';
8
8
 
9
9
  const ImpersonatorBanner = () => {
10
10
  const { qpp_auth_token: token = null, qpp_impersonated_user: user = null } =
@@ -21,8 +21,10 @@ const ImpersonatorBanner = () => {
21
21
  ].join(' ');
22
22
 
23
23
  const onClick = () => {
24
- const fn = () => {
24
+ const fn = () => {
25
25
  deleteImpersonatedUser({ qpp_impersonated_user: user });
26
+ // Set qpp_has_authorizations cookie back to impersonator's value
27
+ revertQppHasAuthsCookie();
26
28
  window.location.reload();
27
29
  };
28
30
  return axios
@@ -1,56 +1,55 @@
1
- import React, { useEffect, useState } from 'react';
2
- import PropTypes from 'prop-types';
3
- import MuiTabs from '@material-ui/core/Tabs';
4
-
1
+ import React, { useEffect, useState } from 'react'
2
+ import PropTypes from 'prop-types'
3
+ import MuiTabs from '@material-ui/core/Tabs'
5
4
  import TabPanel from './TabPanel'
6
5
  import LinkTab from './Tab'
7
6
 
8
7
  const isTabPanel = (child) => child?.type === TabPanel
9
8
 
10
9
  const getPanelChildren = (children) => {
11
- return React.Children.toArray(children).filter(isTabPanel);
10
+ return React.Children.toArray(children).filter(isTabPanel)
12
11
  };
13
12
 
14
13
  const Tabs = ({ children, onChange, selected, defaultSelectedId, ariaLabel }) => {
15
- const [tabList, setTabList] = useState([]);
16
- const [value, setValue] = useState(defaultSelectedId || selected);
14
+ const [value, setValue] = useState(defaultSelectedId || selected)
15
+
16
+ useEffect(() => {
17
+ if (selected) {
18
+ setValue(selected)
19
+ }
20
+ }, [selected])
21
+
22
+ if (!children) return null
17
23
 
18
24
  const handleChange = (event, newValue) => {
19
25
  if (onChange) {
20
- onChange(tabList[newValue]?.id, event);
26
+ onChange(tabList[newValue]?.id, event)
21
27
  }
22
28
  if (setValue) {
23
- setValue(tabList[newValue]?.id);
29
+ setValue(tabList[newValue]?.id)
24
30
  }
25
- };
31
+ }
26
32
 
27
33
  const renderChildren = () => {
28
34
  return React.Children.map(children, (child, index) => {
29
35
  if (isTabPanel(child)) {
30
36
  return React.cloneElement(child, { index, value: tabIndex })
31
37
  }
32
- return child;
33
- });
34
- };
38
+ return child
39
+ })
40
+ }
35
41
 
36
- useEffect(() => {
37
- const panels = getPanelChildren(children);
38
- const tabs = panels.map(
39
- (panel) => {
40
- const { id, tab, tabHref, disabled } = panel?.props || {};
41
- return { tab, tabHref, disabled, id };
42
- },
43
- );
44
- setTabList(tabs);
45
- }, []);
42
+ const panels = getPanelChildren(children)
43
+
44
+ const tabList = panels.map(
45
+ (panel) => {
46
+ const { id, tab, tabHref, disabled } = panel?.props || {}
47
+ return { tab, tabHref, disabled, id }
48
+ },
49
+ )
46
50
 
47
- useEffect(() => {
48
- if (selected) {
49
- setValue(selected);
50
- }
51
- }, [selected]);
52
-
53
- const foundIndex = tabList.findIndex(({ id }) => id === value);
51
+ const foundIndex = tabList.findIndex(({ id }) => id === value)
52
+
54
53
  const tabIndex = foundIndex >= 0 ? foundIndex : 0
55
54
 
56
55
  return (
@@ -71,16 +70,19 @@ const Tabs = ({ children, onChange, selected, defaultSelectedId, ariaLabel }) =>
71
70
  </div>
72
71
  {renderChildren()}
73
72
  </>
74
- );
75
- };
73
+ )
74
+ }
76
75
 
77
76
  Tabs.propTypes = {
78
77
  ariaLabel: PropTypes.string,
79
78
  selected: PropTypes.string,
80
79
  defaultSelectedId: PropTypes.string,
81
80
  onChange: PropTypes.func,
82
- children: PropTypes.node,
83
- };
81
+ children: PropTypes.oneOfType([
82
+ PropTypes.node,
83
+ PropTypes.array,
84
+ ])
85
+ }
84
86
 
85
87
  Tabs.defaultProps = {
86
88
  ariaLabel: 'qpp tabs',
@@ -88,6 +90,6 @@ Tabs.defaultProps = {
88
90
  defaultSelectedId: null,
89
91
  onChange: null,
90
92
  children: null,
91
- };
93
+ }
92
94
 
93
- export default Tabs;
95
+ export default Tabs