@@ -4,32 +4,27 @@ import PropTypes from 'prop-types';
4
4
import { useMutation , useQuery , useQueryClient } from 'react-query' ;
5
5
import { FormattedMessage , useIntl } from 'react-intl' ;
6
6
7
- import { get , flatten , uniqBy } from 'lodash' ;
7
+ import { flatten } from 'lodash' ;
8
8
9
- import { CalloutContext , stripesConnect , useOkapiKy } from '@folio/stripes/core' ;
10
- import { useAgreement , useInfiniteFetch , useUsers } from '@folio/stripes-erm-components' ;
9
+ import { CalloutContext , useOkapiKy } from '@folio/stripes/core' ;
10
+ import { useInfiniteFetch , useInterfaces , useUsers } from '@folio/stripes-erm-components' ;
11
11
12
12
import { generateKiwtQueryParams } from '@k-int/stripes-kint-components' ;
13
13
14
14
import View from '../../components/views/Agreement' ;
15
15
import { parseMclPageSize , urls } from '../../components/utilities' ;
16
- import { errorTypes , resultCount } from '../../constants' ;
16
+ import { errorTypes } from '../../constants' ;
17
17
18
18
import { joinRelatedAgreements } from '../utilities/processRelatedAgreements' ;
19
19
20
20
import { useAgreementsHelperApp , useAgreementsSettings , useChunkedOrderLines } from '../../hooks' ;
21
21
import { AGREEMENT_ENDPOINT , AGREEMENT_ERESOURCES_ENDPOINT , AGREEMENT_LINES_ENDPOINT } from '../../constants/endpoints' ;
22
22
23
- const { RECORDS_PER_REQUEST_MEDIUM } = resultCount ;
24
-
25
- const credentialsArray = [ ] ;
26
23
const AgreementViewRoute = ( {
27
24
handlers = { } ,
28
25
history,
29
26
location,
30
27
match : { params : { id : agreementId } } ,
31
- mutator,
32
- resources,
33
28
} ) => {
34
29
const queryClient = useQueryClient ( ) ;
35
30
@@ -52,6 +47,11 @@ const AgreementViewRoute = ({
52
47
53
48
const { agreement, isAgreementLoading } = useAgreement ( { agreementId } ) ;
54
49
50
+
51
+ const interfaces = useInterfaces ( {
52
+ interfaceIds : flatten ( ( agreement ?. orgs ?? [ ] ) . map ( o => o ?. org ?. orgsUuid_object ?. interfaces ?? [ ] ) )
53
+ } ) ?? [ ] ;
54
+
55
55
const { mutateAsync : deleteAgreement } = useMutation (
56
56
[ agreementPath , 'ui-agreements' , 'AgreementViewRoute' , 'deleteAgreement' ] ,
57
57
( ) => ky . delete ( agreementPath ) . then ( ( ) => queryClient . invalidateQueries ( [ 'ERM' , 'Agreements' ] ) )
@@ -200,32 +200,18 @@ const AgreementViewRoute = ({
200
200
}
201
201
) ;
202
202
203
- const getRecord = ( id , resourceType ) => {
204
- return get ( resources , `${ resourceType } .records` , [ ] )
205
- . find ( i => i . id === id ) ;
206
- } ;
207
-
208
203
const getCompositeAgreement = ( ) => {
209
204
const contacts = agreement . contacts . map ( c => ( {
210
205
...c ,
211
206
user : users ?. find ( user => user ?. id === c . user ) || c . user ,
212
207
} ) ) ;
213
208
214
- const interfacesCredentials = uniqBy ( get ( resources , 'interfacesCredentials.records' , [ ] ) , 'id' ) ;
215
-
216
- if ( interfacesCredentials [ 0 ] ) {
217
- const index = credentialsArray . findIndex ( object => object . id === interfacesCredentials [ 0 ] . id ) ;
218
- if ( index === - 1 ) {
219
- credentialsArray . push ( interfacesCredentials [ 0 ] ) ;
220
- }
221
- }
222
-
223
209
const orgs = agreement . orgs . map ( o => ( {
224
210
...o ,
225
- interfaces : get ( o , ' org.orgsUuid_object.interfaces' , [ ] )
211
+ interfaces : ( o ?. org ? .orgsUuid_object ? .interfaces ?? [ ] )
226
212
. map ( id => ( {
227
- ...getRecord ( id , 'interfaces' ) || { } ,
228
- credentials : credentialsArray . find ( cred => cred . interfaceId === id )
213
+ ...( interfaces ?. find ( int => int ?. id === id ) ?? { } ) ,
214
+ /* Credentials are now handled by ViewOrganizationCard directly */
229
215
} ) ) ,
230
216
} ) ) ;
231
217
@@ -281,10 +267,6 @@ const AgreementViewRoute = ({
281
267
history . push ( `${ urls . agreementEdit ( agreementId ) } ${ location . search } ` ) ;
282
268
} ;
283
269
284
- const handleFetchCredentials = ( id ) => {
285
- mutator . interfaceRecord . replace ( { id } ) ;
286
- } ;
287
-
288
270
const handleViewAgreementLine = ( lineId ) => {
289
271
history . push ( `${ urls . agreementLineView ( agreementId , lineId ) } ${ location . search } ` ) ;
290
272
} ;
@@ -319,7 +301,6 @@ const AgreementViewRoute = ({
319
301
onExportAgreement : exportAgreement ,
320
302
onExportEResourcesAsJSON : exportEresourcesAsJson ,
321
303
onExportEResourcesAsKBART : exportEresourcesAsKBART ,
322
- onFetchCredentials : handleFetchCredentials ,
323
304
onFilterEResources : handleFilterEResources ,
324
305
onNeedMoreEResources : ( _askAmount , index ) => fetchNextEresourcePage ( { pageParam : index } ) ,
325
306
onNeedMoreLines : ( _askAmount , index ) => fetchNextLinesPage ( { pageParam : index } ) ,
@@ -331,36 +312,6 @@ const AgreementViewRoute = ({
331
312
) ;
332
313
} ;
333
314
334
- AgreementViewRoute . manifest = Object . freeze ( {
335
- interfaces : { // We can and shouold migrate these to react-query at some point as a separate task
336
- type : 'okapi' ,
337
- path : 'organizations-storage/interfaces' ,
338
- perRequest : RECORDS_PER_REQUEST_MEDIUM ,
339
- params : ( _q , _p , _r , _l , props ) => {
340
- const orgs = get ( props . resources , 'agreement.records[0].orgs' , [ ] ) ;
341
- const interfaces = flatten ( orgs . map ( o => get ( o , 'org.orgsUuid_object.interfaces' , [ ] ) ) ) ;
342
- const query = [
343
- ...new Set ( interfaces . map ( i => `id==${ i } ` ) )
344
- ] . join ( ' or ' ) ;
345
-
346
- return query ? { query } : { } ;
347
- } ,
348
- fetch : props => ! ! props . stripes . hasInterface ( 'organizations-storage.interfaces' , '2.0' ) ,
349
- permissionsRequired : 'organizations-storage.interfaces.collection.get' ,
350
- records : 'interfaces' ,
351
- } ,
352
- interfacesCredentials : {
353
- clientGeneratePk : false ,
354
- throwErrors : false ,
355
- path : 'organizations-storage/interfaces/%{interfaceRecord.id}/credentials' ,
356
- type : 'okapi' ,
357
- pk : 'FAKE_PK' , // it's done to fool stripes-connect not to add cred id to the path's end.
358
- permissionsRequired : 'organizations-storage.interfaces.credentials.item.get' ,
359
- fetch : props => ! ! props . stripes . hasInterface ( 'organizations-storage.interfaces' , '1.0 2.0' ) ,
360
- } ,
361
- interfaceRecord : { } ,
362
- } ) ;
363
-
364
315
AgreementViewRoute . propTypes = {
365
316
handlers : PropTypes . object ,
366
317
history : PropTypes . shape ( {
@@ -374,19 +325,6 @@ AgreementViewRoute.propTypes = {
374
325
id : PropTypes . string . isRequired ,
375
326
} ) . isRequired
376
327
} ) . isRequired ,
377
- mutator : PropTypes . shape ( {
378
- interfaceRecord : PropTypes . shape ( {
379
- replace : PropTypes . func ,
380
- } ) ,
381
- } ) ,
382
- resources : PropTypes . shape ( {
383
- interfaces : PropTypes . object ,
384
- query : PropTypes . object ,
385
- } ) . isRequired ,
386
- stripes : PropTypes . shape ( {
387
- hasInterface : PropTypes . func . isRequired ,
388
- hasPerm : PropTypes . func . isRequired ,
389
- } ) . isRequired ,
390
328
} ;
391
329
392
- export default stripesConnect ( AgreementViewRoute ) ;
330
+ export default AgreementViewRoute ;
0 commit comments