@hedia/recommendation-screen 2.1.15 → 2.1.16

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 (102) hide show
  1. package/coverage/clover.xml +586 -588
  2. package/coverage/coverage-final.json +27 -27
  3. package/coverage/lcov-report/index.html +7 -7
  4. package/coverage/lcov-report/src/RecommendationScreen.tsx.html +979 -10
  5. package/coverage/lcov-report/src/__tests__/index.html +1 -1
  6. package/coverage/lcov-report/src/__tests__/utils.tsx.html +29 -8
  7. package/coverage/lcov-report/src/components/Header.tsx.html +13 -4
  8. package/coverage/lcov-report/src/components/InfoBars.tsx.html +86 -2
  9. package/coverage/lcov-report/src/components/InvisibleNumberInput.tsx.html +196 -4
  10. package/coverage/lcov-report/src/components/LimitationMessage.tsx.html +20 -2
  11. package/coverage/lcov-report/src/components/LineSeparator.tsx.html +12 -3
  12. package/coverage/lcov-report/src/components/RecentInsulin.tsx.html +30 -3
  13. package/coverage/lcov-report/src/components/RecommendationModal.tsx.html +184 -4
  14. package/coverage/lcov-report/src/components/RecommendedCarbs.tsx.html +205 -7
  15. package/coverage/lcov-report/src/components/RecommendedInsulin.tsx.html +187 -19
  16. package/coverage/lcov-report/src/components/Remeasure.tsx.html +114 -3
  17. package/coverage/lcov-report/src/components/TransferToLogbook.tsx.html +67 -4
  18. package/coverage/lcov-report/src/components/TwoOptionModal.tsx.html +34 -10
  19. package/coverage/lcov-report/src/components/activity/Activity.tsx.html +58 -7
  20. package/coverage/lcov-report/src/components/activity/ActivityIcon.tsx.html +42 -3
  21. package/coverage/lcov-report/src/components/activity/ActivityIntensity.tsx.html +30 -6
  22. package/coverage/lcov-report/src/components/activity/index.html +1 -1
  23. package/coverage/lcov-report/src/components/index.html +10 -10
  24. package/coverage/lcov-report/src/components/mood/Emotion.tsx.html +78 -3
  25. package/coverage/lcov-report/src/components/mood/MoodIcon.tsx.html +80 -5
  26. package/coverage/lcov-report/src/components/mood/index.html +1 -1
  27. package/coverage/lcov-report/src/index.html +1 -1
  28. package/coverage/lcov-report/src/locale/i18nUtils.ts.html +41 -2
  29. package/coverage/lcov-report/src/locale/index.html +1 -1
  30. package/coverage/lcov-report/src/utils/AttentionMessages.tsx.html +231 -3
  31. package/coverage/lcov-report/src/utils/Constants.ts.html +71 -2
  32. package/coverage/lcov-report/src/utils/RecommendationError.tsx.html +89 -2
  33. package/coverage/lcov-report/src/utils/RecommendationUtils.ts.html +306 -9
  34. package/coverage/lcov-report/src/utils/Translations.ts.html +27 -3
  35. package/coverage/lcov-report/src/utils/Utils.ts.html +278 -2
  36. package/coverage/lcov-report/src/utils/Validations.ts.html +716 -14
  37. package/coverage/lcov-report/src/utils/index.html +1 -1
  38. package/coverage/lcov.info +1158 -1164
  39. package/ignore-git.sh +1 -0
  40. package/ignore-publish.sh +1 -0
  41. package/package.json +5 -3
  42. package/src/RecommendationScreen.d.ts +323 -6
  43. package/src/RecommendationScreen.js +234 -1
  44. package/src/__tests__/RecommendationScreen.test.js +1 -1
  45. package/src/__tests__/utils.d.ts +5 -5
  46. package/src/__tests__/utils.js +1 -1
  47. package/src/components/Header.d.ts +4 -43
  48. package/src/components/Header.js +3 -1
  49. package/src/components/Icon.d.ts +9 -2
  50. package/src/components/Icon.js +6 -1
  51. package/src/components/InfoBars.d.ts +28 -0
  52. package/src/components/InfoBars.js +23 -0
  53. package/src/components/InvisibleNumberInput.d.ts +66 -3
  54. package/src/components/InvisibleNumberInput.js +53 -0
  55. package/src/components/LimitationMessage.d.ts +6 -0
  56. package/src/components/LimitationMessage.js +4 -0
  57. package/src/components/LineSeparator.d.ts +4 -2
  58. package/src/components/LineSeparator.js +2 -0
  59. package/src/components/RecentInsulin.d.ts +10 -2
  60. package/src/components/RecentInsulin.js +7 -0
  61. package/src/components/RecommendationModal.d.ts +61 -3
  62. package/src/components/RecommendationModal.js +45 -0
  63. package/src/components/RecommendedCarbs.d.ts +71 -4
  64. package/src/components/RecommendedCarbs.js +56 -0
  65. package/src/components/RecommendedInsulin.d.ts +66 -4
  66. package/src/components/RecommendedInsulin.js +51 -5
  67. package/src/components/Remeasure.d.ts +38 -2
  68. package/src/components/Remeasure.js +31 -0
  69. package/src/components/TransferToLogbook.d.ts +23 -3
  70. package/src/components/TransferToLogbook.js +18 -0
  71. package/src/components/TwoOptionModal.d.ts +12 -1
  72. package/src/components/TwoOptionModal.js +3 -3
  73. package/src/components/activity/Activity.d.ts +21 -5
  74. package/src/components/activity/Activity.js +14 -0
  75. package/src/components/activity/ActivityIcon.d.ts +15 -0
  76. package/src/components/activity/ActivityIcon.js +14 -1
  77. package/src/components/activity/ActivityIntensity.d.ts +11 -4
  78. package/src/components/activity/ActivityIntensity.js +7 -0
  79. package/src/components/mood/Emotion.d.ts +26 -1
  80. package/src/components/mood/Emotion.js +20 -0
  81. package/src/components/mood/MoodIcon.d.ts +28 -2
  82. package/src/components/mood/MoodIcon.js +20 -2
  83. package/src/locale/i18nUtils.d.ts +13 -0
  84. package/src/locale/i18nUtils.js +13 -0
  85. package/src/types/enum.d.ts +10 -0
  86. package/src/types/enum.js +9 -0
  87. package/src/types/types.d.ts +9 -7
  88. package/src/utils/AttentionMessages.d.ts +65 -0
  89. package/src/utils/AttentionMessages.js +65 -1
  90. package/src/utils/Constants.d.ts +23 -0
  91. package/src/utils/Constants.js +23 -0
  92. package/src/utils/RecommendationError.d.ts +29 -0
  93. package/src/utils/RecommendationError.js +29 -0
  94. package/src/utils/RecommendationUtils.d.ts +98 -6
  95. package/src/utils/RecommendationUtils.js +92 -0
  96. package/src/utils/Translations.d.ts +7 -0
  97. package/src/utils/Translations.js +7 -0
  98. package/src/utils/Utils.d.ts +92 -0
  99. package/src/utils/Utils.js +92 -0
  100. package/src/utils/Validations.d.ts +232 -9
  101. package/src/utils/Validations.js +225 -2
  102. package/typedoc.json +13 -0
