-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move duplicated code into MentionEditButton (sonar audit)
- Loading branch information
1 parent
29cfb7d
commit 2e3767a
Showing
3 changed files
with
56 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// SPDX-FileCopyrightText: 2023 Dusan Mijatovic (Netherlands eScience Center) | ||
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import {useSession} from '~/auth' | ||
import useEditMentionReducer from './useEditMentionReducer' | ||
|
||
import IconButton from '@mui/material/IconButton' | ||
import EditIcon from '@mui/icons-material/Edit' | ||
import DeleteIcon from '@mui/icons-material/Delete' | ||
import {MentionItemProps} from '~/types/Mention' | ||
|
||
export default function MentionEditButtons({item}: {item:MentionItemProps}) { | ||
const {user} = useSession() | ||
const {setEditModal,confirmDelete} = useEditMentionReducer() | ||
const html = [] | ||
|
||
// console.group('MentionEditButtons') | ||
// console.log('user...', user) | ||
// console.log('item...', item) | ||
// console.groupEnd() | ||
|
||
if (user?.role==='rsd_admin') { | ||
// items without DOI can be edited by rsd_admin | ||
html.push( | ||
<IconButton | ||
data-testid="edit-mention-btn" | ||
key="edit-button" | ||
onClick={()=>setEditModal(item)}> | ||
<EditIcon /> | ||
</IconButton> | ||
) | ||
} | ||
// all items can be deleted | ||
html.push( | ||
<IconButton | ||
data-testid="delete-mention-btn" | ||
key="delete-button" | ||
sx={{ | ||
marginLeft:'1rem' | ||
}} | ||
onClick={() => confirmDelete(item)}> | ||
<DeleteIcon /> | ||
</IconButton> | ||
) | ||
|
||
return html | ||
|
||
} |
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