Skip to content

Commit

Permalink
Merge pull request #19 from tylerablackham/master
Browse files Browse the repository at this point in the history
feat: upgrade to persons v4
  • Loading branch information
jvisker authored Jun 20, 2024
2 parents 8123173 + dd1d98c commit d620b53
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 215 deletions.
20 changes: 16 additions & 4 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<script type="module" src="https://cdn.byu.edu/byu-person-lookup/latest/byu-person-lookup-bundle.min.js"></script>
<script type="module" src="https://cdn.byu.edu/byu-person-lookup/latest/byu-personsv2-datasource-bundle.min.js"></script>
<script type="module" src="https://cdn.byu.edu/byu-person-lookup/latest/byu-personsv3-datasource-bundle.min.js"></script>
<script type="module" src="https://cdn.byu.edu/byu-person-lookup/latest/byu-personsv4-datasource-bundle.min.js"></script>
<!-- <script type="module" src="../dist/byu&#45;person&#45;lookup&#45;bundle.js"></script> -->
<!-- <script type="module" src="../dist/byu&#45;personsv2&#45;datasource&#45;bundle.js"></script> -->
<!-- <script type="module" src="../dist/byu&#45;personsv3&#45;datasource&#45;bundle.js"></script> -->
Expand All @@ -29,10 +30,10 @@ <h1 slot="site-title">Demo: BYU Person Lookup Component</h1>

<div id="content">

<!-- <h2>PersonsV4 Lookup (not in production until March)</h2>-->
<!-- <byu-person-lookup id="lookup-3" context="directory">-->
<!-- <byu-personsv4-datasource></byu-personsv4-datasource>-->
<!-- </byu-person-lookup>-->
<h2>PersonsV4 Lookup</h2>
<byu-person-lookup id="lookup-4" context="directory">
<byu-personsv4-datasource></byu-personsv4-datasource>
</byu-person-lookup>

<h2>PersonsV3 Lookup</h2>
<byu-person-lookup id="lookup-3" context="directory">
Expand Down Expand Up @@ -146,20 +147,29 @@ <h1>Test Authentication (from WSO2)</h1>
selectionElem.textContent = `Selected person ${JSON.stringify(e.detail, null, 2)}`
})

document.getElementById('lookup-4').addEventListener('byu-lookup-results-select', e => {
console.log(`Selected byuId: ${e.detail}`)
const selectionElem = document.getElementById('selection')
selectionElem.textContent = `Selected person ${JSON.stringify(e.detail, null, 2)}`
})

document.getElementById('searchContext').addEventListener('change', e => {
const val = e.target.value
document.getElementById('lookup-2').setAttribute('context', val)
document.getElementById('lookup-3').setAttribute('context', val)
document.getElementById('lookup-4').setAttribute('context', val)
})

document.getElementById('searchCompact').addEventListener('change', e => {
const val = e.target.checked
if (val) {
document.getElementById('lookup-2').setAttribute('compact', '')
document.getElementById('lookup-3').setAttribute('compact', '')
document.getElementById('lookup-4').setAttribute('compact', '')
} else {
document.getElementById('lookup-2').removeAttribute('compact')
document.getElementById('lookup-3').removeAttribute('compact')
document.getElementById('lookup-4').removeAttribute('compact')
}
})

Expand All @@ -168,9 +178,11 @@ <h1>Test Authentication (from WSO2)</h1>
if (val) {
document.getElementById('lookup-2').setAttribute('no-autoselect', '')
document.getElementById('lookup-3').setAttribute('no-autoselect', '')
document.getElementById('lookup-4').setAttribute('no-autoselect', '')
} else {
document.getElementById('lookup-2').removeAttribute('no-autoselect')
document.getElementById('lookup-3').removeAttribute('no-autoselect')
document.getElementById('lookup-4').removeAttribute('no-autoselect')
}
})

