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, } ) } > -