From 9415570241e7563dabef19f800a61a5bed93ba59 Mon Sep 17 00:00:00 2001 From: Philipp Melab Date: Sat, 9 Dec 2023 05:05:43 +0000 Subject: [PATCH] WIP --- apps/decap/src/collections/page.tsx | 13 ++++--- apps/decap/src/helpers/frame.tsx | 20 +++++++---- apps/website/src/preview/page.tsx | 34 +++++++++---------- packages/schema/src/operations/ListPages.gql | 10 ++++++ packages/schema/src/schema.graphql | 3 ++ .../components/Organisms/Header.stories.ts | 8 +---- 6 files changed, 50 insertions(+), 38 deletions(-) create mode 100644 packages/schema/src/operations/ListPages.gql diff --git a/apps/decap/src/collections/page.tsx b/apps/decap/src/collections/page.tsx index e20e94141..dc72a7e53 100644 --- a/apps/decap/src/collections/page.tsx +++ b/apps/decap/src/collections/page.tsx @@ -1,4 +1,4 @@ -import { ImageSource, PreviewPageQuery, Url } from '@custom/schema'; +import { ImageSource, Url, ViewPageQuery } from '@custom/schema'; import { BlockMarkupSource, BlockMediaSource, @@ -220,6 +220,7 @@ export function PagePreview({ const previewSourceData = parsed.success ? parsed.data : ({ + id: '', __typename: 'Page', title: '[Missing title]', path: '/preview' as Url, @@ -230,10 +231,10 @@ export function PagePreview({ // data into the exact shape of the query result expected by the // route. const data = useQuery( - PreviewPageQuery, + ViewPageQuery, { - previewPage: previewSourceData, - } satisfies PreviewPageQuery, + page: previewSourceData, + } satisfies ViewPageQuery, { id: '', rid: '', @@ -243,8 +244,6 @@ export function PagePreview({ ); return ( - - {data?.previewPage ? : null} - + {data?.page ? : null} ); } diff --git a/apps/decap/src/helpers/frame.tsx b/apps/decap/src/helpers/frame.tsx index bcba58e3e..49d75d532 100644 --- a/apps/decap/src/helpers/frame.tsx +++ b/apps/decap/src/helpers/frame.tsx @@ -1,4 +1,4 @@ -import { FrameQuery, registerOperator, Url } from '@custom/schema'; +import { FrameQuery, Locale, registerOperator, Url } from '@custom/schema'; import { NavigationItemSource } from '@custom/schema/source'; import { IntlProvider } from '@custom/ui/intl'; import { Frame } from '@custom/ui/routes/Frame'; @@ -18,12 +18,18 @@ const menuItems = (amount: number) => export function PreviewFrame({ children }: PropsWithChildren) { registerOperator( () => ({ - mainNavigation: { - items: menuItems(4), - }, - footerNavigation: { - items: menuItems(4), - }, + mainNavigation: [ + { + locale: Locale.En, + items: menuItems(4), + }, + ], + footerNavigation: [ + { + locale: Locale.En, + items: menuItems(4), + }, + ], }), FrameQuery, ); diff --git a/apps/website/src/preview/page.tsx b/apps/website/src/preview/page.tsx index 573427b51..6d3c10ed7 100644 --- a/apps/website/src/preview/page.tsx +++ b/apps/website/src/preview/page.tsx @@ -2,31 +2,31 @@ import { drupalOperator, - PreviewPageQuery, registerOperator, - useOperation, + ViewPageQuery, } from '@custom/schema'; import { Loading } from '@custom/ui/routes/Loading'; -import { Page } from '@custom/ui/routes/Page'; +// import { Page } from '@custom/ui/routes/Page'; import React from 'react'; -import { usePreviewParameters } from '../utils/preview'; +// import { usePreviewParameters } from '../utils/preview'; export default function PagePreview() { - const { nid, rid, lang } = usePreviewParameters(); + // const { nid, rid, lang } = usePreviewParameters(); registerOperator( drupalOperator(`${process.env.GATSBY_DRUPAL_URL}/graphql`), - PreviewPageQuery, + ViewPageQuery, ); - const data = useOperation( - PreviewPageQuery, - nid && rid && lang - ? { - id: nid, - rid: rid, - locale: lang, - } - : undefined, - ); - return data?.previewPage ? : ; + return ; + // const data = useOperation( + // PreviewPageQuery, + // nid && rid && lang + // ? { + // id: nid, + // rid: rid, + // locale: lang, + // } + // : undefined, + // ); + // return data?.previewPage ? : ; } diff --git a/packages/schema/src/operations/ListPages.gql b/packages/schema/src/operations/ListPages.gql new file mode 100644 index 000000000..412d8ed02 --- /dev/null +++ b/packages/schema/src/operations/ListPages.gql @@ -0,0 +1,10 @@ +fragment PageListEntry on Page { + id + locale +} + +query ListPages { + allPages { + ...PageListEntry + } +} diff --git a/packages/schema/src/schema.graphql b/packages/schema/src/schema.graphql index dc4c0b3f0..deea00138 100644 --- a/packages/schema/src/schema.graphql +++ b/packages/schema/src/schema.graphql @@ -63,6 +63,7 @@ A generic page. type Page implements ContentHubResultItem @entity(type: "node", bundle: "page") @type(id: "page") { + id: ID! @resolveEntityId locale: Locale! @resolveEntityLanguage path: Url! @resolveEntityPath @isPath title: String! @resolveProperty(path: "title.value") @@ -134,6 +135,8 @@ type Query { footerNavigation: [FooterNavigation] @gatsbyNodes(type: "FooterNavigation") + allPages: [Page] @gatsbyNodes(type: "Page") + page(id: ID!, rid: ID, locale: String!): Page @fetchEntity(type: "node", id: "$id", rid: "$rid", language: "$locale") diff --git a/packages/ui/src/components/Organisms/Header.stories.ts b/packages/ui/src/components/Organisms/Header.stories.ts index c98293c78..c030074c9 100644 --- a/packages/ui/src/components/Organisms/Header.stories.ts +++ b/packages/ui/src/components/Organisms/Header.stories.ts @@ -1,10 +1,4 @@ -import { - FrameQuery, - Locale, - Navigation, - NavigationItemFragment, - Url, -} from '@custom/schema'; +import { FrameQuery, Locale, Navigation, Url } from '@custom/schema'; import { Meta, StoryObj } from '@storybook/react'; import { userEvent, within } from '@storybook/testing-library';