From 3e59803db0d7adefc12aa534ecf513c97295a75f Mon Sep 17 00:00:00 2001 From: Oleksandr Hladchenko <85172747+OleksandrHladchenko1@users.noreply.github.com> Date: Tue, 7 Nov 2023 18:34:49 +0200 Subject: [PATCH] UIIN-2647: Share instance when there are no linked MARC Authorities (follow-up) (#2337) * UIIN-2647: Show only local authorities when share local instance * UIIN-2647: Update CHANGELOG.md * UIIN-2647: Add brackets to query * UIIN-2647: Fix test * UIIN-2647: Share instance when there are no linked MARC Authorities * UIIN-2647: Use selectedInstance instead of regular instance * UIIN-2647: Reduce the depth --- src/ViewInstance.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/ViewInstance.js b/src/ViewInstance.js index 1384c86a0..146344a59 100644 --- a/src/ViewInstance.js +++ b/src/ViewInstance.js @@ -526,12 +526,18 @@ class ViewInstance extends React.Component { }); } - checkIfHasLinkedAuthorities = (instance = {}) => { - const authorityIds = getLinkedAuthorityIds(instance).join(' or '); + checkIfHasLinkedAuthorities = () => { + const { selectedInstance } = this.props; + const authorityIds = getLinkedAuthorityIds(selectedInstance); + + if (isEmpty(authorityIds)) { + this.handleShareLocalInstance(selectedInstance); + return; + } this.props.mutator.authorities.GET({ params: { - query: `id==(${authorityIds})`, + query: `id==(${authorityIds.join(' or ')})`, } }).then(({ authorities }) => { const localAuthorities = authorities.filter(authority => !authority.source.startsWith(CONSORTIUM_PREFIX)); @@ -543,7 +549,7 @@ class ViewInstance extends React.Component { isUnlinkAuthoritiesModalOpen: true, }); } else { - this.handleShareLocalInstance(instance); + this.handleShareLocalInstance(selectedInstance); } }); } @@ -1027,7 +1033,7 @@ class ViewInstance extends React.Component { message={} confirmLabel={} onCancel={() => this.setState({ isShareLocalInstanceModalOpen: false })} - onConfirm={() => this.checkIfHasLinkedAuthorities(instance)} + onConfirm={this.checkIfHasLinkedAuthorities} />