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

Async getQuestionnairePages and Add progress bar to the 'Next' button #2645

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

FikriMilano
Copy link
Collaborator

@FikriMilano FikriMilano commented Jul 27, 2024

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

Fixes #2639

Description
Clear and concise code change description.

Alternative(s) considered
Have you considered any alternatives? And if so, why have you chosen the approach in this PR?

Type
Feature

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

ndegwamartin added a commit to opensrp/android-fhir that referenced this pull request Jul 30, 2024
    - With unmerged PR #9
    - WUP PR google#2178

- WUP google#2652
- WUP google#2521
- WUP google#2645
- WUP google#2648
- WUP google#2650
@jingtang10
Copy link
Collaborator

jingtang10 commented Aug 6, 2024

I haven't build the app from your change yet, but it looks like you're adding a new component. Would it be possible for you to do this instead: https://m3.material.io/components/progress-indicators/guidelines#01dea24a-ce29-4353-99da-35472e24f4f9 to combine the circular progress indicator with the next button?

@FikriMilano
Copy link
Collaborator Author

@jingtang10 yeah, that's exactly what I did

Comment on lines +388 to +409
viewModelScope.launch(Dispatchers.IO) {
var isReferenced = false
kotlin.run {
isReferenced = questionnaireItem.isExpressionReferencedBy(questionnaire)
if (isReferenced) return@run

questionnaire.item.flattened().forEach { item ->
isReferenced = questionnaireItem.isEnableWhenReferencedBy(item)
if (isReferenced) return@run

isReferenced = questionnaireItem.isExpressionReferencedBy(item)
if (isReferenced) return@run
}
}
if (isReferenced) isLoadingNextPage.value = true
modificationCount.update { it + 1 }

updateAnswerWithAffectedCalculatedExpression(questionnaireItem)

modificationCount.update { it + 1 }
updateAnswerWithAffectedCalculatedExpression(questionnaireItem)
pages = getQuestionnairePages()
isLoadingNextPage.value = false
modificationCount.update { it + 1 }
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should investigate if parallel coroutine here could cause any issues incase of answersChangedCallback in quick successions like typing an answer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will investigate

Copy link
Collaborator

@joiskash joiskash left a comment

Choose a reason for hiding this comment

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

Just left a comment on the approach, thanks!

isReferenced = questionnaireItem.isExpressionReferencedBy(questionnaire)
if (isReferenced) return@run

questionnaire.item.flattened().forEach { item ->
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a way to avoid this for loop? If the questionnaire is long? Also is there any value in avoiding it? Maybe we can just time this part and see how long it takes given a large questionnaire with many expressions and enable whens. If it takes < x% of the time then we don't really need to worry about it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

go through only:

  1. pages
  2. do it once

consider to use dependency graph, in the future.

Comment on lines +389 to +402
var isReferenced = false
kotlin.run {
isReferenced = questionnaireItem.isExpressionReferencedBy(questionnaire)
if (isReferenced) return@run

questionnaire.item.flattened().forEach { item ->
isReferenced = questionnaireItem.isEnableWhenReferencedBy(item)
if (isReferenced) return@run

isReferenced = questionnaireItem.isExpressionReferencedBy(item)
if (isReferenced) return@run
}
}
if (isReferenced) isLoadingNextPage.value = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

this whole bit should be calculated once for the questionnaire instead of being calculated each time when the answer changes?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

okay

@@ -29,4 +29,6 @@ data class QuestionnaireNavigationUIState(
val navSubmit: QuestionnaireNavigationViewUIState = QuestionnaireNavigationViewUIState.Hidden,
val navCancel: QuestionnaireNavigationViewUIState = QuestionnaireNavigationViewUIState.Hidden,
val navReview: QuestionnaireNavigationViewUIState = QuestionnaireNavigationViewUIState.Hidden,
val navNextProgressBar: QuestionnaireNavigationViewUIState =
QuestionnaireNavigationViewUIState.Hidden,
)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jingtang10 what do you think of this current code?
Initially I did add a new UI state for loading, but changed my mind, then implement it this current way.

My reasoning:
In the future, I'm thinking there might be other types of UI other than button that might use this UI state, it makes sense to have Loading state for button, but might not be for other types of UI.

Or am I just overthinking it(?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Jing:
Use loading state to update both next button and next button's circular progress indicator together

FikriMilano added a commit to opensrp/fhircore that referenced this pull request Sep 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PR under Review
Development

Successfully merging this pull request may close these issues.

Async process for getQuestionnairePages
5 participants