Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OP-1077: Policy page either doesn't fetch products or fetches all the products. #25

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 7 additions & 20 deletions src/components/PolicyMasterPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
Contributions,
PublishedComponent,
ProgressOrError,
decodeId,
} from "@openimis/fe-core";
import {
policyLabel,
Expand Down Expand Up @@ -67,25 +68,6 @@ class PolicyMasterPanel extends FormPanel {
: this.updateAttribute("product", product);
};

_filterProducts = (products) => {
if (!products || !this.props.edited || !this.props.edited.family)
return products;
let loc = this.props.edited.family.location;
let familyRegion = null;
let familyDistrict = null;
while (!!loc) {
familyRegion = familyDistrict;
familyDistrict = loc;
loc = loc.parent;
}
return products.filter(
(p) =>
!p.location ||
p.location.id === familyRegion.id ||
p.location.id === familyDistrict.id
);
};

renewPolicy = () =>
historyPush(
this.props.modulesManager,
Expand Down Expand Up @@ -175,6 +157,7 @@ class PolicyMasterPanel extends FormPanel {
errorPolicyValues,
title = "Policy.details.title",
} = this.props;

let actions = [];
if (this.canRenew(edited)) {
actions.push({
Expand Down Expand Up @@ -303,8 +286,12 @@ class PolicyMasterPanel extends FormPanel {
withNull={true}
nullLabel={formatMessage(intl, "product", "Product.none")}
onChange={this._onProductChange}
filter={this._filterProducts}
required={true}
locationId={
!!edited.family
? decodeId(edited.family.location.parent.parent.parent.id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that will get you only the region level product, I think we should have a way in the core to say "location and its parents"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. It will give you district, region and national products.

: 0
}
/>
</Grid>
<Grid item xs={3} className={classes.item}>
Expand Down