orc-shared 5.10.0-dev.2 → 5.10.0-dev.21

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 (186) hide show
  1. package/dist/actions/metadata.js +30 -11
  2. package/dist/actions/requestsApi.js +10 -1
  3. package/dist/components/AppFrame/About.js +136 -100
  4. package/dist/components/AppFrame/Anchor.js +45 -21
  5. package/dist/components/AppFrame/AppFrame.js +53 -31
  6. package/dist/components/AppFrame/Help.js +35 -15
  7. package/dist/components/AppFrame/MenuItem.js +148 -114
  8. package/dist/components/AppFrame/Preferences.js +136 -97
  9. package/dist/components/AppFrame/Sidebar.js +51 -28
  10. package/dist/components/AppFrame/Topbar.js +61 -36
  11. package/dist/components/ColumnWrapper.js +28 -5
  12. package/dist/components/Culture.js +33 -14
  13. package/dist/components/DropMenu/Menu.js +79 -45
  14. package/dist/components/DropMenu/index.js +34 -29
  15. package/dist/components/Form/Combination.js +45 -16
  16. package/dist/components/Form/Field.js +57 -38
  17. package/dist/components/Form/FieldElements.js +0 -11
  18. package/dist/components/Form/Fieldset.js +47 -19
  19. package/dist/components/Form/Form.js +22 -9
  20. package/dist/components/Form/FormElement.js +40 -7
  21. package/dist/components/Form/Inputs/Button.js +63 -18
  22. package/dist/components/Form/Inputs/ReadOnly.js +50 -27
  23. package/dist/components/{AppFrame/ApplicationSelector/Header.js → Form/Inputs/Selector.js} +30 -31
  24. package/dist/components/Form/Inputs/Text.js +20 -37
  25. package/dist/components/Form/Inputs/Toggles.js +39 -40
  26. package/dist/components/Form/Inputs/index.js +2 -13
  27. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +31 -11
  28. package/dist/components/MaterialUI/DataDisplay/PredefinedElements/SectionToolbar.js +89 -0
  29. package/dist/components/MaterialUI/DataDisplay/Table.js +109 -18
  30. package/dist/components/MaterialUI/DataDisplay/TableProps.js +5 -1
  31. package/dist/components/MaterialUI/DataDisplay/TableWithInMemoryPaging.js +198 -0
  32. package/dist/components/MaterialUI/DataDisplay/TooltippedElements/MultipleLinesText.js +4 -1
  33. package/dist/components/MaterialUI/Inputs/DatePicker.js +14 -14
  34. package/dist/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +1 -0
  35. package/dist/components/MaterialUI/Inputs/Select.js +2 -0
  36. package/dist/components/MaterialUI/Inputs/SelectProps.js +2 -0
  37. package/dist/components/MaterialUI/Inputs/Switch.js +17 -1
  38. package/dist/components/MaterialUI/Inputs/SwitchProps.js +2 -0
  39. package/dist/components/MaterialUI/Inputs/TimePicker.js +14 -21
  40. package/dist/components/MaterialUI/hocs/withDeferredTooltip.js +3 -1
  41. package/dist/components/MaterialUI/muiThemes.js +2 -1
  42. package/dist/components/Provision.js +1 -1
  43. package/dist/constants.js +2 -1
  44. package/dist/content/iconsSheet.svg +740 -116
  45. package/dist/hocs/withScrollBox.js +27 -12
  46. package/dist/hooks/useDaysAndMonthsLocalization.js +77 -0
  47. package/dist/hooks/useInMemoryPaging.js +135 -0
  48. package/dist/hooks/useMultipleFieldEditState.js +12 -3
  49. package/dist/reducers/metadata.js +6 -0
  50. package/dist/schemas/metadata.js +9 -1
  51. package/dist/selectors/locale.js +1 -0
  52. package/dist/selectors/metadata.js +14 -11
  53. package/dist/sharedMessages.js +184 -0
  54. package/dist/utils/ListHelper.js +271 -0
  55. package/dist/utils/comparisonHelper.js +185 -0
  56. package/dist/utils/propertyBagHelper.js +3 -1
  57. package/dist/utils/timezoneHelper.js +18 -31
  58. package/package.json +4 -3
  59. package/src/actions/metadata.js +11 -0
  60. package/src/actions/metadata.test.js +27 -0
  61. package/src/actions/requestsApi.js +6 -0
  62. package/src/components/AppFrame/About.js +97 -117
  63. package/src/components/AppFrame/About.test.js +128 -90
  64. package/src/components/AppFrame/Anchor.js +34 -36
  65. package/src/components/AppFrame/Anchor.test.js +5 -68
  66. package/src/components/AppFrame/AppFrame.js +31 -40
  67. package/src/components/AppFrame/AppFrame.test.js +424 -445
  68. package/src/components/AppFrame/Help.js +23 -20
  69. package/src/components/AppFrame/Help.test.js +3 -3
  70. package/src/components/AppFrame/MenuItem.js +106 -126
  71. package/src/components/AppFrame/MenuItem.test.js +78 -169
  72. package/src/components/AppFrame/Preferences.js +110 -98
  73. package/src/components/AppFrame/Preferences.test.js +115 -219
  74. package/src/components/AppFrame/Sidebar.js +39 -41
  75. package/src/components/AppFrame/Sidebar.test.js +88 -168
  76. package/src/components/AppFrame/Topbar.js +59 -52
  77. package/src/components/AppFrame/Topbar.test.js +31 -39
  78. package/src/components/ColumnWrapper.js +18 -9
  79. package/src/components/Culture.js +20 -10
  80. package/src/components/Culture.test.js +27 -16
  81. package/src/components/DropMenu/DropMenu.test.js +185 -224
  82. package/src/components/DropMenu/Menu.js +73 -80
  83. package/src/components/DropMenu/Menu.test.js +35 -86
  84. package/src/components/DropMenu/index.js +19 -15
  85. package/src/components/Form/Combination.js +35 -28
  86. package/src/components/Form/Combination.test.js +6 -19
  87. package/src/components/Form/Field.js +53 -66
  88. package/src/components/Form/Field.test.js +29 -51
  89. package/src/components/Form/FieldElements.js +0 -14
  90. package/src/components/Form/FieldElements.test.js +104 -111
  91. package/src/components/Form/Fieldset.js +42 -37
  92. package/src/components/Form/Fieldset.test.js +14 -7
  93. package/src/components/Form/Form.js +11 -7
  94. package/src/components/Form/Form.test.js +75 -56
  95. package/src/components/Form/FormElement.js +24 -16
  96. package/src/components/Form/InputField.test.js +24 -30
  97. package/src/components/Form/Inputs/Button.js +58 -14
  98. package/src/components/Form/Inputs/Button.test.js +32 -7
  99. package/src/components/Form/Inputs/Inputs.test.js +0 -7
  100. package/src/components/Form/Inputs/ReadOnly.js +34 -28
  101. package/src/components/Form/Inputs/ReadOnly.test.js +45 -7
  102. package/src/components/Form/Inputs/Selector.js +22 -0
  103. package/src/components/Form/Inputs/Selector.test.js +105 -0
  104. package/src/components/Form/Inputs/Text.js +15 -44
  105. package/src/components/Form/Inputs/Text.test.js +20 -29
  106. package/src/components/Form/Inputs/Toggles.js +27 -26
  107. package/src/components/Form/Inputs/Toggles.test.js +22 -28
  108. package/src/components/Form/Inputs/index.js +4 -15
  109. package/src/components/MaterialUI/DataDisplay/PredefinedElements/InformationItem.test.js +1 -4
  110. package/src/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.js +32 -6
  111. package/src/components/MaterialUI/DataDisplay/PredefinedElements/Placeholder.test.js +3 -1
  112. package/src/components/MaterialUI/DataDisplay/PredefinedElements/SectionToolbar.js +39 -0
  113. package/src/components/MaterialUI/DataDisplay/Table.js +190 -114
  114. package/src/components/MaterialUI/DataDisplay/Table.test.js +246 -1
  115. package/src/components/MaterialUI/DataDisplay/TableProps.js +4 -0
  116. package/src/components/MaterialUI/DataDisplay/TableProps.test.js +2 -0
  117. package/src/components/MaterialUI/DataDisplay/TableWithInMemoryPaging.js +145 -0
  118. package/src/components/MaterialUI/DataDisplay/TableWithInMemoryPaging.test.js +457 -0
  119. package/src/components/MaterialUI/DataDisplay/TooltippedElements/MultipleLinesText.js +5 -1
  120. package/src/components/MaterialUI/DataDisplay/TooltippedElements/MultipleLinesText.test.js +7 -1
  121. package/src/components/MaterialUI/Inputs/DatePicker.js +19 -20
  122. package/src/components/MaterialUI/Inputs/DatePicker.test.js +11 -6
  123. package/src/components/MaterialUI/Inputs/PredefinedElements/SearchControl.js +1 -0
  124. package/src/components/MaterialUI/Inputs/Select.js +2 -0
  125. package/src/components/MaterialUI/Inputs/SelectProps.js +2 -0
  126. package/src/components/MaterialUI/Inputs/SelectProps.test.js +2 -0
  127. package/src/components/MaterialUI/Inputs/Switch.js +22 -1
  128. package/src/components/MaterialUI/Inputs/Switch.test.js +23 -0
  129. package/src/components/MaterialUI/Inputs/SwitchProps.js +2 -0
  130. package/src/components/MaterialUI/Inputs/SwitchProps.test.js +2 -0
  131. package/src/components/MaterialUI/Inputs/TimePicker.js +10 -19
  132. package/src/components/MaterialUI/Inputs/TimePicker.test.js +278 -117
  133. package/src/components/MaterialUI/hocs/withDeferredTooltip.js +4 -1
  134. package/src/components/MaterialUI/hocs/withDeferredTooltip.test.js +27 -0
  135. package/src/components/MaterialUI/muiThemes.js +1 -0
  136. package/src/components/Navigation/Bar.test.js +92 -87
  137. package/src/components/Provision.js +1 -1
  138. package/src/components/TaskDetailsModal.test.js +1 -3
  139. package/src/constants.js +1 -0
  140. package/src/content/iconsSheet.svg +740 -116
  141. package/src/hocs/withScrollBox.js +32 -19
  142. package/src/hocs/withScrollBox.test.js +15 -3
  143. package/src/hooks/useDaysAndMonthsLocalization.js +79 -0
  144. package/src/hooks/useDaysAndMonthsLocalization.test.js +107 -0
  145. package/src/hooks/useInMemoryPaging.js +78 -0
  146. package/src/hooks/useInMemoryPaging.test.js +515 -0
  147. package/src/hooks/useMultipleFieldEditState.js +11 -4
  148. package/src/hooks/useMultipleFieldEditState.test.js +49 -1
  149. package/src/reducers/metadata.js +6 -1
  150. package/src/reducers/metadata.test.js +31 -0
  151. package/src/requests +1 -0
  152. package/src/schemas/metadata.js +3 -0
  153. package/src/selectors/locale.js +1 -1
  154. package/src/selectors/metadata.js +12 -9
  155. package/src/selectors/metadata.test.js +92 -11
  156. package/src/sharedMessages.js +184 -0
  157. package/src/timezones.json +883 -0
  158. package/src/translations/en-US.json +46 -0
  159. package/src/translations/fr-CA.json +46 -0
  160. package/src/utils/ListHelper.js +203 -0
  161. package/src/utils/ListHelper.test.js +710 -0
  162. package/src/utils/comparisonHelper.js +135 -0
  163. package/src/utils/comparisonHelper.test.js +334 -0
  164. package/src/utils/propertyBagHelper.js +2 -0
  165. package/src/utils/propertyBagHelper.test.js +6 -0
  166. package/src/utils/timezoneHelper.js +10 -135
  167. package/src/utils/timezoneHelper.test.js +7 -7
  168. package/dist/components/Form/FieldList.js +0 -270
  169. package/dist/components/Form/Inputs/FieldButtons.js +0 -66
  170. package/dist/components/Form/Inputs/Number.js +0 -117
  171. package/dist/components/Form/Inputs/SmallButton.js +0 -91
  172. package/dist/components/Form/Inputs/Time.js +0 -86
  173. package/dist/components/Form/Inputs/Translation.js +0 -169
  174. package/src/components/AppFrame/ApplicationSelector/Header.js +0 -34
  175. package/src/components/AppFrame/ApplicationSelector/Header.test.js +0 -23
  176. package/src/components/Form/FieldList.js +0 -210
  177. package/src/components/Form/FieldList.test.js +0 -558
  178. package/src/components/Form/Inputs/FieldButtons.js +0 -90
  179. package/src/components/Form/Inputs/Number.js +0 -60
  180. package/src/components/Form/Inputs/Number.test.js +0 -435
  181. package/src/components/Form/Inputs/SmallButton.js +0 -37
  182. package/src/components/Form/Inputs/SmallButton.test.js +0 -65
  183. package/src/components/Form/Inputs/Time.js +0 -32
  184. package/src/components/Form/Inputs/Time.test.js +0 -41
  185. package/src/components/Form/Inputs/Translation.js +0 -93
  186. package/src/components/Form/Inputs/Translation.test.js +0 -204
