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

#5697 - Update the levels displayed in breadcrumbs across the app #7732

Merged
merged 47 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
cdcf4da
remove own place for offline users reports breadcrumbs
elvisdorkenoo Aug 16, 2022
7538e37
fix ponctuation coding style
elvisdorkenoo Aug 17, 2022
eceb40e
minor changes
elvisdorkenoo Aug 19, 2022
ea0fbfc
update messages tab breadcrumbs
elvisdorkenoo Aug 25, 2022
d56e881
update messages tab breadcrumbs
elvisdorkenoo Aug 25, 2022
9523922
add breadcrumbs display update to report and message
elvisdorkenoo Aug 26, 2022
f15dc81
fix unit test
elvisdorkenoo Aug 26, 2022
2660772
fix unit test 2
elvisdorkenoo Aug 26, 2022
2ddc752
fix unit test 2
elvisdorkenoo Aug 26, 2022
de97add
fix unit test 3
elvisdorkenoo Aug 26, 2022
c6152dd
fix unit test 4
elvisdorkenoo Aug 26, 2022
884e3f4
fix unit test 5
elvisdorkenoo Aug 26, 2022
3fe346d
fix unit tests
elvisdorkenoo Aug 26, 2022
0d189c2
fix unit tests functions
elvisdorkenoo Aug 26, 2022
ed07e1c
fix unit tests functions
elvisdorkenoo Aug 26, 2022
cfb46e1
fix unit tests messages component
elvisdorkenoo Aug 26, 2022
7915562
fix coding style
elvisdorkenoo Aug 29, 2022
dac433f
some refactoring following PR code review
elvisdorkenoo Aug 30, 2022
00e507a
breadcrumbs in two lines
elvisdorkenoo Sep 1, 2022
fcfdc5a
add unit tests to messages tab
elvisdorkenoo Sep 2, 2022
cacd0e8
add unit test to messages breadcrumbs
elvisdorkenoo Sep 2, 2022
65a130d
add unit tests to reports and messages breadcrumbs
elvisdorkenoo Sep 3, 2022
ae37aed
minor changes
elvisdorkenoo Sep 3, 2022
ca5627c
apply code review recommandations
elvisdorkenoo Sep 5, 2022
4aaed95
apply code review recommandations
elvisdorkenoo Sep 5, 2022
8998312
apply most of review recommandations for messages and reports
elvisdorkenoo Sep 6, 2022
4a52c83
apply most of review recommandations for messages and reports
elvisdorkenoo Sep 7, 2022
6011687
apply most of review recommandations for tasks
elvisdorkenoo Sep 7, 2022
4d0d319
Merge branch 'master' of github.com:medic/cht-core into 5697-update-b…
elvisdorkenoo Sep 7, 2022
70137c5
apply most of review recommandations for messages and reports
elvisdorkenoo Sep 7, 2022
683f668
apply recommandations except report unit tests structure for now
elvisdorkenoo Sep 11, 2022
f480f7c
fix indentations
elvisdorkenoo Sep 11, 2022
7169639
Merge branch 'master' of github.com:medic/cht-core into 5697-update-b…
elvisdorkenoo Sep 11, 2022
2602efe
trying report unit tests refactoring
elvisdorkenoo Sep 12, 2022
03bd416
Fixing unit test
latin-panda Sep 12, 2022
a38ded8
removing .only() from unit tests
latin-panda Sep 12, 2022
ff93496
remove console.log for report component
elvisdorkenoo Sep 12, 2022
6d7cb7f
make this.currentLevel a promise for report component
elvisdorkenoo Sep 12, 2022
46441e7
remove tick for imports
elvisdorkenoo Sep 12, 2022
09ef7e5
Merge branch 'master' of github.com:medic/cht-core into 5697-update-b…
elvisdorkenoo Sep 13, 2022
9f97525
apply code review requested changes
elvisdorkenoo Sep 13, 2022
5d3648e
apply code review requested changes
elvisdorkenoo Sep 13, 2022
bcf9870
apply code review requested changes
elvisdorkenoo Sep 14, 2022
919d64f
apply code review requested changes
elvisdorkenoo Sep 15, 2022
d6eec6c
add e2e tests for reports breadcrumbs
elvisdorkenoo Sep 16, 2022
5430cc3
add e2e tests for reports breadcrumbs
elvisdorkenoo Sep 16, 2022
3c78995
apply review requested changes
elvisdorkenoo Sep 19, 2022
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
17 changes: 17 additions & 0 deletions webapp/src/ts/modules/messages/messages.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { ModalService } from '@mm-modals/mm-modal/mm-modal';
import { SendMessageComponent } from '@mm-modals/send-message/send-message.component';
import { TourService } from '@mm-services/tour.service';
import { ResponsiveService } from '@mm-services/responsive.service';
import { UserContactService } from '@mm-services/user-contact.service';
import { SessionService } from '@mm-services/session.service';

