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

Change areItemsTheSame to check if internal objects are the same with === #1185

Merged
merged 14 commits into from
Feb 24, 2022

Conversation

joiskash
Copy link
Collaborator

@joiskash joiskash commented Feb 21, 2022

IMPORTANT: All PRs must be linked to an issue (except for extremely trivial and straightforward changes).

Fixes #765

Description
If you have a questionnaire with multiple levels of nesting, questionnaire response items are nested within answers. When the parent answer is changed, we clear the questionnaireResponseItem.answer list and add the new answer to it. The nested questionnaireResponseItems also get cleared and new instances of them are created in the questionnaireResponseItemChangedCallback. Since questionnaireItemViewItem.questionnaireResponseItem was a value , the ViewHolderFactory would always hold the reference to the old nested questionnaireResponseItem. On making it a variable, the viewHolderFactory now gets the reference of the correct questionnaireResponseitem while setting the answer. This allows enable when to work properly and thus displays the third nested answer too.

Alternative(s) considered
No

Type
Choose one: Bug fix

Screenshots (if applicable)

Checklist

  • I have read and acknowledged the Code of conduct
  • I have read the Contributing page
  • I have signed the Google Individual CLA, or I am covered by my company's Corporate CLA
  • I have discussed my proposed solution with code owners in the linked issue(s) and we have agreed upon the general approach
  • I have run ./gradlew spotlessApply and ./gradlew spotlessCheck to check my code follows the style guide of this project
  • I have run ./gradlew check and ./gradlew connectedCheck to test my changes locally
  • I have built and run the reference app(s) to verify my change fixes the issue and/or does not break the reference app(s)

@codecov
Copy link

codecov bot commented Feb 21, 2022

Codecov Report

Merging #1185 (23782b0) into master (e6bb4c4) will increase coverage by 0.00%.
The diff coverage is 62.50%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #1185   +/-   ##
=========================================
  Coverage     84.57%   84.57%           
- Complexity      627      632    +5     
=========================================
  Files           135      135           
  Lines         10404    10407    +3     
  Branches        786      787    +1     
=========================================
+ Hits           8799     8802    +3     
+ Misses         1210     1209    -1     
- Partials        395      396    +1     
Impacted Files Coverage Δ
...QuestionnaireItemBarCodeReaderViewHolderFactory.kt 36.73% <0.00%> (ø)
...iews/QuestionnaireItemDropDownViewHolderFactory.kt 50.00% <ø> (+1.35%) ⬆️
...hir/datacapture/views/QuestionnaireItemViewItem.kt 88.23% <60.00%> (-4.87%) ⬇️
...droid/fhir/datacapture/QuestionnaireItemAdapter.kt 61.11% <100.00%> (+0.83%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e6bb4c4...23782b0. Read the comment docs.

@jingtang10
Copy link
Collaborator

Thanks Kashyap for fixing this. First thought is that we should write some tests to cover this case. Upon second thought I'm not entirely sure why this would be the fix anyway - it seems like if val vs var can fix this issue there's probably an underlying problem which is the items are not being replaced/deleted/cached correctly.

@joiskash
Copy link
Collaborator Author

Thanks Kashyap for fixing this. First thought is that we should write some tests to cover this case. Upon second thought I'm not entirely sure why this would be the fix anyway - it seems like if val vs var can fix this issue there's probably an underlying problem which is the items are not being replaced/deleted/cached correctly.

Sure , ill write a UT first.

@joiskash joiskash changed the title Change questionnaireResponseItem to var from val in questionnaireItemViewItem Change areItemsTheSame to check if internal objects are the same with === Feb 22, 2022
* perform a Diff before updating the view. While checking if two [QuestionnaireItemViewItem]s are
* equal or not, we need to check if they are referencing the same objects.
*/
override fun equals(other: Any?): Boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

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

return early if other isn't also a questionnaire item view item?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

return this.questionnaireItem === (other as QuestionnaireItemViewItem).questionnaireItem &&
this.questionnaireResponseItem ===
(other as QuestionnaireItemViewItem).questionnaireResponseItem
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

add another function equalsDeep to handle the areContentsTheSame functino of the DiffCallback.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator

@jingtang10 jingtang10 left a comment

Choose a reason for hiding this comment

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

Thanks @joiskash again for debugging fixing this very thorny issue!

Just a few nits! Please feel free to merge once these are addressed.

* [QuestionnaireResponseItem] match.
*/
override fun equals(other: Any?): Boolean {
return if (other is QuestionnaireItemViewItem) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

turn this if condition around and return early.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

* On the other hand, under certain circumstances, the underlying [QuestionnaireResponseItem]
* might be recreated for the same question. For example, if a [QuestionnaireItem] is nested under
* another [QuestionnaireItem], the [QuestionnaireResponseItem](s) will be nested under the parent
* [QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent]. and if the
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* [QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent]. and if the
* [QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent], and if the

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Comment on lines 139 to 143
* Comparing the contents of two [QuestionnaireItemViewItem]s,involves traversing the underlying
* [Questionnaire.QuestionnaireItemComponent] and
* [QuestionnaireResponse.QuestionnaireResponseItemComponent],and comparing values of all the
* properties. This is done by using the [Questionnaire.QuestionnaireItemComponent.equalsDeep] and
* [QuestionnaireResponse.QuestionnaireResponseItemComponent.equalsDeep] functions
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* Comparing the contents of two [QuestionnaireItemViewItem]s,involves traversing the underlying
* [Questionnaire.QuestionnaireItemComponent] and
* [QuestionnaireResponse.QuestionnaireResponseItemComponent],and comparing values of all the
* properties. This is done by using the [Questionnaire.QuestionnaireItemComponent.equalsDeep] and
* [QuestionnaireResponse.QuestionnaireResponseItemComponent.equalsDeep] functions
* Comparing the contents of two [QuestionnaireItemViewItem]s by traversing the underlying
* [Questionnaire.QuestionnaireItemComponent] and
* [QuestionnaireResponse.QuestionnaireResponseItemComponent] and comparing values of all the
* properties. This is done by using [Questionnaire.QuestionnaireItemComponent.equalsDeep] and
* [QuestionnaireResponse.QuestionnaireResponseItemComponent.equalsDeep].

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@joiskash joiskash enabled auto-merge (squash) February 24, 2022 08:06
@joiskash joiskash merged commit f31f5b7 into master Feb 24, 2022
@joiskash joiskash deleted the kj/fix-single-option-drop-down branch February 24, 2022 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
2 participants