Skip to content

Commit

Permalink
Add comment suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mdperez86 committed Mar 15, 2023
1 parent 82b2cd6 commit 62efff6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
11 changes: 4 additions & 7 deletions packages/js/product-editor/src/components/editor/editor.tsx
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { createElement, StrictMode } from '@wordpress/element';
import {
EditorSettings,
Expand All @@ -13,7 +12,6 @@ import { Product } from '@woocommerce/data';
// @ts-ignore No types for this exist yet.
// eslint-disable-next-line @woocommerce/dependency-group
import { EntityProvider } from '@wordpress/core-data';

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore No types for this exist yet.
// eslint-disable-next-line @woocommerce/dependency-group
Expand All @@ -32,9 +30,11 @@ import { BlockEditor } from '../block-editor';
import { initBlocks } from './init-blocks';

initBlocks();

export type ProductEditorSettings = Partial<
EditorSettings & EditorBlockListSettings
>;

type EditorProps = {
product: Product;
settings: ProductEditorSettings | undefined;
Expand All @@ -50,11 +50,8 @@ export function Editor( { product, settings }: EditorProps ) {
<InterfaceSkeleton
header={
<Header
product={ product }
title={
product.name ||
__( 'Add new product', 'woocommerce' )
}
productId={ product.id }
title={ product.name }
/>
}
sidebar={ <Sidebar /> }
Expand Down
19 changes: 12 additions & 7 deletions packages/js/product-editor/src/components/header/header.tsx
Expand Up @@ -5,14 +5,15 @@ import { Button } from '@wordpress/components';
import { useDispatch, useSelect } from '@wordpress/data';
import { createElement } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { Product } from '@woocommerce/data';

export type HeaderProps = {
product: Product;
productId: number;
title: string;
};

export function Header( { product, title }: HeaderProps ) {
const DEFAULT_PRODUCT_NAME = 'AUTO-DRAFT';

export function Header( { productId, title }: HeaderProps ) {
const { isProductLocked, isSaving } = useSelect(
( select ) => {
const { isSavingEntityRecord } = select( 'core' );
Expand All @@ -22,19 +23,19 @@ export function Header( { product, title }: HeaderProps ) {
isSaving: isSavingEntityRecord(
'postType',
'product',
product.id
productId
),
};
},
[ product.id ]
[ productId ]
);

const isDisabled = isProductLocked || isSaving;

const { saveEditedEntityRecord } = useDispatch( 'core' );

function handleSave() {
saveEditedEntityRecord( 'postType', 'product', product.id );
saveEditedEntityRecord( 'postType', 'product', productId );
}

return (
Expand All @@ -44,7 +45,11 @@ export function Header( { product, title }: HeaderProps ) {
aria-label={ __( 'Product Editor top bar.', 'woocommerce' ) }
tabIndex={ -1 }
>
<h1 className="woocommerce-product-header__title">{ title }</h1>
<h1 className="woocommerce-product-header__title">
{ title === DEFAULT_PRODUCT_NAME
? __( 'Add new product', 'woocommerce' )
: title }
</h1>

<div className="woocommerce-product-header__actions">
<Button
Expand Down
2 changes: 1 addition & 1 deletion plugins/woocommerce-admin/client/products/product-page.tsx
Expand Up @@ -22,7 +22,7 @@ declare const productBlockEditorSettings: ProductEditorSettings;
const ProductEditor: React.FC< { product: Product | undefined } > = ( {
product,
} ) => {
if ( ! product ) {
if ( ! product?.id ) {
return <Spinner />;
}

Expand Down

0 comments on commit 62efff6

Please sign in to comment.