-
Notifications
You must be signed in to change notification settings - Fork 364
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
upcoming: [DI-22184] - Added Metric Criteria, Metric components #11392
base: develop
Are you sure you want to change the base?
upcoming: [DI-22184] - Added Metric Criteria, Metric components #11392
Conversation
…nit Tests and minor changes to align with changes in API spec
…nit tests, added a type for the Form, renamed prop
There are currently some discussions with respect to limiting the number of Metric Components and the way to limit them in UI. |
The typecheck manager test is failing as there is a state variable that's not used as it will be used in components that will be added later, but we are setting the state in this component |
Coverage Report: ✅ |
Cloud Manager UI test results🎉 467 passing tests on test run #2 ↗︎
|
metric: rule.metric!, | ||
operator: rule.operator!, |
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.
Is there a way to avoid this non-null assertion?
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 metric value is null in the first place just to handle clear option in the Autocomplete, and we have validation to make sure it's a required field and the submit won't happen successfully unless and until the field has the proper value . So the non-null assertion is almost never going to be checked.
We actually did the same thing for Severity.
const severity = formValues.severity!; |
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.
It's important to note this isn't a null check, it's just a null assertion which will assume the value is non-null even if it isn't. I prefer to avoid it if at all possible unless the team believes it's harmless. For example, we can use a default instead:
metric: rule.metric!, | |
operator: rule.operator!, | |
metric: rule.metric ?? '', | |
operator: rule.operator ?? 'eq', |
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.
I guess to fix this we'd have to update the form types to not allow things like metric
and operator
to be nullable. This might require us to make those fields not clearable to satisfy the types
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 fields not being clearable should be fine, but for components to be controlled we have initialized with null. I think the solution suggested by @hkhalil-akamai might be more suited for our use-case. I will try that change and if it's not affecting anything I'll make that change and push the changes.
|
||
const { control, watch } = useFormContext<CreateAlertDefinitionForm>(); | ||
|
||
const metricCriteriaWatcher = watch(name); |
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.
Please see #11357 (comment). watch
should be avoided if possible
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.
Okay, going ahead with useWatch()
React.useEffect(() => { | ||
const formMetricValues = new Set( | ||
metricCriteriaWatcher.map((item: MetricCriteriaForm) => item.metric) | ||
); | ||
|
||
const intervalList = | ||
metricDefinitions && | ||
metricDefinitions.data | ||
.filter((item) => formMetricValues.has(item.metric)) | ||
.map((item) => item.scrape_interval); | ||
const maxInterval = Math.max( | ||
...convertToSeconds(intervalList ? intervalList : []) | ||
); | ||
setMaxInterval(maxInterval); | ||
}, [setMaxInterval, metricCriteriaWatcher, metricDefinitions]); |
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.
Let's try to remove this useEffect
. We're really trying to not use useEffect in our codebase anymore 😖. Usually this can be accomplished by moving this logic into an onChange rather than doing it here as a side-effect of something changing.
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.
Any particular reason why we are avoiding useEffect ? Because while implementing I saw multiple components using it, so implemented
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.
We've had a handful of bugs caused by useEffect
. The official react docs also advocate to not use useEffect
: https://react.dev/learn/you-might-not-need-an-effect
Description 📝
Changes 🔄
Target release date 🗓️
Please specify a release date (and environment, if applicable) to guarantee timely review of this PR. If exact date is not known, please approximate and update it as needed.
Preview 📷
How to test 🧪
Prerequisites
(How to setup test environment)
Verification steps
Author Checklists
As an Author, to speed up the review process, I considered 🤔
👀 Doing a self review
❔ Our contribution guidelines
🤏 Splitting feature into small PRs
➕ Adding a changeset
🧪 Providing/improving test coverage
🔐 Removing all sensitive information from the code and PR description
🚩 Using a feature flag to protect the release
👣 Providing comprehensive reproduction steps
📑 Providing or updating our documentation
🕛 Scheduling a pair reviewing session
📱 Providing mobile support
♿ Providing accessibility support
As an Author, before moving this PR from Draft to Open, I confirmed ✅