Skip to content

Commit

Permalink
MERL-1004: fixed missing edit button in the Faust toolbar when previe…
Browse files Browse the repository at this point in the history
…wing a post (#1556)

* Added preview typeName query to edit functionality

Co-authored-by: Joe Fusco <[email protected]>
Co-authored-by: Blake Wilson <[email protected]>

* Fixed TypeScript error

* Create funny-starfishes-melt.md

* Update postID and postType to accept edge case of undefined

Co-authored-by: Blake Wilson <[email protected]>

* Fixed moderate severity vulnerability in css-tools

* Revert test for failing E2E toolbar.test.tsx

* Revert "Revert test for failing E2E toolbar.test.tsx"

This reverts commit d8e86df.

* Update .changeset/funny-starfishes-melt.md

Co-authored-by: John Parris <[email protected]>

* Test implementation of mocked useRouter call

* Added mocked useRouter call to additional tests

* Added databaseId to failing tests

* Added regression testing for edit button in preview

* Added databaseId to test

* Reordered tests to fix test package check on GitHub

* Merged updated package-lock.json

---------

Co-authored-by: Joe Fusco <[email protected]>
Co-authored-by: Blake Wilson <[email protected]>
Co-authored-by: Blake Wilson <[email protected]>
Co-authored-by: John Parris <[email protected]>
  • Loading branch information
5 people authored Sep 1, 2023
1 parent 031eee6 commit cf887d3
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 58 deletions.
5 changes: 5 additions & 0 deletions .changeset/funny-starfishes-melt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@faustwp/core": patch
---

Fixed bug where the "Edit Post" link was missing in the Faust Toolbar
180 changes: 132 additions & 48 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 13 additions & 7 deletions packages/faustwp-core/src/components/Toolbar/nodes/Edit.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { useRouter } from 'next/router.js';
import { SeedNode } from '../../../queries/seedQuery.js';
import { getAdminUrl } from '../../../lib/getAdminUrl.js';
import { ToolbarItem } from '../index.js';
Expand All @@ -8,17 +9,22 @@ type Props = {
};

export function Edit({ seedNode }: Props) {
if (
seedNode === undefined ||
seedNode?.isFrontPage ||
seedNode?.isPostsPage
) {
const {
query: { p, typeName },
} = useRouter();

if (seedNode?.isFrontPage || seedNode?.isPostsPage) {
return null;
}

// eslint-disable-next-line no-underscore-dangle
const postType = seedNode?.__typename || '';
const postId = seedNode?.databaseId || '';
// eslint-disable-next-line no-underscore-dangle
const postType = seedNode?.__typename ?? (typeName as string | undefined);
const postId = seedNode?.databaseId ?? (p as string | undefined);

if (!postId || !postType) {
return null;
}

const editPostUrl = getAdminUrl(`post.php?post=${postId}&action=edit`);

Expand Down
Loading

1 comment on commit cf887d3

@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 Atlas environment:

App Environment URL Build
faustjs canary https://hg…wered.com ✅ (logs)

Learn more about building on Atlas in our documentation.

Please sign in to comment.