Skip to content

Commit 69631cd

Browse files
authored
[7.x] [Logs UI] Improve infra plugin compatibility with TS 3.7… (#50701)
Backports the following commits to 7.x: - [Logs UI] Improve infra plugin compatibility with TS 3.7 (#50491)
1 parent 8a3c485 commit 69631cd

File tree

5 files changed

+35
-19
lines changed

5 files changed

+35
-19
lines changed

x-pack/legacy/common/eui_styled_components/eui_styled_components.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ const {
3838
injectGlobal,
3939
keyframes,
4040
withTheme,
41-
} = styledComponents as ThemedStyledComponentsModule<EuiTheme>;
41+
} = (styledComponents as unknown) as ThemedStyledComponentsModule<EuiTheme>;
4242

4343
export { css, euiStyled, EuiThemeProvider, injectGlobal, keyframes, withTheme };

x-pack/legacy/plugins/infra/public/components/help_center_content.tsx

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { EuiLink } from '@elastic/eui';
8-
import React from 'react';
8+
import React, { useEffect } from 'react';
99
import ReactDOM from 'react-dom';
1010
import chrome from 'ui/chrome';
1111

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

23-
export class HelpCenterContent extends React.Component<HelpCenterContentProps> {
24-
public componentDidMount = () => {
23+
export const HelpCenterContent: React.FC<HelpCenterContentProps> = ({
24+
feedbackLink,
25+
feedbackLinkText,
26+
}) => {
27+
useEffect(() => {
2528
chrome.helpExtension.set(domElement => {
26-
ReactDOM.render(<Content {...this.props} />, domElement);
29+
ReactDOM.render(
30+
<Content feedbackLink={feedbackLink} feedbackLinkText={feedbackLinkText} />,
31+
domElement
32+
);
2733
return () => {
2834
ReactDOM.unmountComponentAtNode(domElement);
2935
};
3036
});
31-
};
37+
}, [feedbackLink, feedbackLinkText]);
3238

33-
public render = () => {
34-
return null;
35-
};
36-
}
39+
return null;
40+
};

x-pack/legacy/plugins/infra/public/containers/waffle/with_waffle_options.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const WithWaffleOptionsUrlState = () => (
9090
changeAutoBounds,
9191
changeBoundsOverride,
9292
}) => (
93-
<UrlStateContainer
93+
<UrlStateContainer<WaffleOptionsUrlState>
9494
urlState={urlState}
9595
urlStateKey="waffleOptions"
9696
mapToUrlState={mapToUrlState}
@@ -158,8 +158,10 @@ const mapToUrlState = (value: any): WaffleOptionsUrlState | undefined =>
158158
}
159159
: undefined;
160160

161+
const isInfraNodeType = (value: any): value is InfraNodeType => value in InfraNodeType;
162+
161163
const isInfraSnapshotMetricInput = (subject: any): subject is InfraSnapshotMetricInput => {
162-
return subject != null && subject.type != null && InfraSnapshotMetricType[subject.type] != null;
164+
return subject != null && subject.type in InfraSnapshotMetricType;
163165
};
164166

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

183185
const mapToNodeTypeUrlState = (subject: any) => {
184-
return subject && InfraNodeType[subject] ? subject : undefined;
186+
return isInfraNodeType(subject) ? subject : undefined;
185187
};
186188

187189
const mapToViewUrlState = (subject: any) => {

x-pack/legacy/plugins/infra/public/utils/typed_react.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ import { InferableComponentEnhancerWithProps } from 'react-redux';
1111
export type RendererResult = React.ReactElement<any> | null;
1212
export type RendererFunction<RenderArgs, Result = RendererResult> = (args: RenderArgs) => Result;
1313

14-
export type ChildFunctionRendererProps<RenderArgs> = {
14+
export type ChildFunctionRendererProps<RenderArgs extends {}> = {
1515
children: RendererFunction<RenderArgs>;
1616
initializeOnMount?: boolean;
1717
resetOnUnmount?: boolean;
1818
} & RenderArgs;
1919

20-
interface ChildFunctionRendererOptions<RenderArgs> {
20+
interface ChildFunctionRendererOptions<RenderArgs extends {}> {
2121
onInitialize?: (props: RenderArgs) => void;
2222
onCleanup?: (props: RenderArgs) => void;
2323
}
2424

25-
export const asChildFunctionRenderer = <InjectedProps, OwnProps>(
25+
export const asChildFunctionRenderer = <InjectedProps extends {}, OwnProps>(
2626
hoc: InferableComponentEnhancerWithProps<InjectedProps, OwnProps>,
2727
{ onInitialize, onCleanup }: ChildFunctionRendererOptions<InjectedProps> = {}
2828
) =>
@@ -43,7 +43,9 @@ export const asChildFunctionRenderer = <InjectedProps, OwnProps>(
4343
}
4444

4545
public render() {
46-
return this.props.children(this.getRendererArgs());
46+
return (this.props.children as ChildFunctionRendererProps<InjectedProps>['children'])(
47+
this.getRendererArgs()
48+
);
4749
}
4850

4951
private getRendererArgs = () =>

x-pack/legacy/plugins/infra/server/lib/snapshot/response_helpers.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,19 @@ export const getIPFromBucket = (
7373
nodeType: InfraNodeType,
7474
bucket: InfraSnapshotNodeGroupByBucket
7575
): string | null => {
76-
const ip = get(bucket, `ip.hits.hits[0]._source.${IP_FIELDS[nodeType]}`, null);
76+
const ip = get<typeof bucket, unknown>(
77+
bucket,
78+
`ip.hits.hits[0]._source.${IP_FIELDS[nodeType]}`,
79+
null
80+
);
81+
7782
if (Array.isArray(ip)) {
7883
return ip.find(isIPv4) || null;
84+
} else if (typeof ip === 'string') {
85+
return ip;
7986
}
80-
return ip;
87+
88+
return null;
8189
};
8290

8391
export const getNodePath = (

0 commit comments

Comments
 (0)