Expand Down
87 changes: 36 additions & 51 deletions dist/byu-personsv4-datasource-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -1009,22 +1009,22 @@ function parseAddresses (addresses) {
return null
}
return addresses.values
.filter(address => address.metadata.validation_response.code === 200)
.reduce((all, c) => {
const data = [
lodash_get(c, 'address_line_1.value', ''),
lodash_get(c, 'address_line_2.value', ''),
lodash_get(c, 'address_line_3.value', ''),
lodash_get(c, 'address_line_4.value', '')
].filter(l => l.trim().length > 0);
const key = {
'MAL': 'mailing',
'RES': 'residential',
'WRK': 'work',
'PRM': 'permanent'
}[c.address_type.value] || c.address_type.value;
return Object.assign({}, all, { [key]: data })
}, {})
.filter(address => address.metadata.validation_response.code === 200)
.reduce((all, c) => {
const data = [
lodash_get(c, 'address_line_1.value', ''),
lodash_get(c, 'address_line_2.value', ''),
lodash_get(c, 'address_line_3.value', ''),
lodash_get(c, 'address_line_4.value', '')
].filter(l => l.trim().length > 0);
const key = {
'MAL': 'mailing',
'RES': 'residential',
'WRK': 'work',
'PRM': 'permanent'
}[c.address_type.value] || c.address_type.value;
return Object.assign({}, all, { [key]: data })
}, {})
}

function parseBasic (basic) {
Expand All @@ -1045,38 +1045,33 @@ function parseEmailAddresses (emailAddresses) {
return null
}
return emailAddresses.values.map(e => lodash_get(e, 'email_address.value', ''))
.filter(e => !!e)
.reduce(pickFirst, '')
.filter(e => !!e)
.reduce(pickFirst, '')
}

function parsePhones (phones) {
if (phones.metadata.validation_response.code !== 200) {
return null
}
return phones.values.map(p => lodash_get(p, 'phone_number.value', ''))
.filter(p => !!p)
.reduce(pickFirst, '')
.filter(p => !!p)
.reduce(pickFirst, '')
}

function parseEmployeeSummaries (employeeSummaries) {
if (employeeSummaries.metadata.validation_response.code !== 200) {
return null
}
const isActive = lodash_get(employeeSummaries, 'is_active.value');
const activeStatus = isActive ? 'Active' : 'Not Active';
return {
employeeStatus: lodash_get(employeeSummaries, 'employee_role.value'),
department: lodash_get(employeeSummaries, 'department.value'),
jobTitle: lodash_get(employeeSummaries, 'job_title.description')
employeeStatus: `${lodash_get(employeeSummaries, 'employee_or_contingent_worker_type.value')} (${activeStatus})`,
department: lodash_get(employeeSummaries, 'supervisory_org.value'),
jobTitle: lodash_get(employeeSummaries, 'business_title.value'),
isActive: isActive
}
}

function parseStudentSummaries (studentSummaries) {
if (studentSummaries.metadata.validation_response.code !== 200) {
return null
}
const studentStatus = lodash_get(studentSummaries, 'student_status.value');
return { studentStatus }
}

