Skip to content

Commit

Permalink
Merge branch 'main' into renovate-to-renovate
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Oct 27, 2021
2 parents fd4cb0f + db7f231 commit 896048a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-emus-compare.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@keystone-next/keystone': patch
---

Fixed bug in LinkToRelatedItems button for double sided relationships
16 changes: 8 additions & 8 deletions packages/keystone/src/fields/types/relationship/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ import { RelationshipSelect } from './RelationshipSelect';

function LinkToRelatedItems({
itemId,
isDoubleSided,
value,
list,
refFieldKey,
}: {
itemId: string | null;
isDoubleSided: boolean;
value: FieldProps<typeof controller>['value'] & { kind: 'many' | 'one' };
list: ListMeta;
refFieldKey?: string;
}) {
function constructQuery({
isDoubleSided,
refFieldKey,
itemId,
value,
}: {
isDoubleSided?: boolean;
refFieldKey?: string;
itemId: string | null;
value: FieldProps<typeof controller>['value'] & { kind: 'many' | 'one' };
}) {
if (isDoubleSided && itemId) {
return `!assignedTo_matches="${itemId}"`;
if (!!refFieldKey && itemId) {
return `!${refFieldKey}_matches="${itemId}"`;
}
return `!id_in="${(value?.value as { id: string; label: string }[])
.slice(0, 100)
Expand All @@ -58,7 +58,7 @@ function LinkToRelatedItems({
} as const;

if (value.kind === 'many') {
const query = constructQuery({ isDoubleSided, value, itemId });
const query = constructQuery({ refFieldKey, value, itemId });
return (
<Button {...commonProps} as={Link} href={`/${list.path}?${query}`}>
View related {list.plural}
Expand Down Expand Up @@ -240,7 +240,7 @@ export const Field = ({
: value.kind === 'one' && value.value) && (
<LinkToRelatedItems
itemId={value.id}
isDoubleSided={!!field.refFieldKey}
refFieldKey={field.refFieldKey}
list={foreignList}
value={value}
/>
Expand Down

0 comments on commit 896048a

Please sign in to comment.