Skip to content

Commit d7aad4d

Browse files
committed
#701 AvniIcon to be able to use any type vector icon. Display color issues. Styling of wizard buttons.
1 parent 17dbc92 commit d7aad4d

File tree

10 files changed

+97
-86
lines changed

10 files changed

+97
-86
lines changed

packages/openchs-android/src/Playground.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, {Component} from 'react';
22
import {Text} from "react-native";
33
import RealmFactory from "./framework/db/RealmFactory";
44
import {Individual} from 'openchs-models';
5+
import _ from 'lodash';
56

67
const db = RealmFactory.createRealm();
78

@@ -11,8 +12,8 @@ export default class App extends Component {
1112
}
1213

1314
test() {
14-
const entitySyncStatuses = db.objects(Individual.schema.name);
15-
console.log("Playground-1", entitySyncStatuses.length);
15+
const encounters = db.objects("Encounter").filtered("uuid = $0", "0d84bf5d-29c7-4ada-b957-6992064033e1").map(_.identity);
16+
console.log("Playground-1", encounters[0].observations);
1617
}
1718

1819
render() {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from "react";
2+
import IconFactory from "./IconFactory";
3+
4+
export default function ({type, name, color}) {
5+
const IconType = IconFactory.getIcon(type);
6+
return <IconType name={name} color={color}/>;
7+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import MaterialIcons from "react-native-vector-icons/MaterialIcons";
22
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
33
import FontAwesome5 from "react-native-vector-icons/FontAwesome5";
44
import Entypo from "react-native-vector-icons/Entypo";
5+
import AntDesign from "react-native-vector-icons/AntDesign";
56

67
const map = new Map();
78
map.set("MaterialIcons", MaterialIcons);
89
map.set("MaterialCommunityIcons", MaterialCommunityIcons);
910
map.set("FontAwesome5", FontAwesome5);
1011
map.set("Entypo", Entypo);
12+
map.set("AntDesign", AntDesign);
1113

1214
class IconFactory {
1315
static getIcon(type) {

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ class IndividualProfile extends AbstractComponent {
4141
Program: 'Program',
4242
General: 'General',
4343
Wizard: 'Wizard',
44-
Individual: 'Individual'
44+
Individual: 'Individual',
45+
SystemRecommendations: 'SystemRecommendations'
4546
};
4647

4748
constructor(props, context) {
4849
super(props, context, Reducers.reducerKeys.individualProfile);
4950
}
5051

5152
getMobileNoFromObservation() {
52-
var i;
53+
let i;
5354
for (i = 0; i < this.props.individual.observations.length; i++) {
54-
const observation = this.props.individual.observations[i];
5555
return this.props.individual.getMobileNo();
5656
}
5757
}
@@ -204,9 +204,11 @@ class IndividualProfile extends AbstractComponent {
204204
render() {
205205
General.logDebug('IndividualProfile', 'render');
206206
const backgroundColor = this.props.individual.isGroup() ? Styles.groupSubjectBackground : Styles.defaultBackground;
207+
const textColor = (this.props.viewContext === IndividualProfile.viewContext.SystemRecommendations
208+
|| this.props.viewContext === IndividualProfile.viewContext.Wizard) ? Styles.blackColor : Styles.whiteColor;
207209
return <View style={{backgroundColor: backgroundColor}}>
208210
<CustomActivityIndicator loading={this.state.displayProgressIndicator}/>
209-
{this.props.viewContext !== IndividualProfile.viewContext.Wizard ?
211+
{(this.props.viewContext !== IndividualProfile.viewContext.Wizard && this.props.viewContext !== IndividualProfile.viewContext.SystemRecommendations) ?
210212
(
211213
<View style={{
212214
marginVertical: 10,
@@ -262,19 +264,20 @@ class IndividualProfile extends AbstractComponent {
262264
<View style={this.appendedStyle({
263265
flexDirection: 'column',
264266
backgroundColor: backgroundColor,
265-
paddingHorizontal: Distances.ContentDistanceFromEdge
267+
paddingHorizontal: Distances.ContentDistanceFromEdge,
268+
paddingVertical: Distances.ContentDistanceFromEdge
266269
})}>
267270
<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
268-
<Text style={Fonts.LargeBold}>{this.props.individual.nameString}</Text>
271+
<Text style={[Fonts.LargeBold, {color: textColor}]}>{this.props.individual.nameString}</Text>
269272
</View>
270273
{
271-
this.props.individual.subjectType.isPerson() ?
274+
this.props.individual.subjectType.isPerson() &&
272275
<View style={{flexDirection: 'row', justifyContent: 'space-between'}}>
273-
<Text style={{fontSize: Fonts.Normal}}>
276+
<Text style={{fontSize: Fonts.Normal, color: textColor}}>
274277
{this.I18n.t(this.props.individual.gender.name)}, {this.props.individual.getAge().toString(this.I18n)}</Text>
275278
<Text
276-
style={Fonts.LargeRegular}>{this.I18n.t(this.props.individual.lowestAddressLevel.name)}</Text>
277-
</View> : <View/>
279+
style={[Fonts.LargeRegular, {color: textColor}]}>{this.I18n.t(this.props.individual.lowestAddressLevel.name)}</Text>
280+
</View>
278281
}
279282
</View>
280283
)}

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,6 @@ import CustomActivityIndicator from "../CustomActivityIndicator";
2323
import PhoneCall from "../../model/PhoneCall";
2424
import {TaskActionNames as Actions} from "../../action/task/TaskActions";
2525

26-
const renderTypes = {
27-
Image: "Image",
28-
Text: "Text",
29-
};
30-
3126
class Observations extends AbstractComponent {
3227
static propTypes = {
3328
observations: PropTypes.any.isRequired,

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import AbstractComponent from "../../framework/view/AbstractComponent";
66
import _ from 'lodash';
77
import Colors from '../primitives/Colors';
88
import Distances from "../primitives/Distances";
9+
import AvniIcon from "./AvniIcon";
910

1011
class WizardButtons extends AbstractComponent {
1112
constructor(props, context) {
@@ -49,22 +50,21 @@ class WizardButtons extends AbstractComponent {
4950
<Button primary
5051
style={{
5152
flex: 0.5,
53+
flexDirection: "row",
5254
backgroundColor: Colors.SecondaryActionButtonColor,
53-
justifyContent: "center"
55+
justifyContent: "center",
56+
color: "#000"
5457
}}
55-
onPress={() => previousButton.func()}
56-
iconLeft={true}>
57-
<Icon style={{color: '#212121'}} name='stepbackward' type='AntDesign' />
58-
<Text style={{color: '#212121'}}>{previousButton.label}</Text>
59-
</Button> :
58+
_text={{color: "#212121"}}
59+
leftIcon={<AvniIcon color={'#212121'} name='stepbackward' type='AntDesign' />}
60+
onPress={() => previousButton.func()}>
61+
{previousButton.label}</Button> :
6062
<View style={{flex: 0.5}}/>}
6163
{nextButton.visible ?
6264
<Button primary
63-
style={{flex: 0.5, marginLeft: 8, justifyContent: "center"}}
65+
style={{flex: 0.5, flexDirection: "row", marginLeft: 8, justifyContent: "center"}}
6466
onPress={() => nextButton.func()}
65-
iconRight={true}>
66-
<Text>{nextButton.label}</Text>
67-
<Icon name='stepforward' type='AntDesign' />
67+
rightIcon={<AvniIcon color={Colors.buttonIconColor} name='stepforward' type='AntDesign'/>}>{nextButton.label}
6868
</Button> : <View style={{flex: 0.5}}/>}
6969
</View>
7070
</View>);

packages/openchs-android/src/views/conclusion/SystemRecommendationView.js

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {Alert, View} from "react-native";
55
import Path from "../../framework/routing/Path";
66
import IndividualProfile from "../common/IndividualProfile";
77
import FamilyProfile from "../familyfolder/FamilyProfile";
8-
import {Text} from "native-base";
8+
import {ScrollView, Text} from "native-base";
99
import TypedTransition from "../../framework/routing/TypedTransition";
1010
import WizardButtons from "../common/WizardButtons";
1111
import AppHeader from "../common/AppHeader";
@@ -81,7 +81,7 @@ class SystemRecommendationView extends AbstractComponent {
8181

8282
get nextAndMore() {
8383
let workListState = this.props.workListState;
84-
if(_.isNil(workListState))
84+
if (_.isNil(workListState))
8585
return {};
8686
if (!workListState.peekNextWorkItem()) return {};
8787

@@ -139,12 +139,12 @@ class SystemRecommendationView extends AbstractComponent {
139139
}
140140

141141
previous() {
142-
TypedTransition.from(this).goBack();
142+
TypedTransition.from(this).goBack();
143143
}
144144

145145
profile() {
146146
return (this.props.individual instanceof Individual) ?
147-
<IndividualProfile viewContext={IndividualProfile.viewContext.Wizard}
147+
<IndividualProfile viewContext={IndividualProfile.viewContext.SystemRecommendations}
148148
individual={this.props.individual} style={{
149149
backgroundColor: Colors.GreyContentBackground,
150150
paddingHorizontal: 24,
@@ -176,54 +176,59 @@ class SystemRecommendationView extends AbstractComponent {
176176
func={() => this.onAppHeaderBack(this.props.isSaveDraftOn)}
177177
displayHomePressWarning={!this.props.isSaveDraftOn}/>
178178
<RejectionMessage I18n={this.I18n} entityApprovalStatus={this.props.entityApprovalStatus}/>
179-
<View style={{flexDirection: 'column'}}>
180-
{!_.isNil(this.props.individual) && this.profile()}
181-
<View style={{flexDirection: 'column', marginHorizontal: Distances.ContentDistanceFromEdge}}>
182-
<View style={this.scaleStyle({paddingVertical: 12, flexDirection: 'column'})}>
183-
{
184-
this.props.validationErrors.map((validationResult, index) => {
185-
return (
186-
<View style={this.scaleStyle(SystemRecommendationView.styles.rulesRowView)}
187-
key={`error${index}`}>
188-
<Text style={{
189-
fontSize: Fonts.Medium,
190-
color: Colors.ValidationError
191-
}}>{this.I18n.t(validationResult.messageKey)}</Text>
192-
</View>
193-
);
194-
})
195-
}
196-
<Observations highlight
197-
observations={this.context.getService(ConceptService).getObservationsFromDecisions(this.props.decisions)}
198-
title={this.I18n.t('systemRecommendations')}/>
199-
</View>
200-
<NextScheduledVisits nextScheduledVisits={this.props.nextScheduledVisits.filter(nsv => _.isNil(nsv.subject))}
201-
title={this.I18n.t('visitsBeingScheduled')}/>
202-
<NextScheduledVisitsForOtherSubjects nextScheduledVisits={this.props.nextScheduledVisits.filter(nsv => !_.isNil(nsv.subject))}
203-
title={this.I18n.t('visitsBeingScheduledForOthers')}/>
204-
{!_.isNil(this.props.individual) &&
179+
<ScrollView>
180+
<View style={{flexDirection: 'column'}}>
181+
{!_.isNil(this.props.individual) && this.profile()}
182+
<View style={{flexDirection: 'column', marginHorizontal: Distances.ContentDistanceFromEdge}}>
183+
<View style={this.scaleStyle({paddingVertical: 12, flexDirection: 'column'})}>
184+
{
185+
this.props.validationErrors.map((validationResult, index) => {
186+
return (
187+
<View style={this.scaleStyle(SystemRecommendationView.styles.rulesRowView)}
188+
key={`error${index}`}>
189+
<Text style={{
190+
fontSize: Fonts.Medium,
191+
color: Colors.ValidationError
192+
}}>{this.I18n.t(validationResult.messageKey)}</Text>
193+
</View>
194+
);
195+
})
196+
}
197+
<Observations highlight
198+
observations={this.context.getService(ConceptService).getObservationsFromDecisions(this.props.decisions)}
199+
title={this.I18n.t('systemRecommendations')}/>
200+
</View>
201+
<NextScheduledVisits nextScheduledVisits={this.props.nextScheduledVisits.filter(nsv => _.isNil(nsv.subject))}
202+
title={this.I18n.t('visitsBeingScheduled')}/>
203+
<NextScheduledVisitsForOtherSubjects nextScheduledVisits={this.props.nextScheduledVisits.filter(nsv => !_.isNil(nsv.subject))}
204+
title={this.I18n.t('visitsBeingScheduledForOthers')}/>
205+
{!_.isNil(this.props.individual) &&
205206
<GroupAffiliationInformation individual={this.props.individual} I18n={this.I18n}/>}
206-
<Observations observations={this.props.observations} form={this.props.form}
207-
title={this.I18n.t('observations')}/>
208-
<WizardButtons previous={{func: () => !_.isUndefined(this.props.onPreviousCallback)? this.props.onPreviousCallback(this.context) : this.previous(), label: this.I18n.t('previous')}}
209-
next={{
210-
func: () => this.save(() => this.props.onSaveCallback(this)),
211-
visible: this.props.validationErrors.length === 0,
212-
label: this.I18n.t('save')
213-
}}
214-
nextAndMore={this.nextAndMore}
215-
style={{marginHorizontal: 24}}/>
207+
<Observations observations={this.props.observations} form={this.props.form}
208+
title={this.I18n.t('observations')}/>
209+
<WizardButtons previous={{
210+
func: () => !_.isUndefined(this.props.onPreviousCallback) ? this.props.onPreviousCallback(this.context) : this.previous(),
211+
label: this.I18n.t('previous')
212+
}}
213+
next={{
214+
func: () => this.save(() => this.props.onSaveCallback(this)),
215+
visible: this.props.validationErrors.length === 0,
216+
label: this.I18n.t('save')
217+
}}
218+
nextAndMore={this.nextAndMore}
219+
style={{marginHorizontal: 24}}/>
216220

221+
</View>
222+
<ApprovalDialog
223+
primaryButton={this.I18n.t('yes')}
224+
secondaryButton={this.I18n.t('no')}
225+
onPrimaryPress={() => this.onYesPress(() => this.props.onSaveCallback(this))}
226+
onSecondaryPress={() => this.onNoPress(() => this.props.onSaveCallback(this))}
227+
onClose={() => this.onClose()}
228+
state={this.getDialogState()}
229+
I18n={this.I18n}/>
217230
</View>
218-
<ApprovalDialog
219-
primaryButton={this.I18n.t('yes')}
220-
secondaryButton={this.I18n.t('no')}
221-
onPrimaryPress={() => this.onYesPress(() => this.props.onSaveCallback(this))}
222-
onSecondaryPress={() => this.onNoPress(() => this.props.onSaveCallback(this))}
223-
onClose={() => this.onClose()}
224-
state={this.getDialogState()}
225-
I18n={this.I18n}/>
226-
</View>
231+
</ScrollView>
227232
</CHSContent>
228233
</CHSContainer>
229234
);

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@ class NumericFormElement extends AbstractFormElement {
2323
allowedValues: PropTypes.array,
2424
isTableView: PropTypes.bool
2525
};
26-
state = {value: ''};
2726

2827
constructor(props, context) {
2928
super(props, context);
29+
this.state = {
30+
value: ""
31+
};
32+
if (props.value.getValue() !== _.toNumber(props.value.getValue())) {
33+
this.state.value = _.toString(props.value.getValue());
34+
}
3035
}
3136

3237
rangeText() {
@@ -49,14 +54,6 @@ class NumericFormElement extends AbstractFormElement {
4954
}));
5055
}
5156

52-
static getDerivedStateFromProps(props, state) {
53-
if (props.value.getValue() !== _.toNumber(state.value)) {
54-
return {
55-
value: _.toString(props.value.getValue())
56-
}
57-
}
58-
}
59-
6057
unitText() {
6158
return _.isEmpty(this.props.element.concept.unit) ? <Text></Text> :
6259
<Text style={Styles.formLabel}> ({this.props.element.concept.unit}) </Text>;

packages/openchs-android/src/views/primitives/Colors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Colors {
3434
return color[colorName];
3535
}
3636

37+
static buttonIconColor = '#FFFFFF';
3738
static headerIconColor = '#FFFFFF';
3839
static headerTextColor = '#FFFFFF';
3940
static headerBackgroundColor = '#212121';

packages/openchs-android/src/views/primitives/Styles.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ Styles.basicPrimaryButtonView = {
274274
backgroundColor: Styles.accentColor,
275275
alignItems: 'center',
276276
justifyContent: 'center',
277-
paddingHorizontal: 4,
277+
paddingHorizontal: 8,
278278
paddingVertical: 4,
279279
};
280280

0 commit comments

Comments
 (0)