From 4054062749d05fa4de89deae72b23e3c1ea4053e Mon Sep 17 00:00:00 2001 From: Oleksandr Hladchenko <85172747+OleksandrHladchenko1@users.noreply.github.com> Date: Mon, 23 Oct 2023 16:24:08 +0300 Subject: [PATCH 1/3] UIIN-2634: Remove error when search for an item (#2318) * UIIN-2634: Remove error when search for an item * UIIN-2634: Fix tests --- CHANGELOG.md | 1 + src/ViewHoldingsRecord.js | 3 ++- src/components/InstancesList/InstancesList.js | 18 +++++++++++++++--- .../InstancesList/InstancesList.test.js | 1 + src/routes/ItemRoute.js | 3 ++- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b58071dda..d2f21a30f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ * Instance. Series heading has vanished in detailed view. Fixes UIIN-2601. * 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. +* User receives an error when searching for an item in the Inventory app. Fixes UIIN-2634. ## [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/ViewHoldingsRecord.js b/src/ViewHoldingsRecord.js index 35c0bc150..8684f4f6d 100644 --- a/src/ViewHoldingsRecord.js +++ b/src/ViewHoldingsRecord.js @@ -479,9 +479,10 @@ class ViewHoldingsRecord extends React.Component { referenceTables, goTo, stripes, - location: { state: { tenantFrom } }, + location, } = this.props; const { instance } = this.state; + const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant; if (this.isAwaitingResource()) return ; diff --git a/src/components/InstancesList/InstancesList.js b/src/components/InstancesList/InstancesList.js index afe57ce1e..49a468b63 100644 --- a/src/components/InstancesList/InstancesList.js +++ b/src/components/InstancesList/InstancesList.js @@ -16,6 +16,7 @@ import { import saveAs from 'file-saver'; import moment from 'moment'; import classnames from 'classnames'; +import { stringify } from 'query-string'; import { Pluggable, @@ -134,6 +135,7 @@ class InstancesList extends React.Component { }), stripes: PropTypes.object.isRequired, history: PropTypes.shape({ + push: PropTypes.func, listen: PropTypes.func, replace: PropTypes.func, }), @@ -956,8 +958,9 @@ class InstancesList extends React.Component { const { parentResources, parentMutator: { itemsByQuery }, - goTo, getParams, + stripes, + history, } = this.props; const { query, qindex } = parentResources?.query ?? {}; const { searchInProgress } = this.state; @@ -973,7 +976,10 @@ class InstancesList extends React.Component { } itemsByQuery.reset(); - const items = await itemsByQuery.GET({ params: { query: itemQuery } }); + const items = await itemsByQuery.GET({ + params: { query: itemQuery }, + tenant: stripes.okapi.tenant, + }); this.setState({ searchInProgress: false }); @@ -984,7 +990,13 @@ class InstancesList extends React.Component { } const { id, holdingsRecordId } = items[0]; - goTo(`/inventory/view/${instance.id}/${holdingsRecordId}/${id}`, getParams()); + const search = stringify(getParams()); + + history.push({ + pathname: `/inventory/view/${instance.id}/${holdingsRecordId}/${id}`, + search, + state: { tenantTo: stripes.okapi.tenant }, + }); return null; } diff --git a/src/components/InstancesList/InstancesList.test.js b/src/components/InstancesList/InstancesList.test.js index ea5f0f3d3..2c88470d9 100644 --- a/src/components/InstancesList/InstancesList.test.js +++ b/src/components/InstancesList/InstancesList.test.js @@ -559,6 +559,7 @@ describe('InstancesList', () => { params: { query: `${option}=="${_query}"`, }, + tenant: 'diku', }); }); }); diff --git a/src/routes/ItemRoute.js b/src/routes/ItemRoute.js index f3235ab5e..c55ec7d76 100644 --- a/src/routes/ItemRoute.js +++ b/src/routes/ItemRoute.js @@ -174,8 +174,9 @@ class ItemRoute extends React.Component { onClose = () => { const { stripes, - location: { state: { tenantFrom } }, + location, } = this.props; + const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant; switchAffiliation(stripes, tenantFrom, this.goBack); } From f0c4b11848fc19da6abdb8de73cdde863db371ff Mon Sep 17 00:00:00 2001 From: Mariia Aloshyna <55138456+mariia-aloshyna@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:11:19 +0300 Subject: [PATCH 2/3] UIIN-2635: Create new instance success toast no longer shows the instance HRID (#2317) --- CHANGELOG.md | 1 + src/ViewInstance.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2f21a30f..b686dab07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * 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. * User receives an error when searching for an item in the Inventory app. Fixes UIIN-2634. +* Create new instance success toast no longer shows the instance HRID. Fixes UIIN-2635. ## [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/ViewInstance.js b/src/ViewInstance.js index 3aa636308..beeed1f4d 100644 --- a/src/ViewInstance.js +++ b/src/ViewInstance.js @@ -960,9 +960,9 @@ class ViewInstance extends React.Component { - {this.state.afterCreate && + {this.state.afterCreate && !isEmpty(instance) && } + message={} /> } From 33589f72ccdc7418f83d43ce9574b0387daf48cc Mon Sep 17 00:00:00 2001 From: Mariia Aloshyna <55138456+mariia-aloshyna@users.noreply.github.com> Date: Mon, 23 Oct 2023 17:32:10 +0300 Subject: [PATCH 3/3] UIIN-2628: Optimistic locking message not working for instances in non-consortial tenant (#2316) --- CHANGELOG.md | 1 + src/Instance/InstanceEdit/InstanceEdit.js | 10 ++++------ src/hooks/useInstanceMutation/useInstanceMutation.js | 6 +++--- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b686dab07..a2e12fcb6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * Enable/disable consortial holdings/item actions based on User permissions. Refs UIIN-2452. * User receives an error when searching for an item in the Inventory app. Fixes UIIN-2634. * Create new instance success toast no longer shows the instance HRID. Fixes UIIN-2635. +* Optimistic locking message not working for instances in non-consortial tenant. Fixes UIIN-2628. ## [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/Instance/InstanceEdit/InstanceEdit.js b/src/Instance/InstanceEdit/InstanceEdit.js index ed10ba12c..4eb34cae4 100644 --- a/src/Instance/InstanceEdit/InstanceEdit.js +++ b/src/Instance/InstanceEdit/InstanceEdit.js @@ -72,22 +72,20 @@ const InstanceEdit = ({ }, [callout, goBack]); const onError = async error => { - const parsedError = await parseHttpError(error); + const response = await error.response; + const parsedError = await parseHttpError(response); setHttpError(parsedError); }; const isMemberTenant = checkIfUserInMemberTenant(stripes); const tenantId = (isMemberTenant && instance?.shared) ? stripes.user.user.consortium.centralTenantId : stripes.okapi.tenant; - const { mutateInstance } = useInstanceMutation({ - options: { onSuccess, onError }, - tenantId, - }); + const { mutateInstance } = useInstanceMutation({ tenantId }); const onSubmit = useCallback((initialInstance) => { const updatedInstance = marshalInstance(initialInstance, identifierTypesByName); - return mutateInstance(updatedInstance); + return mutateInstance(updatedInstance, { onSuccess, onError }); }, [mutateInstance]); if (isInstanceLoading) return ; diff --git a/src/hooks/useInstanceMutation/useInstanceMutation.js b/src/hooks/useInstanceMutation/useInstanceMutation.js index 7ed3c2af3..082e4548b 100644 --- a/src/hooks/useInstanceMutation/useInstanceMutation.js +++ b/src/hooks/useInstanceMutation/useInstanceMutation.js @@ -5,18 +5,18 @@ import { useTenantKy } from '../../common'; const useInstanceMutation = ({ tenantId, options = {} }) => { const ky = useTenantKy({ tenantId }); - const { mutateAsync } = useMutation({ + const { mutate } = useMutation({ mutationFn: (instance) => { const kyMethod = instance.id ? 'put' : 'post'; const kyPath = instance.id ? `inventory/instances/${instance.id}` : 'inventory/instances'; - return ky[kyMethod](kyPath, { json: instance }); + return ky[kyMethod](kyPath, { json: instance }).json(); }, ...options, }); return { - mutateInstance: mutateAsync, + mutateInstance: mutate, }; };