forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add request flyouts to JSON watch form and Threshold Watch edit form. (…
…elastic#43232) * Refactor watch serialization logic into common serialization functions. - Refactor build helpers to accept specific arguments instead of the entire watch object, to make dependencies more obvious. - Move action models into common directory. * Remove boom error reporting from action models because this is an unnecessary level of defensiveness since we control the UI that consumes this API. * Convert tests from Mocha to Jest. - Remove mocks and fix assertions that depended upon mocked dependencies. These assertions were low-value because they tested implementation details. - Remove other assertions based upon implementation details. * Remove serializeMonitoringWatch logic, since Monitoring doesn't use the create endpoint.
- Loading branch information
Showing
48 changed files
with
1,486 additions
and
1,434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
x-pack/legacy/plugins/watcher/common/lib/serialization/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* 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 declare function serializeJsonWatch(name: string, json: any): any; | ||
export declare function serializeThresholdWatch(config: any): any; | ||
export declare function buildInput(config: any): any; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...k/legacy/plugins/watcher/common/lib/serialization/serialization_helpers/build_metadata.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/* | ||
watch.metadata | ||
*/ | ||
|
||
export function buildMetadata({ | ||
index, | ||
timeField, | ||
triggerIntervalSize, | ||
triggerIntervalUnit, | ||
aggType, | ||
aggField, | ||
termSize, | ||
termField, | ||
thresholdComparator, | ||
timeWindowSize, | ||
timeWindowUnit, | ||
threshold, | ||
}) { | ||
return { | ||
watcherui: { | ||
index, | ||
time_field: timeField, | ||
trigger_interval_size: triggerIntervalSize, | ||
trigger_interval_unit: triggerIntervalUnit, | ||
agg_type: aggType, | ||
agg_field: aggField, | ||
term_size: termSize, | ||
term_field: termField, | ||
threshold_comparator: thresholdComparator, | ||
time_window_size: timeWindowSize, | ||
time_window_unit: timeWindowUnit, | ||
threshold, | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
x-pack/legacy/plugins/watcher/common/lib/serialization/serialization_helpers/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* 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 { buildActions } from './build_actions'; | ||
export { buildCondition } from './build_condition'; | ||
export { buildInput } from './build_input'; | ||
export { buildMetadata } from './build_metadata'; | ||
export { buildTransform } from './build_transform'; | ||
export { buildTrigger } from './build_trigger'; |
File renamed without changes.
25 changes: 25 additions & 0 deletions
25
x-pack/legacy/plugins/watcher/common/lib/serialization/serialize_json_watch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { set } from 'lodash'; | ||
import { WATCH_TYPES } from '../../constants'; | ||
|
||
export function serializeJsonWatch(name, json) { | ||
// We don't want to overwrite any metadata provided by the consumer. | ||
const { metadata = {} } = json; | ||
set(metadata, 'xpack.type', WATCH_TYPES.JSON); | ||
|
||
const serializedWatch = { | ||
...json, | ||
metadata, | ||
}; | ||
|
||
if (name) { | ||
serializedWatch.metadata.name = name; | ||
} | ||
|
||
return serializedWatch; | ||
} |
43 changes: 43 additions & 0 deletions
43
x-pack/legacy/plugins/watcher/common/lib/serialization/serialize_json_watch.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
import { serializeJsonWatch } from './serialize_json_watch'; | ||
|
||
describe('serializeJsonWatch', () => { | ||
it('serializes with name', () => { | ||
expect(serializeJsonWatch('test', { foo: 'bar' })).toEqual({ | ||
foo: 'bar', | ||
metadata: { | ||
name: 'test', | ||
xpack: { | ||
type: 'json', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('serializes without name', () => { | ||
expect(serializeJsonWatch(undefined, { foo: 'bar' })).toEqual({ | ||
foo: 'bar', | ||
metadata: { | ||
xpack: { | ||
type: 'json', | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('respects provided metadata', () => { | ||
expect(serializeJsonWatch(undefined, { metadata: { foo: 'bar' } })).toEqual({ | ||
metadata: { | ||
foo: 'bar', | ||
xpack: { | ||
type: 'json', | ||
}, | ||
}, | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.