-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/elastic/kibana into alert…
…ing/default-es-index-schema
- Loading branch information
Showing
56 changed files
with
1,004 additions
and
857 deletions.
There are no files selected for viewing
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
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
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
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]}> | ||
{badgeText[performanceRating]} | ||
</EuiBadge> | ||
); | ||
}; |
Oops, something went wrong.