Skip to content

Commit

Permalink
UIIN-2452: Fix creating/editing/duplicating holdings/items for differ…
Browse files Browse the repository at this point in the history
…ent member tenants (follow-up) (#2319)

(cherry picked from commit e583600)
  • Loading branch information
OleksandrHladchenko1 authored and mariia-aloshyna committed Nov 7, 2023
1 parent 33a5eb3 commit f89ff88
Show file tree
Hide file tree
Showing 20 changed files with 214 additions and 110 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change history for ui-inventory

## [10.0.2] IN PROGRESS

* Enable/disable consortial holdings/item actions based on User permissions. Refs UIIN-2452.

## [10.0.1](https://github.com/folio-org/ui-inventory/tree/v10.0.1) (2023-11-03)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v10.0.0...v10.0.1)

Expand All @@ -10,7 +14,6 @@
* Show facet options, if they exist, after clicking the +More button. Refs UIIN-2533.
* If Shared & Held by facets were selected in the Browse search, then retain them in the Search lookup after clicking the record. Refs UIIN-2608.
* Remove error message after switch from Instance Edit screen to another app. Fixes UIIN-2600.
* Enable/disable consortial holdings/item actions based on User permissions. Refs UIIN-2452.

## [10.0.0](https://github.com/folio-org/ui-inventory/tree/v10.0.0) (2023-10-13)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v9.4.12...v10.0.0)
Expand Down
11 changes: 6 additions & 5 deletions src/Holding/CreateHolding/CreateHolding.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CreateHolding = ({
const callout = useCallout();
const { instance, isLoading: isInstanceLoading } = useInstance(instanceId);
const sourceId = referenceData.holdingsSourcesByName?.FOLIO?.id;
const { location: { state: { tenantFrom } } } = history;
const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;

const goBack = useCallback(() => {
history.push({
Expand All @@ -39,21 +39,22 @@ const CreateHolding = ({
});
}, [location.search, instanceId]);

const onCancel = useCallback(() => {
switchAffiliation(stripes, tenantFrom, goBack);
const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);

const onSubmit = useCallback((newHolding) => {
return mutator.holding.POST(newHolding)
.then((holdingsRecord) => {
.then(async (holdingsRecord) => {
await onCancel();

callout.sendCallout({
type: 'success',
message: <FormattedMessage
id="ui-inventory.holdingsRecord.successfullySaved"
values={{ hrid: holdingsRecord.hrid }}
/>,
});
onCancel();
});
}, [onCancel, callout]);

Expand Down
25 changes: 22 additions & 3 deletions src/Holding/DuplicateHolding/DuplicateHolding.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ import {
} from '../../hooks';
import HoldingsForm from '../../edit/holdings/HoldingsForm';
import withLocation from '../../withLocation';
import { switchAffiliation } from '../../utils';

const DuplicateHolding = ({
goTo,
history,
instanceId,
holdingId,
location: { search, state: locationState },
location: {
search,
state: {
backPathname: locationState,
tenantFrom,
} = {},
},
referenceTables,
}) => {
const callout = useCallout();
Expand All @@ -37,10 +44,18 @@ const DuplicateHolding = ({
sourceId,
}), [holding, sourceId]);

const goToDuplicatedHolding = useCallback((id) => {
history.push({
pathname: `/inventory/view/${instanceId}/${id}`,
search,
state: { tenantTo: stripes.okapi.tenant },
});
}, [search, instanceId]);

const onSuccess = useCallback(async (response) => {
const { id, hrid } = await response.json();

goTo(`/inventory/view/${instanceId}/${id}`);
await switchAffiliation(stripes, tenantFrom, () => goToDuplicatedHolding(id));

return callout.sendCallout({
type: 'success',
Expand All @@ -53,13 +68,17 @@ const DuplicateHolding = ({

const { mutateHolding } = useHoldingMutation({ onSuccess });

const onCancel = useCallback(() => {
const goBack = useCallback(() => {
history.push({
pathname: locationState?.backPathname ?? `/inventory/view/${instanceId}`,
search,
});
}, [search, instanceId]);

const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);

const onSubmit = useCallback(holdingValues => (
mutateHolding(holdingValues)
), [mutateHolding]);
Expand Down
25 changes: 19 additions & 6 deletions src/Holding/EditHolding/EditHolding.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
} from '../../hooks';
import HoldingsForm from '../../edit/holdings/HoldingsForm';
import withLocation from '../../withLocation';
import { parseHttpError } from '../../utils';
import {
parseHttpError,
switchAffiliation,
} from '../../utils';

const EditHolding = ({
goTo,
Expand All @@ -28,7 +31,13 @@ const EditHolding = ({
referenceTables,
}) => {
const callout = useCallout();
const { search, state: locationState } = location;
const {
search,
state: {
backPathname: locationState,
tenantFrom,
} = {},
} = location;
const stripes = useStripes();
const [httpError, setHttpError] = useState();
const { instance, isLoading: isInstanceLoading } = useInstanceQuery(instanceId);
Expand All @@ -42,17 +51,21 @@ const EditHolding = ({
referenceTables?.holdingsSources?.find(source => source.id === holding?.sourceId)?.name === 'MARC'
), [holding]);

const onCancel = useCallback(() => {
const goBack = useCallback(() => {
history.push({
pathname: locationState?.backPathname ?? `/inventory/view/${instanceId}`,
search,
});
}, [search, instanceId]);

const onSuccess = useCallback(() => {
onCancel();
const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);

const onSuccess = useCallback(async () => {
await onCancel();

return callout.sendCallout({
callout.sendCallout({
type: 'success',
message: <FormattedMessage
id="ui-inventory.holdingsRecord.successfullySaved"
Expand Down
8 changes: 6 additions & 2 deletions src/Instance/HoldingsList/Holding/HoldingButtonsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const HoldingButtonsGroup = ({
<Button
id={`clickable-view-holdings-${holding.id}`}
data-test-view-holdings
onClick={() => switchAffiliation(stripes, tenantId, onViewHolding)}
onClick={async () => {
await switchAffiliation(stripes, tenantId, onViewHolding);
}}
>
<FormattedMessage id="ui-inventory.viewHoldings" />
</Button>
Expand All @@ -58,7 +60,9 @@ const HoldingButtonsGroup = ({
<Button
id={`clickable-new-item-${holding.id}`}
data-test-add-item
onClick={() => switchAffiliation(stripes, tenantId, onAddItem)}
onClick={async () => {
await switchAffiliation(stripes, tenantId, onAddItem);
}}
buttonStyle="primary paneHeaderNewButton"
>
<FormattedMessage id="ui-inventory.addItem" />
Expand Down
13 changes: 6 additions & 7 deletions src/Instance/HoldingsList/HoldingsListContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ const HoldingsListContainer = ({
const stripes = useStripes();
const { holdingsRecords: holdings, isLoading } = useInstanceHoldingsQuery(instance.id, { tenantId });

const canViewHoldings = stripes.hasPerm('ui-inventory.instance.view');
const canCreateItem = stripes.hasPerm('ui-inventory.item.edit');
const canViewItems = stripes.hasPerm('ui-inventory.instance.view');
const canViewHoldingsAndItems = stripes.hasPerm('ui-inventory.instance.view');
const canCreateItem = stripes.hasPerm('ui-inventory.item.create');

if (isLoading) return <Loading size="large" />;

Expand All @@ -31,9 +30,9 @@ const HoldingsListContainer = ({
holdings={holdings}
instance={instance}
tenantId={tenantId}
showViewHoldingsButton={canViewHoldings}
showViewHoldingsButton={canViewHoldingsAndItems}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
isBarcodeAsHotlink={canViewHoldingsAndItems}
pathToAccordionsState={pathToAccordionsState}
/>
) : (
Expand All @@ -42,9 +41,9 @@ const HoldingsListContainer = ({
holdings={holdings}
instance={instance}
tenantId={tenantId}
showViewHoldingsButton={canViewHoldings}
showViewHoldingsButton={canViewHoldingsAndItems}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
isBarcodeAsHotlink={canViewHoldingsAndItems}
pathToAccordionsState={pathToAccordionsState}
/>
)
Expand Down
2 changes: 1 addition & 1 deletion src/Instance/InstanceDetails/InstanceDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const InstanceDetails = forwardRef(({
const tags = instance?.tags?.tagList;
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);

const canCreateHoldings = stripes.hasPerm('ui-inventory.holdings.edit');
const canCreateHoldings = stripes.hasPerm('ui-inventory.holdings.create');

const detailsLastMenu = useMemo(() => {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import PropTypes from 'prop-types';
import { withRouter } from 'react-router';
import { useHistory } from 'react-router-dom';

import {
IfPermission,
useStripes,
} from '@folio/stripes/core';
import { useStripes } from '@folio/stripes/core';
import {
Row,
Col,
Expand Down Expand Up @@ -39,21 +36,21 @@ const InstanceNewHolding = ({
}, [location.search, instance.id]);

return (
<IfPermission perm="ui-inventory.holdings.create">
<Row>
<Col sm={12}>
<Button
id="clickable-new-holdings-record"
aria-label={label}
buttonStyle="primary"
fullWidth
onClick={() => switchAffiliation(stripes, tenantId, onNewHolding)}
>
{label}
</Button>
</Col>
</Row>
</IfPermission>
<Row>
<Col sm={12}>
<Button
id="clickable-new-holdings-record"
aria-label={label}
buttonStyle="primary"
fullWidth
onClick={async () => {
await switchAffiliation(stripes, tenantId, onNewHolding);
}}
>
{label}
</Button>
</Col>
</Row>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('InstanceNewHolding', () => {
const { getByText } = renderInstanceNewHolding();
fireEvent.click(getByText(/ui-inventory.addHoldings/i));

expect(mockPush).toHaveBeenCalledWith();
expect(mockPush).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ const MemberTenantHoldings = ({
const { holdingsRecords, isLoading } = useInstanceHoldingsQuery(instance?.id, { tenantId: id });
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);

const canViewHoldings = hasMemberTenantPermission('ui-inventory.instance.view', id, userTenantPermissions);
const canCreateItem = hasMemberTenantPermission('ui-inventory.item.edit', id, userTenantPermissions);
const canCreateHoldings = hasMemberTenantPermission('ui-inventory.holdings.edit', id, userTenantPermissions);
const canViewItems = hasMemberTenantPermission('ui-inventory.instance.view', id, userTenantPermissions);
const canViewHoldingsAndItems = hasMemberTenantPermission('ui-inventory.instance.view', id, userTenantPermissions);
const canCreateItem = hasMemberTenantPermission('ui-inventory.item.create', id, userTenantPermissions);
const canCreateHoldings = hasMemberTenantPermission('ui-inventory.holdings.create', id, userTenantPermissions);

if (isEmpty(holdingsRecords)) return null;

Expand All @@ -66,9 +65,9 @@ const MemberTenantHoldings = ({
tenantId={id}
draggable={false}
droppable={false}
showViewHoldingsButton={canViewHoldings}
showViewHoldingsButton={canViewHoldingsAndItems}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
isBarcodeAsHotlink={canViewHoldingsAndItems}
pathToAccordionsState={pathToHoldingsAccordion}
/>
</MoveItemsContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const mockMemberTenant = {
const userTenantPermissions = [{
tenantId: 'college',
permissionNames: [{
permissionName: 'ui-inventory.holdings.edit',
permissionName: 'ui-inventory.holdings.create',
subPermissions: ['test subPermission 1']
}],
}];
Expand Down
4 changes: 3 additions & 1 deletion src/Instance/ItemsList/ItemBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const ItemBarcode = ({
<Button
buttonStyle="link"
buttonClass={css.linkWithoutBorder}
onClick={() => switchAffiliation(stripes, tenantId, onViewItem)}
onClick={async () => {
await switchAffiliation(stripes, tenantId, onViewItem);
}}
>
{itemBarcode}
</Button>
Expand Down
10 changes: 5 additions & 5 deletions src/Item/CreateItem/CreateItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const CreateItem = ({
state: {
tenantTo,
tenantFrom,
},
},
} = {},
} = {},
} = useHistory();

const { isLoading: isInstanceLoading, instance } = useInstanceQuery(instanceId, { tenantId: tenantTo });
Expand All @@ -51,14 +51,14 @@ const CreateItem = ({
});
}, [instanceId, search]);

const onCancel = useCallback(() => {
switchAffiliation(stripes, tenantFrom, goBack);
const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom]);

const onSuccess = useCallback(async (response) => {
const { hrid } = await response.json();

onCancel();
await onCancel();

return callout.sendCallout({
type: 'success',
Expand Down
Loading

0 comments on commit f89ff88

Please sign in to comment.