-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[App Search] Added a query performance rating to the Result Settings page #96230
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
...arch/public/applications/app_search/components/result_settings/query_performance/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { QueryPerformance } from './query_performance'; |
59 changes: 59 additions & 0 deletions
59
...ations/app_search/components/result_settings/query_performance/query_performance.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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 { setMockValues } from '../../../../__mocks__/kea.mock'; | ||
|
||
import React from 'react'; | ||
|
||
import { shallow } from 'enzyme'; | ||
|
||
import { EuiBadge } from '@elastic/eui'; | ||
|
||
import { QueryPerformance } from './query_performance'; | ||
|
||
describe('QueryPerformance', () => { | ||
const values = { | ||
queryPerformanceScore: 1, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
setMockValues(values); | ||
}); | ||
|
||
it('renders as green with the text "optimal" for a performance score of less than 6', () => { | ||
const wrapper = shallow(<QueryPerformance />); | ||
expect(wrapper.find(EuiBadge).prop('color')).toEqual('#59deb4'); | ||
expect(wrapper.find(EuiBadge).children().text()).toEqual('Query performance: optimal'); | ||
}); | ||
|
||
it('renders as blue with the text "good" for a performance score of less than 11', () => { | ||
setMockValues({ | ||
queryPerformanceScore: 10, | ||
}); | ||
const wrapper = shallow(<QueryPerformance />); | ||
expect(wrapper.find(EuiBadge).prop('color')).toEqual('#40bfff'); | ||
expect(wrapper.find(EuiBadge).children().text()).toEqual('Query performance: good'); | ||
}); | ||
|
||
it('renders as yellow with the text "standard" for a performance score of less than 21', () => { | ||
setMockValues({ | ||
queryPerformanceScore: 20, | ||
}); | ||
const wrapper = shallow(<QueryPerformance />); | ||
expect(wrapper.find(EuiBadge).prop('color')).toEqual('#fed566'); | ||
expect(wrapper.find(EuiBadge).children().text()).toEqual('Query performance: standard'); | ||
}); | ||
|
||
it('renders as red with the text "delayed" for a performance score of 21 or more', () => { | ||
setMockValues({ | ||
queryPerformanceScore: 100, | ||
}); | ||
const wrapper = shallow(<QueryPerformance />); | ||
expect(wrapper.find(EuiBadge).prop('color')).toEqual('#ff9173'); | ||
expect(wrapper.find(EuiBadge).children().text()).toEqual('Query performance: delayed'); | ||
}); | ||
}); |
87 changes: 87 additions & 0 deletions
87
...pplications/app_search/components/result_settings/query_performance/query_performance.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* 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 React from 'react'; | ||
|
||
import { useValues } from 'kea'; | ||
|
||
import { EuiBadge } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { ResultSettingsLogic } from '../result_settings_logic'; | ||
|
||
enum QueryPerformanceRating { | ||
Optimal = 'Optimal', | ||
Good = 'Good', | ||
Standard = 'Standard', | ||
Delayed = 'Delayed', | ||
} | ||
|
||
const QUERY_PERFORMANCE_LABEL = (performanceValue: string) => | ||
i18n.translate('xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformanceLabel', { | ||
defaultMessage: 'Query performance: {performanceValue}', | ||
values: { | ||
performanceValue, | ||
}, | ||
}); | ||
|
||
const QUERY_PERFORMANCE_OPTIMAL = i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformance.optimalValue', | ||
{ defaultMessage: 'optimal' } | ||
); | ||
|
||
const QUERY_PERFORMANCE_GOOD = i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformance.goodValue', | ||
{ defaultMessage: 'good' } | ||
); | ||
|
||
const QUERY_PERFORMANCE_STANDARD = i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformance.standardValue', | ||
{ defaultMessage: 'standard' } | ||
); | ||
|
||
const QUERY_PERFORMANCE_DELAYED = i18n.translate( | ||
'xpack.enterpriseSearch.appSearch.engine.resultSettings.queryPerformance.delayedValue', | ||
{ defaultMessage: 'delayed' } | ||
); | ||
|
||
const badgeText: Record<QueryPerformanceRating, string> = { | ||
[QueryPerformanceRating.Optimal]: QUERY_PERFORMANCE_LABEL(QUERY_PERFORMANCE_OPTIMAL), | ||
[QueryPerformanceRating.Good]: QUERY_PERFORMANCE_LABEL(QUERY_PERFORMANCE_GOOD), | ||
[QueryPerformanceRating.Standard]: QUERY_PERFORMANCE_LABEL(QUERY_PERFORMANCE_STANDARD), | ||
[QueryPerformanceRating.Delayed]: QUERY_PERFORMANCE_LABEL(QUERY_PERFORMANCE_DELAYED), | ||
}; | ||
|
||
const badgeColors: Record<QueryPerformanceRating, string> = { | ||
[QueryPerformanceRating.Optimal]: '#59deb4', | ||
[QueryPerformanceRating.Good]: '#40bfff', | ||
[QueryPerformanceRating.Standard]: '#fed566', | ||
[QueryPerformanceRating.Delayed]: '#ff9173', | ||
}; | ||
|
||
const getPerformanceRating = (score: number) => { | ||
switch (true) { | ||
case score < 6: | ||
return QueryPerformanceRating.Optimal; | ||
case score < 11: | ||
return QueryPerformanceRating.Good; | ||
case score < 21: | ||
return QueryPerformanceRating.Standard; | ||
default: | ||
return QueryPerformanceRating.Delayed; | ||
} | ||
}; | ||
|
||
export const QueryPerformance: React.FC = () => { | ||
const { queryPerformanceScore } = useValues(ResultSettingsLogic); | ||
const performanceRating = getPerformanceRating(queryPerformanceScore); | ||
return ( | ||
<EuiBadge role="region" aria-live="polite" color={badgeColors[performanceRating]}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sweeeeet! |
||
{badgeText[performanceRating]} | ||
</EuiBadge> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whoa TIL
switch (true)
🤯