({
translations = {},
askAiState,
onAskAiToggle,
setAskAiState,
...props
}: SearchBoxProps)
| 62 | } |
| 63 | |
| 64 | export function SearchBox({ |
| 65 | translations = {}, |
| 66 | askAiState, |
| 67 | onAskAiToggle, |
| 68 | setAskAiState, |
| 69 | ...props |
| 70 | }: SearchBoxProps): JSX.Element { |
| 71 | const { |
| 72 | clearButtonTitle = 'Clear', |
| 73 | clearButtonAriaLabel = 'Clear the query', |
| 74 | closeButtonText = 'Close', |
| 75 | closeButtonAriaLabel = 'Close', |
| 76 | searchInputLabel = 'Search', |
| 77 | backToKeywordSearchButtonText = 'Back to keyword search', |
| 78 | backToKeywordSearchButtonAriaLabel = 'Back to keyword search', |
| 79 | placeholderTextAskAiStreaming = 'Answering...', |
| 80 | newConversationPlaceholder = 'Ask a question', |
| 81 | conversationHistoryTitle = 'My conversation history', |
| 82 | startNewConversationText = 'Start a new conversation', |
| 83 | viewConversationHistoryText = 'Conversation history', |
| 84 | threadDepthErrorPlaceholder = 'Conversation limit reached', |
| 85 | } = translations; |
| 86 | const { onReset } = props.getFormProps({ |
| 87 | inputElement: props.inputRef.current, |
| 88 | }); |
| 89 | |
| 90 | React.useEffect(() => { |
| 91 | if (props.autoFocus && props.inputRef.current) { |
| 92 | props.inputRef.current.focus(); |
| 93 | } |
| 94 | }, [props.autoFocus, props.inputRef]); |
| 95 | |
| 96 | React.useEffect(() => { |
| 97 | if (props.isFromSelection && props.inputRef.current) { |
| 98 | props.inputRef.current.select(); |
| 99 | } |
| 100 | }, [props.isFromSelection, props.inputRef]); |
| 101 | |
| 102 | const hasRecentConversations = React.useMemo(() => { |
| 103 | const askAiSource = props.state.collections[2]; |
| 104 | |
| 105 | if (!askAiSource) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | return askAiSource.items.length > 0; |
| 110 | }, [props.state.collections]); |
| 111 | |
| 112 | const baseInputProps = props.getInputProps({ |
| 113 | inputElement: props.inputRef.current!, |
| 114 | autoFocus: props.autoFocus, |
| 115 | maxLength: MAX_QUERY_SIZE, |
| 116 | }); |
| 117 | |
| 118 | const blockedKeys = new Set(['ArrowUp', 'ArrowDown', 'Enter']); |
| 119 | const origOnKeyDown = baseInputProps.onKeyDown; |
| 120 | const origOnChange = baseInputProps.onChange; |
| 121 | const isAskAiStreaming = props.askAiStatus === 'streaming' || props.askAiStatus === 'submitted'; |
nothing calls this directly
no outgoing calls
no test coverage detected