-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This PR adds an Alerts Details page, linked from the Alerts List. It includes: Header containing details about the Alert. Quick Enable / Mute buttons for the Alert Disabled buttons to the _Edit Alert+ flyout (waiting on #51545), View in App (waiting on #56298) and Activity Log (waiting on #51548)
- Loading branch information
Showing
36 changed files
with
2,527 additions
and
165 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
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
77 changes: 77 additions & 0 deletions
77
...gacy/plugins/triggers_actions_ui/np_ready/public/application/lib/value_validators.test.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,77 @@ | ||
/* | ||
* 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 { throwIfAbsent, throwIfIsntContained } from './value_validators'; | ||
import uuid from 'uuid'; | ||
|
||
describe('throwIfAbsent', () => { | ||
test('throws if value is absent', () => { | ||
[undefined, null].forEach(val => { | ||
expect(() => { | ||
throwIfAbsent('OMG no value')(val); | ||
}).toThrowErrorMatchingInlineSnapshot(`"OMG no value"`); | ||
}); | ||
}); | ||
|
||
test('doesnt throws if value is present but falsey', () => { | ||
[false, ''].forEach(val => { | ||
expect(throwIfAbsent('OMG no value')(val)).toEqual(val); | ||
}); | ||
}); | ||
|
||
test('doesnt throw if value is present', () => { | ||
expect(throwIfAbsent('OMG no value')({})).toEqual({}); | ||
}); | ||
}); | ||
|
||
describe('throwIfIsntContained', () => { | ||
test('throws if value is absent', () => { | ||
expect(() => { | ||
throwIfIsntContained<string>(new Set([uuid.v4()]), 'OMG no value', val => val)([uuid.v4()]); | ||
}).toThrowErrorMatchingInlineSnapshot(`"OMG no value"`); | ||
}); | ||
|
||
test('throws if value is absent using custom message', () => { | ||
const id = uuid.v4(); | ||
expect(() => { | ||
throwIfIsntContained<string>( | ||
new Set([id]), | ||
(value: string) => `OMG no ${value}`, | ||
val => val | ||
)([uuid.v4()]); | ||
}).toThrow(`OMG no ${id}`); | ||
}); | ||
|
||
test('returns values if value is present', () => { | ||
const id = uuid.v4(); | ||
const values = [uuid.v4(), uuid.v4(), id, uuid.v4()]; | ||
expect(throwIfIsntContained<string>(new Set([id]), 'OMG no value', val => val)(values)).toEqual( | ||
values | ||
); | ||
}); | ||
|
||
test('returns values if multiple values is present', () => { | ||
const [firstId, secondId] = [uuid.v4(), uuid.v4()]; | ||
const values = [uuid.v4(), uuid.v4(), secondId, uuid.v4(), firstId]; | ||
expect( | ||
throwIfIsntContained<string>(new Set([firstId, secondId]), 'OMG no value', val => val)(values) | ||
).toEqual(values); | ||
}); | ||
|
||
test('allows a custom value extractor', () => { | ||
const [firstId, secondId] = [uuid.v4(), uuid.v4()]; | ||
const values = [ | ||
{ id: firstId, some: 'prop' }, | ||
{ id: secondId, someOther: 'prop' }, | ||
]; | ||
expect( | ||
throwIfIsntContained<{ id: string }>( | ||
new Set([firstId, secondId]), | ||
'OMG no value', | ||
(val: { id: string }) => val.id | ||
)(values) | ||
).toEqual(values); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
...ck/legacy/plugins/triggers_actions_ui/np_ready/public/application/lib/value_validators.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,33 @@ | ||
/* | ||
* 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 { constant } from 'lodash'; | ||
|
||
export function throwIfAbsent<T>(message: string) { | ||
return (value: T | undefined): T => { | ||
if (value === undefined || value === null) { | ||
throw new Error(message); | ||
} | ||
return value; | ||
}; | ||
} | ||
|
||
export function throwIfIsntContained<T>( | ||
requiredValues: Set<string>, | ||
message: string | ((requiredValue: string) => string), | ||
valueExtractor: (value: T) => string | ||
) { | ||
const toError = typeof message === 'function' ? message : constant(message); | ||
return (values: T[]) => { | ||
const availableValues = new Set(values.map(valueExtractor)); | ||
for (const value of requiredValues.values()) { | ||
if (!availableValues.has(value)) { | ||
throw new Error(toError(value)); | ||
} | ||
} | ||
return values; | ||
}; | ||
} |
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
Oops, something went wrong.