Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/UIIN-2617' into UIIN-2617
Browse files Browse the repository at this point in the history
  • Loading branch information
mariia-aloshyna committed Oct 26, 2023
2 parents 527f14c + ebcd7ab commit e5eb10f
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
* 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.
* 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.
* Add immediate warning message when a local instance is shared. Refs UIIN-2617.

## [10.0.0](https://github.com/folio-org/ui-inventory/tree/v10.0.0) (2023-10-13)
Expand Down
10 changes: 4 additions & 6 deletions src/Instance/InstanceEdit/InstanceEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <LoadingView />;
Expand Down
3 changes: 2 additions & 1 deletion src/ViewHoldingsRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <LoadingView />;

Expand Down
4 changes: 2 additions & 2 deletions src/ViewInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -965,9 +965,9 @@ class ViewInstance extends React.Component {

<Callout ref={this.calloutRef} />

{this.state.afterCreate &&
{this.state.afterCreate && !isEmpty(instance) &&
<CalloutRenderer
message={<FormattedMessage id="ui-inventory.instance.successfullySaved" values={{ hrid: instance?.hrid }} />}
message={<FormattedMessage id="ui-inventory.instance.successfullySaved" values={{ hrid: instance.hrid }} />}
/>
}

Expand Down
18 changes: 15 additions & 3 deletions src/components/InstancesList/InstancesList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}),
Expand Down Expand Up @@ -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;
Expand All @@ -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 });

Expand All @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/components/InstancesList/InstancesList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,7 @@ describe('InstancesList', () => {
params: {
query: `${option}=="${_query}"`,
},
tenant: 'diku',
});
});
});
Expand Down
6 changes: 3 additions & 3 deletions src/hooks/useInstanceMutation/useInstanceMutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};

Expand Down
3 changes: 2 additions & 1 deletion src/routes/ItemRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit e5eb10f

Please sign in to comment.