Skip to content

Commit

Permalink
Merge branch 'trunk' into remove-block-hooks-theme-include-list-guard
Browse files Browse the repository at this point in the history
  • Loading branch information
tjcafferkey committed Mar 20, 2024
2 parents 5b68f23 + 55cd198 commit 03d087c
Show file tree
Hide file tree
Showing 111 changed files with 1,316 additions and 626 deletions.
194 changes: 194 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

@@ -0,0 +1,4 @@
Significance: minor
Type: add

Product Editor: Add loading state functionality to Schedule Product modal
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Fix publish dropdown visibility in new product after hiding pre-publish modal #45682
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Fix section title styles in the pre-publish panel on WP 6.5 #45689
4 changes: 4 additions & 0 deletions packages/js/product-editor/changelog/fix-45665
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Header tag Hidden now is aligned with the Visibility: Hidden from the pre publish modal
4 changes: 4 additions & 0 deletions packages/js/product-editor/changelog/fix-45667
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Replace the Draft tag with a Scheduled tag in the product header
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

Fix double scroll bar in pre-publish panel #45671
@@ -0,0 +1,4 @@
Significance: minor
Type: dev

Exports handlePrompt from @woocommerce/product-editor for use by extensions expanding the variation quick update menu. Also introduces handleConfirm and exposes it also
15 changes: 12 additions & 3 deletions packages/js/product-editor/src/components/header/header.tsx
Expand Up @@ -125,16 +125,24 @@ export function Header( {

function getVisibilityTags() {
const tags = [];
if ( productStatus === 'draft' || productStatus === 'future' ) {
if ( productStatus === 'draft' ) {
tags.push(
<Tag
key={ 'draft-tag' }
label={ __( 'Draft', 'woocommerce' ) }
/>
);
}
if ( productStatus === 'future' ) {
tags.push(
<Tag
key={ 'scheduled-tag' }
label={ __( 'Scheduled', 'woocommerce' ) }
/>
);
}
if (
( productStatus !== 'future' && catalogVisibility === 'hidden' ) ||
( productStatus !== 'future' && catalogVisibility !== 'visible' ) ||
( isVariation && productStatus === 'private' )
) {
tags.push(
Expand Down Expand Up @@ -249,7 +257,8 @@ export function Header( {

<PublishButton
productType={ productType }
prePublish={ showPrepublishChecks }
isPrePublishPanelVisible={ showPrepublishChecks }
isMenuButton
/>

<WooHeaderItem.Slot name="product" />
Expand Down
Expand Up @@ -4,6 +4,7 @@
import { MouseEvent } from 'react';
import { Button } from '@wordpress/components';
import { useEntityProp } from '@wordpress/core-data';
import { isInTheFuture } from '@wordpress/date';
import { __ } from '@wordpress/i18n';
import type { Product } from '@woocommerce/data';

Expand All @@ -28,12 +29,18 @@ export function usePublish< T = Product >( {
const { isValidating, isDirty, isPublishing, publish } =
useProductManager( productType );

const [ status, , prevStatus ] = useEntityProp< Product[ 'status' ] >(
const [ , , prevStatus ] = useEntityProp< Product[ 'status' ] >(
'postType',
productType,
'status'
);

const [ editedDate ] = useEntityProp< string >(
'postType',
productType,
'date_created_gmt'
);

const isBusy = isPublishing || isValidating;
const isDisabled = disabled || isBusy || ! isDirty;

Expand All @@ -53,7 +60,7 @@ export function usePublish< T = Product >( {
function getButtonText() {
if (
window.wcAdminFeatures[ 'product-pre-publish-modal' ] &&
status === 'future'
isInTheFuture( editedDate )
) {
return __( 'Schedule', 'woocommerce' );
}
Expand Down
Expand Up @@ -26,7 +26,7 @@ export function PublishButtonMenu( {
postType,
...props
}: PublishButtonMenuProps ) {
const { isScheduled, schedule, date, formattedDate } =
const { isScheduling, isScheduled, schedule, date, formattedDate } =
useProductScheduled( postType );
const [ showScheduleModal, setShowScheduleModal ] = useState<
'schedule' | 'edit' | undefined
Expand Down Expand Up @@ -62,6 +62,7 @@ export function PublishButtonMenu( {
<SchedulePublishModal
postType={ postType }
value={ showScheduleModal === 'edit' ? date : undefined }
isScheduling={ isScheduling }
onCancel={ () => setShowScheduleModal( undefined ) }
onSchedule={ scheduleProduct }
/>
Expand Down
Expand Up @@ -25,7 +25,8 @@ import type { PublishButtonProps } from './types';

export function PublishButton( {
productType = 'product',
prePublish,
isMenuButton,
isPrePublishPanelVisible = true,
...props
}: PublishButtonProps ) {
const { createErrorNotice } = useDispatch( 'core/notices' );
Expand Down Expand Up @@ -68,7 +69,7 @@ export function PublishButton( {
if (
productType === 'product' &&
window.wcAdminFeatures[ 'product-pre-publish-modal' ] &&
prePublish
isMenuButton
) {
function renderPublishButtonMenu(
menuProps: Dropdown.RenderProps
Expand All @@ -78,7 +79,11 @@ export function PublishButton( {
);
}

if ( editedStatus !== 'publish' && editedStatus !== 'future' ) {
if (
editedStatus !== 'publish' &&
editedStatus !== 'future' &&
isPrePublishPanelVisible
) {
function handlePrePublishButtonClick(
event: MouseEvent< HTMLButtonElement >
) {
Expand Down
Expand Up @@ -8,5 +8,6 @@ export type PublishButtonProps = Omit<
'aria-disabled' | 'variant' | 'children'
> & {
productType?: string;
prePublish?: boolean;
isMenuButton?: boolean;
isPrePublishPanelVisible?: boolean;
};
Expand Up @@ -10,6 +10,7 @@ import { useEntityProp } from '@wordpress/core-data';
import { closeSmall } from '@wordpress/icons';
import classnames from 'classnames';
import type { Product } from '@woocommerce/data';
import { isInTheFuture } from '@wordpress/date';

/**
* Internal dependencies
Expand All @@ -30,10 +31,10 @@ export function PrepublishPanel( {
'woocommerce'
),
}: PrepublishPanelProps ) {
const [ editedDate, , date ] = useEntityProp< string >(
const [ editedDate ] = useEntityProp< string >(
'postType',
productType,
'date_created'
'date_created_gmt'
);

const [ productStatus, , prevStatus ] = useEntityProp<
Expand All @@ -47,7 +48,7 @@ export function PrepublishPanel( {
? productStatus === 'publish'
: true;

if ( editedDate !== date ) {
if ( isInTheFuture( editedDate ) ) {
title = __( 'Are you ready to schedule this product?', 'woocommerce' );
description = __(
'Your product will be published at the specified date and time.',
Expand Down
Expand Up @@ -52,7 +52,12 @@
}

&__content {
min-height: calc( 100% - #{ $header-height + 220px } );
// Ensure the pre-publish panel content accounts for the header and footer height.
min-height: calc( 100% - #{ $header-height + 222px } );
.editor-post-publish-panel__link {
font-weight: 400;
padding-left: $gap-smallest;
}
}

&__footer {
Expand Down
Expand Up @@ -26,6 +26,7 @@ export function SchedulePublishModal( {
className,
onCancel,
onSchedule,
isScheduling,
...props
}: SchedulePublishModalProps ) {
const [ date, setDate ] = useState< string | undefined >(
Expand Down Expand Up @@ -77,6 +78,8 @@ export function SchedulePublishModal( {
</Button>
<Button
variant="primary"
isBusy={ isScheduling }
disabled={ isScheduling }
onClick={ () => onSchedule?.( date ) }
>
{ __( 'Schedule', 'woocommerce' ) }
Expand Down
Expand Up @@ -13,4 +13,5 @@ export type SchedulePublishModalProps = Omit<
value?: string;
onCancel?(): void;
onSchedule?( value?: string ): void;
isScheduling?: boolean;
};
24 changes: 24 additions & 0 deletions packages/js/product-editor/src/utils/handle-confirm.ts
@@ -0,0 +1,24 @@
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';

export type HandleConfirmProps = {
message?: string;
onOk(): void;
onCancel?(): void;
};

export async function handleConfirm( {
message = __( 'Are you sure?', 'woocommerce' ),
onOk,
onCancel,
}: HandleConfirmProps ) {
// eslint-disable-next-line no-alert
if ( window.confirm( message ) ) {
onOk?.();
return;
}

onCancel?.();
}
4 changes: 1 addition & 3 deletions packages/js/product-editor/src/utils/handle-prompt.ts
Expand Up @@ -20,9 +20,7 @@ export async function handlePrompt( {
const value = window.prompt( message, defaultValue );

if ( value === null ) {
if ( onCancel ) {
onCancel();
}
onCancel?.();
return;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/js/product-editor/src/utils/index.ts
Expand Up @@ -21,6 +21,8 @@ import {
import { preventLeavingProductForm } from './prevent-leaving-product-form';
import { hasAttributesUsedForVariations } from './has-attributes-used-for-variations';
import { isValidEmail } from './validate-email';
import { handlePrompt } from './handle-prompt';
import { handleConfirm } from './handle-confirm';

export * from './create-ordered-children';
export * from './date';
Expand All @@ -45,6 +47,8 @@ export {
getProductTitle,
getProductVariationTitle,
getTruncatedProductVariationTitle,
handleConfirm,
handlePrompt,
hasAttributesUsedForVariations,
isValidEmail,
preventLeavingProductForm,
Expand Down
Expand Up @@ -7,15 +7,20 @@
import { store as blockEditorStore } from '@wordpress/block-editor';
// @ts-expect-error No types for this exist yet.
import { store as coreStore, useEntityRecords } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { useDispatch, useSelect } from '@wordpress/data';
// @ts-expect-error No types for this exist yet.
import { privateApis as routerPrivateApis } from '@wordpress/router';
// @ts-expect-error No types for this exist yet.
import { unlock } from '@wordpress/edit-site/build-module/lock-unlock';
import { useQuery } from '@woocommerce/navigation';
// @ts-expect-error No types for this exist yet.
import useSiteEditorSettings from '@wordpress/edit-site/build-module/components/block-editor/use-site-editor-settings';
import { useCallback, useContext, useMemo } from '@wordpress/element';
import {
useCallback,
useContext,
useEffect,
useMemo,
} from '@wordpress/element';
// @ts-expect-error No types for this exist yet.
import { store as editSiteStore } from '@wordpress/edit-site/build-module/store';

Expand Down Expand Up @@ -159,36 +164,51 @@ export const BlockEditorContainer = () => {

const opacityClass = 'preview-opacity';

const renderedBlocks = useMemo(
() =>
blocks.map( ( block ) => {
const clientIds = blocks.map( ( block ) => block.clientId );

// @ts-expect-error No types for this exist yet.
const { updateBlockAttributes } = useDispatch( blockEditorStore );

useEffect( () => {
const { blockIdToHighlight, restOfBlockIds } = clientIds.reduce(
( acc, clientId ) => {
if (
! isHighlighting ||
block.clientId === highlightedBlockClientId
clientId === highlightedBlockClientId
) {
return {
...block,
attributes: {
...block.attributes,
className: block.attributes.className?.replace(
opacityClass,
''
),
},
blockIdToHighlight: clientId,
restOfBlockIds: acc.restOfBlockIds,
};
}

return {
...block,
attributes: {
...block.attributes,
className:
block.attributes.className + ` ${ opacityClass }`,
},
blockIdToHighlight: acc.blockIdToHighlight,
restOfBlockIds: [ ...acc.restOfBlockIds, clientId ],
};
} ),
[ blocks, highlightedBlockClientId, isHighlighting ]
);
},
{
blockIdToHighlight: null,
restOfBlockIds: [],
} as {
blockIdToHighlight: string | null;
restOfBlockIds: string[];
}
);

updateBlockAttributes( blockIdToHighlight, {
className: '',
} );

updateBlockAttributes( restOfBlockIds, {
className: ` ${ opacityClass }`,
} );
}, [
clientIds,
highlightedBlockClientId,
isHighlighting,
updateBlockAttributes,
] );

const isScrollable = useMemo(
() =>
Expand All @@ -202,7 +222,7 @@ export const BlockEditorContainer = () => {

return (
<BlockEditor
renderedBlocks={ renderedBlocks }
renderedBlocks={ blocks }
isScrollable={ isScrollable }
onChange={ onChange }
settings={ settings }
Expand Down

0 comments on commit 03d087c

Please sign in to comment.