@@ -1,29 +1,32 @@
1
1
  import React from "react";
2
- import styled from "styled-components";
3
- import Text from "../Text";
4
- import { getThemeProp } from "../../utils";
2
+ import { FormattedMessage } from "react-intl";
3
+ import { makeStyles } from "@material-ui/core/styles";
5
4
  import sharedMessages from "./../../sharedMessages";
6
5
 
7
- export const HelpLink = styled.a`
8
- font-family: ${getThemeProp(["fonts", "header"], "sans-serif")};
9
- font-size: 12px;
10
- text-transform: uppercase;
11
- color: ${getThemeProp(["colors", "textLight"], "#cccccc")};
12
- width: 40px;
13
- cursor: pointer;
14
- padding-top: 14px;
15
- padding-right: 10px;
16
- text-decoration: none;
17
- &:hover {
18
- color: ${getThemeProp(["colors", "application", "base"], "#cccccc")};
19
- }
20
- `;
6
+ const useStyles = makeStyles(theme => ({
7
+ helpLink: {
8
+ fontFamily: theme.typography.button.fontFamily,
9
+ fontSize: "12px",
10
+ textTransform: "uppercase",
11
+ color: theme.palette.grey.borders,
12
+ width: "40px",
13
+ cursor: "pointer",
14
+ paddingTop: "14px",
15
+ paddingRight: "10px",
16
+ textDecoration: "none",
17
+ "&:hover": {
18
+ color: theme.palette.primary.light,
19
+ },
20
+ },
21
+ }));
21
22
 
