Skip to content

Commit

Permalink
UISACQCOMP-238 Support 'CLAIMS' export type in the 'useIntegrationCon…
Browse files Browse the repository at this point in the history
…figs' hook (#842)

* UISACQCOMP-238 Support 'CLAIMS' export type in the 'useIntegrationConfigs' hook

* update test
  • Loading branch information
usavkov-epam authored Dec 23, 2024
1 parent 76fa627 commit a2bf4fe
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lib/constants/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 0 additions & 2 deletions lib/constants/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
3 changes: 3 additions & 0 deletions lib/constants/cql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const ALL_RECORDS_CQL = 'cql.allRecords=1';
export const CQL_OR_OPERATOR = 'or';
export const CQL_AND_OPERATOR = 'and';
20 changes: 20 additions & 0 deletions lib/constants/export.js
Original file line number Diff line number Diff line change
@@ -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,
];
2 changes: 2 additions & 0 deletions lib/constants/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
23 changes: 19 additions & 4 deletions lib/hooks/useIntegrationConfigs/useIntegrationConfigs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
};
9 changes: 3 additions & 6 deletions lib/hooks/useIntegrationConfigs/useIntegrationConfigs.test.js
Original file line number Diff line number Diff line change
@@ -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 }) => (
<QueryClientProvider client={queryClient}>
{children}
Expand Down Expand Up @@ -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),
},
);
});
Expand Down

0 comments on commit a2bf4fe

Please sign in to comment.