Skip to content

Commit cae3a47

Browse files
authored
[APM Replace usage of idx with optional chaining (#50849)
Closes #50758
1 parent ee7338e commit cae3a47

File tree

43 files changed

+168
-185
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+168
-185
lines changed

x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ErrorTabs.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import { i18n } from '@kbn/i18n';
88
import { isEmpty } from 'lodash';
9-
import { idx } from '@kbn/elastic-idx';
109
import { APMError } from '../../../../../typings/es_schemas/ui/APMError';
1110

1211
export interface ErrorTab {
@@ -39,7 +38,7 @@ export const metadataTab: ErrorTab = {
3938
};
4039

4140
export function getTabs(error: APMError) {
42-
const hasLogStacktrace = !isEmpty(idx(error, _ => _.error.log.stacktrace));
41+
const hasLogStacktrace = !isEmpty(error.error.log?.stacktrace);
4342
return [
4443
...(hasLogStacktrace ? [logStacktraceTab] : []),
4544
exceptionStacktraceTab,

x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/ExceptionStacktrace.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import React from 'react';
88
import { EuiTitle } from '@elastic/eui';
9-
import { idx } from '@kbn/elastic-idx/target';
109
import { Exception } from '../../../../../typings/es_schemas/raw/ErrorRaw';
1110
import { Stacktrace } from '../../../shared/Stacktrace';
1211
import { CauseStacktrace } from '../../../shared/Stacktrace/CauseStacktrace';
@@ -20,7 +19,7 @@ export function ExceptionStacktrace({
2019
codeLanguage,
2120
exceptions
2221
}: ExceptionStacktraceProps) {
23-
const title = idx(exceptions, _ => _[0].message);
22+
const title = exceptions[0]?.message;
2423

2524
return (
2625
<>

x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/__snapshots__/index.test.tsx.snap

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.test.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ describe('DetailView', () => {
6060
const errorGroup = {
6161
occurrencesCount: 10,
6262
error: {
63+
error: {},
6364
timestamp: {
6465
us: 0
6566
}
@@ -85,6 +86,7 @@ describe('DetailView', () => {
8586
timestamp: {
8687
us: 0
8788
},
89+
error: {},
8890
service: {},
8991
user: {}
9092
} as any
@@ -109,6 +111,7 @@ describe('DetailView', () => {
109111
timestamp: {
110112
us: 0
111113
},
114+
error: {},
112115
context: {}
113116
} as any
114117
};

x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/DetailView/index.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { Location } from 'history';
1919
import React from 'react';
2020
import styled from 'styled-components';
2121
import { first } from 'lodash';
22-
import { idx } from '@kbn/elastic-idx';
2322
import { ErrorGroupAPIResponse } from '../../../../../server/lib/errors/get_error_group';
2423
import { APMError } from '../../../../../typings/es_schemas/ui/APMError';
2524
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
@@ -80,11 +79,12 @@ export function DetailView({ errorGroup, urlParams, location }: Props) {
8079
const tabs = getTabs(error);
8180
const currentTab = getCurrentTab(tabs, urlParams.detailTab);
8281

83-
const errorUrl =
84-
idx(error, _ => _.error.page.url) || idx(error, _ => _.url.full);
82+
const errorUrl = error.error.page?.url || error.url?.full;
8583

86-
const method = idx(error, _ => _.http.request.method);
87-
const status = idx(error, _ => _.http.response.status_code);
84+
const method = error.http?.request.method;
85+
// TODO(TS-3.7-ESLINT)
86+
// eslint-disable-next-line @typescript-eslint/camelcase
87+
const status = error.http?.response?.status_code;
8888

8989
return (
9090
<EuiPanel>
@@ -188,9 +188,9 @@ function TabContent({
188188
error: APMError;
189189
currentTab: ErrorTab;
190190
}) {
191-
const codeLanguage = idx(error, _ => _.service.language.name);
192-
const exceptions = idx(error, _ => _.error.exception) || [];
193-
const logStackframes = idx(error, _ => _.error.log.stacktrace);
191+
const codeLanguage = error.service.language?.name;
192+
const exceptions = error.error.exception || [];
193+
const logStackframes = error.error.log?.stacktrace;
194194

195195
switch (currentTab.key) {
196196
case logStacktraceTab.key:

x-pack/legacy/plugins/apm/public/components/app/ErrorGroupDetails/index.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import theme from '@elastic/eui/dist/eui_theme_light.json';
1717
import { i18n } from '@kbn/i18n';
1818
import React, { Fragment } from 'react';
1919
import styled from 'styled-components';
20-
import { idx } from '@kbn/elastic-idx';
2120
import { NOT_AVAILABLE_LABEL } from '../../../../common/i18n';
2221
import { useFetcher } from '../../../hooks/useFetcher';
2322
import { fontFamilyCode, fontSizes, px, units } from '../../../style/variables';
@@ -115,14 +114,11 @@ export function ErrorGroupDetails() {
115114

116115
// If there are 0 occurrences, show only distribution chart w. empty message
117116
const showDetails = errorGroupData.occurrencesCount !== 0;
118-
const logMessage = idx(errorGroupData, _ => _.error.error.log.message);
119-
const excMessage = idx(
120-
errorGroupData,
121-
_ => _.error.error.exception[0].message
122-
);
123-
const culprit = idx(errorGroupData, _ => _.error.error.culprit);
117+
const logMessage = errorGroupData.error?.error.log?.message;
118+
const excMessage = errorGroupData.error?.error.exception?.[0].message;
119+
const culprit = errorGroupData.error?.error.culprit;
124120
const isUnhandled =
125-
idx(errorGroupData, _ => _.error.error.exception[0].handled) === false;
121+
errorGroupData.error?.error.exception?.[0].handled === false;
126122

127123
return (
128124
<div>

x-pack/legacy/plugins/apm/public/components/app/ServiceDetails/ServiceIntegrations/index.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {
1313
import { i18n } from '@kbn/i18n';
1414
import { memoize } from 'lodash';
1515
import React, { Fragment } from 'react';
16-
import { idx } from '@kbn/elastic-idx';
1716
import { KibanaCoreContext } from '../../../../../../observability/public';
1817
import { IUrlParams } from '../../../../context/UrlParamsContext/types';
1918
import { LicenseContext } from '../../../../context/LicenseContext';
@@ -149,9 +148,9 @@ export class ServiceIntegrations extends React.Component<Props, State> {
149148
panels={[
150149
{
151150
id: 0,
152-
items: this.getPanelItems(
153-
idx(license, _ => _.features.ml.is_available)
154-
)
151+
// TODO(TS-3.7-ESLINT)
152+
// eslint-disable-next-line @typescript-eslint/camelcase
153+
items: this.getPanelItems(license.features.ml?.is_available)
155154
}
156155
]}
157156
/>

x-pack/legacy/plugins/apm/public/components/app/Settings/AgentConfigurations/AddEditFlyout/index.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
EuiText,
2020
EuiSpacer
2121
} from '@elastic/eui';
22-
import { idx } from '@kbn/elastic-idx';
2322
import React, { useState } from 'react';
2423
import { i18n } from '@kbn/i18n';
2524
import { isRight } from 'fp-ts/lib/Either';
@@ -89,18 +88,21 @@ export function AddEditFlyout({
8988

9089
// config settings
9190
const [sampleRate, setSampleRate] = useState<string>(
91+
// TODO(TS-3.7-ESLINT)
9292
(
93-
idx(selectedConfig, _ => _.settings.transaction_sample_rate) ||
93+
selectedConfig?.settings.transaction_sample_rate || // eslint-disable-line @typescript-eslint/camelcase
9494
defaultSettings.TRANSACTION_SAMPLE_RATE
9595
).toString()
9696
);
9797
const [captureBody, setCaptureBody] = useState<string>(
98-
idx(selectedConfig, _ => _.settings.capture_body) ||
99-
defaultSettings.CAPTURE_BODY
98+
// TODO(TS-3.7-ESLINT)
99+
// eslint-disable-next-line @typescript-eslint/camelcase
100+
selectedConfig?.settings.capture_body || defaultSettings.CAPTURE_BODY
100101
);
101102
const [transactionMaxSpans, setTransactionMaxSpans] = useState<string>(
103+
// TODO(TS-3.7-ESLINT)
102104
(
103-
idx(selectedConfig, _ => _.settings.transaction_max_spans) ||
105+
selectedConfig?.settings.transaction_max_spans || // eslint-disable-line @typescript-eslint/camelcase
104106
defaultSettings.TRANSACTION_MAX_SPANS
105107
).toString()
106108
);

x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/HttpContext.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import styled from 'styled-components';
99

1010
import { EuiSpacer, EuiTitle } from '@elastic/eui';
1111
import theme from '@elastic/eui/dist/eui_theme_light.json';
12-
import { idx } from '@kbn/elastic-idx';
1312
import {
1413
borderRadius,
1514
fontFamilyCode,
@@ -34,7 +33,7 @@ interface Props {
3433
}
3534

3635
export function HttpContext({ httpContext }: Props) {
37-
const url = idx(httpContext, _ => _.url.original);
36+
const url = httpContext?.url?.original;
3837

3938
if (!url) {
4039
return null;

x-pack/legacy/plugins/apm/public/components/app/TransactionDetails/WaterfallWithSummmary/WaterfallContainer/Waterfall/SpanFlyout/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import {
2121
import { i18n } from '@kbn/i18n';
2222
import React, { Fragment } from 'react';
2323
import styled from 'styled-components';
24-
import { idx } from '@kbn/elastic-idx';
2524
import { px, units } from '../../../../../../../style/variables';
2625
import { Summary } from '../../../../../../shared/Summary';
2726
import { TimestampTooltip } from '../../../../../../shared/TimestampTooltip';
@@ -98,13 +97,15 @@ export function SpanFlyout({
9897
}
9998

10099
const stackframes = span.span.stacktrace;
101-
const codeLanguage = idx(parentTransaction, _ => _.service.language.name);
102-
const dbContext = idx(span, _ => _.span.db);
103-
const httpContext = idx(span, _ => _.span.http);
100+
const codeLanguage = parentTransaction?.service.language?.name;
101+
const dbContext = span.span.db;
102+
const httpContext = span.span.http;
104103
const spanTypes = getSpanTypes(span);
105-
const spanHttpStatusCode = idx(httpContext, _ => _.response.status_code);
106-
const spanHttpUrl = idx(httpContext, _ => _.url.original);
107-
const spanHttpMethod = idx(httpContext, _ => _.method);
104+
// TODO(TS-3.7-ESLINT)
105+
// eslint-disable-next-line @typescript-eslint/camelcase
106+
const spanHttpStatusCode = httpContext?.response.status_code;
107+
const spanHttpUrl = httpContext?.url?.original;
108+
const spanHttpMethod = httpContext?.method;
108109

109110
return (
110111
<EuiPortal>

0 commit comments

Comments
 (0)