mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
## Summary Resolves System Prompt not sending issues: https://github.com/elastic/kibana/issues/161809 Also resolves: - [X] Not being able to delete really long Conversation, System Prompt, and Quick Prompt names - [X] Fix user/all System Prompts being overridden on refresh - [X] Conversation without default System Prompt not healed if it is initial conversation when Assistant opens (Timeline) - [X] New conversation created from Conversations Settings not getting a connector by default - [X] Current conversation not selected by default when settings gear is clicked (and other assistant instances exist) - [X] Sent to Timeline action sends anonymized values instead of actual plaintext - [X] Clicking Submit does not clear the text area - [X] Remove System Prompt Tooltip - [X] Fixes confusion when System or Quick Prompt is empty by adding a placeholder value - [X] Shows (empty prompt) in System Prompt selector when the Prompt content is empty - [X] Fixes connector error callout flashing on initial load - [X] Shows `(empty prompt)` text within Prompt Editor when prompt content is empty to prevent confusion ### Checklist Delete any items that are not applicable to this PR. - [X] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
71 lines
2.1 KiB
TypeScript
71 lines
2.1 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License
|
|
* 2.0; you may not use this file except in compliance with the Elastic License
|
|
* 2.0.
|
|
*/
|
|
|
|
import { EuiTextArea } from '@elastic/eui';
|
|
import React, { useCallback, useEffect, forwardRef } from 'react';
|
|
|
|
// eslint-disable-next-line @kbn/eslint/module_migration
|
|
import styled from 'styled-components';
|
|
import * as i18n from './translations';
|
|
|
|
export interface Props extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
|
|
handlePromptChange: (value: string) => void;
|
|
isDisabled?: boolean;
|
|
onPromptSubmit: (value: string) => void;
|
|
value: string;
|
|
}
|
|
|
|
const StyledTextArea = styled(EuiTextArea)`
|
|
min-height: 125px;
|
|
padding-right: 42px;
|
|
`;
|
|
|
|
export const PromptTextArea = forwardRef<HTMLTextAreaElement, Props>(
|
|
({ isDisabled = false, value, onPromptSubmit, handlePromptChange, ...props }, ref) => {
|
|
const onChangeCallback = useCallback(
|
|
(event: React.ChangeEvent<HTMLTextAreaElement>) => {
|
|
handlePromptChange(event.target.value);
|
|
},
|
|
[handlePromptChange]
|
|
);
|
|
|
|
const onKeyDown = useCallback(
|
|
(event) => {
|
|
if (event.key === 'Enter' && !event.shiftKey && value.trim().length > 0) {
|
|
event.preventDefault();
|
|
onPromptSubmit(event.target.value?.trim());
|
|
handlePromptChange('');
|
|
} else if (event.key === 'Enter' && !event.shiftKey && value.trim().length === 0) {
|
|
event.preventDefault();
|
|
event.stopPropagation();
|
|
}
|
|
},
|
|
[value, onPromptSubmit, handlePromptChange]
|
|
);
|
|
|
|
useEffect(() => {
|
|
handlePromptChange(value);
|
|
}, [handlePromptChange, value]);
|
|
|
|
return (
|
|
<StyledTextArea
|
|
className="eui-scrollBar"
|
|
inputRef={ref}
|
|
id={'prompt-textarea'}
|
|
data-test-subj={'prompt-textarea'}
|
|
fullWidth
|
|
autoFocus
|
|
disabled={isDisabled}
|
|
placeholder={i18n.PROMPT_PLACEHOLDER}
|
|
value={value}
|
|
onChange={onChangeCallback}
|
|
onKeyDown={onKeyDown}
|
|
/>
|
|
);
|
|
}
|
|
);
|
|
PromptTextArea.displayName = 'PromptTextArea';
|