Skip to content

Commit

Permalink
MBS-12937: Changing credits should work without modifying the source …
Browse files Browse the repository at this point in the history
…relationship (#2865)

Fixes the check in `update-relationship-state` to proceed with updating entity
credits even if the source relationship did not change.
  • Loading branch information
mwiencek committed Feb 24, 2023
1 parent 1a7ac86 commit 9fcb286
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,17 +435,30 @@ export function runReducer(
sourceEntity,
} = action;

const relationshipStateChanged = (
oldRelationshipState != null &&
!relationshipsAreIdentical(
oldRelationshipState,
newRelationshipState,
)
);

if (
oldRelationshipState == null ||
!relationshipsAreIdentical(oldRelationshipState, newRelationshipState)
relationshipStateChanged ||
creditsToChangeForSource ||
creditsToChangeForTarget
) {
const targetEntity = getRelationshipTarget(
newRelationshipState,
sourceEntity,
);
const updates = [];

if (oldRelationshipState != null) {
if (
oldRelationshipState != null &&
relationshipStateChanged
) {
/*
* The old relationship state must be removed first in a separate
* `updateRelationships` call, because its presence affects other
Expand All @@ -464,11 +477,16 @@ export function runReducer(
);
}

updates.push(...getUpdatesForAcceptedRelationship(
writableState,
newRelationshipState,
sourceEntity,
));
if (
oldRelationshipState == null ||
relationshipStateChanged
) {
updates.push(...getUpdatesForAcceptedRelationship(
writableState,
newRelationshipState,
sourceEntity,
));
}

/*
* `updateEntityCredits` only uses `newRelationshipState` to obtain
Expand Down
65 changes: 65 additions & 0 deletions root/static/scripts/tests/relationship-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,71 @@ test('splitRelationshipByAttributes', function (t) {
);
});

test('MBS-12937: Changing credits for other relationships without modifying the source relationship', function (t) {
t.plan(1);

const relationship1 = {
_lineage: [],
_original: null,
_status: REL_STATUS_ADD,
attributes: null,
begin_date: null,
editsPending: false,
end_date: null,
ended: false,
entity0: artist,
entity0_credit: 'SOMECREDIT',
entity1: recording,
entity1_credit: '',
id: -1,
linkOrder: 0,
linkTypeID: 148,
};

const relationship2 = {
...relationship1,
entity0_credit: '',
id: -2,
linkTypeID: 297,
};

Object.freeze(relationship1);
Object.freeze(relationship2);

let state = addRelationships(
initialState,
recording,
[relationship1, relationship2],
);

state = reducer(
state,
{
batchSelectionCount: 0,
creditsToChangeForSource: '',
creditsToChangeForTarget: 'all',
newRelationshipState: relationship1,
oldRelationshipState: relationship1,
sourceEntity: recording,
type: 'update-relationship-state',
},
);

currentRelationshipsEqual(
t,
state,
[
relationship1,
{
...relationship2,
entity0_credit: 'SOMECREDIT',
},
],
'all entity credits are updated despite not modifying the source ' +
'relationship',
);
});

function addRelationships(
rootState: RelationshipEditorStateT,
source: CoreEntityT,
Expand Down

0 comments on commit 9fcb286

Please sign in to comment.