forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Converts full time range selector control to EUI / React (elasti…
…c#35074) * [ML] Converts full time range selector control to EUI / React * [ML] Remove console log from time range selector service * [ML] Fix linting errors in full time range selector ts files * [ML] Switch to using I18nContext in wrapping directive * [ML] Remove unnecessary return from setFullTimeRange * [ML] Add setFullTimeRange return back in for clone job settings
- Loading branch information
1 parent
dee396e
commit 02bde32
Showing
18 changed files
with
200 additions
and
97 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
...k/plugins/ml/public/components/full_time_range_selector/__snapshots__/index.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
x-pack/plugins/ml/public/components/full_time_range_selector/full_time_range_selector.html
This file was deleted.
Oops, something went wrong.
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
40 changes: 0 additions & 40 deletions
40
...plugins/ml/public/components/full_time_range_selector/full_time_range_selector_service.js
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...plugins/ml/public/components/full_time_range_selector/full_time_range_selector_service.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,36 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import moment from 'moment'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
import { Query } from 'ui/embeddable'; | ||
import { IndexPattern } from 'ui/index_patterns'; | ||
import { toastNotifications } from 'ui/notify'; | ||
import { timefilter } from 'ui/timefilter'; | ||
import { ml } from '../../services/ml_api_service'; | ||
|
||
export function setFullTimeRange(indexPattern: IndexPattern, query: Query) { | ||
return ml | ||
.getTimeFieldRange({ | ||
index: indexPattern.title, | ||
timeFieldName: indexPattern.timeFieldName, | ||
query, | ||
}) | ||
.then(resp => { | ||
timefilter.setTime({ | ||
from: moment(resp.start.epoch).toISOString(), | ||
to: moment(resp.end.epoch).toISOString(), | ||
}); | ||
}) | ||
.catch(resp => { | ||
toastNotifications.addDanger( | ||
i18n.translate('xpack.ml.fullTimeRangeSelector.errorSettingTimeRangeNotification', { | ||
defaultMessage: 'An error occurred setting the time range.', | ||
}) | ||
); | ||
}); | ||
} |
10 changes: 0 additions & 10 deletions
10
x-pack/plugins/ml/public/components/full_time_range_selector/index.js
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
x-pack/plugins/ml/public/components/full_time_range_selector/index.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,62 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { shallowWithIntl } from 'test_utils/enzyme_helpers'; | ||
|
||
import { Query } from 'ui/embeddable'; | ||
import { QueryLanguageType } from 'ui/embeddable/types'; | ||
import { IndexPattern } from 'ui/index_patterns'; | ||
import { FullTimeRangeSelector } from './index'; | ||
|
||
// Create a mock for the setFullTimeRange function in the service. | ||
// The mock is hoisted to the top, so need to prefix the mock function | ||
// with 'mock' so it can be used lazily. | ||
const mockSetFullTimeRange = jest.fn((indexPattern: IndexPattern, query: Query) => true); | ||
jest.mock('./full_time_range_selector_service', () => ({ | ||
setFullTimeRange: (indexPattern: IndexPattern, query: Query) => | ||
mockSetFullTimeRange(indexPattern, query), | ||
})); | ||
|
||
describe('FullTimeRangeSelector', () => { | ||
const indexPattern: IndexPattern = { | ||
id: '0844fc70-5ab5-11e9-935e-836737467b0f', | ||
fields: [], | ||
title: 'test-index-pattern', | ||
timeFieldName: '@timestamp', | ||
}; | ||
|
||
const query: Query = { | ||
language: QueryLanguageType.KUERY, | ||
query: 'region:us-east-1', | ||
}; | ||
|
||
const requiredProps = { | ||
indexPattern, | ||
query, | ||
}; | ||
|
||
test('renders the selector', () => { | ||
const props = { | ||
...requiredProps, | ||
disabled: false, | ||
}; | ||
|
||
const wrapper = shallowWithIntl(<FullTimeRangeSelector {...props} />); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
test('calls setFullTimeRange on clicking button', () => { | ||
const props = { | ||
...requiredProps, | ||
disabled: false, | ||
}; | ||
|
||
const wrapper = shallowWithIntl(<FullTimeRangeSelector {...props} />); | ||
wrapper.find('EuiButton').simulate('click'); | ||
expect(mockSetFullTimeRange).toHaveBeenCalled(); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
x-pack/plugins/ml/public/components/full_time_range_selector/index.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,35 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
|
||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { Query } from 'ui/embeddable'; | ||
import { IndexPattern } from 'ui/index_patterns'; | ||
import { EuiButton } from '@elastic/eui'; | ||
import { setFullTimeRange } from './full_time_range_selector_service'; | ||
|
||
interface Props { | ||
indexPattern: IndexPattern; | ||
query: Query; | ||
disabled: boolean; | ||
} | ||
|
||
// Component for rendering a button which automatically sets the range of the time filter | ||
// to the time range of data in the index(es) mapped to the supplied Kibana index pattern or query. | ||
export const FullTimeRangeSelector: React.SFC<Props> = ({ indexPattern, query, disabled }) => { | ||
return ( | ||
<EuiButton fill isDisabled={disabled} onClick={() => setFullTimeRange(indexPattern, query)}> | ||
<FormattedMessage | ||
id="xpack.ml.fullTimeRangeSelector.useFullDataButtonLabel" | ||
defaultMessage="Use full {indexPatternTitle} data" | ||
values={{ | ||
indexPatternTitle: indexPattern.title, | ||
}} | ||
/> | ||
</EuiButton> | ||
); | ||
}; |
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
Oops, something went wrong.