Skip to content

Commit

Permalink
UIIN-2647: Share instance when there are no linked MARC Authorities (…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
OleksandrHladchenko1 authored Nov 7, 2023
1 parent c4faa0c commit 3e59803
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/ViewInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -543,7 +549,7 @@ class ViewInstance extends React.Component {
isUnlinkAuthoritiesModalOpen: true,
});
} else {
this.handleShareLocalInstance(instance);
this.handleShareLocalInstance(selectedInstance);
}
});
}
Expand Down Expand Up @@ -1027,7 +1033,7 @@ class ViewInstance extends React.Component {
message={<FormattedMessage id="ui-inventory.shareLocalInstance.modal.message" values={{ instanceTitle: instance?.title }} />}
confirmLabel={<FormattedMessage id="ui-inventory.shareLocalInstance.modal.confirmButton" />}
onCancel={() => this.setState({ isShareLocalInstanceModalOpen: false })}
onConfirm={() => this.checkIfHasLinkedAuthorities(instance)}
onConfirm={this.checkIfHasLinkedAuthorities}
/>

<ConfirmationModal
Expand Down

0 comments on commit 3e59803

Please sign in to comment.