korbit-ai[bot] commented on code in PR #34892:
URL: https://github.com/apache/superset/pull/34892#discussion_r2308338146
##########
superset-frontend/src/explore/components/controls/AnnotationLayerControl/index.tsx:
##########
@@ -107,17 +107,25 @@ class AnnotationLayerControl extends PureComponent<Props,
PopoverState> {
AnnotationLayer.preload();
}
- UNSAFE_componentWillReceiveProps(nextProps: Props) {
- const { name, annotationError, validationErrors, value } = nextProps;
- if (Object.keys(annotationError).length && !validationErrors.length) {
- this.props.actions.setControlValue(
- name,
- value,
- Object.keys(annotationError),
- );
- }
- if (!Object.keys(annotationError).length && validationErrors.length) {
- this.props.actions.setControlValue(name, value, []);
+ componentDidUpdate(prevProps: Props) {
+ const { name, annotationError, validationErrors, value } = this.props;
+ if (
+ (Object.keys(annotationError).length && !validationErrors.length) ||
+ (!Object.keys(annotationError).length && validationErrors.length)
+ ) {
+ if (
+ annotationError !== prevProps.annotationError ||
+ validationErrors !== prevProps.validationErrors ||
+ value !== prevProps.value
+ ) {
Review Comment:
### Redundant Object.keys() Computation <sub></sub>
<details>
<summary>Tell me more</summary>
###### What is the issue?
Multiple redundant Object.keys() calculations within nested conditional
blocks
###### Why this matters
Repeatedly calling Object.keys() increases computational overhead,
especially when the result is used multiple times in the same function scope
###### Suggested change ∙ *Feature Preview*
Store the Object.keys() result in a variable before the conditional checks:
```typescript
const annotationErrorKeys = Object.keys(annotationError);
if (
(annotationErrorKeys.length && !validationErrors.length) ||
(!annotationErrorKeys.length && validationErrors.length)
) {
if (
annotationError !== prevProps.annotationError ||
validationErrors !== prevProps.validationErrors ||
value !== prevProps.value
) {
this.props.actions.setControlValue(
name,
value,
annotationErrorKeys.length ? annotationErrorKeys : []
);
}
}
```
###### Provide feedback to improve future suggestions
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c/upvote)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c?what_not_true=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c?what_out_of_scope=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c?what_not_in_standard=true)
[](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/d050d70b-c90b-4499-ac1a-0ff1fd01ce5c)
</details>
<sub>
💬 Looking for more details? Reply to this comment to chat with Korbit.
</sub>
<!--- korbi internal id:e76a45b6-46d0-4c81-afd3-f67f85455f22 -->
[](e76a45b6-46d0-4c81-afd3-f67f85455f22)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]