22
23
  const Help = ({ helpUrl }) => {
24
+ const classes = useStyles();
25
+
23
26
  return (
24
- <HelpLink href={helpUrl} target="_blank">
25
- <Text message={sharedMessages.help} />
26
- </HelpLink>
27
+ <a href={helpUrl} target="_blank" rel="noreferrer" className={classes.helpLink}>
28
+ <FormattedMessage {...sharedMessages.help} />
29
+ </a>
27
30
  );
28
31
  };
29
32
 
@@ -2,7 +2,7 @@ import React from "react";
2
2
  import Immutable from "immutable";
3
3
  import { Provider } from "react-redux";
4
4
  import { IntlProvider } from "react-intl";
5
- import Help, { HelpLink } from "./Help";
5
+ import Help from "./Help";
6
6
  import { extractMessages } from "./../../utils/testUtils";
7
7
  import sharedMessages from "./../../sharedMessages";
8
8
  import { stringifyWithoutQuotes } from "./../../utils/parseHelper";
@@ -50,7 +50,7 @@ describe("Help", () => {
50
50
  </Provider>,
51
51
  "when mounted",
52
52
  "to satisfy",
53
- <HelpLink href="any_help_url.com">{stringifyWithoutQuotes(messages["orc-shared.help"])}</HelpLink>,
53
+ <a href="any_help_url.com">{stringifyWithoutQuotes(messages["orc-shared.help"])}</a>,
54
54
  ));
