fix(ui): create-first-user crashes when users collection has join field (#10871)

Fixes https://github.com/payloadcms/payload/issues/10870
Now we hide join fields from the `/create-first-user` view since they're
not meaningful there.
This commit is contained in:
Sasha
2025-01-29 19:52:22 +02:00
committed by GitHub
parent 5bd17cc111
commit 2f66bdc2dc
5 changed files with 80 additions and 41 deletions

View File

@@ -161,18 +161,22 @@ const JoinFieldComponent: JoinFieldClientComponent = (props) => {
} }
return where return where
}, [docID, field.targetField.relationTo, field.where, on, docConfig.slug]) }, [docID, field.targetField.relationTo, field.where, on, docConfig?.slug])
const initialDrawerData = useMemo(() => { const initialDrawerData = useMemo(() => {
const relatedCollection = getEntityConfig({ collectionSlug: field.collection }) const relatedCollection = getEntityConfig({ collectionSlug: field.collection })
return getInitialDrawerData({ return getInitialDrawerData({
collectionSlug: docConfig.slug, collectionSlug: docConfig?.slug,
docID, docID,
fields: relatedCollection.fields, fields: relatedCollection.fields,
segments: field.on.split('.'), segments: field.on.split('.'),
}) })
}, [getEntityConfig, field.collection, field.on, docConfig.slug, docID]) }, [getEntityConfig, field.collection, field.on, docConfig?.slug, docID])
if (!docConfig) {
return null
}
return ( return (
<div <div

View File

@@ -13,6 +13,11 @@ export const Posts: CollectionConfig = {
name: 'title', name: 'title',
type: 'text', type: 'text',
}, },
{
name: 'author',
type: 'relationship',
relationTo: 'users',
},
{ {
name: 'isFiltered', name: 'isFiltered',
type: 'checkbox', type: 'checkbox',

View File

@@ -29,8 +29,21 @@ export default buildConfigWithDefaults({
importMap: { importMap: {
baseDir: path.resolve(dirname), baseDir: path.resolve(dirname),
}, },
user: 'users',
}, },
collections: [ collections: [
{
slug: 'users',
auth: true,
fields: [
{
type: 'join',
collection: 'posts',
on: 'author',
name: 'posts',
},
],
},
Posts, Posts,
Categories, Categories,
HiddenPosts, HiddenPosts,

View File

@@ -439,4 +439,11 @@ test.describe('Join Field', () => {
await expect(rows).toHaveCount(1) await expect(rows).toHaveCount(1)
await expect(joinField.locator('.cell-canRead')).not.toContainText('false') await expect(joinField.locator('.cell-canRead')).not.toContainText('false')
}) })
test('should render create-first-user with when users collection has a join field and hide it', async () => {
await payload.delete({ collection: 'users', where: {} })
const url = new AdminUrlUtil(serverURL, 'users')
await page.goto(url.admin + '/create-first-user')
await expect(page.locator('.field-type.join')).toBeHidden()
})
}) })

View File

