diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/_step_progress.scss b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/_step_progress.scss index a754541c2ff83..4d8ee5def30eb 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/_step_progress.scss +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/_step_progress.scss @@ -18,7 +18,7 @@ $stepStatusToCallOutColor: ( failed: 'danger', complete: 'success', paused: 'warning', - cancelled: 'danger', + cancelled: 'warning', ); .upgStepProgress__status--circle { diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/checklist_step.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/checklist_step.tsx index 19d61b3a8afa9..5e2f0d26447b2 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/checklist_step.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/checklist_step.tsx @@ -47,6 +47,13 @@ const buttonLabel = (status?: ReindexStatus) => { defaultMessage="Resume" /> ); + case ReindexStatus.cancelled: + return ( + + ); default: return ( { }, Object { "status": "incomplete", - "title": - - - - , + "title": , }, Object { "status": "incomplete", diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/progress.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/progress.tsx index afeac303284f1..f5dc04783b031 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/progress.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/progress.tsx @@ -7,18 +7,11 @@ import React from 'react'; -import { - EuiButtonEmpty, - EuiCallOut, - EuiFlexGroup, - EuiFlexItem, - EuiText, - EuiTitle, -} from '@elastic/eui'; +import { EuiCallOut, EuiFlexGroup, EuiFlexItem, EuiLink, EuiText, EuiTitle } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n/react'; import { ReindexStatus, ReindexStep } from '../../../../../../../common/types'; -import { LoadingState } from '../../../../types'; +import { CancelLoadingState } from '../../../../types'; import type { ReindexState } from '../use_reindex_state'; import { StepProgress, StepProgressStep } from './step_progress'; import { getReindexProgressLabel } from '../../../../../lib/utils'; @@ -40,13 +33,27 @@ const PausedCallout = () => ( /> ); -const CancelReindexingDocumentsButton: React.FunctionComponent<{ +const ReindexingDocumentsStepTitle: React.FunctionComponent<{ reindexState: ReindexState; cancelReindex: () => void; }> = ({ reindexState: { lastCompletedStep, status, cancelLoadingState }, cancelReindex }) => { + if (status === ReindexStatus.cancelled) { + return ( + <> + + + ); + } + const showCancelLink = + status === ReindexStatus.inProgress && lastCompletedStep === ReindexStep.reindexStarted; + let cancelText: React.ReactNode; switch (cancelLoadingState) { - case LoadingState.Loading: + case CancelLoadingState.Requested: + case CancelLoadingState.Loading: cancelText = ( ); break; - case LoadingState.Success: + case CancelLoadingState.Success: cancelText = ( ); break; - case LoadingState.Error: + case CancelLoadingState.Error: cancelText = ( - {cancelText} - + + + + + {showCancelLink && ( + + + {cancelText} + + + )} + ); }; @@ -145,22 +159,7 @@ export const ReindexProgress: React.FunctionComponent<{ // The reindexing step is special because it generally lasts longer and can be cancelled mid-flight const reindexingDocsStep = { - title: ( - - - - - {(lastCompletedStep === ReindexStep.newIndexCreated || - lastCompletedStep === ReindexStep.reindexStarted) && ( - - - - )} - - ), + title: , } as StepProgressStep; if ( diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/step_progress.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/step_progress.tsx index d5947426aee3d..2de21ad86f839 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/step_progress.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/flyout/step_progress.tsx @@ -56,11 +56,7 @@ const Step: React.FunctionComponent = ({ }) => { const titleClassName = classNames('upgStepProgress__title', { // eslint-disable-next-line @typescript-eslint/naming-convention - 'upgStepProgress__title--currentStep': - status === 'inProgress' || - status === 'paused' || - status === 'failed' || - status === 'cancelled', + 'upgStepProgress__title--currentStep': status === 'inProgress', }); return ( diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/resolution_table_cell.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/resolution_table_cell.tsx index 84c6c16d4032a..d743a7d3018dc 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/resolution_table_cell.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/resolution_table_cell.tsx @@ -55,7 +55,7 @@ const i18nTexts = { reindexCanceledText: i18n.translate( 'xpack.upgradeAssistant.esDeprecations.reindex.reindexCanceledText', { - defaultMessage: 'Reindex canceled', + defaultMessage: 'Reindex cancelled', } ), reindexPausedText: i18n.translate( @@ -154,17 +154,6 @@ export const ReindexResolutionCell: React.FunctionComponent = () => { ); - case ReindexStatus.cancelled: - return ( - - - - - - {i18nTexts.reindexCanceledText} - - - ); } return ( diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/use_reindex_state.tsx b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/use_reindex_state.tsx index cbeebd00f2bb8..68737d1bbff87 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/use_reindex_state.tsx +++ b/x-pack/plugins/upgrade_assistant/public/application/components/es_deprecations/deprecation_types/reindex/use_reindex_state.tsx @@ -13,14 +13,14 @@ import { ReindexStep, ReindexWarning, } from '../../../../../../common/types'; -import { LoadingState } from '../../../types'; +import { CancelLoadingState, LoadingState } from '../../../types'; import { ApiService } from '../../../../lib/api'; const POLL_INTERVAL = 1000; export interface ReindexState { loadingState: LoadingState; - cancelLoadingState?: LoadingState; + cancelLoadingState?: CancelLoadingState; lastCompletedStep?: ReindexStep; status?: ReindexStatus; reindexTaskPercComplete: number | null; @@ -59,8 +59,21 @@ const getReindexState = ( newReindexState.reindexTaskPercComplete = reindexOp.reindexTaskPercComplete; newReindexState.errorMessage = reindexOp.errorMessage; - if (reindexOp.status === ReindexStatus.cancelled) { - newReindexState.cancelLoadingState = LoadingState.Success; + // if reindex cancellation was "requested" or "loading" and the reindex task is now cancelled, + // then reindex cancellation has completed, set it to "success" + if ( + (reindexState.cancelLoadingState === CancelLoadingState.Requested || + reindexState.cancelLoadingState === CancelLoadingState.Loading) && + reindexOp.status === ReindexStatus.cancelled + ) { + newReindexState.cancelLoadingState = CancelLoadingState.Success; + } else if ( + // if reindex cancellation has been requested and the reindex task is still in progress, + // then reindex cancellation has not completed yet, set it to "loading" + reindexState.cancelLoadingState === CancelLoadingState.Requested && + reindexOp.status === ReindexStatus.inProgress + ) { + newReindexState.cancelLoadingState = CancelLoadingState.Loading; } } @@ -90,39 +103,39 @@ export const useReindexStatus = ({ indexName, api }: { indexName: string; api: A const { data, error } = await api.getReindexStatus(indexName); if (error) { - setReindexState({ - ...reindexState, - loadingState: LoadingState.Error, - errorMessage: error.message.toString(), - status: ReindexStatus.fetchFailed, + setReindexState((prevValue: ReindexState) => { + return { + ...prevValue, + loadingState: LoadingState.Error, + errorMessage: error.message.toString(), + status: ReindexStatus.fetchFailed, + }; }); return; } - setReindexState(getReindexState(reindexState, data)); + setReindexState((prevValue: ReindexState) => { + return getReindexState(prevValue, data); + }); // Only keep polling if it exists and is in progress. if (data.reindexOp && data.reindexOp.status === ReindexStatus.inProgress) { pollIntervalIdRef.current = setTimeout(updateStatus, POLL_INTERVAL); } - }, [clearPollInterval, api, indexName, reindexState]); + }, [clearPollInterval, api, indexName]); const startReindex = useCallback(async () => { - const currentReindexState = { - ...reindexState, - }; - - setReindexState({ - ...currentReindexState, - // Only reset last completed step if we aren't currently paused - lastCompletedStep: - currentReindexState.status === ReindexStatus.paused - ? currentReindexState.lastCompletedStep - : undefined, - status: ReindexStatus.inProgress, - reindexTaskPercComplete: null, - errorMessage: null, - cancelLoadingState: undefined, + setReindexState((prevValue: ReindexState) => { + return { + ...prevValue, + // Only reset last completed step if we aren't currently paused + lastCompletedStep: + prevValue.status === ReindexStatus.paused ? prevValue.lastCompletedStep : undefined, + status: ReindexStatus.inProgress, + reindexTaskPercComplete: null, + errorMessage: null, + cancelLoadingState: undefined, + }; }); api.sendReindexTelemetryData({ start: true }); @@ -130,37 +143,45 @@ export const useReindexStatus = ({ indexName, api }: { indexName: string; api: A const { data: reindexOp, error } = await api.startReindexTask(indexName); if (error) { - setReindexState({ - ...reindexState, - loadingState: LoadingState.Error, - errorMessage: error.message.toString(), - status: ReindexStatus.failed, + setReindexState((prevValue: ReindexState) => { + return { + ...prevValue, + loadingState: LoadingState.Error, + errorMessage: error.message.toString(), + status: ReindexStatus.failed, + }; }); return; } - setReindexState(getReindexState(reindexState, { reindexOp })); + setReindexState((prevValue: ReindexState) => { + return getReindexState(prevValue, { reindexOp }); + }); updateStatus(); - }, [api, indexName, reindexState, updateStatus]); + }, [api, indexName, updateStatus]); const cancelReindex = useCallback(async () => { api.sendReindexTelemetryData({ stop: true }); - const { error } = await api.cancelReindexTask(indexName); - - setReindexState({ - ...reindexState, - cancelLoadingState: LoadingState.Loading, + setReindexState((prevValue: ReindexState) => { + return { + ...prevValue, + cancelLoadingState: CancelLoadingState.Requested, + }; }); + const { error } = await api.cancelReindexTask(indexName); + if (error) { - setReindexState({ - ...reindexState, - cancelLoadingState: LoadingState.Error, + setReindexState((prevValue: ReindexState) => { + return { + ...prevValue, + cancelLoadingState: CancelLoadingState.Error, + }; }); return; } - }, [api, indexName, reindexState]); + }, [api, indexName]); useEffect(() => { isMounted.current = true; diff --git a/x-pack/plugins/upgrade_assistant/public/application/components/types.ts b/x-pack/plugins/upgrade_assistant/public/application/components/types.ts index 31dd9cf43656d..637c48cc61403 100644 --- a/x-pack/plugins/upgrade_assistant/public/application/components/types.ts +++ b/x-pack/plugins/upgrade_assistant/public/application/components/types.ts @@ -13,6 +13,13 @@ export enum LoadingState { Error, } +export enum CancelLoadingState { + Requested, + Loading, + Success, + Error, +} + export type DeprecationTableColumns = | 'type' | 'index'