diff --git a/src/components/MediatedRequestsActivities/components/MediatedRequestsFilters/MediatedRequestsFilters.js b/src/components/MediatedRequestsActivities/components/MediatedRequestsFilters/MediatedRequestsFilters.js index 8ef6c01..c622d43 100644 --- a/src/components/MediatedRequestsActivities/components/MediatedRequestsFilters/MediatedRequestsFilters.js +++ b/src/components/MediatedRequestsActivities/components/MediatedRequestsFilters/MediatedRequestsFilters.js @@ -1,5 +1,3 @@ -import PropTypes from 'prop-types'; - import { stripesConnect } from '@folio/stripes/core'; import { @@ -11,18 +9,13 @@ import { import { getIsTitleLevelRequestsFeatureEnabled, } from '../../../../utils'; +import { + useGeneralTlrSettings +} from '../../../../hooks'; -const SETTINGS_SCOPES = { - CIRCULATION: 'circulation', -}; -const SETTINGS_KEYS = { - GENERAL_TLR: 'generalTlr', -}; - -const MediatedRequestsFilters = ({ - resources, -}) => { - const isTitleLevelRequestsFeatureEnabled = getIsTitleLevelRequestsFeatureEnabled(resources); +const MediatedRequestsFilters = () => { + const { data } = useGeneralTlrSettings(); + const isTitleLevelRequestsFeatureEnabled = getIsTitleLevelRequestsFeatureEnabled(data); return (
({ Search: jest.fn((props) => (
)), })); +jest.mock('../../../../hooks', () => ({ + useGeneralTlrSettings: () => false, +})); + const testIds = { mediatedRequestsFiltersForm: 'MediatedRequestsFiltersForm', mediatedRequestsFiltersSearch: 'MediatedRequestsFiltersSearch', @@ -47,7 +51,7 @@ describe('MediatedRequestsFilters', () => { expect(MediatedRequestStatusFilter).toHaveBeenCalledWith(expect.objectContaining({}), {}); }); - it('should not render status filter', () => { + it('should not render level filter', () => { expect(screen.queryByTestId(testIds.mediatedRequestFiltersLevelFilter)).not.toBeInTheDocument(); }); }); diff --git a/src/hooks/index.js b/src/hooks/index.js new file mode 100644 index 0000000..77571bf --- /dev/null +++ b/src/hooks/index.js @@ -0,0 +1 @@ +export { default as useGeneralTlrSettings } from './useGeneralTlrSettings'; diff --git a/src/hooks/useGeneralTlrSettings.js b/src/hooks/useGeneralTlrSettings.js new file mode 100644 index 0000000..4f1c260 --- /dev/null +++ b/src/hooks/useGeneralTlrSettings.js @@ -0,0 +1,33 @@ +import { useQuery } from 'react-query'; + +import { useNamespace, useOkapiKy } from '@folio/stripes/core'; + +const SETTINGS_SCOPES = { + CIRCULATION: 'circulation', +}; +const SETTINGS_KEYS = { + GENERAL_TLR: 'generalTlr', +}; + +const useGeneralTlrSettings = () => { + const ky = useOkapiKy(); + const [namespace] = useNamespace({ key: 'generalTlrSettings' }); + const searchParams = { + query: `(scope==${SETTINGS_SCOPES.CIRCULATION} and key==${SETTINGS_KEYS.GENERAL_TLR})`, + }; + + const { isLoading, data, refetch, isFetching } = useQuery( + [namespace], + () => ky.get('settings/entries', { searchParams }).json(), + { enabled: true }, + ); + + return ({ + isLoading, + isFetching, + data, + refetch, + }); +}; + +export default useGeneralTlrSettings; diff --git a/src/utils.js b/src/utils.js index 1925274..b92cbbb 100644 --- a/src/utils.js +++ b/src/utils.js @@ -6,5 +6,5 @@ export const transformRequestFilterOptions = (formatMessage, source = []) => ( ); export const getIsTitleLevelRequestsFeatureEnabled = (data) => ( - data?.configs.records[0]?.value?.titleLevelRequestsFeatureEnabled || false + data?.items[0]?.value?.titleLevelRequestsFeatureEnabled || false );