Skip to content
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

Custom Reports: Include current #2684

Merged
merged 13 commits into from
Jun 17, 2024
24 changes: 14 additions & 10 deletions packages/desktop-client/src/components/reports/ReportOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const defaultReport: CustomReportEntity = {
showEmpty: false,
showOffBudget: false,
showHiddenCategories: false,
includeCurrentInterval: true,
showUncategorized: false,
graphType: 'BarGraph',
conditions: [],
Expand Down Expand Up @@ -58,7 +59,7 @@ const dateRangeOptions: dateRangeProps[] = [
{
description: 'This week',
name: 0,
type: 'Weeks',
type: 'Week',
Daily: true,
Weekly: true,
Monthly: false,
Expand All @@ -67,7 +68,7 @@ const dateRangeOptions: dateRangeProps[] = [
{
description: 'Last week',
name: 1,
type: 'Weeks',
type: 'Week',
Daily: true,
Weekly: true,
Monthly: false,
Expand All @@ -76,7 +77,7 @@ const dateRangeOptions: dateRangeProps[] = [
{
description: 'This month',
name: 0,
type: 'Months',
type: 'Month',
Daily: true,
Weekly: true,
Monthly: true,
Expand All @@ -85,34 +86,34 @@ const dateRangeOptions: dateRangeProps[] = [
{
description: 'Last month',
name: 1,
type: 'Months',
type: 'Month',
Daily: true,
Weekly: true,
Monthly: true,
Yearly: false,
},
{
description: 'Last 3 months',
name: 2,
type: 'Months',
name: 3,
type: 'Month',
Daily: true,
Weekly: true,
Monthly: true,
Yearly: false,
},
{
description: 'Last 6 months',
name: 5,
type: 'Months',
name: 6,
type: 'Month',
Daily: false,
Weekly: false,
Monthly: true,
Yearly: false,
},
{
description: 'Last 12 months',
name: 11,
type: 'Months',
name: 12,
type: 'Month',
Daily: false,
Weekly: false,
Monthly: true,
Expand All @@ -121,6 +122,7 @@ const dateRangeOptions: dateRangeProps[] = [
{
description: 'Year to date',
name: 'yearToDate',
type: 'Month',
Daily: false,
Weekly: true,
Monthly: true,
Expand All @@ -129,6 +131,7 @@ const dateRangeOptions: dateRangeProps[] = [
{
description: 'Last year',
name: 'lastYear',
type: 'Month',
Daily: false,
Weekly: true,
Monthly: true,
Expand All @@ -137,6 +140,7 @@ const dateRangeOptions: dateRangeProps[] = [
{
description: 'All time',
name: 'allTime',
type: 'Month',
Daily: false,
Weekly: true,
Monthly: true,
Expand Down
45 changes: 42 additions & 3 deletions packages/desktop-client/src/components/reports/ReportSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { Text } from '../common/Text';
import { View } from '../common/View';

import { CategorySelector } from './CategorySelector';
import { defaultsList } from './disabledList';
import { defaultsList, disabledList } from './disabledList';
import { getLiveRange } from './getLiveRange';
import { ModeButton } from './ModeButton';
import { type dateRangeProps, ReportOptions } from './ReportOptions';
Expand All @@ -38,6 +38,7 @@ type ReportSidebarProps = {
setShowOffBudget: (value: boolean) => void;
setShowHiddenCategories: (value: boolean) => void;
setShowUncategorized: (value: boolean) => void;
setIncludeCurrentInterval: (value: boolean) => void;
setSelectedCategories: (value: CategoryEntity[]) => void;
onChangeDates: (dateStart: string, dateEnd: string) => void;
onReportChange: ({
Expand Down Expand Up @@ -69,6 +70,7 @@ export function ReportSidebar({
setShowEmpty,
setShowOffBudget,
setShowHiddenCategories,
setIncludeCurrentInterval,
setShowUncategorized,
setSelectedCategories,
onChangeDates,
Expand All @@ -86,7 +88,12 @@ export function ReportSidebar({
onReportChange({ type: 'modify' });
setDateRange(cond);
onChangeDates(
...getLiveRange(cond, earliestTransaction, firstDayOfWeekIdx),
...getLiveRange(
cond,
earliestTransaction,
customReportItems.includeCurrentInterval,
firstDayOfWeekIdx,
),
);
};

Expand Down Expand Up @@ -269,7 +276,15 @@ export function ReportSidebar({
onMenuSelect={type => {
onReportChange({ type: 'modify' });

if (type === 'show-hidden-categories') {
if (type === 'include-current-interval') {
setSessionReport(
'includeCurrentInterval',
!customReportItems.includeCurrentInterval,
);
setIncludeCurrentInterval(
!customReportItems.includeCurrentInterval,
);
} else if (type === 'show-hidden-categories') {
setSessionReport(
'showHiddenCategories',
!customReportItems.showHiddenCategories,
Expand All @@ -295,6 +310,30 @@ export function ReportSidebar({
}
}}
items={[
{
name: 'include-current-interval',
text:
'Include current ' +
(
ReportOptions.dateRangeType.get(
customReportItems.dateRange,
) || ''
).toLowerCase(),
tooltip:
'Include current ' +
(
ReportOptions.dateRangeType.get(
customReportItems.dateRange,
) || ''
).toLowerCase() +
' in live range',
toggle: customReportItems.includeCurrentInterval,
disabled:
customReportItems.isDateStatic ||
disabledList.currentInterval.get(
customReportItems.dateRange,
),
},
{
name: 'show-hidden-categories',
text: 'Show hidden categories',
Expand Down
26 changes: 26 additions & 0 deletions packages/desktop-client/src/components/reports/disabledList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,29 @@ const intervalOptions = [
},
];

const currentIntervalOptions = [
{
description: 'This week',
disableInclude: true,
},
{
description: 'This month',
disableInclude: true,
},
{
description: 'Year to date',
disableInclude: true,
},
{
description: 'Last year',
disableInclude: true,
},
{
description: 'All time',
disableInclude: true,
},
];

type graphOptions = {
description: string;
disabledSplit: string[];
Expand Down Expand Up @@ -164,6 +187,9 @@ export const disabledList = {
modeGraphsMap: new Map(
modeOptions.map(item => [item.description, item.disabledGraph]),
),
currentInterval: new Map(
currentIntervalOptions.map(item => [item.description, item.disableInclude]),
),
};

export const defaultsList = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { getSpecificRange, validateRange } from './reportRanges';
export function getLiveRange(
cond: string,
earliestTransaction: string,
includeCurrentInterval: boolean,
firstDayOfWeekIdx?: LocalPrefs['firstDayOfWeekIdx'],
): [string, string] {
let dateStart = earliestTransaction;
Expand Down Expand Up @@ -38,7 +39,9 @@ export function getLiveRange(
if (typeof rangeName === 'number') {
[dateStart, dateEnd] = getSpecificRange(
rangeName,
cond === 'Last month' || cond === 'Last week' ? 0 : null,
['This month', 'This week'].includes(cond)
? null
: rangeName - (includeCurrentInterval ? 0 : 1),
ReportOptions.dateRangeType.get(cond),
firstDayOfWeekIdx,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export function getSpecificRange(
'-01',
);

if (type === 'Weeks') {
if (type === 'Week') {
dateStart = monthUtils.subWeeks(currentWeek, offset);
dateEnd = monthUtils.getWeekEnd(
monthUtils.addWeeks(dateStart, addNumber === null ? offset : addNumber),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ export function CustomReport() {
const [balanceType, setBalanceType] = useState(loadReport.balanceType);
const [showEmpty, setShowEmpty] = useState(loadReport.showEmpty);
const [showOffBudget, setShowOffBudget] = useState(loadReport.showOffBudget);
const [includeCurrentInterval, setIncludeCurrentInterval] = useState(
loadReport.includeCurrentInterval,
);
const [showHiddenCategories, setShowHiddenCategories] = useState(
loadReport.showHiddenCategories,
);
Expand Down Expand Up @@ -212,6 +215,7 @@ export function CustomReport() {
const [dateStart, dateEnd] = getLiveRange(
dateRange,
trans ? trans.date : monthUtils.currentDay(),
includeCurrentInterval,
firstDayOfWeekIdx,
);
setStartDate(dateStart);
Expand All @@ -226,6 +230,7 @@ export function CustomReport() {
isDateStatic,
onApplyFilter,
report.conditions,
includeCurrentInterval,
]);

useEffect(() => {
Expand Down Expand Up @@ -340,6 +345,7 @@ export function CustomReport() {
showEmpty,
showOffBudget,
showHiddenCategories,
includeCurrentInterval,
showUncategorized,
selectedCategories,
graphType,
Expand Down Expand Up @@ -482,6 +488,7 @@ export function CustomReport() {
setShowEmpty(input.showEmpty);
setShowOffBudget(input.showOffBudget);
setShowHiddenCategories(input.showHiddenCategories);
setIncludeCurrentInterval(input.includeCurrentInterval);
setShowUncategorized(input.showUncategorized);
setSelectedCategories(input.selectedCategories || selectAll);
setGraphType(input.graphType);
Expand Down Expand Up @@ -583,6 +590,7 @@ export function CustomReport() {
setShowEmpty={setShowEmpty}
setShowOffBudget={setShowOffBudget}
setShowHiddenCategories={setShowHiddenCategories}
setIncludeCurrentInterval={setIncludeCurrentInterval}
setShowUncategorized={setShowUncategorized}
setSelectedCategories={setSelectedCategories}
onChangeDates={onChangeDates}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export function GetCardData({
const [dateStart, dateEnd] = getLiveRange(
report.dateRange,
earliestTransaction,
report.includeCurrentInterval,
firstDayOfWeekIdx,
);
startDate = dateStart || report.startDate;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN TRANSACTION;

ALTER TABLE custom_reports ADD COLUMN include_current INTEGER DEFAULT 0;

COMMIT;
1 change: 1 addition & 0 deletions packages/loot-core/src/client/data-hooks/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function toJS(rows: CustomReportData[]) {
showEmpty: row.show_empty === 1,
showOffBudget: row.show_offbudget === 1,
showHiddenCategories: row.show_hidden === 1,
includeCurrentInterval: row.include_current === 1,
showUncategorized: row.show_uncategorized === 1,
selectedCategories: row.selected_categories,
graphType: row.graph_type,
Expand Down
1 change: 1 addition & 0 deletions packages/loot-core/src/server/aql/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const schema = {
show_offbudget: f('integer', { default: 0 }),
show_hidden: f('integer', { default: 0 }),
show_uncategorized: f('integer', { default: 0 }),
include_current: f('integer', { default: 0 }),
selected_categories: f('json'),
graph_type: f('string', { default: 'BarGraph' }),
conditions: f('json'),
Expand Down
2 changes: 2 additions & 0 deletions packages/loot-core/src/server/reports/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const reportModel = {
showOffBudget: row.show_offbudget === 1,
showHiddenCategories: row.show_hidden === 1,
showUncategorized: row.show_uncategorized === 1,
includeCurrentInterval: row.include_current === 1,
selectedCategories: row.selected_categories,
graphType: row.graph_type,
conditions: row.conditions,
Expand All @@ -65,6 +66,7 @@ const reportModel = {
show_offbudget: report.showOffBudget ? 1 : 0,
show_hidden: report.showHiddenCategories ? 1 : 0,
show_uncategorized: report.showUncategorized ? 1 : 0,
include_current: report.includeCurrentInterval ? 1 : 0,
selected_categories: report.selectedCategories,
graph_type: report.graphType,
conditions: report.conditions,
Expand Down
6 changes: 4 additions & 2 deletions packages/loot-core/src/shared/months.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ export function _yearRange(
): string[] {
const years: string[] = [];
let year = yearFromDate(start);
while (d.isBefore(_parse(year), _parse(end))) {
const endYear = yearFromDate(end);
while (d.isBefore(_parse(year), _parse(endYear))) {
years.push(year);
year = addYears(year, 1);
}
Expand Down Expand Up @@ -284,7 +285,8 @@ export function _range(
): string[] {
const months: string[] = [];
let month = monthFromDate(start);
while (d.isBefore(_parse(month), _parse(end))) {
const endMonth = monthFromDate(end);
while (d.isBefore(_parse(month), _parse(endMonth))) {
months.push(month);
month = addMonths(month, 1);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/loot-core/src/types/models/reports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface CustomReportEntity {
showEmpty: boolean;
showOffBudget: boolean;
showHiddenCategories: boolean;
includeCurrentInterval: boolean;
showUncategorized: boolean;
selectedCategories?: CategoryEntity[];
graphType: string;
Expand Down Expand Up @@ -114,6 +115,7 @@ export interface CustomReportData {
show_empty: number;
show_offbudget: number;
show_hidden: number;
include_current: number;
show_uncategorized: number;
selected_categories?: CategoryEntity[];
graph_type: string;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/2684.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [carkom]
---

Option to add/remove current interval to "live" ranges
Loading