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

report sorting on dashboard #4276

Merged
merged 8 commits into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
type CategoryEntity,
type CategoryGroupEntity,
type PayeeEntity,
type sortByOpType,
} from 'loot-core/src/types/models';

const startDate = monthUtils.subMonths(monthUtils.currentMonth(), 5) + '-01';
Expand All @@ -23,7 +24,7 @@ export const defaultReport: CustomReportEntity = {
groupBy: 'Category',
interval: 'Monthly',
balanceType: 'Payment',
sortBy: 'Descending',
sortBy: 'desc',
showEmpty: false,
showOffBudget: false,
showHiddenCategories: false,
Expand All @@ -50,7 +51,10 @@ const groupByOptions = [
{ description: 'Interval' },
];

const sortByOptions = [
const sortByOptions: {
description: string;
format: sortByOpType;
}[] = [
{ description: t('Ascending'), format: 'asc' as const },
{ description: t('Descending'), format: 'desc' as const },
{ description: t('Name'), format: 'name' as const },
Expand Down
14 changes: 9 additions & 5 deletions packages/desktop-client/src/components/reports/ReportSidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import * as monthUtils from 'loot-core/src/shared/months';
import { type CategoryEntity } from 'loot-core/types/models/category';
import { type CategoryGroupEntity } from 'loot-core/types/models/category-group';
import { type TimeFrame } from 'loot-core/types/models/dashboard';
import { type CustomReportEntity } from 'loot-core/types/models/reports';
import {
type CustomReportEntity,
type sortByOpType,
} from 'loot-core/types/models/reports';
import { type SyncedPrefs } from 'loot-core/types/prefs';

import { styles } from '../../style/styles';
Expand Down Expand Up @@ -143,7 +146,8 @@ export function ReportSidebar({
setBalanceType(cond);
};

const onChangeSortBy = (cond: string) => {
const onChangeSortBy = (cond?: sortByOpType) => {
cond ??= 'desc';
setSessionReport('sortBy', cond);
onReportChange({ type: 'modify' });
setSortBy(cond);
Expand Down Expand Up @@ -297,12 +301,12 @@ export function ReportSidebar({
</Text>
<Select
value={customReportItems.sortBy}
onChange={e => onChangeSortBy(e)}
onChange={(e?: sortByOpType) => onChangeSortBy(e)}
options={ReportOptions.sortBy.map(option => [
option.description,
option.format,
option.description,
])}
disabledKeys={disabledItems('sort')}
disabledKeys={disabledItems('sort') as sortByOpType[]}
/>
</View>
)}
Expand Down
18 changes: 10 additions & 8 deletions packages/desktop-client/src/components/reports/disabledList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { t } from 'i18next';

import { type sortByOpType } from 'loot-core/types/models';

const intervalOptions = [
{
description: t('Daily'),
Expand Down Expand Up @@ -48,7 +50,7 @@ type graphOptions = {
defaultSplit: string;
disabledType: string[];
defaultType: string;
defaultSort: string;
defaultSort: sortByOpType;
disableLegend?: boolean;
disableLabel?: boolean;
disableSort?: boolean;
Expand All @@ -62,15 +64,15 @@ const totalGraphOptions: graphOptions[] = [
defaultType: 'Payment',
disableLegend: true,
disableLabel: true,
defaultSort: 'Budget',
defaultSort: 'budget',
},
{
description: 'BarGraph',
disabledSplit: [],
defaultSplit: 'Category',
disabledType: [],
defaultType: 'Payment',
defaultSort: 'Descending',
defaultSort: 'desc',
},
{
description: 'AreaGraph',
Expand All @@ -80,15 +82,15 @@ const totalGraphOptions: graphOptions[] = [
defaultType: 'Payment',
disableLegend: true,
disableSort: true,
defaultSort: 'Descending',
defaultSort: 'desc',
},
{
description: 'DonutGraph',
disabledSplit: [],
defaultSplit: 'Category',
disabledType: ['Net'],
defaultType: 'Payment',
defaultSort: 'Descending',
defaultSort: 'desc',
},
];

Expand All @@ -102,7 +104,7 @@ const timeGraphOptions: graphOptions[] = [
disableLegend: true,
disableLabel: true,
disableSort: true,
defaultSort: 'Descending',
defaultSort: 'desc',
},
{
description: 'StackedBarGraph',
Expand All @@ -111,7 +113,7 @@ const timeGraphOptions: graphOptions[] = [
disabledType: [],
defaultType: 'Payment',
disableSort: true,
defaultSort: 'Descending',
defaultSort: 'desc',
},
{
description: 'LineGraph',
Expand All @@ -122,7 +124,7 @@ const timeGraphOptions: graphOptions[] = [
disableLegend: false,
disableLabel: true,
disableSort: true,
defaultSort: 'Descending',
defaultSort: 'desc',
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ function CustomReportInner({ report: initialReport }: CustomReportInnerProps) {

const balanceTypeOp: balanceTypeOpType =
ReportOptions.balanceTypeMap.get(balanceType) || 'totalDebts';
const sortByOp: sortByOpType = ReportOptions.sortByMap.get(sortBy) || 'desc';
const sortByOp: sortByOpType = sortBy || 'desc';
const payees = usePayees();
const accounts = useAccounts();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export function GetCardData({
showUncategorized: report.showUncategorized,
balanceTypeOp: ReportOptions.balanceTypeMap.get(report.balanceType),
firstDayOfWeekIdx,
sortByOp: report.sortBy,
});
}, [report, categories, startDate, endDate, firstDayOfWeekIdx]);
const getGraphData = useMemo(() => {
Expand All @@ -149,6 +150,7 @@ export function GetCardData({
accounts,
graphType: report.graphType,
firstDayOfWeekIdx,
sortByOp: report.sortBy,
});
}, [
report,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BEGIN TRANSACTION;

ALTER TABLE custom_reports ALTER COLUMN sort_by set DEFAULT 'desc';
UPDATE custom_reports SET sort_by = 'desc' where sort_by = 'Descending';
UPDATE custom_reports SET sort_by = 'asc' where sort_by = 'Ascending';
UPDATE custom_reports SET sort_by = 'budget' where sort_by = 'Budget';
UPDATE custom_reports SET sort_by = 'name' where sort_by = 'Name';

COMMIT;
2 changes: 1 addition & 1 deletion packages/loot-core/src/types/models/reports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface CustomReportEntity {
groupBy: string;
interval: string;
balanceType: string;
sortBy: string;
sortBy?: sortByOpType;
showEmpty: boolean;
showOffBudget: boolean;
showHiddenCategories: boolean;
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/4276.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [UnderKoen]
---

Show sorting of reports on the dashboard
Loading