Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/relationship filter bug #6837

Merged
merged 4 commits into from
Oct 27, 2021
Merged
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
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