-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DCJ-286] Add bulk User operations to dropdown on SO Console (#2563)
- Loading branch information
1 parent
8ffc55b
commit e4f2ba0
Showing
6 changed files
with
286 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import { Checkbox } from '@mui/material'; | ||
import { DAA } from '../../libs/ajax/DAA'; | ||
import { Notifications } from '../../libs/utils'; | ||
|
||
export default function DAACell(props) { | ||
const {rowDac, researcher, institutionId, daas, refreshResearchers, setResearchers} = props; | ||
const id = researcher?.userId || researcher?.email; | ||
const libraryCards = researcher?.libraryCards; | ||
const card = libraryCards?.find(card => card.institutionId === institutionId); | ||
const daaIds = researcher && card?.daaIds; | ||
const filteredDaas = daaIds && daas?.filter(daa => daaIds.includes(daa.daaId)); | ||
const hasDacId = filteredDaas && filteredDaas.some(daa => daa.dacs.some(dac => dac.dacId === rowDac.dacId)); | ||
|
||
const createDaaLcLink = async (daaId, researcher, dacName) => { | ||
try { | ||
await DAA.createDaaLcLink(daaId, researcher.userId); | ||
Notifications.showSuccess({text: `Approved access to ${dacName} to user: ${researcher.displayName}`}); | ||
refreshResearchers(setResearchers); | ||
} catch(error) { | ||
Notifications.showError({text: `Error approving access to ${dacName} to user: ${researcher.displayName}`}); | ||
} | ||
}; | ||
|
||
const deleteDaaLcLink = async (daaId, researcher, dacName) => { | ||
try { | ||
await DAA.deleteDaaLcLink(daaId, researcher.userId); | ||
Notifications.showSuccess({text: `Removed approval of access to ${dacName} to user: ${researcher.displayName}`}); | ||
refreshResearchers(setResearchers); | ||
} catch(error) { | ||
Notifications.showError({text: `Error removing approval of access to ${dacName} to user: ${researcher.displayName}`}); | ||
} | ||
}; | ||
|
||
const handleClick = async (daas, specificDac, researcher) => { | ||
const daaId = daas.find(daa => daa.dacs.some(dac => dac.dacId === specificDac.dacId))?.daaId; | ||
if (!hasDacId) { | ||
createDaaLcLink(daaId, researcher, specificDac.name); | ||
} else { | ||
deleteDaaLcLink(daaId, researcher, specificDac.name); | ||
} | ||
}; | ||
|
||
return { | ||
isComponent: true, | ||
id, | ||
label: 'lc-button', | ||
data: ( | ||
<div> | ||
<Checkbox checked={hasDacId} onClick={() => handleClick(daas, rowDac, researcher)}/> | ||
</div> | ||
), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import React, { useState } from 'react'; | ||
import { Button } from '@mui/material'; | ||
import { DownloadLink } from '../../components/DownloadLink'; | ||
import { DAA } from '../../libs/ajax/DAA'; | ||
import { Notifications } from '../../libs/utils'; | ||
|
||
export default function ManageDaasDropdown(props) { | ||
const [applyAll, setApplyAll] = useState(null); | ||
const {actionsTitle, download, moreData, researchers, refreshResearchers, setResearchers} = props; | ||
|
||
const handleApplyAllChange = (event) => { | ||
setApplyAll(event.target.checked); | ||
}; | ||
|
||
const handleRemoveAllChange = (event) => { | ||
setApplyAll(!event.target.checked); | ||
}; | ||
|
||
const addUsersToDaa = async (userList) => { | ||
try { | ||
await DAA.bulkAddUsersToDaa(moreData.id, userList); | ||
Notifications.showSuccess({text: `Approved all users access to request from: ${moreData.name}`}); | ||
refreshResearchers(setResearchers); | ||
} catch(error) { | ||
Notifications.showError({text: `Error approving all users access to request from: ${moreData.name}`}); | ||
} | ||
}; | ||
|
||
const removeUsersFromDaa = async (userList) => { | ||
try { | ||
await DAA.bulkRemoveUsersFromDaa(moreData.id, userList); | ||
Notifications.showSuccess({text: `Removed all users' approval to request from: ${moreData.name}`}); | ||
refreshResearchers(setResearchers); | ||
} catch(error) { | ||
Notifications.showError({text: `Error removing all users' approval to request from: ${moreData.name}`}); | ||
} | ||
}; | ||
|
||
const handleApplyAll = async () => { | ||
const userList = { 'users': researchers.map(researcher => researcher.userId) }; | ||
if (applyAll) { | ||
addUsersToDaa(userList); | ||
} else { | ||
removeUsersFromDaa(userList); | ||
} | ||
}; | ||
|
||
return ( | ||
<ul className="dropdown-menu" role="menu" style={{ padding: '20px', textTransform:'none'}}> | ||
<div id="link_signOut" style={{display:'flex', padding: '5px', textAlign: 'left'}}> | ||
<strong>{actionsTitle}</strong> | ||
</div> | ||
<form> | ||
<li style={{paddingTop: '5px', paddingBottom: '5px'}}> | ||
<DownloadLink label={`Download agreement`} onDownload={() => {DAA.getDaaFileById(download.id, download.fileName);}}/> | ||
</li> | ||
<li style={{paddingTop: '5px', paddingBottom: '5px'}}> | ||
<label style={{fontWeight: 'normal', whiteSpace: 'nowrap'}}> | ||
<input type="radio" name="daa" value="apply" checked={applyAll === true} onChange={handleApplyAllChange}/> | ||
Apply agreement to all users | ||
</label> | ||
</li> | ||
<li style={{paddingTop: '5px', paddingBottom: '5px'}}> | ||
<label style={{fontWeight: 'normal', whiteSpace: 'nowrap' }}> | ||
<input type="radio" name="daa" value="remove" checked={applyAll === false} onChange={handleRemoveAllChange}/> | ||
Remove agreement from all users | ||
</label> | ||
</li> | ||
</form> | ||
<li style={{paddingTop: '5px', paddingBottom: '5px'}}> | ||
<Button style={{ | ||
fontSize: '15px', | ||
fontWeight: 'normal', | ||
fontFamily: 'Montserrat', | ||
border: '1px solid #0948B7', | ||
borderRadius: '5px', | ||
height: '40px', | ||
marginRight: '1em', | ||
cursor: 'pointer', | ||
color: '#0948B7', | ||
padding: '10px 20px', | ||
textTransform: 'none' | ||
}} onClick={() => handleApplyAll()}>Apply</Button> | ||
</li> | ||
</ul> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.