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

Add Reference class to display string function #1740

Merged
merged 13 commits into from
Jan 3, 2023
Merged

Add Reference class to display string function #1740

merged 13 commits into from
Jan 3, 2023

Conversation

omarismail94
Copy link
Contributor

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

Fixes #1735

Description
Add Reference type and obtain the field to display the string of on the UI.

Follow-up question: are there other class types we could be missing here other than Reference?

Alternative(s) considered
N/A

Type
Choose one: (Bug fix | Feature | Documentation | Testing | Code health | Builds | Releases | Other)

Screenshots (if applicable)

device-2022-11-30-223358.mp4

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 demo app(s) to verify my change fixes the issue and/or does not break the demo app(s).

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 @omarismail94!

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 @omarismail94!

@jingtang10 jingtang10 assigned omarismail94 and unassigned jingtang10 Dec 1, 2022
@omarismail94
Copy link
Contributor Author

@jingtang10 PTAL. I resolved your comment and also moved where the displayString function is called to MoreAnswerOptions to be in the same location where displayString value is called for QuestionnaireItemAnswerOptionComponent.

I wanted to come up with one function to combine both like this:

internal val Questionnaire.QuestionnaireItemAnswerOptionComponent.displayString: String
  get() = displayString(null, value)

internal fun QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent.displayString(
  context: Context
) = displayString(context, value)


private fun displayString(context: Context?, value: Type?) : String =
  return when(value) {
   //logic
  }
    

however, the logic becomes divergent. An example: in QuestionnaireItemAnswerOptionComponent, if the value is DateType, we just return value.primitiveValue(); so if we pass 2022-01-01 it will return 2022-01-01.

For DateTypes in QuestionnaireResponseItemAnswerComponent, we return value.localDate?.localizedString; so if we pass 2022-01-01, it will return 01/01/22.

Do we want to make what is displayed consistent, or is there a reason there is a difference between how QuestionnaireItemAnswerOptionComponents and QuestionnaireResponseItemAnswerComponent`s are displayed?

@jingtang10
Copy link
Collaborator

@jingtang10 PTAL. I resolved your comment and also moved where the displayString function is called to MoreAnswerOptions to be in the same location where displayString value is called for QuestionnaireItemAnswerOptionComponent.

I wanted to come up with one function to combine both like this:

internal val Questionnaire.QuestionnaireItemAnswerOptionComponent.displayString: String
  get() = displayString(null, value)

internal fun QuestionnaireResponse.QuestionnaireResponseItemAnswerComponent.displayString(
  context: Context
) = displayString(context, value)


private fun displayString(context: Context?, value: Type?) : String =
  return when(value) {
   //logic
  }
    

however, the logic becomes divergent. An example: in QuestionnaireItemAnswerOptionComponent, if the value is DateType, we just return value.primitiveValue(); so if we pass 2022-01-01 it will return 2022-01-01.

For DateTypes in QuestionnaireResponseItemAnswerComponent, we return value.localDate?.localizedString; so if we pass 2022-01-01, it will return 01/01/22.

Do we want to make what is displayed consistent, or is there a reason there is a difference between how QuestionnaireItemAnswerOptionComponents and QuestionnaireResponseItemAnswerComponent`s are displayed?

I don't think they need to be different - please unify them.

@omarismail94
Copy link
Contributor Author

@jingtang10 Unified the functions. With regards to existing tests that I needed to change, I only had to change MoreAnswerOptionsTest; I had to change the display format of the Date

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.

discussed with @omarismail94 - will refactor and make context mandatory, and then maybe move the extension function to Type instead.

@omarismail94
Copy link
Contributor Author

discussed with @omarismail94 - will refactor and make context mandatory, and then maybe move the extension function to Type instead.

implemented this

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 omar!

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.

Initial and initial expression not working on dropdown items with the type 'reference'
3 participants