From f89ff88b3eaf70dd3cd952f1897c16851858e8e0 Mon Sep 17 00:00:00 2001
From: Oleksandr Hladchenko
<85172747+oleksandrhladchenko1@users.noreply.github.com>
Date: Fri, 27 Oct 2023 14:57:07 +0300
Subject: [PATCH] UIIN-2452: Fix creating/editing/duplicating holdings/items
for different member tenants (follow-up) (#2319)
(cherry picked from commit e5836008f6dfd32baab98fd7453f296bb8687986)
---
CHANGELOG.md | 5 ++-
src/Holding/CreateHolding/CreateHolding.js | 11 ++---
.../DuplicateHolding/DuplicateHolding.js | 25 +++++++++--
src/Holding/EditHolding/EditHolding.js | 25 ++++++++---
.../Holding/HoldingButtonsGroup.js | 8 +++-
.../HoldingsList/HoldingsListContainer.js | 13 +++---
.../InstanceDetails/InstanceDetails.js | 2 +-
.../InstanceNewHolding/InstanceNewHolding.js | 35 +++++++---------
.../InstanceNewHolding.test.js | 2 +-
.../MemberTenantHoldings.js | 11 +++--
.../MemberTenantHoldings.test.js | 2 +-
src/Instance/ItemsList/ItemBarcode.js | 4 +-
src/Item/CreateItem/CreateItem.js | 10 ++---
src/Item/DuplicateItem/DuplicateItem.js | 19 +++++++--
src/Item/EditItem/EditItem.js | 13 ++++--
src/ViewHoldingsRecord.js | 36 +++++++++++++---
src/ViewHoldingsRecord.test.js | 35 +++++++++++-----
src/routes/ItemRoute.js | 24 -----------
src/utils.js | 2 +-
src/views/ItemView.js | 42 +++++++++++++++++--
20 files changed, 214 insertions(+), 110 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index c7f46d8bc..1c20b9237 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)
@@ -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)
diff --git a/src/Holding/CreateHolding/CreateHolding.js b/src/Holding/CreateHolding/CreateHolding.js
index 1cfcceef9..d778690ee 100644
--- a/src/Holding/CreateHolding/CreateHolding.js
+++ b/src/Holding/CreateHolding/CreateHolding.js
@@ -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({
@@ -39,13 +39,15 @@ 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: ,
});
- onCancel();
});
}, [onCancel, callout]);
diff --git a/src/Holding/DuplicateHolding/DuplicateHolding.js b/src/Holding/DuplicateHolding/DuplicateHolding.js
index 96fb49f32..eac3e2078 100644
--- a/src/Holding/DuplicateHolding/DuplicateHolding.js
+++ b/src/Holding/DuplicateHolding/DuplicateHolding.js
@@ -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();
@@ -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',
@@ -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]);
diff --git a/src/Holding/EditHolding/EditHolding.js b/src/Holding/EditHolding/EditHolding.js
index bb9e3432e..4a855213f 100644
--- a/src/Holding/EditHolding/EditHolding.js
+++ b/src/Holding/EditHolding/EditHolding.js
@@ -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,
@@ -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);
@@ -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: switchAffiliation(stripes, tenantId, onViewHolding)}
+ onClick={async () => {
+ await switchAffiliation(stripes, tenantId, onViewHolding);
+ }}
>
@@ -58,7 +60,9 @@ const HoldingButtonsGroup = ({