Skip to content

Commit

Permalink
UIREQMED-3: Add Search field for Mediated requests activity page
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitriy-Litvinenko committed Jun 21, 2024
1 parent dc33e6f commit 2ffaedd
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import PropTypes from 'prop-types';

import { stripesConnect } from '@folio/stripes/core';

import {
Expand All @@ -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 (
<form
Expand All @@ -43,19 +36,4 @@ const MediatedRequestsFilters = ({
);
};

MediatedRequestsFilters.manifest = {
configs: {
type: 'okapi',
records: 'items',
path: 'settings/entries',
params: {
query: `(scope==${SETTINGS_SCOPES.CIRCULATION} and key==${SETTINGS_KEYS.GENERAL_TLR})`,
},
},
};

MediatedRequestsFilters.propTypes = {
resources: PropTypes.object.isRequired,
};

export default stripesConnect(MediatedRequestsFilters);
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ jest.mock('./components', () => ({
Search: jest.fn((props) => (<div {...props} />)),
}));

jest.mock('../../../../hooks', () => ({
useGeneralTlrSettings: () => false,
}));

const testIds = {
mediatedRequestsFiltersForm: 'MediatedRequestsFiltersForm',
mediatedRequestsFiltersSearch: 'MediatedRequestsFiltersSearch',
Expand Down Expand Up @@ -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();
});
});
1 change: 1 addition & 0 deletions src/hooks/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as useGeneralTlrSettings } from './useGeneralTlrSettings';
33 changes: 33 additions & 0 deletions src/hooks/useGeneralTlrSettings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { useQuery } from 'react-query';

Check failure on line 1 in src/hooks/useGeneralTlrSettings.js

View workflow job for this annotation

GitHub Actions / build-npm

'react-query' should be listed in the project's dependencies. Run 'npm i -S react-query' to add it

Check failure on line 1 in src/hooks/useGeneralTlrSettings.js

View workflow job for this annotation

GitHub Actions / build-npm

'react-query' should be listed in the project's dependencies. Run 'npm i -S react-query' to add it

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;
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

0 comments on commit 2ffaedd

Please sign in to comment.