From 15445939dd4b2de85898de068e80e00ad453f3f4 Mon Sep 17 00:00:00 2001 From: Oleksandr Hladchenko1 Date: Fri, 3 Nov 2023 15:40:26 +0200 Subject: [PATCH 1/4] UIIN-2647: Show only local authorities when share local instance --- src/ViewInstance.js | 56 ++++++++++++++++++++-------------------- src/ViewInstance.test.js | 18 ++++++++++--- src/utils.js | 14 ++++++++++ 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/src/ViewInstance.js b/src/ViewInstance.js index f687c918a..1c471f9f0 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, indentifierTypeNames, INSTANCE_SHARING_STATUSES, layers, @@ -167,6 +167,12 @@ class ViewInstance extends React.Component { accumulate: true, throwErrors: false, }, + authorities: { + type: 'okapi', + path: 'authority-storage/authorities', + accumulate: true, + throwErrors: false, + } }); constructor(props) { @@ -519,34 +525,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 = () => { @@ -1066,6 +1063,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 188eb8000..8e23c34ca 100644 --- a/src/ViewInstance.test.js +++ b/src/ViewInstance.test.js @@ -107,9 +107,10 @@ ConfirmationModal.mockImplementation(({ open, onCancel, onConfirm, + heading, }) => (open ? (
- Confirmation modal + {heading}