Skip to content

Commit 5924e4c

Browse files
committed
Flatten dynamic settings object, update saved object mapping.
1 parent 1106482 commit 5924e4c

14 files changed

Lines changed: 59 additions & 85 deletions

File tree

x-pack/plugins/uptime/common/constants/settings_defaults.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { DynamicSettings } from '../runtime_types';
88

99
export const DYNAMIC_SETTINGS_DEFAULTS: DynamicSettings = {
1010
heartbeatIndices: 'heartbeat-8*',
11-
certThresholds: {
12-
expiration: 30,
13-
age: 365,
14-
},
11+
certAgeThreshold: 365,
12+
certExpirationThreshold: 30,
1513
};

x-pack/plugins/uptime/common/runtime_types/dynamic_settings.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66

77
import * as t from 'io-ts';
88

9-
export const CertStateThresholdsType = t.type({
10-
age: t.number,
11-
expiration: t.number,
12-
});
13-
149
export const DynamicSettingsType = t.type({
1510
heartbeatIndices: t.string,
16-
certThresholds: CertStateThresholdsType,
11+
certAgeThreshold: t.number,
12+
certExpirationThreshold: t.number,
1713
});
1814

1915
export const DynamicSettingsSaveType = t.intersection([
@@ -27,4 +23,3 @@ export const DynamicSettingsSaveType = t.intersection([
2723

2824
export type DynamicSettings = t.TypeOf<typeof DynamicSettingsType>;
2925
export type DynamicSettingsSaveResponse = t.TypeOf<typeof DynamicSettingsSaveType>;
30-
export type CertStateThresholds = t.TypeOf<typeof CertStateThresholdsType>;

x-pack/plugins/uptime/public/components/settings/__tests__/__snapshots__/certificate_form.test.tsx.snap

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/uptime/public/components/settings/__tests__/__snapshots__/indices_form.test.tsx.snap

Lines changed: 2 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/uptime/public/components/settings/__tests__/certificate_form.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ describe('CertificateForm', () => {
1717
onChange={jest.fn()}
1818
formFields={{
1919
heartbeatIndices: 'heartbeat-8*',
20-
certThresholds: { expiration: 7, age: 36 },
20+
certExpirationThreshold: 7,
21+
certAgeThreshold: 36,
2122
}}
2223
fieldErrors={null}
2324
isDisabled={false}

x-pack/plugins/uptime/public/components/settings/__tests__/indices_form.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ describe('CertificateForm', () => {
1717
onChange={jest.fn()}
1818
formFields={{
1919
heartbeatIndices: 'heartbeat-8*',
20-
certThresholds: { expiration: 7, age: 36 },
20+
certAgeThreshold: 36,
21+
certExpirationThreshold: 7,
2122
}}
2223
fieldErrors={null}
2324
isDisabled={false}

x-pack/plugins/uptime/public/components/settings/certificate_form.tsx

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@ import {
1717
EuiFlexGroup,
1818
EuiFlexItem,
1919
} from '@elastic/eui';
20-
import { CertStateThresholds } from '../../../common/runtime_types';
2120
import { DYNAMIC_SETTINGS_DEFAULTS } from '../../../common/constants';
21+
import { DynamicSettings } from '../../../common/runtime_types';
2222
import { SettingsFormProps } from '../../pages/settings';
2323

24-
interface ChangedValues {
25-
heartbeatIndices?: string;
26-
certThresholds?: Partial<CertStateThresholds>;
27-
}
28-
29-
export type OnFieldChangeType = (changedValues: ChangedValues) => void;
24+
export type OnFieldChangeType = (changedValues: Partial<DynamicSettings>) => void;
3025

3126
export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({
3227
loading,
@@ -70,9 +65,7 @@ export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({
7065
id="xpack.uptime.sourceConfiguration.expirationThresholdDefaultValue"
7166
defaultMessage="The default value is {defaultValue}"
7267
values={{
73-
defaultValue: (
74-
<EuiCode>{DYNAMIC_SETTINGS_DEFAULTS.certThresholds.expiration}</EuiCode>
75-
),
68+
defaultValue: <EuiCode>{DYNAMIC_SETTINGS_DEFAULTS.certExpirationThreshold}</EuiCode>,
7669
}}
7770
/>
7871
}
@@ -91,12 +84,10 @@ export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({
9184
fullWidth
9285
disabled={isDisabled}
9386
isLoading={loading}
94-
value={formFields?.certThresholds?.expiration || ''}
87+
value={formFields?.certExpirationThreshold ?? ''}
9588
onChange={e =>
9689
onChange({
97-
certThresholds: {
98-
expiration: Number(e.target.value),
99-
},
90+
certExpirationThreshold: Number(e.target.value),
10091
})
10192
}
10293
/>
@@ -120,7 +111,7 @@ export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({
120111
id="xpack.uptime.sourceConfiguration.ageThresholdDefaultValue"
121112
defaultMessage="The default value is {defaultValue}"
122113
values={{
123-
defaultValue: <EuiCode>{DYNAMIC_SETTINGS_DEFAULTS.certThresholds.age}</EuiCode>,
114+
defaultValue: <EuiCode>{DYNAMIC_SETTINGS_DEFAULTS.certAgeThreshold}</EuiCode>,
124115
}}
125116
/>
126117
}
@@ -139,10 +130,10 @@ export const CertificateExpirationForm: React.FC<SettingsFormProps> = ({
139130
fullWidth
140131
disabled={isDisabled}
141132
isLoading={loading}
142-
value={formFields?.certThresholds?.age || ''}
133+
value={formFields?.certAgeThreshold ?? ''}
143134
onChange={e =>
144135
onChange({
145-
certThresholds: { age: Number(e.currentTarget.value) },
136+
certAgeThreshold: Number(e.currentTarget.value),
146137
})
147138
}
148139
/>

x-pack/plugins/uptime/public/pages/settings.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ export interface SettingsFormProps {
5252
const getFieldErrors = (formFields: DynamicSettings | null): SettingsPageFieldErrors | null => {
5353
if (formFields) {
5454
const blankStr = 'May not be blank';
55-
const { certThresholds: certificatesThresholds, heartbeatIndices } = formFields;
55+
const { certAgeThreshold, certExpirationThreshold, heartbeatIndices } = formFields;
5656
const heartbeatIndErr = heartbeatIndices.match(/^\S+$/) ? '' : blankStr;
57-
const expirationThresholdError = certificatesThresholds?.expiration ? null : blankStr;
58-
const ageThresholdError = certificatesThresholds?.age ? null : blankStr;
57+
const expirationThresholdError = certExpirationThreshold ? null : blankStr;
58+
const ageThresholdError = certAgeThreshold ? null : blankStr;
5959
return {
6060
heartbeatIndices: heartbeatIndErr,
6161
certificatesThresholds:
@@ -98,12 +98,14 @@ export const SettingsPage = () => {
9898
const onChangeFormField: OnFieldChangeType = changedField => {
9999
if (formFields) {
100100
setFormFields({
101-
heartbeatIndices: changedField.heartbeatIndices ?? formFields.heartbeatIndices,
102-
certThresholds: Object.assign(
103-
{},
104-
formFields.certThresholds,
105-
changedField?.certThresholds ?? null
106-
),
101+
...formFields,
102+
...changedField,
103+
// heartbeatIndices: changedField.heartbeatIndices ?? formFields.heartbeatIndices,
104+
// certThresholds: Object.assign(
105+
// {},
106+
// formFields.certThresholds,
107+
// changedField?.certThresholds ?? null
108+
// ),
107109
});
108110
}
109111
};

x-pack/plugins/uptime/server/lib/alerts/__tests__/status_check.test.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,8 @@ describe('status check alert', () => {
8888
Object {
8989
"callES": [MockFunction],
9090
"dynamicSettings": Object {
91-
"certThresholds": Object {
92-
"age": 365,
93-
"expiration": 30,
94-
},
91+
"certAgeThreshold": 365,
92+
"certExpirationThreshold": 30,
9593
"heartbeatIndices": "heartbeat-8*",
9694
},
9795
"locations": Array [],
@@ -135,10 +133,8 @@ describe('status check alert', () => {
135133
Object {
136134
"callES": [MockFunction],
137135
"dynamicSettings": Object {
138-
"certThresholds": Object {
139-
"age": 365,
140-
"expiration": 30,
141-
},
136+
"certAgeThreshold": 365,
137+
"certExpirationThreshold": 30,
142138
"heartbeatIndices": "heartbeat-8*",
143139
},
144140
"locations": Array [],

x-pack/plugins/uptime/server/lib/requests/__tests__/get_certs.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ describe('getCerts', () => {
8989
callES: mockCallES,
9090
dynamicSettings: {
9191
heartbeatIndices: 'heartbeat*',
92-
certThresholds: DYNAMIC_SETTINGS_DEFAULTS.certThresholds,
92+
certAgeThreshold: DYNAMIC_SETTINGS_DEFAULTS.certAgeThreshold,
93+
certExpirationThreshold: DYNAMIC_SETTINGS_DEFAULTS.certExpirationThreshold,
9394
},
9495
index: 1,
9596
from: 'now-2d',

0 commit comments

Comments
 (0)