Skip to content
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
26 changes: 12 additions & 14 deletions routes/post-type-edit/stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,22 @@ function PostTypeEditStage() {
const navigate = useNavigate();
const isAddMode = id === NEW_ID;
const postTypeId = parseInt( id, 10 );
const initialData = useSelect(
const record = useSelect(
( select ) => {
if ( isAddMode ) {
return BLANK_RECORD;
}
// beforeLoad (route.ts) guarantees the record is in cache.
const record = select(
coreStore
).getEntityRecord< PostTypeRecord >(
'postType',
USER_POST_TYPE_POST_TYPE,
postTypeId
)!;
return toFormData( record );
return (
! isAddMode &&
// beforeLoad (route.ts) guarantees the record is in cache.
select( coreStore ).getEntityRecord< PostTypeRecord >(
'postType',
USER_POST_TYPE_POST_TYPE,
postTypeId
)!
);
},
[ isAddMode, postTypeId ]
);

const initialData =
! isAddMode && record ? toFormData( record ) : BLANK_RECORD;
const title = isAddMode ? __( 'Add post type' ) : initialData.title.raw;
const commonProps = { initialData, title };
const postTypePageProps: PostTypePageProps = isAddMode
Expand Down
26 changes: 12 additions & 14 deletions routes/taxonomy-edit/stage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,24 +83,22 @@ function TaxonomyEditStage() {
const navigate = useNavigate();
const isAddMode = id === NEW_ID;
const taxonomyId = parseInt( id, 10 );
const initialData = useSelect(
const record = useSelect(
( select ) => {
if ( isAddMode ) {
return BLANK_RECORD;
}
// beforeLoad (route.ts) guarantees the record is in cache.
const record = select(
coreStore
).getEntityRecord< TaxonomyRecord >(
'postType',
USER_TAXONOMY_POST_TYPE,
taxonomyId
)!;
return toFormData( record );
return (
! isAddMode &&
// beforeLoad (route.ts) guarantees the record is in cache.
select( coreStore ).getEntityRecord< TaxonomyRecord >(
'postType',
USER_TAXONOMY_POST_TYPE,
taxonomyId
)!
);
},
[ isAddMode, taxonomyId ]
);

const initialData =
! isAddMode && record ? toFormData( record ) : BLANK_RECORD;
const title = isAddMode ? __( 'Add taxonomy' ) : initialData.title.raw;
const commonProps = { initialData, title };
const taxonomyPageProps: TaxonomyPageProps = isAddMode
Expand Down
Loading