From 2f66bdc2dc94aedfb710602b65cf325ab92afea0 Mon Sep 17 00:00:00 2001 From: Sasha <64744993+r1tsuu@users.noreply.github.com> Date: Wed, 29 Jan 2025 19:52:22 +0200 Subject: [PATCH] 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. --- packages/ui/src/fields/Join/index.tsx | 10 +++- test/joins/collections/Posts.ts | 5 ++ test/joins/config.ts | 13 ++++ test/joins/e2e.spec.ts | 7 +++ test/joins/payload-types.ts | 86 +++++++++++++++------------ 5 files changed, 80 insertions(+), 41 deletions(-) diff --git a/packages/ui/src/fields/Join/index.tsx b/packages/ui/src/fields/Join/index.tsx index 28780706f..6f8c0000d 100644 --- a/packages/ui/src/fields/Join/index.tsx +++ b/packages/ui/src/fields/Join/index.tsx @@ -161,18 +161,22 @@ const JoinFieldComponent: JoinFieldClientComponent = (props) => { } return where - }, [docID, field.targetField.relationTo, field.where, on, docConfig.slug]) + }, [docID, field.targetField.relationTo, field.where, on, docConfig?.slug]) const initialDrawerData = useMemo(() => { const relatedCollection = getEntityConfig({ collectionSlug: field.collection }) return getInitialDrawerData({ - collectionSlug: docConfig.slug, + collectionSlug: docConfig?.slug, docID, fields: relatedCollection.fields, 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 (
{ await expect(rows).toHaveCount(1) 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() + }) }) diff --git a/test/joins/payload-types.ts b/test/joins/payload-types.ts index 5281144b9..315ce77fe 100644 --- a/test/joins/payload-types.ts +++ b/test/joins/payload-types.ts @@ -11,6 +11,7 @@ export interface Config { users: UserAuthOperations; }; collections: { + users: User; posts: Post; categories: Category; 'hidden-posts': HiddenPost; @@ -28,12 +29,14 @@ export interface Config { 'depth-joins-1': DepthJoins1; 'depth-joins-2': DepthJoins2; 'depth-joins-3': DepthJoins3; - users: User; 'payload-locked-documents': PayloadLockedDocument; 'payload-preferences': PayloadPreference; 'payload-migrations': PayloadMigration; }; collectionsJoins: { + users: { + posts: 'posts'; + }; categories: { relatedPosts: 'posts'; hasManyPosts: 'posts'; @@ -78,6 +81,7 @@ export interface Config { }; }; collectionsSelect: { + users: UsersSelect | UsersSelect; posts: PostsSelect | PostsSelect; categories: CategoriesSelect | CategoriesSelect; 'hidden-posts': HiddenPostsSelect | HiddenPostsSelect; @@ -95,7 +99,6 @@ export interface Config { 'depth-joins-1': DepthJoins1Select | DepthJoins1Select; 'depth-joins-2': DepthJoins2Select | DepthJoins2Select; 'depth-joins-3': DepthJoins3Select | DepthJoins3Select; - users: UsersSelect | UsersSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect; 'payload-migrations': PayloadMigrationsSelect | PayloadMigrationsSelect; @@ -132,6 +135,27 @@ export interface UserAuthOperations { 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 * via the `definition` "posts". @@ -139,6 +163,7 @@ export interface UserAuthOperations { export interface Post { id: string; title?: string | null; + author?: (string | null) | User; /** * Hides posts for the `filtered` join field in categories */ @@ -335,23 +360,6 @@ export interface Singular { updatedAt: 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 * via the `definition` "versions". @@ -518,6 +526,10 @@ export interface DepthJoins3 { export interface PayloadLockedDocument { id: string; document?: + | ({ + relationTo: 'users'; + value: string | User; + } | null) | ({ relationTo: 'posts'; value: string | Post; @@ -585,10 +597,6 @@ export interface PayloadLockedDocument { | ({ relationTo: 'depth-joins-3'; value: string | DepthJoins3; - } | null) - | ({ - relationTo: 'users'; - value: string | User; } | null); globalSlug?: string | null; user: { @@ -632,12 +640,29 @@ export interface PayloadMigration { updatedAt: string; createdAt: string; } +/** + * This interface was referenced by `Config`'s JSON-Schema + * via the `definition` "users_select". + */ +export interface UsersSelect { + 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 * via the `definition` "posts_select". */ export interface PostsSelect { title?: T; + author?: T; isFiltered?: T; restrictedField?: T; upload?: T; @@ -868,21 +893,6 @@ export interface DepthJoins3Select { updatedAt?: T; createdAt?: T; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "users_select". - */ -export interface UsersSelect { - 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 * via the `definition` "payload-locked-documents_select".