Skip to content

Commit 528bf32

Browse files
committed
[ML] Fix the limit control on the Anomaly explorer page (#65459)
* [ML] persist limit control value * [ML] remove console statement * [ML] fix default value
1 parent a755c2e commit 528bf32

3 files changed

Lines changed: 5 additions & 12 deletions

File tree

x-pack/plugins/ml/public/application/explorer/explorer.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { i18n } from '@kbn/i18n';
1414
import { FormattedMessage } from '@kbn/i18n/react';
1515
import DragSelect from 'dragselect/dist/ds.min.js';
1616
import { Subject } from 'rxjs';
17-
import { map, takeUntil } from 'rxjs/operators';
17+
import { takeUntil } from 'rxjs/operators';
1818

1919
import {
2020
EuiFlexGroup,
@@ -169,12 +169,7 @@ export class Explorer extends React.Component {
169169
};
170170

171171
componentDidMount() {
172-
limit$
173-
.pipe(
174-
takeUntil(this._unsubscribeAll),
175-
map(d => d.val)
176-
)
177-
.subscribe(explorerService.setSwimlaneLimit);
172+
limit$.pipe(takeUntil(this._unsubscribeAll)).subscribe(explorerService.setSwimlaneLimit);
178173

179174
// Required to redraw the time series chart when the container is resized.
180175
this.resizeChecker = new ResizeChecker(this.resizeRef.current);

x-pack/plugins/ml/public/application/explorer/select_limit/select_limit.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import { act } from 'react-dom/test-utils';
99
import { shallow } from 'enzyme';
1010
import { SelectLimit } from './select_limit';
1111

12-
jest.useFakeTimers();
13-
1412
describe('SelectLimit', () => {
1513
test('creates correct initial selected value', () => {
1614
const wrapper = shallow(<SelectLimit />);

x-pack/plugins/ml/public/application/explorer/select_limit/select_limit.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010
import React from 'react';
1111
import useObservable from 'react-use/lib/useObservable';
12-
import { Subject } from 'rxjs';
12+
import { BehaviorSubject } from 'rxjs';
1313

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

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

23-
export const limit$ = new Subject<number>();
2423
export const defaultLimit = limitOptions[1];
24+
export const limit$ = new BehaviorSubject<number>(defaultLimit);
2525

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

29-
return [limit, (newLimit: number) => limit$.next(newLimit)];
29+
return [limit!, (newLimit: number) => limit$.next(newLimit)];
3030
};
3131

3232
export const SelectLimit = () => {

0 commit comments

Comments
 (0)