@hedia/recommendation-screen 2.1.14 → 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.
- package/coverage/clover.xml +588 -590
- package/coverage/coverage-final.json +27 -27
- package/coverage/lcov-report/index.html +7 -7
- package/coverage/lcov-report/src/RecommendationScreen.tsx.html +1039 -70
- package/coverage/lcov-report/src/__tests__/index.html +1 -1
- package/coverage/lcov-report/src/__tests__/utils.tsx.html +35 -14
- package/coverage/lcov-report/src/components/Header.tsx.html +14 -5
- package/coverage/lcov-report/src/components/InfoBars.tsx.html +97 -13
- package/coverage/lcov-report/src/components/InvisibleNumberInput.tsx.html +206 -14
- package/coverage/lcov-report/src/components/LimitationMessage.tsx.html +20 -2
- package/coverage/lcov-report/src/components/LineSeparator.tsx.html +13 -4
- package/coverage/lcov-report/src/components/RecentInsulin.tsx.html +30 -3
- package/coverage/lcov-report/src/components/RecommendationModal.tsx.html +200 -20
- package/coverage/lcov-report/src/components/RecommendedCarbs.tsx.html +218 -20
- package/coverage/lcov-report/src/components/RecommendedInsulin.tsx.html +195 -27
- package/coverage/lcov-report/src/components/Remeasure.tsx.html +125 -14
- package/coverage/lcov-report/src/components/TransferToLogbook.tsx.html +71 -8
- package/coverage/lcov-report/src/components/TwoOptionModal.tsx.html +34 -10
- package/coverage/lcov-report/src/components/activity/Activity.tsx.html +58 -7
- package/coverage/lcov-report/src/components/activity/ActivityIcon.tsx.html +42 -3
- package/coverage/lcov-report/src/components/activity/ActivityIntensity.tsx.html +30 -6
- package/coverage/lcov-report/src/components/activity/index.html +1 -1
- package/coverage/lcov-report/src/components/index.html +10 -10
- package/coverage/lcov-report/src/components/mood/Emotion.tsx.html +85 -10
- package/coverage/lcov-report/src/components/mood/MoodIcon.tsx.html +87 -12
- package/coverage/lcov-report/src/components/mood/index.html +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/locale/i18nUtils.ts.html +47 -8
- package/coverage/lcov-report/src/locale/index.html +1 -1
- package/coverage/lcov-report/src/utils/AttentionMessages.tsx.html +235 -7
- package/coverage/lcov-report/src/utils/Constants.ts.html +71 -2
- package/coverage/lcov-report/src/utils/RecommendationError.tsx.html +89 -2
- package/coverage/lcov-report/src/utils/RecommendationUtils.ts.html +337 -40
- package/coverage/lcov-report/src/utils/Translations.ts.html +27 -3
- package/coverage/lcov-report/src/utils/Utils.ts.html +295 -19
- package/coverage/lcov-report/src/utils/Validations.ts.html +763 -61
- package/coverage/lcov-report/src/utils/index.html +1 -1
- package/coverage/lcov.info +1243 -1249
- package/ignore-git.sh +1 -0
- package/ignore-publish.sh +1 -0
- package/package.json +5 -3
- package/src/RecommendationScreen.d.ts +323 -6
- package/src/RecommendationScreen.js +234 -1
- package/src/__tests__/RecommendationScreen.test.js +35 -1
- package/src/__tests__/utils.d.ts +5 -5
- package/src/__tests__/utils.js +1 -1
- package/src/components/Header.d.ts +4 -43
- package/src/components/Header.js +3 -1
- package/src/components/Icon.d.ts +9 -2
- package/src/components/Icon.js +6 -1
- package/src/components/InfoBars.d.ts +28 -0
- package/src/components/InfoBars.js +23 -0
- package/src/components/InvisibleNumberInput.d.ts +66 -3
- package/src/components/InvisibleNumberInput.js +53 -0
- package/src/components/LimitationMessage.d.ts +6 -0
- package/src/components/LimitationMessage.js +4 -0
- package/src/components/LineSeparator.d.ts +4 -2
- package/src/components/LineSeparator.js +2 -0
- package/src/components/RecentInsulin.d.ts +10 -2
- package/src/components/RecentInsulin.js +7 -0
- package/src/components/RecommendationModal.d.ts +61 -3
- package/src/components/RecommendationModal.js +45 -0
- package/src/components/RecommendedCarbs.d.ts +71 -4
- package/src/components/RecommendedCarbs.js +56 -0
- package/src/components/RecommendedInsulin.d.ts +66 -4
- package/src/components/RecommendedInsulin.js +51 -5
- package/src/components/Remeasure.d.ts +38 -2
- package/src/components/Remeasure.js +31 -0
- package/src/components/TransferToLogbook.d.ts +23 -3
- package/src/components/TransferToLogbook.js +18 -0
- package/src/components/TwoOptionModal.d.ts +12 -1
- package/src/components/TwoOptionModal.js +3 -3
- package/src/components/activity/Activity.d.ts +21 -5
- package/src/components/activity/Activity.js +14 -0
- package/src/components/activity/ActivityIcon.d.ts +15 -0
- package/src/components/activity/ActivityIcon.js +14 -1
- package/src/components/activity/ActivityIntensity.d.ts +11 -4
- package/src/components/activity/ActivityIntensity.js +7 -0
- package/src/components/mood/Emotion.d.ts +26 -1
- package/src/components/mood/Emotion.js +20 -0
- package/src/components/mood/MoodIcon.d.ts +28 -2
- package/src/components/mood/MoodIcon.js +20 -2
- package/src/locale/i18nUtils.d.ts +13 -0
- package/src/locale/i18nUtils.js +13 -0
- package/src/types/enum.d.ts +10 -0
- package/src/types/enum.js +9 -0
- package/src/types/types.d.ts +9 -7
- package/src/utils/AttentionMessages.d.ts +65 -0
- package/src/utils/AttentionMessages.js +65 -1
- package/src/utils/Constants.d.ts +23 -0
- package/src/utils/Constants.js +23 -0
- package/src/utils/RecommendationError.d.ts +29 -0
- package/src/utils/RecommendationError.js +29 -0
- package/src/utils/RecommendationUtils.d.ts +98 -6
- package/src/utils/RecommendationUtils.js +92 -0
- package/src/utils/Translations.d.ts +7 -0
- package/src/utils/Translations.js +7 -0
- package/src/utils/Utils.d.ts +92 -0
- package/src/utils/Utils.js +94 -2
- package/src/utils/Validations.d.ts +232 -9
- package/src/utils/Validations.js +225 -2
- package/typedoc.json +13 -0
|
@@ -10,20 +10,51 @@ import { infoStyles } from "./InfoBars";
|
|
|
10
10
|
import InvisibleNumberInput from "./InvisibleNumberInput";
|
|
11
11
|
import LineSeparator from "./LineSeparator";
|
|
12
12
|
const { RecommendedCarbsTestIds } = Testing.Id;
|
|
13
|
+
/**
|
|
14
|
+
* The contents of the RecommendedCarbs component may vary quite a bit depending on data that was entered by the user
|
|
15
|
+
* and on the result of the recommendation calculation.
|
|
16
|
+
* For instance the part of the component that displays any recommendation of eating additional carbohydrates
|
|
17
|
+
* (composed by the renderRecommendedCarbs() method) will only be visible if it is actually recommended that the user eats additional carbohydrates.
|
|
18
|
+
*/
|
|
13
19
|
export default class RecommendedCarbs extends React.Component {
|
|
14
20
|
constructor() {
|
|
15
21
|
super(...arguments);
|
|
22
|
+
/** Initialise the state partialInput variable with undefined */
|
|
16
23
|
this.state = {
|
|
17
24
|
partialInput: undefined,
|
|
18
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Handle what should happen when the additional carbohydrates amount has been pressed.
|
|
28
|
+
* Uses the InvisibleNumberInput child component to enable the user to input the amount of additional carbohydrates that they are taking.
|
|
29
|
+
*/
|
|
19
30
|
this.showTextInput = () => {
|
|
20
31
|
this.callbackInput?.();
|
|
21
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Passed to the InvisibleNumberInput child component as a callback function to be called every time the content of the input field changes.
|
|
35
|
+
*
|
|
36
|
+
* Steps:
|
|
37
|
+
* 1. Save partialInput argument to the partialInput state variable.
|
|
38
|
+
* @param partialInput The contents of the input field.
|
|
39
|
+
*/
|
|
22
40
|
this.handlePartialInput = (partialInput) => {
|
|
23
41
|
this.setState({
|
|
24
42
|
partialInput,
|
|
25
43
|
});
|
|
26
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* Handle what happens when input in the InvisibleNumberInput child component is completed.
|
|
47
|
+
*
|
|
48
|
+
* Steps:
|
|
49
|
+
* 1. If the carbs argument is greater than or equal to 0:
|
|
50
|
+
* - If the carbs argument is greater than 300:
|
|
51
|
+
* - Set the partialInput state variable to the value of the recommemdedCarbs prop.
|
|
52
|
+
* - Return - An alert message with the message of CarbohydrateLimitError() and with an OK button for closing it.
|
|
53
|
+
* - Use carbs as argument to call the changedRecommendedCarbs prop callback function.
|
|
54
|
+
|
|
55
|
+
* @param carbs The numerical value of the input field at completion.
|
|
56
|
+
* @returns void
|
|
57
|
+
*/
|
|
27
58
|
this.handleChangedCarbs = (carbs) => {
|
|
28
59
|
if (carbs >= 0) {
|
|
29
60
|
if (carbs > 300) {
|
|
@@ -37,6 +68,19 @@ export default class RecommendedCarbs extends React.Component {
|
|
|
37
68
|
this.props.changedRecommendedCarbs(carbs);
|
|
38
69
|
}
|
|
39
70
|
};
|
|
71
|
+
/**
|
|
72
|
+
* Render the section of the component that displays the extra carbs that the user should eat
|
|
73
|
+
* and allows the user to change the contents to indicate how many extra carbs they are actually going to eat.
|
|
74
|
+
*
|
|
75
|
+
* Steps:
|
|
76
|
+
* 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.
|
|
77
|
+
* 2. Set a variable named totalCarbs to the sum of the enteredCarbs prop and shownCarbs rounded to the nearest integer.
|
|
78
|
+
* 3. Compose and return a JSX element consisting of the following sub-components
|
|
79
|
+
* - A cancel button to remove recommended carbs from the calculation - When tapped, call the removeRecommendedCarbs prop callback function.
|
|
80
|
+
* - The text from the shownCarbs variable from step 1 - When tapped, call the showTextInput() method.
|
|
81
|
+
* - Use renderRow() to display the value of totalCarbs.
|
|
82
|
+
* - InvisibleNumberInput for showing the keyboard to enable the user to enter a number.
|
|
83
|
+
*/
|
|
40
84
|
this.renderRecommendedCarbs = () => {
|
|
41
85
|
const shownCarbs = this.state.partialInput ?? Math.round(Number(this.props.recommendedCarbs));
|
|
42
86
|
const totalCarbs = Math.round(parseFloat(this.props.enteredCarbs) + Number(shownCarbs));
|
|
@@ -81,6 +125,12 @@ export default class RecommendedCarbs extends React.Component {
|
|
|
81
125
|
<InvisibleNumberInput testID={RecommendedCarbsTestIds.InvisibleCarbInput} negativeAllowed={false} cleanPartialInput={true} decimalPlaces={0} visible={(callback) => (this.callbackInput = callback)} partialInput={this.handlePartialInput} onEnd={this.handleChangedCarbs} startValue={this.props.recommendedCarbs} maxLength={3}/>
|
|
82
126
|
</React.Fragment>);
|
|
83
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* Display a row of information for the user. Specifically used to display the amount of carbohydrates that the user has entered.
|
|
130
|
+
* @param row The values to display
|
|
131
|
+
* @param testID Id used for component testing
|
|
132
|
+
* @returns A JSX element to display 3 strings on the screen: label, value, and a unit.
|
|
133
|
+
*/
|
|
84
134
|
this.renderRow = (row, testID) => {
|
|
85
135
|
return (<View style={[calculationStyles.borderContainer, { paddingVertical: `1%` }]}>
|
|
86
136
|
<View style={calculationStyles.rowContainer}>
|
|
@@ -99,6 +149,12 @@ export default class RecommendedCarbs extends React.Component {
|
|
|
99
149
|
</View>);
|
|
100
150
|
};
|
|
101
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Steps:
|
|
154
|
+
* 1. Convert the recommendedCarbs prop to a number and save that as a variable named carbs.
|
|
155
|
+
* 2. Use renderRow() to display the user’s entered amount of carbohydrates
|
|
156
|
+
* 3. If carbs is not a NaN-value and it is positive, call renderRecommendedCarbs() to display the carbohydrate recommendation.
|
|
157
|
+
*/
|
|
102
158
|
render() {
|
|
103
159
|
const carbs = Number(this.props.recommendedCarbs);
|
|
104
160
|
return (<React.Fragment>
|
|
@@ -1,22 +1,84 @@
|
|
|
1
1
|
import { UserSettings } from "@hedia/types";
|
|
2
2
|
import React from "react";
|
|
3
|
-
interface IProps {
|
|
3
|
+
export interface IProps {
|
|
4
|
+
/** The amount of insulin in units to display to the user as a recommendation. */
|
|
4
5
|
insulinRecommendation: number;
|
|
6
|
+
/** The amount of insulin introduced by the user. */
|
|
5
7
|
enteredInsulin: number | null;
|
|
8
|
+
/**
|
|
9
|
+
* The factor by which the recommendation was multiplied to get the reduced insulin amount.
|
|
10
|
+
* Used by the RecommendedInsulin component to check that the user’s input doesn’t exceed the maximum allowed.
|
|
11
|
+
* If no activity has been entered, this prop should be null.
|
|
12
|
+
* */
|
|
6
13
|
activityReduction: number | null;
|
|
14
|
+
/** Used to determine how the insulin amount should be rounded. */
|
|
7
15
|
injectionMethod: UserSettings.Enums.InjectionMethod;
|
|
16
|
+
/**
|
|
17
|
+
* Callback function taking a number as argument and giving no return value.
|
|
18
|
+
* To be called with the new value every time the content of the insulin input field gets changed.
|
|
19
|
+
*/
|
|
8
20
|
updateRecommendedInsulin(value: number): void;
|
|
9
21
|
}
|
|
10
|
-
interface IState {
|
|
22
|
+
export interface IState {
|
|
23
|
+
/** The entered amount of insulin as a string. */
|
|
11
24
|
partialInput?: string;
|
|
12
25
|
}
|
|
26
|
+
/** Input field for displaying the entered amount of insulin (which defaults to HDA’s recommendation) and allowing the user to edit it. */
|
|
13
27
|
export default class RecommendedInsulin extends React.Component<IProps, IState> {
|
|
28
|
+
/** Initialise the state partialInput variable with undefined */
|
|
29
|
+
state: IState;
|
|
30
|
+
/**
|
|
31
|
+
* Function taking no arguments and returning no value.
|
|
32
|
+
* Will be bound to the function that activates input for InvisibleNumberInput when that component has been mounted.
|
|
33
|
+
*/
|
|
14
34
|
callbackInput?: () => void;
|
|
15
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Called immediately after updating occurs. Not called for the initial render.
|
|
37
|
+
* The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
|
|
38
|
+
*
|
|
39
|
+
* Steps:
|
|
40
|
+
* 1. If the value of the enteredInsulin prop was changed, set the partialInput state variable to the new value.
|
|
41
|
+
* @param prevProps The previous component props
|
|
42
|
+
*/
|
|
16
43
|
componentDidUpdate(prevProps: IProps): void;
|
|
44
|
+
/**
|
|
45
|
+
* Handle what should happen when the InsulinRecommendation component has been pressed.
|
|
46
|
+
* Uses the InvisibleNumberInput child component to enable the user to input the amount of insulin that hey are taking.
|
|
47
|
+
*
|
|
48
|
+
* Steps:
|
|
49
|
+
* 1. Call the callbackInput() member method.
|
|
50
|
+
*/
|
|
17
51
|
handleOnPress: () => void;
|
|
52
|
+
/**
|
|
53
|
+
* Passed to the InvisibleNumberInput child component as a callback function to be called every time the content of the input field changes.
|
|
54
|
+
*
|
|
55
|
+
* Steps:
|
|
56
|
+
* 1. Assign a new local variable, replacedZero, with the value of the insulin argument string
|
|
57
|
+
* except for the first character if insulin is longer than 1 character and starts with a '0' but doesn’t start with ‘0.’.
|
|
58
|
+
* Otherwise set it to insulin. This would be better handled by converting it to a number: replacedZero = Number(insulin);
|
|
59
|
+
* 2. Save replacedZero to the partialInput state variable.
|
|
60
|
+
* 3. Return replacedZero
|
|
61
|
+
* @param insulin The contents of the input field.
|
|
62
|
+
* @returns The partially cleaned input.
|
|
63
|
+
*/
|
|
18
64
|
updatePartially: (insulin: string) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Handle what happens when input in the InvisibleNumberInput child component is completed.
|
|
67
|
+
*
|
|
68
|
+
* Steps:
|
|
69
|
+
* 1. Get the rounded insulin amount using the value argument and the injectionMethod prop as arguments for the Utils.roundValue() function.
|
|
70
|
+
* 2. Get the adjusted safety insulin limit (due to activity) by multiplying the activity reduction factor (which is 1 minus the activityReduction prop) with the SAFETY_INSULIN_LIMIT constant.
|
|
71
|
+
* 3. If the rounded value exceeds the adjusted safety threshold:
|
|
72
|
+
* - Call the updatePartially() method with the adjusted safety threshold to set the insulin amount to the capped value.
|
|
73
|
+
* - Return an Alert with a message about the insulin limit.
|
|
74
|
+
* 4. Call the updatePartially() method with the rounded value to set the entered insulin value.
|
|
75
|
+
* 5. Call the updateRecommendedInsulin callback function prop with rounded as the argument to report back the updated insulin amount to the parent RecommendationScreen component.
|
|
76
|
+
* @param value The numerical value of the input field at completion.
|
|
77
|
+
*/
|
|
19
78
|
handleUpdatedInsulin: (value: number) => void;
|
|
79
|
+
/**
|
|
80
|
+
* Render a JSX element to display the insulin input field with the current insulin amount value
|
|
81
|
+
* and using an InvisibleNumberInput component to enable input when the insulin amount is tapped.
|
|
82
|
+
*/
|
|
20
83
|
render: () => JSX.Element;
|
|
21
84
|
}
|
|
22
|
-
export {};
|
|
@@ -12,12 +12,36 @@ import { infoStyles } from "./InfoBars";
|
|
|
12
12
|
import InvisibleNumberInput from "./InvisibleNumberInput";
|
|
13
13
|
const { RecommendedInsulinTestIds } = Testing.Id;
|
|
14
14
|
const SAFETY_INSULIN_LIMIT = BolusCalculator.Constants.SAFETY_INSULIN_LIMIT;
|
|
15
|
+
/** Input field for displaying the entered amount of insulin (which defaults to HDA’s recommendation) and allowing the user to edit it. */
|
|
15
16
|
export default class RecommendedInsulin extends React.Component {
|
|
16
|
-
constructor(
|
|
17
|
-
super(
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
/** Initialise the state partialInput variable with undefined */
|
|
20
|
+
this.state = {
|
|
21
|
+
partialInput: undefined,
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Handle what should happen when the InsulinRecommendation component has been pressed.
|
|
25
|
+
* Uses the InvisibleNumberInput child component to enable the user to input the amount of insulin that hey are taking.
|
|
26
|
+
*
|
|
27
|
+
* Steps:
|
|
28
|
+
* 1. Call the callbackInput() member method.
|
|
29
|
+
*/
|
|
18
30
|
this.handleOnPress = () => {
|
|
19
31
|
this.callbackInput?.();
|
|
20
32
|
};
|
|
33
|
+
/**
|
|
34
|
+
* Passed to the InvisibleNumberInput child component as a callback function to be called every time the content of the input field changes.
|
|
35
|
+
*
|
|
36
|
+
* Steps:
|
|
37
|
+
* 1. Assign a new local variable, replacedZero, with the value of the insulin argument string
|
|
38
|
+
* except for the first character if insulin is longer than 1 character and starts with a '0' but doesn’t start with ‘0.’.
|
|
39
|
+
* Otherwise set it to insulin. This would be better handled by converting it to a number: replacedZero = Number(insulin);
|
|
40
|
+
* 2. Save replacedZero to the partialInput state variable.
|
|
41
|
+
* 3. Return replacedZero
|
|
42
|
+
* @param insulin The contents of the input field.
|
|
43
|
+
* @returns The partially cleaned input.
|
|
44
|
+
*/
|
|
21
45
|
this.updatePartially = (insulin) => {
|
|
22
46
|
const replacedZero = insulin.length > 1 && insulin.startsWith(`0`) && !insulin.startsWith(`0.`) ? insulin.substring(1) : insulin;
|
|
23
47
|
this.setState({
|
|
@@ -25,6 +49,19 @@ export default class RecommendedInsulin extends React.Component {
|
|
|
25
49
|
});
|
|
26
50
|
return replacedZero;
|
|
27
51
|
};
|
|
52
|
+
/**
|
|
53
|
+
* Handle what happens when input in the InvisibleNumberInput child component is completed.
|
|
54
|
+
*
|
|
55
|
+
* Steps:
|
|
56
|
+
* 1. Get the rounded insulin amount using the value argument and the injectionMethod prop as arguments for the Utils.roundValue() function.
|
|
57
|
+
* 2. Get the adjusted safety insulin limit (due to activity) by multiplying the activity reduction factor (which is 1 minus the activityReduction prop) with the SAFETY_INSULIN_LIMIT constant.
|
|
58
|
+
* 3. If the rounded value exceeds the adjusted safety threshold:
|
|
59
|
+
* - Call the updatePartially() method with the adjusted safety threshold to set the insulin amount to the capped value.
|
|
60
|
+
* - Return an Alert with a message about the insulin limit.
|
|
61
|
+
* 4. Call the updatePartially() method with the rounded value to set the entered insulin value.
|
|
62
|
+
* 5. Call the updateRecommendedInsulin callback function prop with rounded as the argument to report back the updated insulin amount to the parent RecommendationScreen component.
|
|
63
|
+
* @param value The numerical value of the input field at completion.
|
|
64
|
+
*/
|
|
28
65
|
this.handleUpdatedInsulin = (value) => {
|
|
29
66
|
const rounded = Utils.roundValue(value, this.props.injectionMethod);
|
|
30
67
|
// https://hedia.atlassian.net/browse/HDA-795
|
|
@@ -41,6 +78,10 @@ export default class RecommendedInsulin extends React.Component {
|
|
|
41
78
|
this.updatePartially(`${rounded}`);
|
|
42
79
|
this.props.updateRecommendedInsulin(rounded);
|
|
43
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* Render a JSX element to display the insulin input field with the current insulin amount value
|
|
83
|
+
* and using an InvisibleNumberInput component to enable input when the insulin amount is tapped.
|
|
84
|
+
*/
|
|
44
85
|
this.render = () => {
|
|
45
86
|
const paddingBottom = Platform.OS === `ios` ? `3%` : `1%`;
|
|
46
87
|
const shownInsulin = this.state.partialInput ?? this.props.insulinRecommendation ?? `0`;
|
|
@@ -66,10 +107,15 @@ export default class RecommendedInsulin extends React.Component {
|
|
|
66
107
|
<InvisibleNumberInput testID={RecommendedInsulinTestIds.InvisibleInsulinInput} decimalPlaces={3} negativeAllowed={false} cleanPartialInput={false} partialInput={this.updatePartially} onEnd={this.handleUpdatedInsulin} visible={(visible) => (this.callbackInput = visible)} startValue={`${shownInsulin}`}/>
|
|
67
108
|
</React.Fragment>);
|
|
68
109
|
};
|
|
69
|
-
this.state = {
|
|
70
|
-
partialInput: undefined,
|
|
71
|
-
};
|
|
72
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Called immediately after updating occurs. Not called for the initial render.
|
|
113
|
+
* The snapshot is only present if getSnapshotBeforeUpdate is present and returns non-null.
|
|
114
|
+
*
|
|
115
|
+
* Steps:
|
|
116
|
+
* 1. If the value of the enteredInsulin prop was changed, set the partialInput state variable to the new value.
|
|
117
|
+
* @param prevProps The previous component props
|
|
118
|
+
*/
|
|
73
119
|
componentDidUpdate(prevProps) {
|
|
74
120
|
const { enteredInsulin } = this.props;
|
|
75
121
|
if (prevProps.enteredInsulin !== enteredInsulin) {
|
|
@@ -1,13 +1,49 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
interface IProps {
|
|
2
|
+
export interface IProps {
|
|
3
|
+
/** The initial time (in hours) after which the user should be reminded to measure their BGL. */
|
|
3
4
|
remeasureTime: number;
|
|
5
|
+
/**
|
|
6
|
+
* Callback function taking a single number (the new remeasurement time) as argument
|
|
7
|
+
* Function to be called every time the slider component is changed to a new value.
|
|
8
|
+
*/
|
|
4
9
|
onSliderChange(value: number): void;
|
|
5
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* The Remeasure component has a slider child component that the user can drag to change
|
|
13
|
+
* when they will get a reminder notification about measuring their BGL again.
|
|
14
|
+
*/
|
|
6
15
|
export default class Remeasure extends React.Component<IProps> {
|
|
16
|
+
/** For holding a reference to the slider component so its initial value can be set (only one time) when the Remeasure component has been mounted. */
|
|
7
17
|
private slider?;
|
|
18
|
+
/**
|
|
19
|
+
* Called immediately after a component is mounted. Setting state here will trigger re-rendering.
|
|
20
|
+
*
|
|
21
|
+
* If the value of a slider component in React Native is set to track an outside state,
|
|
22
|
+
* the slider indicator may jump back and forth while updates to the value are propagated through the affected objects and components.
|
|
23
|
+
* Since we don’t need to change the value of the slider from the outside after initialising it to the default value,
|
|
24
|
+
* we simply set the default value (using setNativeProp) upon initialisation instead of using the slider’s normal value prop to set it.
|
|
25
|
+
*
|
|
26
|
+
* Steps:
|
|
27
|
+
* 1. Call the setNativeProps() method on the slider to set its value to the remeasureTime prop.
|
|
28
|
+
*/
|
|
8
29
|
componentDidMount(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Steps:
|
|
32
|
+
* 1. Use limitTime() to limit/clamp the value of remeasureTime in the range 0 to 6.
|
|
33
|
+
* 2. Call the onSliderChange prop callback function with the limited value as argument.
|
|
34
|
+
* @param remeasureTime The value of the remeasurement slider.
|
|
35
|
+
*/
|
|
9
36
|
handleSliderChange: (remeasureTime: number) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Steps:
|
|
39
|
+
* 1.Use Math.min() and Math.max() to clamp remeasureTime in the range 0 to 6 and return the result.
|
|
40
|
+
* @param remeasureTime The value of the remeasurement slider.
|
|
41
|
+
* @returns The limited remeasurement time in hours
|
|
42
|
+
*/
|
|
10
43
|
limitTime: (remeasureTime: number) => number;
|
|
44
|
+
/**
|
|
45
|
+
* Compose a JSX element for displaying the currently selected remeasurement time along
|
|
46
|
+
* with a horizontal slider for changing it in increments of 0.5 hours in the range 0 to 6.
|
|
47
|
+
*/
|
|
11
48
|
render(): JSX.Element;
|
|
12
49
|
}
|
|
13
|
-
export {};
|
|
@@ -6,22 +6,53 @@ import { i18n } from "../locale/i18nUtils";
|
|
|
6
6
|
import { Testing } from "../types/enum";
|
|
7
7
|
import { BORDER_COLOUR_GREY, BORDER_COLOUR_TEAL } from "../utils/Constants";
|
|
8
8
|
import { infoStyles } from "./InfoBars";
|
|
9
|
+
/**
|
|
10
|
+
* The Remeasure component has a slider child component that the user can drag to change
|
|
11
|
+
* when they will get a reminder notification about measuring their BGL again.
|
|
12
|
+
*/
|
|
9
13
|
export default class Remeasure extends React.Component {
|
|
10
14
|
constructor() {
|
|
11
15
|
super(...arguments);
|
|
16
|
+
/**
|
|
17
|
+
* Steps:
|
|
18
|
+
* 1. Use limitTime() to limit/clamp the value of remeasureTime in the range 0 to 6.
|
|
19
|
+
* 2. Call the onSliderChange prop callback function with the limited value as argument.
|
|
20
|
+
* @param remeasureTime The value of the remeasurement slider.
|
|
21
|
+
*/
|
|
12
22
|
this.handleSliderChange = (remeasureTime) => {
|
|
13
23
|
const limited = this.limitTime(remeasureTime);
|
|
14
24
|
this.props.onSliderChange(limited);
|
|
15
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Steps:
|
|
28
|
+
* 1.Use Math.min() and Math.max() to clamp remeasureTime in the range 0 to 6 and return the result.
|
|
29
|
+
* @param remeasureTime The value of the remeasurement slider.
|
|
30
|
+
* @returns The limited remeasurement time in hours
|
|
31
|
+
*/
|
|
16
32
|
this.limitTime = (remeasureTime) => {
|
|
17
33
|
return Math.min(Math.max(0, remeasureTime), 6);
|
|
18
34
|
};
|
|
19
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Called immediately after a component is mounted. Setting state here will trigger re-rendering.
|
|
38
|
+
*
|
|
39
|
+
* If the value of a slider component in React Native is set to track an outside state,
|
|
40
|
+
* the slider indicator may jump back and forth while updates to the value are propagated through the affected objects and components.
|
|
41
|
+
* Since we don’t need to change the value of the slider from the outside after initialising it to the default value,
|
|
42
|
+
* we simply set the default value (using setNativeProp) upon initialisation instead of using the slider’s normal value prop to set it.
|
|
43
|
+
*
|
|
44
|
+
* Steps:
|
|
45
|
+
* 1. Call the setNativeProps() method on the slider to set its value to the remeasureTime prop.
|
|
46
|
+
*/
|
|
20
47
|
componentDidMount() {
|
|
21
48
|
this.slider?.setNativeProps({
|
|
22
49
|
value: this.props.remeasureTime,
|
|
23
50
|
});
|
|
24
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Compose a JSX element for displaying the currently selected remeasurement time along
|
|
54
|
+
* with a horizontal slider for changing it in increments of 0.5 hours in the range 0 to 6.
|
|
55
|
+
*/
|
|
25
56
|
render() {
|
|
26
57
|
const measure = this.props.remeasureTime > 0;
|
|
27
58
|
const limited = this.limitTime(this.props.remeasureTime);
|
|
@@ -1,14 +1,34 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
interface IProps {
|
|
2
|
+
export interface IProps {
|
|
3
|
+
/** Whether or not the transfer button shall be visible on the screen. */
|
|
3
4
|
visible: boolean;
|
|
5
|
+
/** To be called when the button is pressed. */
|
|
4
6
|
transfer(): void;
|
|
5
7
|
}
|
|
6
|
-
interface IState {
|
|
8
|
+
export interface IState {
|
|
9
|
+
/** Keeps track of whether the button was already pressed and thus should be displayed in the inactive visually distinct pressed state. */
|
|
7
10
|
pressed: boolean;
|
|
8
11
|
}
|
|
12
|
+
/**
|
|
13
|
+
* Render a button for transferring the recommendation to a logbook entry.
|
|
14
|
+
* The button has a visually distinct pressed state to signal to the user that the button was actually activated before returning to the dashboard screen.
|
|
15
|
+
*/
|
|
9
16
|
export default class TransferToLogbook extends React.Component<IProps, IState> {
|
|
17
|
+
/** Initialise the state pressed variable with false */
|
|
10
18
|
state: IState;
|
|
19
|
+
/**
|
|
20
|
+
* Handle what happens when the button is pressed.
|
|
21
|
+
*
|
|
22
|
+
* Steps:
|
|
23
|
+
* 1. Toggle the pressed state to the opposite of its current value.
|
|
24
|
+
* 2. Call the transfer prop callback function.
|
|
25
|
+
*/
|
|
11
26
|
handlePress: () => void;
|
|
27
|
+
/**
|
|
28
|
+
* Steps:
|
|
29
|
+
* 1. If the visible prop is false, display an empty space to keep the correct margins in the screen.
|
|
30
|
+
* 2. Return a JSX element to display a touchable button (that is disabled when the pressed state is true)
|
|
31
|
+
* @returns JSX element for displaying the transfer button
|
|
32
|
+
*/
|
|
12
33
|
render(): JSX.Element;
|
|
13
34
|
}
|
|
14
|
-
export {};
|
|
@@ -4,12 +4,24 @@ import { t } from "@lingui/macro";
|
|
|
4
4
|
import { i18n } from "../locale/i18nUtils";
|
|
5
5
|
import { Testing } from "../types/enum";
|
|
6
6
|
import Icon from "./Icon";
|
|
7
|
+
/**
|
|
8
|
+
* Render a button for transferring the recommendation to a logbook entry.
|
|
9
|
+
* The button has a visually distinct pressed state to signal to the user that the button was actually activated before returning to the dashboard screen.
|
|
10
|
+
*/
|
|
7
11
|
export default class TransferToLogbook extends React.Component {
|
|
8
12
|
constructor() {
|
|
9
13
|
super(...arguments);
|
|
14
|
+
/** Initialise the state pressed variable with false */
|
|
10
15
|
this.state = {
|
|
11
16
|
pressed: false,
|
|
12
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Handle what happens when the button is pressed.
|
|
20
|
+
*
|
|
21
|
+
* Steps:
|
|
22
|
+
* 1. Toggle the pressed state to the opposite of its current value.
|
|
23
|
+
* 2. Call the transfer prop callback function.
|
|
24
|
+
*/
|
|
13
25
|
this.handlePress = () => {
|
|
14
26
|
this.setState({
|
|
15
27
|
pressed: !this.state.pressed,
|
|
@@ -17,6 +29,12 @@ export default class TransferToLogbook extends React.Component {
|
|
|
17
29
|
this.props.transfer();
|
|
18
30
|
};
|
|
19
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Steps:
|
|
34
|
+
* 1. If the visible prop is false, display an empty space to keep the correct margins in the screen.
|
|
35
|
+
* 2. Return a JSX element to display a touchable button (that is disabled when the pressed state is true)
|
|
36
|
+
* @returns JSX element for displaying the transfer button
|
|
37
|
+
*/
|
|
20
38
|
render() {
|
|
21
39
|
if (!this.props.visible) {
|
|
22
40
|
return <View style={addToLogbookStyles.marginContainer}/>;
|
|
@@ -1,19 +1,30 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
export interface ITwoOptionModalProps {
|
|
3
|
+
/** The title of the modal. */
|
|
3
4
|
title: string;
|
|
5
|
+
/** The message to show in the modal. */
|
|
4
6
|
message: string;
|
|
7
|
+
/** The label of the first option. */
|
|
5
8
|
textFirstOption: string;
|
|
9
|
+
/** The label of the second option. */
|
|
6
10
|
textSecondOption: string;
|
|
11
|
+
/** Whether or not the modal shall have a cancel button in the corner to close the modal. */
|
|
7
12
|
isCancelable?: boolean;
|
|
13
|
+
/** If true the buttons will be displayed side-by-side. If false the buttons will be displayed on top of each other. */
|
|
8
14
|
rowAsButtonLayout: boolean;
|
|
15
|
+
/** To be called if the user taps the first option button. */
|
|
9
16
|
firstOption(): void;
|
|
17
|
+
/** To be called if the user taps the second option button. */
|
|
10
18
|
secondOption(): void;
|
|
19
|
+
/** To be called if the user taps the optionally shown close button. */
|
|
11
20
|
onClose?(): void;
|
|
12
21
|
}
|
|
22
|
+
/** Display a modal with two buttons for the user to choose between. */
|
|
13
23
|
export default class TwoOptionModal extends React.Component<ITwoOptionModalProps> {
|
|
14
|
-
|
|
24
|
+
/** Compose a JSX element for displaying the modal. */
|
|
15
25
|
render(): JSX.Element;
|
|
16
26
|
}
|
|
27
|
+
/** @internal */
|
|
17
28
|
export declare const modalStyle: {
|
|
18
29
|
container: {
|
|
19
30
|
justifyContent: "center";
|
|
@@ -5,10 +5,9 @@ import { BACKGROUND_COLOUR_PURPLE, BORDER_COLOUR_GREY, BORDER_COLOUR_TEAL } from
|
|
|
5
5
|
import Icon from "./Icon";
|
|
6
6
|
import { stylesModal } from "./RecommendationModal";
|
|
7
7
|
const { TwoOptionModalTestIds } = Testing.Id;
|
|
8
|
+
/** Display a modal with two buttons for the user to choose between. */
|
|
8
9
|
export default class TwoOptionModal extends React.Component {
|
|
9
|
-
|
|
10
|
-
super(props);
|
|
11
|
-
}
|
|
10
|
+
/** Compose a JSX element for displaying the modal. */
|
|
12
11
|
render() {
|
|
13
12
|
const { rowAsButtonLayout, isCancelable } = this.props;
|
|
14
13
|
return (<View style={modalStyle.container}>
|
|
@@ -41,6 +40,7 @@ export default class TwoOptionModal extends React.Component {
|
|
|
41
40
|
}
|
|
42
41
|
}
|
|
43
42
|
const { height, width } = Dimensions.get(`screen`);
|
|
43
|
+
/** @internal */
|
|
44
44
|
export const modalStyle = StyleSheet.create({
|
|
45
45
|
container: {
|
|
46
46
|
...StyleSheet.absoluteFillObject,
|
|
@@ -1,10 +1,26 @@
|
|
|
1
|
+
import { Activity as ActivityTypes, BolusCalculator } from "@hedia/types";
|
|
1
2
|
import React from "react";
|
|
2
|
-
import { IActivityDisplayProps
|
|
3
|
-
interface IProps extends IActivityDisplayProps {
|
|
4
|
-
activity
|
|
5
|
-
|
|
3
|
+
import { IActivityDisplayProps } from "../../types/types";
|
|
4
|
+
export interface IProps extends IActivityDisplayProps {
|
|
5
|
+
/** Details about the activity that affect the calculation */
|
|
6
|
+
activity: BolusCalculator.Types.IActivityParams;
|
|
7
|
+
/** The fraction (in the interval [0; 1]) by which the insulin recommendation is being reduced due to physical activity */
|
|
8
|
+
activityReduction: ActivityTypes.Types.ReductionType;
|
|
6
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Component for displaying a summary of the entered physical activity along with the effect it has on the insulin recommendation.
|
|
12
|
+
*/
|
|
7
13
|
export default class Activity extends React.Component<IProps> {
|
|
14
|
+
/**
|
|
15
|
+
* Steps:
|
|
16
|
+
* 1. Unpack activity, activityType, activityReduction, and activityTitle from props.
|
|
17
|
+
* 2. Compute the reductionPercentage by multiplying the activityReduction prop by 100 and rounding to the nearest integer.
|
|
18
|
+
* 3. Generate and return the JSX element to display the following on the screen:
|
|
19
|
+
* - Print the activity duration.
|
|
20
|
+
* - Display the ActivityIcon that corresponds to the type of activity.
|
|
21
|
+
* - Display the ActivityIntensity for the activity.
|
|
22
|
+
* - Print the reductionPercentage.
|
|
23
|
+
* @returns JSX Element containing all the user's physical activity details
|
|
24
|
+
*/
|
|
8
25
|
render(): JSX.Element;
|
|
9
26
|
}
|
|
10
|
-
export {};
|
|
@@ -6,7 +6,21 @@ import { Testing } from "../../types/enum";
|
|
|
6
6
|
import { infoStyles } from "../InfoBars";
|
|
7
7
|
import ActivityIcon from "./ActivityIcon";
|
|
8
8
|
import ActivityIntensity from "./ActivityIntensity";
|
|
9
|
+
/**
|
|
10
|
+
* Component for displaying a summary of the entered physical activity along with the effect it has on the insulin recommendation.
|
|
11
|
+
*/
|
|
9
12
|
export default class Activity extends React.Component {
|
|
13
|
+
/**
|
|
14
|
+
* Steps:
|
|
15
|
+
* 1. Unpack activity, activityType, activityReduction, and activityTitle from props.
|
|
16
|
+
* 2. Compute the reductionPercentage by multiplying the activityReduction prop by 100 and rounding to the nearest integer.
|
|
17
|
+
* 3. Generate and return the JSX element to display the following on the screen:
|
|
18
|
+
* - Print the activity duration.
|
|
19
|
+
* - Display the ActivityIcon that corresponds to the type of activity.
|
|
20
|
+
* - Display the ActivityIntensity for the activity.
|
|
21
|
+
* - Print the reductionPercentage.
|
|
22
|
+
* @returns JSX Element containing all the user's physical activity details
|
|
23
|
+
*/
|
|
10
24
|
render() {
|
|
11
25
|
const { activity, activityType, activityReduction, activityTitle } = this.props;
|
|
12
26
|
const reductionPercentage = ((activityReduction ?? 0) * 100).toFixed(0);
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
import { Activity } from "@hedia/types";
|
|
1
2
|
import React from "react";
|
|
2
3
|
import { ImageURISource } from "react-native";
|
|
3
4
|
import { IActivityDisplayProps } from "../../types/types";
|
|
5
|
+
/** Mapping from ActivityEnums to corresponding image resource. */
|
|
6
|
+
export declare const ACTIVITY_ICONS: Record<Activity.Enums.ActivityEnum, ImageURISource>;
|
|
7
|
+
/** Component used to displat the user's physical activity type icon */
|
|
4
8
|
export default class ActivityIcon extends React.Component<IActivityDisplayProps> {
|
|
9
|
+
/**
|
|
10
|
+
* @returns The value from the ACTIVITY_ICONS constant that corresponds to the value of the activityType prop.
|
|
11
|
+
*/
|
|
5
12
|
getActivityIcon: () => ImageURISource;
|
|
13
|
+
/**
|
|
14
|
+
* Steps:
|
|
15
|
+
* 1. Unpack activityType and activityTitle from props.
|
|
16
|
+
* 2. Create an accessibility label string by appending ‘_activity’ to the enum label corresponding to the activityType prop.
|
|
17
|
+
* @returns A JSX element including the following:
|
|
18
|
+
* 1. An image component with the generated accessibility label displaying the icon from getActivityIcon().
|
|
19
|
+
* 2. The activityTitle if it is truthy or the string “Untitled Activity” otherwise
|
|
20
|
+
*/
|
|
6
21
|
render(): JSX.Element | null;
|
|
7
22
|
}
|
|
@@ -4,20 +4,33 @@ import React from "react";
|
|
|
4
4
|
import { Dimensions, Image, StyleSheet, Text, View } from "react-native";
|
|
5
5
|
import { i18n } from "../../locale/i18nUtils";
|
|
6
6
|
const { Other } = Activity.Enums.ActivityEnum;
|
|
7
|
-
|
|
7
|
+
/** Mapping from ActivityEnums to corresponding image resource. */
|
|
8
|
+
export const ACTIVITY_ICONS = {
|
|
8
9
|
Run: require(`../../assets/activity/Runner.png`),
|
|
9
10
|
Walk: require(`../../assets/activity/Walk.png`),
|
|
10
11
|
Cycling: require(`../../assets/activity/Cyclist.png`),
|
|
11
12
|
Swim: require(`../../assets/activity/Swimmer.png`),
|
|
12
13
|
Other: require(`../../assets/activity/Other.png`),
|
|
13
14
|
};
|
|
15
|
+
/** Component used to displat the user's physical activity type icon */
|
|
14
16
|
export default class ActivityIcon extends React.Component {
|
|
15
17
|
constructor() {
|
|
16
18
|
super(...arguments);
|
|
19
|
+
/**
|
|
20
|
+
* @returns The value from the ACTIVITY_ICONS constant that corresponds to the value of the activityType prop.
|
|
21
|
+
*/
|
|
17
22
|
this.getActivityIcon = () => {
|
|
18
23
|
return ACTIVITY_ICONS[this.props.activityType ?? Other];
|
|
19
24
|
};
|
|
20
25
|
}
|
|
26
|
+
/**
|
|
27
|
+
* Steps:
|
|
28
|
+
* 1. Unpack activityType and activityTitle from props.
|
|
29
|
+
* 2. Create an accessibility label string by appending ‘_activity’ to the enum label corresponding to the activityType prop.
|
|
30
|
+
* @returns A JSX element including the following:
|
|
31
|
+
* 1. An image component with the generated accessibility label displaying the icon from getActivityIcon().
|
|
32
|
+
* 2. The activityTitle if it is truthy or the string “Untitled Activity” otherwise
|
|
33
|
+
*/
|
|
21
34
|
render() {
|
|
22
35
|
const { activityType, activityTitle } = this.props;
|
|
23
36
|
const label = `${Activity.Enums.ActivityEnum[activityType ?? Other]}_activity`;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
import { BolusCalculator } from "@hedia/types";
|
|
1
2
|
import React from "react";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
activityIntensity: IActivityParams["activityIntensity"];
|
|
3
|
+
export interface IProps {
|
|
4
|
+
/** - Indicates the intensity of the activity. */
|
|
5
|
+
activityIntensity: BolusCalculator.Types.IActivityParams["activityIntensity"];
|
|
5
6
|
}
|
|
7
|
+
/** Component used to display the users's physical activity intensity on its corresponding background color */
|
|
6
8
|
export default class ActivityIntensity extends React.Component<IProps> {
|
|
9
|
+
/**
|
|
10
|
+
* Steps:
|
|
11
|
+
* 1. Set intensity to the activityIntensity prop.
|
|
12
|
+
* 2. Set the style variable to the style that correspond to the intensity.
|
|
13
|
+
* @returns JSX element that displays the intensity of the user’s activity along with the associated color coding
|
|
14
|
+
*/
|
|
7
15
|
render: () => JSX.Element;
|
|
8
16
|
}
|
|
9
|
-
export {};
|