-
Notifications
You must be signed in to change notification settings - Fork 33
fix: nan issue when typing incomplete scientific notation #2016
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
Open
abdimo101
wants to merge
2
commits into
master
Choose a base branch
from
fix-condition-value-input-nan
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+86
−19
Conversation
This file contains hidden or 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
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.
Hey there - I've reviewed your changes - here's some feedback:
- Consider extracting the updatedConditions mapping logic into a dedicated helper function to improve readability and testability.
- Ensure tempConditionValues is initialized or reset whenever conditionConfigs changes to avoid stale or misaligned buffered inputs.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the updatedConditions mapping logic into a dedicated helper function to improve readability and testability.
- Ensure tempConditionValues is initialized or reset whenever conditionConfigs changes to avoid stale or misaligned buffered inputs.
## Individual Comments
### Comment 1
<location> `src/app/datasets/datasets-filter/datasets-filter.component.ts:248-249` </location>
<code_context>
+ condition: {
+ ...config.condition,
+ rhs: isNumeric ? Number(value) : value,
+ relation: isNumeric
+ ? ("EQUAL_TO_NUMERIC" as ScientificCondition["relation"])
+ : ("EQUAL_TO_STRING" as ScientificCondition["relation"]),
+ },
</code_context>
<issue_to_address>
**nitpick:** Type assertion for relation may be unnecessary if type inference is sufficient.
Remove the type assertion if the assignment is already type-safe and the type checker does not require it.
</issue_to_address>
### Comment 2
<location> `src/app/datasets/datasets-filter/datasets-filter.component.ts:271-272` </location>
<code_context>
+ return config;
+ });
+
+ updatedConditions.forEach((oldCondition) => {
this.store.dispatch(
removeScientificConditionAction({
</code_context>
<issue_to_address>
**suggestion:** Variable naming: 'oldCondition' is misleading after mapping to updatedConditions.
Please rename 'oldCondition' to 'condition' or 'updatedCondition' to better reflect its current meaning.
```suggestion
updatedConditions.forEach((condition) => {
this.store.dispatch(
removeScientificConditionAction({
condition: condition.condition,
);
});
```
</issue_to_address>
### Comment 3
<location> `src/app/datasets/datasets-filter/datasets-filter.component.ts:234` </location>
<code_context>
this.conditionConfigs$.pipe(take(1)).subscribe((conditionConfigs) => {
- (conditionConfigs || []).forEach((oldCondition) => {
+ const updatedConditions = (conditionConfigs || []).map((config, i) => {
+ if (this.tempConditionValues[i] !== undefined) {
+ const value = this.tempConditionValues[i];
</code_context>
<issue_to_address>
**issue (complexity):** Consider extracting the condition transformation logic into a helper function to improve readability and testability.
Here’s one way to collapse that nested‐branching and spread logic into a single helper, then use it inside your subscription. This keeps exactly the same behavior but is much easier to read and test.
```ts
// add somewhere in your component (or in a util file)
private transformConfigWithTempValue(
config: ConditionConfig,
tempVal?: string
): ConditionConfig {
if (tempVal === undefined) {
return config;
}
const isNumeric = tempVal !== '' && !isNaN(Number(tempVal));
const newCondition: ScientificCondition = {
...config.condition,
rhs: isNumeric ? Number(tempVal) : tempVal,
// if it was previously EQUAL_TO(_NUMERIC|_STRING), we overwrite;
// otherwise we just keep the old relation
relation: isNumeric
? 'EQUAL_TO_NUMERIC'
: 'EQUAL_TO_STRING',
};
return { ...config, condition: newCondition };
}
```
Then in your subscription:
```ts
this.conditionConfigs$.pipe(take(1)).subscribe((conditionConfigs) => {
const updatedConditions = (conditionConfigs || []).map((cfg, idx) =>
this.transformConfigWithTempValue(cfg, this.tempConditionValues[idx])
);
// remove old, add new, update settings, fetch…
updatedConditions.forEach(c =>
this.store.dispatch(removeScientificConditionAction({ condition: c.condition }))
);
updatedConditions.forEach(c => {
if (c.enabled && c.condition.lhs && c.condition.rhs) {
this.store.dispatch(addScientificConditionAction({ condition: c.condition }));
}
});
this.store.dispatch(updateUserSettingsAction({
property: { conditions: updatedConditions },
}));
this.store.dispatch(fetchDatasetsAction());
this.store.dispatch(fetchFacetCountsAction());
});
```
• Extracting the mapping makes the transformation logic reusable and removes all the nested `if/else` and重复 spread blocks.
• You can now unit‐test `transformConfigWithTempValue` in isolation without wiring up the whole RxJS pipeline.
</issue_to_address>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
cd8a400
to
f732cfd
Compare
Can you add a test for the fix? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
This PR refactors the handling of condition values in datasets filter component.
Motivation
Previously the condition values was updated in the global state immediately as the user typed, causing issues when entering partial scientific notation (e.g typing "3e" would result in the value being set to NaN).
Fixes:
Please provide a list of the fixes implemented in this PR
Changes:
Please provide a list of the changes implemented by this PR
Tests included
Documentation
official documentation info
If you have updated the official documentation, please provide PR # and URL of the pages where the updates are included
Backend version
Summary by Sourcery
Refactor the datasets filter component to buffer raw input values and defer updating the global state until filter application, fixing NaN errors when entering incomplete scientific notation
Bug Fixes:
Enhancements: