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

Expose item child nodes in SelectChoice #660

Merged
merged 3 commits into from
Mar 24, 2022

Conversation

lognaturel
Copy link
Member

Provides direct access to item children from a SelectChoice.

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

Tests.

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

It's the best I could come up with. It makes the most sense to me that the SelectChoice itself would provide direct access to children of the item node that the choice is based on. Once reaching that conclusion there aren't a whole lot of options.

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?

This should be additive and have no effect on users. I don't think there's a regression risk but I think that it might be an incomplete solution. Technically an item could have a complex structure (nested nodes). I've never seen it but an XML or geojson document could have it. This doesn't give access to that more complex structure. The only use for it we have right now is to access the well-known geometry child so I think it's ok.

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

Tests.

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

No.

: formDef.getMainInstance().resolveReference(item));

choice.setIndex(i);

if (copyMode) {
Copy link
Member Author

Choose a reason for hiding this comment

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

This copyMode stuff isn't tested or documented. I think we should remove all of it in the near-ish future. For now I wanted to at least group it together so it's out of the way.

/**
* The node that this choice represents. Not serialized.
*/
private TreeElement item;
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 briefly considered trying to use copyNode for this. But like I said in another comment, I think we should remove all that stuff instead.

@@ -75,6 +81,16 @@ public String getValue() {
return value;
}

public String getChild(String childName) {
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 also considered getProperty. I went with getChild because it best matches the underlying tree representation. Property makes the most sense for geojson and column makes the most sense for CSV.

}

@Test
public void getChild_updates_whenChoicesAreFromRepeat() throws IOException {
Copy link
Member Author

Choose a reason for hiding this comment

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

Dude. You could, like, have a repeat that has a field called geometry. And then build a select with a map appearance on top of that. I don't know why exactly but that makes my brain explode a little bit. 🤯

I almost only populated the item field in the case of an external secondary instance because this kind of very dynamic situation scared me. But I can't actually think of a case where it wouldn't work.

@lognaturel lognaturel requested a review from seadowg March 23, 2022 00:38
@lognaturel lognaturel changed the title Expose siblings of select label and value Expose item child nodes in SelectChoice Mar 23, 2022
@lognaturel lognaturel marked this pull request as ready for review March 23, 2022 16:31
@lognaturel lognaturel merged commit 4b9abf0 into getodk:master Mar 24, 2022
@lognaturel lognaturel deleted the select-children branch March 24, 2022 18:55
@lognaturel
Copy link
Member Author

@seadowg hasn't done a final review yet but we're going to merge and make a snapshot so it's easier to integrate in ongoing Collect work (getodk/collect#4949). He'll then come back and file issues for anything that still needs to be addressed.

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