-
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.
Revert "[ML] Transforms: Deprecate custom KibanaContext. (#59133)"
This reverts commit 29975fa.
- Loading branch information
Showing
31 changed files
with
937 additions
and
3,114 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
8 changes: 0 additions & 8 deletions
8
x-pack/legacy/plugins/transform/public/app/hooks/use_search_items/index.ts
This file was deleted.
Oops, something went wrong.
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
17 changes: 17 additions & 0 deletions
17
x-pack/legacy/plugins/transform/public/app/lib/kibana/index.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,17 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { getIndexPatternIdByTitle, loadIndexPatterns } from './common'; | ||
export { | ||
useKibanaContext, | ||
InitializedKibanaContextValue, | ||
KibanaContext, | ||
KibanaContextValue, | ||
SavedSearchQuery, | ||
RenderOnlyWithInitializedKibanaContext, | ||
} from './kibana_context'; | ||
export { KibanaProvider } from './kibana_provider'; | ||
export { useCurrentIndexPattern } from './use_current_index_pattern'; |
72 changes: 72 additions & 0 deletions
72
x-pack/legacy/plugins/transform/public/app/lib/kibana/kibana_context.tsx
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,72 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React, { createContext, useContext, FC } from 'react'; | ||
|
||
import { IUiSettingsClient } from 'kibana/public'; | ||
|
||
import { | ||
IndexPattern, | ||
IndexPatternsContract, | ||
} from '../../../../../../../../src/plugins/data/public'; | ||
import { SavedSearch } from '../../../../../../../../src/plugins/discover/public/'; | ||
|
||
interface UninitializedKibanaContextValue { | ||
initialized: false; | ||
} | ||
|
||
export interface InitializedKibanaContextValue { | ||
combinedQuery: any; | ||
indexPatterns: IndexPatternsContract; | ||
initialized: true; | ||
kibanaConfig: IUiSettingsClient; | ||
currentIndexPattern: IndexPattern; | ||
currentSavedSearch?: SavedSearch; | ||
} | ||
|
||
export type KibanaContextValue = UninitializedKibanaContextValue | InitializedKibanaContextValue; | ||
|
||
export function isKibanaContextInitialized(arg: any): arg is InitializedKibanaContextValue { | ||
return arg.initialized; | ||
} | ||
|
||
export type SavedSearchQuery = object; | ||
|
||
export const KibanaContext = createContext<KibanaContextValue>({ initialized: false }); | ||
|
||
/** | ||
* Custom hook to get the current kibanaContext. | ||
* | ||
* @remarks | ||
* This hook should only be used in components wrapped in `RenderOnlyWithInitializedKibanaContext`, | ||
* otherwise it will throw an error when KibanaContext hasn't been initialized yet. | ||
* In return you get the benefit of not having to check if it's been initialized in the component | ||
* where it's used. | ||
* | ||
* @returns `kibanaContext` | ||
*/ | ||
export const useKibanaContext = () => { | ||
const kibanaContext = useContext(KibanaContext); | ||
|
||
if (!isKibanaContextInitialized(kibanaContext)) { | ||
throw new Error('useKibanaContext: kibanaContext not initialized'); | ||
} | ||
|
||
return kibanaContext; | ||
}; | ||
|
||
/** | ||
* Wrapper component to render children only if `kibanaContext` has been initialized. | ||
* In combination with `useKibanaContext` this avoids having to check for the initialization | ||
* in consuming components. | ||
* | ||
* @returns `children` or `null` depending on whether `kibanaContext` is initialized or not. | ||
*/ | ||
export const RenderOnlyWithInitializedKibanaContext: FC = ({ children }) => { | ||
const kibanaContext = useContext(KibanaContext); | ||
|
||
return isKibanaContextInitialized(kibanaContext) ? <>{children}</> : null; | ||
}; |
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
19 changes: 19 additions & 0 deletions
19
x-pack/legacy/plugins/transform/public/app/lib/kibana/use_current_index_pattern.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,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { useContext } from 'react'; | ||
|
||
import { isKibanaContextInitialized, KibanaContext } from './kibana_context'; | ||
|
||
export const useCurrentIndexPattern = () => { | ||
const context = useContext(KibanaContext); | ||
|
||
if (!isKibanaContextInitialized(context)) { | ||
throw new Error('useCurrentIndexPattern: kibanaContext not initialized'); | ||
} | ||
|
||
return context.currentIndexPattern; | ||
}; |
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
Oops, something went wrong.