diff --git a/.changeset/witty-fishes-mix.md b/.changeset/witty-fishes-mix.md new file mode 100644 index 00000000000..1c1c914a217 --- /dev/null +++ b/.changeset/witty-fishes-mix.md @@ -0,0 +1,5 @@ +--- +'@keystone-next/keystone': patch +--- + +The `Set as Authenticated Item`/`Add Authenticated Item` button is now hidden if the relationship field already has the authenticated item. diff --git a/packages/keystone/src/fields/types/relationship/views/index.tsx b/packages/keystone/src/fields/types/relationship/views/index.tsx index 6efefc305e6..c7bfb620973 100644 --- a/packages/keystone/src/fields/types/relationship/views/index.tsx +++ b/packages/keystone/src/fields/types/relationship/views/index.tsx @@ -156,6 +156,8 @@ export const Field = ({ ); } + const authenticatedItem = keystone.authenticatedItem; + return ( {field.label} @@ -206,33 +208,34 @@ export const Field = ({ Create related {foreignList.singular} )} - {keystone.authenticatedItem.state === 'authenticated' && - keystone.authenticatedItem.listKey === field.refListKey && ( + {authenticatedItem.state === 'authenticated' && + authenticatedItem.listKey === field.refListKey && + (value.kind === 'many' + ? value.value.find(x => x.id === authenticatedItem.id) === undefined + : value.value?.id !== authenticatedItem.id) && ( )} {!!(value.kind === 'many'