@@ -18,14 +18,22 @@ import {
1818 Row ,
1919 checkScope ,
2020 collapseAllSections ,
21- expandAllSections
21+ expandAllSections ,
2222} from '@folio/stripes/components' ;
2323
2424import { NotesSmartAccordion } from '@folio/stripes/smart-components' ;
2525
26- import { AccessControl , AccessControlErrorPane } from '@folio/stripes-erm-components' ;
26+ import {
27+ AccessControl ,
28+ AccessControlErrorPane ,
29+ } from '@folio/stripes-erm-components' ;
2730
28- import { Info , POLines , Coverage , Documents } from '../../AgreementLineSections' ;
31+ import {
32+ Info ,
33+ POLines ,
34+ Coverage ,
35+ Documents ,
36+ } from '../../AgreementLineSections' ;
2937
3038import { isExternal , urls } from '../../utilities' ;
3139import DiscoverySettings from '../../DiscoverySettings' ;
@@ -38,7 +46,7 @@ const propTypes = {
3846 canEdit : PropTypes . bool ,
3947 canEditLoading : PropTypes . bool ,
4048 canDelete : PropTypes . bool ,
41- canDeleteLoading : PropTypes . bool
49+ canDeleteLoading : PropTypes . bool ,
4250 } ) ,
4351 components : PropTypes . shape ( {
4452 HelperComponent : PropTypes . elementType ,
@@ -95,23 +103,20 @@ const AgreementLine = ({
95103 canEdit,
96104 canEditLoading,
97105 canDelete,
98- canDeleteLoading
106+ canDeleteLoading,
99107 } = {
100108 canRead : true ,
101109 canReadLoading : false ,
102110 canEdit : true ,
103111 canEditLoading : false ,
104112 canDelete : true ,
105- canDeleteLoading : false
113+ canDeleteLoading : false ,
106114 } , // If not passed, assume everything is accessible and not loading...?
107- components : {
108- TagButton,
109- HelperComponent,
110- } ,
115+ components : { TagButton, HelperComponent } ,
111116 data : { line, policies, tagsLink, tagsInvalidateLinks } ,
112117 handlers,
113118 isLoading,
114- id
119+ id,
115120} ) => {
116121 const stripes = useStripes ( ) ;
117122 const paneProps = {
@@ -123,20 +128,18 @@ const AgreementLine = ({
123128
124129 const accordionStatusRef = useRef ( ) ;
125130
126- const [ showDeleteConfirmationModal , setShowDeleteConfirmationModal ] = useState ( false ) ;
131+ const [ showDeleteConfirmationModal , setShowDeleteConfirmationModal ] =
132+ useState ( false ) ;
127133
128134 if ( isLoading || canReadLoading ) return < LoadingPane data-loading { ...paneProps } /> ;
129135
130136 if ( ! canRead ) {
131- return (
132- < AccessControlErrorPane
133- { ...paneProps }
134- />
135- ) ;
137+ return < AccessControlErrorPane { ...paneProps } /> ;
136138 }
137139
138140 const resource = isExternal ( line ) ? line : ( line . resource ?. _object ?? { } ) ;
139- const resourceName = resource . pti ?. titleInstance . name ?? resource . reference_object ?. label ?? '' ;
141+ const resourceName =
142+ resource . pti ?. titleInstance . name ?? resource . reference_object ?. label ?? '' ;
140143
141144 // istanbul ignore next
142145 const shortcuts = [
@@ -150,10 +153,44 @@ const AgreementLine = ({
150153 } ,
151154 {
152155 name : 'collapseAllSections' ,
153- handler : ( e ) => collapseAllSections ( e , accordionStatusRef )
154- }
156+ handler : ( e ) => collapseAllSections ( e , accordionStatusRef ) ,
157+ } ,
155158 ] ;
156159
160+ const getActionMenu = ( ) => {
161+ const buttons = [ ] ;
162+ if ( stripes . hasPerm ( 'ui-agreements.agreements.edit' ) ) {
163+ buttons . push (
164+ < Button
165+ buttonStyle = "dropdownItem"
166+ disabled = { ! canEdit || canEditLoading }
167+ id = "clickable-dropdown-edit-agreement-line"
168+ onClick = { handlers . onEdit }
169+ >
170+ < Icon icon = { canEditLoading ? 'spinner-ellipsis' : 'edit' } >
171+ < FormattedMessage id = "ui-agreements.agreements.edit" />
172+ </ Icon >
173+ </ Button >
174+ ) ;
175+ }
176+
177+ if ( stripes . hasPerm ( 'ui-agreements.agreements.delete' ) ) {
178+ buttons . push (
179+ < Button
180+ buttonStyle = "dropdownItem"
181+ disabled = { ! canDelete || canDeleteLoading }
182+ id = "clickable-dropdown-delete-agreement-line"
183+ onClick = { ( ) => setShowDeleteConfirmationModal ( true ) }
184+ >
185+ < Icon icon = { canDeleteLoading ? 'spinner-ellipsis' : 'trash' } >
186+ < FormattedMessage id = "ui-agreements.delete" />
187+ </ Icon >
188+ </ Button >
189+ ) ;
190+ }
191+ return buttons ?. length ? buttons : null ;
192+ } ;
193+
157194 return (
158195 < HasCommand
159196 commands = { shortcuts }
@@ -162,30 +199,7 @@ const AgreementLine = ({
162199 >
163200 < >
164201 < Pane
165- actionMenu = { ( ) => ( stripes . hasPerm ( 'ui-agreements.agreements.edit' ) ? (
166- < >
167- < Button
168- buttonStyle = "dropdownItem"
169- disabled = { canEditLoading || ! canEdit }
170- id = "clickable-dropdown-edit-agreement-line"
171- onClick = { handlers . onEdit }
172- >
173- < Icon icon = "edit" >
174- < FormattedMessage id = "ui-agreements.agreements.edit" />
175- </ Icon >
176- </ Button >
177- < Button
178- buttonStyle = "dropdownItem"
179- disabled = { canDeleteLoading || ! canDelete }
180- id = "clickable-dropdown-delete-agreement-line"
181- onClick = { ( ) => setShowDeleteConfirmationModal ( true ) }
182- >
183- < Icon icon = { canEditLoading ? 'spinner-ellipsis' : 'trash' } >
184- < FormattedMessage id = "ui-agreements.delete" />
185- </ Icon >
186- </ Button >
187- </ >
188- ) : null ) }
202+ actionMenu = { getActionMenu }
189203 appIcon = { < AppIcon app = "agreements" iconKey = "agreementLine" /> }
190204 lastMenu = {
191205 < IfPermission perm = "ui-agreements.agreements.edit" >
@@ -198,7 +212,9 @@ const AgreementLine = ({
198212 { ...paneProps }
199213 >
200214 < Info
201- isSuppressFromDiscoveryEnabled = { handlers . isSuppressFromDiscoveryEnabled }
215+ isSuppressFromDiscoveryEnabled = {
216+ handlers . isSuppressFromDiscoveryEnabled
217+ }
202218 line = { line }
203219 resource = { resource }
204220 />
0 commit comments