Skip to content

Commit

Permalink
Remove "Primary Contacts" from Contact Tab LHS
Browse files Browse the repository at this point in the history
Regarding removing "Primary Contacts" from RHS: I'd like to take a bit of time to double-check the database interactions and can either push in new PR or merge here.

To keep things simple at first, this creates a new hydrateDataRecords which defaults to true. I suspect we may want the interface to default to false, but looking for thoughts on that before I make any changes.

#5084
  • Loading branch information
kennsippell authored and garethbowen committed Dec 13, 2018
1 parent 1d8ce7b commit aa9847b
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 26 deletions.
2 changes: 1 addition & 1 deletion tests/e2e/sms-gateway.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ describe('sms-gateway api', () => {
done();
});
})
.catch(done);
.catch(done.fail);
});

afterEach(done => {
Expand Down
5 changes: 1 addition & 4 deletions webapp/src/js/controllers/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,7 @@ var _ = require('underscore'),
limit,
withIds,
silent: true,

// The logic for updating Primary Contact changes is complex
// So redraw everything when a person changes
reuseExistingDom: change.doc && change.doc.type !== 'person',
reuseExistingDom: true,
});
},
filter: function(change) {
Expand Down
9 changes: 4 additions & 5 deletions webapp/src/js/controllers/reports.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,8 @@ angular
});
};

var query = function(options) {
options = options || {};
options.limit = options.limit || 50;
var query = function(opts) {
const options = _.extend({ limit: 50, hydrateContactNames: true }, opts);
if (!options.silent) {
$scope.error = false;
$scope.errorSyntax = false;
Expand Down Expand Up @@ -442,7 +441,7 @@ angular

$scope.$on('SelectAll', function() {
$scope.setLoadingContent(true);
Search('reports', $scope.filters, { limit: 500 })
Search('reports', $scope.filters, { limit: 500, hydrateContactNames: true })
.then(function(summaries) {
$scope.selected = summaries.map(function(summary) {
return {
Expand Down Expand Up @@ -508,7 +507,7 @@ angular
$scope.hasReports = liveList.count() > 0;
setActionBarData();
} else {
query({ silent: true, limit: liveList.count() });
query({ silent: true, limit: Math.max(50, liveList.count()) });
}
},
filter: function(change) {
Expand Down
12 changes: 8 additions & 4 deletions webapp/src/js/services/get-data-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,17 @@ angular.module('inboxServices').factory('GetDataRecords',
});
};

var getSummaries = function(ids) {
const getSummaries = function(ids, options) {
return GetSummaries(ids)
.then(HydrateContactNames)
.then(GetSubjectSummaries);
.then(summaries => {
const promiseToSummary = options.hydrateContactNames ? HydrateContactNames(summaries) : Promise.resolve(summaries);
return promiseToSummary.then(GetSubjectSummaries);
});
};

return function(ids, options) {
const opts = _.extend({ hydrateContactNames: false, include_docs: false }, options);

if (!ids) {
return $q.resolve([]);
}
Expand All @@ -53,7 +57,7 @@ angular.module('inboxServices').factory('GetDataRecords',
if (!ids.length) {
return $q.resolve([]);
}
var getFn = options && options.include_docs ? getDocs : getSummaries;
const getFn = opts.include_docs ? getDocs : ids => getSummaries(ids, opts);
return getFn(ids)
.then(function(response) {
if (!arrayGiven) {
Expand Down
5 changes: 5 additions & 0 deletions webapp/src/js/services/get-subject-summaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ angular.module('inboxServices').factory('GetSubjectSummaries',

return function(summaries, hydratedLineage) {
var containsReports = false;

if (!summaries) {
return [];
}

summaries.forEach(function (summary) {
if (summary.form) {
containsReports = true;
Expand Down
2 changes: 0 additions & 2 deletions webapp/src/js/services/live-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ angular.module('inboxServices').factory('LiveListConfig',
scope.visits.status = 'done';
}
}
} else {
scope.summary = $translate.instant('contact.primary_contact_name', { name: contact.contact });
}
}
return renderTemplate(scope);
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/js/services/select2-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ angular.module('inboxServices').factory('Select2Search',
types: { selected: types },
search: params.data.q
};
var options = {
const options = {
limit: pageSize,
skip: skip
skip,
hydrateContactNames: true,
};

Search('contacts', filters, options)
Expand Down
10 changes: 5 additions & 5 deletions webapp/tests/karma/unit/controllers/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ describe('Contacts controller', () => {
assert.deepEqual(searchService.args[i], [
'contacts',
{ types: { selected: ['childType'] } },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: i !== 5 },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: true },
{ displayLastVisitedDate: true, visitCountSettings: {} },
undefined,
]);
Expand Down Expand Up @@ -1200,7 +1200,7 @@ describe('Contacts controller', () => {
assert.deepEqual(searchService.args[i], [
'contacts',
{ types: { selected: ['childType'] } },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: i !== 5 },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: true },
{
displayLastVisitedDate: true,
visitCountSettings: {},
Expand Down Expand Up @@ -1243,7 +1243,7 @@ describe('Contacts controller', () => {
assert.deepEqual(searchService.args[i], [
'contacts',
{ types: { selected: ['childType'] } },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: i !== 5 },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: true },
{ displayLastVisitedDate: true, visitCountSettings: {} },
undefined,
]);
Expand Down Expand Up @@ -1285,7 +1285,7 @@ describe('Contacts controller', () => {
assert.deepEqual(searchService.args[i], [
'contacts',
{ types: { selected: ['childType'] } },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: i !== 5 },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: true },
{
displayLastVisitedDate: true,
visitCountSettings: {},
Expand Down Expand Up @@ -1328,7 +1328,7 @@ describe('Contacts controller', () => {
assert.deepEqual(searchService.args[i], [
'contacts',
{ types: { selected: ['childType'] } },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: i !== 5 },
{ limit: 5, withIds: false, silent: true, reuseExistingDom: true },
{},
undefined,
]);
Expand Down
6 changes: 3 additions & 3 deletions webapp/tests/karma/unit/services/get-data-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe('GetDataRecords service', () => {
});
});

it('single result', () => {
it('single hydrated result', () => {
const expected = {
_id: '5',
name: 'five',
Expand All @@ -71,7 +71,7 @@ describe('GetDataRecords service', () => {
}
]));
HydrateContactNames.returns(Promise.resolve([ expected ]));
return service('5').then(actual => {
return service('5', { hydrateContactNames: true }).then(actual => {
chai.expect(actual).to.deep.equal(expected);
chai.expect(GetSummaries.callCount).to.equal(1);
chai.expect(allDocs.callCount).to.equal(0);
Expand All @@ -97,7 +97,7 @@ describe('GetDataRecords service', () => {
{ _id: '7', name: 'seven' }
]));
HydrateContactNames.returns(Promise.resolve(expected));
return service([ '5', '6', '7' ]).then(actual => {
return service([ '5', '6', '7' ], { hydrateContactNames: true }).then(actual => {
chai.expect(actual).to.deep.equal(expected);
chai.expect(GetSummaries.callCount).to.equal(1);
chai.expect(GetSummaries.args[0][0]).to.deep.equal([ '5', '6', '7' ]);
Expand Down

0 comments on commit aa9847b

Please sign in to comment.