Skip to content

Commit

Permalink
Merge branch 'chore/update-faustwp-core'
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json
#	wp-blocks/CoreQuote.js
#	wp-blocks/index.js
#	wp-templates/single-field_type.js
  • Loading branch information
jasonbahl committed Aug 27, 2024
2 parents 18f4781 + 833f7e0 commit 9a4309a
Show file tree
Hide file tree
Showing 11 changed files with 598 additions and 756 deletions.
6 changes: 3 additions & 3 deletions components/Layout.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { gql } from '@apollo/client'
import { flatListToHierarchical, useFaustQuery } from '@faustwp/core'
import { flatListToHierarchical } from '@faustwp/core'
import clsx from 'clsx'
import Link from 'next/link'
import { useCallback, useEffect, useState } from 'react'
Expand Down Expand Up @@ -79,8 +79,8 @@ function useTableOfContents(tableOfContents) {
return currentSection
}

export function Layout({ node, children, toc, title }) {
const { sitewideNotice, primaryMenuItems, footerMenuItems, docsSidebarMenuItems } = useFaustQuery(LAYOUT_QUERY);
export function Layout({ node, children, toc, title, sitewideNotice, primaryMenuItems, footerMenuItems, docsSidebarMenuItems }) {

let tableOfContents = toc && toc.length ? collectHeadings(toc) : []

const primaryNavigation = primaryMenuItems?.nodes
Expand Down
1,177 changes: 495 additions & 682 deletions package-lock.json

Large diffs are not rendered by default.

13 changes: 3 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,22 @@
"lint": "eslint . --ext js,jsx,ts,tsx",
"lint:fix": "eslint . --ext js,jsx,ts,tsx --fix",
"predev": "npm run generate",
"prebuild": "npm run generate",
"prebuild": "npm run generate && rm -rf public/sitemap* public/robots.txt",
"postbuild": "next-sitemap"
},
"dependencies": {
"@algolia/autocomplete-core": "^1.9.2",
"@apollo/client": "^3.7.7",
"@docsearch/css": "^3.5.2",
"@docsearch/react": "^3.5.2",
"@faustwp/blocks": "4.1.0",
"@faustwp/blocks": "^4.1.0",
"@faustwp/cli": "3.1.0",
"@faustwp/core": "3.1.0",
"@graphiql/react": "^0.20.2",
"@graphiql/toolkit": "^0.9.1",
"@headlessui/react": "^1.7.13",
"@markdoc/markdoc": "0.1.7",
"@markdoc/next.js": "^0.3.6",
"@next/env": "^14.2.5",
"@radix-ui/react-accordion": "^1.1.2",
"@radix-ui/react-context-menu": "^2.1.5",
"@radix-ui/react-dropdown-menu": "^2.0.6",
Expand All @@ -35,11 +34,9 @@
"@radix-ui/react-popover": "^1.0.7",
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-separator": "^1.0.2",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tabs": "^1.0.4",
"@sindresorhus/slugify": "^2.1.1",
"@tailwindcss/typography": "^0.5.8",
"@wordpress/style-engine": "^1.18.0",
"@wpengine/atlas-next": "^1.0.0",
"acorn": "^8.8.1",
"algoliasearch": "^4.14.2",
Expand All @@ -62,12 +59,10 @@
"next": "^13.1.6",
"next-sitemap": "^3.1.3",
"next-themes": "^0.2.1",
"node-fetch": "^2.6.1",
"postcss-focus-visible": "^6.0.4",
"postcss-import": "^14.1.0",
"prism-react-renderer": "^1.3.5",
"prismjs": "^1.29.0",
"prop-types": "^15.8.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-highlight-words": "^0.20.0",
Expand Down Expand Up @@ -102,9 +97,7 @@
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-tailwindcss": "^3.13.0",
"jest": "^29.7.0",
"postcss": "^8.4.41",
"prettier": "^3.0.3",
"prettier-plugin-tailwindcss": "^0.5.5",
"typescript": "^5.5.4"
"prettier-plugin-tailwindcss": "^0.5.5"
}
}
67 changes: 39 additions & 28 deletions wp-blocks/AcfFieldTypeConfigurationBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { snakeToPascalCase } from '@/lib/snakeToPascalCase';
import { stringToHash } from '@/lib/stringToHash';

