Skip to content

Commit 2f66bdc

Browse files
authored
fix(ui): create-first-user crashes when users collection has join field (#10871)
Fixes #10870 Now we hide join fields from the `/create-first-user` view since they're not meaningful there.
1 parent 5bd17cc commit 2f66bdc

File tree

5 files changed

+80
-41
lines changed

5 files changed

+80
-41
lines changed

packages/ui/src/fields/Join/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,22 @@ const JoinFieldComponent: JoinFieldClientComponent = (props) => {
161161
}
162162

163163
return where
164-
}, [docID, field.targetField.relationTo, field.where, on, docConfig.slug])
164+
}, [docID, field.targetField.relationTo, field.where, on, docConfig?.slug])
165165

166166
const initialDrawerData = useMemo(() => {
167167
const relatedCollection = getEntityConfig({ collectionSlug: field.collection })
168168

169169
return getInitialDrawerData({
170-
collectionSlug: docConfig.slug,
170+
collectionSlug: docConfig?.slug,
171171
docID,
172172
fields: relatedCollection.fields,
173173
segments: field.on.split('.'),
174174
})
175-
}, [getEntityConfig, field.collection, field.on, docConfig.slug, docID])
175+
}, [getEntityConfig, field.collection, field.on, docConfig?.slug, docID])
176+
177+
if (!docConfig) {
178+
return null
179+
}
176180

