From a2bf4fe7150e509e5265342fbf468e3e66b27f65 Mon Sep 17 00:00:00 2001 From: Yury Saukou Date: Mon, 23 Dec 2024 11:52:08 +0400 Subject: [PATCH] UISACQCOMP-238 Support 'CLAIMS' export type in the 'useIntegrationConfigs' hook (#842) * UISACQCOMP-238 Support 'CLAIMS' export type in the 'useIntegrationConfigs' hook * update test --- CHANGELOG.md | 1 + lib/constants/api.js | 1 + lib/constants/constants.js | 2 -- lib/constants/cql.js | 3 +++ lib/constants/export.js | 20 ++++++++++++++++ lib/constants/index.js | 2 ++ .../useIntegrationConfigs.js | 23 +++++++++++++++---- .../useIntegrationConfigs.test.js | 9 +++----- 8 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 lib/constants/cql.js create mode 100644 lib/constants/export.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 18f6c496..872718d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * Move reusable helper function to support version history functionality. Refs UISACQCOMP-232. * Move reusable version history hook useVersionHistoryValueResolvers to the ACQ lib. Refs UISACQCOMP-235. * Move reusable claiming code from `ui-receiving` to the shared library. Refs UISACQCOMP-236. +* Support `CLAIMS` export type in the `useIntegrationConfigs` hook. Refs UISACQCOMP-238. ## [6.0.2](https://github.com/folio-org/stripes-acq-components/tree/v6.0.2) (2024-12-04) [Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v6.0.1...v6.0.2) diff --git a/lib/constants/api.js b/lib/constants/api.js index c3fff00b..53917849 100644 --- a/lib/constants/api.js +++ b/lib/constants/api.js @@ -15,6 +15,7 @@ export const CONSORTIUM_INSTITUTIONS_API = 'search/consortium/institutions'; export const CONSORTIUM_LIBRARIES_API = 'search/consortium/libraries'; export const CONSORTIUM_LOCATIONS_API = 'search/consortium/locations'; export const CONTRIBUTOR_NAME_TYPES_API = 'contributor-name-types'; +export const DATA_EXPORT_CONFIGS_API = 'data-export-spring/configs'; export const EXCHANGE_RATE_API = 'finance/exchange-rate'; export const EXPENSE_CLASSES_API = 'finance/expense-classes'; export const FUNDS_API = 'finance/funds'; diff --git a/lib/constants/constants.js b/lib/constants/constants.js index 462e04c8..35ec81b1 100644 --- a/lib/constants/constants.js +++ b/lib/constants/constants.js @@ -39,5 +39,3 @@ export const CENTRAL_ORDERING_DEFAULT_RECEIVING_SEARCH = { centralDefault: 'Central default', activeAffiliationDefault: 'Active affiliation default', }; - -export const ALL_RECORDS_CQL = 'cql.allRecords=1'; diff --git a/lib/constants/cql.js b/lib/constants/cql.js new file mode 100644 index 00000000..3bab77fc --- /dev/null +++ b/lib/constants/cql.js @@ -0,0 +1,3 @@ +export const ALL_RECORDS_CQL = 'cql.allRecords=1'; +export const CQL_OR_OPERATOR = 'or'; +export const CQL_AND_OPERATOR = 'and'; diff --git a/lib/constants/export.js b/lib/constants/export.js new file mode 100644 index 00000000..fc7ba78b --- /dev/null +++ b/lib/constants/export.js @@ -0,0 +1,20 @@ +export const FOLIO_EXPORT_TYPE = { + CIRCULATION_LOG: 'CIRCULATION_LOG', + BURSAR_FEES_FINES: 'BURSAR_FEES_FINES', + BATCH_VOUCHER_EXPORT: 'BATCH_VOUCHER_EXPORT', + EDIFACT_ORDERS_EXPORT: 'EDIFACT_ORDERS_EXPORT', + CLAIMS: 'CLAIMS', + ORDERS_EXPORT: 'ORDERS_EXPORT', + INVOICE_EXPORT: 'INVOICE_EXPORT', + BULK_EDIT_IDENTIFIERS: 'BULK_EDIT_IDENTIFIERS', + BULK_EDIT_QUERY: 'BULK_EDIT_QUERY', + BULK_EDIT_UPDATE: 'BULK_EDIT_UPDATE', + E_HOLDINGS: 'E_HOLDINGS', + AUTH_HEADINGS_UPDATES: 'AUTH_HEADINGS_UPDATES', + FAILED_LINKED_BIB_UPDATES: 'FAILED_LINKED_BIB_UPDATES', +}; + +export const ORGANIZATION_INTEGRATION_EXPORT_TYPES = [ + FOLIO_EXPORT_TYPE.CLAIMS, + FOLIO_EXPORT_TYPE.EDIFACT_ORDERS_EXPORT, +]; diff --git a/lib/constants/index.js b/lib/constants/index.js index b6077df1..2fd9ebf7 100644 --- a/lib/constants/index.js +++ b/lib/constants/index.js @@ -2,8 +2,10 @@ export * from './acqCommands'; export * from './api'; export * from './constants'; export * from './countries'; +export * from './cql'; export * from './customFields'; export * from './events'; +export * from './export'; export * from './invoice'; export * from './item'; export * from './languages'; diff --git a/lib/hooks/useIntegrationConfigs/useIntegrationConfigs.js b/lib/hooks/useIntegrationConfigs/useIntegrationConfigs.js index 3d9063cc..d6125db8 100644 --- a/lib/hooks/useIntegrationConfigs/useIntegrationConfigs.js +++ b/lib/hooks/useIntegrationConfigs/useIntegrationConfigs.js @@ -5,25 +5,40 @@ import { useOkapiKy, } from '@folio/stripes/core'; -import { LIMIT_MAX } from '../../constants'; +import { + CQL_OR_OPERATOR, + DATA_EXPORT_CONFIGS_API, + LIMIT_MAX, + ORGANIZATION_INTEGRATION_EXPORT_TYPES, +} from '../../constants'; + +const buildQuery = (organizationId) => { + const configName = ORGANIZATION_INTEGRATION_EXPORT_TYPES + .map(type => `"${type}_${organizationId}*"`) + .join(` ${CQL_OR_OPERATOR} `); + + return `configName==(${configName})`; +}; + +const DEFAULT_DATA = []; export const useIntegrationConfigs = ({ organizationId }) => { const ky = useOkapiKy(); const [namespace] = useNamespace({ key: 'organization-integrations' }); const searchParams = { - query: `configName==EDIFACT_ORDERS_EXPORT_${organizationId}*`, + query: buildQuery(organizationId), limit: LIMIT_MAX, }; const { isFetching, data = {} } = useQuery( [namespace, organizationId], - () => ky.get('data-export-spring/configs', { searchParams }).json(), + ({ signal }) => ky.get(DATA_EXPORT_CONFIGS_API, { searchParams, signal }).json(), { enabled: Boolean(organizationId) }, ); return ({ - integrationConfigs: data.configs || [], + integrationConfigs: data.configs || DEFAULT_DATA, isFetching, }); }; diff --git a/lib/hooks/useIntegrationConfigs/useIntegrationConfigs.test.js b/lib/hooks/useIntegrationConfigs/useIntegrationConfigs.test.js index 4d5e2463..58a7b872 100644 --- a/lib/hooks/useIntegrationConfigs/useIntegrationConfigs.test.js +++ b/lib/hooks/useIntegrationConfigs/useIntegrationConfigs.test.js @@ -1,19 +1,15 @@ -import React from 'react'; +import { renderHook } from '@testing-library/react-hooks'; import { QueryClient, QueryClientProvider, } from 'react-query'; -import { renderHook } from '@testing-library/react-hooks'; import { useOkapiKy } from '@folio/stripes/core'; import { LIMIT_MAX } from '../../constants'; - import { useIntegrationConfigs } from './useIntegrationConfigs'; const queryClient = new QueryClient(); - -// eslint-disable-next-line react/prop-types const wrapper = ({ children }) => ( {children} @@ -54,9 +50,10 @@ describe('useIntegrationConfigs', () => { 'data-export-spring/configs', { searchParams: { - query: `configName==EDIFACT_ORDERS_EXPORT_${organizationId}*`, + query: `configName==("CLAIMS_${organizationId}*" or "EDIFACT_ORDERS_EXPORT_${organizationId}*")`, limit: LIMIT_MAX, }, + signal: expect.any(AbortSignal), }, ); });