function generateData(uniqueId, acfFieldType) {
if (!uniqueId || !acfFieldType) return {}; // Defensive check

return {
key: `my_field_group_${uniqueId}`,
title: `My Field Group with ${acfFieldType}`,
Expand All @@ -33,6 +35,8 @@ function generateData(uniqueId, acfFieldType) {
}

function generatePHPTabContent(data) {
if (!data || Object.keys(data).length === 0) return ''; // Defensive check

const phpString = `<?php
add_action( 'acf/include_fields', function() {
if ( ! function_exists( 'acf_add_local_field_group' ) ) {
Expand All @@ -48,59 +52,66 @@ add_action( 'acf/include_fields', function() {
}

function generateJSONTabContent(data) {
if (!data || Object.keys(data).length === 0) return ''; // Defensive check

const jsonString = JSON.stringify(data, null, 2);
return HighlightCode(jsonString, "json", [4, 5, 6, 7, 8, 9, 16, 17]);
}

function TabContent({ fieldTypeConfigurationBlockFields, uniqueId, format }) {
const { acfFieldType } = fieldTypeConfigurationBlockFields;

const acfFieldType = fieldTypeConfigurationBlockFields?.acfFieldType; // Defensive check

if (!acfFieldType || !uniqueId) return null; // Defensive check

const data = generateData(uniqueId, acfFieldType);

return format === 'php' ? generatePHPTabContent(data) : generateJSONTabContent(data);
}

export function AcfFieldTypeConfigurationBlock({ fieldTypeConfigurationBlockFields }) {
const { acfFieldType } = fieldTypeConfigurationBlockFields;
const acfFieldType = fieldTypeConfigurationBlockFields?.acfFieldType; // Defensive check
const [uniqueId, setUniqueId] = useState('');

useEffect(() => {
setUniqueId(stringToHash(acfFieldType));
if (acfFieldType) {
setUniqueId(stringToHash(acfFieldType));
}
}, [acfFieldType]);
if ( ! acfFieldType ) {

if (!acfFieldType) {
return (
<Card>
<CardHeader className="grid grid-cols-[1fr_110px] items-start space-y-2">
Field Type Config has not been configured for this field type
</CardHeader>
</Card>
<Card>
<CardHeader className="grid grid-cols-[1fr_110px] items-start space-y-2">
Field Type Config has not been configured for this field type
</CardHeader>
</Card>
);
};
}

const tabData = [
{ key: 'php', name: 'PHP' },
{ key: 'json', name: 'JSON' },
];

return (
<Card>
<CardHeader className="grid grid-cols-[1fr_110px] items-start gap-4 space-y-0 overflow-x-auto">
<Tabs defaultValue={tabData[0].key}>
<TabsList aria-label="Dynamic Tabs">
<Card>
<CardHeader className="grid grid-cols-[1fr_110px] items-start gap-4 space-y-0 overflow-x-auto">
<Tabs defaultValue={tabData[0].key}>
<TabsList aria-label="Dynamic Tabs">
{tabData.map(tab => (
<TabsTrigger key={tab.key} value={tab.key}>
{tab.name}
</TabsTrigger>
))}
</TabsList>
{tabData.map(tab => (
<TabsTrigger key={tab.key} value={tab.key}>
{tab.name}
</TabsTrigger>
<TabsContent key={tab.key} value={tab.key}>
<TabContent fieldTypeConfigurationBlockFields={fieldTypeConfigurationBlockFields} uniqueId={uniqueId} format={tab.key} />
</TabsContent>
))}
</TabsList>
{tabData.map(tab => (
<TabsContent key={tab.key} value={tab.key}>
<TabContent fieldTypeConfigurationBlockFields={fieldTypeConfigurationBlockFields} uniqueId={uniqueId} format={tab.key} />
</TabsContent>
))}
</Tabs>
</CardHeader>
</Card>
</Tabs>
</CardHeader>
</Card>
);
}

Expand Down
4 changes: 2 additions & 2 deletions wp-blocks/CoreQuote.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CoreBlocks } from "@faustwp/blocks";
const { CoreQuote: FaustCoreQuote } = CoreBlocks;

export function CoreQuote(props) {
return <FaustCoreQuote {...props} />;
return <FaustCoreQuote {...props} />;
}

CoreQuote.displayName = { ...FaustCoreQuote.displayName };
Expand Down Expand Up @@ -32,4 +32,4 @@ CoreQuote.fragments = {
}
}
`
};
};
2 changes: 1 addition & 1 deletion wp-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { AcfFieldTypeSettingsBlock } from './AcfFieldTypeSettingsBlock'
import { AcfGraphqlQuery } from './AcfGraphqlQuery'
import { CoreCode } from './CoreCode'
import { CoreHeading } from './CoreHeading'
import { CoreQuote } from './CoreQuote'
import { CoreQuote } from './CoreQuote.js'

const blocks = {
...CoreBlocks,
Expand Down
8 changes: 6 additions & 2 deletions wp-templates/IndexTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,15 @@ ${blocks.CoreHeading.fragments.entry}
`

export const IndexTemplate = () => {
const { node } = useFaustQuery(INDEX_TEMPLATE_QUERY)
const faustData = useFaustQuery(INDEX_TEMPLATE_QUERY)
const layoutData = useFaustQuery(LAYOUT_QUERY);

if (!node) {
if (!faustData?.node || !layoutData) {
return null
}

const node = faustData?.node;

const { editorBlocks } = node

let toc = []
Expand Down Expand Up @@ -108,6 +111,7 @@ export const IndexTemplate = () => {
title={node?.title ? node.title : 'WPGraphQL for ACF'}
toc={toc}
node={node}
{...layoutData}
>
{node?.modified && (
<div id="last-updated" className="text-sm text-gray-500">
Expand Down
22 changes: 10 additions & 12 deletions wp-templates/archive-field_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,19 @@ export const GET_POST_QUERY = gql`
`;

export const ArchiveFieldType = () => {
const { node } = useFaustQuery(GET_POST_QUERY);
const {
docsSidebarMenuItems,
footerMenuItems,
primaryMenuItems,
sitewideNotice
} = useFaustQuery(LAYOUT_ARCHIVE_QUERY);
const postData = useFaustQuery(GET_POST_QUERY);
const layoutData = useFaustQuery(LAYOUT_ARCHIVE_QUERY);

if (!node) {
if (!postData?.node) {
return null
}

if (!layoutData) {
return null
}

const { node } = postData;

return (
<>
<Head>
Expand All @@ -60,10 +61,7 @@ export const ArchiveFieldType = () => {
title={node?.label ? node.label : 'WPGraphQL for ACF'}
data={{
node,
docsSidebarMenuItems,
footerMenuItems,
primaryMenuItems,
sitewideNotice
...layoutData
}}
>
<FieldTypesList data={{ node }} />
Expand Down
24 changes: 13 additions & 11 deletions wp-templates/archive.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@ const ARCHIVE_QUERY = gql`
`

export const Archive = () => {
const { node } = useFaustQuery(ARCHIVE_QUERY);
const {
docsSidebarMenuItems,
footerMenuItems,
primaryMenuItems,
sitewideNotice
} = useFaustQuery(LAYOUT_ARCHIVE_QUERY);
const archiveData = useFaustQuery(ARCHIVE_QUERY);
const arciveLayoutData = useFaustQuery(LAYOUT_ARCHIVE_QUERY);

if ( !archiveData?.node ) {
return null
}

if ( ! arciveLayoutData ) {
return null
}

const { node } = archiveData;

return (
<>
Expand All @@ -44,10 +49,7 @@ export const Archive = () => {
title={node?.name ? node.name : 'Archive'}
data={{
node,
docsSidebarMenuItems,
footerMenuItems,
primaryMenuItems,
sitewideNotice
...arciveLayoutData
}}
>
{/* <pre>{JSON.stringify(props, null, 2)}</pre> */}
Expand Down
8 changes: 7 additions & 1 deletion wp-templates/front-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ const FRONT_PAGE_QUERY = gql`

export const FrontPage = () => {

const { frontPage } = useFaustQuery(FRONT_PAGE_QUERY);
const faustData = useFaustQuery(FRONT_PAGE_QUERY)

if (!faustData?.frontPage) {
return null
}

const frontPage = faustData.frontPage;

return (
<LayoutFrontPage>
Expand Down
23 changes: 19 additions & 4 deletions wp-templates/single-field_type.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,19 @@ ${blocks.CoreHeading.fragments.entry}
`

export const SingleFieldType = () => {
const { node } = useFaustQuery(SINGLE_ACF_FIELD_TYPE_QUERY)

if (!node) {
const acfFieldData = useFaustQuery(SINGLE_ACF_FIELD_TYPE_QUERY)
const layoutData = useFaustQuery(LAYOUT_QUERY);
if (!acfFieldData?.node) {
return null
}

if (!layoutData) {
return null
}

const { node } = acfFieldData;

const { title, editorBlocks } = node
let toc = []

Expand Down Expand Up @@ -111,13 +118,21 @@ export const SingleFieldType = () => {
childrenKey: 'innerBlocks',
})

console.log( {
blockList
})

return (
<>
<Head>
<title>{`${title} - WPGraphQL for ACF`}</title>
</Head>
<Layout node={node} toc={toc}>
<h1><EditPost post={node}>{title}</EditPost></h1>
<Layout
node={node}
toc={toc}
{...layoutData}
>
<EditPost post={node}><h1>{title}</h1></EditPost>
{node?.aCFFieldTypeCategories && node?.aCFFieldTypeCategories?.nodes && (
<div id="field-type-categories" className="my-2">
{node.aCFFieldTypeCategories.nodes.map((fieldTypeCategory) => (
Expand Down

1 comment on commit 9a4309a

@headless-platform-by-wp-engine

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check out the recent updates to your Headless WordPress environment:

App Environment URL Build
acf.wpgraphql.com main https://hb…wered.com ✅ (logs)

Learn more about building on Headless WordPress in our documentation.

Please sign in to comment.