-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Uptime] Certificate expiration threshold settings #63682
Merged
shahzad31
merged 7 commits into
elastic:master
from
shahzad31:certificate-threshold-settings
Apr 16, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a193f46
update settings
shahzad31 3f3ea12
added cert form
shahzad31 f703b94
update settings
shahzad31 aa3b048
update types
shahzad31 9a009ca
update test
shahzad31 3074ed4
updated tests
shahzad31 ac2e520
updated snapshots
shahzad31 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
.../uptime/public/components/settings/__tests__/__snapshots__/certificate_form.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
...gins/uptime/public/components/settings/__tests__/__snapshots__/indices_form.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
x-pack/legacy/plugins/uptime/public/components/settings/__tests__/certificate_form.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { CertificateExpirationForm } from '../certificate_form'; | ||
import { shallowWithRouter } from '../../../lib'; | ||
|
||
describe('CertificateForm', () => { | ||
it('shallow renders expected elements for valid props', () => { | ||
expect( | ||
shallowWithRouter( | ||
<CertificateExpirationForm | ||
onChange={jest.fn()} | ||
formFields={{ | ||
heartbeatIndices: 'heartbeat-8*', | ||
certificatesThresholds: { errorState: 7, warningState: 36 }, | ||
}} | ||
fieldErrors={{}} | ||
isDisabled={false} | ||
/> | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
x-pack/legacy/plugins/uptime/public/components/settings/__tests__/indices_form.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { IndicesForm } from '../indices_form'; | ||
import { shallowWithRouter } from '../../../lib'; | ||
|
||
describe('CertificateForm', () => { | ||
it('shallow renders expected elements for valid props', () => { | ||
expect( | ||
shallowWithRouter( | ||
<IndicesForm | ||
onChange={jest.fn()} | ||
formFields={{ | ||
heartbeatIndices: 'heartbeat-8*', | ||
certificatesThresholds: { errorState: 7, warningState: 36 }, | ||
}} | ||
fieldErrors={{}} | ||
isDisabled={false} | ||
/> | ||
) | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
160 changes: 160 additions & 0 deletions
160
x-pack/legacy/plugins/uptime/public/components/settings/certificate_form.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { useSelector } from 'react-redux'; | ||
import { | ||
EuiDescribedFormGroup, | ||
EuiFormRow, | ||
EuiCode, | ||
EuiFieldNumber, | ||
EuiTitle, | ||
EuiSpacer, | ||
EuiSelect, | ||
EuiFlexGroup, | ||
EuiFlexItem, | ||
} from '@elastic/eui'; | ||
import { defaultDynamicSettings, DynamicSettings } from '../../../common/runtime_types'; | ||
import { selectDynamicSettings } from '../../state/selectors'; | ||
|
||
type NumStr = string | number; | ||
|
||
export type OnFieldChangeType = (field: string, value?: NumStr) => void; | ||
|
||
export interface SettingsFormProps { | ||
onChange: OnFieldChangeType; | ||
formFields: DynamicSettings | null; | ||
fieldErrors: any; | ||
isDisabled: boolean; | ||
} | ||
|
||
export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({ | ||
onChange, | ||
formFields, | ||
fieldErrors, | ||
isDisabled, | ||
}) => { | ||
const dss = useSelector(selectDynamicSettings); | ||
|
||
return ( | ||
<> | ||
<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.stateThresholds" | ||
defaultMessage="Expiration State Thresholds" | ||
/> | ||
</h4> | ||
} | ||
description={ | ||
<FormattedMessage | ||
id="xpack.uptime.sourceConfiguration.stateThresholdsDescription" | ||
defaultMessage="Set certificate expiration warning/error thresholds" | ||
/> | ||
} | ||
> | ||
<EuiFormRow | ||
describedByIds={['errorState']} | ||
error={fieldErrors?.certificatesThresholds?.errorState} | ||
fullWidth | ||
helpText={ | ||
<FormattedMessage | ||
id="xpack.uptime.sourceConfiguration.errorStateDefaultValue" | ||
defaultMessage="The default value is {defaultValue}" | ||
values={{ | ||
defaultValue: ( | ||
<EuiCode>{defaultDynamicSettings?.certificatesThresholds?.errorState}</EuiCode> | ||
), | ||
}} | ||
/> | ||
} | ||
isInvalid={!!fieldErrors?.certificatesThresholds?.errorState} | ||
label={ | ||
<FormattedMessage | ||
id="xpack.uptime.sourceConfiguration.errorStateLabel" | ||
defaultMessage="Error state" | ||
/> | ||
} | ||
> | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={2}> | ||
<EuiFieldNumber | ||
data-test-subj={`error-state-threshold-input-${dss.loading ? 'loading' : 'loaded'}`} | ||
fullWidth | ||
disabled={isDisabled} | ||
isLoading={dss.loading} | ||
value={formFields?.certificatesThresholds?.errorState || ''} | ||
onChange={({ currentTarget: { value } }: any) => | ||
onChange( | ||
'certificatesThresholds.errorState', | ||
value === '' ? undefined : Number(value) | ||
) | ||
} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={1}> | ||
<EuiSelect options={[{ value: 'day', text: 'Days' }]} /> | ||
</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>{defaultDynamicSettings?.certificatesThresholds?.warningState}</EuiCode> | ||
), | ||
}} | ||
/> | ||
} | ||
isInvalid={!!fieldErrors?.certificatesThresholds?.warningState} | ||
label={ | ||
<FormattedMessage | ||
id="xpack.uptime.sourceConfiguration.warningStateLabel" | ||
defaultMessage="Warning state" | ||
/> | ||
} | ||
> | ||
<EuiFlexGroup> | ||
<EuiFlexItem grow={2}> | ||
<EuiFieldNumber | ||
data-test-subj={`warning-state-threshold-input-${ | ||
dss.loading ? 'loading' : 'loaded' | ||
}`} | ||
fullWidth | ||
disabled={isDisabled} | ||
isLoading={dss.loading} | ||
value={formFields?.certificatesThresholds?.warningState || ''} | ||
onChange={(event: any) => | ||
onChange('certificatesThresholds.warningState', Number(event.currentTarget.value)) | ||
} | ||
/> | ||
</EuiFlexItem> | ||
<EuiFlexItem grow={1}> | ||
<EuiSelect options={[{ value: 'day', text: 'Days' }]} /> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFormRow> | ||
</EuiDescribedFormGroup> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want more options here besides
day
? If not we may not want to use a Select here.