Skip to content

Commit

Permalink
[DT-252][risk=no] Refactor user properties (#2567)
Browse files Browse the repository at this point in the history
  • Loading branch information
rushtong authored Feb 24, 2025
1 parent 6311d8c commit 744f90f
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const user = {
email: 'janedoe@gmail.com',
eraCommonsId: 'asdg',
libraryCards: [{}],
researcherProperties: [
properties: [
{
propertyId: 10350,
userId: 5,
Expand All @@ -45,7 +45,7 @@ const userNoLibraryCard = {
email: 'janedoe@gmail.com',
eraCommonsId: 'asdg',
libraryCards: [],
researcherProperties: [
properties: [
{
propertyId: 10350,
userId: 5,
Expand Down
4 changes: 2 additions & 2 deletions cypress/component/ERACommons/era_commons.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ describe('ERA Commons Component', function () {
clonedResearcher.eraCommonsId = 'testing';
const iat = new Date().getTime();
const exp = iat + (30 * 24 * 60 * 60 * 1000); // iat + 30 days
clonedResearcher.researcherProperties = [
clonedResearcher.properties = [
{propertyKey:'eraAuthorized', propertyValue: true},
{propertyKey:'eraExpiration', propertyValue: exp}
];
cy.stub(User, 'getMe').returns(clonedResearcher);
// The saveNihUsr function only returns the user's properties, not the entire user object
cy.stub(AuthenticateNIH, 'saveNihUsr').returns(clonedResearcher.researcherProperties);
cy.stub(AuthenticateNIH, 'saveNihUsr').returns(clonedResearcher.properties);
mount(<ERACommons
isAuthorized={true}
className={''}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ERACommons.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export default function ERACommons(props) {
const deleteResponse = await AuthenticateNIH.deleteAccountLinkage();
if (deleteResponse) {
const response = await User.getMe();
const eraAuthState = extractEraAuthenticationState(response.researcherProperties);
const eraAuthState = extractEraAuthenticationState(response.properties);
setAuthorized(eraAuthState.isAuthorized);
setExpirationCount(eraAuthState.expirationCount);
setEraCommonsId(researcherProfile.eraCommonsId);
Expand Down
10 changes: 5 additions & 5 deletions src/components/ResearcherReview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ export const ResearcherReview = (props) => {
value: '',
user: {},
institution: {},
researcherProperties: {
properties: {
eraCommonsId: ''
}
});

useEffect(() => {
const user = props.user;
let researcherProps = getPropertyValuesFromUser(user);
let userProps = getPropertyValuesFromUser(user);
setState((prev) => ({
...prev,
user: user,
institution: !isEmpty(user.institution) ? user.institution : null,
researcherProperties: researcherProps
properties: userProps
}));
}, [props.user]);

const { researcherProperties, user, institution } = state;
const { properties, user, institution } = state;

return (
<div className="container">
Expand All @@ -49,7 +49,7 @@ export const ResearcherReview = (props) => {
<div className="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<label className="control-label">NIH User Name</label>
<div id="lbl_profileeraCommonsId" className="control-data" name="profileeraCommonsId" readOnly={true}>
{researcherProperties.eraCommonsId}
{properties.eraCommonsId}
</div>
</div>
<div className="col-lg-6 col-md-6 col-sm-6 col-xs-12">
Expand Down
1 change: 1 addition & 0 deletions src/libs/models.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const Models = {
associatedDaa: null
},
dar: {
properties: [],
researcherProperties: [],
researcherId: '',
rus: '',
Expand Down
5 changes: 3 additions & 2 deletions src/libs/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ export const goToPage = (value, pageCount, setCurrentPage) => {
};

export const findPropertyValue = (propName, researcher) => {
const prop = isNil(researcher.researcherProperties) ?
const props = researcher.properties;
const prop = isNil(props) ?
null
: find({propertyKey: propName})(researcher.researcherProperties);
: find({propertyKey: propName})(props);
return isNil(prop) ? '' : prop.propertyValue;
};

Expand Down

0 comments on commit 744f90f

Please sign in to comment.