Skip to content

Commit

Permalink
[Track-303] RF Update phases in month grid (#2461)
Browse files Browse the repository at this point in the history
  • Loading branch information
tolkamps1 authored Dec 2, 2024
1 parent cf59c10 commit 6d54b75
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 49 deletions.
64 changes: 29 additions & 35 deletions epictrack-api/src/api/reports/resource_forecast_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,30 +424,33 @@ def _update_month_labels(self, works, start_events):
for work_id, work_data in works.items():
work = work_data[0]
for index, month in enumerate(self.months[1:]):
month_events = list(
filter(
lambda x: x["start_date"].date() <= month,
start_events[work_id],
)
month_start = month.replace(day=1)
month_end = (month_start + timedelta(days=31)).replace(day=1) - timedelta(days=1)
event_to_show = {"event_phase": "", "phase_color": "#FFFFFF"}
work_events = start_events.get(work_id, [])
sorted_events = sorted(work_events, key=lambda x: x["phase_end"].date())
for event in sorted_events:
phase_start = event["phase_start"].date()
phase_end = event["phase_end"].date()
if phase_start <= month_end and phase_end >= month_start:
if phase_end.month == month_start.month and 1 <= phase_end.day <= 14:
# Show the next phase if the phase ends in the early part of the month
next_event = next(
(e for e in sorted_events if e["phase_start"].date() > phase_end),
None,
)
event_to_show = next_event or {"event_phase": "", "phase_color": "#FFFFFF"}
else:
event_to_show = event
phase_label = self.month_labels[index]
work.update(
{
phase_label: event_to_show["event_phase"],
f"{phase_label}_color": color_with_opacity(
event_to_show["phase_color"], self.color_intensity
),
}
)
if month_events:
month_events = sorted(month_events, key=lambda x: x["start_date"])
latest_event = month_events[-1]
work.update(
{
self.month_labels[index]: latest_event["event_phase"],
f"{self.month_labels[index]}_color": color_with_opacity(
latest_event["phase_color"], self.color_intensity
),
}
)
else:
work.update(
{
self.month_labels[index]: "",
f"{self.month_labels[index]}_color": "#FFFFFF",
}
)
work_data[0] = work
results[work_id] = work_data
return results
Expand All @@ -461,6 +464,8 @@ def _filter_start_events(self, events: [Event]) -> [Event]:
event.actual_date if event.actual_date else event.anticipated_date
),
"event_phase": event.event_configuration.work_phase.name,
"phase_start": event.event_configuration.work_phase.start_date,
"phase_end": event.event_configuration.work_phase.end_date,
"phase_color": event.event_configuration.work_phase.phase.color,
}
for event in events
Expand Down Expand Up @@ -839,18 +844,7 @@ def _handle_months(self, work_data) -> dict:
referral_date = self._get_referral_timing(work_data["work_id"])
work_data["referral_timing"] = f"{referral_date:%B %d, %Y}"
months = []
referral_month_index = len(self.month_labels)
referral_month = next(
(x for x in self.months if referral_date.date() <= x),
None,
)
if referral_month:
referral_month_index = self.months.index(referral_month)
for month in self.month_labels[referral_month_index:]:
month_data = work_data.pop(month)
color = work_data.pop(f"{month}_color")
months.append({"label": month, "phase": "Referred", "color": color})
for month in self.month_labels[:referral_month_index]:
for month in self.month_labels:
month_data = work_data.pop(month)
color = work_data.pop(f"{month}_color")
months.append({"label": month, "phase": month_data, "color": color})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,20 +147,23 @@ export default function ResourceForecast() {
enableHiding: false,
size: 200,
enableColumnFilter: false,
Cell: ({ row }: any) => (
<Tooltip title={row.original.months[index].phase}>
<Box
sx={{
bgcolor: row.original.months[index].color,
overflow: "hidden",
padding: "0.5rem 0.5rem 0.5rem 1rem",
textOverflow: "ellipsis",
}}
>
{row.original.months[index].phase}
</Box>
</Tooltip>
),
Cell: ({ row }: any) => {
const phase = row.original.months[index].phase;
return phase ? (
<Tooltip title={row.original.months[index].phase}>
<Box
sx={{
bgcolor: row.original.months[index].color,
overflow: "hidden",
padding: "0.5rem 0.5rem 0.5rem 1rem",
textOverflow: "ellipsis",
}}
>
{phase}
</Box>
</Tooltip>
) : null;
},
} as MRT_ColumnDef<ResourceForecastModel>;
});
}
Expand Down

0 comments on commit 6d54b75

Please sign in to comment.