Skip to content

Commit

Permalink
Add error handling when fetching configuration fails
Browse files Browse the repository at this point in the history
  • Loading branch information
sorenlouv committed Mar 23, 2020
1 parent c585a15 commit d83d7a1
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { AgentConfigurationIntake } from '../../../../../../../../../../plugins/
import {
omitAllOption,
getOptionLabel
} from '../../../../../../../../../../plugins/apm/common/agent_configuration/constants';
} from '../../../../../../../../../../plugins/apm/common/agent_configuration/all_option';
import { useFetcher, FETCH_STATUS } from '../../../../../../hooks/useFetcher';
import { FormRowSelect } from './FormRowSelect';
import { APMLink } from '../../../../../shared/Links/apm/APMLink';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
import React, { useState, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiButtonEmpty } from '@elastic/eui';
import { EuiCallOut } from '@elastic/eui';
import { FETCH_STATUS } from '../../../../../../hooks/useFetcher';
import { AgentName } from '../../../../../../../../../../plugins/apm/typings/es_schemas/ui/fields/agent';
import { history } from '../../../../../../utils/history';
import { AgentConfigurationIntake } from '../../../../../../../../../../plugins/apm/common/agent_configuration/configuration_types';
Expand All @@ -33,7 +35,7 @@ import { saveConfig } from './saveConfig';
import { useApmPluginContext } from '../../../../../../hooks/useApmPluginContext';
import { useUiTracker } from '../../../../../../../../../../plugins/observability/public';
import { SettingFormRow } from './SettingFormRow';
import { getOptionLabel } from '../../../../../../../../../../plugins/apm/common/agent_configuration/constants';
import { getOptionLabel } from '../../../../../../../../../../plugins/apm/common/agent_configuration/all_option';

