mirror of
https://github.com/elastic/kibana.git
synced 2025-04-25 02:09:32 -04:00
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:
parent
b2d4412146
commit
fd2e9d0821
7 changed files with 62 additions and 51 deletions
|
@ -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.',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
|
@ -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."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,3 +5,4 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const Watch: any;
|
export const Watch: any;
|
||||||
|
export const defaultWatch: any;
|
||||||
|
|
|
@ -5,3 +5,4 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export { Watch } from './watch';
|
export { Watch } from './watch';
|
||||||
|
export { defaultWatch } from './default_watch';
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
|
|
||||||
import uuid from 'uuid';
|
import uuid from 'uuid';
|
||||||
import { get } from 'lodash';
|
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 { 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.
|
* {@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;
|
props.id = typeof props.id === 'undefined' ? uuid.v4() : props.id;
|
||||||
super(props);
|
super(props);
|
||||||
const existingWatch = get(props, 'watch');
|
const existingWatch = get(props, 'watch');
|
||||||
this.watch = existingWatch ? existingWatch : defaultWatchJson;
|
this.watch = existingWatch ? existingWatch : defaultWatch;
|
||||||
this.watchString = get(
|
this.watchString = get(
|
||||||
props,
|
props,
|
||||||
'watchString',
|
'watchString',
|
||||||
JSON.stringify(existingWatch ? existingWatch : defaultWatchJson, null, 2)
|
JSON.stringify(existingWatch ? existingWatch : defaultWatch, null, 2)
|
||||||
);
|
);
|
||||||
this.id = props.id;
|
this.id = props.id;
|
||||||
}
|
}
|
||||||
|
@ -113,7 +114,6 @@ export class JsonWatch extends BaseWatch {
|
||||||
return new JsonWatch(upstreamWatch);
|
return new JsonWatch(upstreamWatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static defaultWatchJson = defaultWatchJson;
|
|
||||||
static typeName = i18n.translate('xpack.watcher.models.jsonWatch.typeName', {
|
static typeName = i18n.translate('xpack.watcher.models.jsonWatch.typeName', {
|
||||||
defaultMessage: 'Advanced Watch',
|
defaultMessage: 'Advanced Watch',
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { act } from 'react-dom/test-utils';
|
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 { setupEnvironment, pageHelpers, nextTick, wrapBodyResponse } from './helpers';
|
||||||
import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers';
|
import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers';
|
||||||
import { WATCH } from './helpers/jest_constants';
|
import { WATCH } from './helpers/jest_constants';
|
||||||
import defaultWatchJson from '../public/application/models/watch/default_watch.json';
|
|
||||||
import { getExecuteDetails } from '../__fixtures__';
|
|
||||||
|
|
||||||
const { setup } = pageHelpers.watchCreateJson;
|
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 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: any, action) => {
|
||||||
actionAccum[action] = 'simulate';
|
actionAccum[action] = 'simulate';
|
||||||
return actionAccum;
|
return actionAccum;
|
||||||
|
@ -186,7 +187,7 @@ describe('<JsonWatchEdit /> create route', () => {
|
||||||
isNew: true,
|
isNew: true,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
actions: [],
|
actions: [],
|
||||||
watch: defaultWatchJson,
|
watch: defaultWatch,
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(latestRequest.requestBody).toEqual(
|
expect(latestRequest.requestBody).toEqual(
|
||||||
|
@ -234,7 +235,7 @@ describe('<JsonWatchEdit /> create route', () => {
|
||||||
|
|
||||||
const latestRequest = server.requests[server.requests.length - 1];
|
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: any, action) => {
|
||||||
actionAccum[action] = ACTION_MODE;
|
actionAccum[action] = ACTION_MODE;
|
||||||
return actionAccum;
|
return actionAccum;
|
||||||
|
@ -248,7 +249,7 @@ describe('<JsonWatchEdit /> create route', () => {
|
||||||
isNew: true,
|
isNew: true,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
actions: [],
|
actions: [],
|
||||||
watch: defaultWatchJson,
|
watch: defaultWatch,
|
||||||
};
|
};
|
||||||
|
|
||||||
const triggeredTime = `now+${TRIGGERED_TIME}s`;
|
const triggeredTime = `now+${TRIGGERED_TIME}s`;
|
||||||
|
|
|
@ -7,12 +7,13 @@
|
||||||
import { act } from 'react-dom/test-utils';
|
import { act } from 'react-dom/test-utils';
|
||||||
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
|
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
|
||||||
import axios from 'axios';
|
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 { setupEnvironment, pageHelpers, nextTick, wrapBodyResponse } from './helpers';
|
||||||
import { WatchEditTestBed } from './helpers/watch_edit.helpers';
|
import { WatchEditTestBed } from './helpers/watch_edit.helpers';
|
||||||
import { WATCH } from './helpers/jest_constants';
|
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 });
|
const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });
|
||||||
|
|
||||||
|
@ -69,7 +70,7 @@ describe('<WatchEdit />', () => {
|
||||||
expect(exists('jsonWatchForm')).toBe(true);
|
expect(exists('jsonWatchForm')).toBe(true);
|
||||||
expect(find('nameInput').props().value).toBe(watch.name);
|
expect(find('nameInput').props().value).toBe(watch.name);
|
||||||
expect(find('idInput').props().value).toBe(watch.id);
|
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
|
// ID should not be editable
|
||||||
expect(find('idInput').props().readOnly).toEqual(true);
|
expect(find('idInput').props().readOnly).toEqual(true);
|
||||||
|
@ -112,7 +113,7 @@ describe('<WatchEdit />', () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
watch: defaultWatchJson,
|
watch: defaultWatch,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue