Skip to content

Commit

Permalink
Merge pull request #2453 from folio-org/UIIN-2831
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-blazhko committed May 13, 2024
2 parents cb36601 + e355fda commit 7858ac5
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Use consolidated locations endpoint to fetch all locations when in central tenant context. Refs UIIN-2811.
* Change label of eye-readable call number search option in holdings/items. Refs UIIN-2797.
* Jest/RTL: Cover ModalContent components with unit tests. Refs UIIN-2669.
* Add callout noting user's active affiliation when it changes after selecting holding or item. Refs UIIN-2831, UIIN-2872.

## [11.0.4](https://github.com/folio-org/ui-inventory/tree/v11.0.4) (2024-04-30)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v11.0.3...v11.0.4)
Expand Down
10 changes: 9 additions & 1 deletion src/Instance/HoldingsList/Holding/HoldingContainer.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import React, {
useCallback,
useMemo,
useContext,
} from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router';
import { Draggable } from 'react-beautiful-dnd';
import { FormattedMessage } from 'react-intl';

import { useStripes } from '@folio/stripes/core';
import {
useStripes,
CalloutContext,
} from '@folio/stripes/core';

import Holding from './Holding';
import {
navigateToHoldingsViewPage,
navigateToItemCreatePage,
} from '../../utils';
import { sendCalloutOnAffiliationChange } from '../../../utils';

const dragStyles = {
background: '#333',
Expand Down Expand Up @@ -128,9 +133,12 @@ const HoldingContainer = ({
...rest
}) => {
const stripes = useStripes();
const callout = useContext(CalloutContext);

const onViewHolding = useCallback(() => {
navigateToHoldingsViewPage(history, location, instance, holding, tenantId, stripes.okapi.tenant);

sendCalloutOnAffiliationChange(stripes, tenantId, callout);
}, [location.search, instance.id, holding.id]);

const onAddItem = useCallback(() => {
Expand Down
9 changes: 7 additions & 2 deletions src/Instance/ItemsList/ItemBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import {
} from '@folio/stripes/components';
import css from '../../View.css';
import { QUERY_INDEXES } from '../../constants';
import { switchAffiliation } from '../../utils';
import {
switchAffiliation,
sendCalloutOnAffiliationChange,
} from '../../utils';

const ItemBarcode = ({
location,
Expand All @@ -33,6 +36,7 @@ const ItemBarcode = ({
}) => {
const history = useHistory();
const stripes = useStripes();
const callout = useContext(CalloutContext);
const { search } = location;
const queryBarcode = queryString.parse(search)?.query;
const isQueryByBarcode = queryString.parse(search)?.qindex === QUERY_INDEXES.BARCODE;
Expand All @@ -46,9 +50,10 @@ const ItemBarcode = ({
tenantFrom: stripes.okapi.tenant,
},
});

sendCalloutOnAffiliationChange(stripes, tenantId, callout);
}, [instanceId, holdingId, item.id, search]);

const callout = useContext(CalloutContext);
const onCopyToClipbaord = useCallback(() => {
callout.sendCallout({
type: 'success',
Expand Down
23 changes: 23 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -915,3 +915,26 @@ export const getTemplateForSelectedFromBrowseRecord = (queryParams, queryIndex,

return null;
};

export const sendCalloutOnAffiliationChange = (stripes, tenantId, callout) => {
if (tenantId && stripes.okapi.tenant !== tenantId) {
const name = stripes.user.user.tenants.find(tenant => tenant.id === tenantId)?.name;

if (name) {
callout.sendCallout({
type: 'info',
message: (
<FormattedMessage
id="ui-inventory.affiliationChanging.namedNotification"
values={{ name }}
/>
),
});
} else {
callout.sendCallout({
type: 'info',
message: <FormattedMessage id="ui-inventory.affiliationChanging.notification" />,
});
}
}
};
85 changes: 85 additions & 0 deletions src/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
switchAffiliation,
setRecordForDeletion,
parseEmptyFormValue,
sendCalloutOnAffiliationChange,
} from './utils';
import {
CONTENT_TYPE_HEADER,
Expand Down Expand Up @@ -278,3 +279,87 @@ describe('parseEmptyFormValue', () => {
expect(parseEmptyFormValue(value)).toEqual(undefined);
});
});

describe('sendCalloutOnAffiliationChange', () => {
const callout = {
sendCallout: jest.fn(),
};
const tenantId = 'tenantId';

afterEach(() => {
jest.clearAllMocks();
});

describe('When tenant changed', () => {
const okapi = {
tenant: 'okapiTenantId',
};

it('should send named informational notification callout', () => {
const stripes = {
user: {
user: {
tenants: [
{
id: tenantId,
name: 'name',
}
],
},
},
okapi,
};
const expectedArgs = {
type: 'info',
message: (
<FormattedMessage
id="ui-inventory.affiliationChanging.namedNotification"
values={{ name: stripes.user.user.tenants[0].name }}
/>
),
};

sendCalloutOnAffiliationChange(stripes, tenantId, callout);

expect(callout.sendCallout).toHaveBeenCalledWith(expect.objectContaining(expectedArgs));
});

it('should send general informational notification callout', () => {
const stripes = {
user: {
user: {
tenants: [],
},
},
okapi,
};
const expectedArgs = {
type: 'info',
message: <FormattedMessage id="ui-inventory.affiliationChanging.notification" />,
};

sendCalloutOnAffiliationChange(stripes, tenantId, callout);

expect(callout.sendCallout).toHaveBeenCalledWith(expect.objectContaining(expectedArgs));
});
});

describe('When tenant is not changed', () => {
it('should not trigger callout', () => {
const stripes = {
user: {
user: {
tenants: [],
},
},
okapi: {
tenant: tenantId,
},
};

sendCalloutOnAffiliationChange(stripes, tenantId, callout);

expect(callout.sendCallout).not.toHaveBeenCalled();
});
});
});
2 changes: 2 additions & 0 deletions translations/ui-inventory/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,8 @@
"marc": "MARC",
"unknownNoteType": "Unknown note type",
"communicationProblem": "Server communication problem. Please try again",
"affiliationChanging.notification": "Active affiliation has changed",
"affiliationChanging.namedNotification": "Active affiliation has changed to {name}",
"item.status": "Item status",
"item.status.agedToLost": "Aged to lost",
"item.status.available": "Available",
Expand Down

0 comments on commit 7858ac5

Please sign in to comment.