Skip to content

Commit

Permalink
Implement functionality for hiding proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-blazhko committed Nov 18, 2024
1 parent 21f2a60 commit 1cce240
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Add circulation-storage.staff-slips.collection.get for get staff-slips on Send item in transit. Refs UIREQMED-55.
* Add Decline Action for Mediated request with status of New - Awaiting confirmation. Refs UIREQMED-42.
* Fix DOMPurify import. Refs UIREQMED-56.
* Hide proxy functionality. Refs UIREQMED-59.

## [1.1.0](https://github.com/folio-org/ui-requests-mediated/tree/v1.1.0) (2024-10-30)
* Update github actions. Refs UIREQMED-14.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import {
import {
getTotalCount,
modifyRecordsToExport,
isProxyFunctionalityAvailable,
} from '../../utils';

export const getActionMenu = ({
Expand Down Expand Up @@ -146,7 +147,11 @@ export const getActionMenu = ({
const queryString = queryParams.join(' and ');
const records = await getRecords(queryString);
const recordsToCSV = buildRecords(records);
const columns = getColumnHeaders(REPORT_HEADERS);
const columnHeaders = [
...REPORT_HEADERS,
...(isProxyFunctionalityAvailable() ? ['proxy.name', 'proxy.barcode'] : []),
]

Check failure on line 153 in src/components/MediatedRequestsActivities/MediatedRequestsActivities.js

View workflow job for this annotation

GitHub Actions / build-npm

Missing semicolon

Check failure on line 153 in src/components/MediatedRequestsActivities/MediatedRequestsActivities.js

View workflow job for this annotation

GitHub Actions / build-npm

Missing semicolon
const columns = getColumnHeaders(columnHeaders);

exportToCsv(recordsToCSV, {
onlyFields: columns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
getDeliveryInformation,
getResourceTypeId,
getRequestInformation,
isProxyFunctionalityAvailable,
} from '../../../../utils';

import css from './RequestForm.css';
Expand Down Expand Up @@ -198,7 +199,7 @@ class RequestForm extends React.Component {
});
}

if (request.proxy) {
if (isProxyFunctionalityAvailable() && request.proxy) {
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.PROXY_USER_ID, request.proxyUserId);
onSetSelectedProxy(request.proxy);
}
Expand Down Expand Up @@ -299,20 +300,28 @@ class RequestForm extends React.Component {
onSetSelectedUser,
onSetSelectedProxy,
} = this.props;
const isProxyAvailable = isProxyFunctionalityAvailable();

this.setState({
isUserLoading: true,
requestTypes: {},
isRequestTypesReceived: false,
isUserPreselected: false,
});
onSetSelectedProxy(EMPTY_RESOURCE_VALUE);

if (isProxyAvailable) {
onSetSelectedProxy(EMPTY_RESOURCE_VALUE);
}

onSetSelectedUser(EMPTY_RESOURCE_VALUE);

form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.REQUEST_TYPE, DEFAULT_REQUEST_TYPE_VALUE);
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.PICKUP_SERVICE_POINT_ID, EMPTY_MEDIATED_REQUEST_FORM_VALUE);
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.DELIVERY_ADDRESS_TYPE_ID, EMPTY_MEDIATED_REQUEST_FORM_VALUE);
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.PROXY_USER_ID, EMPTY_MEDIATED_REQUEST_FORM_VALUE);

if (isProxyAvailable) {
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.PROXY_USER_ID, EMPTY_MEDIATED_REQUEST_FORM_VALUE);
}

return findResource(RESOURCE_TYPES.USER, value, fieldName)
.then((result) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getRequestInformation,
getFulfillmentPreference,
getDefaultRequestPreferences,
isProxyFunctionalityAvailable,
} from '../../../../utils';