55
55
 
56
56
  it("sets css for help button ", () =>
@@ -62,6 +62,6 @@ describe("Help", () => {
62
62
  </Provider>,
63
63
  "when mounted",
64
64
  "to have style rules satisfying",
65
- expect.it("to contain", "cursor: pointer;").and("to contain", ":hover {color: #cccccc;}"),
65
+ expect.it("to contain", "cursor: pointer;").and("to contain", ":hover {color: #7986cb;}"),
66
66
  ));
67
67
  });
@@ -1,147 +1,127 @@
1
1
  import React, { useRef } from "react";
2
- import styled, { css } from "styled-components";
3
- import transition from "styled-transition-group";
2
+ import { makeStyles } from "@material-ui/core/styles";
4
3
  import { Link } from "react-router-dom";
5
- import { getThemeProp, ifFlag } from "../../utils";
6
- import Text from "../Text";
7
- import Icon from "../Icon";
4
+ import { FormattedMessage } from "react-intl";
5
+ import Icon from "../MaterialUI/DataDisplay/Icon";
8
6
 
9
- const FilteredLink = ({ menuToggle, staticContext, dispatch, active, component, ...props }) => <Link {...props} />;
7
+ const getToastColor = (theme, alertType) => {
8
+ const toastBorderColors = {
9
+ error: theme.palette.error.main,
10
+ warn: theme.palette.warning.main,
11
+ confirm: theme.palette.success.main,
12
+ };
13
+ return toastBorderColors[alertType] || "red";
14
+ };
10
15
 
