|
6 | 6 | import { EuiErrorBoundary } from '@elastic/eui';
|
7 | 7 | import React, { useEffect, useMemo, useRef, useState } from 'react';
|
8 | 8 | import ReactDOM from 'react-dom';
|
| 9 | +import { Observable } from 'rxjs'; |
9 | 10 | import { IIndexPattern } from '../../../../common';
|
10 | 11 | import { DataSource } from '../../../data_sources/datasource';
|
11 | 12 |
|
@@ -33,30 +34,30 @@ export interface QueryEditorExtensionDependencies {
|
33 | 34 |
|
34 | 35 | export interface QueryEditorExtensionConfig {
|
35 | 36 | /**
|
36 |
| - * The id for the search bar extension. |
| 37 | + * The id for the query editor extension. |
37 | 38 | */
|
38 | 39 | id: string;
|
39 | 40 | /**
|
40 | 41 | * Lower order indicates higher position on UI.
|
41 | 42 | */
|
42 | 43 | order: number;
|
43 | 44 | /**
|
44 |
| - * A function that determines if the search bar extension is enabled and should be rendered on UI. |
| 45 | + * A function that determines if the query editor extension is enabled and should be rendered on UI. |
45 | 46 | * @returns whether the extension is enabled.
|
46 | 47 | */
|
47 |
| - isEnabled: (dependencies: QueryEditorExtensionDependencies) => Promise<boolean>; |
| 48 | + isEnabled$: (dependencies: QueryEditorExtensionDependencies) => Observable<boolean>; |
48 | 49 | /**
|
49 |
| - * A function that returns the search bar extension component. The component |
| 50 | + * A function that returns the query editor extension component. The component |
50 | 51 | * will be displayed on top of the query editor in the search bar.
|
51 | 52 | * @param dependencies - The dependencies required for the extension.
|
52 |
| - * @returns The component the search bar extension. |
| 53 | + * @returns The component the query editor extension. |
53 | 54 | */
|
54 | 55 | getComponent?: (dependencies: QueryEditorExtensionDependencies) => React.ReactElement | null;
|
55 | 56 | /**
|
56 |
| - * A function that returns the search bar extension banner. The banner is a |
| 57 | + * A function that returns the query editor extension banner. The banner is a |
57 | 58 | * component that will be displayed on top of the search bar.
|
58 | 59 | * @param dependencies - The dependencies required for the extension.
|
59 |
| - * @returns The component the search bar extension. |
| 60 | + * @returns The component the query editor extension. |
60 | 61 | */
|
61 | 62 | getBanner?: (dependencies: QueryEditorExtensionDependencies) => React.ReactElement | null;
|
62 | 63 | }
|
@@ -92,9 +93,10 @@ export const QueryEditorExtension: React.FC<QueryEditorExtensionProps> = (props)
|
92 | 93 | }, []);
|
93 | 94 |
|
94 | 95 | useEffect(() => {
|
95 |
| - props.config.isEnabled(props.dependencies).then((enabled) => { |
| 96 | + const subscription = props.config.isEnabled$(props.dependencies).subscribe((enabled) => { |
96 | 97 | if (isMounted.current) setIsEnabled(enabled);
|
97 | 98 | });
|
| 99 | + return () => subscription.unsubscribe(); |
98 | 100 | }, [props.dependencies, props.config]);
|
99 | 101 |
|
100 | 102 | if (!isEnabled) return null;
|
|
0 commit comments