Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -38,6 +38,6 @@ const {
injectGlobal,
keyframes,
withTheme,
} = styledComponents as ThemedStyledComponentsModule<EuiTheme>;
} = (styledComponents as unknown) as ThemedStyledComponentsModule<EuiTheme>;

export { css, euiStyled, EuiThemeProvider, injectGlobal, keyframes, withTheme };
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { EuiLink } from '@elastic/eui';
import React from 'react';
import React, { useEffect } from 'react';
import ReactDOM from 'react-dom';
import chrome from 'ui/chrome';

Expand All @@ -20,17 +20,21 @@ const Content: React.FC<HelpCenterContentProps> = ({ feedbackLink, feedbackLinkT
</EuiLink>
);

export class HelpCenterContent extends React.Component<HelpCenterContentProps> {
public componentDidMount = () => {
export const HelpCenterContent: React.FC<HelpCenterContentProps> = ({
feedbackLink,
feedbackLinkText,
}) => {
useEffect(() => {
chrome.helpExtension.set(domElement => {
ReactDOM.render(<Content {...this.props} />, domElement);
ReactDOM.render(
<Content feedbackLink={feedbackLink} feedbackLinkText={feedbackLinkText} />,
domElement
);
return () => {
ReactDOM.unmountComponentAtNode(domElement);
};
});
};
}, [feedbackLink, feedbackLinkText]);

public render = () => {
return null;
};
}
return null;
};
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const WithWaffleOptionsUrlState = () => (
changeAutoBounds,
changeBoundsOverride,
}) => (
<UrlStateContainer
<UrlStateContainer<WaffleOptionsUrlState>
urlState={urlState}
urlStateKey="waffleOptions"
mapToUrlState={mapToUrlState}
Expand Down Expand Up @@ -158,8 +158,10 @@ const mapToUrlState = (value: any): WaffleOptionsUrlState | undefined =>
}
: undefined;

const isInfraNodeType = (value: any): value is InfraNodeType => value in InfraNodeType;

const isInfraSnapshotMetricInput = (subject: any): subject is InfraSnapshotMetricInput => {
return subject != null && subject.type != null && InfraSnapshotMetricType[subject.type] != null;
return subject != null && subject.type in InfraSnapshotMetricType;
};

const isInfraSnapshotGroupbyInput = (subject: any): subject is InfraSnapshotGroupbyInput => {
Expand All @@ -181,7 +183,7 @@ const mapToGroupByUrlState = (subject: any) => {
};

const mapToNodeTypeUrlState = (subject: any) => {
return subject && InfraNodeType[subject] ? subject : undefined;
return isInfraNodeType(subject) ? subject : undefined;
};

const mapToViewUrlState = (subject: any) => {
Expand Down
10 changes: 6 additions & 4 deletions x-pack/legacy/plugins/infra/public/utils/typed_react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import { InferableComponentEnhancerWithProps } from 'react-redux';
export type RendererResult = React.ReactElement<any> | null;
export type RendererFunction<RenderArgs, Result = RendererResult> = (args: RenderArgs) => Result;

export type ChildFunctionRendererProps<RenderArgs> = {
export type ChildFunctionRendererProps<RenderArgs extends {}> = {
children: RendererFunction<RenderArgs>;
initializeOnMount?: boolean;
resetOnUnmount?: boolean;
} & RenderArgs;

interface ChildFunctionRendererOptions<RenderArgs> {
interface ChildFunctionRendererOptions<RenderArgs extends {}> {
onInitialize?: (props: RenderArgs) => void;
onCleanup?: (props: RenderArgs) => void;
}

export const asChildFunctionRenderer = <InjectedProps, OwnProps>(
export const asChildFunctionRenderer = <InjectedProps extends {}, OwnProps>(
hoc: InferableComponentEnhancerWithProps<InjectedProps, OwnProps>,
{ onInitialize, onCleanup }: ChildFunctionRendererOptions<InjectedProps> = {}
) =>
Expand All @@ -43,7 +43,9 @@ export const asChildFunctionRenderer = <InjectedProps, OwnProps>(
}

public render() {
return this.props.children(this.getRendererArgs());
return (this.props.children as ChildFunctionRendererProps<InjectedProps>['children'])(
this.getRendererArgs()
);
}

private getRendererArgs = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,19 @@ export const getIPFromBucket = (
nodeType: InfraNodeType,
bucket: InfraSnapshotNodeGroupByBucket
): string | null => {
const ip = get(bucket, `ip.hits.hits[0]._source.${IP_FIELDS[nodeType]}`, null);
const ip = get<typeof bucket, unknown>(
bucket,
`ip.hits.hits[0]._source.${IP_FIELDS[nodeType]}`,
null
);

if (Array.isArray(ip)) {
return ip.find(isIPv4) || null;
} else if (typeof ip === 'string') {
return ip;
}
return ip;

return null;
};

export const getNodePath = (
Expand Down