Skip to content

Commit fc697c7

Browse files
committed
#746 fixes to be tested
- should component update for frequently rendered components - do not deep clone tx objects - removed from some functions getting created repeatedly
1 parent cfb7735 commit fc697c7

File tree

12 files changed

+58
-139
lines changed

12 files changed

+58
-139
lines changed

packages/openchs-android/src/action/common/ObservationsHolderActions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import _ from "lodash";
22
import {Concept, Duration, FormElementGroup, ValidationResult} from 'avni-models';
33
import RuleEvaluationService from "../../service/RuleEvaluationService";
4+
import General from "../../utility/General";
45

56
class ObservationsHolderActions {
67
static updateFormElements(formElementGroup, state, context) {
78
const ruleService = context.get(RuleEvaluationService);
8-
let formElementStatuses = ruleService.getFormElementsStatuses(state.getEntity(), state.getEntityType(), formElementGroup, state.getEntityContext());
9+
const formElementStatuses = ruleService.getFormElementsStatuses(state.getEntity(), state.getEntityType(), formElementGroup, state.getEntityContext());
910
state.filteredFormElements = FormElementGroup._sortedFormElements(formElementGroup.filterElements(formElementStatuses));
1011
return formElementStatuses;
1112
}

packages/openchs-android/src/action/individual/EncounterActions.js

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,30 @@ import UserInfoService from "../../service/UserInfoService";
1515
import _ from "lodash";
1616
import {ObservationsHolder} from "openchs-models";
1717

18+
function getPreviousEncounter(action, form, context) {
19+
const previousEncounter = action.encounter.individual.findLastEncounterOfType(action.encounter, [action.encounter.encounterType.name]);
20+
if (previousEncounter) {
21+
action.encounter.observations = previousEncounter.cloneForEdit().observations;
22+
const observationsHolder = new ObservationsHolder(action.encounter.observations);
23+
let groupNo = 0;
24+
const firstGroupWithAllVisibleElementsEmpty = _.find(form.getFormElementGroups(),
25+
(formElementGroup) => {
26+
groupNo = groupNo + 1;
27+
const filteredFormElements = EncounterActions.filterFormElements(formElementGroup, context, previousEncounter);
28+
if (filteredFormElements.length === 0) return false;
29+
return formElementGroup.areAllFormElementsEmpty(filteredFormElements, observationsHolder);
30+
});
31+
32+
if (_.isNil(firstGroupWithAllVisibleElementsEmpty))
33+
action.allElementsFilledForImmutableEncounter = true;
34+
else
35+
action.pageNumber = groupNo;
36+
}
37+
return action.encounter;
38+
}
39+
1840
export class EncounterActions {
19-
static getInitialState(context) {
41+
static getInitialState() {
2042
return {};
2143
}
2244

@@ -31,29 +53,8 @@ export class EncounterActions {
3153
const form = formMapping && formMapping.form;
3254

3355
const encounterType = action.encounter.encounterType;
34-
const getPreviousEncounter = () => {
35-
const previousEncounter = action.encounter.individual.findLastEncounterOfType(action.encounter, [encounterType.name]);
36-
if (previousEncounter) {
37-
action.encounter.observations = previousEncounter.cloneForEdit().observations;
38-
const observationsHolder = new ObservationsHolder(action.encounter.observations);
39-
let groupNo = 0;
40-
const firstGroupWithAllVisibleElementsEmpty = _.find(form.getFormElementGroups(),
41-
(formElementGroup) => {
42-
groupNo = groupNo + 1;
43-
let filteredFormElements = EncounterActions.filterFormElements(formElementGroup, context, previousEncounter);
44-
if (filteredFormElements.length === 0) return false;
45-
return formElementGroup.areAllFormElementsEmpty(filteredFormElements, observationsHolder);
46-
});
47-
48-
if (_.isNil(firstGroupWithAllVisibleElementsEmpty))
49-
action.allElementsFilledForImmutableEncounter = true;
50-
else
51-
action.pageNumber = groupNo;
52-
}
53-
return action.encounter;
54-
};
55-
56-
const encounterToPass = encounterType.immutable && _.isUndefined(action.pageNumber) ? getPreviousEncounter() : action.encounter;
56+
const encounterToPass = encounterType.immutable && _.isUndefined(action.pageNumber) ?
57+
getPreviousEncounter(action, form, context) : action.encounter;
5758

5859
const firstGroupWithAtLeastOneVisibleElement = _.find(_.sortBy(form.nonVoidedFormElementGroups(), [function (o) {
5960
return o.displayOrder

packages/openchs-android/src/codeExamples/RealmExamples.js

Lines changed: 0 additions & 99 deletions
This file was deleted.

packages/openchs-android/src/framework/view/AbstractComponent.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,14 @@ class AbstractComponent extends Component {
4848
didFocus() {
4949
}
5050

51-
componentDidUpdate() {
52-
// General.logDebug((this.viewName ? this.viewName() : this.constructor.name), "DID UPDATE");
53-
}
51+
// shouldComponentUpdate(nextProps, nextState, nextContext): boolean {
52+
// General.logDebug((this.viewName ? this.viewName() : this.constructor.name), "SHOULD UPDATE");
53+
// return true;
54+
// }
55+
//
56+
// componentDidUpdate() {
57+
// General.logDebug((this.viewName ? this.viewName() : this.constructor.name), "DID UPDATE");
58+
// }
5459

5560
dispatchAction(action, params) {
5661
const type = action instanceof Function ? action.Id : action;

packages/openchs-android/src/state/EncounterActionState.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ class EncounterActionState extends AbstractDataEntryState {
2828

2929
clone() {
3030
const newState = new EncounterActionState();
31-
newState.encounter = _.isNil(this.encounter) ? this.encounter : this.encounter.cloneForEdit();
31+
// newState.encounter = _.isNil(this.encounter) ? this.encounter : this.encounter.cloneForEdit();
32+
newState.encounter = this.encounter;
3233
newState.previousEncountersDisplayed = this.previousEncountersDisplayed;
3334
newState.loadPullDownView = this.loadPullDownView;
3435
newState.messageDisplayed = this.messageDisplayed;

packages/openchs-android/src/views/ProgressBarView.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class ProgressBarView extends AbstractComponent {
5959
}
6060

6161
render() {
62+
if (!this.props.syncing) return null;
63+
6264
return (
6365
<Modal animationType={'fade'}
6466
transparent={true}

packages/openchs-android/src/views/SyncComponent.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class SyncComponent extends AbstractComponent {
208208
});
209209
const entitySyncStatusService = this.context.getService(EntitySyncStatusService);
210210
const totalPending = entitySyncStatusService.getTotalEntitiesPending();
211-
return !this.state.syncing && totalPending > 0 ? Badge(totalPending)(icon) : icon;
211+
return !this.state.syncing && totalPending > 0 ? Badge(icon, totalPending) : icon;
212212
}
213213

214214
render() {
@@ -234,9 +234,8 @@ class SyncComponent extends AbstractComponent {
234234

235235
}
236236

237-
238-
const Badge = (number) => (icon) => {
239-
const [height, width, fontSize, paddingLeft] = number > 99 ? [17, 17, 9, 0] : [17, 17, 11, 6];
237+
const Badge = function({icon, number}) {
238+
const [height, width, fontSize] = number > 99 ? [17, 17, 9, 0] : [17, 17, 11, 6];
240239
return (
241240
<View style={{
242241
width: 50,

packages/openchs-android/src/views/common/FormElementLabelWithDocumentation.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ class FormElementLabelWithDocumentation extends AbstractComponent {
125125
;
126126
}
127127

128+
shouldComponentUpdate(nextProps, nextState, nextContext): boolean {
129+
return this.props.moreTextForLabel !== nextProps.moreTextForLabel;
130+
}
131+
128132
getContentHtml(element) {
129133
const currentLocale = _.get(this.getService(UserInfoService).getUserSettings(), 'locale', 'en');
130134
const documentationItems = _.get(element.documentation, 'documentationItems', []);
@@ -140,7 +144,7 @@ class FormElementLabelWithDocumentation extends AbstractComponent {
140144
if (_.isNil(element)) return null;
141145
if (_.isNil(element.documentation)) return this.labelDisplay();
142146
const contentHtml = this.getContentHtml(element);
143-
return _.isEmpty(contentHtml) ? this.labelDisplay() : this.renderHtml(contentHtml)
147+
return _.isEmpty(contentHtml) ? this.labelDisplay() : this.renderHtml(contentHtml);
144148
}
145149
}
146150

packages/openchs-android/src/views/form/ValidationErrorMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ class ValidationErrorMessage extends AbstractComponent {
2020
}
2121
}
2222

23-
export default ValidationErrorMessage;
23+
export default ValidationErrorMessage;

packages/openchs-android/src/views/form/formElement/SelectFormElement.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
import {Text, View} from "react-native";
1+
import {View} from "react-native";
22
import PropTypes from 'prop-types';
33
import React from "react";
44
import _ from "lodash";
55
import AbstractFormElement from "./AbstractFormElement";
6-
import Colors from "../../primitives/Colors";
76
import Distances from "../../primitives/Distances";
8-
import PresetOptionItem from "../../primitives/PresetOptionItem";
97
import RadioGroup, {RadioLabelValue} from "../../primitives/RadioGroup";
108
import FormElementLabelWithDocumentation from "../../common/FormElementLabelWithDocumentation";
119

0 commit comments

Comments
 (0)