Skip to content

Commit

Permalink
#1375 - include full hierarchy above the lowest level.
Browse files Browse the repository at this point in the history
  • Loading branch information
petmongrels committed Apr 18, 2024
1 parent 3734b74 commit 30f6fe8
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,16 @@ class CustomDashboardActions {
reportCardSectionMappings.forEach(rcm => {
const start = new Date();
const countQueryResponse = context.get(ReportCardService).getReportCardCount(rcm.card, newState.ruleInput.ruleInputArray);
if(rcm.card.nested) {
if(countQueryResponse && countQueryResponse.length === rcm.card.countOfCards) {
if (rcm.card.nested) {
if (countQueryResponse && countQueryResponse.length === rcm.card.countOfCards) {
_.forEach(countQueryResponse, (reportCard, index) => {
const itemKey = rcm.card.getCardId(index);
newState.cardToCountResultMap[itemKey] = {
...reportCard,
itemKey
};
});
} else if(countQueryResponse && countQueryResponse.length !== rcm.card.countOfCards) {
} else if (countQueryResponse && countQueryResponse.length !== rcm.card.countOfCards) {
Array(rcm.card.countOfCards).fill(rcm.card).forEach((reportCard, index) => {
const itemKey = reportCard.getCardId(index);
newState.cardToCountResultMap[itemKey] = {
Expand All @@ -152,9 +152,9 @@ class CustomDashboardActions {
const reportCardSectionMappings = state.reportCardSectionMappings;
newState.countUpdateTime = new Date(); //Update this to ensure reportCard count change is reflected
reportCardSectionMappings.forEach(rcm => {
const keysOfReportCard= _.keys(newState.cardToCountResultMap).filter((itemKey) => itemKey.startsWith(rcm.card.uuid));
const keysOfReportCard = _.keys(newState.cardToCountResultMap).filter((itemKey) => itemKey.startsWith(rcm.card.uuid));
_.forEach(keysOfReportCard, (itemKey) => {
newState.cardToCountResultMap[itemKey]= null;
newState.cardToCountResultMap[itemKey] = null;
});
});
return newState;
Expand All @@ -169,7 +169,7 @@ class CustomDashboardActions {
static setCustomDashboardFilters(state, action, context) {
const newState = {...state};
newState.customDashboardFilters = action.filterApplied ? action.customDashboardFilters
: CustomDashboardActions.getDefaultCustomDashboardFilters();
: CustomDashboardActions.getDefaultCustomDashboardFilters();
return newState;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class IndividualSearchActions {
const addressLevelState = action.values;
const lowestSelectedAddressLevels = addressLevelState.lowestSelectedAddresses;
const lowestAddressLevels = lowestSelectedAddressLevels
.reduce((acc, parent) => acc.concat(addressLevelService.getChildrenOfNode(parent, false)), []);
.reduce((acc, parent) => acc.concat(addressLevelService.getDescendantsOfNode(parent, false)), []);
newState.searchCriteria.toggleLowestAddresses(lowestAddressLevels);
newState.addressLevelState = addressLevelState;
return newState;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class FiltersActions {
const addressLevelService = beans.get(AddressLevelService);
const lowestSelectedAddressLevels = action.addressLevelState.lowestSelectedAddresses;
const lowestAddressLevels = lowestSelectedAddressLevels
.reduce((acc, parent) => acc.concat(addressLevelService.getChildrenOfNode(parent, false)), []);
.reduce((acc, parent) => acc.concat(addressLevelService.getDescendantsOfNode(parent, false)), []);
newState.locationSearchCriteria.toggleLowestAddresses(lowestAddressLevels);
return newState;
}
Expand Down
12 changes: 6 additions & 6 deletions packages/openchs-android/src/service/BaseAddressLevelService.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,19 @@ class BaseAddressLevelService extends BaseService {
return child.level === this.minLevel();
}

getChildrenOfNode( node, leavesOnly = true) {
if (this.isLeaf(node)) {
getDescendantsOfNode(node, excludeSelf = true) {
if (this.isLeaf(node)) { //in this case excludeSelf is not respected
return [node];
}
const children = this.getChildrenParent(node.uuid);
if (_.isEmpty(children)) {
return leavesOnly ? [] : [node];
return excludeSelf ? [] : [node];
}
else if (this.isLeaf(_.first(children))) {
return leavesOnly ? children : [node].concat(children);
return excludeSelf ? children : [node].concat(children);
}
return leavesOnly ? _.flatten(children.map(c => this.getChildrenOfNode(c, leavesOnly)))
: [node].concat(_.flatten(children.map(c => this.getChildrenOfNode(c, leavesOnly))));
return excludeSelf ? _.flatten(children.map(c => this.getDescendantsOfNode(c, excludeSelf)))
: [node].concat(_.flatten(children.map(c => this.getDescendantsOfNode(c, excludeSelf))));
}

getDescendantsOfParent(parentUuid, minLevelTypeUUIDs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
import {DashboardReportFilter} from "../../model/DashboardReportFilters";
import _ from "lodash";
import AddressLevelService from "../AddressLevelService";
import GlobalContext from "../../GlobalContext";


@Service("dashboardFilterService")
Expand Down Expand Up @@ -77,12 +76,13 @@ class DashboardFilterService extends BaseService {
if (_.isEmpty(filterValue.selectedAddresses)) {
ruleInput.filterValue = filterValue.selectedAddresses;
} else {
const addressLevelService = GlobalContext.getInstance().beanRegistry.getService(AddressLevelService);
const addressLevelService = this.getService(AddressLevelService);
const addressFilterValues = [...filterValue.selectedAddresses];
const allChildrenOfLowestSelectedLocations = filterValue.selectedAddresses
.filter(location => location.level === _.get(_.minBy(filterValue.selectedAddresses, 'level'), 'level'))
.reduce((acc, parent) => acc.concat(addressLevelService.getChildrenOfNode(parent, false)), []);
ruleInput.filterValue = allChildrenOfLowestSelectedLocations
.map(addressLevel => _.pick(addressLevel, ['uuid', 'name', 'level', 'type', 'parentUuid', 'typeUuid']));
.reduce((acc, parent) => acc.concat(addressLevelService.getDescendantsOfNode(parent, true)), []);
ruleInput.filterValue = addressFilterValues.concat(allChildrenOfLowestSelectedLocations
.map(addressLevel => _.pick(addressLevel, ['uuid', 'name', 'level', 'type', 'parentUuid'])));
}
}
else
Expand Down

0 comments on commit 30f6fe8

Please sign in to comment.