Skip to content

Hide Pages Manager “Page Type” filter when only default page types exist#797

Merged
surajair merged 4 commits intodevfrom
copilot/fix-152845344-752521913-ac2f6c82-3f4c-4e73-9e53-db8ab73fd0b4
Mar 10, 2026
Merged

Hide Pages Manager “Page Type” filter when only default page types exist#797
surajair merged 4 commits intodevfrom
copilot/fix-152845344-752521913-ac2f6c82-3f4c-4e73-9e53-db8ab73fd0b4

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 9, 2026

Pages Manager currently shows a “Page Type” filter even when only built-in types are available. This updates rendering logic to show the filter only when at least one custom page type is registered, while always treating page and global as defaults.

  • Pages Manager filter visibility

    • Updated PageTypeSelector to compute whether any custom page type exists (key not in ["page", "global"]).
    • Short-circuits rendering of the selector when no custom types are present.
  • Filter state guardrail

    • Added an effect to normalize selectedPageType to "all" when custom types are absent, preventing stale non-default filter state.
  • Focused coverage for visibility behavior

    • Added component tests for:
      • hidden selector when only page + global exist
      • visible selector when any custom type exists
const hasCustomPageTypes = useMemo(
  () => pageTypes.some((pageType: ChaiPageType) => !["page", "global"].includes(get(pageType, "key", ""))),
  [pageTypes],
);

if (!hasCustomPageTypes) return null;
Original prompt

This section details on the original issue you should resolve

<issue_title>Hide "Page Type" dropdown in Pages Manager if only default types exist</issue_title>
<issue_description>Feature Request

In the Pages Manager UI, the "Page Type" dropdown should be hidden if there are no custom page types registered. The dropdown is only relevant when there are more than the default page types, which are "page" and "global". If only these defaults exist, the dropdown should be removed to simplify the UI and reduce user confusion.

Acceptance Criteria:

  • The "Page Type" dropdown is not displayed unless there is at least one custom page type registered.
  • "page" and "global" are always considered default types.
  • UI logic checks for custom types before rendering the dropdown.

Notes:

  • This change improves user experience and keeps the Pages Manager interface cleaner.
  • Please ensure proper testing for cases with and without custom page types.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@vercel
Copy link
Copy Markdown

vercel Bot commented Mar 9, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sdk Ready Ready Preview, Comment Mar 10, 2026 5:14am

Request Review

Co-authored-by: surajair <9153560+surajair@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 9, 2026

Deploying sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: d732833
Status: ✅  Deploy successful!
Preview URL: https://a4cbff22.sdk-8n4.pages.dev
Branch Preview URL: https://copilot-fix-152845344-752521.sdk-8n4.pages.dev

View logs

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Mar 9, 2026

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
sdk-nextjs d732833 Mar 10 2026, 05:13 AM

Co-authored-by: surajair <9153560+surajair@users.noreply.github.com>
Copilot AI changed the title [WIP] Hide "Page Type" dropdown in Pages Manager if only default types exist Hide Pages Manager “Page Type” filter when only default page types exist Mar 9, 2026
@surajair surajair added the qa Test the issue/PR label Mar 9, 2026
@surajair surajair marked this pull request as ready for review March 9, 2026 17:07
Copilot AI review requested due to automatic review settings March 9, 2026 17:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR hides the "Page Type" dropdown in the Pages Manager when only the built-in page types ("page" and "global") are registered. It simplifies the UI by conditionally rendering the selector and ensures stale filter state is normalized back to "all" when custom types are absent.

Changes:

  • Computed hasCustomPageTypes via useMemo, early-returning null from PageTypeSelector when no custom types exist
  • Added a useEffect guardrail to reset selectedPageType to "all" if it holds a stale custom-type value when custom types disappear
  • Replaced any type annotations with ChaiPageType in the PageTypeSelector filter functions

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/pages/client/components/page-manager/page-manager-search-and-filter.tsx Adds hasCustomPageTypes memo, normalization effect, conditional null return, and improves type annotations
src/pages/client/components/page-manager/page-manager-search-and-filter.test.tsx New tests covering dropdown visibility for default-only and custom page type scenarios

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +55 to +66
it("hides page type dropdown when only default page types exist", () => {
mockUsePageTypes.mockReturnValue({
data: [
{ key: "page", name: "Page", hasSlug: true },
{ key: "global", name: "Global", hasSlug: false },
],
});

renderPageManagerSearchAndFilter();

expect(screen.queryByText("All")).toBeNull();
});
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

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

The normalization useEffect (lines 52–56) resets selectedPageType to "all" when hasCustomPageTypes is false and selectedPageType !== "all". However, neither test exercises this code path — both tests pass selectedPageType="all" to the rendered component, so the effect condition is never satisfied. There is no test verifying that setSelectedPageType gets called with "all" when a non-default filter value (e.g., "landing") is held in state while custom page types are removed.

Copilot uses AI. Check for mistakes.
@surajair surajair merged commit 0ab5c47 into dev Mar 10, 2026
3 of 4 checks passed
@surajair surajair deleted the copilot/fix-152845344-752521913-ac2f6c82-3f4c-4e73-9e53-db8ab73fd0b4 branch March 10, 2026 05:19
surajair added a commit that referenced this pull request Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

qa Test the issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hide "Page Type" dropdown in Pages Manager if only default types exist

3 participants