Skip to content

Commit

Permalink
add cancel button to get rid of the assistant block (#34524)
Browse files Browse the repository at this point in the history
  • Loading branch information
CGastrell committed Dec 12, 2023
1 parent a929801 commit e119747
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 15 deletions.
4 changes: 4 additions & 0 deletions projects/js-packages/ai-client/changelog/add-ai-cancel-button
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: added

AI Client: add cancel button to get rid of the assistant block
47 changes: 32 additions & 15 deletions projects/js-packages/ai-client/src/components/ai-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function AIControl(
onSend = noop,
onStop = noop,
onAccept = noop,
onDiscard = noop,
onDiscard = null,
}: AiControlProps,
ref: React.MutableRefObject< null > // eslint-disable-line @typescript-eslint/ban-types
): React.ReactElement {
Expand Down Expand Up @@ -162,7 +162,7 @@ export function AIControl(
/>
</div>

{ ( ! showAccept || editRequest ) && value?.length > 0 && (
{ ( ! showAccept || editRequest ) && (
<div className="jetpack-components-ai-control__controls-prompt_button_wrapper">
{ ! loading ? (
<>
Expand All @@ -181,19 +181,36 @@ export function AIControl(
</Button>
) }

<Button
className="jetpack-components-ai-control__controls-prompt_button"
onClick={ sendRequest }
variant="primary"
disabled={ ! value?.length || disabled }
label={ __( 'Send request', 'jetpack-ai-client' ) }
>
{ showButtonLabels ? (
__( 'Generate', 'jetpack-ai-client' )
) : (
<Icon icon={ arrowUp } />
) }
</Button>
{ ! editRequest && ! value?.length && onDiscard && (
<Button
className="jetpack-components-ai-control__controls-prompt_button"
onClick={ discardHandler }
variant="secondary"
label={ __( 'Cancel', 'jetpack-ai-client' ) }
>
{ showButtonLabels ? (
__( 'Cancel', 'jetpack-ai-client' )
) : (
<Icon icon={ closeSmall } />
) }
</Button>
) }

{ value?.length > 0 && (
<Button
className="jetpack-components-ai-control__controls-prompt_button"
onClick={ sendRequest }
variant="primary"
disabled={ ! value?.length || disabled }
label={ __( 'Send request', 'jetpack-ai-client' ) }
>
{ showButtonLabels ? (
__( 'Generate', 'jetpack-ai-client' )
) : (
<Icon icon={ arrowUp } />
) }
</Button>
) }
</>
) : (
<Button
Expand Down

0 comments on commit e119747

Please sign in to comment.