177181
return (
178182
<div

test/joins/collections/Posts.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export const Posts: CollectionConfig = {
1313
name: 'title',
1414
type: 'text',
1515
},
16+
{
17+
name: 'author',
18+
type: 'relationship',
19+
relationTo: 'users',
20+
},
1621
{
1722
name: 'isFiltered',
1823
type: 'checkbox',

test/joins/config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,21 @@ export default buildConfigWithDefaults({
2929
importMap: {
3030
baseDir: path.resolve(dirname),
3131
},
32+
user: 'users',
3233
},
3334
collections: [
35+
{
36+
slug: 'users',
37+
auth: true,
38+
fields: [
39+
{
40+
type: 'join',
41+
collection: 'posts',
42+
on: 'author',
43+
name: 'posts',
44+
},
45+
],
46+
},
3447
Posts,
3548
Categories,
3649
HiddenPosts,

test/joins/e2e.spec.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,4 +439,11 @@ test.describe('Join Field', () => {
439439
await expect(rows).toHaveCount(1)
440440
await expect(joinField.locator('.cell-canRead')).not.toContainText('false')
441441
})
442+
443+
test('should render create-first-user with when users collection has a join field and hide it', async () => {
444+
await payload.delete({ collection: 'users', where: {} })
445+
const url = new AdminUrlUtil(serverURL, 'users')
446+
await page.goto(url.admin + '/create-first-user')
447+
await expect(page.locator('.field-type.join')).toBeHidden()
448+
})
442449
})

test/joins/payload-types.ts

Lines changed: 48 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface Config {
1111
users: UserAuthOperations;
1212
};
1313
collections: {
14+
users: User;
1415
posts: Post;
1516
categories: Category;
1617
'hidden-posts': HiddenPost;
@@ -28,12 +29,14 @@ export interface Config {
2829
'depth-joins-1': DepthJoins1;
2930
'depth-joins-2': DepthJoins2;
3031
'depth-joins-3': DepthJoins3;
31-
users: User;
3232
'payload-locked-documents': PayloadLockedDocument;
3333
'payload-preferences': PayloadPreference;
3434
'payload-migrations': PayloadMigration;
3535
};
3636
collectionsJoins: {
37+
users: {
38+
posts: 'posts';
39+
};
3740
categories: {
3841
relatedPosts: 'posts';
3942
hasManyPosts: 'posts';
@@ -78,6 +81,7 @@ export interface Config {
7881
};
7982
};
8083
collectionsSelect: {
84+
users: UsersSelect<false> | UsersSelect<true>;
8185
posts: PostsSelect<false> | PostsSelect<true>;
8286
categories: CategoriesSelect<false> | CategoriesSelect<true>;
8387
'hidden-posts': HiddenPostsSelect<false> | HiddenPostsSelect<true>;
@@ -95,7 +99,6 @@ export interface Config {
9599
'depth-joins-1': DepthJoins1Select<false> | DepthJoins1Select<true>;
96100
'depth-joins-2': DepthJoins2Select<false> | DepthJoins2Select<true>;
97101
'depth-joins-3': DepthJoins3Select<false> | DepthJoins3Select<true>;
98-
users: UsersSelect<false> | UsersSelect<true>;
99102
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
100103
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
101104
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
@@ -132,13 +135,35 @@ export interface UserAuthOperations {
132135
password: string;
133136
};
134137
}
138+
/**
139+
* This interface was referenced by `Config`'s JSON-Schema
140+
* via the `definition` "users".
141+
*/
142+
export interface User {
143+
id: string;
144+
posts?: {
145+
docs?: (string | Post)[] | null;
146+
hasNextPage?: boolean | null;
147+
} | null;
148+
updatedAt: string;
149+
createdAt: string;
150+
email: string;
151+
resetPasswordToken?: string | null;
152+
resetPasswordExpiration?: string | null;
153+
salt?: string | null;
154+
hash?: string | null;
155+
loginAttempts?: number | null;
156+
lockUntil?: string | null;
157+
password?: string | null;
158+
}
135159
/**
136160
* This interface was referenced by `Config`'s JSON-Schema
137161
* via the `definition` "posts".
138162
*/
139163
export interface Post {
140164
id: string;
141165
title?: string | null;
166+
author?: (string | null) | User;
142167
/**
143168
* Hides posts for the `filtered` join field in categories
144169
*/
@@ -335,23 +360,6 @@ export interface Singular {
335360
updatedAt: string;
336361
createdAt: string;
337362
}
338-
/**
339-
* This interface was referenced by `Config`'s JSON-Schema
340-
* via the `definition` "users".
341-
*/
342-
export interface User {
343-
id: string;
344-
updatedAt: string;
345-
createdAt: string;
346-
email: string;
347-
resetPasswordToken?: string | null;
348-
resetPasswordExpiration?: string | null;
349-
salt?: string | null;
350-
hash?: string | null;
351-
loginAttempts?: number | null;
352-
lockUntil?: string | null;
353-
password?: string | null;
354-
}
355363
/**
356364
* This interface was referenced by `Config`'s JSON-Schema
357365
* via the `definition` "versions".
@@ -518,6 +526,10 @@ export interface DepthJoins3 {
518526
export interface PayloadLockedDocument {
519527
id: string;
520528
document?:
529+
| ({
530+
relationTo: 'users';
531+
value: string | User;
532+
} | null)
521533
| ({
522534
relationTo: 'posts';
523535
value: string | Post;
@@ -585,10 +597,6 @@ export interface PayloadLockedDocument {
585597
| ({
586598
relationTo: 'depth-joins-3';
587599
value: string | DepthJoins3;
588-
} | null)
589-
| ({
590-
relationTo: 'users';
591-
value: string | User;
592600
} | null);
593601
globalSlug?: string | null;
594602
user: {
@@ -632,12 +640,29 @@ export interface PayloadMigration {
632640
updatedAt: string;
633641
createdAt: string;
634642
}
643+
/**
644+
* This interface was referenced by `Config`'s JSON-Schema
645+
* via the `definition` "users_select".
646+
*/
647+
export interface UsersSelect<T extends boolean = true> {
648+
posts?: T;
649+
updatedAt?: T;
650+
createdAt?: T;
651+
email?: T;
652+
resetPasswordToken?: T;
653+
resetPasswordExpiration?: T;
654+
salt?: T;
655+
hash?: T;
656+
loginAttempts?: T;
657+
lockUntil?: T;
658+
}
635659
/**
636660
* This interface was referenced by `Config`'s JSON-Schema
637661
* via the `definition` "posts_select".
638662
*/
639663
export interface PostsSelect<T extends boolean = true> {
640664
title?: T;
665+
author?: T;
641666
isFiltered?: T;
642667
restrictedField?: T;
643668
upload?: T;
@@ -868,21 +893,6 @@ export interface DepthJoins3Select<T extends boolean = true> {
868893
updatedAt?: T;
869894
createdAt?: T;
870895
}
871-
/**
872-
* This interface was referenced by `Config`'s JSON-Schema
873-
* via the `definition` "users_select".
874-
*/
875-
export interface UsersSelect<T extends boolean = true> {
876-
updatedAt?: T;
877-
createdAt?: T;
878-
email?: T;
879-
resetPasswordToken?: T;
880-
resetPasswordExpiration?: T;
881-
salt?: T;
882-
hash?: T;
883-
loginAttempts?: T;
884-
lockUntil?: T;
885-
}
886896
/**
887897
* This interface was referenced by `Config`'s JSON-Schema
888898
* via the `definition` "payload-locked-documents_select".

0 commit comments

Comments
 (0)