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

[8.x] [ML] Fix Anomaly Swim Lane Embeddable not updating properly on query change (#195090) #195725

Merged
merged 1 commit into from
Oct 10, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
apiHasExecutionContext,
apiHasParentApi,
apiPublishesTimeRange,
fetch$,
initializeTimeRange,
initializeTitles,
useBatchedPublishingSubjects,
Expand All @@ -26,7 +27,8 @@ import { KibanaRenderContextProvider } from '@kbn/react-kibana-context-render';
import React, { useCallback, useState } from 'react';
import useUnmount from 'react-use/lib/useUnmount';
import type { Observable } from 'rxjs';
import { BehaviorSubject, combineLatest, map, of, Subscription } from 'rxjs';
import { BehaviorSubject, combineLatest, distinctUntilChanged, map, of, Subscription } from 'rxjs';
import fastIsEqual from 'fast-deep-equal';
import type { AnomalySwimlaneEmbeddableServices } from '..';
import { ANOMALY_SWIMLANE_EMBEDDABLE_TYPE } from '..';
import type { MlDependencies } from '../../application/app';
Expand Down Expand Up @@ -235,6 +237,21 @@ export const getAnomalySwimLaneEmbeddableFactory = (
anomalySwimLaneServices
);

subscriptions.add(
fetch$(api)
.pipe(
map((fetchContext) => ({
query: fetchContext.query,
filters: fetchContext.filters,
timeRange: fetchContext.timeRange,
})),
distinctUntilChanged(fastIsEqual)
)
.subscribe(() => {
api.updatePagination({ fromPage: 1 });
})
);

const onRenderComplete = () => {};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import type { estypes } from '@elastic/elasticsearch';
import type { TimeRange } from '@kbn/es-query';
import { type TimeRange } from '@kbn/es-query';
import type { PublishesUnifiedSearch } from '@kbn/presentation-publishing';
import {
BehaviorSubject,
Expand All @@ -29,7 +29,6 @@ import {
SWIMLANE_TYPE,
} from '../../application/explorer/explorer_constants';
import type { OverallSwimlaneData } from '../../application/explorer/explorer_utils';
import { isViewBySwimLaneData } from '../../application/explorer/swimlane_container';
import { CONTROLLED_BY_SWIM_LANE_FILTER } from '../../ui_actions/constants';
import { getJobsObservable } from '../common/get_jobs_observable';
import { processFilters } from '../common/process_filters';
Expand Down Expand Up @@ -114,12 +113,7 @@ export const initializeSwimLaneDataFetcher = (
const { earliest, latest } = overallSwimlaneData;

if (overallSwimlaneData && swimlaneType === SWIMLANE_TYPE.VIEW_BY) {
const swimlaneData = swimLaneData$.value;

let swimLaneLimit = ANOMALY_SWIM_LANE_HARD_LIMIT;
if (isViewBySwimLaneData(swimlaneData) && viewBy === swimlaneData.fieldName) {
swimLaneLimit = swimlaneData.cardinality;
}
const swimLaneLimit = ANOMALY_SWIM_LANE_HARD_LIMIT;

return from(
anomalyTimelineService.loadViewBySwimlane(
Expand Down