Skip to content

Commit 772a711

Browse files
committed
Converted selectActiveOrInactiveProfile to a standard selector
1 parent f7a6851 commit 772a711

File tree

2 files changed

+81
-11
lines changed

2 files changed

+81
-11
lines changed

web-ui/src/context/selectors.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createSelector } from 'reselect';
22

33
export const selectMemberProfiles = state => state.memberProfiles || [];
4-
export const selectTerminatedMembers = state => state.terminatedMembers;
4+
export const selectTerminatedMembers = state => state.terminatedMembers || [];
55
export const selectMemberSkills = state => state.memberSkills || [];
66
export const selectSkills = state => state.skills || [];
77
export const selectTeamMembers = state => state.teamMembers;
@@ -327,15 +327,12 @@ export const selectProfile = createSelector(
327327
(profileMap, profileId) => profileMap[profileId]
328328
);
329329

330-
export const selectActiveOrInactiveProfile = (state, profileId) => {
331-
// See if the profile is active, return it if so.
332-
const sender = selectProfile(state, profileId);
333-
if (sender) return sender;
334-
335-
// The profile is inactive or does not exist. Check terminated members.
336-
const terminatedMap = selectProfileMapForTerminatedMembers(state);
337-
return terminatedMap[profileId];
338-
};
330+
export const selectActiveOrInactiveProfile = createSelector(
331+
selectProfileMap,
332+
selectProfileMapForTerminatedMembers,
333+
(state, profileId) => profileId,
334+
(profileMap, termedProfileMap, profileId) => profileMap[profileId] || termedProfileMap[profileId]
335+
);
339336

340337
export const selectSkill = createSelector(
341338
selectSkills,

web-ui/src/context/selectors.test.js

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
selectSupervisorHierarchyIds,
2121
selectSubordinates,
2222
selectIsSubordinateOfCurrentUser,
23-
selectHasReportPermission
23+
selectHasReportPermission,
24+
selectActiveOrInactiveProfile
2425
} from './selectors';
2526

2627
describe('Selectors', () => {
@@ -1525,4 +1526,76 @@ describe('Selectors', () => {
15251526

15261527
expect(selectHasReportPermission(testState)).toBe(false);
15271528
});
1529+
1530+
it('selectActiveOrInactiveProfile should a profile if active or inactive', () => {
1531+
const activeTestMember = {
1532+
id: 1,
1533+
bioText: 'foo',
1534+
employeeId: 11,
1535+
name: 'A Person',
1536+
firstName: 'A',
1537+
lastName: 'PersonA',
1538+
location: 'St Louis',
1539+
title: 'engineer',
1540+
workEmail: '[email protected]',
1541+
pdlId: 9,
1542+
startDate: [2012, 9, 29],
1543+
};
1544+
const inactiveTestMember = {
1545+
id: 2,
1546+
bioText: 'foo',
1547+
employeeId: 12,
1548+
name: 'B Person',
1549+
firstName: 'B',
1550+
lastName: 'PersonB',
1551+
location: 'St Louis',
1552+
title: 'engineer',
1553+
workEmail: '[email protected]',
1554+
pdlId: 9,
1555+
startDate: [2012, 9, 29],
1556+
terminationDate: [2013, 9, 29],
1557+
};
1558+
/** @type MemberProfile[] */
1559+
const testActiveMemberProfiles = [
1560+
activeTestMember,
1561+
{
1562+
id: 3,
1563+
bioText: 'foo',
1564+
employeeId: 13,
1565+
name: 'C Person',
1566+
firstName: 'C',
1567+
lastName: 'PersonC',
1568+
location: 'St Louis',
1569+
title: 'engineer',
1570+
workEmail: '[email protected]',
1571+
pdlId: 9,
1572+
startDate: [2012, 9, 29],
1573+
}
1574+
];
1575+
/** @type MemberProfile[] */
1576+
const testInactiveMemberProfiles = [
1577+
inactiveTestMember,
1578+
{
1579+
id: 4,
1580+
bioText: 'foo',
1581+
employeeId: 13,
1582+
name: 'D Person',
1583+
firstName: 'D',
1584+
lastName: 'PersonD',
1585+
location: 'St Louis',
1586+
title: 'engineer',
1587+
workEmail: '[email protected]',
1588+
pdlId: 9,
1589+
startDate: [2012, 9, 29],
1590+
terminationDate: [2013, 9, 29],
1591+
}
1592+
];
1593+
const testState = {
1594+
memberProfiles: testActiveMemberProfiles,
1595+
terminatedMembers: testInactiveMemberProfiles,
1596+
};
1597+
1598+
expect(selectActiveOrInactiveProfile(testState, activeTestMember.id)).toEqual(activeTestMember);
1599+
expect(selectActiveOrInactiveProfile(testState, inactiveTestMember.id)).toEqual(inactiveTestMember);
1600+
});
15281601
});

0 commit comments

Comments
 (0)