Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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,
Expand All @@ -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 = '';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down