11
- export const Block = styled(FilteredLink)`
12
- display: block;
13
- position: relative;
14
- padding: 0 10px;
15
- margin-bottom: 35px;
16
- color: ${ifFlag(
17
- "active",
18
- getThemeProp(["colors", "application", "highlight"]),
19
- getThemeProp(["colors", "textMedium"], "#999999"),
20
- )};
21
- text-decoration: none;
22
- cursor: pointer;
16
+ const useStyles = makeStyles(theme => ({
17
+ block: props => ({
18
+ display: "block",
19
+ position: "relative",
20
+ padding: "0 10px",
21
+ marginBottom: "35px",
22
+ textDecoration: "none",
23
+ cursor: "pointer",
24
+ color: props.active ? theme.palette.primary.light : theme.palette.text.hint,
23
25
 
24
- ${ifFlag(
25
- "menuToggle",
26
- "",
27
- css`
28
- &:hover {
29
- color: ${getThemeProp(["colors", "application", "highlight"], "#ffffff")};
30
- }
31
- `,
32
- )};
33
- `;
26
+ "&:hover": {
27
+ color: props.menuToggle ? undefined : theme.palette.primary.light,
28
+ },
29
+ }),
30
+ alert: props => {
31
+ const toastColor = getToastColor(theme, props.alertType);
34
32
 
35
- export const BlockWithA = Block.withComponent("a");
33
+ return {
34
+ borderRadius: "50%",
35
+ border: `4px solid ${toastColor}`,
36
+ position: "absolute",
37
+ top: 0,
38
+ left: "27px",
39
+ visibility: "hidden",
36
40
 
37
- export const Alert = styled.div`
38
- border-radius: 50%;
39
- border: 4px solid ${getThemeProp(["colors", "toasts", props => props.type], "red")};
40
- position: absolute;
41
- top: 0;
42
- left: 27px;
43
- `;
41
+ "&.show": {
42
+ visibility: "visible",
43
+ },
44
+ };
45
+ },
46
+ alertMessage: props => {
47
+ const toastColor = getToastColor(theme, props.alertType);
44
48
 
45
- const transformTime = ({ timeout }) => timeout;
46
- const opacityTime = ({ timeout }) => Math.round(timeout * 0.5);
47
- const opacityDelay = ({ timeout }) => Math.round(timeout * 0.25);
48
- // XXX: The below is a hack to get syntax highlighting in transition styles.
49
- // Adding the "transition" tag to styled-components tags would solve it.
50
- const alertStyling = css`
51
- position: absolute;
52
- z-index: 10000;
53
- top: calc(-10px - 0.7em);
54
- left: 22px;
55
- width: auto;
56
- width: max-content;
57
- border-radius: 5px;
58
- padding: 10px 15px;
59
- box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.5);
60
- color: ${getThemeProp(["colors", "textWhite"], "#efefef")};
61
- background-color: ${getThemeProp(["colors", "toasts", props => props.type], "red")};
62
- font-size: 11px;
63
- font-weight: bold;
64
- line-height: 1.2;
49
+ return {
50
+ position: "absolute",
51
+ zIndex: 10000,
52
+ top: "calc(-10px - 0.7em)",
53
+ left: "22px",
54
+ width: "max-content",
55
+ borderRadius: "5px",
56
+ padding: "10px 15px",
57
+ boxShadow: "0 2px 4px 0 rgba(0, 0, 0, 0.5)",
58
+ color: theme.palette.grey.light,
59
+ backgroundColor: toastColor,
60
+ fontSize: "11px",
61
+ fontWeight: "bold",
62
+ lineHeight: 1.2,
63
+ transition: `transform 200ms cubic-bezier(0.68, -0.55, 0.27, 1.55), opacity 100ms 50ms ease-out`,
64
+ opacity: 0.01,
65
+ transform: "translateX(-50%) scaleX(0)",
65
66
 
66
- &::before {
67
- content: "";
68
- position: absolute;
69
- top: calc(10px + 0.2em);
70
- left: -0.9em;
71
- border: solid transparent;
72
- border-width: 0.4em 0.9em 0.4em 0;
73
- border-right-color: ${getThemeProp(["colors", "toasts", props => props.type], "red")};
74
- }
75
- `;
76
- const transitionStatement = css`
77
- transition: transform ${transformTime}ms cubic-bezier(0.68, -0.55, 0.27, 1.55),
78
- opacity ${opacityTime}ms ${opacityDelay}ms ease-out;
79
- `;
80
- export const AlertMessage = transition.div`
81
- ${alertStyling}
82
- ${transitionStatement}
67
+ "&::before": {
68
+ content: "",
69
+ position: "absolute",
70
+ top: "calc(10px + 0.2em)",
71
+ left: "-0.9em",
72
+ border: "solid transparent",
73
+ borderWidth: "0.4em 0.9em 0.4em 0",
74
+ borderRightColor: toastColor,
75
+ },
83
76
 
84
- &:enter {
85
- opacity: 0.01;
86
- transform: translateX(-50%) scaleX(0);
87
- }
88
- &:enter-active {
89
- opacity: 1;
90
- transform: translateX(0) scaleX(1);
91
- }
92
- &:exit {
93
- opacity: 1;
94
- transform: translateX(0) scaleX(1);
95
- }
96
- &:exit-active {
97
- opacity: 0.01;
98
- transform: translateX(-50%) scaleX(0);
99
- }
100
- `;
101
- AlertMessage.defaultProps = { timeout: 200, unmountOnExit: true, appear: true };
77
+ "&.show": {
78
+ opacity: 1,
79
+ transform: "translateX(0) scaleX(1)",
80
+ },
81
+ };
82
+ },
83
+ menuIcon: props => ({
84
+ fontSize: "24px",
85
+ verticalAlign: "middle",
86
+ color: props.active ? theme.palette.primary.light : theme.palette.text.hint,
87
+ }),
88
+ label: props => ({
89
+ fontFamily: theme.typography.button.fontFamily,
90
+ fontSize: "13px",
91
+ verticalAlign: "middle",
92
+ textTransform: "uppercase",
93
+ paddingLeft: "10px",
94
+ transition: "opacity 0.3s ease-out",
95
+ opacity: props.showLabel ? 1 : 0,
96
+ }),
97
+ }));
102
98
 
