Skip to content

Commit

Permalink
Changes per review
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jun 27, 2024
1 parent d334e16 commit b917103
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
18 changes: 7 additions & 11 deletions packages/editor/src/dataviews/actions/delete-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ import type { StoreDescriptor } from '@wordpress/data';
* Internal dependencies
*/
import {
TEMPLATE_PART_POST_TYPE,
TEMPLATE_POST_TYPE,
} from '../../store/constants';
import { isTemplateRemovable, getItemTitle } from './utils';
isTemplateRemovable,
getItemTitle,
isTemplateOrTemplatePart,
} from './utils';
// @ts-ignore
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';
import type { Post, TemplateOrTemplatePart } from '../types';
import type { Post } from '../types';

const { PATTERN_TYPES } = unlock( patternsPrivateApis );

Expand All @@ -40,12 +40,8 @@ const deletePostAction: Action< Post > = {
isPrimary: true,
icon: trash,
isEligible( post ) {
if (
[ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes(
post.type
)
) {
return isTemplateRemovable( post as TemplateOrTemplatePart );
if ( isTemplateOrTemplatePart( post ) ) {
return isTemplateRemovable( post );
}
// We can only remove user patterns.
return post.type === PATTERN_TYPES.user;
Expand Down
2 changes: 1 addition & 1 deletion packages/editor/src/dataviews/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export default function useDefaultActions() {
unregisterEntityAction( 'postType', '*', deletePost.id );
};
}, [ registerEntityAction, unregisterEntityAction ] );
}
}
13 changes: 12 additions & 1 deletion packages/editor/src/dataviews/actions/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,20 @@ import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import { TEMPLATE_ORIGINS } from '../../store/constants';
import {
TEMPLATE_ORIGINS,
TEMPLATE_PART_POST_TYPE,
TEMPLATE_POST_TYPE,
} from '../../store/constants';

import type { Post, TemplateOrTemplatePart } from '../types';

export function isTemplateOrTemplatePart(
p: Post
): p is TemplateOrTemplatePart {
return p.type === TEMPLATE_POST_TYPE || p.type === TEMPLATE_PART_POST_TYPE;
}

export function getItemTitle( item: Post ) {
if ( typeof item.title === 'string' ) {
return decodeEntities( item.title );
Expand Down
10 changes: 2 additions & 8 deletions packages/editor/src/dataviews/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,15 @@ type PostStatus =
| 'auto-draft'
| 'trash';

type ReservedPostTypes = 'template' | 'template-part';

export interface BasePost {
status?: PostStatus;
title: string | { rendered: string };
type: string;
}

export interface TemplateOrTemplatePart extends BasePost {
type: 'template' | 'template-part';
source: string;
has_theme_file: boolean;
}

export interface OtherPost extends BasePost {
type: Exclude< string, ReservedPostTypes >;
}

export type Post = TemplateOrTemplatePart | OtherPost;
export type Post = TemplateOrTemplatePart | BasePost;

0 comments on commit b917103

Please sign in to comment.