-
-
Notifications
You must be signed in to change notification settings - Fork 217
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
Filename broadcast bug fix 2 #35108
Filename broadcast bug fix 2 #35108
Conversation
…rrect child entry to append filename to
for (let i = 0; i < allChildren.length; i++) { | ||
if (allChildren[i].control >= constants.CONTROL_IMAGE_CHOOSE) { | ||
allChildren[i].filename = element.answer(); | ||
var findChildAndSetFilename = function (children) { |
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.
lets use const
and let
where possible.
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.
looks good, couple comments
corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js
Outdated
Show resolved
Hide resolved
findChildAndSetFilename(child.children); | ||
} else if (child.control >= constants.CONTROL_IMAGE_CHOOSE) { | ||
child.filename = element.answer(); | ||
break; |
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.
nit: i think we can just return here?
corehq/apps/cloudcare/static/cloudcare/js/form_entry/form_ui.js
Outdated
Show resolved
Hide resolved
if (child.children && child.children.length > 0) { | ||
findChildAndSetFilename(child.children); | ||
} else if (inputControl.includes(child.control)) { | ||
child.filename = element.answer(); |
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.
I realize i'm not completely understanding this. Does element
represent a single question? It seems to me that this for loop will overwrite all filenames to be the same value - is that true?
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.
Yep as far as I can tell element does represent a single question. And thanks for bringing up the concern - I did some testing and found that there is a pretty convoluted edge case where if you have 2 input questions of the same type AND one them is broadcasting their filename to a text question AND they're all (2 input questions and a text question) contained in the same question tile AND the input question that's not broadcasting is placed before the the broadcasting question, then it'll assign the filename to the wrong input question. I tried a bunch of different variations of this format but this is strangely the only instance where it doesn't work as you'd expect.
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.
I'll see if there's something obvious I missed that can more assuredly pick out the right child to assign the filename to
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.
Just added a check that will only assign filename to input questions that match the broadcast style (or lack thereof) of the question you just answered. Testing locally seems to work fine (questions without any style at all don't need this - this is specifically for input questions within the same question tile block that needs updating frequently like when there's a conditionally visible question) but I'm going to ask QA to have another look at it.
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.
I see, there's still a part i'm confused on. Is this the appearance attribute this work is related to? So element
represents the text question and has an appearance attribute receive...
and if so, why would element.style.raw().includes('broadcast')
ever be true?
Is what you're doing checking that the topic
portion of the appearance attribute matches between element
and child
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.
Yep that's the broadcasting logic I'm dealing with. Element in this case is representing the input question and needs the filename to properly populate the text next to the upload button (this resolved the previous bug we had where having it broadcast to a hidden question in the same question tile would wipe the uploaded file the first time). I'm not sure what you mean by topic
but yea I'm comparing the style
attribute between element and child to make sure it targets the correct input question, if there are multiple. I guess in that regard I can just make sure they're completely equal instead of checking whether they both contain 'broadcast' or not but I feel like the latter method emphasizes that this is specifically to handle for certain edge cases associated with the filename broadcasting logic.
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.
hmm ok the only part i'm still not understanding is, if there are multiple input questions broadcasting (such that they each have a broadcast appearance attribute), would this conditional incorrectly match to all of them?
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.
theoretically I think so... but that would mean there would have to be two or more input questions broadcasting to one or more receiving text questions present in a single question tile (basically all in a row) which doesn't make sense to do in a form.
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.
Actually I'm not even sure you can have more than broadcasting/receiving pair in a question tile? In any case, I think the best fix for this (assigning filename based on question/child id) is a bit out of scope for this relatively small issue since it'll probably require additional formplayer changes too. How would you feel about keeping track of this as a backlog item to revisit in the future?
…tion based on broadcast styles or lack thereof
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.
looks good! Thank you for answering my questions
for (let child of children) { | ||
if (child.children && child.children.length > 0) { | ||
findChildAndSetFilename(child.children); | ||
} else if (inputControl.includes(child.control) && element.binding() === child.binding && |
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.
What is this binding property?
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.
not a 100% sure what it's used by but as far as I can tell its the "path" to the question. in the simplest instance it'll just be /data/<question_name>
but it'll always end with the question name
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.
interesting... in that case, is there a reason to check equality for both binding and ix? From what i remember, ix is the key used for knockout mapping to identify elements. Did you find that checking for just ix equality isn't strict enough?
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.
Yep, at least in the few sample forms I've set up with inputs in different broadcasting/question tile configurations I've found that it does sometimes get a little confused when just checking for ix
.
Product Description
Continuation of this PR that addressed the initial problem of filename not being propagated to hidden text questions within the same question tile.
Technical Summary
Jira Ticket
I hadn't realized the extent to which a single question can be buried under parent questions / nested under additional question tiles so all this adds is a recursion logic that searches for any questions of file type input (
control >= 10
) throughout the form question tree and sets the correct filename based on theix
andbinding
properties.Feature Flag
WEB_APPS_UPLOAD_QUESTIONS
Safety Assurance
Safety story
Tested on staging - QA will test again on prod. Does the same thing as before but checks children questions to ensure the right question gets the right filename.
QA Plan
QA will test again on prod. (previous QA ticket)
Rollback instructions
Labels & Review