From ced79be5916377f66e6a55ad39137ea48ceda7e2 Mon Sep 17 00:00:00 2001 From: James Mikrut Date: Wed, 13 Nov 2024 14:12:19 -0500 Subject: [PATCH] Chore/clean community (#9181) Cleans up _community test suite --- .../_community/collections/Posts/MyAvatar.tsx | 6 - .../collections/Posts/MyClientField.tsx | 9 - .../collections/Posts/MyComponent2.tsx | 6 - .../collections/Posts/MyServerField.tsx | 29 ---- test/_community/collections/Posts/index.ts | 90 +--------- test/_community/config.ts | 164 +----------------- test/_community/payload-types.ts | 155 ++++++++++------- 7 files changed, 96 insertions(+), 363 deletions(-) delete mode 100644 test/_community/collections/Posts/MyAvatar.tsx delete mode 100644 test/_community/collections/Posts/MyClientField.tsx delete mode 100644 test/_community/collections/Posts/MyComponent2.tsx delete mode 100644 test/_community/collections/Posts/MyServerField.tsx diff --git a/test/_community/collections/Posts/MyAvatar.tsx b/test/_community/collections/Posts/MyAvatar.tsx deleted file mode 100644 index a5837810a2..0000000000 --- a/test/_community/collections/Posts/MyAvatar.tsx +++ /dev/null @@ -1,6 +0,0 @@ -'use client' -import React from 'react' - -export const MyAvatar: React.FC = () => { - return

Some custom Avatar

-} diff --git a/test/_community/collections/Posts/MyClientField.tsx b/test/_community/collections/Posts/MyClientField.tsx deleted file mode 100644 index b6c13f5346..0000000000 --- a/test/_community/collections/Posts/MyClientField.tsx +++ /dev/null @@ -1,9 +0,0 @@ -'use client' -import type { TextFieldClientComponent } from 'payload' - -import { TextField } from '@payloadcms/ui' -import React from 'react' - -export const MyClientFieldComponent: TextFieldClientComponent = (props) => { - return -} diff --git a/test/_community/collections/Posts/MyComponent2.tsx b/test/_community/collections/Posts/MyComponent2.tsx deleted file mode 100644 index 5dd4476725..0000000000 --- a/test/_community/collections/Posts/MyComponent2.tsx +++ /dev/null @@ -1,6 +0,0 @@ -'use client' -import React from 'react' - -export const MyComponent2: React.FC = () => { - return

Some custom label2

-} diff --git a/test/_community/collections/Posts/MyServerField.tsx b/test/_community/collections/Posts/MyServerField.tsx deleted file mode 100644 index 2a27b83f2b..0000000000 --- a/test/_community/collections/Posts/MyServerField.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import type { TextFieldServerComponent } from 'payload' - -import { TextField } from '@payloadcms/ui' -import React from 'react' - -export const MyServerFieldComponent: TextFieldServerComponent = (props) => { - const { - clientField, - indexPath, - parentPath, - parentSchemaPath, - path, - schemaPath, - // siblingData, - // value, - // data - } = props - - return ( - - ) -} diff --git a/test/_community/collections/Posts/index.ts b/test/_community/collections/Posts/index.ts index 1cf70ab330..ffed2abbd1 100644 --- a/test/_community/collections/Posts/index.ts +++ b/test/_community/collections/Posts/index.ts @@ -5,99 +5,13 @@ export const postsSlug = 'posts' export const PostsCollection: CollectionConfig = { slug: postsSlug, admin: { - useAsTitle: 'text', + useAsTitle: 'title', }, fields: [ { - admin: { - components: { - Field: '/collections/Posts/MyClientField.js#MyClientFieldComponent', - }, - }, - name: 'text', - label: 'Client Text Field', + name: 'title', type: 'text', }, - { - admin: { - components: { - Field: '/collections/Posts/MyServerField.js#MyServerFieldComponent', - }, - }, - name: 'serverTextField', - type: 'text', - }, - { - name: 'relationToSelf', - type: 'relationship', - relationTo: postsSlug, - }, - { - name: 'myArray', - type: 'array', - fields: [ - { - admin: { - components: { - Field: '/collections/Posts/MyServerField.js#MyServerFieldComponent', - }, - }, - name: 'serverTextField', - type: 'text', - }, - { - admin: { - components: { - Field: '/collections/Posts/MyClientField.js#MyClientFieldComponent', - }, - }, - name: 'text', - label: 'Client Text Field', - type: 'text', - }, - ], - }, - // { - // name: 'richText', - // type: 'richText', - // }, - // { - // name: 'myBlocks', - // type: 'blocks', - // blocks: [ - // { - // slug: 'test', - // fields: [ - // { - // name: 'test', - // type: 'text', - // }, - // ], - // }, - // { - // slug: 'someBlock2', - // fields: [ - // { - // name: 'test2', - // type: 'text', - // }, - // ], - // }, - // ], - // }, - // { - // type: 'row', - // fields: [], - // }, - // { - // name: 'associatedMedia', - // type: 'upload', - // access: { - // create: () => true, - // update: () => false, - // }, - // relationTo: mediaSlug, - // }, ], versions: { drafts: true, diff --git a/test/_community/config.ts b/test/_community/config.ts index e7e8ca763e..ee1aee6e46 100644 --- a/test/_community/config.ts +++ b/test/_community/config.ts @@ -1,4 +1,4 @@ -// import { BlocksFeature, lexicalEditor } from '@payloadcms/richtext-lexical' +import { lexicalEditor } from '@payloadcms/richtext-lexical' import { fileURLToPath } from 'node:url' import path from 'path' @@ -7,148 +7,22 @@ import { devUser } from '../credentials.js' import { MediaCollection } from './collections/Media/index.js' import { PostsCollection, postsSlug } from './collections/Posts/index.js' import { MenuGlobal } from './globals/Menu/index.js' + const filename = fileURLToPath(import.meta.url) const dirname = path.dirname(filename) export default buildConfigWithDefaults({ // ...extend config here - collections: [ - PostsCollection, - { - slug: 'simple', - fields: [ - { - name: 'text', - type: 'text', - }, - ], - }, - ], + collections: [PostsCollection, MediaCollection], admin: { importMap: { baseDir: path.resolve(dirname), }, - avatar: { - Component: '/collections/Posts/MyAvatar.js#MyAvatar', - }, }, - editor: null, - // editor: lexicalEditor({ - // features: ({ defaultFeatures }) => [ - // ...defaultFeatures, - // BlocksFeature({ - // blocks: [ - // { - // admin: { - // components: { - // Label: '/collections/Posts/MyComponent2.js#MyComponent2', - // }, - // }, - // slug: 'test', - // fields: [ - // { - // name: 'test', - // type: 'text', - // }, - // ], - // }, - // { - // slug: 'someBlock2', - // fields: [ - // { - // name: 'test2', - // type: 'text', - // }, - // ], - // }, - // ], - // inlineBlocks: [ - // { - // admin: { - // components: { - // Label: '/collections/Posts/MyComponent2.js#MyComponent2', - // }, - // }, - // slug: 'test', - // fields: [ - // { - // name: 'test', - // type: 'text', - // }, - // ], - // }, - // { - // slug: 'someBlock2', - // fields: [ - // { - // name: 'test2', - // type: 'text', - // }, - // ], - // }, - // ], - // }), - // ], - // }), - cors: ['http://localhost:3000', 'http://localhost:3001'], + editor: lexicalEditor({}), globals: [ - MenuGlobal, - { - slug: 'custom-ts', - fields: [ - { - name: 'custom', - type: 'text', - typescriptSchema: [ - () => ({ - enum: ['hello', 'world'], - }), - ], - }, - { - name: 'withDefinitionsUsage', - type: 'text', - typescriptSchema: [ - () => ({ - type: 'array', - items: { - $ref: `#/definitions/objectWithNumber`, - }, - }), - ], - }, - { - name: 'json', - type: 'json', - jsonSchema: { - fileMatch: ['a://b/foo.json'], - schema: { - type: 'array', - items: { - type: 'object', - additionalProperties: false, - properties: { - id: { - type: 'string', - }, - name: { - type: 'string', - }, - age: { - type: 'integer', - }, - // Add other properties here - }, - required: ['id', 'name'], // Specify which properties are required - }, - }, - uri: 'a://b/foo.json', - }, - required: true, - }, - ], - }, // ...add more globals here + MenuGlobal, ], onInit: async (payload) => { await payload.create({ @@ -162,37 +36,11 @@ export default buildConfigWithDefaults({ await payload.create({ collection: postsSlug, data: { - text: 'example post', + title: 'example post', }, }) - - // // Create image - // const imageFilePath = path.resolve(dirname, '../uploads/image.png') - // const imageFile = await getFileByPath(imageFilePath) - - // await payload.create({ - // collection: 'media', - // data: {}, - // file: imageFile, - // }) }, typescript: { outputFile: path.resolve(dirname, 'payload-types.ts'), - schema: [ - ({ jsonSchema }) => { - jsonSchema.definitions.objectWithNumber = { - type: 'object', - additionalProperties: false, - properties: { - id: { - type: 'number', - required: true, - }, - }, - required: true, - } - return jsonSchema - }, - ], }, }) diff --git a/test/_community/payload-types.ts b/test/_community/payload-types.ts index a64d6bd9b6..129bd05dd7 100644 --- a/test/_community/payload-types.ts +++ b/test/_community/payload-types.ts @@ -12,7 +12,7 @@ export interface Config { }; collections: { posts: Post; - simple: Simple; + media: Media; users: User; 'payload-locked-documents': PayloadLockedDocument; 'payload-preferences': PayloadPreference; @@ -21,7 +21,7 @@ export interface Config { collectionsJoins: {}; collectionsSelect: { posts: PostsSelect | PostsSelect; - simple: SimpleSelect | SimpleSelect; + media: MediaSelect | MediaSelect; users: UsersSelect | UsersSelect; 'payload-locked-documents': PayloadLockedDocumentsSelect | PayloadLockedDocumentsSelect; 'payload-preferences': PayloadPreferencesSelect | PayloadPreferencesSelect; @@ -32,11 +32,9 @@ export interface Config { }; globals: { menu: Menu; - 'custom-ts': CustomT; }; globalsSelect: { menu: MenuSelect | MenuSelect; - 'custom-ts': CustomTsSelect | CustomTsSelect; }; locale: null; user: User & { @@ -71,29 +69,54 @@ export interface UserAuthOperations { */ export interface Post { id: string; - text?: string | null; - serverTextField?: string | null; - relationToSelf?: (string | null) | Post; - myArray?: - | { - serverTextField?: string | null; - text?: string | null; - id?: string | null; - }[] - | null; + title?: string | null; updatedAt: string; createdAt: string; _status?: ('draft' | 'published') | null; } /** * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "simple". + * via the `definition` "media". */ -export interface Simple { +export interface Media { id: string; - text?: string | null; updatedAt: string; createdAt: string; + url?: string | null; + thumbnailURL?: string | null; + filename?: string | null; + mimeType?: string | null; + filesize?: number | null; + width?: number | null; + height?: number | null; + focalX?: number | null; + focalY?: number | null; + sizes?: { + thumbnail?: { + url?: string | null; + width?: number | null; + height?: number | null; + mimeType?: string | null; + filesize?: number | null; + filename?: string | null; + }; + medium?: { + url?: string | null; + width?: number | null; + height?: number | null; + mimeType?: string | null; + filesize?: number | null; + filename?: string | null; + }; + large?: { + url?: string | null; + width?: number | null; + height?: number | null; + mimeType?: string | null; + filesize?: number | null; + filename?: string | null; + }; + }; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -124,8 +147,8 @@ export interface PayloadLockedDocument { value: string | Post; } | null) | ({ - relationTo: 'simple'; - value: string | Simple; + relationTo: 'media'; + value: string | Media; } | null) | ({ relationTo: 'users'; @@ -178,28 +201,61 @@ export interface PayloadMigration { * via the `definition` "posts_select". */ export interface PostsSelect { - text?: T; - serverTextField?: T; - relationToSelf?: T; - myArray?: - | T - | { - serverTextField?: T; - text?: T; - id?: T; - }; + title?: T; updatedAt?: T; createdAt?: T; _status?: T; } /** * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "simple_select". + * via the `definition` "media_select". */ -export interface SimpleSelect { - text?: T; +export interface MediaSelect { updatedAt?: T; createdAt?: T; + url?: T; + thumbnailURL?: T; + filename?: T; + mimeType?: T; + filesize?: T; + width?: T; + height?: T; + focalX?: T; + focalY?: T; + sizes?: + | T + | { + thumbnail?: + | T + | { + url?: T; + width?: T; + height?: T; + mimeType?: T; + filesize?: T; + filename?: T; + }; + medium?: + | T + | { + url?: T; + width?: T; + height?: T; + mimeType?: T; + filesize?: T; + filename?: T; + }; + large?: + | T + | { + url?: T; + width?: T; + height?: T; + mimeType?: T; + filesize?: T; + filename?: T; + }; + }; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -258,29 +314,6 @@ export interface Menu { updatedAt?: string | null; createdAt?: string | null; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "custom-ts". - */ -export interface CustomT { - id: string; - custom?: 'hello' | 'world'; - withDefinitionsUsage?: ObjectWithNumber[]; - json: { - id: string; - name: string; - age?: number; - }[]; - updatedAt?: string | null; - createdAt?: string | null; -} -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "objectWithNumber". - */ -export interface ObjectWithNumber { - id?: number; -} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "menu_select". @@ -291,18 +324,6 @@ export interface MenuSelect { createdAt?: T; globalType?: T; } -/** - * This interface was referenced by `Config`'s JSON-Schema - * via the `definition` "custom-ts_select". - */ -export interface CustomTsSelect { - custom?: T; - withDefinitionsUsage?: T; - json?: T; - updatedAt?: T; - createdAt?: T; - globalType?: T; -} /** * This interface was referenced by `Config`'s JSON-Schema * via the `definition` "auth".