function pickAddress (addrs) {
if (!addrs) return []
if (addrs.mailing) return addrs.mailing
Expand All @@ -1085,13 +1080,6 @@ function pickAddress (addrs) {
return []
}

function isEmployee (results) {
if (results.employeeStatus) {
return /ACT|LEV/.test(results.employeeStatus)
}
return results.department && results.jobTitle
}

function buildAdditionalInfo (results) {
const workAddress = results.addresses.work ? results.addresses.work : [];
return [
Expand All @@ -1103,14 +1091,13 @@ function buildAdditionalInfo (results) {

function parsePerson (data) {
const results = Object.assign(
{
addresses: parseAddresses(data.addresses),
email: parseEmailAddresses(data.email_addresses),
phone: parsePhones(data.phones)
},
parseBasic(data.basic),
parseEmployeeSummaries(data.employee_summary),
parseStudentSummaries(data.student_summary)
{
addresses: parseAddresses(data.addresses),
email: parseEmailAddresses(data.email_addresses),
phone: parsePhones(data.phones)
},
parseBasic(data.basic),
parseEmployeeSummaries(data.employee_summary),
);
const address = pickAddress(results.addresses);
const {
Expand All @@ -1119,10 +1106,9 @@ function parsePerson (data) {
name,
byuId,
netId,
employeeStatus,
studentStatus
employeeStatus
} = results;
const showAdditionalInfo = isEmployee(results);
const showAdditionalInfo = results.isActive;
const additionalInfo = showAdditionalInfo ? buildAdditionalInfo(results) : [];
return {
address,
Expand All @@ -1132,7 +1118,6 @@ function parsePerson (data) {
byuId,
netId,
employeeStatus,
studentStatus,
showAdditionalInfo,
additionalInfo
}
Expand Down Expand Up @@ -1193,7 +1178,7 @@ async function search (searchText, pageLink) {
headers: new window.Headers({ 'Authorization': authHeader })
};

const fieldSets = 'basic,addresses,email_addresses,phones,employee_summary,student_summary';
const fieldSets = 'basic,addresses,email_addresses,phones,employee_summary';
q.append('field_sets', fieldSets);

q.append('page_size', '50');
Expand Down
4 changes: 2 additions & 2 deletions dist/byu-personsv4-datasource-bundle.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ var t=isObject(e)?objectToString.call(e):"";return t==funcTag||t==genTag}/**
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/const pickFirst=(e,t)=>e||t;function parseLinks(e){const t=lodash_get(e,"persons__next.href"),n=lodash_get(e,"persons__prev.href");return{next:t,prev:n}}function parseAddresses(e){return 200===e.metadata.validation_response.code?e.values.filter(e=>200===e.metadata.validation_response.code).reduce((e,t)=>{const n=[lodash_get(t,"address_line_1.value",""),lodash_get(t,"address_line_2.value",""),lodash_get(t,"address_line_3.value",""),lodash_get(t,"address_line_4.value","")].filter(e=>0<e.trim().length),a={MAL:"mailing",RES:"residential",WRK:"work",PRM:"permanent"}[t.address_type.value]||t.address_type.value;return Object.assign({},e,{[a]:n})},{}):null}function parseBasic(e){const t=lodash_get(e,"name_lnf.value",""),n=lodash_get(e,"byu_id.value",""),a=lodash_get(e,"net_id.value",""),r=lodash_get(e,"person_id.value","");return{name:t,byuId:n,netId:a,personId:r}}function parseEmailAddresses(e){return 200===e.metadata.validation_response.code?e.values.map(t=>lodash_get(t,"email_address.value","")).filter(t=>!!t).reduce(pickFirst,""):null}function parsePhones(e){return 200===e.metadata.validation_response.code?e.values.map(e=>lodash_get(e,"phone_number.value","")).filter(e=>!!e).reduce(pickFirst,""):null}function parseEmployeeSummaries(e){return 200===e.metadata.validation_response.code?{employeeStatus:lodash_get(e,"employee_role.value"),department:lodash_get(e,"department.value"),jobTitle:lodash_get(e,"job_title.description")}:null}function parseStudentSummaries(e){if(200!==e.metadata.validation_response.code)return null;const t=lodash_get(e,"student_status.value");return{studentStatus:t}}function pickAddress(e){return e?e.mailing?e.mailing:e.residential?e.mailing:e.permanent?e.permanent:[]:[]}function isEmployee(e){return e.employeeStatus?/ACT|LEV/.test(e.employeeStatus):e.department&&e.jobTitle}function buildAdditionalInfo(e){const t=e.addresses.work?e.addresses.work:[];return[e.department,e.jobTitle,...t]}function parsePerson(e){const t=Object.assign({addresses:parseAddresses(e.addresses),email:parseEmailAddresses(e.email_addresses),phone:parsePhones(e.phones)},parseBasic(e.basic),parseEmployeeSummaries(e.employee_summary),parseStudentSummaries(e.student_summary)),n=pickAddress(t.addresses),{email:a,phone:r,name:s,byuId:d,netId:o,employeeStatus:i,studentStatus:p}=t,l=isEmployee(t),u=l?buildAdditionalInfo(t):[];return{address:n,email:a,phone:r,name:s,byuId:d,netId:o,employeeStatus:i,studentStatus:p,showAdditionalInfo:l,additionalInfo:u}}function parsePersonv4(e){const t=e.values.map(parsePerson),{next:n,prev:a}=parseLinks(e.links);return{next:n,prev:a,people:t}}/*
*/const pickFirst=(e,t)=>e||t;function parseLinks(e){const t=lodash_get(e,"persons__next.href"),n=lodash_get(e,"persons__prev.href");return{next:t,prev:n}}function parseAddresses(e){return 200===e.metadata.validation_response.code?e.values.filter(e=>200===e.metadata.validation_response.code).reduce((e,t)=>{const n=[lodash_get(t,"address_line_1.value",""),lodash_get(t,"address_line_2.value",""),lodash_get(t,"address_line_3.value",""),lodash_get(t,"address_line_4.value","")].filter(e=>0<e.trim().length),a={MAL:"mailing",RES:"residential",WRK:"work",PRM:"permanent"}[t.address_type.value]||t.address_type.value;return Object.assign({},e,{[a]:n})},{}):null}function parseBasic(e){const t=lodash_get(e,"name_lnf.value",""),n=lodash_get(e,"byu_id.value",""),a=lodash_get(e,"net_id.value",""),r=lodash_get(e,"person_id.value","");return{name:t,byuId:n,netId:a,personId:r}}function parseEmailAddresses(e){return 200===e.metadata.validation_response.code?e.values.map(t=>lodash_get(t,"email_address.value","")).filter(t=>!!t).reduce(pickFirst,""):null}function parsePhones(e){return 200===e.metadata.validation_response.code?e.values.map(e=>lodash_get(e,"phone_number.value","")).filter(e=>!!e).reduce(pickFirst,""):null}function parseEmployeeSummaries(e){if(200!==e.metadata.validation_response.code)return null;const t=lodash_get(e,"is_active.value"),n=t?"Active":"Not Active";return{employeeStatus:`${lodash_get(e,"employee_or_contingent_worker_type.value")} (${n})`,department:lodash_get(e,"supervisory_org.value"),jobTitle:lodash_get(e,"business_title.value"),isActive:t}}function pickAddress(e){return e?e.mailing?e.mailing:e.residential?e.mailing:e.permanent?e.permanent:[]:[]}function buildAdditionalInfo(e){const t=e.addresses.work?e.addresses.work:[];return[e.department,e.jobTitle,...t]}function parsePerson(e){const t=Object.assign({addresses:parseAddresses(e.addresses),email:parseEmailAddresses(e.email_addresses),phone:parsePhones(e.phones)},parseBasic(e.basic),parseEmployeeSummaries(e.employee_summary)),n=pickAddress(t.addresses),{email:a,phone:r,name:s,byuId:d,netId:o,employeeStatus:i}=t,p=t.isActive,l=p?buildAdditionalInfo(t):[];return{address:n,email:a,phone:r,name:s,byuId:d,netId:o,employeeStatus:i,showAdditionalInfo:p,additionalInfo:l}}function parsePersonv4(e){const t=e.values.map(parsePerson),{next:n,prev:a}=parseLinks(e.links);return{next:n,prev:a,people:t}}/*
* Copyright 2018 Brigham Young University
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -510,7 +510,7 @@ var t=isObject(e)?objectToString.call(e):"";return t==funcTag||t==genTag}/**
* See the License for the specific language governing permissions and
* limitations under the License.
*/let authHeader=null,observer=null;function connect(){observer||(observer=new AuthenticationObserver(({state:e,token:t,user:n,error:a})=>{// React to change
authHeader=t?t.authorizationHeader:null}))}function resolveSearchType(){return{label:"Search"}}async function search(e,t){if(!authHeader)throw new Error("Not authenticated!");const n=encodeURIComponent(e),a=new URLSearchParams;a.append("search_context","person_lookup"),a.append("search_text",n);const r={method:"GET",headers:new window.Headers({Authorization:authHeader})};a.append("field_sets","basic,addresses,email_addresses,phones,employee_summary,student_summary"),a.append("page_size","50");const s=t||`${"https://api.byu.edu:443/byuapi/persons/v4"}/?${a.toString()}`,d=await window.fetch(s,r);if(d.ok){const e=await d.json();return parsePersonv4(e)}if(404===d.status)return{};const o=`Error ${d.status} while querying personsv4`;throw new Error(o)}// in disconnectedCallback():
authHeader=t?t.authorizationHeader:null}))}function resolveSearchType(){return{label:"Search"}}async function search(e,t){if(!authHeader)throw new Error("Not authenticated!");const n=encodeURIComponent(e),a=new URLSearchParams;a.append("search_context","person_lookup"),a.append("search_text",n);const r={method:"GET",headers:new window.Headers({Authorization:authHeader})};a.append("field_sets","basic,addresses,email_addresses,phones,employee_summary"),a.append("page_size","50");const s=t||`${"https://api.byu.edu:443/byuapi/persons/v4"}/?${a.toString()}`,d=await window.fetch(s,r);if(d.ok){const e=await d.json();return parsePersonv4(e)}if(404===d.status)return{};const o=`Error ${d.status} while querying personsv4`;throw new Error(o)}// in disconnectedCallback():
function disconnect(){observer&&observer.disconnect(),observer=null}/**
* @license
* Copyright (c) 2017 The Polymer Project Authors. All rights reserved.
Expand Down
Loading

0 comments on commit d620b53

Please sign in to comment.