@@ -11,6 +11,7 @@ export interface Config {
users: UserAuthOperations; users: UserAuthOperations;
}; };
collections: { collections: {
users: User;
posts: Post; posts: Post;
categories: Category; categories: Category;
'hidden-posts': HiddenPost; 'hidden-posts': HiddenPost;
@@ -28,12 +29,14 @@ export interface Config {
'depth-joins-1': DepthJoins1; 'depth-joins-1': DepthJoins1;
'depth-joins-2': DepthJoins2; 'depth-joins-2': DepthJoins2;
'depth-joins-3': DepthJoins3; 'depth-joins-3': DepthJoins3;
users: User;
'payload-locked-documents': PayloadLockedDocument; 'payload-locked-documents': PayloadLockedDocument;
'payload-preferences': PayloadPreference; 'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration; 'payload-migrations': PayloadMigration;
}; };
collectionsJoins: { collectionsJoins: {
users: {
posts: 'posts';
};
categories: { categories: {
relatedPosts: 'posts'; relatedPosts: 'posts';
hasManyPosts: 'posts'; hasManyPosts: 'posts';
@@ -78,6 +81,7 @@ export interface Config {
}; };
}; };
collectionsSelect: { collectionsSelect: {
users: UsersSelect<false> | UsersSelect<true>;
posts: PostsSelect<false> | PostsSelect<true>; posts: PostsSelect<false> | PostsSelect<true>;
categories: CategoriesSelect<false> | CategoriesSelect<true>; categories: CategoriesSelect<false> | CategoriesSelect<true>;
'hidden-posts': HiddenPostsSelect<false> | HiddenPostsSelect<true>; 'hidden-posts': HiddenPostsSelect<false> | HiddenPostsSelect<true>;
@@ -95,7 +99,6 @@ export interface Config {
'depth-joins-1': DepthJoins1Select<false> | DepthJoins1Select<true>; 'depth-joins-1': DepthJoins1Select<false> | DepthJoins1Select<true>;
'depth-joins-2': DepthJoins2Select<false> | DepthJoins2Select<true>; 'depth-joins-2': DepthJoins2Select<false> | DepthJoins2Select<true>;
'depth-joins-3': DepthJoins3Select<false> | DepthJoins3Select<true>; 'depth-joins-3': DepthJoins3Select<false> | DepthJoins3Select<true>;
users: UsersSelect<false> | UsersSelect<true>;
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>; 'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>; 'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>; 'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
@@ -132,6 +135,27 @@ export interface UserAuthOperations {
password: string; password: string;
}; };
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users".
*/
export interface User {
id: string;
posts?: {
docs?: (string | Post)[] | null;
hasNextPage?: boolean | null;
} | null;
updatedAt: string;
createdAt: string;
email: string;
resetPasswordToken?: string | null;
resetPasswordExpiration?: string | null;
salt?: string | null;
hash?: string | null;
loginAttempts?: number | null;
lockUntil?: string | null;
password?: string | null;
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "posts". * via the `definition` "posts".
@@ -139,6 +163,7 @@ export interface UserAuthOperations {
export interface Post { export interface Post {
id: string; id: string;
title?: string | null; title?: string | null;
author?: (string | null) | User;
/** /**
* Hides posts for the `filtered` join field in categories * Hides posts for the `filtered` join field in categories
*/ */
@@ -335,23 +360,6 @@ export interface Singular {
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users".
*/
export interface User {
id: string;
updatedAt: string;
createdAt: string;
email: string;
resetPasswordToken?: string | null;
resetPasswordExpiration?: string | null;
salt?: string | null;
hash?: string | null;
loginAttempts?: number | null;
lockUntil?: string | null;
password?: string | null;
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "versions". * via the `definition` "versions".
@@ -518,6 +526,10 @@ export interface DepthJoins3 {
export interface PayloadLockedDocument { export interface PayloadLockedDocument {
id: string; id: string;
document?: document?:
| ({
relationTo: 'users';
value: string | User;
} | null)
| ({ | ({
relationTo: 'posts'; relationTo: 'posts';
value: string | Post; value: string | Post;
@@ -585,10 +597,6 @@ export interface PayloadLockedDocument {
| ({ | ({
relationTo: 'depth-joins-3'; relationTo: 'depth-joins-3';
value: string | DepthJoins3; value: string | DepthJoins3;
} | null)
| ({
relationTo: 'users';
value: string | User;
} | null); } | null);
globalSlug?: string | null; globalSlug?: string | null;
user: { user: {
@@ -632,12 +640,29 @@ export interface PayloadMigration {
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users_select".
*/
export interface UsersSelect<T extends boolean = true> {
posts?: T;
updatedAt?: T;
createdAt?: T;
email?: T;
resetPasswordToken?: T;
resetPasswordExpiration?: T;
salt?: T;
hash?: T;
loginAttempts?: T;
lockUntil?: T;
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "posts_select". * via the `definition` "posts_select".
*/ */
export interface PostsSelect<T extends boolean = true> { export interface PostsSelect<T extends boolean = true> {
title?: T; title?: T;
author?: T;
isFiltered?: T; isFiltered?: T;
restrictedField?: T; restrictedField?: T;
upload?: T; upload?: T;
@@ -868,21 +893,6 @@ export interface DepthJoins3Select<T extends boolean = true> {
updatedAt?: T; updatedAt?: T;
createdAt?: T; createdAt?: T;
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users_select".
*/
export interface UsersSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
email?: T;
resetPasswordToken?: T;
resetPasswordExpiration?: T;
salt?: T;
hash?: T;
loginAttempts?: T;
lockUntil?: T;
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents_select". * via the `definition` "payload-locked-documents_select".