Skip to content

Commit

Permalink
fix: expose children to contact summary
Browse files Browse the repository at this point in the history
  • Loading branch information
ChinHairSaintClair committed Sep 6, 2024
1 parent bbe5ded commit ebee299
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
2 changes: 1 addition & 1 deletion webapp/src/ts/effects/contacts.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ export class ContactsEffects {
const trackPerformance = this.performanceService.track();
const selected = this.selectedContact;
return this.contactSummaryService
.get(selected.doc, selected.reports, selected.lineage, selected.targetDoc)
.get(selected.doc, selected.reports, selected.lineage, selected.children, selected.targetDoc)
.catch(error => {
this.contactsActions.updateSelectedContactSummary({ errorStack: error.stack });
throw error;
Expand Down
10 changes: 6 additions & 4 deletions webapp/src/ts/services/contact-summary.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export class ContactSummaryService {
'contact',
'reports',
'lineage',
'children',
'uhcStats',
'cht',
'targetDoc',
Expand Down Expand Up @@ -78,11 +79,11 @@ export class ContactSummaryService {
return summary;
}

get(contact, reports, lineage, targetDocs) {
return this.ngZone.runOutsideAngular(() => this._get(contact, reports, lineage, targetDocs));
get(contact, reports, lineage, children, targetDocs) {
return this.ngZone.runOutsideAngular(() => this._get(contact, reports, lineage, children, targetDocs));
}

private async _get(contact, reports, lineage, targetDocs) {
private async _get(contact, reports, lineage, children, targetDocs) {
if (!this.settings) {
this.settings = await this.settingsService.get();
}
Expand All @@ -101,7 +102,8 @@ export class ContactSummaryService {
chtScriptApi.v1.analytics.getTargetDocs = () => targetDocs;

try {
const summary = generatorFunction(contact, reports || [], lineage || [], uhcStats, chtScriptApi, targetDocs[0]);
// eslint-disable-next-line max-len
const summary = generatorFunction(contact, reports || [], lineage || [], children || [], uhcStats, chtScriptApi, targetDocs[0]);
return this.applyFilters(summary);
} catch (error) {
console.error('Configuration error in contact-summary function: ', error);
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/ts/services/form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ export class FormService {
this.getLineage(contact),
this.getTargetDocs(contact),
])
.then(([reports, lineage, targetDocs]) => this.contactSummaryService.get(contact, reports, lineage, targetDocs));
// eslint-disable-next-line max-len
.then(([reports, lineage, targetDocs]) => this.contactSummaryService.get(contact, reports, lineage, contact.children, targetDocs));
}

private canAccessForm(formContext: EnketoFormContext) {
Expand Down Expand Up @@ -355,4 +356,3 @@ export class FormService {
this.enketoService.unload(form);
}
}

1 change: 1 addition & 0 deletions webapp/tests/karma/ts/effects/contacts.effects.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,7 @@ describe('Contacts effects', () => {
{ _id: 'person', parent: { _id: 'parent' } },
[{ _id: 'the_report' }],
[{ _id: 'parent' }, { _id: 'grandparent' }],
[],
[{ _id: 'targetDoc' }],
]);
const updateSelectedContactSummary:any = ContactsActions.prototype.updateSelectedContactSummary;
Expand Down
16 changes: 8 additions & 8 deletions webapp/tests/karma/ts/services/contact-summary.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('ContactSummary service', () => {
Settings.resolves({ contact_summary: '' });
const contact = {};
const reports = [];
return service.get(contact, reports, [], []).then(actual => {
return service.get(contact, reports, [], [], []).then(actual => {
expect(actual.fields.length).to.equal(0);
expect(actual.cards.length).to.equal(0);
});
Expand All @@ -77,7 +77,7 @@ describe('ContactSummary service', () => {
Settings.resolves({ contact_summary: script });
const contact = { name: 'jack' };
const reports = [ { _id: 1 }, { _id: 2} ];
return service.get(contact, reports, [], []).then(actual => {
return service.get(contact, reports, [], [], []).then(actual => {
expect(actual.fields.length).to.equal(2);
expect(actual.fields[0].label).to.equal('Notes');
expect(actual.fields[0].value).to.equal('Hello jack');
Expand All @@ -94,7 +94,7 @@ describe('ContactSummary service', () => {
Settings.resolves({ contact_summary: script });
const contact = {};
const reports = [];
return service.get(contact, reports, [], []).then(actual => {
return service.get(contact, reports, [], [], []).then(actual => {
expect(actual.fields.length).to.equal(1);
expect(actual.fields[0].label).to.equal('Notes');
expect(actual.fields[0].value).to.equal('olleH');
Expand All @@ -112,7 +112,7 @@ describe('ContactSummary service', () => {
Settings.resolves({ contact_summary: script });
const contact = {};
const reports = [];
return service.get(contact, reports, [], []).then(actual => {
return service.get(contact, reports, [], [], []).then(actual => {
expect(actual.fields).to.deep.equal([undefined]);
expect(actual.cards).to.deep.equal([undefined]);
});
Expand All @@ -128,7 +128,7 @@ describe('ContactSummary service', () => {
Settings.resolves({ contact_summary: script });
const contact = {};
const reports = [];
return service.get(contact, reports, [], []).then(actual => {
return service.get(contact, reports, [], [], []).then(actual => {
expect(actual.fields).to.be.an('array');
expect(actual.fields.length).to.equal(0);
expect(actual.cards).to.be.an('array');
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('ContactSummary service', () => {
{ date_updated: 'a month ago', targets: [{ id: 'target', type: 'count' }] },
];

return service.get(contact, reports, lineage, targetDocs).then(contactSummary => {
return service.get(contact, reports, lineage, [], targetDocs).then(contactSummary => {
expect(contactSummary).to.deep.equal({
fields: ['boa', 'parent'],
cards: [
Expand Down Expand Up @@ -213,7 +213,7 @@ describe('ContactSummary service', () => {
end: moment('2021-04-25 23:59:59.999').valueOf()
});

const contactSummary = await service.get(contact, reports, [], []);
const contactSummary = await service.get(contact, reports, [], [], []);

expect(contactSummary).to.deep.equal({
cards: [],
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('ContactSummary service', () => {

Settings.resolves({ contact_summary: script });

const contactSummary = await service.get(contact, reports, [], []);
const contactSummary = await service.get(contact, reports, [], [], []);

expect(contactSummary).to.deep.equal({
cards: [],
Expand Down
7 changes: 6 additions & 1 deletion webapp/tests/karma/ts/services/form.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,12 @@ describe('Form service', () => {
expect(ContactSummary.args[0][1][0]._id).to.equal('somereport');
expect(ContactSummary.args[0][2].length).to.equal(1);
expect(ContactSummary.args[0][2][0]._id).to.equal('someparent');
expect(ContactSummary.args[0][3]).to.deep.equal([{ _id: 't1' }, { _id: 't2' }]);
console.log('The contact summary data:');
console.log(ContactSummary);
console.log(ContactSummary.args[0]);
console.log(ContactSummary.args[0][3]);
// Verify child addition
expect(ContactSummary.args[0][4]).to.deep.equal([{ _id: 't1' }, { _id: 't2' }]);
});
});

Expand Down

0 comments on commit ebee299

Please sign in to comment.