-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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] Fix Anomaly Swim Lane Embeddable not updating properly on query change #195090
Changes from 8 commits
31cf041
aca7988
133ece2
c2e7e9e
868dd88
fdcfc26
5a95ba0
ab9b445
55c3e67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import { | |
apiHasExecutionContext, | ||
apiHasParentApi, | ||
apiPublishesTimeRange, | ||
fetch$, | ||
initializeTimeRange, | ||
initializeTitles, | ||
useBatchedPublishingSubjects, | ||
|
@@ -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'; | ||
|
@@ -235,6 +237,19 @@ export const getAnomalySwimLaneEmbeddableFactory = ( | |
anomalySwimLaneServices | ||
); | ||
|
||
const fetchSubscription = fetch$(api) | ||
.pipe( | ||
map((fetchContext) => ({ | ||
query: fetchContext.query, | ||
filters: fetchContext.filters, | ||
timeRange: fetchContext.timeRange, | ||
})), | ||
distinctUntilChanged(fastIsEqual) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: I presume it's more expensive than skipWhile, because you need to compare objects on every emission instead of checking a boolean value of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed offline, neither |
||
) | ||
.subscribe(() => { | ||
api.updatePagination({ fromPage: 1 }); | ||
}); | ||
|
||
const onRenderComplete = () => {}; | ||
|
||
return { | ||
|
@@ -260,6 +275,7 @@ export const getAnomalySwimLaneEmbeddableFactory = ( | |
onSwimLaneDestroy(); | ||
onDestroy(); | ||
subscriptions.unsubscribe(); | ||
fetchSubscription.unsubscribe(); | ||
}); | ||
|
||
const [fromPage, perPage, swimlaneType, swimlaneData, error] = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need a dedicated subscription. Try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated in: 55c3e67