-
Notifications
You must be signed in to change notification settings - Fork 149
GenericFilter: activating a configuration in onInit breaks subsequent configuration switching #5400 #5403
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
Merged
Merged
GenericFilter: activating a configuration in onInit breaks subsequent configuration switching #5400 #5403
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
f6cc263
GenericFilter, GroupFilter: capture the initial data loader condition…
fractal3000 a3ea99c
GenericFilter: tests for configuration activation in onInit jmix-fram…
fractal3000 c1a90b3
GenericFilter: adopt externally set data loader condition as baseline
fractal3000 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
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
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
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
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
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
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
104 changes: 104 additions & 0 deletions
104
.../test/groovy/component/genericfilter/GenericFilterBaseConditionAfterActivationTest.groovy
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * Copyright 2026 Haulmont. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package component.genericfilter | ||
|
|
||
| import component.genericfilter.view.GfBaseConditionAfterActivationView | ||
| import component.genericfilter.view.GfBaseConditionReviseView | ||
| import component.genericfilter.view.GfConfigsNoActivationView | ||
| import io.jmix.core.querycondition.Condition | ||
| import io.jmix.core.querycondition.LogicalCondition | ||
| import io.jmix.core.querycondition.PropertyCondition | ||
| import io.jmix.flowui.component.genericfilter.FilterUtils | ||
| import io.jmix.flowui.component.genericfilter.GenericFilter | ||
| import org.springframework.boot.test.context.SpringBootTest | ||
| import test_support.spec.FlowuiTestSpecification | ||
|
|
||
| /** | ||
| * A base condition set on the data loader after a configuration is activated in {@code onInit} | ||
| * must still be applied after switching configurations. | ||
| */ | ||
| @SpringBootTest | ||
| class GenericFilterBaseConditionAfterActivationTest extends FlowuiTestSpecification { | ||
|
|
||
| void setup() { | ||
| registerViewBasePackages("component.genericfilter.view") | ||
| } | ||
|
|
||
| def "base condition set after activation in onInit survives a configuration switch"() { | ||
| when: "the view opens: c1 activated in onInit, then a base condition on 'amount' set on the loader" | ||
| GenericFilter filter = navigateToView(GfBaseConditionAfterActivationView).genericFilter | ||
|
|
||
| and: "switching to c2" | ||
| filter.setCurrentConfiguration(filter.getConfiguration("c2")) | ||
|
|
||
| then: "the base condition (on 'amount') is still applied alongside c2" | ||
| hasPropertyConditionOn(filter.dataLoader.condition, "amount") | ||
| } | ||
|
|
||
| def "base condition revised after activation in onInit is the one preserved on switch"() { | ||
| when: "the view opens: base on 'amount', activate c1, then base revised to 'total' — all in onInit" | ||
| GenericFilter filter = navigateToView(GfBaseConditionReviseView).genericFilter | ||
|
|
||
| and: "switching to c2" | ||
| filter.setCurrentConfiguration(filter.getConfiguration("c2")) | ||
|
|
||
| then: "the revised base condition (on 'total') is applied, not the pre-activation one" | ||
| hasPropertyConditionOn(filter.dataLoader.condition, "total") | ||
| } | ||
|
|
||
| def "explicitly set initial condition is preserved when a configuration is later activated"() { | ||
| given: "the view opens with a configuration built but not activated (filter has not contributed yet)" | ||
| GenericFilter filter = navigateToView(GfConfigsNoActivationView).genericFilter | ||
|
|
||
| and: "the loader already holds some condition, and a DIFFERENT initial condition is set explicitly" | ||
| filter.dataLoader.setCondition(PropertyCondition.equal("number", "X")) | ||
| FilterUtils.updateDataLoaderInitialCondition(filter, PropertyCondition.greater("amount", 0)) | ||
|
|
||
| when: "a configuration is activated (the first filter contribution)" | ||
| filter.setCurrentConfiguration(filter.getConfiguration("c1")) | ||
|
|
||
| then: "the explicitly set initial condition (on 'amount') is used, not the loader's prior condition" | ||
| hasPropertyConditionOn(filter.dataLoader.condition, "amount") | ||
| } | ||
|
|
||
| def "a logical base condition is preserved and combined with the active configuration"() { | ||
| given: "the view opens with a configuration built but not activated" | ||
| GenericFilter filter = navigateToView(GfConfigsNoActivationView).genericFilter | ||
|
|
||
| and: "the loader has a logical base condition with two properties" | ||
| filter.dataLoader.setCondition(LogicalCondition.and( | ||
| PropertyCondition.greater("amount", 0), | ||
| PropertyCondition.greater("total", 0))) | ||
|
|
||
| when: "a configuration is activated" | ||
| filter.setCurrentConfiguration(filter.getConfiguration("c1")) | ||
|
|
||
| then: "both base conditions are still applied alongside the configuration" | ||
| hasPropertyConditionOn(filter.dataLoader.condition, "amount") | ||
| hasPropertyConditionOn(filter.dataLoader.condition, "total") | ||
| } | ||
|
|
||
| protected static boolean hasPropertyConditionOn(Condition condition, String property) { | ||
| if (condition instanceof PropertyCondition) { | ||
| return property == condition.property | ||
| } | ||
| if (condition instanceof LogicalCondition) { | ||
| return condition.conditions.any { hasPropertyConditionOn(it, property) } | ||
| } | ||
| return false | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Breaking changes is not documented. Was this approved?
The base loader condition must now be set before a configuration is activated. Previously the loader
inittask ran afteronInit, so this capturedmyBaseCondition:Now the first
updateDataLoaderCondition()snapshots the baseline without it, and it's lost on the next switch — a silent regression for anyone relying on the old timing.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.
Thanks, valid point. Removed the regression: the filter now adopts the loader's condition as its baseline if it was replaced externally (a different object, not the filter's own output). So setting the base condition after activating a configuration in onInit works again (and the same for a standalone GroupFilter), while configuration switching stays fixed. Covered by tests.
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.
Separately: we need to remember to add a clarification to the documentation. To change the base condition, set a new object via DataLoader.setCondition(). If instead, after the first updateDataLoaderCondition (for GenericFilter or GroupFilter), you obtain a reference to the Condition from DataLoader and modify it in place without changing the reference in DataLoader, the filter ignores it: the change is not picked up and is overwritten on the next condition rebuild (the exception being a direct DataLoader.load() before the rebuild, which reads the mutated object, but the filter does not preserve it). This behavior is not changed by this PR — it was the case before as well.