Skip to content

Commit e24f9df

Browse files
committed
Address CR changes
1 parent 273faa4 commit e24f9df

File tree

7 files changed

+62
-55
lines changed

7 files changed

+62
-55
lines changed

x-pack/plugins/upgrade_assistant/__jest__/client_integration/helpers/app_context.mock.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const idToUrlMap = {
3535
};
3636
type IdKey = keyof typeof idToUrlMap;
3737

38-
const convertObjectValuesToString = (params: Record<string, any>) => {
38+
const stringifySearchParams = (params: Record<string, any>) => {
3939
return Object.keys(params).reduce((list, key) => {
4040
const value = typeof params[key] === 'object' ? JSON.stringify(params[key]) : params[key];
4141

@@ -48,7 +48,7 @@ const shareMock = sharePluginMock.createSetupContract();
4848
shareMock.url.locators.get = (id: IdKey) => ({
4949
useUrl: (): string | undefined => idToUrlMap[id],
5050
getUrl: (params: Record<string, any>): string | undefined =>
51-
`${idToUrlMap[id]}?${new URLSearchParams(convertObjectValuesToString(params)).toString()}`,
51+
`${idToUrlMap[id]}?${new URLSearchParams(stringifySearchParams(params)).toString()}`,
5252
});
5353

5454
export const getAppContextMock = () => ({

x-pack/plugins/upgrade_assistant/__jest__/client_integration/overview/fix_logs_step/fix_logs_step.test.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77

88
import { act } from 'react-dom/test-utils';
99

10+
// Once the logs team register the kibana locators in their app, we should be able
11+
// to remove this mock and follow a similar approach to how discover link is tested.
12+
// See: https://github.com/elastic/kibana/issues/104855
1013
const MOCKED_TIME = '2021-09-05T10:49:01.805Z';
11-
jest.mock('../../../../public/application/lib/utils', () => {
12-
const originalModule = jest.requireActual('../../../../public/application/lib/utils');
14+
jest.mock('../../../../public/application/lib/logs_checkpoint', () => {
15+
const originalModule = jest.requireActual('../../../../public/application/lib/logs_checkpoint');
1316

1417
return {
1518
__esModule: true,
1619
...originalModule,
17-
getLastCheckpointFromLS: jest.fn().mockReturnValue('2021-09-05T10:49:01.805Z'),
20+
loadLogsCheckpoint: jest.fn().mockReturnValue('2021-09-05T10:49:01.805Z'),
1821
};
1922
});
2023

x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/deprecations_count_checkpoint/deprecations_count_checkpoint.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ const i18nTexts = {
4848
};
4949

5050
interface Props {
51-
lastCheckpoint: string;
52-
resetLastCheckpoint: (value: string) => void;
51+
checkpoint: string;
52+
setCheckpoint: (value: string) => void;
5353
}
5454

5555
export const DeprecationsCountCheckpoint: FunctionComponent<Props> = ({
56-
lastCheckpoint,
57-
resetLastCheckpoint,
56+
checkpoint,
57+
setCheckpoint,
5858
}) => {
5959
const {
6060
services: { api },
6161
} = useAppContext();
6262
const { data, error, isLoading, resendRequest, isInitialRequest } = api.getDeprecationLogsCount(
63-
lastCheckpoint
63+
checkpoint
6464
);
6565

6666
const warningsCount = data?.count || 0;
@@ -70,7 +70,7 @@ export const DeprecationsCountCheckpoint: FunctionComponent<Props> = ({
7070

7171
const onResetClick = () => {
7272
const now = moment().toISOString();
73-
resetLastCheckpoint(now);
73+
setCheckpoint(now);
7474
};
7575

7676
if (isInitialRequest && isLoading) {
@@ -97,7 +97,7 @@ export const DeprecationsCountCheckpoint: FunctionComponent<Props> = ({
9797

9898
return (
9999
<EuiCallOut
100-
title={i18nTexts.calloutTitle(warningsCount, lastCheckpoint)}
100+
title={i18nTexts.calloutTitle(warningsCount, checkpoint)}
101101
color={calloutTint}
102102
iconType={calloutIcon}
103103
data-test-subj={calloutTestId}

x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/external_links.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from '../../../../../common/constants';
2020

2121
interface Props {
22-
lastCheckpoint: string;
22+
checkpoint: string;
2323
}
2424

2525
const getDeprecationIndexPatternId = async (dataService: DataPublicPluginStart) => {
@@ -41,7 +41,7 @@ const getDeprecationIndexPatternId = async (dataService: DataPublicPluginStart)
4141
}
4242
};
4343

44-
const DiscoverAppLink: FunctionComponent<Props> = ({ lastCheckpoint }) => {
44+
const DiscoverAppLink: FunctionComponent<Props> = ({ checkpoint }) => {
4545
const {
4646
services: { data: dataService },
4747
plugins: { share },
@@ -62,15 +62,15 @@ const DiscoverAppLink: FunctionComponent<Props> = ({ lastCheckpoint }) => {
6262
indexPatternId,
6363
query: {
6464
language: 'kuery',
65-
query: `@timestamp > "${lastCheckpoint}"`,
65+
query: `@timestamp > "${checkpoint}"`,
6666
},
6767
});
6868

6969
setDiscoveryUrl(url);
7070
};
7171

7272
getDiscoveryUrl();
73-
}, [dataService, lastCheckpoint, share.url.locators]);
73+
}, [dataService, checkpoint, share.url.locators]);
7474

7575
return (
7676
<EuiLink href={discoveryUrl} data-test-subj="viewDiscoverLogs">
@@ -82,15 +82,15 @@ const DiscoverAppLink: FunctionComponent<Props> = ({ lastCheckpoint }) => {
8282
);
8383
};
8484

85-
const ObservabilityAppLink: FunctionComponent<Props> = ({ lastCheckpoint }) => {
85+
const ObservabilityAppLink: FunctionComponent<Props> = ({ checkpoint }) => {
8686
const {
8787
services: {
8888
core: { http },
8989
},
9090
} = useAppContext();
9191
const logStreamUrl = http?.basePath?.prepend(
9292
`/app/logs/stream?sourceId=${DEPRECATION_LOGS_SOURCE_ID}&logPosition=(end:now,start:${encode(
93-
lastCheckpoint
93+
checkpoint
9494
)})`
9595
);
9696

@@ -104,7 +104,7 @@ const ObservabilityAppLink: FunctionComponent<Props> = ({ lastCheckpoint }) => {
104104
);
105105
};
106106

107-
export const ExternalLinks: FunctionComponent<Props> = ({ lastCheckpoint }) => {
107+
export const ExternalLinks: FunctionComponent<Props> = ({ checkpoint }) => {
108108
return (
109109
<EuiFlexGroup>
110110
<EuiFlexItem>
@@ -118,7 +118,7 @@ export const ExternalLinks: FunctionComponent<Props> = ({ lastCheckpoint }) => {
118118
</p>
119119
</EuiText>
120120
<EuiSpacer size="m" />
121-
<ObservabilityAppLink lastCheckpoint={lastCheckpoint} />
121+
<ObservabilityAppLink checkpoint={checkpoint} />
122122
</EuiPanel>
123123
</EuiFlexItem>
124124
<EuiFlexItem>
@@ -132,7 +132,7 @@ export const ExternalLinks: FunctionComponent<Props> = ({ lastCheckpoint }) => {
132132
</p>
133133
</EuiText>
134134
<EuiSpacer size="m" />
135-
<DiscoverAppLink lastCheckpoint={lastCheckpoint} />
135+
<DiscoverAppLink checkpoint={checkpoint} />
136136
</EuiPanel>
137137
</EuiFlexItem>
138138
</EuiFlexGroup>

x-pack/plugins/upgrade_assistant/public/application/components/overview/fix_logs_step/fix_logs_step.tsx

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* 2.0.
66
*/
77

8-
import React, { FunctionComponent, useState, useCallback } from 'react';
8+
import React, { FunctionComponent, useState, useEffect } from 'react';
99

1010
import { i18n } from '@kbn/i18n';
1111
import { EuiText, EuiSpacer, EuiPanel, EuiCallOut } from '@elastic/eui';
@@ -15,7 +15,7 @@ import { ExternalLinks } from './external_links';
1515
import { DeprecationsCountCheckpoint } from './deprecations_count_checkpoint';
1616
import { useDeprecationLogging } from './use_deprecation_logging';
1717
import { DeprecationLoggingToggle } from './deprecation_logging_toggle';
18-
import { getLastCheckpointFromLS, setLastCheckpointToLS } from '../../../lib/utils';
18+
import { loadLogsCheckpoint, saveLogsCheckpoint } from '../../../lib/logs_checkpoint';
1919

2020
const i18nTexts = {
2121
identifyStepTitle: i18n.translate('xpack.upgradeAssistant.overview.identifyStepTitle', {
@@ -50,12 +50,11 @@ const i18nTexts = {
5050

5151
const FixLogsStep: FunctionComponent = () => {
5252
const state = useDeprecationLogging();
53-
const [lastCheckpoint, setLastCheckpoint] = useState(getLastCheckpointFromLS());
53+
const [checkpoint, setCheckpoint] = useState(loadLogsCheckpoint());
5454

55-
const resetLastCheckpoint = useCallback((newValue: string) => {
56-
setLastCheckpoint(newValue);
57-
setLastCheckpointToLS(newValue);
58-
}, []);
55+
useEffect(() => {
56+
saveLogsCheckpoint(checkpoint);
57+
}, [checkpoint]);
5958

6059
return (
6160
<>
@@ -88,17 +87,14 @@ const FixLogsStep: FunctionComponent = () => {
8887
<h4>{i18nTexts.analyzeTitle}</h4>
8988
</EuiText>
9089
<EuiSpacer size="m" />
91-
<ExternalLinks lastCheckpoint={lastCheckpoint} />
90+
<ExternalLinks checkpoint={checkpoint} />
9291

9392
<EuiSpacer size="xl" />
9493
<EuiText data-test-subj="deprecationsCountTitle">
9594
<h4>{i18nTexts.deprecationsCountCheckpointTitle}</h4>
9695
</EuiText>
9796
<EuiSpacer size="m" />
98-
<DeprecationsCountCheckpoint
99-
lastCheckpoint={lastCheckpoint}
100-
resetLastCheckpoint={resetLastCheckpoint}
101-
/>
97+
<DeprecationsCountCheckpoint checkpoint={checkpoint} setCheckpoint={setCheckpoint} />
10298
</>
10399
)}
104100
</>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import moment from 'moment-timezone';
9+
10+
import { Storage } from '../../shared_imports';
11+
12+
const SETTING_ID = 'kibana.upgradeAssistant.lastCheckpoint';
13+
const localStorage = new Storage(window.localStorage);
14+
15+
export const loadLogsCheckpoint = () => {
16+
const storedValue = moment(localStorage.get(SETTING_ID));
17+
18+
if (storedValue.isValid()) {
19+
return storedValue.toISOString();
20+
}
21+
22+
const now = moment().toISOString();
23+
localStorage.set(SETTING_ID, now);
24+
25+
return now;
26+
};
27+
28+
export const saveLogsCheckpoint = (value: string) => {
29+
localStorage.set(SETTING_ID, value);
30+
};

x-pack/plugins/upgrade_assistant/public/application/lib/utils.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
* 2.0.
66
*/
77

8-
import moment from 'moment-timezone';
98
import { pipe } from 'fp-ts/lib/pipeable';
109
import { tryCatch, fold } from 'fp-ts/lib/Either';
1110

1211
import { DEPRECATION_WARNING_UPPER_LIMIT } from '../../../common/constants';
13-
import { Storage } from '../../shared_imports';
1412

1513
export const validateRegExpString = (s: string) =>
1614
pipe(
@@ -36,23 +34,3 @@ export const getDeprecationsUpperLimit = (count: number) => {
3634

3735
return count.toString();
3836
};
39-
40-
const LS_SETTING_ID = 'kibana.upgradeAssistant.lastCheckpoint';
41-
const localStorage = new Storage(window.localStorage);
42-
43-
export const getLastCheckpointFromLS = () => {
44-
const storedValue = moment(localStorage.get(LS_SETTING_ID));
45-
46-
if (storedValue.isValid()) {
47-
return storedValue.toISOString();
48-
}
49-
50-
const now = moment().toISOString();
51-
localStorage.set(LS_SETTING_ID, now);
52-
53-
return now;
54-
};
55-
56-
export const setLastCheckpointToLS = (value: string) => {
57-
localStorage.set(LS_SETTING_ID, value);
58-
};

0 commit comments

Comments
 (0)