Skip to content

Commit fa1b1d6

Browse files
authored
SearchOrAskAI UX adjustments (#1798)
* SearchOrAskAI UX adjustments * Prettier * Fix compontent usage * Run prettier * Use thumbUp and thumbDown icons and adjust suggested questions * Run prettier
1 parent 602bc48 commit fa1b1d6

File tree

7 files changed

+90
-57
lines changed

7 files changed

+90
-57
lines changed

src/Elastic.Documentation.Site/Assets/eui-icons-cache.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { icon as EuiIconNewChat } from '@elastic/eui/es/components/icon/assets/n
1313
import { icon as EuiIconRefresh } from '@elastic/eui/es/components/icon/assets/refresh'
1414
import { icon as EuiIconSearch } from '@elastic/eui/es/components/icon/assets/search'
1515
import { icon as EuiIconSparkles } from '@elastic/eui/es/components/icon/assets/sparkles'
16+
import { icon as EuiIconThumbDown } from '@elastic/eui/es/components/icon/assets/thumbDown'
17+
import { icon as EuiIconThumbUp } from '@elastic/eui/es/components/icon/assets/thumbUp'
1618
import { icon as EuiIconTrash } from '@elastic/eui/es/components/icon/assets/trash'
1719
import { icon as EuiIconUser } from '@elastic/eui/es/components/icon/assets/user'
1820
import { icon as EuiIconWrench } from '@elastic/eui/es/components/icon/assets/wrench'
@@ -37,4 +39,6 @@ appendIconComponentCache({
3739
faceSad: EuiIconFaceSad,
3840
refresh: EuiIconRefresh,
3941
error: EuiIconError,
42+
thumbUp: EuiIconThumbUp,
43+
thumbDown: EuiIconThumbDown,
4044
})

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/AskAi/AskAiAnswer.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
EuiToolTip,
1313
useEuiTheme,
1414
EuiCallOut,
15+
EuiIcon,
1516
} from '@elastic/eui'
1617
import { css } from '@emotion/react'
1718
import * as React from 'react'
@@ -69,6 +70,7 @@ export const AskAiAnswer = () => {
6970
hasShadow={false}
7071
hasBorder={false}
7172
css={css`
73+
flex-grow: 1;
7274
.euiMarkdownFormat {
7375
font-size: ${euiTheme.size.base};
7476
}
@@ -77,15 +79,26 @@ export const AskAiAnswer = () => {
7779
}
7880
`}
7981
>
82+
<div
83+
css={css`
84+
display: flex;
85+
gap: ${euiTheme.size.s};
86+
align-items: center;
87+
`}
88+
>
89+
<EuiIcon type="sparkles" color="subdued" size="s" />
90+
<EuiText size="xs">Ask Elastic Docs AI Assistant</EuiText>
91+
</div>
92+
<EuiSpacer size="s" />
8093
<EuiPanel
8194
panelRef={scrollRef}
8295
paddingSize="m"
8396
hasShadow={false}
8497
hasBorder={false}
8598
css={css`
86-
max-height: 50vh;
87-
overflow-y: scroll;
88-
background-color: ${euiTheme.colors.backgroundBaseSubdued};
99+
//max-height: 50vh;
100+
//overflow-y: scroll;
101+
background-color: ${euiTheme.colors.backgroundLightText};
89102
`}
90103
>
91104
<EuiMarkdownFormat>
@@ -104,7 +117,7 @@ export const AskAiAnswer = () => {
104117
<EuiToolTip content="This answer was helpful">
105118
<EuiButtonIcon
106119
aria-label="This answer was helpful"
107-
iconType="faceHappy"
120+
iconType="thumbUp"
108121
color="success"
109122
/>
110123
</EuiToolTip>
@@ -113,7 +126,7 @@ export const AskAiAnswer = () => {
113126
<EuiToolTip content="This answer was not helpful">
114127
<EuiButtonIcon
115128
aria-label="This answer was not helpful"
116-
iconType="faceSad"
129+
iconType="thumbDown"
117130
color="danger"
118131
/>
119132
</EuiToolTip>
@@ -142,7 +155,7 @@ export const AskAiAnswer = () => {
142155
).length > 0 && <EuiSpacer size="s" />}
143156
<EuiFlexGroup
144157
alignItems="center"
145-
gutterSize="xs"
158+
gutterSize="s"
146159
responsive={false}
147160
>
148161
<EuiFlexItem grow={false}>

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/AskAi/useLlmGateway.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,10 @@ export const useLlmGateway = (props: Props): UseLlmGatewayResponse => {
154154
async (question: string) => {
155155
if (question.trim() && question !== lastSentQuestionRef.current) {
156156
abort()
157-
lastSentQuestionRef.current = question
158157
setError(null)
158+
setMessages([])
159+
clearQueue()
160+
lastSentQuestionRef.current = question
159161
const payload = createLlmGatewayRequest(
160162
question,
161163
props.threadId

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/Search/SearchResults.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
useEuiTheme,
1111
EuiIcon,
1212
EuiPagination,
13+
EuiHorizontalRule,
1314
} from '@elastic/eui'
1415
import { css } from '@emotion/react'
1516
import { useDebounce } from '@uidotdev/usehooks'
@@ -70,14 +71,15 @@ export const SearchResults = () => {
7071
<SearchResultListItem item={result} />
7172
))}
7273
</ul>
74+
<EuiSpacer size="m" />
7375
<div
7476
css={css`
7577
display: flex;
76-
justify-content: flex-end;
78+
justify-content: center;
7779
`}
7880
>
7981
<EuiPagination
80-
aria-label="Many pages example"
82+
aria-label="Search results pages"
8183
pageCount={Math.min(data.pageCount, 10)}
8284
activePage={activePage}
8385
onPageClick={(activePage) =>
@@ -87,6 +89,7 @@ export const SearchResults = () => {
8789
</div>
8890
</>
8991
)}
92+
<EuiHorizontalRule margin="m" />
9093
</div>
9194
)
9295
}
@@ -99,7 +102,11 @@ function SearchResultListItem({ item: result }: SearchResultListItemProps) {
99102
const { euiTheme } = useEuiTheme()
100103
const searchTerm = useSearchTerm()
101104
const highlightSearchTerms = useMemo(
102-
() => searchTerm.toLowerCase().split(' '),
105+
() =>
106+
searchTerm
107+
.toLowerCase()
108+
.split(' ')
109+
.filter((i) => i.length > 1),
103110
[searchTerm]
104111
)
105112

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { AskAiAnswer } from './AskAi/AskAiAnswer'
2+
import { AskAiSuggestions } from './AskAi/AskAiSuggestions'
23
import { SearchResults } from './Search/SearchResults'
3-
import { Suggestions } from './Suggestions'
44
import { useAskAiTerm, useSearchActions, useSearchTerm } from './search.store'
55
import {
66
EuiFieldSearch,
77
EuiSpacer,
88
EuiBetaBadge,
99
EuiText,
1010
EuiHorizontalRule,
11+
useEuiOverflowScroll,
1112
} from '@elastic/eui'
1213
import { css } from '@emotion/react'
1314
import * as React from 'react'
@@ -18,24 +19,59 @@ export const SearchOrAskAiModal = () => {
1819
const { setSearchTerm, submitAskAiTerm } = useSearchActions()
1920

2021
return (
21-
<>
22-
<EuiFieldSearch
23-
fullWidth
24-
placeholder="Search the docs or ask Elastic Docs AI Assistant"
25-
value={searchTerm}
26-
onChange={(e) => setSearchTerm(e.target.value)}
27-
onSearch={(e) => {
28-
submitAskAiTerm(e)
29-
}}
30-
isClearable
31-
autoFocus={true}
32-
/>
33-
<EuiSpacer size="m" />
34-
<SearchResults />
35-
{askAiTerm ? <AskAiAnswer /> : <Suggestions />}
22+
<div
23+
css={css`
24+
display: flex;
25+
flex-direction: column;
26+
`}
27+
>
28+
<div
29+
css={css`
30+
flex-grow: 0;
31+
`}
32+
>
33+
<EuiFieldSearch
34+
fullWidth
35+
placeholder="Search the docs or ask Elastic Docs AI Assistant"
36+
value={searchTerm}
37+
onChange={(e) => setSearchTerm(e.target.value)}
38+
onSearch={(e) => {
39+
submitAskAiTerm(e)
40+
}}
41+
isClearable
42+
autoFocus={true}
43+
/>
44+
<EuiSpacer size="m" />
45+
</div>
46+
<div
47+
css={css`
48+
flex-grow: 1;
49+
overflow-y: scroll;
50+
max-height: 80vh;
51+
${useEuiOverflowScroll('y')}
52+
`}
53+
>
54+
<SearchResults />
55+
{askAiTerm ? (
56+
<AskAiAnswer />
57+
) : (
58+
<AskAiSuggestions
59+
suggestions={[
60+
{ question: 'What is an index template?' },
61+
{ question: 'What is semantic search?' },
62+
{
63+
question:
64+
'How do I create an elasticsearch index?',
65+
},
66+
{ question: 'How do I set up an ingest pipeline?' },
67+
]}
68+
/>
69+
)}
70+
</div>
3671
<EuiHorizontalRule margin="m" />
3772
<div
3873
css={css`
74+
flex-grow: 0;
3975
display: flex;
4076
align-items: center;
4177
gap: calc(var(--spacing) * 2);
@@ -56,6 +92,6 @@ export const SearchOrAskAiModal = () => {
5692
This feature is in beta. Got feedback? We'd love to hear it!
5793
</EuiText>
5894
</div>
59-
</>
95+
</div>
6096
)
6197
}

src/Elastic.Documentation.Site/Assets/web-components/SearchOrAskAi/Suggestions.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/api/Elastic.Documentation.Api.Core/AskAi/AskAiUsecase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public record AskAiRequest(string Message, string? ThreadId)
2828
- Handling Unknowns: If the information required to answer the question is not present in the provided documents, you must explicitly state that the answer cannot be found. Do not attempt to guess, infer, or provide a general response.
2929
- Helpful Fallback: If you cannot find a direct answer, you may suggest and link to a few related or similar topics that are present in the documentation. This provides value even when a direct answer is unavailable.
3030
- Output Format: Your final response should be a single, coherent block of text.
31+
- Short and Concise: Keep your answers as brief as possible while still being complete and informative. For more more details refer to the documentation with links.
3132
3233
## Negative Constraints:
3334

0 commit comments

Comments
 (0)