-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ML] Propagate execution context (#131374)
* report execution context for routes * report execution context for routes * useExecutionContext for embeddable swim lane * useExecutionContext for embeddable anomaly charts * fix activeRoute * refactor
- Loading branch information
Showing
5 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
x-pack/plugins/ml/public/embeddables/common/use_embeddable_execution_context.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import useObservable from 'react-use/lib/useObservable'; | ||
import { map } from 'rxjs/operators'; | ||
import { KibanaExecutionContext } from '@kbn/core/types'; | ||
import { useMemo } from 'react'; | ||
import { useExecutionContext } from '@kbn/kibana-react-plugin/public'; | ||
import type { Observable } from 'rxjs'; | ||
import type { EmbeddableInput } from '@kbn/embeddable-plugin/common'; | ||
import { ExecutionContextStart } from '@kbn/core/public'; | ||
|
||
/** | ||
* Use execution context for ML embeddables. | ||
* @param executionContext | ||
* @param embeddableInput$ | ||
* @param embeddableType | ||
* @param id | ||
*/ | ||
export function useEmbeddableExecutionContext<T extends EmbeddableInput>( | ||
executionContext: ExecutionContextStart, | ||
embeddableInput$: Observable<T>, | ||
embeddableType: string, | ||
id: string | ||
) { | ||
const parentExecutionContext = useObservable( | ||
embeddableInput$.pipe(map((v) => v.executionContext)) | ||
); | ||
|
||
const embeddableExecutionContext: KibanaExecutionContext = useMemo(() => { | ||
const child: KibanaExecutionContext = { | ||
type: 'visualization', | ||
name: embeddableType, | ||
id, | ||
}; | ||
|
||
return { | ||
...parentExecutionContext, | ||
child, | ||
}; | ||
}, [parentExecutionContext, id]); | ||
|
||
useExecutionContext(executionContext, embeddableExecutionContext); | ||
} |