Skip to content
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

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

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.',
},
},
},
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*/

export const Watch: any;
export const defaultWatch: any;
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
*/

export { Watch } from './watch';
export { defaultWatch } from './default_watch';
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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;
}
Expand Down Expand Up @@ -113,7 +114,7 @@ export class JsonWatch extends BaseWatch {
return new JsonWatch(upstreamWatch);
}

static defaultWatchJson = defaultWatchJson;
static defaultWatch = defaultWatch;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewers, I need to do a quick grep and see if this renaming will cause any problems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this isn't referenced anywhere in the codebase, so I removed it.

static typeName = i18n.translate('xpack.watcher.models.jsonWatch.typeName', {
defaultMessage: 'Advanced Watch',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -117,7 +118,7 @@ describe('<JsonWatchEdit /> create route', () => {
},
},
],
watch: defaultWatchJson,
watch: defaultWatch,
})
);
});
Expand Down Expand Up @@ -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;
Expand All @@ -186,7 +187,7 @@ describe('<JsonWatchEdit /> create route', () => {
isNew: true,
isActive: true,
actions: [],
watch: defaultWatchJson,
watch: defaultWatch,
};

expect(latestRequest.requestBody).toEqual(
Expand Down Expand Up @@ -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;
Expand All @@ -248,7 +249,7 @@ describe('<JsonWatchEdit /> create route', () => {
isNew: true,
isActive: true,
actions: [],
watch: defaultWatchJson,
watch: defaultWatch,
};

const triggeredTime = `now+${TRIGGERED_TIME}s`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -112,7 +113,7 @@ describe('<WatchEdit />', () => {
},
},
],
watch: defaultWatchJson,
watch: defaultWatch,
})
);
});
Expand Down