Skip to content

Commit

Permalink
few of review comment changes
Browse files Browse the repository at this point in the history
Signed-off-by: Nilesh Gupta <[email protected]>
  • Loading branch information
ngu04 committed Oct 28, 2024
1 parent 47fd8a1 commit 8c6a49f
Show file tree
Hide file tree
Showing 13 changed files with 711 additions and 891 deletions.
1,276 changes: 619 additions & 657 deletions client/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/src/main/scala/drt/client/components/Debug.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object Debug {
.render_P { _ =>
val staffingRCP = SPACircuit.connect(
m => (
m.dayOfShift,
m.dayOfShifts,
m.fixedPoints,
m.staffMovements,
m.portStatePot,
Expand Down
60 changes: 32 additions & 28 deletions client/src/main/scala/drt/client/components/MonthlyStaffing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ object MonthlyStaffing {
})
}

def consecutiveDaysWithinDates(startDay: SDateLike, endDay: SDateLike): Seq[(SDateLike, String)] = {
def consecutiveDaysInMonth(startDay: SDateLike, endDay: SDateLike): Seq[(SDateLike, String)] = {
val lastDayOfPreviousMonth = SDate(startDay.getFullYear, startDay.getMonth, 1).addDays(-1)
val adjustedStartDay: SDateLike = if (startDay.getDate == lastDayOfPreviousMonth.getDate) {
if (startDay.getMonth == 11) // December
Expand Down Expand Up @@ -214,6 +214,32 @@ object MonthlyStaffing {
scope.modState(state => state.copy(showEditStaffForm = true)).runNow()
}

def handleNavigation(props: Props, viewingDate: SDateLike, isWeekly: Boolean, isDaily: Boolean): VdomTagOf[Div] = {
if (isWeekly) {
val previousWeekDate = {
val potentialPreviousWeekDate = viewingDate.addDays(-7)
val firstDayOfMonth = SDate.firstDayOfMonth(viewingDate)
if (potentialPreviousWeekDate.millisSinceEpoch < firstDayOfMonth.millisSinceEpoch) firstDayOfMonth else potentialPreviousWeekDate
}
val nextWeekDate = {
val potentialNextWeekDate = viewingDate.addDays(7)
val lastDayOfMonth = SDate.lastDayOfMonth(viewingDate)
if (potentialNextWeekDate.millisSinceEpoch > lastDayOfMonth.millisSinceEpoch) lastDayOfMonth else potentialNextWeekDate
}
navigationArrows(props, previousWeekDate, nextWeekDate)
} else if (isDaily) {
val isFirstDayOfMonth = viewingDate.getDate == 1
val isLastDayOfMonth = viewingDate.getDate == SDate.lastDayOfMonth(viewingDate).getDate
val previousDayDate = if (isFirstDayOfMonth) viewingDate else viewingDate.addDays(-1)
val nextDayDate = if (isLastDayOfMonth) viewingDate else viewingDate.addDays(1)
navigationArrows(props, previousDayDate, nextDayDate)
} else {
val previousMonthDate = viewingDate.addMonths(-1)
val nextMonthDate = viewingDate.addMonths(1)
navigationArrows(props, previousMonthDate, nextMonthDate)
}
}

def confirmAndSave(startOfMonthMidnight: SDateLike, timeSlots: Seq[Seq[Any]]): ReactEventFromInput => Callback = (_: ReactEventFromInput) =>
Callback {
val initialTimeSlots: Seq[Seq[Any]] = slotsFromShifts(state.shifts, props.terminalPageTab.terminal, startOfMonthMidnight, props.timeSlotMinutes, props.terminalPageTab.dayRangeType.getOrElse("monthly"))
Expand Down Expand Up @@ -266,7 +292,7 @@ object MonthlyStaffing {
modelChangeDetection,
<.div(
if (state.showStaffSuccess)
StaffSuccess(IStaffSuccess(0, "You updated the staff number for selected date and time", () => {
StaffUpdateSuccess(IStaffSuccess(0, "You updated the staff number for selected date and time", () => {
scope.modState(state => state.copy(showStaffSuccess = false)).runNow()
})) else EmptyVdom,
),
Expand All @@ -288,29 +314,7 @@ object MonthlyStaffing {
<.div(^.style := js.Dictionary("padding-top" -> "5px", "padding-left" -> "10px"),
<.strong(s"Staff numbers in ${props.terminalPageTab.dateFromUrlOrNow.getMonthString} ${props.terminalPageTab.dateFromUrlOrNow.getFullYear}")),
if (props.enableStaffPlanningChanges) <.div(^.className := "staffing-controls-navigation",
if (isWeekly) {
val previousWeekDate = {
val potentialPreviousWeekDate = viewingDate.addDays(-7)
val firstDayOfMonth = SDate.firstDayOfMonth(viewingDate)
if (potentialPreviousWeekDate.millisSinceEpoch < firstDayOfMonth.millisSinceEpoch) firstDayOfMonth else potentialPreviousWeekDate
}
val nextWeekDate = {
val potentialNextWeekDate = viewingDate.addDays(7)
val lastDayOfMonth = SDate.lastDayOfMonth(viewingDate)
if (potentialNextWeekDate.millisSinceEpoch > lastDayOfMonth.millisSinceEpoch) lastDayOfMonth else potentialNextWeekDate
}
navigationArrows(props, previousWeekDate, nextWeekDate)
} else if (isDaily) {
val isFirstDayOfMonth = viewingDate.getDate == 1
val isLastDayOfMonth = viewingDate.getDate == SDate.lastDayOfMonth(viewingDate).getDate
val previousDayDate = if (isFirstDayOfMonth) viewingDate else viewingDate.addDays(-1)
val nextDayDate = if (isLastDayOfMonth) viewingDate else viewingDate.addDays(1)
navigationArrows(props, previousDayDate, nextDayDate)
} else {
val previousMonthDate = viewingDate.addMonths(-1)
val nextMonthDate = viewingDate.addMonths(1)
navigationArrows(props, previousMonthDate, nextMonthDate)
}
handleNavigation(props, viewingDate, isWeekly, isDaily)
) else EmptyVdom,
<.div(^.className := "staffing-controls-select",
drawSelect(
Expand Down Expand Up @@ -476,7 +480,7 @@ object MonthlyStaffing {
}

private def daysInMonthByTimeSlotCalc(viewingDate: SDateLike, timeSlotMinutes: Int): Seq[Seq[Option[SDateLike]]] =
consecutiveDaysWithinDates(SDate.firstDayOfMonth(viewingDate), SDate.lastDayOfMonth(viewingDate))
consecutiveDaysInMonth(SDate.firstDayOfMonth(viewingDate), SDate.lastDayOfMonth(viewingDate))
.map { day =>
timeZoneSafeTimeSlots(
slotsInDay(day._1, timeSlotMinutes),
Expand Down Expand Up @@ -518,8 +522,8 @@ object MonthlyStaffing {

val daysInMonth: Seq[(SDateLike, String)] = props.terminalPageTab.dayRangeType match {
case Some("weekly") => consecutiveDayForWeek(viewingDate)
case Some("daily") => consecutiveDaysWithinDates(viewingDate, viewingDate)
case _ => consecutiveDaysWithinDates(SDate.firstDayOfMonth(viewingDate), SDate.lastDayOfMonth(viewingDate))
case Some("daily") => consecutiveDaysInMonth(viewingDate, viewingDate)
case _ => consecutiveDaysInMonth(SDate.firstDayOfMonth(viewingDate), SDate.lastDayOfMonth(viewingDate))
}

val dayForRowLabels = if (viewingDate.getMonth != 10)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ object IStaffSuccess {
}
}

object StaffSuccess {
object StaffUpdateSuccess {
@js.native
@JSImport("@drt/drt-react", "StaffSuccess")
object RawComponent extends js.Object
Expand Down
69 changes: 24 additions & 45 deletions client/src/main/scala/drt/client/components/TerminalComponent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ object TerminalComponent {

val modelRCP = SPACircuit.connect(model => TerminalModel(
userSelectedPlanningTimePeriod = model.userSelectedPlanningTimePeriod,
potShifts = model.dayOfShift,
potShifts = model.dayOfShifts,
potFixedPoints = model.fixedPoints,
potStaffMovements = model.staffMovements,
airportConfig = model.airportConfig,
Expand Down Expand Up @@ -223,11 +223,11 @@ object TerminalComponent {

case Planning =>
<.div(model.userSelectedPlanningTimePeriod.render { timePeriod =>
TerminalPlanningComponent(TerminalPlanningComponent.Props(props.terminalPageTab, props.router, timePeriod,airportConfig))
TerminalPlanningComponent(TerminalPlanningComponent.Props(props.terminalPageTab, props.router, timePeriod, airportConfig))
})

case Staffing if loggedInUser.roles.contains(StaffEdit) =>
<.div(MonthlyStaffing(props.terminalPageTab, props.router, airportConfig,featureFlags.enableStaffPlanningChange))
<.div(MonthlyStaffing(props.terminalPageTab, props.router, airportConfig, featureFlags.enableStaffPlanningChange))
}
}
}
Expand All @@ -241,9 +241,7 @@ object TerminalComponent {

val component: Component[Props, Unit, Backend, CtorType.Props] = ScalaComponent.builder[Props]("Loader")
.renderBackend[Backend]
.componentDidMount(_ =>
Callback(SPACircuit.dispatch(GetUserPreferenceIntervalMinutes())))
.configure(Reusability.shouldComponentUpdate)
.componentDidMount(_ => Callback(SPACircuit.dispatch(GetUserPreferenceIntervalMinutes())))
.build

private def terminalTabs(props: Props, loggedInUser: LoggedInUser, airportConfig: AirportConfig, timeMachineEnabled: Boolean): VdomTagOf[UList] = {
Expand All @@ -266,51 +264,32 @@ object TerminalComponent {

<.ul(^.className := "nav nav-tabs",
<.li(^.className := tabClass(Current) + " " + timeMachineClass,
<.a(^.id := "currentTab", "Queues & Arrivals", VdomAttr("data-toggle") := "tab"),
^.onClick ==> { e: ReactEventFromInput =>
e.preventDefault()
GoogleEventTracker.sendEvent(terminalName, "click", "Queues & Arrivals")
props.router.set(props.terminalPageTab.update(
mode = Current,
subMode = subMode,
queryParams = props.terminalPageTab.withUrlParameters(UrlDateParameter(None), viewTypeQueryParam).queryParams
))
}),
props.router.link(props.terminalPageTab.update(
mode = Current,
subMode = subMode,
queryParams = props.terminalPageTab.withUrlParameters(UrlDateParameter(None), viewTypeQueryParam).queryParams
))(^.id := "currentTab", "Queues & Arrivals", VdomAttr("data-toggle") := "tab")),
<.li(^.className := tabClass(Planning),
<.a(^.id := "planning-tab", VdomAttr("data-toggle") := "tab", "Planning"),
^.onClick ==> { e: ReactEventFromInput =>
e.preventDefault()
GoogleEventTracker.sendEvent(terminalName, "click", "Planning")
props.router.set(props.terminalPageTab.update(
mode = Planning,
subMode = subMode,
queryParams = props.terminalPageTab.withUrlParameters(UrlDateParameter(None), UrlTimeMachineDateParameter(None)).queryParams
))
}
props.router.link(props.terminalPageTab.update(
mode = Planning,
subMode = subMode,
queryParams = props.terminalPageTab.withUrlParameters(UrlDateParameter(None), UrlTimeMachineDateParameter(None)).queryParams
))(^.id := "planning-tab", VdomAttr("data-toggle") := "tab", "Planning"),
),
if (loggedInUser.roles.contains(StaffEdit))
<.li(^.className := tabClass(Staffing),
<.a(^.id := "monthlyStaffingTab", ^.className := "flex-forizontally", VdomAttr("data-toggle") := "tab", "Monthly Staffing", " ", monthlyStaffingTooltip),
^.onClick ==> { e: ReactEventFromInput =>
e.preventDefault()
GoogleEventTracker.sendEvent(terminalName, "click", "Monthly Staffing")
props.router.set(props.terminalPageTab.update(
mode = Staffing,
subMode = "60",
queryParams = props.terminalPageTab.withUrlParameters(UrlDateParameter(None), UrlTimeMachineDateParameter(None)).queryParams
))
}
props.router.link(props.terminalPageTab.update(
mode = Staffing,
subMode = "60",
queryParams = props.terminalPageTab.withUrlParameters(UrlDateParameter(None), UrlTimeMachineDateParameter(None)).queryParams
))(^.id := "monthlyStaffingTab", ^.className := "flex-forizontally", VdomAttr("data-toggle") := "tab", "Monthly Staffing", " ", monthlyStaffingTooltip)
) else "",
<.li(^.className := tabClass(Dashboard),
<.a(^.id := "terminalDashboardTab", VdomAttr("data-toggle") := "tab", s"$terminalName Dashboard"), ^.onClick --> {
GoogleEventTracker.sendEvent(terminalName, "click", "Terminal Dashboard")
props.router.set(
props.terminalPageTab.update(
mode = Dashboard,
subMode = "summary",
queryParams = props.terminalPageTab.withUrlParameters(UrlDateParameter(None), UrlTimeMachineDateParameter(None)).queryParams)
)
}
props.router.link(props.terminalPageTab.update(
mode = Dashboard,
subMode = "summary",
queryParams = props.terminalPageTab.withUrlParameters(UrlDateParameter(None), UrlTimeMachineDateParameter(None)).queryParams
))(^.id := "terminalDashboardTab", VdomAttr("data-toggle") := "tab", s"$terminalName Dashboard")
)
)
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/scala/drt/client/services/SPACircuit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ case class RootModel(applicationVersion: Pot[ClientServerVersions] = Empty,
airportConfig: Pot[AirportConfig] = Empty,
arrivalSources: Option[(UniqueArrival, Pot[List[Option[FeedSourceArrival]]])] = None,
contactDetails: Pot[ContactDetails] = Empty,
dayOfShift: Pot[ShiftAssignments] = Empty,
dayOfShifts: Pot[ShiftAssignments] = Empty,
allShifts: Pot[ShiftAssignments] = Empty,
fixedPoints: Pot[FixedPointAssignments] = Empty,
staffMovements: Pot[StaffMovements] = Empty,
Expand Down Expand Up @@ -222,7 +222,7 @@ trait DrtCircuit extends Circuit[RootModel] with ReactConnector[RootModel] {
new OohForSupportHandler(zoomRW(_.oohStatus)((m, v) => m.copy(oohStatus = v))),
new FeatureFlagHandler(zoomRW(_.featureFlags)((m, v) => m.copy(featureFlags = v))),
new ApplicationVersionHandler(zoomRW(_.applicationVersion)((m, v) => m.copy(applicationVersion = v))),
new ShiftsHandler(currentViewMode, zoomRW(_.dayOfShift)((m, v) => m.copy(dayOfShift = v))),
new ShiftsHandler(currentViewMode, zoomRW(_.dayOfShifts)((m, v) => m.copy(dayOfShifts = v))),
new AllShiftsHandler(zoomRW(_.allShifts)((m, v) => m.copy(allShifts = v))),
new FixedPointsHandler(currentViewMode, zoomRW(_.fixedPoints)((m, v) => m.copy(fixedPoints = v))),
new StaffMovementsHandler(currentViewMode, zoomRW(_.staffMovements)((m, v) => m.copy(staffMovements = v))),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class ShiftsHandler[M](getCurrentViewMode: () => ViewMode, modelRW: ModelRW[M, P
.recoverWith {
case _ =>
log.error(s"Failed to save Shifts. Re-requesting after ${PollDelay.recoveryDelay}")
Future(RetryActionAfter(UpdateShifts(assignments), 90.minutes))
Future(RetryActionAfter(UpdateShifts(assignments), PollDelay.recoveryDelay))
}
effectOnly(Effect(futureResponse))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ object StaffingComponentTests extends TestSuite {
val startDay = SDate("2017-12-21")
val endDay = SDate("2017-12-25")

val result = consecutiveDaysWithinDates(startDay, endDay).map(_._1.millisSinceEpoch)
val result = consecutiveDaysInMonth(startDay, endDay).map(_._1.millisSinceEpoch)

val expected = List(
SDate("2017-12-21"),
Expand Down
4 changes: 0 additions & 4 deletions server/src/main/assets/stylesheets/main.less
Original file line number Diff line number Diff line change
Expand Up @@ -1410,7 +1410,6 @@ p {
z-index: 100;
background-color: white;
padding-top: 10px;
//padding-left: 10px;
display: flex;
flex-direction: column;
justify-content: flex-start;
Expand All @@ -1421,10 +1420,7 @@ p {
padding-top: 10px;
padding-right: 10px;
padding-bottom: 10px;
//padding-left: 10px;
display: flex;
//flex-direction: column;
//justify-content: flex-end;
gap: 15px;
background-color: #E6E9F1;
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/resources/config/persistence.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ persistence {
on-stop-backoff {
minimum-seconds: 10
minimum-seconds: ${?PERSISTENCE_ON_STOP_BACKOFF_MIN_SECONDS}
maximum-seconds: 60
maximum-seconds: 30
maximum-seconds: ${?PERSISTENCE_ON_STOP_BACKOFF_MAX_SECONDS}
}
}
15 changes: 3 additions & 12 deletions server/src/main/scala/actors/persistent/staffing/ShiftsActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ trait ShiftsActorLike {
}

object ShiftsActor extends ShiftsActorLike {
val snapshotInterval = 10 // this is the number of events between snapshots at moment as it taking time to recover
val snapshotInterval = 5000

trait ShiftUpdate

Expand Down Expand Up @@ -166,17 +166,8 @@ class ShiftsActor(val now: () => SDateLike,
def processRecoveryMessage: PartialFunction[Any, Unit] = {
case sm: ShiftsMessage =>
log.info(s"Recovery: ShiftsMessage received with ${sm.shifts.length} shifts")
val shiftsToRecover: ShiftAssignments = shiftMessagesToStaffAssignments(sm.shifts)

val batchSize = 200
val updatedShifts = if (shiftsToRecover.assignments.size > batchSize) {
shiftsToRecover.assignments.grouped(batchSize).flatMap { batch =>
applyUpdatedShifts(state.assignments, batch, "shiftsToRecover batched - processRecoveryMessage")
}.toSeq
} else {
applyUpdatedShifts(state.assignments, shiftsToRecover.assignments, "shiftsToRecover - processRecoveryMessage")
}

val shiftsToRecover = shiftMessagesToStaffAssignments(sm.shifts)
val updatedShifts = applyUpdatedShifts(state.assignments, shiftsToRecover.assignments,"shiftsToRecover - processRecoveryMessage")
purgeExpiredAndUpdateState(ShiftAssignments(updatedShifts))
}

Expand Down
Loading

0 comments on commit 8c6a49f

Please sign in to comment.