@@ -1,26 +1,89 @@
1
1
  import React from "react";
2
2
  import { TextInput } from "react-native";
3
- interface IProps {
3
+ export interface IProps {
4
+ /** The initial value to put in the input field. */
4
5
  startValue?: string;
6
+ /** The precision with which the content of the input field may be displayed */
5
7
  decimalPlaces: number;
8
+ /** Whether or not the clean method should be used on the content every time it is changed */
6
9
  cleanPartialInput: boolean;
10
+ /** Whether or not negative values can be entered. */
7
11
  negativeAllowed: boolean;
12
+ /** Max length of the content in the input field. */
8
13
  maxLength?: number;
14
+ /** Test id used for component testing */
9
15
  testID: string;
16
+ /** Callback function taking a function as argument - For passing a reference for the input field’s to the parent component. */
10
17
  visible(toggle: () => void): void;
18
+ /** Callback function taking a number argument - To be called when the user finishes editing the invisible text field with the final numerical value as argument. */
11
19
  onEnd?(value: number): void;
20
+ /** Callback function taking a string as input and not returning anything - To be called every time the content in the input field changes. */
12
21
  partialInput?(value: string): void;
13
22
  }
14
- interface IState {
23
+ export interface IState {
24
+ /** For storing the value of the text input so it is available for handling in onEndEdit() when editing the text input ends. */
15
25
  value: string;
16
26
  }
27
+ /**
28
+ * InvisibleNumberInput is used to enable numerical input by the user without displaying a traditional input field on the screen.
29
+ * Since the input field is made invisible and thus can’t be tapped directly by the user we need to be able to call
30
+ * its focus() method from the parent component in order to activate the input field and show the keyboard.
31
+ * We do this by defining a function that calls the input field’s focus() method inside the InvisibleNumberInput component when it has been mounted.
32
+ * This function is then passed to the parent by giving it as the argument for a callback function named visible.
33
+ */
17
34
  export default class InvisibleNumberInput extends React.Component<IProps, IState> {
35
+ /** For holding a reference to the TextInput component so it can be focused when the InvisibleNumberInput component has been mounted. */
18
36
  textInput?: TextInput;
37
+ /** Initialise the state value variable with `0` */
19
38
  state: IState;
39
+ /**
40
+ * Called immediately after a component is mounted. Setting state here will trigger re-rendering.
41
+ * Perform various initialisation steps:
42
+ * 1. Set the value state of the component to the startValue prop (or to '0' if it is undefined)
43
+ * 2. Call the visible callback function using an anonymous function as argument. The anonymous function shall do the following:
44
+ * - Set the value state of the InvisibleNumberInput component to the startValue prop (or to '0' if it is undefined)
45
+ * - Return the value from calling the focus() method on the input field.
46
+ */
20
47
  componentDidMount(): void;
48
+ /**
49
+ * Sanitise a user-entered value by removing invalid characters
50
+ *
51
+ * Steps:
52
+ * 1. Use regular expressions to make the following manipulations to the text argument in the defined order and save the result to a local string variable named replaced.
53
+ * - Replace any commas with periods
54
+ * - Remove any characters that comes after two groups of zero or more digits separated by a period.
55
+ * 2. Define a function named round that rounds a given string that contains a number to have the amount of decimals given by the decimalPlaces prop. Return the result as a string.
56
+ * 3. If the value of the replaced variable from step 1 is not a NaN (not a number) when converted to a Number type then use the round function defined in step 2 on replaced and return the result
57
+ * 4. (If the NaN-check from step 2 didn’t fail) return the string '0'.
58
+
59
+ * @param text The string input to clean up
60
+ * @returns A string with the cleaned text.
61
+ */
21
62
  cleanInput: (text: string) => string;
63
+ /**
64
+ * Handle what happens when the text in the input field is being changed.
65
+ * That includes cleaning the text a little and then saving the value and potentially calling a callback function.
66
+ *
67
+ * Steps:
68
+ * 1. If the cleanPartialInput prop is true, use the cleanInput() method to to clean the content of the text argument and save it to a variable named cleaned.
69
+ * Otherwise just replace any commas in the text argument with periods and save the result to the same variable.
70
+ * 2. Remove repeated periods from the text in the cleaned variable and save the the result in a new variable named replacedSeparator.
71
+ * 3. Set the value state of the component to replacedSeparator.
72
+ * 4. If the partialInput callback function prop is defined, call it with replacedSeparator as argument.
73
+ * @param text The updated text in the input field
74
+ */
22
75
  handleOnChangeText: (text: string) => void;
76
+ /**
77
+ * Handle what should happen when the user finish editing the input field.
78
+ *
79
+ * Steps:
80
+ * 1. Use the cleanInput() method on the value state and store the result in a variable named cleaned.
81
+ * 2. If the onEnd prop is not null, then convert the value of cleaned to a number and use it as an argument to call the onEnd prop function.
82
+ */
23
83
  onEndEdit: () => void;
84
+ /**
85
+ * @returns JSX element to display a TextInput field with the component’s value state as its value
86
+ * and the handleOnChangeText() and onEndEdit() methods as the textInput’s onChangeText and onEndEditing respectively.
87
+ */
24
88
  render(): JSX.Element;
25
89
  }
26
- export {};
@@ -1,11 +1,33 @@
1
1
  import React from "react";
2
2
  import { StyleSheet, TextInput } from "react-native";
3
+ /**
4
+ * InvisibleNumberInput is used to enable numerical input by the user without displaying a traditional input field on the screen.
5
+ * Since the input field is made invisible and thus can’t be tapped directly by the user we need to be able to call
6
+ * its focus() method from the parent component in order to activate the input field and show the keyboard.
7
+ * We do this by defining a function that calls the input field’s focus() method inside the InvisibleNumberInput component when it has been mounted.
8
+ * This function is then passed to the parent by giving it as the argument for a callback function named visible.
9
+ */
3
10
  export default class InvisibleNumberInput extends React.Component {
4
11
  constructor() {
5
12
  super(...arguments);
13
+ /** Initialise the state value variable with `0` */
6
14
  this.state = {
7
15
  value: `0`,
8
16
  };
17
+ /**
18
+ * Sanitise a user-entered value by removing invalid characters
19
+ *
20
+ * Steps:
21
+ * 1. Use regular expressions to make the following manipulations to the text argument in the defined order and save the result to a local string variable named replaced.
22
+ * - Replace any commas with periods
23
+ * - Remove any characters that comes after two groups of zero or more digits separated by a period.
24
+ * 2. Define a function named round that rounds a given string that contains a number to have the amount of decimals given by the decimalPlaces prop. Return the result as a string.
25
+ * 3. If the value of the replaced variable from step 1 is not a NaN (not a number) when converted to a Number type then use the round function defined in step 2 on replaced and return the result
26
+ * 4. (If the NaN-check from step 2 didn’t fail) return the string '0'.
27
+
28
+ * @param text The string input to clean up
29
+ * @returns A string with the cleaned text.
30
+ */
9
31
  this.cleanInput = (text) => {
10
32
  const replaced = text.replace(/\,/g, `.`).replace(/(\d*\.\d*).*/, `$1`);
11
33
  const round = (value) => {
@@ -18,6 +40,18 @@ export default class InvisibleNumberInput extends React.Component {
18
40
  }
19
41
  return `0`;
20
42
  };
43
+ /**
44
+ * Handle what happens when the text in the input field is being changed.
45
+ * That includes cleaning the text a little and then saving the value and potentially calling a callback function.
46
+ *
47
+ * Steps:
48
+ * 1. If the cleanPartialInput prop is true, use the cleanInput() method to to clean the content of the text argument and save it to a variable named cleaned.
49
+ * Otherwise just replace any commas in the text argument with periods and save the result to the same variable.
50
+ * 2. Remove repeated periods from the text in the cleaned variable and save the the result in a new variable named replacedSeparator.
51
+ * 3. Set the value state of the component to replacedSeparator.
52
+ * 4. If the partialInput callback function prop is defined, call it with replacedSeparator as argument.
53
+ * @param text The updated text in the input field
54
+ */
21
55
  this.handleOnChangeText = (text) => {
22
56
  const cleaned = this.props.cleanPartialInput ? this.cleanInput(text) : text.replace(/\,/g, `.`);
23
57
  let replacedSeparator = cleaned.replace(/\.+/g, `.`).replace(/(\d*\.\d*).*/, `$1`);
@@ -29,11 +63,26 @@ export default class InvisibleNumberInput extends React.Component {
29
63
  });
30
64
  this.props.partialInput?.(`${replacedSeparator}`);
31
65
  };
66
+ /**
67
+ * Handle what should happen when the user finish editing the input field.
68
+ *
69
+ * Steps:
70
+ * 1. Use the cleanInput() method on the value state and store the result in a variable named cleaned.
71
+ * 2. If the onEnd prop is not null, then convert the value of cleaned to a number and use it as an argument to call the onEnd prop function.
72
+ */
32
73
  this.onEndEdit = () => {
33
74
  const cleaned = this.cleanInput(this.state.value);
34
75
  this.props.onEnd?.(Number(cleaned));
35
76
  };
36
77
  }
78
+ /**
79
+ * Called immediately after a component is mounted. Setting state here will trigger re-rendering.
80
+ * Perform various initialisation steps:
81
+ * 1. Set the value state of the component to the startValue prop (or to '0' if it is undefined)
82
+ * 2. Call the visible callback function using an anonymous function as argument. The anonymous function shall do the following:
83
+ * - Set the value state of the InvisibleNumberInput component to the startValue prop (or to '0' if it is undefined)
84
+ * - Return the value from calling the focus() method on the input field.
85
+ */
37
86
  componentDidMount() {
38
87
  this.setState({
39
88
  value: this.props.startValue ?? `0`,
@@ -45,6 +94,10 @@ export default class InvisibleNumberInput extends React.Component {
45
94
  return this.textInput?.focus();
46
95
  });
47
96
  }
97
+ /**
98
+ * @returns JSX element to display a TextInput field with the component’s value state as its value
99
+ * and the handleOnChangeText() and onEndEdit() methods as the textInput’s onChangeText and onEndEditing respectively.
100
+ */
48
101
  render() {
49
102
  const { testID } = this.props;
50
103
  return (<TextInput testID={testID} accessibilityLabel="InvisibleNumberInput" value={`${this.state.value}`} ref={(textInput) => {
@@ -1,8 +1,14 @@
1
1
  import * as React from "react";
2
2
  export interface ILimitationMessageProps {
3
+ /** The message to display to the user. */
3
4
  limitationMessage: string | null;
5
+ /** Callback function taking no arguments and giving no return value - To be called when the user presses the “OK” button. */
4
6
  onPressNextButton(): void;
5
7
  }
8
+ /** Display a message on the screen to inform the user that their insulin recommendation was limited. */
6
9
  export default class LimitationMessage extends React.Component<ILimitationMessageProps> {
10
+ /**
11
+ * @returns JSX element for displaying a dialog with the limitationMessage and an “OK” button that calls the onPressNextButton prop callback when tapped.
12
+ */
7
13
  render: () => JSX.Element;
8
14
  }
@@ -4,9 +4,13 @@ import { Text, TouchableOpacity, View } from "react-native";
4
4
  import { i18n } from "../locale/i18nUtils";
5
5
  import { Testing } from "../types/enum";
6
6
  import { stylesModal } from "./RecommendationModal";
7
+ /** Display a message on the screen to inform the user that their insulin recommendation was limited. */
7
8
  export default class LimitationMessage extends React.Component {
8
9
  constructor() {
9
10
  super(...arguments);
11
+ /**
12
+ * @returns JSX element for displaying a dialog with the limitationMessage and an “OK” button that calls the onPressNextButton prop callback when tapped.
13
+ */
10
14
  this.render = () => {
11
15
  const { limitationMessage } = this.props;
12
16
  return (<React.Fragment>
@@ -1,8 +1,10 @@
1
1
  import React from "react";
2
- interface IProps {
2
+ export interface IProps {
3
+ /** The color that the line should have. */
3
4
  color: string;
4
5
  }
6
+ /** Display a horizontal line for visually separating elements in the user interface. */
5
7
  export default class LineSeparator extends React.Component<IProps> {
8
+ /** @return JSX element for displaying a thin horizontal line in the given color. */
6
9
  render(): JSX.Element;
7
10
  }
8
- export {};
@@ -1,6 +1,8 @@
1
1
  import React from "react";
2
2
  import { StyleSheet, View } from "react-native";
3
+ /** Display a horizontal line for visually separating elements in the user interface. */
3
4
  export default class LineSeparator extends React.Component {
5
+ /** @return JSX element for displaying a thin horizontal line in the given color. */
4
6
  render() {
5
7
  return (<React.Fragment>
6
8
  <View style={[lineSeparatorStyles.lineStyle, { borderBottomColor: this.props.color }]}/>
@@ -1,9 +1,17 @@
1
1
  import React from "react";
2
- interface IProps {
2
+ export interface IProps {
3
+ /** Callback function taking no arguments and returning no value - To be called if the user presses the “Yes” button. */
3
4
  onRecentInsulinYes(): void;
5
+ /** Callback function taking no arguments and returning no value - To be called if the user presses the “No” button. */
4
6
  onRecentInsulinNo(): void;
5
7
  }
8
+ /** Display a card that prompts the user to recall if they injected insulin recently. */
6
9
  export default class RecentInsulin extends React.Component<IProps> {
10
+ /**
11
+ *
12
+ * @returns JSX element that displays a card with the question “Have you taken insulin within the last 4 hours? Along with two buttons labeled “Yes” and “No” respectively.
13
+ * If the user taps the “Yes” button, the onRecentInsulinYes prop callback function should be called.
14
+ * If the user taps the “No” button, the onRecentInsulinNo prop callback function should be called.
15
+ */
7
16
  render: () => JSX.Element;
8
17
  }
9
- export {};
@@ -4,9 +4,16 @@ import { Dimensions, StyleSheet, Text, TouchableOpacity, View } from "react-nati
4
4
  import { i18n } from "../locale/i18nUtils";
5
5
  import { Testing } from "../types/enum";
6
6
  import { infoStyles } from "./InfoBars";
7
+ /** Display a card that prompts the user to recall if they injected insulin recently. */
7
8
  export default class RecentInsulin extends React.Component {
8
9
  constructor() {
9
10
  super(...arguments);
11
+ /**
12
+ *
13
+ * @returns JSX element that displays a card with the question “Have you taken insulin within the last 4 hours? Along with two buttons labeled “Yes” and “No” respectively.
14
+ * If the user taps the “Yes” button, the onRecentInsulinYes prop callback function should be called.
15
+ * If the user taps the “No” button, the onRecentInsulinNo prop callback function should be called.
16
+ */
10
17
  this.render = () => {
11
18
  return (<View style={recentInsulinStyles.container}>
12
19
  <View style={recentInsulinStyles.titleContainer}>
@@ -1,25 +1,84 @@
1
1
  import * as React from "react";
2
- interface IModalProps {
2
+ export interface IModalProps {
3
+ /** Whether or not the modal should currently be displayed on the screen */
3
4
  isVisible: boolean;
5
+ /** The amount of additional carbohydrates that is being recommended for the user in grams. */
4
6
  suggestedCarbohydrates: number | null;
7
+ /** A message to display to the user to inform them in natural language about special recommendations or warnings from HDA. */
5
8
  attentionMessage: string | null;
9
+ /** A message to display to the user to inform them if their insulin recommendation was limited by the maximum threshold. */
6
10
  limitationMessage: string | null;
11
+ /** Callback function taking no arguments and returning no value - Should be called if the user taps the “OK” button on the modal. */
7
12
  onClickOkButton(): void;
13
+ /**
14
+ * Callback function taking no arguments and returning no value.
15
+ * Should be called if the user taps the “accept” button when they are recommended to eat additional carbohydrates.
16
+ */
8
17
  onAcceptCarbohydrates(): void;
18
+ /**
19
+ * Callback function taking no arguments and returning no value.
20
+ * Should be called if the user taps the “decline” button when they are recommended to eat additional carbohydrates.
21
+ */
9
22
  onDeclineCarbohydrates(): void;
10
23
  }
11
- interface IModalState {
24
+ export interface IModalState {
25
+ /** If true then the first page will be displayed, otherwise the second page will be displayed. */
12
26
  firstPageVisible: boolean;
13
27
  }
28
+ /**
29
+ * Popup modal for displaying information messages or warnings to the user if necessary.
30
+ * The modal has two “pages” with different content that it is able to display.
31
+ * The first page is for informing the user if their insulin recommendation was limited by the maximum insulin safety limit.
32
+ * This page will only be displayed if the recommendation was actually limited.
33
+ * The second page is for displaying a general attention message that may contain instructions for the user,
34
+ * and for letting the user know if they are being recommended eating additional carbohydrates.
35
+ */
14
36
  export default class RecommendationModal extends React.Component<IModalProps, IModalState> {
37
+ /**
38
+ * Steps:
39
+ * 1. Call the super() method with the props.
40
+ * 2. Set the firstPageVisible state variable true if the limitationMessage prop is truthy.
41
+ * @param props The class props
42
+ */
15
43
  constructor(props: IModalProps);
44
+ /**
45
+ * Handle what happens when the “next” button is pressed.
46
+ *
47
+ * Steps:
48
+ * 1. Unpack attentionMessage and suggestedCarbohydrates from the props object.
49
+ * 2. Define isPageVisible to be true if either attentionMessage or suggestedCarbohydrates is truthy.
50
+ * 3. If isPageVisible is true then set the firstPageVisible state variable to false. Otherwise call the onClickOkButton prop callback function.
51
+ */
16
52
  onPressNextButton: () => void;
53
+ /**
54
+ * @returns Return an JSX element for composing two buttons: one for accepting a suggestion and one for rejecting it.
55
+ * If the accept button is pressed the onAcceptCarbohydrates prop callback function shall be called.
56
+ * If the accept button is pressed the onDeclineCarbohydrates prop callback function shall be called.
57
+ */
17
58
  recommendationButtons: () => JSX.Element;
59
+ /**
60
+ * Compose a JSX element for displaying a recommendation of additional carbohydrates (the value of the suggestedCarbohydrates prop rounded to the nearest integer)
61
+ * to the user in a way that explains what to do with the suggestion.
62
+ * @param suggestedCarbohydrates the recommended additional carbohydrates
63
+ */
18
64
  recommendCarbohydrates: (suggestedCarbohydrates: number) => JSX.Element;
65
+ /**
66
+ * @returns JSX element for displaying the “second” page of the recommendation modal. The second page displays the string from the attentionMessage prop.
67
+ */
19
68
  secondPage: () => JSX.Element;
69
+ /**
70
+ * @returns JSX element for displaying the “first” page of the recommendation modal.
71
+ * The first page consists of a limitation message rendered using a LimitationMessage component.
72
+ */
20
73
  firstPage: () => JSX.Element;
74
+ /**
75
+ * @returns JSX element for rendering a modal that is visible if the isVisible prop is true.
76
+ * If the firstPageVisible state variable is true then use firstPage() to render the first page.
77
+ * Otherwise use secondPage() to render the second page.
78
+ */
21
79
  render(): JSX.Element;
22
80
  }
81
+ /** @internal */
23
82
  export declare const stylesModal: {
24
83
  modalStyle: {
25
84
  margin: number;
@@ -146,4 +205,3 @@ export declare const stylesModal: {
146
205
  justifyContent: "center";
147
206
  };
148
207
  };
149
- export {};
@@ -7,14 +7,41 @@ import { Testing } from "../types/enum";
7
7
  import { BORDER_COLOUR_TEAL } from "../utils/Constants";
8
8
  import LimitationMessage from "./LimitationMessage";
9
9
  const { RecommendationModalTestIds } = Testing.Id;
10
+ /**
11
+ * Popup modal for displaying information messages or warnings to the user if necessary.
12
+ * The modal has two “pages” with different content that it is able to display.
13
+ * The first page is for informing the user if their insulin recommendation was limited by the maximum insulin safety limit.
14
+ * This page will only be displayed if the recommendation was actually limited.
15
+ * The second page is for displaying a general attention message that may contain instructions for the user,
16
+ * and for letting the user know if they are being recommended eating additional carbohydrates.
17
+ */
10
18
  export default class RecommendationModal extends React.Component {
19
+ /**
20
+ * Steps:
21
+ * 1. Call the super() method with the props.
22
+ * 2. Set the firstPageVisible state variable true if the limitationMessage prop is truthy.
23
+ * @param props The class props
24
+ */
11
25
  constructor(props) {
12
26
  super(props);
27
+ /**
28
+ * Handle what happens when the “next” button is pressed.
29
+ *
30
+ * Steps:
31
+ * 1. Unpack attentionMessage and suggestedCarbohydrates from the props object.
32
+ * 2. Define isPageVisible to be true if either attentionMessage or suggestedCarbohydrates is truthy.
33
+ * 3. If isPageVisible is true then set the firstPageVisible state variable to false. Otherwise call the onClickOkButton prop callback function.
34
+ */
13
35
  this.onPressNextButton = () => {
14
36
  const { attentionMessage, suggestedCarbohydrates } = this.props;
15
37
  const isPageVisible = !!attentionMessage || !!suggestedCarbohydrates;
16
38
  return isPageVisible ? this.setState({ firstPageVisible: false }) : this.props.onClickOkButton();
17
39
  };
40
+ /**
41
+ * @returns Return an JSX element for composing two buttons: one for accepting a suggestion and one for rejecting it.
42
+ * If the accept button is pressed the onAcceptCarbohydrates prop callback function shall be called.
43
+ * If the accept button is pressed the onDeclineCarbohydrates prop callback function shall be called.
44
+ */
18
45
  this.recommendationButtons = () => {
19
46
  return (<View style={stylesModal.recommendationButtonsContainer}>
20
47
  <TouchableOpacity testID={RecommendationModalTestIds.AcceptCarbs} accessibilityLabel="yesButtonModal" style={stylesModal.affirmativeCarbsButton} onPress={this.props.onAcceptCarbohydrates}>
@@ -25,6 +52,11 @@ export default class RecommendationModal extends React.Component {
25
52
  </TouchableOpacity>
26
53
  </View>);
27
54
  };
55
+ /**
56
+ * Compose a JSX element for displaying a recommendation of additional carbohydrates (the value of the suggestedCarbohydrates prop rounded to the nearest integer)
57
+ * to the user in a way that explains what to do with the suggestion.
58
+ * @param suggestedCarbohydrates the recommended additional carbohydrates
59
+ */
28
60
  this.recommendCarbohydrates = (suggestedCarbohydrates) => {
29
61
  const displayCarbs = Math.round(suggestedCarbohydrates);
30
62
  return (<React.Fragment>
@@ -52,6 +84,9 @@ export default class RecommendationModal extends React.Component {
52
84
  </View>
53
85
  </React.Fragment>);
54
86
  };
87
+ /**
88
+ * @returns JSX element for displaying the “second” page of the recommendation modal. The second page displays the string from the attentionMessage prop.
89
+ */
55
90
  this.secondPage = () => {
56
91
  const { attentionMessage, suggestedCarbohydrates } = this.props;
57
92
  const willRecommendCarbs = suggestedCarbohydrates !== null && suggestedCarbohydrates > 0;
@@ -70,6 +105,10 @@ export default class RecommendationModal extends React.Component {
70
105
  </View>)}
71
106
  </React.Fragment>);
72
107
  };
108
+ /**
109
+ * @returns JSX element for displaying the “first” page of the recommendation modal.
110
+ * The first page consists of a limitation message rendered using a LimitationMessage component.
111
+ */
73
112
  this.firstPage = () => {
74
113
  const { limitationMessage } = this.props;
75
114
  return <LimitationMessage limitationMessage={limitationMessage} onPressNextButton={this.onPressNextButton}/>;
@@ -78,6 +117,11 @@ export default class RecommendationModal extends React.Component {
78
117
  firstPageVisible: !!this.props.limitationMessage,
79
118
  };
80
119
  }
120
+ /**
121
+ * @returns JSX element for rendering a modal that is visible if the isVisible prop is true.
122
+ * If the firstPageVisible state variable is true then use firstPage() to render the first page.
123
+ * Otherwise use secondPage() to render the second page.
124
+ */
81
125
  render() {
82
126
  const { isVisible } = this.props;
83
127
  const { firstPageVisible } = this.state;
@@ -96,6 +140,7 @@ const sugestionFontSize = width / 19;
96
140
  const recommendEatingFontSize = height / 45;
97
141
  const textFontSize = width / 20;
98
142
  const titleFontSize = width / 13;
143
+ /** @internal */
99
144
  export const stylesModal = StyleSheet.create({
100
145
  modalStyle: { margin: 0 },
101
146
  container: {
@@ -1,27 +1,94 @@
1
1
  import React from "react";
2
2
  import { Testing } from "../types/enum";
3
- interface ICalculationRow {
3
+ export interface ICalculationRow {
4
4
  label: string;
5
5
  value: string;
6
6
  units: string;
7
7
  }
8
- interface IProps {
8
+ export interface IProps {
9
+ /** The amount of carbs in grams that was recommended to and accepted by the user. */
9
10
  recommendedCarbs?: string;
11
+ /** The amount of carbs in grams that the user entered on the food screen. */
10
12
  enteredCarbs: string;
13
+ /** Callback function that doesn’t accept any arguments and doesn’t return anything - To be called every time the “remove additional carbs” button has been pressed. */
11
14
  removeRecommendedCarbs(): void;
15
+ /**
16
+ * Callback function that takes a single number as argument and doesn’t return anything.
17
+ * Function to be called when the entered carbohydrate value is changed by the user. The new value should be given as argument
18
+ */
12
19
  changedRecommendedCarbs(value: number): void;
13
20
  }
14
- interface IState {
21
+ export interface IState {
22
+ /** The internal value of the input field. */
15
23
  partialInput?: string;
16
24
  }
25
+ /**
26
+ * The contents of the RecommendedCarbs component may vary quite a bit depending on data that was entered by the user
27
+ * and on the result of the recommendation calculation.
28
+ * For instance the part of the component that displays any recommendation of eating additional carbohydrates
29
+ * (composed by the renderRecommendedCarbs() method) will only be visible if it is actually recommended that the user eats additional carbohydrates.
30
+ */
17
31
  export default class RecommendedCarbs extends React.Component<IProps, IState> {
32
+ /** Initialise the state partialInput variable with undefined */
18
33
  state: IState;
34
+ /**
35
+ * Function taking no arguments and returning no value.
36
+ * Will be bound to the function that activates input for InvisibleNumberInput when that component has been mounted.
37
+ */
19
38
  callbackInput?: () => void;
39
+ /**
40
+ * Handle what should happen when the additional carbohydrates amount has been pressed.
41
+ * Uses the InvisibleNumberInput child component to enable the user to input the amount of additional carbohydrates that they are taking.
42
+ */
20
43
  showTextInput: () => void;
44
+ /**
45
+ * Passed to the InvisibleNumberInput child component as a callback function to be called every time the content of the input field changes.
46
+ *
47
+ * Steps:
48
+ * 1. Save partialInput argument to the partialInput state variable.
49
+ * @param partialInput The contents of the input field.
50
+ */
21
51
  handlePartialInput: (partialInput: string) => void;
52
+ /**
53
+ * Handle what happens when input in the InvisibleNumberInput child component is completed.
54
+ *
55
+ * Steps:
56
+ * 1. If the carbs argument is greater than or equal to 0:
57
+ * - If the carbs argument is greater than 300:
58
+ * - Set the partialInput state variable to the value of the recommemdedCarbs prop.
59
+ * - Return - An alert message with the message of CarbohydrateLimitError() and with an OK button for closing it.
60
+ * - Use carbs as argument to call the changedRecommendedCarbs prop callback function.
61
+
62
+ * @param carbs The numerical value of the input field at completion.
63
+ * @returns void
64
+ */
22
65
  handleChangedCarbs: (carbs: number) => void;
66
+ /**
67
+ * Render the section of the component that displays the extra carbs that the user should eat
68
+ * and allows the user to change the contents to indicate how many extra carbs they are actually going to eat.
69
+ *
70
+ * Steps:
71
+ * 1. Set a variable named shownCarbs to the partialInput state if it is set, or to the recommendedCarbs prop rounded to the nearest integer otherwise.
72
+ * 2. Set a variable named totalCarbs to the sum of the enteredCarbs prop and shownCarbs rounded to the nearest integer.
73
+ * 3. Compose and return a JSX element consisting of the following sub-components
74
+ * - A cancel button to remove recommended carbs from the calculation - When tapped, call the removeRecommendedCarbs prop callback function.
75
+ * - The text from the shownCarbs variable from step 1 - When tapped, call the showTextInput() method.
76
+ * - Use renderRow() to display the value of totalCarbs.
77
+ * - InvisibleNumberInput for showing the keyboard to enable the user to enter a number.
78
+ */
23
79
  renderRecommendedCarbs: () => JSX.Element;
80
+ /**
81
+ * Display a row of information for the user. Specifically used to display the amount of carbohydrates that the user has entered.
82
+ * @param row The values to display
83
+ * @param testID Id used for component testing
84
+ * @returns A JSX element to display 3 strings on the screen: label, value, and a unit.
85
+ */
24
86
  renderRow: (row: ICalculationRow, testID: Testing.Id.RecommendedCarbsTestIds) => JSX.Element;
87
+ /**
88
+ * Steps:
89
+ * 1. Convert the recommendedCarbs prop to a number and save that as a variable named carbs.
90
+ * 2. Use renderRow() to display the user’s entered amount of carbohydrates
91
+ * 3. If carbs is not a NaN-value and it is positive, call renderRecommendedCarbs() to display the carbohydrate recommendation.
92
+ */
25
93
  render(): JSX.Element;
26
94
  }
27
- export {};