function removeEmpty<T>(obj: T): T {
return Object.fromEntries(
Expand All @@ -42,15 +44,15 @@ function removeEmpty<T>(obj: T): T {
}

export function SettingsPage({
isLoading,
status,
unsavedChanges,
newConfig,
setNewConfig,
resetSettings,
isEditMode,
onClickEdit
}: {
isLoading: boolean;
status?: FETCH_STATUS;
unsavedChanges: Record<string, string>;
newConfig: AgentConfigurationIntake;
setNewConfig: React.Dispatch<React.SetStateAction<AgentConfigurationIntake>>;
Expand All @@ -63,6 +65,7 @@ export function SettingsPage({
const { toasts } = useApmPluginContext().core.notifications;
const [isSaving, setIsSaving] = useState(false);
const unsavedChangesCount = Object.keys(unsavedChanges).length;
const isLoading = status === FETCH_STATUS.LOADING;

const isFormValid = useMemo(() => {
return (
Expand Down Expand Up @@ -96,6 +99,26 @@ export function SettingsPage({
});
};

if (status === FETCH_STATUS.FAILURE) {
return (
<EuiCallOut
title={i18n.translate(
'xpack.apm.agentConfig.settingsPage.notFound.title',
{ defaultMessage: 'Sorry, there was an error' }
)}
color="danger"
iconType="alert"
>
<p>
{i18n.translate(
'xpack.apm.agentConfig.settingsPage.notFound.message',
{ defaultMessage: 'The requested configuration does not exist' }
)}
</p>
</EuiCallOut>
);
}

return (
<>
<EuiForm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { AgentConfigurationIntake } from '../../../../../../../../../../plugins/
import {
getOptionLabel,
omitAllOption
} from '../../../../../../../../../../plugins/apm/common/agent_configuration/constants';
} from '../../../../../../../../../../plugins/apm/common/agent_configuration/all_option';
import { callApmApi } from '../../../../../../services/rest/createCallApmApi';

export async function saveConfig({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { isEmpty } from 'lodash';
import { EuiTitle, EuiText, EuiSpacer } from '@elastic/eui';
import React, { useState, useEffect, useCallback } from 'react';
import { i18n } from '@kbn/i18n';
import { FetcherResult, FETCH_STATUS } from '../../../../../hooks/useFetcher';
import { FetcherResult } from '../../../../../hooks/useFetcher';
import { history } from '../../../../../utils/history';
import {
AgentConfigurationIntake,
Expand Down Expand Up @@ -90,6 +91,15 @@ export function AgentConfigurationCreateEdit({
if (pageStep === 'choose-service-step' && isEditMode) {
setPage('choose-settings-step');
}

// the user skipped the first step (select service)
if (
pageStep === 'choose-settings-step' &&
!isEditMode &&
isEmpty(newConfig.service)
) {
setPage('choose-service-step');
}
}, [isEditMode, newConfig, pageStep]);

const unsavedChanges = getUnsavedChanges({ newConfig, existingConfig });
Expand Down Expand Up @@ -128,7 +138,7 @@ export function AgentConfigurationCreateEdit({

{pageStep === 'choose-settings-step' && (
<SettingsPage
isLoading={existingConfigResult?.status === FETCH_STATUS.LOADING}
status={existingConfigResult?.status}
unsavedChanges={unsavedChanges}
onClickEdit={() => setPage('choose-service-step')}
newConfig={newConfig}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { NotificationsStart } from 'kibana/public';
import { i18n } from '@kbn/i18n';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { AgentConfigurationListAPIResponse } from '../../../../../../../../../plugins/apm/server/lib/settings/agent_configuration/list_configurations';
import { getOptionLabel } from '../../../../../../../../../plugins/apm/common/agent_configuration/constants';
import { getOptionLabel } from '../../../../../../../../../plugins/apm/common/agent_configuration/all_option';
import { callApmApi } from '../../../../../services/rest/createCallApmApi';
import { useApmPluginContext } from '../../../../../hooks/useApmPluginContext';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { LoadingStatePrompt } from '../../../../shared/LoadingStatePrompt';
import { AgentConfigurationListAPIResponse } from '../../../../../../../../../plugins/apm/server/lib/settings/agent_configuration/list_configurations';
import { TimestampTooltip } from '../../../../shared/TimestampTooltip';
import { px, units } from '../../../../../style/variables';
import { getOptionLabel } from '../../../../../../../../../plugins/apm/common/agent_configuration/constants';
import { getOptionLabel } from '../../../../../../../../../plugins/apm/common/agent_configuration/all_option';
import {
createAgentConfigurationHref,
editAgentConfigurationHref
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
SERVICE_NAME,
SERVICE_ENVIRONMENT
} from '../../../../../common/elasticsearch_fieldnames';
import { ALL_OPTION_VALUE } from '../../../../../common/agent_configuration/constants';
import { ALL_OPTION_VALUE } from '../../../../../common/agent_configuration/all_option';

export async function getAllEnvironments({
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SERVICE_NAME,
SERVICE_ENVIRONMENT
} from '../../../../../common/elasticsearch_fieldnames';
import { ALL_OPTION_VALUE } from '../../../../../common/agent_configuration/constants';
import { ALL_OPTION_VALUE } from '../../../../../common/agent_configuration/all_option';

export async function getExistingEnvironmentsForService({
serviceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
PROCESSOR_EVENT,
SERVICE_NAME
} from '../../../../common/elasticsearch_fieldnames';
import { ALL_OPTION_VALUE } from '../../../../common/agent_configuration/constants';
import { ALL_OPTION_VALUE } from '../../../../common/agent_configuration/all_option';

export type AgentConfigurationServicesAPIResponse = PromiseReturnType<
typeof getServiceNames
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import expect from '@kbn/expect';
import { AgentConfigurationIntake } from '../../../../plugins/apm/common/runtime_types/agent_configuration/configuration_types';
import { AgentConfigurationIntake } from '../../../../plugins/apm/common/agent_configuration/configuration_types';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function agentConfigurationTests({ getService }: FtrProviderContext) {
Expand Down

0 comments on commit d83d7a1

Please sign in to comment.