-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jetpack AI: Adding AI feedback component and implementing on carousel (…
…#40488) * Jetpack AI: Adding AI feedback component and implementing it on the image carousel * changelog * Removing isDisabled and shouldBeDisabled in favor or regular ol' disabled
- Loading branch information
Showing
5 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/update-jetpack-ai-feedback-component
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
Jetpack AI: Adding AI feedback component and implementing it on the image carousel |
58 changes: 58 additions & 0 deletions
58
...s/plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/ai-feedback/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { thumbsUp, thumbsDown } from '@wordpress/icons'; | ||
import clsx from 'clsx'; | ||
import { useState } from 'react'; | ||
import { getFeatureAvailability } from '../../../../blocks/ai-assistant/lib/utils/get-feature-availability'; | ||
|
||
import './style.scss'; | ||
|
||
export default function AiFeedbackThumbs( { disabled = false, iconSize = 24, ratedItem } ) { | ||
const [ itemsRated, setItemsRated ] = useState( {} ); | ||
|
||
const rateAI = ( isThumbsUp: boolean ) => { | ||
const aiRating = isThumbsUp ? 'thumbs-up' : 'thumbs-down'; | ||
|
||
setItemsRated( { | ||
...itemsRated, | ||
[ ratedItem ]: aiRating, | ||
} ); | ||
|
||
// calls to Tracks or whatever else can be made here | ||
}; | ||
|
||
const checkThumb = ( thumbValue: string ) => { | ||
if ( ! itemsRated[ ratedItem ] ) { | ||
return false; | ||
} | ||
|
||
return itemsRated[ ratedItem ] === thumbValue; | ||
}; | ||
|
||
return getFeatureAvailability( 'ai-response-feedback' ) ? ( | ||
<div className="ai-assistant-feedback__selection"> | ||
<Button | ||
aria-label={ __( 'Good Response', 'jetpack' ) } | ||
disabled={ disabled } | ||
icon={ thumbsUp } | ||
onClick={ () => rateAI( true ) } | ||
iconSize={ iconSize } | ||
showTooltip={ false } | ||
className={ clsx( { 'ai-assistant-feedback__thumb-selected': checkThumb( 'thumbs-up' ) } ) } | ||
/> | ||
<Button | ||
aria-label={ __( 'Bad Response', 'jetpack' ) } | ||
disabled={ disabled } | ||
icon={ thumbsDown } | ||
onClick={ () => rateAI( false ) } | ||
iconSize={ iconSize } | ||
showTooltip={ false } | ||
className={ clsx( { | ||
'ai-assistant-feedback__thumb-selected': checkThumb( 'thumbs-down' ), | ||
} ) } | ||
/> | ||
</div> | ||
) : ( | ||
<></> | ||
); | ||
} |
16 changes: 16 additions & 0 deletions
16
.../plugins/jetpack/extensions/plugins/ai-assistant-plugin/components/ai-feedback/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@import "@wordpress/base-styles/colors"; | ||
|
||
.ai-assistant-feedback { | ||
&__selection { | ||
display: flex; | ||
|
||
.components-button.has-icon { | ||
padding: 0; | ||
min-width: 28px; | ||
} | ||
} | ||
|
||
&__thumb-selected { | ||
color: var(--wp-components-color-accent,var(--wp-admin-theme-color,#3858e9)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters