-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[AO] Allow providing custom time range for Alert Summary Widget #147253
Merged
maryam-saeidi
merged 15 commits into
elastic:main
from
maryam-saeidi:139489-time-range-filter
Dec 14, 2022
Merged
Changes from 12 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
371244d
Allow time range filter to be provided by consumer for Alert Summary …
maryam-saeidi 6f43c5e
Add missing copyright
maryam-saeidi 28f806f
Merge branch 'main' into 139489-time-range-filter
maryam-saeidi f449e4a
Merge branch 'main' into 139489-time-range-filter
maryam-saeidi 8fea2d6
Change message id
maryam-saeidi 07d0e4d
Fix useLoadRuleAlertsAggs test
maryam-saeidi cf4cecc
Fix import
maryam-saeidi 4c73260
Merge branch 'main' into 139489-time-range-filter
maryam-saeidi 09c3d54
Update deps
maryam-saeidi 534964b
Merge branch 'main' into 139489-time-range-filter
maryam-saeidi 724874d
Update data-test-subj style
maryam-saeidi a0187c4
Remove unused translations
maryam-saeidi a2afba9
Merge branch 'main' into 139489-time-range-filter
maryam-saeidi 6cf3bcc
Merge branch 'main' into 139489-time-range-filter
maryam-saeidi a226309
Merge branch 'main' into 139489-time-range-filter
maryam-saeidi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...ins/observability/public/pages/rule_details/helpers/get_alert_summary_time_range.test.tsx
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,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import moment from 'moment'; | ||
import { getDefaultAlertSummaryTimeRange } from '.'; | ||
|
||
describe('getDefaultAlertSummaryTimeRange', () => { | ||
it('should return default time in UTC format', () => { | ||
const defaultTimeRange = getDefaultAlertSummaryTimeRange(); | ||
const utcFormat = 'YYYY-MM-DDTHH:mm:ss.SSSZ'; | ||
|
||
expect(moment(defaultTimeRange.utcFrom, utcFormat, true).isValid()).toBeTruthy(); | ||
expect(moment(defaultTimeRange.utcTo, utcFormat, true).isValid()).toBeTruthy(); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
.../plugins/observability/public/pages/rule_details/helpers/get_alert_summary_time_range.tsx
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,28 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { getAbsoluteTimeRange } from '@kbn/data-plugin/common'; | ||
import { FormattedMessage } from '@kbn/i18n-react'; | ||
|
||
export const getDefaultAlertSummaryTimeRange = () => { | ||
const { to, from } = getAbsoluteTimeRange({ | ||
from: 'now-30d', | ||
to: 'now', | ||
}); | ||
|
||
return { | ||
utcFrom: from, | ||
utcTo: to, | ||
title: ( | ||
<FormattedMessage | ||
id="xpack.observability.alertsSummaryWidget.last30days" | ||
defaultMessage="Last 30 days" | ||
/> | ||
), | ||
}; | ||
}; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/observability/public/pages/rule_details/helpers/index.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,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export { getDefaultAlertSummaryTimeRange } from './get_alert_summary_time_range'; |
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
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to use a state for this? Can it be just a variable in this scope, or a constant in the module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason for having this state is to run
getAbsoluteTimeRange
only once during the rendering of this component.getAbsoluteTimeRange
will return the absolute time for the last 30 days at the time of the execution and I didn't want this value to be created more than once in this component but I also didn't want to have it created when the module is loaded so I used the state in this case.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit - I also saw that people use
useRef
to do that to avoid the stateThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case, I'll keep it in the state to be able to refresh it in case we want to.