Skip to content
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

Get additional children #663

Merged
merged 5 commits into from
Mar 31, 2022
Merged

Conversation

lognaturel
Copy link
Member

Adds access to additional children from an itemset item in support of getodk/collect#4948

What has been done to verify that this works as intended?

Tests!

Why is this the best possible solution? Were any other approaches considered?

Comments inline for a few alternatives I considered.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Additive change.

I did put all the copyNode stuff on a deprecation path. It's not documented. If ever we have a use case for it we can bring it back with tests.

Do we need any specific form for testing your changes? If so, please attach one.

See tests.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

Not user-facing so no.

Clearly the design here isn't great. This class represents choices differently for all of the combinations of static vs dynamic and localizable vs not localizable.
assertThat(children, hasEntry("special-property", "AA"));

scenario.answer("/data/repeat[0]/special-property", "changed");
children = scenario.choicesOf("/data/select").get(0).getAdditionalChildren();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't really thought about this previously -- because getChild and getAdditionalChildren use the display text of the children, they're not dynamic. That is, you have to call getChild and getAdditionalChildren again after the form changes to get new values. I think that's ok -- I can't think of a usage where we'd hold on to one of these while other parts of the form are changing but I still wanted to flag it.

The alternative would be to keep a reference to an AnswerData object instead. That would reflect changes to the model.

@lognaturel
Copy link
Member Author

@seadowg May this be of value to you. 🤞🤞😬😬

if (child != null) {
return child.getValue().getDisplayText();
}
if (item == null) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I find hard about JR is that it can be unclear what's a deliberate precondition vs a case that wasn't explicitly considered vs ...? I think this precondition is now much clearer even though it's equivalent to the terser code it replaces. (As I mentioned, this thinking about preconditions is what had nudged me in the direction of runtime exceptions.)

@lognaturel
Copy link
Member Author

Thanks for all the good discussion! I think the two things left are

@@ -38,6 +38,8 @@ dependencies {
// Upgrade to version higher than 1.4 when Collect minSDK >= 26
implementation 'org.apache.commons:commons-csv:1.4'

implementation 'org.jetbrains.kotlin:kotlin-stdlib:1.6.10'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It begins...

@lognaturel lognaturel merged commit 55107e7 into getodk:master Mar 31, 2022
@lognaturel lognaturel deleted the getAddtlChildren branch March 31, 2022 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants