Skip to content

Commit

Permalink
#1256 | Show error if there is mismatch in count between configured a…
Browse files Browse the repository at this point in the history
…nd query returned nested cards count
  • Loading branch information
himeshr committed Jan 25, 2024
1 parent 0ff1f7d commit d13fba8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import General from "../../utility/General";
import DashboardFilterService from "../../service/reports/DashboardFilterService";
import CustomDashboardCacheService from '../../service/CustomDashboardCacheService';
import CryptoUtils from '../../utility/CryptoUtils';
import MessageService from '../../service/MessageService';

class CustomDashboardActions {

Expand Down Expand Up @@ -109,6 +110,7 @@ class CustomDashboardActions {
}

static refreshCount(state, action, context) {
const I18n = context.get(MessageService).getI18n();
const reportCardSectionMappings = state.reportCardSectionMappings;
const newState = {...state};
newState.ruleInput = action.filterApplied ? action.ruleInput : newState.ruleInput;
Expand All @@ -117,15 +119,27 @@ class CustomDashboardActions {
const start = new Date();
const countQueryResponse = context.get(ReportCardService).getReportCardCount(rcm.card, newState.ruleInput.ruleInputArray);
if(rcm.card.nested) {
_.map(countQueryResponse, (reportCard, index) => {
const itemKey = rcm.card.getCardId(index);
newState.cardToCountResultMap[itemKey] = {
...reportCard,
itemKey
};
});
countQueryResponse && countQueryResponse.length != rcm.card.countOfCards && General.logWarn('CustomDashboardActions',
`${rcm.card.name} query returned different number of nested cards(${countQueryResponse.length}) than expected(${rcm.card.countOfCards})`);
if(countQueryResponse && countQueryResponse.length === rcm.card.countOfCards) {
_.map(countQueryResponse, (reportCard, index) => {
const itemKey = rcm.card.getCardId(index);
newState.cardToCountResultMap[itemKey] = {
...reportCard,
itemKey
};
});
} else if(countQueryResponse && countQueryResponse.length !== rcm.card.countOfCards) {
Array(rcm.card.countOfCards).fill(rcm.card).map((reportCard, index) => {
const itemKey = reportCard.getCardId(index);
newState.cardToCountResultMap[itemKey] = {
hasError: true,
primaryValue: I18n.t("Error"),
secondaryValue: `Configured number of cards don\'t match with the number of cards in the rule`,
// secondaryValue: null,
lineListFunction: _.noop(),
itemKey
};
});
}
} else {
newState.cardToCountResultMap[rcm.card.getCardId()] = countQueryResponse;
}
Expand Down
12 changes: 10 additions & 2 deletions packages/openchs-android/src/views/customDashboard/CardListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export const CardListView = ({reportCard, I18n, onCardPress, countResult}) => {
direction={'column'}
primary={countResult.primaryValue}
secondary={countResult.secondaryValue}
primaryStyle={[styles.primaryTextStyle, {color: textColor}]}
secondaryStyle={[styles.secondaryTextStyle, {color: textColor}]}
primaryStyle={[styles.primaryTextStyle, {color: textColor}, countResult.hasError && styles.cardPrimaryTextErrorStyle]}
secondaryStyle={[styles.secondaryTextStyle, {color: textColor}, countResult.hasError && styles.cardSecondaryTextErrorStyle]}
/>
)
};
Expand Down Expand Up @@ -78,5 +78,13 @@ const styles = StyleSheet.create({
secondaryTextStyle: {
fontSize: 23,
fontStyle: 'normal',
},
cardPrimaryTextErrorStyle: {
fontSize: 11,
fontStyle: 'normal',
},
cardSecondaryTextErrorStyle: {
fontSize: 9,
fontStyle: 'normal',
}
});
12 changes: 10 additions & 2 deletions packages/openchs-android/src/views/customDashboard/CardTileView.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ const renderNumber = function (countResult, textColor) {
direction={'row'}
primary={countResult.primaryValue}
secondary={countResult.secondaryValue}
primaryStyle={[styles.cardPrimaryTextStyle, {color: textColor}]}
secondaryStyle={[styles.cardSecondaryTextStyle, {color: textColor}]}
primaryStyle={[styles.cardPrimaryTextStyle, {color: textColor}, countResult.hasError && styles.cardPrimaryTextErrorStyle]}
secondaryStyle={[styles.cardSecondaryTextStyle, {color: textColor}, countResult.hasError && styles.cardSecondaryTextErrorStyle]}
/>
)
};
Expand Down Expand Up @@ -87,5 +87,13 @@ const styles = StyleSheet.create({
flexDirection: 'column',
alignItems: 'flex-end',
flex: 1
},
cardPrimaryTextErrorStyle: {
fontSize: 11,
fontStyle: 'normal',
},
cardSecondaryTextErrorStyle: {
fontSize: 8,
fontStyle: 'normal',
}
});

0 comments on commit d13fba8

Please sign in to comment.