diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b28dad54..5ed328dcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ * 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. * ECS: Show info message when user in member tenant tries to view shared instance details without permission. Refs UIIN-2590. +* Show only local MARC Authorities when share local instance. Fixes UIIN-2647. ## [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) diff --git a/src/ViewInstance.js b/src/ViewInstance.js index 2ae2cd82a..053d8a80f 100644 --- a/src/ViewInstance.js +++ b/src/ViewInstance.js @@ -9,7 +9,6 @@ import { import { flowRight, isEmpty, - pick, } from 'lodash'; import { @@ -38,9 +37,10 @@ import { handleKeyCommand, isInstanceShadowCopy, isMARCSource, + getLinkedAuthorityIds, } from './utils'; import { - AUTHORITY_LINKED_FIELDS, + CONSORTIUM_PREFIX, HTTP_RESPONSE_STATUS_CODES, indentifierTypeNames, INSTANCE_SHARING_STATUSES, @@ -170,6 +170,12 @@ class ViewInstance extends React.Component { accumulate: true, throwErrors: false, }, + authorities: { + type: 'okapi', + path: 'authority-storage/authorities', + accumulate: true, + throwErrors: false, + } }); constructor(props) { @@ -522,34 +528,25 @@ class ViewInstance extends React.Component { } checkIfHasLinkedAuthorities = (instance = {}) => { - const linkedAuthorities = pick(this.props.selectedInstance, AUTHORITY_LINKED_FIELDS); - - const findLinkedAuthorities = authorities => { - const linkedAuthoritiesLength = AUTHORITY_LINKED_FIELDS.reduce((total, field) => { - const authoritiesAmount = authorities[field].filter(item => item.authorityId).length; - return total + authoritiesAmount; - }, 0); + const authorityIds = getLinkedAuthorityIds(instance).join(' or '); - return { - hasLinkedAuthorities: !!linkedAuthoritiesLength, - linkedAuthoritiesLength, - }; - }; - - const { - hasLinkedAuthorities, - linkedAuthoritiesLength, - } = findLinkedAuthorities(linkedAuthorities); + this.props.mutator.authorities.GET({ + params: { + query: `id==(${authorityIds})`, + } + }).then(({ authorities }) => { + const localAuthorities = authorities.filter(authority => !authority.source.startsWith(CONSORTIUM_PREFIX)); - if (hasLinkedAuthorities) { - this.setState({ - linkedAuthoritiesLength, - isShareLocalInstanceModalOpen: false, - isUnlinkAuthoritiesModalOpen: true, - }); - } else { - this.handleShareLocalInstance(instance); - } + if (localAuthorities.length) { + this.setState({ + linkedAuthoritiesLength: localAuthorities.length, + isShareLocalInstanceModalOpen: false, + isUnlinkAuthoritiesModalOpen: true, + }); + } else { + this.handleShareLocalInstance(instance); + } + }); } toggleCopyrightModal = () => { @@ -1096,6 +1093,9 @@ ViewInstance.propTypes = { POST: PropTypes.func.isRequired, GET: PropTypes.func.isRequired, }).isRequired, + authorities: PropTypes.shape({ + GET: PropTypes.func.isRequired, + }).isRequired, }), onClose: PropTypes.func, onCopy: PropTypes.func, diff --git a/src/ViewInstance.test.js b/src/ViewInstance.test.js index 0a6aa4779..c8c51c36d 100644 --- a/src/ViewInstance.test.js +++ b/src/ViewInstance.test.js @@ -112,9 +112,10 @@ ConfirmationModal.mockImplementation(({ open, onCancel, onConfirm, + heading, }) => (open ? (