Skip to content

Fix showing page tree items without slug #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/PageTreeViewItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export const PageTreeViewItem = ({
onClick={onItemClick}>
<Flex align="center" gap={3}>
<UrlText isDisabled={isDisabled || (!page.isPublished && page.isDraft)} textOverflow="ellipsis">
{parentPath ? page.slug?.current : getRootPageSlug(page, config) ?? '/'}
{parentPath ? page.slug?.current ?? 'untitled' : getRootPageSlug(page, config) ?? '/'}
Copy link
Member

Choose a reason for hiding this comment

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

I do not think that untitled is the right word here. Maybe fall back on title and otherwise untitled?

Copy link
Author

Choose a reason for hiding this comment

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

We never show the title in the page tree but always the slug, right? I chose untitled, because sanity does the same for documents that do not have a title-like field available. I feel like that consistency is nice here.

</UrlText>
{!isDisabled && (isHovered || hasActionOpen) && (
<PageTreeViewItemActions
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/page-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const mapPageTreeItems = (

return getChildPages(parentId).map(page => {
const pagePath = parentPath
? `${parentPath === '/' ? '' : parentPath}/${page.slug?.current}`
? `${parentPath === '/' ? '' : parentPath}/${page.slug?.current ?? ''}`
: `/${getRootPageSlug(page, config) ?? ''}`;
const children = orderBy(mapPageTreeItems(config, pagesWithPublishedState, page._id, pagePath), 'path');

Expand Down Expand Up @@ -134,7 +134,7 @@ const getPublishedAndDraftRawPageMetadata = (
};

const isValidPage = (config: PageTreeConfig, page: RawPageMetadata): boolean => {
if (!page.parent || !page.slug) {
if (!page.parent) {
if (page._type !== config.rootSchemaType) {
return false;
}
Expand Down
Loading