Convert default_watch.json to a JS object in order to avoid TS complaints (#89488)

* Remove unused defaultWatchJson static member from public JsonWatch model.
This commit is contained in:
CJ Cenizal 2021-01-27 16:21:30 -08:00 committed by GitHub
parent b2d4412146
commit fd2e9d0821
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 62 additions and 51 deletions

View file

@ -0,0 +1,40 @@
/*
* 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.
*/
export const defaultWatch = {
trigger: {
schedule: {
interval: '30m',
},
},
input: {
search: {
request: {
body: {
size: 0,
query: {
match_all: {},
},
},
indices: ['*'],
},
},
},
condition: {
compare: {
'ctx.payload.hits.total': {
gte: 10,
},
},
},
actions: {
'my-logging-action': {
logging: {
text: 'There are {{ctx.payload.hits.total}} documents in your index. Threshold is 10.',
},
},
},
};

View file

@ -1,33 +0,0 @@
{
"trigger": {
"schedule": {
"interval": "30m"
}
},
"input": {
"search": {
"request": {
"body": {
"size": 0,
"query" : {
"match_all": {}
}
},
"indices": [ "*" ]
}
}
},
"condition": {
"compare": {
"ctx.payload.hits.total": {
"gte": 10
}
}},
"actions": {
"my-logging-action": {
"logging": {
"text": "There are {{ctx.payload.hits.total}} documents in your index. Threshold is 10."
}
}
}
}

View file

@ -5,3 +5,4 @@
*/
export const Watch: any;
export const defaultWatch: any;

View file

@ -5,3 +5,4 @@
*/
export { Watch } from './watch';
export { defaultWatch } from './default_watch';

View file

@ -6,11 +6,12 @@
import uuid from 'uuid';
import { get } from 'lodash';
import { BaseWatch } from './base_watch';
import { ACTION_TYPES, WATCH_TYPES } from '../../../../common/constants';
import defaultWatchJson from './default_watch.json';
import { i18n } from '@kbn/i18n';
import { ACTION_TYPES, WATCH_TYPES } from '../../../../common/constants';
import { BaseWatch } from './base_watch';
import { defaultWatch } from './default_watch';
/**
* {@code JsonWatch} allows a user to create a Watch by writing the raw JSON.
*/
@ -20,11 +21,11 @@ export class JsonWatch extends BaseWatch {
props.id = typeof props.id === 'undefined' ? uuid.v4() : props.id;
super(props);
const existingWatch = get(props, 'watch');
this.watch = existingWatch ? existingWatch : defaultWatchJson;
this.watch = existingWatch ? existingWatch : defaultWatch;
this.watchString = get(
props,
'watchString',
JSON.stringify(existingWatch ? existingWatch : defaultWatchJson, null, 2)
JSON.stringify(existingWatch ? existingWatch : defaultWatch, null, 2)
);
this.id = props.id;
}
@ -113,7 +114,6 @@ export class JsonWatch extends BaseWatch {
return new JsonWatch(upstreamWatch);
}
static defaultWatchJson = defaultWatchJson;
static typeName = i18n.translate('xpack.watcher.models.jsonWatch.typeName', {
defaultMessage: 'Advanced Watch',
});

View file

@ -5,11 +5,12 @@
*/
import { act } from 'react-dom/test-utils';
import { getExecuteDetails } from '../__fixtures__';
import { defaultWatch } from '../public/application/models/watch';
import { setupEnvironment, pageHelpers, nextTick, wrapBodyResponse } from './helpers';
import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers';
import { WATCH } from './helpers/jest_constants';
import defaultWatchJson from '../public/application/models/watch/default_watch.json';
import { getExecuteDetails } from '../__fixtures__';
const { setup } = pageHelpers.watchCreateJson;
@ -117,7 +118,7 @@ describe('<JsonWatchEdit /> create route', () => {
},
},
],
watch: defaultWatchJson,
watch: defaultWatch,
})
);
});
@ -172,7 +173,7 @@ describe('<JsonWatchEdit /> create route', () => {
const latestRequest = server.requests[server.requests.length - 1];
const actionModes = Object.keys(defaultWatchJson.actions).reduce(
const actionModes = Object.keys(defaultWatch.actions).reduce(
(actionAccum: any, action) => {
actionAccum[action] = 'simulate';
return actionAccum;
@ -186,7 +187,7 @@ describe('<JsonWatchEdit /> create route', () => {
isNew: true,
isActive: true,
actions: [],
watch: defaultWatchJson,
watch: defaultWatch,
};
expect(latestRequest.requestBody).toEqual(
@ -234,7 +235,7 @@ describe('<JsonWatchEdit /> create route', () => {
const latestRequest = server.requests[server.requests.length - 1];
const actionModes = Object.keys(defaultWatchJson.actions).reduce(
const actionModes = Object.keys(defaultWatch.actions).reduce(
(actionAccum: any, action) => {
actionAccum[action] = ACTION_MODE;
return actionAccum;
@ -248,7 +249,7 @@ describe('<JsonWatchEdit /> create route', () => {
isNew: true,
isActive: true,
actions: [],
watch: defaultWatchJson,
watch: defaultWatch,
};
const triggeredTime = `now+${TRIGGERED_TIME}s`;

View file

@ -7,12 +7,13 @@
import { act } from 'react-dom/test-utils';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
import axios from 'axios';
import { getRandomString } from '@kbn/test/jest';
import { getWatch } from '../__fixtures__';
import { defaultWatch } from '../public/application/models/watch';
import { setupEnvironment, pageHelpers, nextTick, wrapBodyResponse } from './helpers';
import { WatchEditTestBed } from './helpers/watch_edit.helpers';
import { WATCH } from './helpers/jest_constants';
import defaultWatchJson from '../public/application/models/watch/default_watch.json';
import { getWatch } from '../__fixtures__';
import { getRandomString } from '@kbn/test/jest';
const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });
@ -69,7 +70,7 @@ describe('<WatchEdit />', () => {
expect(exists('jsonWatchForm')).toBe(true);
expect(find('nameInput').props().value).toBe(watch.name);
expect(find('idInput').props().value).toBe(watch.id);
expect(JSON.parse(codeEditor.props().value as string)).toEqual(defaultWatchJson);
expect(JSON.parse(codeEditor.props().value as string)).toEqual(defaultWatch);
// ID should not be editable
expect(find('idInput').props().readOnly).toEqual(true);
@ -112,7 +113,7 @@ describe('<WatchEdit />', () => {
},
},
],
watch: defaultWatchJson,
watch: defaultWatch,
})
);
});