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

"Create poll" UI #1143

Merged
merged 16 commits into from Aug 29, 2023
Merged

"Create poll" UI #1143

merged 16 commits into from Aug 29, 2023

Conversation

julioromano
Copy link
Contributor

@julioromano julioromano commented Aug 24, 2023

NB: This is missing analytics, which will be added once matrix-org/matrix-analytics-events#85 is merged.

Closes element-hq/element-meta#2011

@julioromano julioromano self-assigned this Aug 24, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Aug 24, 2023

📱 Scan the QR code below to install the build (arm64 only) for this PR.
QR code
If you can't scan the QR code you can install the build via this link: https://i.diawi.com/KJzUnv

@julioromano julioromano force-pushed the julioromano/create_poll_ui branch 18 times, most recently from 67b23fc to 051ef60 Compare August 25, 2023 11:59
@codecov
Copy link

codecov bot commented Aug 25, 2023

Codecov Report

Patch coverage: 72.82% and project coverage change: +0.22% 🎉

Comparison is base (5a85459) 56.87% compared to head (10d07d1) 57.09%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1143      +/-   ##
===========================================
+ Coverage    56.87%   57.09%   +0.22%     
===========================================
  Files         1039     1044       +5     
  Lines        26812    27092     +280     
  Branches      5544     5592      +48     
===========================================
+ Hits         15248    15469     +221     
- Misses        9168     9201      +33     
- Partials      2396     2422      +26     
Files Changed Coverage Δ
...es/poll/impl/create/DefaultCreatePollEntryPoint.kt 0.00% <0.00%> (ø)
...ges/impl/messagecomposer/AttachmentsBottomSheet.kt 41.17% <33.33%> (-1.05%) ⬇️
...ssages/impl/messagecomposer/MessageComposerView.kt 53.12% <33.33%> (-0.21%) ⬇️
...es/messages/impl/actionlist/ActionListPresenter.kt 84.12% <36.36%> (-10.11%) ⬇️
...ndroid/features/poll/impl/create/CreatePollView.kt 50.00% <50.00%> (ø)
...ent/android/features/messages/impl/MessagesView.kt 59.09% <66.66%> (+0.11%) ⬆️
...s/impl/messagecomposer/MessageComposerPresenter.kt 90.38% <66.66%> (-0.95%) ⬇️
...d/features/poll/impl/create/CreatePollPresenter.kt 78.46% <78.46%> (ø)
...droid/features/poll/impl/create/CreatePollState.kt 90.90% <90.90%> (ø)
...atures/poll/impl/create/CreatePollStateProvider.kt 94.11% <94.11%> (ø)
... and 5 more

... and 3 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@julioromano julioromano force-pushed the julioromano/create_poll_ui branch 8 times, most recently from 2c31714 to 319e9c2 Compare August 28, 2023 14:40
@julioromano julioromano marked this pull request as ready for review August 29, 2023 08:39
@julioromano julioromano requested a review from a team as a code owner August 29, 2023 08:39
@julioromano julioromano requested review from bmarty and removed request for a team August 29, 2023 08:39
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Nice work, a few remarks and one (or 2) blocking points.
Also maybe add the create poll flow in the Maestro test (can be done later of course).

EDIT: Creating a poll worked :)

@@ -83,6 +83,11 @@ class MessageComposerPresenter @Inject constructor(
canShareLocation.value = featureFlagService.isFeatureEnabled(FeatureFlags.LocationSharing)
}

