Skip to content

Commit fd2e9d0

Browse files
authored
Convert default_watch.json to a JS object in order to avoid TS complaints (#89488)
* Remove unused defaultWatchJson static member from public JsonWatch model.
1 parent b2d4412 commit fd2e9d0

File tree

7 files changed

+62
-51
lines changed

7 files changed

+62
-51
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
export const defaultWatch = {
8+
trigger: {
9+
schedule: {
10+
interval: '30m',
11+
},
12+
},
13+
input: {
14+
search: {
15+
request: {
16+
body: {
17+
size: 0,
18+
query: {
19+
match_all: {},
20+
},
21+
},
22+
indices: ['*'],
23+
},
24+
},
25+
},
26+
condition: {
27+
compare: {
28+
'ctx.payload.hits.total': {
29+
gte: 10,
30+
},
31+
},
32+
},
33+
actions: {
34+
'my-logging-action': {
35+
logging: {
36+
text: 'There are {{ctx.payload.hits.total}} documents in your index. Threshold is 10.',
37+
},
38+
},
39+
},
40+
};

x-pack/plugins/watcher/public/application/models/watch/default_watch.json

Lines changed: 0 additions & 33 deletions
This file was deleted.

x-pack/plugins/watcher/public/application/models/watch/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*/
66

77
export const Watch: any;
8+
export const defaultWatch: any;

x-pack/plugins/watcher/public/application/models/watch/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
*/
66

77
export { Watch } from './watch';
8+
export { defaultWatch } from './default_watch';

x-pack/plugins/watcher/public/application/models/watch/json_watch.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
import uuid from 'uuid';
88
import { get } from 'lodash';
9-
import { BaseWatch } from './base_watch';
10-
import { ACTION_TYPES, WATCH_TYPES } from '../../../../common/constants';
11-
import defaultWatchJson from './default_watch.json';
129
import { i18n } from '@kbn/i18n';
1310

11+
import { ACTION_TYPES, WATCH_TYPES } from '../../../../common/constants';
12+
import { BaseWatch } from './base_watch';
13+
import { defaultWatch } from './default_watch';
14+
1415
/**
1516
* {@code JsonWatch} allows a user to create a Watch by writing the raw JSON.
1617
*/
@@ -20,11 +21,11 @@ export class JsonWatch extends BaseWatch {
2021
props.id = typeof props.id === 'undefined' ? uuid.v4() : props.id;
2122
super(props);
2223
const existingWatch = get(props, 'watch');
23-
this.watch = existingWatch ? existingWatch : defaultWatchJson;
24+
this.watch = existingWatch ? existingWatch : defaultWatch;
2425
this.watchString = get(
2526
props,
2627
'watchString',
27-
JSON.stringify(existingWatch ? existingWatch : defaultWatchJson, null, 2)
28+
JSON.stringify(existingWatch ? existingWatch : defaultWatch, null, 2)
2829
);
2930
this.id = props.id;
3031
}
@@ -113,7 +114,6 @@ export class JsonWatch extends BaseWatch {
113114
return new JsonWatch(upstreamWatch);
114115
}
115116

116-
static defaultWatchJson = defaultWatchJson;
117117
static typeName = i18n.translate('xpack.watcher.models.jsonWatch.typeName', {
118118
defaultMessage: 'Advanced Watch',
119119
});

x-pack/plugins/watcher/tests_client_integration/watch_create_json.test.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
*/
66

77
import { act } from 'react-dom/test-utils';
8+
9+
import { getExecuteDetails } from '../__fixtures__';
10+
import { defaultWatch } from '../public/application/models/watch';
811
import { setupEnvironment, pageHelpers, nextTick, wrapBodyResponse } from './helpers';
912
import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers';
1013
import { WATCH } from './helpers/jest_constants';
11-
import defaultWatchJson from '../public/application/models/watch/default_watch.json';
12-
import { getExecuteDetails } from '../__fixtures__';
1314

1415
const { setup } = pageHelpers.watchCreateJson;
1516

@@ -117,7 +118,7 @@ describe('<JsonWatchEdit /> create route', () => {
117118
},
118119
},
119120
],
120-
watch: defaultWatchJson,
121+
watch: defaultWatch,
121122
})
122123
);
123124
});
@@ -172,7 +173,7 @@ describe('<JsonWatchEdit /> create route', () => {
172173

173174
const latestRequest = server.requests[server.requests.length - 1];
174175

175-
const actionModes = Object.keys(defaultWatchJson.actions).reduce(
176+
const actionModes = Object.keys(defaultWatch.actions).reduce(
176177
(actionAccum: any, action) => {
177178
actionAccum[action] = 'simulate';
178179
return actionAccum;
@@ -186,7 +187,7 @@ describe('<JsonWatchEdit /> create route', () => {
186187
isNew: true,
187188
isActive: true,
188189
actions: [],
189-
watch: defaultWatchJson,
190+
watch: defaultWatch,
190191
};
191192

192193
expect(latestRequest.requestBody).toEqual(
@@ -234,7 +235,7 @@ describe('<JsonWatchEdit /> create route', () => {
234235

235236
const latestRequest = server.requests[server.requests.length - 1];
236237

237-
const actionModes = Object.keys(defaultWatchJson.actions).reduce(
238+
const actionModes = Object.keys(defaultWatch.actions).reduce(
238239
(actionAccum: any, action) => {
239240
actionAccum[action] = ACTION_MODE;
240241
return actionAccum;
@@ -248,7 +249,7 @@ describe('<JsonWatchEdit /> create route', () => {
248249
isNew: true,
249250
isActive: true,
250251
actions: [],
251-
watch: defaultWatchJson,
252+
watch: defaultWatch,
252253
};
253254

254255
const triggeredTime = `now+${TRIGGERED_TIME}s`;

x-pack/plugins/watcher/tests_client_integration/watch_edit.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import { act } from 'react-dom/test-utils';
88
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
99
import axios from 'axios';
10+
import { getRandomString } from '@kbn/test/jest';
11+
12+
import { getWatch } from '../__fixtures__';
13+
import { defaultWatch } from '../public/application/models/watch';
1014
import { setupEnvironment, pageHelpers, nextTick, wrapBodyResponse } from './helpers';
1115
import { WatchEditTestBed } from './helpers/watch_edit.helpers';
1216
import { WATCH } from './helpers/jest_constants';
13-
import defaultWatchJson from '../public/application/models/watch/default_watch.json';
14-
import { getWatch } from '../__fixtures__';
15-
import { getRandomString } from '@kbn/test/jest';
1617

1718
const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });
1819

@@ -69,7 +70,7 @@ describe('<WatchEdit />', () => {
6970
expect(exists('jsonWatchForm')).toBe(true);
7071
expect(find('nameInput').props().value).toBe(watch.name);
7172
expect(find('idInput').props().value).toBe(watch.id);
72-
expect(JSON.parse(codeEditor.props().value as string)).toEqual(defaultWatchJson);
73+
expect(JSON.parse(codeEditor.props().value as string)).toEqual(defaultWatch);
7374

7475
// ID should not be editable
7576
expect(find('idInput').props().readOnly).toEqual(true);
@@ -112,7 +113,7 @@ describe('<WatchEdit />', () => {
112113
},
113114
},
114115
],
115-
watch: defaultWatchJson,
116+
watch: defaultWatch,
116117
})
117118
);
118119
});

0 commit comments

Comments
 (0)