Skip to content

Commit

Permalink
Implement PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
justinkambic committed Apr 23, 2020
1 parent f7678b6 commit 0ddd97b
Show file tree
Hide file tree
Showing 12 changed files with 230 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DynamicSettings } from '../runtime_types';

export const DYNAMIC_SETTINGS_DEFAULTS: DynamicSettings = {
heartbeatIndices: 'heartbeat-8*',
certificatesThresholds: {
certThresholds: {
expiration: 30,
age: 365,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@

import * as t from 'io-ts';

export const CertificatesStatesThresholdType = t.partial({
export const CertStateThresholdsType = t.type({
age: t.number,
expiration: t.number,
});

export const DynamicSettingsType = t.intersection([
t.type({
heartbeatIndices: t.string,
}),
t.partial({
certificatesThresholds: CertificatesStatesThresholdType,
}),
]);
export const DynamicSettingsType = t.type({
heartbeatIndices: t.string,
certThresholds: CertStateThresholdsType,
});

export const DynamicSettingsSaveType = t.intersection([
t.type({
Expand All @@ -31,4 +27,4 @@ export const DynamicSettingsSaveType = t.intersection([

export type DynamicSettings = t.TypeOf<typeof DynamicSettingsType>;
export type DynamicSettingsSaveResponse = t.TypeOf<typeof DynamicSettingsSaveType>;
export type CertificatesStatesThreshold = t.TypeOf<typeof CertificatesStatesThresholdType>;
export type CertStateThresholds = t.TypeOf<typeof CertStateThresholdsType>;
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ describe('CertificateForm', () => {
expect(
shallowWithRouter(
<CertificateExpirationForm
loading={false}
onChange={jest.fn()}
formFields={{
heartbeatIndices: 'heartbeat-8*',
certificatesThresholds: { expiration: 7, age: 36 },
certThresholds: { expiration: 7, age: 36 },
}}
fieldErrors={{}}
isDisabled={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ describe('CertificateForm', () => {
expect(
shallowWithRouter(
<IndicesForm
loading={false}
onChange={jest.fn()}
formFields={{
heartbeatIndices: 'heartbeat-8*',
certificatesThresholds: { expiration: 7, age: 36 },
certThresholds: { expiration: 7, age: 36 },
}}
fieldErrors={{}}
isDisabled={false}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import React from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { useSelector } from 'react-redux';
import {
EuiDescribedFormGroup,
EuiFormRow,
Expand All @@ -18,148 +17,153 @@ import {
EuiFlexGroup,
EuiFlexItem,
} from '@elastic/eui';
import { DynamicSettings } from '../../../common/runtime_types';
import { selectDynamicSettings } from '../../state/selectors';
import { DynamicSettings, CertStateThresholds } from '../../../common/runtime_types';
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../common/constants';

export type OnFieldChangeType = (changedValues: Partial<DynamicSettings>) => void;
interface ChangedValues {
heartbeatIndices?: string;
certThresholds?: Partial<CertStateThresholds>;
}

export type OnFieldChangeType = (changedValues: ChangedValues) => void;

export interface SettingsFormProps {
loading: boolean;
onChange: OnFieldChangeType;
formFields: DynamicSettings | null;
fieldErrors: any;
isDisabled: boolean;
}

export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({
loading,
onChange,
formFields,
fieldErrors,
isDisabled,
}) => {
const dss = useSelector(selectDynamicSettings);

return (
<>
<EuiTitle size="s">
<h3>
}) => (
<>
<EuiTitle size="s">
<h3>
<FormattedMessage
id="xpack.uptime.sourceConfiguration.certificationSectionTitle"
defaultMessage="Certificate Expiration"
/>
</h3>
</EuiTitle>
<EuiSpacer size="m" />
<EuiDescribedFormGroup
title={
<h4>
<FormattedMessage
id="xpack.uptime.sourceConfiguration.certificationSectionTitle"
defaultMessage="Certificate Expiration"
id="xpack.uptime.sourceConfiguration.expirationThreshold"
defaultMessage="Expiration/Age Thresholds"
/>
</h4>
}
description={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.certificateThresholdDescription"
defaultMessage="Change the threshold for displaying and alerting on certificate errors. Note, this will affect any configured alerts"
/>
}
>
<EuiFormRow
describedByIds={['errorState']}
error={fieldErrors?.certificatesThresholds?.errorState}
fullWidth
helpText={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.expirationThresholdDefaultValue"
defaultMessage="The default value is {defaultValue}"
values={{
defaultValue: (
<EuiCode>{DYNAMIC_SETTINGS_DEFAULTS.certThresholds.expiration}</EuiCode>
),
}}
/>
</h3>
</EuiTitle>
<EuiSpacer size="m" />
<EuiDescribedFormGroup
title={
<h4>
<FormattedMessage
id="xpack.uptime.sourceConfiguration.expirationThreshold"
defaultMessage="Expiration/Age Thresholds"
/>
</h4>
}
description={
isInvalid={!!fieldErrors?.certificatesThresholds?.errorState}
label={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.certificateThresholdDescription"
defaultMessage="Set certificate expiration/age thresholds"
id="xpack.uptime.sourceConfiguration.errorStateLabel"
defaultMessage="Expiration threshold"
/>
}
>
<EuiFormRow
describedByIds={['errorState']}
error={fieldErrors?.certificatesThresholds?.errorState}
fullWidth
helpText={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.errorStateDefaultValue"
defaultMessage="The default value is {defaultValue}"
values={{
defaultValue: <EuiCode>{dss.settings.certificatesThresholds?.expiration}</EuiCode>,
}}
<EuiFlexGroup>
<EuiFlexItem grow={2}>
<EuiFieldNumber
data-test-subj={`expiration-threshold-input-${loading ? 'loading' : 'loaded'}`}
fullWidth
disabled={isDisabled}
isLoading={loading}
value={formFields?.certThresholds?.expiration || ''}
onChange={e =>
onChange({
certThresholds: {
expiration: Number(e.target.value),
},
})
}
/>
}
isInvalid={!!fieldErrors?.certificatesThresholds?.errorState}
label={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.errorStateLabel"
defaultMessage="Expiration threshold"
/>
}
>
<EuiFlexGroup>
<EuiFlexItem grow={2}>
<EuiFieldNumber
data-test-subj={`expiration-threshold-input-${dss.loading ? 'loading' : 'loaded'}`}
fullWidth
disabled={isDisabled}
isLoading={dss.loading}
value={formFields?.certificatesThresholds?.expiration || ''}
onChange={({ currentTarget: { value } }: any) =>
onChange({
certificatesThresholds: {
expiration: Number(value),
},
})
}
</EuiFlexItem>
<EuiFlexItem grow={1}>
<EuiText>
<FormattedMessage
id="xpack.uptime.sourceConfiguration.ageLimit.units.days"
defaultMessage="Days"
/>
</EuiFlexItem>
<EuiFlexItem grow={1}>
<EuiText>
<FormattedMessage
id="xpack.uptime.sourceConfiguration.ageLimit.units.days"
defaultMessage="Days"
/>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFormRow>
<EuiFormRow
describedByIds={['warningState']}
error={fieldErrors?.certificatesThresholds?.warningState}
fullWidth
helpText={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.warningStateDefaultValue"
defaultMessage="The default value is {defaultValue}"
values={{
defaultValue: <EuiCode>{dss.settings.certificatesThresholds?.age}</EuiCode>,
}}
/>
}
isInvalid={!!fieldErrors?.certificatesThresholds?.warningState}
label={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.warningStateLabel"
defaultMessage="Age limit"
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFormRow>
<EuiFormRow
describedByIds={['warningState']}
error={fieldErrors?.certificatesThresholds?.warningState}
fullWidth
helpText={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.ageThresholdDefaultValue"
defaultMessage="The default value is {defaultValue}"
values={{
defaultValue: <EuiCode>{DYNAMIC_SETTINGS_DEFAULTS.certThresholds.age}</EuiCode>,
}}
/>
}
isInvalid={!!fieldErrors?.certificatesThresholds?.warningState}
label={
<FormattedMessage
id="xpack.uptime.sourceConfiguration.warningStateLabel"
defaultMessage="Age limit"
/>
}
>
<EuiFlexGroup>
<EuiFlexItem grow={2}>
<EuiFieldNumber
data-test-subj={`age-threshold-input-${loading ? 'loading' : 'loaded'}`}
fullWidth
disabled={isDisabled}
isLoading={loading}
value={formFields?.certThresholds?.age || ''}
onChange={e =>
onChange({
certThresholds: { age: Number(e.currentTarget.value) },
})
}
/>
}
>
<EuiFlexGroup>
<EuiFlexItem grow={2}>
<EuiFieldNumber
data-test-subj={`age-threshold-input-${dss.loading ? 'loading' : 'loaded'}`}
fullWidth
disabled={isDisabled}
isLoading={dss.loading}
value={formFields?.certificatesThresholds?.age || ''}
onChange={(event: any) =>
onChange({
certificatesThresholds: { age: Number(event.currentTarget.value) },
})
}
</EuiFlexItem>
<EuiFlexItem grow={1}>
<EuiText>
<FormattedMessage
id="xpack.uptime.sourceConfiguration.ageLimit.units.days"
defaultMessage="Days"
/>
</EuiFlexItem>
<EuiFlexItem grow={1}>
<EuiText>
<FormattedMessage
id="xpack.uptime.sourceConfiguration.ageLimit.units.days"
defaultMessage="Days"
/>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFormRow>
</EuiDescribedFormGroup>
</>
);
};
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFormRow>
</EuiDescribedFormGroup>
</>
);
Loading

0 comments on commit 0ddd97b

Please sign in to comment.