val canCreatePoll = remember { mutableStateOf(false) }
LaunchedEffect(Unit) {
canCreatePoll.value = featureFlagService.isFeatureEnabled(FeatureFlags.Polls)
Copy link
Member

Choose a reason for hiding this comment

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

Maybe update the string here:
https://github.com/vector-im/element-x-android/blob/41d0d21c808353f91a0d4ceedcb4321a94cf3f31/libraries/featureflag/api/src/main/kotlin/io/element/android/libraries/featureflag/api/FeatureFlags.kt#L32

"Render poll events in the timeline"

since it also a flag to create poll. I propose "Create poll and render poll events in the timeline", but you choose.

private const val MIN_ANSWERS = 2;
private const val MAX_ANSWERS = 20;
private const val MAX_ANSWER_LENGTH = 240;
private const val MAX_SELECTIONS = 1;
Copy link
Member

Choose a reason for hiding this comment

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

remove the ;. You are doing too much Rust :)

},
restore = {
mutableStateOf(
when {
Copy link
Member

Choose a reason for hiding this comment

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

There is a problem here, you are not using it:

Suggested change
when {
when(it) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh damn, thanks, this is fatigue, I was wondering all day why intellij was underlying that when and couldn't fathom.

return map { answer ->
Answer(
text = answer,
canDelete = this.size > MIN_ANSWERS,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe confirm with product, but I fill weird not being able to delete an option if there is only 2 options. It's still possible to add an option, then delete the undesired one, so not a big deal though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was explicitly specced by Product

pollKind = pollKind,
)
// analyticsService.capture(PollCreate()) // TODO: Send PollCreate analytics.
navigateUp()
Copy link
Member

Choose a reason for hiding this comment

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

Is there a risk that calling this will cancel the poll creation (since the scope will be cancelled)?

Also we generally let the Node handle the navigation, so better to follow the existing pattern. The presenter set a boolean to the State that the flow is over, and the View communicate to the Node to handle the navigation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a risk that calling this will cancel the poll creation (since the scope will be cancelled)?

Yes there is, though generally the rust sdk is very quick and I never saw it happen. In general I think this might be a bigger architectural problem as all our presenters use rememberCoroutineScope().

Also we generally let the Node handle the navigation, so better to follow the existing pattern. The presenter set a boolean to the State that the flow is over, and the View communicate to the Node to handle the navigation.

I've seen another case where a custom navigator has been used (MessagesNavigator) so I thought this approach would be better, the added benefit is that it is testable.

// analyticsService.capture(PollCreate()) // TODO: Send PollCreate analytics.
navigateUp()
} else {
Timber.e("Cannot create poll")
Copy link
Member

@bmarty bmarty Aug 29, 2023

Choose a reason for hiding this comment

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

I guess this else block can be removed, the log is not adding lots of value. Or just change it to a debug log.


@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CreatePollView(
Copy link
Member

@bmarty bmarty Aug 29, 2023

Choose a reason for hiding this comment

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

I cannot scroll the content when the keyboard is open, So I cannot see the entered text for the option 5 (depending on your phone size).

@julioromano
Copy link
Contributor Author

Addressed all comments except for: #1143 (comment)

event.text.substring(0, MAX_ANSWER_LENGTH)
} else {
event.text
}
Copy link
Member

Choose a reason for hiding this comment

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

You can simplify with val text = event.text.take(MAX_ANSWER_LENGTH)

@Assisted buildContext: BuildContext,
@Assisted plugins: List<Plugin>,
presenterFactory: CreatePollPresenter.Factory,
analyticsService: AnalyticsService,
Copy link
Member

Choose a reason for hiding this comment

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

For the CI to be happy, this line has to be commented out. We hunt all the warnings.

@julioromano
Copy link
Contributor Author

I've completely commented out the analytics code because the analytics PR is stuck.
I also took care of disabling replies and forwards for poll events.

@sonarcloud
Copy link

sonarcloud bot commented Aug 29, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 11 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@@ -24,6 +24,7 @@
import androidx.compose.material.ListItem
Copy link
Collaborator

Choose a reason for hiding this comment

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

  • ⚠️ Using a material import while also using the material3 library

Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

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

Thanks for the update! LGTM.

@julioromano julioromano merged commit 633d528 into develop Aug 29, 2023
16 of 18 checks passed
@julioromano julioromano deleted the julioromano/create_poll_ui branch August 29, 2023 20:31
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.

"Create poll" UI (EXA)
3 participants