Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Upgrade Assistant] Move fix deprecation logs into the es_deprecation_logs page #118688

Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { FunctionComponent, useEffect, useState } from 'react';
import React, { FunctionComponent, useState } from 'react';
import moment from 'moment-timezone';
import { FormattedDate, FormattedTime, FormattedMessage } from '@kbn/i18n/react';
import { METRIC_TYPE } from '@kbn/analytics';
Expand Down Expand Up @@ -54,13 +54,11 @@ const i18nTexts = {
interface Props {
checkpoint: string;
setCheckpoint: (value: string) => void;
setHasNoDeprecationLogs: (hasNoLogs: boolean) => void;
}

export const DeprecationsCountCheckpoint: FunctionComponent<Props> = ({
checkpoint,
setCheckpoint,
setHasNoDeprecationLogs,
}) => {
const [isDeletingCache, setIsDeletingCache] = useState(false);
const {
Expand Down Expand Up @@ -96,16 +94,6 @@ export const DeprecationsCountCheckpoint: FunctionComponent<Props> = ({
setCheckpoint(now);
};

useEffect(() => {
// Loading shouldn't invalidate the previous state.
if (!isLoading) {
// An error should invalidate the previous state.
setHasNoDeprecationLogs(!error && !hasLogs);
}
// Depending upon setHasNoDeprecationLogs would create an infinite loop.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [error, isLoading, hasLogs]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was part of the logic used used for setting the step completion when there was no deprecation logs.


if (isInitialRequest && isLoading) {
return <EuiLoadingContent lines={6} />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,17 @@ import React, { FunctionComponent, useState, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiText, EuiSpacer, EuiLink, EuiCallOut, EuiCode } from '@elastic/eui';
import type { EuiStepProps } from '@elastic/eui/src/components/steps/step';

import { useAppContext } from '../../../app_context';
import { ExternalLinks } from './external_links';
import { DeprecationsCountCheckpoint } from './deprecations_count_checkpoint';
import { useDeprecationLogging } from './use_deprecation_logging';
import { DeprecationLoggingToggle } from './deprecation_logging_toggle';
import { loadLogsCheckpoint, saveLogsCheckpoint } from '../../../lib/logs_checkpoint';
import type { OverviewStepProps } from '../../types';
import { DEPRECATION_LOGS_INDEX } from '../../../../../common/constants';
import { WithPrivileges, MissingPrivileges } from '../../../../shared_imports';

const i18nTexts = {
identifyStepTitle: i18n.translate('xpack.upgradeAssistant.overview.identifyStepTitle', {
defaultMessage: 'Identify deprecated API use and update your applications',
}),
analyzeTitle: i18n.translate('xpack.upgradeAssistant.overview.analyzeTitle', {
defaultMessage: 'Analyze deprecation logs',
}),
Expand Down Expand Up @@ -93,16 +88,11 @@ const i18nTexts = {
};

interface Props {
setIsComplete: OverviewStepProps['setIsComplete'];
hasPrivileges: boolean;
privilegesMissing: MissingPrivileges;
}

const FixLogsStep: FunctionComponent<Props> = ({
setIsComplete,
hasPrivileges,
privilegesMissing,
}) => {
const FixLogsStep: FunctionComponent<Props> = ({ hasPrivileges, privilegesMissing }) => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: We should rename this function to something like FixDeprecationLogs, and the same goes for the file itself

const {
services: {
core: { docLinks },
Expand All @@ -126,15 +116,6 @@ const FixLogsStep: FunctionComponent<Props> = ({
saveLogsCheckpoint(checkpoint);
}, [checkpoint]);

useEffect(() => {
if (!isDeprecationLogIndexingEnabled) {
setIsComplete(false);
}

// Depending upon setIsComplete would create an infinite loop.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isDeprecationLogIndexingEnabled]);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was part of the logic used used for setting the step completion when there was no deprecation logs.


return (
<>
<DeprecationLoggingToggle
Expand Down Expand Up @@ -189,11 +170,7 @@ const FixLogsStep: FunctionComponent<Props> = ({
<h4>{i18nTexts.deprecationsCountCheckpointTitle}</h4>
</EuiText>
<EuiSpacer size="m" />
<DeprecationsCountCheckpoint
checkpoint={checkpoint}
setCheckpoint={setCheckpoint}
setHasNoDeprecationLogs={setIsComplete}
/>
<DeprecationsCountCheckpoint checkpoint={checkpoint} setCheckpoint={setCheckpoint} />

<EuiSpacer size="xl" />
<EuiText data-test-subj="apiCompatibilityNoteTitle">
Expand All @@ -213,23 +190,15 @@ const FixLogsStep: FunctionComponent<Props> = ({
);
};

export const getFixLogsStep = ({ isComplete, setIsComplete }: OverviewStepProps): EuiStepProps => {
const status = isComplete ? 'complete' : 'incomplete';

return {
status,
title: i18nTexts.identifyStepTitle,
'data-test-subj': `fixLogsStep-${status}`,
children: (
<WithPrivileges privileges={`index.${DEPRECATION_LOGS_INDEX}`}>
{({ hasPrivileges, privilegesMissing, isLoading }) => (
<FixLogsStep
setIsComplete={setIsComplete}
hasPrivileges={!isLoading && hasPrivileges}
privilegesMissing={privilegesMissing}
/>
)}
</WithPrivileges>
),
};
export const getFixLogsStep = () => {
return (
<WithPrivileges privileges={`index.${DEPRECATION_LOGS_INDEX}`}>
{({ hasPrivileges, privilegesMissing, isLoading }) => (
<FixLogsStep
hasPrivileges={!isLoading && hasPrivileges}
privilegesMissing={privilegesMissing}
/>
)}
</WithPrivileges>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ import { useAppContext } from '../../app_context';
import { uiMetricService, UIM_OVERVIEW_PAGE_LOAD } from '../../lib/ui_metric';
import { getBackupStep } from './backup_step';
import { getFixIssuesStep } from './fix_issues_step';
import { getFixLogsStep } from './fix_logs_step';
import { getUpgradeStep } from './upgrade_step';
import { getMigrateSystemIndicesStep } from './migrate_system_indices';

type OverviewStep = 'backup' | 'migrate_system_indices' | 'fix_issues' | 'fix_logs';
type OverviewStep = 'backup' | 'migrate_system_indices' | 'fix_issues';

export const Overview: FunctionComponent = () => {
const {
Expand All @@ -52,7 +51,6 @@ export const Overview: FunctionComponent = () => {
backup: false,
migrate_system_indices: false,
fix_issues: false,
fix_logs: false,
});

const isStepComplete = (step: OverviewStep) => completedStepsMap[step];
Expand Down Expand Up @@ -115,10 +113,6 @@ export const Overview: FunctionComponent = () => {
isComplete: isStepComplete('fix_issues'),
setIsComplete: setCompletedStep.bind(null, 'fix_issues'),
}),
getFixLogsStep({
isComplete: isStepComplete('fix_logs'),
setIsComplete: setCompletedStep.bind(null, 'fix_logs'),
}),
getUpgradeStep(),
]}
/>
Expand Down