Skip to content

Commit

Permalink
[ML] Fix the limit control on the Anomaly explorer page (elastic#65459)
Browse files Browse the repository at this point in the history
* [ML] persist limit control value

* [ML] remove console statement

* [ML] fix default value
  • Loading branch information
darnautov committed May 7, 2020
1 parent a755c2e commit 528bf32
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
9 changes: 2 additions & 7 deletions x-pack/plugins/ml/public/application/explorer/explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import DragSelect from 'dragselect/dist/ds.min.js';
import { Subject } from 'rxjs';
import { map, takeUntil } from 'rxjs/operators';
import { takeUntil } from 'rxjs/operators';

import {
EuiFlexGroup,
Expand Down Expand Up @@ -169,12 +169,7 @@ export class Explorer extends React.Component {
};

componentDidMount() {
limit$
.pipe(
takeUntil(this._unsubscribeAll),
map(d => d.val)
)
.subscribe(explorerService.setSwimlaneLimit);
limit$.pipe(takeUntil(this._unsubscribeAll)).subscribe(explorerService.setSwimlaneLimit);

// Required to redraw the time series chart when the container is resized.
this.resizeChecker = new ResizeChecker(this.resizeRef.current);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import { act } from 'react-dom/test-utils';
import { shallow } from 'enzyme';
import { SelectLimit } from './select_limit';

jest.useFakeTimers();

describe('SelectLimit', () => {
test('creates correct initial selected value', () => {
const wrapper = shallow(<SelectLimit />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
import React from 'react';
import useObservable from 'react-use/lib/useObservable';
import { Subject } from 'rxjs';
import { BehaviorSubject } from 'rxjs';

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

Expand All @@ -20,13 +20,13 @@ const euiOptions = limitOptions.map(limit => ({
text: `${limit}`,
}));

export const limit$ = new Subject<number>();
export const defaultLimit = limitOptions[1];
export const limit$ = new BehaviorSubject<number>(defaultLimit);

export const useSwimlaneLimit = (): [number, (newLimit: number) => void] => {
const limit = useObservable(limit$, defaultLimit);

return [limit, (newLimit: number) => limit$.next(newLimit)];
return [limit!, (newLimit: number) => limit$.next(newLimit)];
};

export const SelectLimit = () => {
Expand Down

0 comments on commit 528bf32

Please sign in to comment.