const basicProps = {
Expand Down Expand Up @@ -169,6 +170,7 @@ jest.mock('../../../../utils', () => ({
getRequestInformation: jest.fn((isTlr, instance, item) => {
return isTlr ? instance : item;
}),
isProxyFunctionalityAvailable: jest.fn(),
}));

describe('RequestForm', () => {
Expand Down Expand Up @@ -253,6 +255,7 @@ describe('RequestForm', () => {
};

beforeEach(() => {
isProxyFunctionalityAvailable.mockReturnValue(true);
props.findResource
.mockResolvedValueOnce(foundInstance)
.mockResolvedValueOnce(user);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
} from '@folio/stripes/core';

import UserForm from '../UserForm';
import { memoizeValidation } from '../../../../utils';
import {
memoizeValidation,
isProxyFunctionalityAvailable,
} from '../../../../utils';
import {
MEDIATED_REQUEST_FORM_FIELD_NAMES,
RESOURCE_KEYS,
Expand Down Expand Up @@ -159,7 +162,10 @@ class RequesterInformation extends Component {
form,
} = this.props;

onSetSelectedProxy(null);
if (isProxyFunctionalityAvailable()) {
onSetSelectedProxy(null);
}

onSetSelectedUser(null);
form.change(MEDIATED_REQUEST_FORM_FIELD_NAMES.REQUEST_TYPE, DEFAULT_REQUEST_TYPE_VALUE);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ import {
ENTER_EVENT_KEY,
BASE_SPINNER_PROPS,
} from '../../../../constants';
import { isProxyFunctionalityAvailable } from '../../../../utils';

jest.mock('../../../../utils', () => ({
...jest.requireActual('../../../../utils'),
memoizeValidation: (fn) => () => fn,
isProxyFunctionalityAvailable: jest.fn(),
}));
jest.mock('../UserForm', () => jest.fn(() => <div />));

Expand Down Expand Up @@ -377,6 +379,18 @@ describe('RequesterInformation', () => {
describe('handleBlur', () => {
const onBlur = jest.fn();

it('should reset proxy if proxy functionality is available', () => {
isProxyFunctionalityAvailable.mockReturnValueOnce(true);
renderRequesterInfoWithBarcode(onBlur);

const requesterBarcodeField = screen.getByTestId(testIds.requesterBarcodeField);

fireEvent.click(requesterBarcodeField);
fireEvent.blur(requesterBarcodeField);

expect(basicProps.onSetSelectedProxy).toHaveBeenCalledWith(null);
});

it('should trigger "input.onBlur" if requester barcode is presented', () => {
renderRequesterInfoWithBarcode(onBlur);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {
getRequesterName,
getProxyInformation,
isProxyFunctionalityAvailable,
} from '../../../../utils';
import UserHighlightBox from '../UserHighlightBox';

Expand All @@ -23,7 +24,7 @@ const UserDetail = ({
const id = user?.id ?? request.requesterId;
const name = getRequesterName(user);
const proxyInformation = getProxyInformation(proxy, request.proxyUserId);
const proxySection = proxyInformation.id ?
const proxySection = (isProxyFunctionalityAvailable() && proxyInformation.id) ?
<UserHighlightBox
title={<FormattedMessage id="ui-requests-mediated.requesterDetails.proxy" />}
name={proxyInformation.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const proxy = {
jest.mock('../../../../utils', () => ({
getRequesterName: jest.fn((user) => user.lastName),
getProxyInformation: jest.fn(() => proxy),
isProxyFunctionalityAvailable: jest.fn(() => true),
}));
jest.mock('../UserHighlightBox', () => jest.fn(({
title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import UserHighlightBox from '../UserHighlightBox';
import {
getProxyInformation,
getRequesterName,
isProxyFunctionalityAvailable,
} from '../../../../utils';

const UserForm = ({
Expand All @@ -31,15 +32,16 @@ const UserForm = ({
const name = getRequesterName(user);
const ConnectedProxyManager = useMemo(() => stripes.connect(ProxyManager), [stripes]);
const proxyInformation = getProxyInformation(proxy, request?.proxyUserId);
const isProxyManagerAvailable = !isEditMode || (!isUserPreselected && isEditPermission);
const isProxyAvailable = isProxyFunctionalityAvailable();
const isProxyManagerAvailable = (!isEditMode || (!isUserPreselected && isEditPermission)) && isProxyAvailable;
const userSection =
<UserHighlightBox
title={<FormattedMessage id="ui-requests-mediated.requesterDetails.requester" />}
name={name}
id={user.id}
barcode={user.barcode}
/>;
const proxySection = proxyInformation.id ?
const proxySection = (isProxyAvailable && proxyInformation.id) ?
<UserHighlightBox
title={<FormattedMessage id="ui-requests-mediated.requesterDetails.proxy" />}
name={proxyInformation.name}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const labelIds = {
jest.mock('../../../../utils', () => ({
getProxyInformation: jest.fn(() => proxy),
getRequesterName: jest.fn((user) => user.lastName),
isProxyFunctionalityAvailable: jest.fn(() => true),
}));
jest.mock('../UserHighlightBox', () => jest.fn(({
title,
Expand Down
4 changes: 2 additions & 2 deletions src/constants/mediatedRequestsActivities.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ export const REPORT_HEADERS = [
'fulfillmentPreference',
'pickupServicePoint.name',
'deliveryAddress',
'proxy.name',
'proxy.barcode',
'patronComments',
];

export const IS_PROXY_AVAILABLE = false;
5 changes: 4 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
REQUEST_PARAMS,
USER_NAMES,
STAFF_SLIPS_TYPE,
IS_PROXY_AVAILABLE,
} from './constants';

export const transformRequestFilterOptions = (formatMessage, source = []) => (
Expand Down Expand Up @@ -337,7 +338,7 @@ export const modifyRecordsToExport = (records) => {
instance.contributorNames = '';
}

if (proxy) {
if (isProxyFunctionalityAvailable() && proxy) {

Check failure on line 341 in src/utils.js

View workflow job for this annotation

GitHub Actions / build-npm

'isProxyFunctionalityAvailable' was used before it was defined

Check failure on line 341 in src/utils.js

View workflow job for this annotation

GitHub Actions / build-npm

'isProxyFunctionalityAvailable' was used before it was defined
proxy.name = getFullNameForCsvRecords(proxy);
}

Expand Down Expand Up @@ -517,3 +518,5 @@ export const convertToSlipData = (source, intl, timeZone, locale) => {

return slipData;
};

export const isProxyFunctionalityAvailable = () => IS_PROXY_AVAILABLE;
7 changes: 2 additions & 5 deletions src/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ import {
buildTemplate,
shouldProcessNode,
buildLocaleDateAndTime,
convertToSlipData, processNode,
convertToSlipData,
processNode,
} from './utils';
import {
FULFILMENT_TYPES,
Expand Down Expand Up @@ -931,10 +932,6 @@ describe('utils', () => {
...records[0].instance,
contributorNames: records[0].instance.contributorNames[0].name,
},
proxy: {
...records[0].proxy,
name: records[0].proxy.lastName,
},
requester: {
...records[0].requester,
name: records[0].requester.lastName,
Expand Down

0 comments on commit 1cce240

Please sign in to comment.