fix: preserve condition values when updating user settings#2203
Open
fix: preserve condition values when updating user settings#2203
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In the new Cypress test, consider relying more consistently on stable
data-cyselectors instead of structural selectors like.condition-panel,mat-select, andmat-option, which are brittle to DOM or component-library changes. - The
userSettings as anycast in the reducer makes it easy to miss shape changes like the newconditionsfield; introducing a typed interface foruserSettings(includingconditions) would make these updates safer and easier to maintain.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the new Cypress test, consider relying more consistently on stable `data-cy` selectors instead of structural selectors like `.condition-panel`, `mat-select`, and `mat-option`, which are brittle to DOM or component-library changes.
- The `userSettings as any` cast in the reducer makes it easy to miss shape changes like the new `conditions` field; introducing a typed interface for `userSettings` (including `conditions`) would make these updates safer and easier to maintain.
## Individual Comments
### Comment 1
<location> `cypress/e2e/datasets/datasets-general.cy.js:716-722` </location>
<code_context>
+
+ cy.get('[data-cy="edit-general-information"]').should("exist");
+
+ cy.go('back');
+
+ cy.get(".condition-panel")
+ .first()
+ .find("mat-panel-title")
+ .should("contain", ">")
+ .and("contain", "19");
+ });
+ })
</code_context>
<issue_to_address>
**suggestion (testing):** Selectors in the new test are fairly generic and may be brittle over time.
The assertions after `cy.go('back')` depend on generic selectors like `.condition-panel` and `mat-panel-title` plus content matches (`>` and `19`), which ties the test to presentation details and may break on minor layout/label changes. Where possible, prefer dedicated hooks (e.g. `data-cy` attributes) for the condition panels and operator/value fields so the test stays stable while still verifying the persisted condition state.
Suggested implementation:
```javascript
cy.go('back');
cy.get('[data-cy="condition-panel"]')
.first()
.within(() => {
cy.get('[data-cy="condition-operator"]').should("contain", ">");
cy.get('[data-cy="condition-value"]').should("contain", "19");
});
```
To make this test pass and keep it robust, you’ll need to:
1. Add `data-cy="condition-panel"` to the element that currently has the `.condition-panel` class in the UI template.
2. Add `data-cy="condition-operator"` to the element within the condition panel that displays the comparison operator (currently the part that ends up in `mat-panel-title`).
3. Add `data-cy="condition-value"` to the element within the condition panel that displays the value (`19` in this test).
4. If the operator/value are rendered differently (e.g., inside chips or separate spans), adjust the specific `data-cy` hooks accordingly, while keeping the Cypress selectors aligned with those hooks.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+716
to
+722
| cy.go('back'); | ||
|
|
||
| cy.get(".condition-panel") | ||
| .first() | ||
| .find("mat-panel-title") | ||
| .should("contain", ">") | ||
| .and("contain", "19"); |
Contributor
There was a problem hiding this comment.
suggestion (testing): Selectors in the new test are fairly generic and may be brittle over time.
The assertions after cy.go('back') depend on generic selectors like .condition-panel and mat-panel-title plus content matches (> and 19), which ties the test to presentation details and may break on minor layout/label changes. Where possible, prefer dedicated hooks (e.g. data-cy attributes) for the condition panels and operator/value fields so the test stays stable while still verifying the persisted condition state.
Suggested implementation:
cy.go('back');
cy.get('[data-cy="condition-panel"]')
.first()
.within(() => {
cy.get('[data-cy="condition-operator"]').should("contain", ">");
cy.get('[data-cy="condition-value"]').should("contain", "19");
});To make this test pass and keep it robust, you’ll need to:
- Add
data-cy="condition-panel"to the element that currently has the.condition-panelclass in the UI template. - Add
data-cy="condition-operator"to the element within the condition panel that displays the comparison operator (currently the part that ends up inmat-panel-title). - Add
data-cy="condition-value"to the element within the condition panel that displays the value (19in this test). - If the operator/value are rendered differently (e.g., inside chips or separate spans), adjust the specific
data-cyhooks accordingly, while keeping the Cypress selectors aligned with those hooks.
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
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 fixes an issue where condition values are lost when navigating away from and back to the dashboard without refreshing the page.
Motivation
Background on use case, changes needed
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
Preserve dataset filter conditions in user settings so condition values persist when navigating away and back to the datasets view.
Bug Fixes:
Tests: