Skip to content
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

[ML] Removes EUI super date picker custom fix, it's now in EUI itself. #45246

Merged
merged 5 commits into from
Sep 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import { mount, shallow } from 'enzyme';
import React from 'react';

import { EuiSuperDatePicker } from '@elastic/eui';

import { uiTimefilterMock } from '../../../contexts/ui/__mocks__/mocks';
import { mlTimefilterRefresh$ } from '../../../services/timefilter_refresh_service';

import { MlSuperDatePickerWithUpdate, TopNav } from './top_nav';
import { TopNav } from './top_nav';

uiTimefilterMock.enableAutoRefreshSelector();
uiTimefilterMock.enableTimeRangeSelector();
Expand Down Expand Up @@ -39,20 +41,14 @@ describe('Navigation Menu: <TopNav />', () => {
refreshSubscription.unsubscribe();
});

// The following tests are written against MlSuperDatePickerWithUpdate
// instead of TopNav. TopNav uses hooks and we cannot writing tests
// The following tests are written against EuiSuperDatePicker
// instead of TopNav. TopNav uses hooks and we cannot write tests
// with async hook updates yet until React 16.9 is available.

// MlSuperDatePickerWithUpdate fixes an issue with EuiSuperDatePicker
// which didn't make it into Kibana 7.4. We should be able to just
// use EuiSuperDatePicker again once the following PR is in EUI:
// https://github.com/elastic/eui/pull/2298

test('Listen for consecutive super date picker refreshs.', async () => {
const onRefresh = jest.fn();

const componentRefresh = mount(
<MlSuperDatePickerWithUpdate
<EuiSuperDatePicker
onTimeChange={noop}
isPaused={false}
onRefresh={onRefresh}
Expand All @@ -76,7 +72,7 @@ describe('Navigation Menu: <TopNav />', () => {
const onRefresh = jest.fn();

const componentRefresh = mount(
<MlSuperDatePickerWithUpdate
<EuiSuperDatePicker
onTimeChange={noop}
isPaused={false}
onRefresh={onRefresh}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Component, FC, Fragment, useState, useEffect } from 'react';
import React, { FC, Fragment, useState, useEffect } from 'react';
import { Subscription } from 'rxjs';
import { EuiSuperDatePicker, EuiSuperDatePickerProps } from '@elastic/eui';
import { EuiSuperDatePicker } from '@elastic/eui';
import { TimeHistory } from 'ui/timefilter';
import { TimeRange } from 'src/plugins/data/public';

import { mlTimefilterRefresh$ } from '../../../services/timefilter_refresh_service';
import { useUiContext } from '../../../contexts/ui/use_ui_context';

interface ComponentWithConstructor<T> extends Component {
new (): Component<T>;
}

const MlSuperDatePicker = (EuiSuperDatePicker as any) as ComponentWithConstructor<
EuiSuperDatePickerProps
>;

// This part fixes a problem with EuiSuperDater picker where it would not reflect
// a prop change of isPaused on the internal interval. This fix will be released
// with EUI 13.7.0 but only 13.6.1 without the fix made it into Kibana 7.4 so
// it's copied here.
export class MlSuperDatePickerWithUpdate extends MlSuperDatePicker {
componentDidUpdate = () => {
// @ts-ignore
this.stopInterval();
if (!this.props.isPaused) {
// @ts-ignore
this.startInterval(this.props.refreshInterval);
}
};
}

interface Duration {
start: string;
end: string;
Expand Down Expand Up @@ -120,7 +97,7 @@ export const TopNav: FC = () => {
<Fragment>
{(isAutoRefreshSelectorEnabled || isTimeRangeSelectorEnabled) && (
<div className="mlNavigationMenu__topNav">
<MlSuperDatePickerWithUpdate
<EuiSuperDatePicker
start={time.from}
end={time.to}
isPaused={refreshInterval.pause}
Expand Down