Skip to content
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

[Site Editor]: Update the add template menu #50595

Merged
merged 8 commits into from
May 17, 2023
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/**
* External dependencies
*/
import { kebabCase } from 'lodash';

/**
* WordPress dependencies
*/
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import {
Button,
TextControl,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
} from '@wordpress/components';

function AddCustomGenericTemplateModalContent( { onClose, createTemplate } ) {
const [ title, setTitle ] = useState( '' );
const defaultTitle = __( 'Custom Template' );
const [ isBusy, setIsBusy ] = useState( false );
async function onCreateTemplate( event ) {
event.preventDefault();
if ( isBusy ) {
return;
}
setIsBusy( true );
try {
await createTemplate(
{
slug:
'wp-custom-template-' +
kebabCase( title || defaultTitle ),
title: title || defaultTitle,
},
false
);
} finally {
setIsBusy( false );
}
}
return (
<form onSubmit={ onCreateTemplate }>
<VStack spacing={ 6 }>
<TextControl
__nextHasNoMarginBottom
label={ __( 'Name' ) }
value={ title }
onChange={ setTitle }
placeholder={ defaultTitle }
disabled={ isBusy }
help={ __(
'Describe the template, e.g. "Post with sidebar".'
) }
/>
<HStack
className="edit-site-custom-generic-template__modal-actions"
justify="right"
>
<Button
variant="tertiary"
onClick={ () => {
onClose();
} }
>
{ __( 'Cancel' ) }
</Button>
<Button
variant="primary"
type="submit"
isBusy={ isBusy }
aria-disabled={ isBusy }
>
{ __( 'Create' ) }
</Button>
</HStack>
</VStack>
</form>
);
}

export default AddCustomGenericTemplateModalContent;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
* WordPress dependencies
*/
import { useState, useMemo, useEffect } from '@wordpress/element';
import { __, sprintf } from '@wordpress/i18n';
import { __ } from '@wordpress/i18n';
import {
Button,
Flex,
FlexItem,
Modal,
SearchControl,
TextHighlight,
__experimentalText as Text,
Expand All @@ -23,7 +22,6 @@ import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import TemplateActionsLoadingScreen from './template-actions-loading-screen';
import { mapToIHasNameAndId } from './utils';

const EMPTY_ARRAY = [];
Expand Down Expand Up @@ -179,36 +177,25 @@ function SuggestionList( { entityForSuggestions, onSelect } ) {
);
}

function AddCustomTemplateModal( {
onClose,
onSelect,
entityForSuggestions,
isCreatingTemplate,
} ) {
function AddCustomTemplateModalContent( { onSelect, entityForSuggestions } ) {
const [ showSearchEntities, setShowSearchEntities ] = useState(
entityForSuggestions.hasGeneralTemplate
);
const baseCssClass = 'edit-site-custom-template-modal';
return (
<Modal
title={ sprintf(
// translators: %s: Name of the post type e.g: "Post".
__( 'Add template: %s' ),
entityForSuggestions.labels.singular_name
) }
className={ baseCssClass }
onRequestClose={ onClose }
<VStack
spacing={ 4 }
className="edit-site-custom-template-modal__contents-wrapper"
alignment="left"
>
{ isCreatingTemplate && <TemplateActionsLoadingScreen /> }
{ ! showSearchEntities && (
<VStack spacing={ 4 }>
<>
<Text as="p">
{ __(
'Select whether to create a single template for all items or a specific one.'
) }
</Text>
<Flex
className={ `${ baseCssClass }__contents` }
className="edit-site-custom-template-modal__contents"
gap="4"
align="initial"
>
Expand Down Expand Up @@ -272,10 +259,10 @@ function AddCustomTemplateModal( {
</Text>
</FlexItem>
</Flex>
</VStack>
</>
) }
{ showSearchEntities && (
<VStack spacing={ 4 }>
<>
<Text as="p">
{ __(
'This template will be used only for the specific item chosen.'
Expand All @@ -285,10 +272,10 @@ function AddCustomTemplateModal( {
entityForSuggestions={ entityForSuggestions }
onSelect={ onSelect }
/>
</VStack>
</>
) }
</Modal>
</VStack>
);
}

export default AddCustomTemplateModal;
export default AddCustomTemplateModalContent;
Loading