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

[DUOS-1967][risk=no] Only show registered users in Add New Researcher modal #1737

Merged
merged 8 commits into from
Aug 31, 2022
Merged
17 changes: 9 additions & 8 deletions src/components/modals/LibraryCardFormModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ export default function LibraryCardFormModal(props) {
{
style: {
display: 'flex',
marginLeft: '85%',
justifyContent: 'space-between',
justifyContent: 'flex-end',
},
},
[
Expand All @@ -179,9 +178,10 @@ export default function LibraryCardFormModal(props) {
? () => createOnClick(card)
: () => updateOnClick(card),
additionalStyle: {
flex: 1,
display: 'inline-block',
margin: '5%',
margin: '0%',
width: '80px',
height: '15px',
padding: '20px'
},
baseColor: Theme.palette.secondary,
disabled: isConfirmDisabled(modalType, card),
Expand All @@ -190,9 +190,10 @@ export default function LibraryCardFormModal(props) {
h(SimpleButton, {
onClick: closeModal,
additionalStyle: {
flex: 1,
display: 'inline-block',
margin: '5%',
marginLeft: '1%',
width: '80px',
height: '15px',
padding: '20px'
},
baseColor: Theme.palette.secondary,
label: 'Cancel'
Expand Down
17 changes: 13 additions & 4 deletions src/components/signing_official_table/SigningOfficialTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, useRef, Fragment } from 'react';
import { Styles, Theme } from '../../libs/theme';
import { a, h, div, img } from 'react-hyperscript-helpers';
import userIcon from '../../images/icon_manage_users.png';
import { cloneDeep, find, findIndex, join, map, sortedUniq, sortBy, isEmpty, isNil, flow } from 'lodash/fp';
import { cloneDeep, find, findIndex, join, map, sortedUniq, sortBy, isEmpty, isNil, flow, filter } from 'lodash/fp';
import SimpleTable from '../SimpleTable';
import SimpleButton from '../SimpleButton';
import PaginationBar from '../PaginationBar';
Expand Down Expand Up @@ -114,7 +114,7 @@ const LibraryCardCell = ({
}) => {
const id = researcher.userId || researcher.email;
const card = !isEmpty(researcher.libraryCards)
? researcher.libraryCards[0]
? find((card) => card.institutionId === institutionId)(researcher.libraryCards)
: null;
const button = !isNil(card)
? DeactivateLibraryCardButton({
Expand Down Expand Up @@ -183,6 +183,15 @@ const displayNameCell = (displayName, id) => {
};


const onlyResearchersWithoutCardFilter = (institutionId) => (researcher) => {
const cards = researcher.libraryCards;
if (isEmpty(cards)) {
return true;
}

return isNil(find((card) => card.institutionId === institutionId)(researcher.libraryCards));
};

export default function SigningOfficialTable(props) {
const [researchers, setResearchers] = useState(props.researchers || []);
const [tableSize, setTableSize] = useState(10);
Expand All @@ -197,7 +206,7 @@ export default function SigningOfficialTable(props) {
const [confirmationModalMsg, setConfirmationModalMsg] = useState('');
const [confirmationTitle, setConfirmationTitle] = useState('');
const [confirmType, setConfirmType] = useState(confirmModalType.delete);
const { signingOfficial, unregisteredResearchers, isLoading } = props;
const { signingOfficial, isLoading } = props;

//Search function for SearchBar component, function defined in utils
const handleSearchChange = useCallback((searchTerms) => {
Expand Down Expand Up @@ -413,7 +422,7 @@ export default function SigningOfficialTable(props) {
createOnClick: (card) => issueLibraryCard(card, researchers),
closeModal: () => setShowModal(false),
card: selectedCard,
users: unregisteredResearchers,
users: filter(onlyResearchersWithoutCardFilter(signingOfficial.institutionId))(researchers),
institutions: [], //pass in empty array to force modal to hide institution dropdown
modalType: 'add',
lcaContent: lcaContent
Expand Down
11 changes: 2 additions & 9 deletions src/pages/SigningOfficialResearchers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { USER_ROLES } from '../libs/utils';
export default function SigningOfficialResearchers() {
const [signingOfficial, setSiginingOfficial] = useState({});
const [researchers, setResearchers] = useState([]);
const [unregisteredResearchers, setUnregisteredResearchers] = useState();

//states to be added and used for manage researcher component
const [isLoading, setIsLoading] = useState(true);
Expand All @@ -20,13 +19,7 @@ export default function SigningOfficialResearchers() {
try {
setIsLoading(true);
const soUser = await User.getMe();
const soPromises = await Promise.all([
User.list(USER_ROLES.signingOfficial),
User.getUnassignedUsers()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was the only usage of User.getUnassignedUsers() so we can remove it, along with deprecating the API method in consent: GET /api/user/institution/unassigned

Copy link
Contributor Author

@connorlbark connorlbark Aug 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's also used in SigningOfficialDataSubmitters.js; is that deprecated code? (also signing official console, but that is being deprecated)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I was incorrect ... it is used in three places in develop right now, not sure how I missed them.

  • SigningOfficialConsole
  • SigningOfficialDataSubmitters
  • SigningOfficialResearchers

]);
const researcherList = soPromises[0];
const unregisteredResearchers = soPromises[1];
Copy link
Contributor

@rushtong rushtong Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note that the naming here was incorrect, these were not unregistered users, they were registered users with no institution selection.

Naming is hard. The API call was actually returning unregistered users with a LC for the calling user's institution, so User.getUnassignedUsers() is what is mis-named here.

setUnregisteredResearchers(unregisteredResearchers);
const researcherList = await User.list(USER_ROLES.signingOfficial);
setResearchers(researcherList);
setSiginingOfficial(soUser);
setIsLoading(false);
Expand All @@ -41,7 +34,7 @@ export default function SigningOfficialResearchers() {
return (
div({style: Styles.PAGE}, [
div({style: {}, className: 'signing-official-tabs'}, [
h(SigningOfficialTable, {researchers, signingOfficial, unregisteredResearchers, isLoading}, [])
h(SigningOfficialTable, {researchers, signingOfficial, isLoading}, [])
])
])
);
Expand Down