Skip to content

Commit

Permalink
Removes space key listener to resolve cypress issues
Browse files Browse the repository at this point in the history
  • Loading branch information
spong committed Jun 2, 2023
1 parent 0bed49d commit 71f0da8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import {
GEN_AI_CONNECTOR_ID,
OpenAiProviderType,
} from '@kbn/stack-connectors-plugin/public/common';
import useEvent from 'react-use/lib/useEvent';
import { ActionConnectorProps } from '@kbn/triggers-actions-ui-plugin/public/types';
import { BASE_CONVERSATIONS, Conversation, Message } from '../../..';
import { useLoadActionTypes } from '../use_load_action_types';
Expand Down Expand Up @@ -115,25 +114,6 @@ export const ConnectorSetup: React.FC<ConnectorSetupProps> = React.memo<Connecto
: 0
);

// Register keyboard listener to show the add connector modal when SPACE is pressed
// Ideally this would be done by focusing the button once rendered, but can't seem to get focus to the EuiCard via refs/tabindex
const onKeyDown = useCallback(
(event: KeyboardEvent) => {
if (event.key === ' ' && !isConnectorModalVisible) {
// Skip intro still going
if (!showAddConnectorButton) {
setCurrentMessageIndex(MESSAGE_INDEX_BEFORE_CONNECTOR);
event.preventDefault();
} else {
setIsConnectorModalVisible(true);
event.preventDefault();
}
}
},
[isConnectorModalVisible, showAddConnectorButton]
);
useEvent('keydown', onKeyDown);

// Once streaming of previous message is complete, proceed to next message
const onHandleMessageStreamingComplete = useCallback(() => {
const timeoutId = setTimeout(
Expand All @@ -151,6 +131,11 @@ export const ConnectorSetup: React.FC<ConnectorSetupProps> = React.memo<Connecto
setConversation({ conversation: clearPresentationData(conversation) });
}, [conversation, onSetupComplete, setConversation]);

// Show button to add connector after last message has finished streaming
const handleSkipSetup = useCallback(() => {
setCurrentMessageIndex(MESSAGE_INDEX_BEFORE_CONNECTOR);
}, [setCurrentMessageIndex]);

// Create EuiCommentProps[] from conversation messages
const commentBody = useCallback(
(message: Message, index: number, length: number) => {
Expand Down Expand Up @@ -226,7 +211,11 @@ export const ConnectorSetup: React.FC<ConnectorSetupProps> = React.memo<Connecto
{!showAddConnectorButton && (
<SkipEuiText color="subdued" size={'xs'}>
<EuiTextAlign textAlign="center">
<EuiBadge color="hollow" isDisabled={true}>
<EuiBadge
color="hollow"
onClick={handleSkipSetup}
onClickAriaLabel={i18n.CONNECTOR_SETUP_SKIP}
>
{i18n.CONNECTOR_SETUP_SKIP}
</EuiBadge>
</EuiTextAlign>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,6 @@ export const CONNECTOR_SETUP_TIMESTAMP_AT = i18n.translate(
export const CONNECTOR_SETUP_SKIP = i18n.translate(
'xpack.elasticAssistant.assistant.connectors.setup.skipTitle',
{
defaultMessage: "Press 'space' to skip...",
defaultMessage: 'Click to skip...',
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ export const WELCOME_GENERAL_3 = i18n.translate(
'xpack.elasticAssistant.securityAssistant.content.prompts.welcome.welcomeGeneral3Prompt',
{
defaultMessage:
'Go ahead and click the add connector button below, or just press the `space-bar` for that quick action! 💨',
'Go ahead and click the add connector button below to continue the conversation!',
}
);

0 comments on commit 71f0da8

Please sign in to comment.