-
Notifications
You must be signed in to change notification settings - Fork 108
[CLX-3253][Horizon] Dashboard widgets improvements #3371
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
Changes from 2 commits
4cdd9d0
c722221
b7c5151
7840689
12f8274
f83620c
e87d697
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,8 +18,6 @@ package com.instructure.horizon.features.dashboard.widget | |
|
|
||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.PaddingValues | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.Spacer | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.pager.rememberPagerState | ||
|
|
@@ -32,21 +30,18 @@ import androidx.compose.ui.res.stringResource | |
| import androidx.compose.ui.semantics.Role | ||
| import androidx.compose.ui.semantics.role | ||
| import androidx.compose.ui.semantics.semantics | ||
| import androidx.compose.ui.text.style.TextOverflow | ||
| import androidx.compose.ui.tooling.preview.Preview | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.navigation.NavHostController | ||
| import androidx.navigation.compose.rememberNavController | ||
| import com.instructure.canvasapi2.utils.ContextKeeper | ||
| import com.instructure.horizon.R | ||
| import com.instructure.horizon.features.dashboard.DashboardCard | ||
| import com.instructure.horizon.horizonui.animation.shimmerEffect | ||
| import com.instructure.horizon.horizonui.foundation.HorizonColors | ||
| import com.instructure.horizon.horizonui.foundation.HorizonSpace | ||
| import com.instructure.horizon.horizonui.foundation.HorizonTypography | ||
| import com.instructure.horizon.horizonui.foundation.SpaceSize | ||
| import com.instructure.horizon.horizonui.molecules.StatusChip | ||
| import com.instructure.horizon.horizonui.molecules.StatusChipColor | ||
| import com.instructure.horizon.horizonui.molecules.StatusChipState | ||
| import com.instructure.horizon.horizonui.organisms.AnimatedHorizontalPager | ||
| import com.instructure.pandautils.utils.localisedFormat | ||
| import java.util.Date | ||
|
|
@@ -71,13 +66,22 @@ fun DashboardPaginatedWidgetCard( | |
| pageSpacing = 12.dp, | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| ) { index, modifier -> | ||
| DashboardCard( | ||
| val item = state.items[index] | ||
| DashboardWidgetCard( | ||
| title = item.headerState.label, | ||
| iconRes = item.headerState.iconRes, | ||
| useMinWidth = false, | ||
| widgetColor = item.headerState.color, | ||
| pageState = DashboardWidgetPageState( | ||
| currentPageNumber = pagerState.currentPage + 1, | ||
| pageCount = state.items.size | ||
| ), | ||
| modifier = modifier.padding(bottom = 16.dp), | ||
| onClick = if (state.isLoading) { | ||
| null | ||
| } else { | ||
| { | ||
| state.items[index].route?.let { route -> | ||
| item.route?.let { route -> | ||
| when (route) { | ||
| is DashboardPaginatedWidgetCardButtonRoute.HomeRoute -> { | ||
| homeNavController.navigate(route.route) | ||
|
|
@@ -96,19 +100,14 @@ fun DashboardPaginatedWidgetCard( | |
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| ) { | ||
| HorizonSpace(SpaceSize.SPACE_24) | ||
|
|
||
| DashboardPaginatedWidgetCardItem( | ||
| item = state.items[index], | ||
| item = item, | ||
| isLoading = state.isLoading, | ||
| modifier = Modifier | ||
|
||
| .padding(horizontal = 24.dp) | ||
| .semantics(mergeDescendants = true) { | ||
| role = Role.Button | ||
| } | ||
| ) | ||
|
|
||
| HorizonSpace(SpaceSize.SPACE_24) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -124,44 +123,14 @@ private fun DashboardPaginatedWidgetCardItem( | |
| Column( | ||
| modifier = modifier.fillMaxWidth() | ||
| ) { | ||
| if (item.chipState != null || item.pageState != null) { | ||
| Row( | ||
| verticalAlignment = Alignment.CenterVertically, | ||
| modifier = Modifier.fillMaxWidth() | ||
| ) { | ||
| item.chipState?.let { chipState -> | ||
| StatusChip( | ||
| state = StatusChipState( | ||
| label = chipState.label, | ||
| color = chipState.color, | ||
| fill = true | ||
| ), | ||
| modifier = Modifier.shimmerEffect( | ||
| isLoading, | ||
| backgroundColor = chipState.color.fillColor.copy(0.8f), | ||
| shimmerColor = chipState.color.fillColor.copy(0.5f) | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| Spacer(Modifier.weight(1f)) | ||
|
|
||
| item.pageState?.let { | ||
| Text( | ||
| it, | ||
| style = HorizonTypography.p2, | ||
| color = HorizonColors.Text.dataPoint(), | ||
| ) | ||
| } | ||
| } | ||
| HorizonSpace(SpaceSize.SPACE_16) | ||
| } | ||
| item.source?.let { source -> | ||
| Text( | ||
| text = stringResource( | ||
| R.string.dashboardAnnouncementBannerFrom, | ||
| source | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good improvement! Adding |
||
| ), | ||
| maxLines = 1, | ||
| overflow = TextOverflow.Ellipsis, | ||
| style = HorizonTypography.p2, | ||
| color = HorizonColors.Text.dataPoint(), | ||
| modifier = Modifier.shimmerEffect(isLoading) | ||
|
|
@@ -182,13 +151,13 @@ private fun DashboardPaginatedWidgetCardItem( | |
| Text( | ||
| text = title, | ||
| style = HorizonTypography.p1, | ||
| maxLines = 3, | ||
| overflow = TextOverflow.Ellipsis, | ||
| color = HorizonColors.Text.body(), | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .shimmerEffect(isLoading) | ||
| ) | ||
|
|
||
| HorizonSpace(SpaceSize.SPACE_16) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -201,29 +170,32 @@ private fun DashboardPaginatedWidgetCardAnnouncementContentPreview() { | |
| state = DashboardPaginatedWidgetCardState( | ||
| items = listOf( | ||
| DashboardPaginatedWidgetCardItemState( | ||
| chipState = DashboardPaginatedWidgetCardChipState( | ||
| headerState = DashboardPaginatedWidgetCardHeaderState( | ||
| label = "Announcement", | ||
| color = StatusChipColor.Sky | ||
| color = HorizonColors.Surface.institution().copy(alpha = 0.1f), | ||
| iconRes = R.drawable.ic_announcement | ||
| ), | ||
| title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Announcement title shown here.", | ||
| source = "Institution or Course Name Here", | ||
| date = Date(), | ||
| route = DashboardPaginatedWidgetCardButtonRoute.MainRoute("") | ||
| ), | ||
| DashboardPaginatedWidgetCardItemState( | ||
| chipState = DashboardPaginatedWidgetCardChipState( | ||
| headerState = DashboardPaginatedWidgetCardHeaderState( | ||
| label = "Announcement", | ||
| color = StatusChipColor.Sky | ||
| color = HorizonColors.Surface.institution().copy(alpha = 0.1f), | ||
| iconRes = R.drawable.ic_announcement | ||
| ), | ||
| title = "Second announcement with different content to show pagination.", | ||
| source = "Another Course Name", | ||
| date = Date(), | ||
| route = DashboardPaginatedWidgetCardButtonRoute.MainRoute("") | ||
| ), | ||
| DashboardPaginatedWidgetCardItemState( | ||
| chipState = DashboardPaginatedWidgetCardChipState( | ||
| headerState = DashboardPaginatedWidgetCardHeaderState( | ||
| label = "Announcement", | ||
| color = StatusChipColor.Sky | ||
| color = HorizonColors.Surface.institution().copy(alpha = 0.1f), | ||
| iconRes = R.drawable.ic_announcement | ||
| ), | ||
| title = "Third global announcement without a source.", | ||
| date = Date(), | ||
|
|
@@ -241,21 +213,7 @@ private fun DashboardPaginatedWidgetCardAnnouncementContentPreview() { | |
| private fun DashboardPaginatedWidgetCardAnnouncementLoadingPreview() { | ||
| ContextKeeper.appContext = LocalContext.current | ||
| DashboardPaginatedWidgetCard( | ||
| state = DashboardPaginatedWidgetCardState( | ||
| items = listOf( | ||
| DashboardPaginatedWidgetCardItemState( | ||
| chipState = DashboardPaginatedWidgetCardChipState( | ||
| label = "Announcement", | ||
| color = StatusChipColor.Sky | ||
| ), | ||
| title = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Announcement title shown here.", | ||
| source = "Institution or Course Name Here", | ||
| date = Date(), | ||
| route = DashboardPaginatedWidgetCardButtonRoute.MainRoute("") | ||
| ), | ||
| ), | ||
| isLoading = true | ||
| ), | ||
| state = DashboardPaginatedWidgetCardState.Loading, | ||
| rememberNavController(), | ||
| rememberNavController(), | ||
| ) | ||
|
|
||
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.
The
elsebranch was removed from the when expression, but this makes the when non-exhaustive. If the pager ever has more than 3 pages or an invalid index, this could lead to silent failures. Consider either keeping the empty else branch for safety, or adding a check/comment explaining why indices 0-2 are guaranteed.