@@ -5,25 +5,40 @@ import {
5
5
useOkapiKy ,
6
6
} from '@folio/stripes/core' ;
7
7
8
- import { LIMIT_MAX } from '../../constants' ;
8
+ import {
9
+ CQL_OR_OPERATOR ,
10
+ DATA_EXPORT_CONFIGS_API ,
11
+ LIMIT_MAX ,
12
+ ORGANIZATION_INTEGRATION_EXPORT_TYPES ,
13
+ } from '../../constants' ;
14
+
15
+ const buildQuery = ( organizationId ) => {
16
+ const configName = ORGANIZATION_INTEGRATION_EXPORT_TYPES
17
+ . map ( type => `"${ type } _${ organizationId } *"` )
18
+ . join ( ` ${ CQL_OR_OPERATOR } ` ) ;
19
+
20
+ return `configName==(${ configName } )` ;
21
+ } ;
22
+
23
+ const DEFAULT_DATA = [ ] ;
9
24
10
25
export const useIntegrationConfigs = ( { organizationId } ) => {
11
26
const ky = useOkapiKy ( ) ;
12
27
const [ namespace ] = useNamespace ( { key : 'organization-integrations' } ) ;
13
28
14
29
const searchParams = {
15
- query : `configName==EDIFACT_ORDERS_EXPORT_ ${ organizationId } *` ,
30
+ query : buildQuery ( organizationId ) ,
16
31
limit : LIMIT_MAX ,
17
32
} ;
18
33
19
34
const { isFetching, data = { } } = useQuery (
20
35
[ namespace , organizationId ] ,
21
- ( ) => ky . get ( 'data-export-spring/configs' , { searchParams } ) . json ( ) ,
36
+ ( { signal } ) => ky . get ( DATA_EXPORT_CONFIGS_API , { searchParams, signal } ) . json ( ) ,
22
37
{ enabled : Boolean ( organizationId ) } ,
23
38
) ;
24
39
25
40
return ( {
26
- integrationConfigs : data . configs || [ ] ,
41
+ integrationConfigs : data . configs || DEFAULT_DATA ,
27
42
isFetching,
28
43
} ) ;
29
44
} ;
0 commit comments