Sortuj kursy kierowcy według dnia

This commit is contained in:
admin
2026-07-10 21:31:17 +02:00
parent e49e7c358e
commit f9c3a2e305
4 changed files with 31 additions and 2 deletions
@@ -245,6 +245,8 @@ data class DriverRouteDto(
val id: String, val id: String,
val routeDate: String? = null, val routeDate: String? = null,
val unloadingDate: String? = null, val unloadingDate: String? = null,
val ordering: Int? = null,
val dayOrderings: Map<String, Int>? = emptyMap(),
val startsAt: String, val startsAt: String,
val originName: String, val originName: String,
val destinationName: String, val destinationName: String,
@@ -66,6 +66,9 @@ fun routeIsActiveToday(
fun routeUnloadingDate(route: DriverRouteDto): String? = route.unloadingDate ?: route.routeDate fun routeUnloadingDate(route: DriverRouteDto): String? = route.unloadingDate ?: route.routeDate
fun routeDayOrdering(route: DriverRouteDto, date: String): Int =
route.dayOrderings?.get(date) ?: route.ordering ?: Int.MAX_VALUE
fun routeScheduleDateLabel(date: String?): String = fun routeScheduleDateLabel(date: String?): String =
date date
?.let { runCatching { LocalDate.parse(it).format(shortDateFormatter) }.getOrNull() } ?.let { runCatching { LocalDate.parse(it).format(shortDateFormatter) }.getOrNull() }
@@ -96,7 +96,10 @@ data class DriverUiState(
val displayRoutes: List<DriverRouteDto> val displayRoutes: List<DriverRouteDto>
get() = projectDriverRoutes(routes, projectionActions) get() = projectDriverRoutes(routes, projectionActions)
.sortedBy { route -> if (route.status == "ZAKOŃCZONA") 1 else 0 } .sortedWith(
compareBy<DriverRouteDto> { route -> if (route.status == "ZAKOŃCZONA") 1 else 0 }
.thenBy { route -> routeDayOrdering(route, selectedDate) },
)
val selectedRouteProjection: ProjectedDriverRoute? val selectedRouteProjection: ProjectedDriverRoute?
get() = selectedRoute?.let { projectDriverRoute(it, projectionActions) } get() = selectedRoute?.let { projectDriverRoute(it, projectionActions) }
@@ -83,6 +83,20 @@ class DriverUiStateTest {
assertEquals(listOf("planned", "active", "completed"), state.displayRoutes.map { it.id }) assertEquals(listOf("planned", "active", "completed"), state.displayRoutes.map { it.id })
} }
@Test
fun displayRoutesUsesTheSelectedDayOrderingForMultiDayRoutes() {
val state = DriverUiState(
selectedDate = "2026-07-02",
routes = listOf(
route(id = "span", status = "ZAPLANOWANA", ordering = 0, dayOrderings = mapOf("2026-07-02" to 2)),
route(id = "above-first", status = "ZAPLANOWANA", ordering = 0, dayOrderings = mapOf("2026-07-02" to 0)),
route(id = "above-second", status = "ZAPLANOWANA", ordering = 1, dayOrderings = mapOf("2026-07-02" to 1)),
),
)
assertEquals(listOf("above-first", "above-second", "span"), state.displayRoutes.map { it.id })
}
private fun leaveRequest(id: String, status: String): DriverLeaveRequestDto = private fun leaveRequest(id: String, status: String): DriverLeaveRequestDto =
DriverLeaveRequestDto( DriverLeaveRequestDto(
id = id, id = id,
@@ -92,10 +106,17 @@ class DriverUiStateTest {
status = status, status = status,
) )
private fun route(id: String = "1", status: String): DriverRouteDto = private fun route(
id: String = "1",
status: String,
ordering: Int? = null,
dayOrderings: Map<String, Int> = emptyMap(),
): DriverRouteDto =
DriverRouteDto( DriverRouteDto(
id = id, id = id,
routeDate = "2026-06-30", routeDate = "2026-06-30",
ordering = ordering,
dayOrderings = dayOrderings,
startsAt = "", startsAt = "",
originName = "Baza", originName = "Baza",
destinationName = "Instalacja", destinationName = "Instalacja",