Skip to content

VIH-8897 Command Centre Participant Sorting #2356

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

Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ describe('ParticipantContactDetails', () => {
expect(participant.hearing_venue_name).toBe(p.hearingVenueName);
expect(participant.contact_email).toBe(p.contactEmail);
expect(participant.contact_telephone).toBe(p.contactTelephone);
expect(p.initialedName).toBe('C Green');
expect(participant.ref_id).toBe(p.refId);
expect(participant.host_in_another_hearing).toBe(p.hostInAnotherHearing);
expect(p.isJudge).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ export class ParticipantContactDetails {
return this.participant.contact_telephone;
}

get initialedName(): string {
const initial = this.participant.first_name ? this.participant.first_name.substr(0, 1) : '';
const name = this.participant.last_name || '';
return `${initial} ${name}`;
}

get status(): ParticipantStatus {
return this.participant.status;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
</span>
</div>
<div id="participant-contact-details-link-{{ participant.id }}" class="govuk-body-s tooltip-wrapper">
<ng-container
*ngIf="participant.isJudge || participant.isQuickLinkUser || participant.isStaffMember; else individualName">
<ng-container>
{{ participant.displayName }}
</ng-container>
<ng-template #individualName>
{{ participant.initialedName }}
</ng-template>
<div id="tooltip-{{ participant.id }}" class="tooltip">
<app-participant-info-tooltip [participant]="participant"></app-participant-info-tooltip>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { fakeAsync, flushMicrotasks } from '@angular/core/testing';
import {
LinkedParticipantResponse,
LinkType,
ParticipantContactDetailsResponseVho,
ParticipantStatus,
Role
} from 'src/app/services/clients/api-client';
import { ParticipantContactDetailsResponseVho, ParticipantStatus, Role } from 'src/app/services/clients/api-client';
import { ParticipantContactDetails } from 'src/app/shared/models/participant-contact-details';
import { ConferenceTestData } from 'src/app/testing/mocks/data/conference-test-data';
import { eventsServiceSpy } from 'src/app/testing/mocks/mock-events-service';
Expand Down Expand Up @@ -80,21 +74,32 @@ describe('ParticipantStatusComponent', () => {
participantsToSort.push(
new ParticipantContactDetails(
new ParticipantContactDetailsResponseVho({
display_name: 'A Staff Member',
hearing_role: HearingRole.STAFF_MEMBER,
display_name: 'JOH2',
hearing_role: HearingRole.PANELMEMBER,
linked_participants: [],
role: Role.StaffMember
role: Role.JudicialOfficeHolder
})
)
);

participantsToSort.push(
new ParticipantContactDetails(
new ParticipantContactDetailsResponseVho({
display_name: 'M Individual 10',
hearing_role: 'Family Member',
display_name: 'JOH1',
hearing_role: HearingRole.PANEL_MEMBER,
linked_participants: [],
role: Role.Individual
role: Role.JudicialOfficeHolder
})
)
);

participantsToSort.push(
new ParticipantContactDetails(
new ParticipantContactDetailsResponseVho({
display_name: 'A Staff Member',
hearing_role: HearingRole.STAFF_MEMBER,
linked_participants: [],
role: Role.StaffMember
})
)
);
Expand All @@ -113,60 +118,40 @@ describe('ParticipantStatusComponent', () => {
participantsToSort.push(
new ParticipantContactDetails(
new ParticipantContactDetailsResponseVho({
display_name: 'M PanelMember 04',
hearing_role: HearingRole.MEDICAL_MEMBER,
display_name: 'QuickLink',
hearing_role: HearingRole.QUICK_LINK_PARTICIPANT,
linked_participants: [],
role: Role.JudicialOfficeHolder
role: Role.QuickLinkParticipant
})
)
);

participantsToSort.push(
new ParticipantContactDetails(
new ParticipantContactDetailsResponseVho({
display_name: 'P Member_01',
hearing_role: HearingRole.LAY_MEMBER,
display_name: 'Individual 01',
hearing_role: HearingRole.APPELLANT,
linked_participants: [],
role: Role.JudicialOfficeHolder
role: Role.Individual
})
)
);

const linkedParticipants1: LinkedParticipantResponse[] = [];
linkedParticipants1.push(
new LinkedParticipantResponse({
link_type: LinkType.Interpreter,
linked_id: 'f195ea9d-0118-4790-bda9-dbc49796584f'
})
);

participantsToSort.push(
new ParticipantContactDetails(
new ParticipantContactDetailsResponseVho({
display_name: 'M Interpreter 06',
hearing_role: HearingRole.INTERPRETER,
id: '77bb94c6-040b-47f3-87ce-378a4fb2ab57',
linked_participants: linkedParticipants1,
display_name: 'Witness 02',
hearing_role: HearingRole.WITNESS,
linked_participants: [],
role: Role.Individual
})
)
);

const linkedParticipants2: LinkedParticipantResponse[] = [];
linkedParticipants2.push(
new LinkedParticipantResponse({
link_type: LinkType.Interpreter,
linked_id: '77bb94c6-040b-47f3-87ce-378a4fb2ab57'
})
);

participantsToSort.push(
new ParticipantContactDetails(
new ParticipantContactDetailsResponseVho({
display_name: 'M Individual 12',
hearing_role: 'Family Member',
id: 'f195ea9d-0118-4790-bda9-dbc49796584f',
linked_participants: linkedParticipants2,
display_name: 'Individual 02',
hearing_role: HearingRole.APPELLANT,
linked_participants: [],
role: Role.Individual
})
)
Expand All @@ -175,7 +160,7 @@ describe('ParticipantStatusComponent', () => {
participantsToSort.push(
new ParticipantContactDetails(
new ParticipantContactDetailsResponseVho({
display_name: 'M Observer 03',
display_name: 'Observer',
hearing_role: HearingRole.OBSERVER,
linked_participants: [],
role: Role.Individual
Expand All @@ -192,32 +177,32 @@ describe('ParticipantStatusComponent', () => {
expect(judgeIndex).toEqual(0);

// Panel members and wingers
const panelMember1Index = participantList.findIndex(x => x.displayName === 'M PanelMember 04');
const panelMember2Index = participantList.findIndex(x => x.displayName === 'P Member_01');
const panelMember1Index = participantList.findIndex(x => x.displayName === 'JOH1');
const panelMember2Index = participantList.findIndex(x => x.displayName === 'JOH2');
expect(panelMember1Index).toEqual(1);
expect(panelMember2Index).toEqual(2);

// Others
const other1Index = participantList.findIndex(x => x.displayName === 'A Staff Member');
const other2Index = participantList.findIndex(x => x.displayName === 'M Individual 10');
const other3Index = participantList.findIndex(x => x.displayName === 'Witness 01');
expect(other1Index).toEqual(3);
expect(other2Index).toEqual(4);
expect(other3Index).toEqual(5);
// Staff
const staff = participantList.findIndex(x => x.displayName === 'A Staff Member');
expect(staff).toEqual(3);

// Interpreters and interpretees
const interp1Index = participantList.findIndex(x => x.displayName === 'M Interpreter 06');
const interp2Index = participantList.findIndex(x => x.displayName === 'M Individual 12');
expect(interp1Index).toEqual(6);
expect(interp2Index).toEqual(7);
// Participants
const pariticpant1 = participantList.findIndex(x => x.displayName === 'Individual 01');
const pariticpant2 = participantList.findIndex(x => x.displayName === 'Individual 02');
expect(pariticpant1).toEqual(4);
expect(pariticpant2).toEqual(5);

// Interpreter 06
// Individual 12
const witness1 = participantList.findIndex(x => x.displayName === 'Witness 01');
const witness2 = participantList.findIndex(x => x.displayName === 'Witness 02');
expect(witness1).toEqual(6);
expect(witness2).toEqual(7);

// Observers
const observer1Index = participantList.findIndex(x => x.displayName === 'M Observer 03');
expect(observer1Index).toEqual(8);
// Observer 03
const observerIndex = participantList.findIndex(x => x.displayName === 'Observer');
expect(observerIndex).toEqual(8);
// Quicklink
const quicklinkIndex = participantList.findIndex(x => x.displayName === 'QuickLink');
expect(quicklinkIndex).toEqual(9);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,22 +135,50 @@ export abstract class ParticipantStatusDirective {
}

sortParticipants() {
const orderByRoleThenName = (a, b) => {
// Sort by User Role
if (a.role < b.role) {
return -1;
}
if (a.role > b.role) {
return 1;
}
// Sort by Hearing Role
if (a.hearingRole < b.hearingRole) {
return -1;
}
if (a.hearingRole > b.hearingRole) {
return 1;
}
// Sort by Name
return a.displayName.localeCompare(b.displayName);
};
const judges = this.participants.filter(participant => participant.hearingRole === HearingRole.JUDGE);

const panelMembersAndWingers = this.participants.filter(participant =>
[...HearingRoleHelper.panelMemberRoles, HearingRole.WINGER.toString()].includes(participant.hearingRole)
);
const observers = this.participants.filter(participant => participant.hearingRole === HearingRole.OBSERVER);
const interpretersAndInterpretees = this.participants.filter(participant => participant.isInterpreterOrInterpretee);
const others = this.participants.filter(
participant =>
!judges.includes(participant) &&
!panelMembersAndWingers.includes(participant) &&
!interpretersAndInterpretees.includes(participant) &&
!observers.includes(participant)
);

this.sortedParticipants = [...judges, ...panelMembersAndWingers, ...others, ...interpretersAndInterpretees, ...observers];
const panelMembersAndWingers = this.participants
.filter(participant => [...HearingRoleHelper.panelMemberRoles, HearingRole.WINGER.toString()].includes(participant.hearingRole))
.sort(orderByRoleThenName);
const staff = this.participants
.filter(participant => participant.hearingRole === HearingRole.STAFF_MEMBER)
.sort(orderByRoleThenName);
const observers = this.participants
.filter(participant => participant.hearingRole === HearingRole.OBSERVER)
.sort(orderByRoleThenName);
const quickLinks = this.participants
.filter(participant => participant.role === Role.QuickLinkParticipant || participant.role === Role.QuickLinkObserver)
.sort(orderByRoleThenName);

const participants = this.participants
.filter(
participant =>
!judges.includes(participant) &&
!panelMembersAndWingers.includes(participant) &&
!observers.includes(participant) &&
!quickLinks.includes(participant) &&
!staff.includes(participant)
)
.sort(orderByRoleThenName);

this.sortedParticipants = [...judges, ...panelMembersAndWingers, ...staff, ...participants, ...observers, ...quickLinks];
return this.sortedParticipants;
}
}
Loading