@Component({
templateUrl: './messages.component.html'
Expand All @@ -28,6 +30,7 @@ export class MessagesComponent implements OnInit, OnDestroy {
conversations = [];
selectedConversationId = null;
error = false;
currentLevel;
private destroyed = false;

constructor(
Expand All @@ -40,6 +43,8 @@ export class MessagesComponent implements OnInit, OnDestroy {
private modalService: ModalService,
private tourService: TourService,
private responsiveService: ResponsiveService,
private userContactService:UserContactService,
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
private sessionService:SessionService,
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
) {
this.globalActions = new GlobalActions(store);
this.messagesActions = new MessagesActions(store);
Expand All @@ -48,6 +53,9 @@ export class MessagesComponent implements OnInit, OnDestroy {
ngOnInit(): void {
this.subscribeToStore();
this.tourService.startIfNeeded(this.route.snapshot);
this.userContactService.getCurrentLineageLevel().then((currentLevel) => {
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
this.currentLevel = currentLevel;
});
this.updateConversations().then(() => this.displayFirstConversation(this.conversations));
this.watchForChanges();
}
Expand Down Expand Up @@ -152,6 +160,15 @@ export class MessagesComponent implements OnInit, OnDestroy {
return this.messageContactService
.getList()
.then((conversations = []) => {
// filter out the lineage level that belongs to the online logged in user
if(!this.sessionService.isOnlineOnly()) {
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
conversations.map((conversation) => {
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
conversation.lineage = conversation.lineage?.filter((level) => {
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
return (level !== this.currentLevel);
});
return conversation;
});
}
this.setConversations(conversations, { merge });
this.loading = false;
});
Expand Down
18 changes: 16 additions & 2 deletions webapp/src/ts/modules/reports/reports.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { TranslateService } from '@mm-services/translate.service';
import { ReportsSidebarFilterComponent } from '@mm-modules/reports/reports-sidebar-filter.component';
import { AuthService } from '@mm-services/auth.service';
import { OLD_REPORTS_FILTER_PERMISSION } from '@mm-modules/reports/reports-filters.component';
import {UserContactService} from '@mm-services/user-contact.service';
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
import { SessionService } from '@mm-services/session.service';

const PAGE_SIZE = 50;
Expand Down Expand Up @@ -60,6 +61,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy {
enketoEdited;
useSidebarFilter = true;
isSidebarFilterOpen = false;
currentLevel;

constructor(
private store:Store,
Expand All @@ -73,9 +75,11 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy {
private addReadStatusService:AddReadStatusService,
private exportService:ExportService,
private ngZone:NgZone,
private userContactService:UserContactService,
private sessionService:SessionService,
private scrollLoaderProvider:ScrollLoaderProvider,
private responsiveService:ResponsiveService,

elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
) {
this.globalActions = new GlobalActions(store);
this.reportsActions = new ReportsActions(store);
Expand Down Expand Up @@ -143,6 +147,11 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy {
this.globalActions.setFilter({ search: this.route.snapshot.queryParams.query || '' });
this.tourService.startIfNeeded(this.route.snapshot);
this.setActionBarData();

this.userContactService.getCurrentLineageLevel().then((currentLevel) => {
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
this.currentLevel = currentLevel;
console.log('this.currentLevel in reports', this.currentLevel);
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
});
}

async ngAfterViewInit() {
Expand Down Expand Up @@ -191,8 +200,13 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy {
report.heading = this.getReportHeading(form, report);
report.summary = form ? form.title : report.form;
report.lineage = report.subject && report.subject.lineage || report.lineage;
// filter out the lineage level that belongs to the online logged in user
if(!this.sessionService.isOnlineOnly()) {
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
report.lineage = report.lineage.filter((level) => {
return (level !== this.currentLevel);
});
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
}
report.unread = !report.read;

return report;
});
}
Expand Down Expand Up @@ -263,7 +277,7 @@ export class ReportsComponent implements OnInit, AfterViewInit, OnDestroy {
search(force = false) {
// clears report selection for any text search or filter selection
// does not clear selection when someone is editing a form
if ((this.filters.search || Object.keys(this.filters).length > 1) && !this.enketoEdited) {
if((this.filters.search || Object.keys(this.filters).length > 1) && !this.enketoEdited) {
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
this.router.navigate(['reports']);
this.reportsActions.clearSelection();
}
Expand Down
1 change: 1 addition & 0 deletions webapp/src/ts/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ export class SearchService {
return Promise.resolve([]);
}
const before = performance.now();

elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
return this
.searchFactory(type, filters, options, extensions)
.then((searchResults) => {
Expand Down
13 changes: 13 additions & 0 deletions webapp/src/ts/services/user-contact.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,17 @@ export class UserContactService {
throw err;
});
}

async getCurrentLineageLevel(){
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
return this
.get()
.then((user) => {
const currentLevel = user?.parent?.name;
console.log('user ', user, 'currentLevel', currentLevel);
return currentLevel;
})
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
.catch((err) => {
throw err;
});
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
}
}
28 changes: 28 additions & 0 deletions webapp/tests/karma/ts/modules/messages/messages.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { ModalService } from '@mm-modals/mm-modal/mm-modal';
import { NavigationComponent } from '@mm-components/navigation/navigation.component';
import { TourService } from '@mm-services/tour.service';
import { NavigationService } from '@mm-services/navigation.service';
import { UserContactService } from '@mm-services/user-contact.service';
import { SessionService } from '@mm-services/session.service';
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved

describe('Messages Component', () => {
let component: MessagesComponent;
Expand All @@ -23,6 +25,18 @@ describe('Messages Component', () => {
let changesService;
let exportService;
let modalService;
let userContactService;
let sessionService;

const userContactGrandparent = { _id: 'grandparent' };
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
const userContactDoc = {
_id: 'user',
parent: {
_id: 'parent',
name: 'parent',
parent: userContactGrandparent,
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
},
};

beforeEach(waitForAsync(() => {
modalService = { show: sinon.stub() };
Expand All @@ -33,6 +47,11 @@ describe('Messages Component', () => {
changesService = {
subscribe: sinon.stub().resolves(of({}))
};
userContactService = {
get: sinon.stub().resolves(userContactDoc),
getCurrentLineageLevel : sinon.stub().resolves('parent')
};
sessionService = { isOnlineOnly : sinon.stub().resolves(true) };
const tourServiceMock = {
startIfNeeded: () => {}
};
Expand Down Expand Up @@ -63,6 +82,8 @@ describe('Messages Component', () => {
{ provide: ModalService, useValue: modalService },
{ provide: TourService, useValue: tourServiceMock },
{ provide: NavigationService, useValue: {} },
{ provide: UserContactService, useValue: userContactService },
{ provide: SessionService, useValue: sessionService },
]
})
.compileComponents()
Expand Down Expand Up @@ -181,4 +202,11 @@ describe('Messages Component', () => {

expect(spySubscriptionsUnsubscribe.callCount).to.equal(1);
});

it('it should retrieve the hierarchy level of the connected user', () => {
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
userContactService.get.resolves(userContactDoc);
component.ngOnInit();
expect(component.currentLevel).to.equal('parent');
});

});
18 changes: 17 additions & 1 deletion webapp/tests/karma/ts/modules/reports/reports.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { AuthService } from '@mm-services/auth.service';
import { ReportsSidebarFilterComponent } from '@mm-modules/reports/reports-sidebar-filter.component';
import { ReportsActionsBarComponent } from '@mm-modules/reports/reports-actions-bar.component';
import { TelemetryService } from '@mm-services/telemetry.service';
import { UserContactService } from '@mm-services/user-contact.service';

describe('Reports Component', () => {
let component: ReportsComponent;
Expand All @@ -39,6 +40,17 @@ describe('Reports Component', () => {
let listContains;
let authService;
let datePipe;
let userContactService;

const userContactGrandparent = { _id: 'grandparent' };
const userContactDoc = {
_id: 'user',
parent: {
_id: 'parent',
name: 'parent',
parent: userContactGrandparent,
},
};

beforeEach(waitForAsync(() => {
listContains = sinon.stub();
Expand Down Expand Up @@ -66,7 +78,10 @@ describe('Reports Component', () => {
isOnlineOnly: sinon.stub()
};
datePipe = { transform: sinon.stub() };

userContactService = {
get: sinon.stub().resolves(userContactDoc),
getCurrentLineageLevel : sinon.stub().resolves('parent')
elvisdorkenoo marked this conversation as resolved.
Show resolved Hide resolved
};
return TestBed
.configureTestingModule({
imports: [
Expand Down Expand Up @@ -97,6 +112,7 @@ describe('Reports Component', () => {
{ provide: TelemetryService, useValue: { record: sinon.stub() } },
{ provide: TourService, useValue: tourServiceMock },
{ provide: SessionService, useValue: sessionService },
{ provide: UserContactService, useValue: userContactService },
{ provide: NavigationService, useValue: {} },
{ provide: AuthService, useValue: authService },
{ provide: DatePipe, useValue: datePipe },
Expand Down