woocommerce/plugins/woocommerce-blocks/assets/js/editor-components/incompatible-extension-notice/index.tsx

148 lines
3.7 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
import { __, _n, sprintf } from '@wordpress/i18n';
import { Notice, ExternalLink } from '@wordpress/components';
import { createInterpolateElement } from '@wordpress/element';
import { Alert } from '@woocommerce/icons';
import { Icon, chevronDown } from '@wordpress/icons';
/**
* Internal dependencies
*/
import { useCombinedIncompatibilityNotice } from './use-combined-incompatibility-notice';
import { SwitchToClassicShortcodeButton } from '../switch-to-classic-shortcode-button';
import './editor.scss';
interface ExtensionNoticeProps {
block: 'woocommerce/cart' | 'woocommerce/checkout';
clientId: string;
}
/**
* Shows a notice when there are incompatible extensions.
*
* Tracks events:
* - switch_to_classic_shortcode_click
* - switch_to_classic_shortcode_confirm
* - switch_to_classic_shortcode_cancel
* - switch_to_classic_shortcode_undo
*/
export function IncompatibleExtensionsNotice( {
block,
clientId,
}: ExtensionNoticeProps ) {
const [
isVisible,
dismissNotice,
incompatibleExtensions,
incompatibleExtensionsCount,
] = useCombinedIncompatibilityNotice( block );
if ( ! isVisible ) {
return null;
}
const noticeContent = (
<>
{ incompatibleExtensionsCount > 1
? createInterpolateElement(
__(
'Some active extensions do not yet support this block. This may impact the shopper experience. <a>Learn more</a>',
'woocommerce'
),
{
a: (
<ExternalLink href="https://woocommerce.com/document/cart-checkout-blocks-status/" />
),
}
)
: createInterpolateElement(
sprintf(
// translators: %s is the name of the extension.
__(
'<strong>%s</strong> does not yet support this block. This may impact the shopper experience. <a>Learn more</a>',
'woocommerce'
),
Object.values( incompatibleExtensions )[ 0 ]
),
{
strong: <strong />,
a: (
<ExternalLink href="https://woocommerce.com/document/cart-checkout-blocks-status/" />
),
}
) }
</>
);
const entries = Object.entries( incompatibleExtensions );
const remainingEntries = entries.length - 2;
return (
<Notice
className="wc-blocks-incompatible-extensions-notice"
status={ 'warning' }
onRemove={ dismissNotice }
spokenMessage={ noticeContent }
>
<div className="wc-blocks-incompatible-extensions-notice__content">
<Icon
className="wc-blocks-incompatible-extensions-notice__warning-icon"
icon={ <Alert /> }
/>
<div>
<p>{ noticeContent }</p>
{ incompatibleExtensionsCount > 1 && (
<ul>
{ entries.slice( 0, 2 ).map( ( [ id, title ] ) => (
<li
key={ id }
className="wc-blocks-incompatible-extensions-notice__element"
>
{ title }
</li>
) ) }
</ul>
) }
{ entries.length > 2 && (
<details>
<summary>
<span>
{ sprintf(
// translators: %s is the number of incompatible extensions.
_n(
'%s more incompatibility',
'%s more incompatibilites',
remainingEntries,
'woocommerce'
),
remainingEntries
) }
</span>
<Icon icon={ chevronDown } />
</summary>
<ul>
{ entries.slice( 2 ).map( ( [ id, title ] ) => (
<li
key={ id }
className="wc-blocks-incompatible-extensions-notice__element"
>
{ title }
</li>
) ) }
</ul>
</details>
) }
<SwitchToClassicShortcodeButton
block={ block }
clientId={ clientId }
Update generic incompatibility notice (#42751) * Move the switch to classic shortcode block button to separate component - Move modal component file from incompatible-extension-notice component folder to switch-to-classic-shortcode-button folder. - Rename modal component file to model-content component file. - Move the switch to classic shortcode block button to separate component folder * Update generic incompatibility notice - Update the notice description. - Add switch to classic shortcode block button to the notice. * Fix margin in editor.scss * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Update class names in switch-to-classic-shortcode-button component * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Update plugins/woocommerce-blocks/assets/js/editor-components/switch-to-classic-shortcode-button/editor.scss Co-authored-by: Niels Lange <info@nielslange.de> * Refactor SwitchToClassicShortcodeButton component * Fix css lint erros * Add changefile(s) from automation for the following project(s): woocommerce-blocks * Add type property to notice events * Refactor switch to classic shortcode button logic * Use isCart for switchButtonLabel and snackbarLabel * Remove empty div in sidebar compatibility notice component * Refactor switch to classic shortcode button event handling * Adjust wording * Adjust marging and readability * Introduce union for SwitchToClassicShortcodeButtonProps type prop * Simplify logic * Use proposed text --------- Co-authored-by: github-actions <github-actions@github.com> Co-authored-by: Niels Lange <info@nielslange.de> Co-authored-by: Paulo Arromba <17236129+wavvves@users.noreply.github.com>
2024-01-05 03:47:34 +00:00
type={ 'incompatible' }
/>
</div>
</div>
</Notice>
);
}