103
- export const MenuIcon = styled(Icon)`
104
- font-size: 24px;
105
- vertical-align: middle;
106
- `;
99
+ const FilteredLink = ({ staticContext, dispatch, component, ...props }) => <Link {...props} />;
107
100
 
108
- export const Label = styled.span`
109
- font-family: ${getThemeProp(["fonts", "header"], "sans-serif")};
110
- font-size: 13px;
111
- vertical-align: middle;
112
- text-transform: uppercase;
113
- padding-left: 10px;
101
+ const MenuItem = ({ open = false, label = "", icon, alert, isHidden = false, href, menuToggle, active, ...props }) => {
102
+ const classes = useStyles({ active: active, menuToggle: menuToggle, alertType: alert?.type, showLabel: open });
114
103
 
115
- transition: opacity 0.3s ease-out;
116
- opacity: ${ifFlag("show", 1, 0)};
117
- `;
118
-
119
- const MenuItem = ({ open = false, label = "", icon, alert, isHidden = false, href, ...props }) => {
120
- let ItemWrapper = Block;
121
- if (props.menuToggle) {
122
- ItemWrapper = BlockWithA;
123
- }
124
104
  const alertMessage = useRef("");
125
- if (alert && alert.message) {
105
+ const showAlert = !!alert;
106
+ const showAlertMessage = !!alert?.message;
107
+ if (showAlert && showAlertMessage) {
126
108
  alertMessage.current = alert.message;
127
109
  }
128
110
 
111
+ if (isHidden) {
112
+ return false;
113
+ }
114
+
115
+ const ItemWrapper = menuToggle ? "a" : FilteredLink;
116
+
129
117
  return (
130
- !isHidden && (
131
- <ItemWrapper to={href} {...props}>
132
- <MenuIcon id={icon} />
133
- {alert ? (
134
- <Alert type={alert.type}>
135
- <AlertMessage in={!!alert.message} type={alert.type}>
136
- <Text message={alertMessage.current} />
137
- </AlertMessage>
138
- </Alert>
139
- ) : null}
140
- <Label show={open}>
141
- <Text message={label} />
142
- </Label>
143
- </ItemWrapper>
144
- )
118
+ <ItemWrapper to={href} className={classes.block} {...props}>
119
+ <Icon id={icon} className={classes.menuIcon} />
120
+ <div className={`${classes.alert} ${showAlert ? "show" : undefined}`}>
121
+ <div className={`${classes.alertMessage} ${showAlertMessage ? "show" : undefined}`}>{alertMessage.current}</div>
122
+ </div>
123
+ <span className={classes.label}>{typeof label === "string" ? label : <FormattedMessage {...label} />}</span>
124
+ </ItemWrapper>
145
125
  );
146
126
  };
147
127
 
@@ -1,11 +1,14 @@
1
1
  import React from "react";
2
2
  import { Provider } from "react-redux";
3
- import { ThemeProvider } from "styled-components";
4
3
  import { MemoryRouter } from "react-router-dom";
5
4
  import { Ignore } from "unexpected-reaction";
6
- import MenuItem, { Block, MenuIcon, Label, Alert, AlertMessage } from "./MenuItem";
5
+ import MenuItem from "./MenuItem";
6
+ import { Link } from "react-router-dom";
7
+ import Icon from "../MaterialUI/DataDisplay/Icon";
8
+ import sharedMessages from "./../../sharedMessages";
9
+ import { extractMessages, TestWrapper } from "./../../utils/testUtils";
7
10
 
8
- const BlockWithA = Block.withComponent("a");
11
+ const messages = extractMessages(sharedMessages);
9
12
 
10
13
  describe("MenuItem", () => {
11
14
  let store = {
@@ -24,10 +27,11 @@ describe("MenuItem", () => {
24
27
  "when mounted",
25
28
  "to satisfy",
26
29
  <MemoryRouter>
27
- <Block id="test" data-test-id="test" to="/foo/test">
28
- <MenuIcon id="cake" />
30
+ <Link id="test" data-test-id="test" to="/foo/test">
31
+ <Icon id="cake" />
29
32
  <Ignore />
30
- </Block>
33
+ <Ignore />
34
+ </Link>
31
35
  </MemoryRouter>,
32
36
  ));
33
37
 
@@ -41,10 +45,11 @@ describe("MenuItem", () => {
41
45
  "when mounted",
42
46
  "to satisfy",
43
47
  <MemoryRouter>
44
- <BlockWithA id="test" menuToggle>
45
- <MenuIcon id="cake" />
48
+ <a id="test">
49
+ <Icon id="cake" />
50
+ <Ignore />
46
51
  <Ignore />
47
- </BlockWithA>
52
+ </a>
48
53
  </MemoryRouter>,
49
54
  ));
50
55
 
@@ -58,10 +63,11 @@ describe("MenuItem", () => {
58
63
  "when mounted",
59
64
  "to satisfy",
60
65
  <MemoryRouter>
61
- <Block id="test" to="/foo/test">
62
- <MenuIcon id="cake" />
63
- <Label>Test</Label>
64
- </Block>
66
+ <Link id="test" to="/foo/test">
67
+ <Icon id="cake" />
68
+ <Ignore />
69
+ <span>Test</span>
70
+ </Link>
65
71
  </MemoryRouter>,
66
72
  ));
67
73
 
@@ -75,12 +81,11 @@ describe("MenuItem", () => {
75
81
  "when mounted",
76
82
  "to satisfy",
77
83
  <MemoryRouter>
78
- <Block id="test" to="/foo/test">
79
- <MenuIcon id="cake" />
80
- <Label show>
81
- <Ignore />
82
- </Label>
83
- </Block>
84
+ <Link id="test" to="/foo/test">
85
+ <Icon id="cake" />
86
+ <Ignore />
87
+ <span></span>
88
+ </Link>
84
89
  </MemoryRouter>,
85
90
  ));
86
91
 
@@ -94,11 +99,13 @@ describe("MenuItem", () => {
94
99
  "when mounted",
95
100
  "to satisfy",
96
101
  <MemoryRouter>
97
- <Block id="test" to="/foo/test">
98
- <MenuIcon id="cake" />
99
- <Alert />
100
- <Label>Test</Label>
101
- </Block>
102
+ <Link id="test" to="/foo/test">
103
+ <Icon id="cake" />
104
+ <div className="show">
105
+ <div></div>
106
+ </div>
107
+ <span>Test</span>
108
+ </Link>
102
109
  </MemoryRouter>,
103
110
  ));
104
111
 
@@ -112,11 +119,13 @@ describe("MenuItem", () => {
112
119
  "when mounted",
113
120
  "to satisfy",
114
121
  <MemoryRouter>
115
- <Block id="test" to="/foo/test">
116
- <MenuIcon id="cake" />
117
- <Alert type="confirm" />
118
- <Label>Test</Label>
119
- </Block>
122
+ <Link id="test" to="/foo/test">
123
+ <Icon id="cake" />
124
+ <div className="show">
125
+ <div></div>
126
+ </div>
127
+ <span>Test</span>
128
+ </Link>
120
129
  </MemoryRouter>,
121
130
  ));
122
131
 
@@ -130,13 +139,13 @@ describe("MenuItem", () => {
130
139
  "when mounted",
131
140
  "to satisfy",
132
141
  <MemoryRouter>
133
- <Block id="test" to="/foo/test">
134
- <MenuIcon id="cake" />
135
- <Alert>
136
- <AlertMessage in>Test message</AlertMessage>
137
- </Alert>
138
- <Label>Test</Label>
139
- </Block>
142
+ <Link id="test" to="/foo/test">
143
+ <Icon id="cake" />
144
+ <div>
145
+ <div className="show">Test message</div>
146
+ </div>
147
+ <span>Test</span>
148
+ </Link>
140
149
  </MemoryRouter>,
141
150
  ));
142
151
 
@@ -156,15 +165,13 @@ describe("MenuItem", () => {
156
165
  "when mounted",
157
166
  "to satisfy",
158
167
  <MemoryRouter>
159
- <Block id="test" to="/foo/test">
160
- <MenuIcon id="cake" />
161
- <Alert type="warn">
162
- <AlertMessage in type="warn">
163
- Test message
164
- </AlertMessage>
165
- </Alert>
166
- <Label>Test</Label>
167
- </Block>
168
+ <Link id="test" to="/foo/test">
169
+ <Icon id="cake" />
170
+ <div>
171
+ <div className="show">Test message</div>
172
+ </div>
173
+ <span>Test</span>
174
+ </Link>
168
175
  </MemoryRouter>,
169
176
  ));
170
177
 
@@ -192,31 +199,27 @@ describe("MenuItem", () => {
192
199
  const hide = state => false;
193
200
 
194
201
  expect(
195
- <Provider store={store}>
196
- <MemoryRouter>
197
- <MenuItem
198
- id="test"
199
- href="/foo/test"
200
- icon="cake"
201
- label="Test"
202
- alert={{ message: "Test message", type: "warn" }}
203
- hide={hide}
204
- />
205
- </MemoryRouter>
206
- </Provider>,
202
+ <TestWrapper provider={{ store }} intlProvider={{ messages }} memoryRouter>
203
+ <MenuItem
204
+ id="test"
205
+ href="/foo/test"
206
+ icon="cake"
207
+ label={{ id: "Test", defaultMessage: "Test" }}
208
+ alert={{ message: "Test message", type: "warn" }}
209
+ hide={hide}
210
+ />
211
+ </TestWrapper>,
207
212
  "when mounted",
208
213
  "to satisfy",
209
- <MemoryRouter>
210
- <Block id="test" to="/foo/test">
211
- <MenuIcon id="cake" />
212
- <Alert type="warn">
213
- <AlertMessage in type="warn">
214
- Test message
215
- </AlertMessage>
216
- </Alert>
217
- <Label>Test</Label>
218
- </Block>
219
- </MemoryRouter>,
214
+ <TestWrapper provider={{ store }} intlProvider={{ messages }} memoryRouter>
215
+ <Link id="test" to="/foo/test">
216
+ <Icon id="cake" />
217
+ <div>
218
+ <div className="show">Test message</div>
219
+ </div>
220
+ <span>Test</span>
221
+ </Link>
222
+ </TestWrapper>,
220
223
  );
221
224
  });
222
225
 
@@ -237,108 +240,14 @@ describe("MenuItem", () => {
237
240
  "when mounted",
238
241
  "to satisfy",
239
242
  <MemoryRouter>
240
- <Block id="test" to="/foo/test">
241
- <MenuIcon id="cake" />
242
- <Alert type="warn">
243
- <AlertMessage in type="warn">
244
- Test message
245
- </AlertMessage>
246
- </Alert>
247
- <Label>Test</Label>
248
- </Block>
243
+ <Link id="test" to="/foo/test">
244
+ <Icon id="cake" />
245
+ <div>
246
+ <div className="show">Test message</div>
247
+ </div>
248
+ <span>Test</span>
249
+ </Link>
249
250
  </MemoryRouter>,
250
251
  );
251
252
  });
252
-
253
- describe("Block", () => {
254
- it("sets text color to highlight if active", () =>
255
- expect(
256
- <MemoryRouter>
257
- <Block to="" active />
258
- </MemoryRouter>,
259
- "when mounted",
260
- "to have style rules satisfying",
261
- "to contain",
262
- "color: #ffffff;",
263
- ));
264
-
265
- it("sets text color to grey if not active", () =>
266
- expect(
267
- <MemoryRouter>
268
- <Block to="" />
269
- </MemoryRouter>,
270
- "when mounted",
271
- "to have style rules satisfying",
272
- "to contain",
273
- "color: #999999;",
274
- ));
275
-
276
- it("adds a hover rule if menu flag is unset", () =>
277
- expect(
278
- <MemoryRouter>
279
- <Block to="" />
280
- </MemoryRouter>,
281
- "when mounted",
282
- "to have style rules satisfying",
283
- "to match",
284
- /:hover\s*\{[^}]*\bcolor: #ffffff;[^}]*\}/,
285
- ));
286
-
287
- it("does not add a hover rule if menuToggle flag is set", () =>
288
- expect(
289
- <MemoryRouter>
290
- <Block to="" menuToggle />
291
- </MemoryRouter>,
292
- "when mounted",
293
- "to have style rules satisfying",
294
- "not to match",
295
- /:hover\s*\{[^}]*\bcolor: #ffffff;[^}]*\}/,
296
- ));
297
- });
298
-
299
- describe("Label", () => {
300
- it("sets full opacity if open", () =>
301
- expect(<Label show />, "when mounted", "to have style rules satisfying", "to contain", "opacity: 1;"));
302
-
303
- it("sets zero opacity if not open", () =>
304
- expect(<Label />, "when mounted", "to have style rules satisfying", "to contain", "opacity: 0;"));
305
- });
306
-
307
- describe("Alert", () => {
308
- it("has a default color (red)", () =>
309
- expect(<Alert />, "when mounted", "to have style rules satisfying", "to match", /border: \d+px solid red/));
310
-
311
- it("has a default color", () =>
312
- expect(
313
- <ThemeProvider theme={{ colors: { toasts: { test: "blue" } } }}>
314
- <Alert type="test" />
315
- </ThemeProvider>,
316
- "when mounted",
317
- "to have style rules satisfying",
318
- "to match",
319
- /border: \d+px solid blue/,
320
- ));
321
- });
322
-
323
- describe("AlertMessage", () => {
324
- it("has a default color (red)", () =>
325
- expect(
326
- <AlertMessage in message="Test" />,
327
- "when mounted",
328
- "to have style rules satisfying",
329
- "to contain",
330
- "background-color: red",
331
- ));
332
-
333
- it("has a default color", () =>
334
- expect(
335
- <ThemeProvider theme={{ colors: { toasts: { test: "blue" } } }}>
336
- <AlertMessage in message="Test" type="test" />
337
- </ThemeProvider>,
338
- "when mounted",
339
- "to have style rules satisfying",
340
- "to contain",
341
- "background-color: blue",
342
- ));
343
- });
344
253
  });