From 5eaea1c7f12eb773c8f479dc0a28bb5621047305 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 18 Mar 2024 14:27:56 -0400 Subject: [PATCH] chore: moves live preview test suite into main app folder --- .vscode/launch.json | 7 + .../(pages)/[slug]/page.client.tsx | 12 +- .../live-preview}/(pages)/[slug]/page.tsx | 11 +- .../(pages)/posts/[slug]/page.client.tsx | 12 +- .../(pages)/posts/[slug]/page.tsx | 10 +- .../app => app/live-preview}/_api/fetchDoc.ts | 10 +- .../live-preview}/_api/fetchDocs.ts | 8 +- .../live-preview}/_api/fetchFooter.ts | 6 +- .../live-preview}/_api/fetchHeader.ts | 6 +- .../live-preview}/_api/serverURL.ts | 0 .../_blocks/ArchiveBlock/index.module.scss | 0 .../_blocks/ArchiveBlock/index.tsx | 8 +- .../_blocks/ArchiveBlock/types.ts | 2 +- .../_blocks/CallToAction/index.module.scss | 0 .../_blocks/CallToAction/index.tsx | 10 +- .../_blocks/Content/index.module.scss | 0 .../live-preview}/_blocks/Content/index.tsx | 8 +- .../_blocks/MediaBlock/index.module.scss | 0 .../_blocks/MediaBlock/index.tsx | 10 +- .../_blocks/RelatedPosts/index.module.scss | 0 .../_blocks/RelatedPosts/index.tsx | 8 +- .../_blocks/Relationships/index.module.scss | 0 .../_blocks/Relationships/index.tsx | 6 +- .../BackgroundColor/index.module.scss | 0 .../_components/BackgroundColor/index.tsx | 0 .../_components/Blocks/index.tsx | 24 +- .../_components/Button/index.module.scss | 0 .../_components/Button/index.tsx | 4 +- .../_components/Card/index.module.scss | 0 .../live-preview}/_components/Card/index.tsx | 10 +- .../_components/Chevron/index.tsx | 0 .../PopulateByCollection/index.module.scss | 0 .../PopulateByCollection/index.tsx | 18 +- .../PopulateBySelection/index.module.scss | 0 .../PopulateBySelection/index.tsx | 6 +- .../_components/CollectionArchive/index.tsx | 6 +- .../_components/Footer/index.module.scss | 0 .../_components/Footer/index.tsx | 10 +- .../_components/Gutter/index.module.scss | 0 .../_components/Gutter/index.tsx | 0 .../_components/Header/Nav/index.module.scss | 0 .../_components/Header/Nav/index.tsx | 4 +- .../_components/Header/index.module.scss | 0 .../_components/Header/index.tsx | 16 +- .../live-preview}/_components/Hero/index.tsx | 6 +- .../live-preview}/_components/Link/index.tsx | 12 +- .../_components/Media/Image/index.module.scss | 0 .../_components/Media/Image/index.tsx | 15 +- .../_components/Media/Video/index.module.scss | 0 .../_components/Media/Video/index.tsx | 4 +- .../live-preview}/_components/Media/index.tsx | 6 +- .../live-preview}/_components/Media/types.ts | 0 .../_components/PageRange/index.module.scss | 0 .../_components/PageRange/index.tsx | 0 .../_components/Pagination/index.module.scss | 0 .../_components/Pagination/index.tsx | 2 +- .../_components/RichText/index.module.scss | 0 .../_components/RichText/index.tsx | 4 +- .../_components/RichText/serializeLexical.tsx | 6 +- .../_components/RichText/serializeSlate.tsx | 4 +- .../VerticalPadding/index.module.scss | 0 .../_components/VerticalPadding/index.tsx | 0 .../app => app/live-preview}/_css/app.scss | 0 .../app => app/live-preview}/_css/colors.scss | 0 .../app => app/live-preview}/_css/common.scss | 0 .../live-preview}/_css/queries.scss | 0 .../app => app/live-preview}/_css/type.scss | 0 .../_heros/HighImpact/index.module.scss | 0 .../live-preview}/_heros/HighImpact/index.tsx | 8 +- .../_heros/LowImpact/index.module.scss | 0 .../live-preview}/_heros/LowImpact/index.tsx | 8 +- .../_heros/PostHero/index.module.scss | 0 .../live-preview}/_heros/PostHero/index.tsx | 16 +- .../_utilities/formatDateTime.ts | 0 .../live-preview}/_utilities/toKebabCase.ts | 0 .../app => app/live-preview}/cssVariables.js | 3 +- .../app => app/live-preview}/layout.tsx | 6 +- .../app => app/live-preview}/not-found.tsx | 4 +- app/live-preview/page.tsx | 3 + next.config.mjs | 3 + .../src/views/LivePreview/Context/index.tsx | 48 +- .../src/views/LivePreview/index.client.tsx | 90 ++-- test/live-preview/next-app/.gitignore | 35 -- test/live-preview/next-app/README.md | 36 -- test/live-preview/next-app/app/page.tsx | 3 - test/live-preview/next-app/next.config.js | 13 - test/live-preview/next-app/package.json | 24 - test/live-preview/next-app/payload-types.ts | 459 ----------------- test/live-preview/next-app/pnpm-lock.yaml | 462 ------------------ test/live-preview/next-app/tsconfig.json | 33 -- test/live-preview/seed/posts-page.ts | 2 +- .../utilities/formatLivePreviewURL.ts | 2 +- tsconfig.json | 6 + 93 files changed, 276 insertions(+), 1279 deletions(-) rename {test/live-preview/next-app/app => app/live-preview}/(pages)/[slug]/page.client.tsx (67%) rename {test/live-preview/next-app/app => app/live-preview}/(pages)/[slug]/page.tsx (62%) rename {test/live-preview/next-app/app => app/live-preview}/(pages)/posts/[slug]/page.client.tsx (83%) rename {test/live-preview/next-app/app => app/live-preview}/(pages)/posts/[slug]/page.tsx (66%) rename {test/live-preview/next-app/app => app/live-preview}/_api/fetchDoc.ts (78%) rename {test/live-preview/next-app/app => app/live-preview}/_api/fetchDocs.ts (67%) rename {test/live-preview/next-app/app => app/live-preview}/_api/fetchFooter.ts (82%) rename {test/live-preview/next-app/app => app/live-preview}/_api/fetchHeader.ts (82%) rename {test/live-preview/next-app/app => app/live-preview}/_api/serverURL.ts (100%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/ArchiveBlock/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/ArchiveBlock/index.tsx (83%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/ArchiveBlock/types.ts (59%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/CallToAction/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/CallToAction/index.tsx (78%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/Content/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/Content/index.tsx (78%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/MediaBlock/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/MediaBlock/index.tsx (75%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/RelatedPosts/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/RelatedPosts/index.tsx (83%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/Relationships/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_blocks/Relationships/index.tsx (96%) rename {test/live-preview/next-app/app => app/live-preview}/_components/BackgroundColor/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/BackgroundColor/index.tsx (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Blocks/index.tsx (76%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Button/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Button/index.tsx (91%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Card/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Card/index.tsx (89%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Chevron/index.tsx (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/CollectionArchive/PopulateByCollection/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/CollectionArchive/PopulateByCollection/index.tsx (92%) rename {test/live-preview/next-app/app => app/live-preview}/_components/CollectionArchive/PopulateBySelection/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/CollectionArchive/PopulateBySelection/index.tsx (90%) rename {test/live-preview/next-app/app => app/live-preview}/_components/CollectionArchive/index.tsx (94%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Footer/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Footer/index.tsx (79%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Gutter/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Gutter/index.tsx (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Header/Nav/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Header/Nav/index.tsx (72%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Header/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Header/index.tsx (63%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Hero/index.tsx (63%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Link/index.tsx (76%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Media/Image/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Media/Image/index.tsx (78%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Media/Video/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Media/Video/index.tsx (89%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Media/index.tsx (83%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Media/types.ts (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/PageRange/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/PageRange/index.tsx (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Pagination/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/Pagination/index.tsx (96%) rename {test/live-preview/next-app/app => app/live-preview}/_components/RichText/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/RichText/index.tsx (85%) rename {test/live-preview/next-app/app => app/live-preview}/_components/RichText/serializeLexical.tsx (95%) rename {test/live-preview/next-app/app => app/live-preview}/_components/RichText/serializeSlate.tsx (97%) rename {test/live-preview/next-app/app => app/live-preview}/_components/VerticalPadding/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_components/VerticalPadding/index.tsx (100%) rename {test/live-preview/next-app/app => app/live-preview}/_css/app.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_css/colors.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_css/common.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_css/queries.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_css/type.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_heros/HighImpact/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_heros/HighImpact/index.tsx (74%) rename {test/live-preview/next-app/app => app/live-preview}/_heros/LowImpact/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_heros/LowImpact/index.tsx (69%) rename {test/live-preview/next-app/app => app/live-preview}/_heros/PostHero/index.module.scss (100%) rename {test/live-preview/next-app/app => app/live-preview}/_heros/PostHero/index.tsx (75%) rename {test/live-preview/next-app/app => app/live-preview}/_utilities/formatDateTime.ts (100%) rename {test/live-preview/next-app/app => app/live-preview}/_utilities/toKebabCase.ts (100%) rename {test/live-preview/next-app/app => app/live-preview}/cssVariables.js (94%) rename {test/live-preview/next-app/app => app/live-preview}/layout.tsx (74%) rename {test/live-preview/next-app/app => app/live-preview}/not-found.tsx (70%) create mode 100644 app/live-preview/page.tsx delete mode 100644 test/live-preview/next-app/.gitignore delete mode 100644 test/live-preview/next-app/README.md delete mode 100644 test/live-preview/next-app/app/page.tsx delete mode 100644 test/live-preview/next-app/next.config.js delete mode 100644 test/live-preview/next-app/package.json delete mode 100644 test/live-preview/next-app/payload-types.ts delete mode 100644 test/live-preview/next-app/pnpm-lock.yaml delete mode 100644 test/live-preview/next-app/tsconfig.json diff --git a/.vscode/launch.json b/.vscode/launch.json index cbace349c8..a0270193ac 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -16,6 +16,13 @@ "request": "launch", "type": "node-terminal" }, + { + "command": "pnpm run dev live-preview -- --no-turbo", + "cwd": "${workspaceFolder}", + "name": "Run Dev Live Preview", + "request": "launch", + "type": "node-terminal" + }, { "command": "pnpm run dev plugin-cloud-storage", "cwd": "${workspaceFolder}", diff --git a/test/live-preview/next-app/app/(pages)/[slug]/page.client.tsx b/app/live-preview/(pages)/[slug]/page.client.tsx similarity index 67% rename from test/live-preview/next-app/app/(pages)/[slug]/page.client.tsx rename to app/live-preview/(pages)/[slug]/page.client.tsx index 34137c1724..d44ed30fd3 100644 --- a/test/live-preview/next-app/app/(pages)/[slug]/page.client.tsx +++ b/app/live-preview/(pages)/[slug]/page.client.tsx @@ -1,13 +1,13 @@ 'use client' -import type { Page as PageType } from '@/payload-types' - -import { PAYLOAD_SERVER_URL } from '@/app/_api/serverURL' -import { Blocks } from '@/app/_components/Blocks' -import { Hero } from '@/app/_components/Hero' +import { useLivePreview } from '@payloadcms/live-preview-react' import React from 'react' -import { useLivePreview } from '../../../../../../packages/live-preview-react/src' +import type { Page as PageType } from '../../../../test/live-preview/payload-types.js' + +import { PAYLOAD_SERVER_URL } from '../../_api/serverURL.js' +import { Blocks } from '../../_components/Blocks/index.js' +import { Hero } from '../../_components/Hero/index.js' export const PageClient: React.FC<{ page: PageType diff --git a/test/live-preview/next-app/app/(pages)/[slug]/page.tsx b/app/live-preview/(pages)/[slug]/page.tsx similarity index 62% rename from test/live-preview/next-app/app/(pages)/[slug]/page.tsx rename to app/live-preview/(pages)/[slug]/page.tsx index 51292c77e2..11d1bc8d18 100644 --- a/test/live-preview/next-app/app/(pages)/[slug]/page.tsx +++ b/app/live-preview/(pages)/[slug]/page.tsx @@ -1,12 +1,13 @@ -import { fetchDoc } from '@/app/_api/fetchDoc' -import { fetchDocs } from '@/app/_api/fetchDocs' -import { notFound } from 'next/navigation' +import { notFound } from 'next/navigation.js' import React from 'react' -import type { Page } from '../../../payload-types' +import type { Page } from '../../../../test/live-preview/payload-types.js' -import { PageClient } from './page.client' +import { fetchDoc } from '../../_api/fetchDoc.js' +import { fetchDocs } from '../../_api/fetchDocs.js' +import { PageClient } from './page.client.js' +// eslint-disable-next-line no-restricted-exports export default async function Page({ params: { slug = 'home' } }) { let page: Page | null = null diff --git a/test/live-preview/next-app/app/(pages)/posts/[slug]/page.client.tsx b/app/live-preview/(pages)/posts/[slug]/page.client.tsx similarity index 83% rename from test/live-preview/next-app/app/(pages)/posts/[slug]/page.client.tsx rename to app/live-preview/(pages)/posts/[slug]/page.client.tsx index 0d8af42139..e5c52f8048 100644 --- a/test/live-preview/next-app/app/(pages)/posts/[slug]/page.client.tsx +++ b/app/live-preview/(pages)/posts/[slug]/page.client.tsx @@ -1,13 +1,13 @@ 'use client' -import type { Post as PostType } from '@/payload-types' - -import { PAYLOAD_SERVER_URL } from '@/app/_api/serverURL' -import { Blocks } from '@/app/_components/Blocks' -import { PostHero } from '@/app/_heros/PostHero' +import { useLivePreview } from '@payloadcms/live-preview-react' import React from 'react' -import { useLivePreview } from '../../../../../../../packages/live-preview-react/src' +import type { Post as PostType } from '../../../../../test/live-preview/payload-types.js' + +import { PAYLOAD_SERVER_URL } from '../../../_api/serverURL.js' +import { Blocks } from '../../../_components/Blocks/index.js' +import { PostHero } from '../../../_heros/PostHero/index.js' export const PostClient: React.FC<{ post: PostType diff --git a/test/live-preview/next-app/app/(pages)/posts/[slug]/page.tsx b/app/live-preview/(pages)/posts/[slug]/page.tsx similarity index 66% rename from test/live-preview/next-app/app/(pages)/posts/[slug]/page.tsx rename to app/live-preview/(pages)/posts/[slug]/page.tsx index 08fe0cbee4..91053d2934 100644 --- a/test/live-preview/next-app/app/(pages)/posts/[slug]/page.tsx +++ b/app/live-preview/(pages)/posts/[slug]/page.tsx @@ -1,11 +1,11 @@ -import { notFound } from 'next/navigation' +import { notFound } from 'next/navigation.js' import React from 'react' -import type { Post } from '../../../../payload-types' +import type { Post } from '../../../../../test/live-preview/payload-types.js' -import { fetchDoc } from '../../../_api/fetchDoc' -import { fetchDocs } from '../../../_api/fetchDocs' -import { PostClient } from './page.client' +import { fetchDoc } from '../../../_api/fetchDoc.js' +import { fetchDocs } from '../../../_api/fetchDocs.js' +import { PostClient } from './page.client.js' export default async function Post({ params: { slug = '' } }) { let post: Post | null = null diff --git a/test/live-preview/next-app/app/_api/fetchDoc.ts b/app/live-preview/_api/fetchDoc.ts similarity index 78% rename from test/live-preview/next-app/app/_api/fetchDoc.ts rename to app/live-preview/_api/fetchDoc.ts index e607ec8e22..d1dc1c2a3a 100644 --- a/test/live-preview/next-app/app/_api/fetchDoc.ts +++ b/app/live-preview/_api/fetchDoc.ts @@ -1,16 +1,14 @@ import QueryString from 'qs' -import type { Config } from '../../payload-types' - -import { PAYLOAD_SERVER_URL } from './serverURL' +import { PAYLOAD_SERVER_URL } from './serverURL.js' export const fetchDoc = async (args: { - collection: keyof Config['collections'] + collection: string depth?: number id?: string slug?: string }): Promise => { - const { collection, slug, id, depth = 2 } = args || {} + const { id, slug, collection, depth = 2 } = args || {} const queryString = QueryString.stringify( { @@ -21,11 +19,11 @@ export const fetchDoc = async (args: { ) const doc: T = await fetch(`${PAYLOAD_SERVER_URL}/api/${collection}${queryString}`, { - method: 'GET', cache: 'no-store', headers: { 'Content-Type': 'application/json', }, + method: 'GET', }) ?.then((res) => res.json()) ?.then((res) => { diff --git a/test/live-preview/next-app/app/_api/fetchDocs.ts b/app/live-preview/_api/fetchDocs.ts similarity index 67% rename from test/live-preview/next-app/app/_api/fetchDocs.ts rename to app/live-preview/_api/fetchDocs.ts index 4d21de0218..104f5e2586 100644 --- a/test/live-preview/next-app/app/_api/fetchDocs.ts +++ b/app/live-preview/_api/fetchDocs.ts @@ -1,14 +1,12 @@ -import type { Config } from '../../payload-types' +import { PAYLOAD_SERVER_URL } from './serverURL.js' -import { PAYLOAD_SERVER_URL } from './serverURL' - -export const fetchDocs = async (collection: keyof Config['collections']): Promise => { +export const fetchDocs = async (collection: string): Promise => { const docs: T[] = await fetch(`${PAYLOAD_SERVER_URL}/api/${collection}?depth=0&limit=100`, { - method: 'GET', cache: 'no-store', headers: { 'Content-Type': 'application/json', }, + method: 'GET', }) ?.then((res) => res.json()) ?.then((res) => { diff --git a/test/live-preview/next-app/app/_api/fetchFooter.ts b/app/live-preview/_api/fetchFooter.ts similarity index 82% rename from test/live-preview/next-app/app/_api/fetchFooter.ts rename to app/live-preview/_api/fetchFooter.ts index b245212563..26b531b620 100644 --- a/test/live-preview/next-app/app/_api/fetchFooter.ts +++ b/app/live-preview/_api/fetchFooter.ts @@ -1,16 +1,16 @@ -import type { Footer } from '../../payload-types' +import type { Footer } from '../../../test/live-preview/payload-types.js' -import { PAYLOAD_SERVER_URL } from './serverURL' +import { PAYLOAD_SERVER_URL } from './serverURL.js' export async function fetchFooter(): Promise