diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/index.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/index.ts index 368c928eed4d4..de7662258558d 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/index.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/features/index.ts @@ -1,3 +1,7 @@ +/** + * External dependencies + */ +import { __ } from '@wordpress/i18n'; /** * Features */ @@ -15,14 +19,17 @@ const features: Array< BreveFeature > = [ config: COMPLEX_WORDS, highlight: complexWords, dictionary: dicComplex, + description: __( 'Use simple, direct words.', 'jetpack' ), }, { config: LONG_SENTENCES, highlight: longSentences, + description: __( 'Long sentences are hard to read.', 'jetpack' ), }, { config: UNCONFIDENT_WORDS, highlight: unconfidentWords, + description: __( 'Remove weasel words.', 'jetpack' ), }, ]; diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/highlight/index.tsx b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/highlight/index.tsx index 59bdfd549da93..9cf54fc0339b1 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/highlight/index.tsx +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/highlight/index.tsx @@ -13,7 +13,6 @@ import { useSelect, } from '@wordpress/data'; import { __ } from '@wordpress/i18n'; -import { trash } from '@wordpress/icons'; import { registerFormatType, removeFormat, RichTextValue } from '@wordpress/rich-text'; import clsx from 'clsx'; import md5 from 'crypto-js/md5'; @@ -56,54 +55,64 @@ export default function Highlight() { return { getBlock: selector.getBlock }; }, [] ); - const { anchor, virtual, popoverOpen, id, feature, blockId, title, loading, suggestions } = - useSelect( select => { - const breveSelect = select( 'jetpack/ai-breve' ) as BreveSelect; - - // Popover - const isPopoverHover = breveSelect.isPopoverHover(); - const isHighlightHover = breveSelect.isHighlightHover(); - - // Anchor data - const { target: anchorEl, virtual: virtualEl } = breveSelect.getPopoverAnchor() ?? { - target: null, - virtual: null, - }; - const anchorFeature = anchorEl?.getAttribute?.( 'data-type' ) as string; - const anchorId = anchorEl?.getAttribute?.( 'data-id' ) as string; - const anchorBlockId = anchorEl?.getAttribute?.( 'data-block' ) as string; - - const config = features?.find?.( ftr => ftr.config.name === anchorFeature )?.config ?? { - name: '', - title: '', - }; - - // Suggestions - const loadingSuggestions = breveSelect.getSuggestionsLoading( { - feature: anchorFeature, - id: anchorId, - blockId: anchorBlockId, - } ); + const { + anchor, + virtual, + popoverOpen, + id, + feature, + blockId, + title, + loading, + suggestions, + description, + } = useSelect( select => { + const breveSelect = select( 'jetpack/ai-breve' ) as BreveSelect; + + // Popover + const isPopoverHover = breveSelect.isPopoverHover(); + const isHighlightHover = breveSelect.isHighlightHover(); + + // Anchor data + const defaultAnchor = { target: null, virtual: null }; + const { target: anchorEl, virtual: virtualEl } = + breveSelect.getPopoverAnchor() ?? defaultAnchor; + const anchorFeature = anchorEl?.getAttribute?.( 'data-type' ) as string; + const anchorId = anchorEl?.getAttribute?.( 'data-id' ) as string; + const anchorBlockId = anchorEl?.getAttribute?.( 'data-block' ) as string; + + // Feature data + const featureData = features?.find?.( ftr => ftr.config.name === anchorFeature ); + const featureConfig = featureData?.config ?? { name: '', title: '' }; + const featureDescription = featureData?.description ?? ''; + const featureTitle = featureConfig?.title ?? ''; + + // Suggestions + const loadingSuggestions = breveSelect.getSuggestionsLoading( { + feature: anchorFeature, + id: anchorId, + blockId: anchorBlockId, + } ); - const suggestionsData = breveSelect.getSuggestions( { - feature: anchorFeature, - id: anchorId, - blockId: anchorBlockId, - } ); + const suggestionsData = breveSelect.getSuggestions( { + feature: anchorFeature, + id: anchorId, + blockId: anchorBlockId, + } ); - return { - config, - anchor: anchorEl, - virtual: virtualEl, - title: config?.title, - feature: anchorFeature, - id: anchorId, - blockId: anchorBlockId, - popoverOpen: isHighlightHover || isPopoverHover, - loading: loadingSuggestions, - suggestions: suggestionsData, - }; - }, [] ); + return { + title: featureTitle, + description: featureDescription, + anchor: anchorEl, + virtual: virtualEl, + feature: anchorFeature, + id: anchorId, + blockId: anchorBlockId, + popoverOpen: isHighlightHover || isPopoverHover, + loading: loadingSuggestions, + suggestions: suggestionsData, + }; + }, [] ); const isPopoverOpen = popoverOpen && virtual; const hasSuggestions = Boolean( suggestions?.suggestion ); @@ -190,6 +199,7 @@ export default function Highlight() { const handleIgnoreSuggestion = () => { ignoreSuggestion( feature, blockId, id ); + setPopoverHover( false ); tracks.recordEvent( 'jetpack_ai_breve_ignore', { feature: BREVE_FEATURE_NAME, type: feature, @@ -214,39 +224,44 @@ export default function Highlight() { 'has-suggestions': hasSuggestions, } ) } > -
-
-
{ title }
+
+
+
+
{ title }
+
+ { ! hasSuggestions && ( +
+ { loading ? ( +
+ +
+ ) : ( + + ) } +
+ ) }
- { hasSuggestions ? ( -
+
+ { hasSuggestions && ( -
- { __( 'Click on the suggestion to insert it.', 'jetpack' ) } -
-
- ) : ( -
- { loading ? ( -
- -
+ ) } +
+ { hasSuggestions ? ( + __( 'Click on the suggestion to insert it.', 'jetpack' ) ) : ( <> - ) }
- ) } +
) } diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/highlight/style.scss b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/highlight/style.scss index 7938c3cae2156..48bd36fc7c4af 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/highlight/style.scss +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/highlight/style.scss @@ -20,70 +20,85 @@ .highlight-content { align-items: center; display: flex; - justify-content: space-between; - gap: 32px; + flex-direction: column; &.has-suggestions { align-items: flex-start; - flex-direction: column; padding-top: 8px; gap: 8px; } - .title, - .action { - padding: 8px 12px; - } - - .title { + .header-container { display: flex; - align-items: center; - justify-content: flex-start; - gap: 8px; - font-size: 14px; - font-weight: 500; - white-space: nowrap; + width: 100%; + justify-content: space-between; + gap: 32px; - .color { - width: 10px; - height: 10px; - border-radius: 50%; - @include features-colors( ( 'background-color' ) ); + .title, + .action { + padding: 8px 12px; } - } - .action { - font-size: 13px; - display: flex; - align-items: center; - justify-content: flex-end; - gap: 4px; + .title { + display: flex; + align-items: center; + justify-content: flex-start; + gap: 8px; + font-size: 14px; + font-weight: 500; + white-space: nowrap; - .suggest.components-button { - padding-top: 0px; - padding-bottom: 0px; - padding-right: 0px; - height: unset; + .color { + width: 10px; + height: 10px; + border-radius: 50%; + @include features-colors( ( 'background-color' ) ); + } + } + + .action { + font-size: 13px; + display: flex; + align-items: center; + justify-content: flex-end; + gap: 4px; - & > svg, - path { - fill: #0277a8; + .suggest.components-button { + padding-top: 0px; + padding-bottom: 0px; + padding-right: 0px; + height: unset; + + & > svg, + path { + fill: #0277a8; + } } } } - .suggestion-container { + .bottom-container { display: flex; flex-direction: column; border-top: 1px solid #dcdcde; + width: 100%; .helper { - padding: 8px; + padding: 4px 8px; background-color: #f6f7f7; white-space: nowrap; color: #646970; - margin: 0 4px 4px 4px; + margin: 4px; border-radius: 4px; + font-size: 12px; + display: flex; + justify-content: space-between; + align-items: center; + + .components-button { + padding: 0px; + color: #646970; + } } .components-button.is-tertiary { diff --git a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/types.ts b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/types.ts index e859779adf4a5..922b1d4807a80 100644 --- a/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/types.ts +++ b/projects/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/breve/types.ts @@ -105,6 +105,7 @@ export type BreveFeature = { config: BreveFeatureConfig; highlight: ( text: string ) => Array< HighlightedText >; dictionary?: { [ key: string ]: string }; + description: string; }; export type HighlightedText = {