Skip to content

Commit

Permalink
Fix year to date and last year
Browse files Browse the repository at this point in the history
  • Loading branch information
rodriguestiago0 committed Jan 11, 2025
1 parent 0d0068c commit 3062cb5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 4 deletions.
7 changes: 5 additions & 2 deletions packages/desktop-client/src/components/reports/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ export function Header({
}: HeaderProps) {
const { t } = useTranslation();
const { isNarrowWidth } = useResponsive();

//debugger;
function convertToMonth(
start: string,
end: string,
_: TimeFrame['mode'],
mode: TimeFrame['mode'],
): [string, string, TimeFrame['mode']] {
return [monthUtils.getMonth(start), monthUtils.getMonth(end), mode];
Expand Down Expand Up @@ -181,6 +182,7 @@ export function Header({
true,
firstDayOfWeekIdx,
),
'yearToDate',
),
)
}
Expand All @@ -195,9 +197,10 @@ export function Header({
...getLiveRange(
'Last year',
earliestTransaction,
true,
false,
firstDayOfWeekIdx,
),
'lastYear',
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export function ReportSidebar({
firstDayOfWeekIdx,
isComplexCategoryCondition = false,
}: ReportSidebarProps) {
debugger;
const { t } = useTranslation();
const [menuOpen, setMenuOpen] = useState(false);
const triggerRef = useRef(null);
Expand Down
12 changes: 12 additions & 0 deletions packages/desktop-client/src/components/reports/reportRanges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export function calculateTimeRange(
timeFrame?: Partial<TimeFrame>,
defaultTimeFrame?: TimeFrame,
) {
debugger;
const start =
timeFrame?.start ??
defaultTimeFrame?.start ??
Expand All @@ -196,6 +197,17 @@ export function calculateTimeRange(

return getLatestRange(offset);
}
if (mode === 'lastYear') {
const year = monthUtils.subYears(monthUtils.currentYear(), 1);
return [year + '-01', year + '-12', 'lastYear'] as const;
}
if (mode === 'yearToDate') {
return [
monthUtils.currentYear() + '-01',
monthUtils.currentMonth(),
'yearToDate',
] as const;
}

return [start, end, 'static'] as const;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ function SummaryInner({ widget }: SummaryInnerProps) {
);
return;
}

debugger;
await send('dashboard-update-widget', {
id: widget.id,
meta: {
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/types/models/dashboard.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type RuleConditionEntity } from './rule';
export type TimeFrame = {
start: string;
end: string;
mode: 'sliding-window' | 'static' | 'full';
mode: 'sliding-window' | 'static' | 'full' | 'lastYear' | 'yearToDate';
};

type AbstractWidget<
Expand Down

0 comments on commit 3062cb5

Please sign in to comment.