diff --git a/root/static/scripts/relationship-editor/components/RelationshipDialogContent.js b/root/static/scripts/relationship-editor/components/RelationshipDialogContent.js index c01ceb215a0..e6b50c07b5d 100644 --- a/root/static/scripts/relationship-editor/components/RelationshipDialogContent.js +++ b/root/static/scripts/relationship-editor/components/RelationshipDialogContent.js @@ -420,8 +420,14 @@ export function reducer( oldTargetType === 'url' && newTargetType !== 'url' ) { - const newPlaceholderTarget = - createNonUrlRelatableEntityObject(newTargetType); + const defaultName = ( + source.entityType === 'recording' && newTargetType === 'work' + ) ? source.name : ''; + + const newPlaceholderTarget = createNonUrlRelatableEntityObject( + newTargetType, + {name: defaultName}, + ); newTargetState.autocomplete = createInitialAutocompleteStateForTarget({ @@ -443,6 +449,11 @@ export function reducer( newTargetState.target = createUrlObject(); newTargetState.error = ''; } else if (newTargetType !== 'url') { + + const defaultName = ( + source.entityType === 'recording' && newTargetType === 'work' + ) ? source.name : ''; + updateTargetAutocomplete(newTargetState, { action: { entityType: newTargetType, @@ -452,6 +463,18 @@ export function reducer( source, type: 'update-autocomplete', }); + + if (defaultName) { + updateTargetAutocomplete(newTargetState, { + action: { + type: 'type-value', + value: defaultName, + }, + linkType: null, + source, + type: 'update-autocomplete', + }); + } } newTargetState.creditedAs = ''; diff --git a/root/static/scripts/relationship-editor/hooks/useRelationshipDialogContent.js b/root/static/scripts/relationship-editor/hooks/useRelationshipDialogContent.js index 4ee1681565b..61fba04af45 100644 --- a/root/static/scripts/relationship-editor/hooks/useRelationshipDialogContent.js +++ b/root/static/scripts/relationship-editor/hooks/useRelationshipDialogContent.js @@ -205,13 +205,18 @@ export function useAddRelationshipDialogContent( : (source.entityType <= targetType), ); } + const defaultName = ( + source.entityType === 'recording' && targetType === 'work' + ) ? source.name : ''; + + const targetId = React.useMemo(() => uniqueNegativeId(), []); const defaultTargetObject = React.useMemo(() => { return createRelatableEntityObject( targetType, - {id: uniqueNegativeId(), name: ''}, + {id: targetId, name: defaultName}, ); - }, [targetType]); + }, [targetType, targetId, defaultName]); const _backward = backward ?? (source.entityType > targetType);