From 106dce25dd85b7574c35ba43b1d6c85799543252 Mon Sep 17 00:00:00 2001
From: Neil <55785687+carkom@users.noreply.github.com>
Date: Thu, 18 Jan 2024 22:39:42 +0000
Subject: [PATCH] Custom Reports update entites (#2244)

* work

* notes

* missing entity

* lint
---
 .../src/components/reports/ChooseGraph.tsx    |  8 +++--
 .../src/components/reports/ReportSummary.tsx  |  5 ++-
 .../components/reports/graphs/AreaGraph.tsx   |  4 +--
 .../components/reports/graphs/BarGraph.tsx    |  4 +--
 .../components/reports/graphs/DonutGraph.tsx  |  4 +--
 .../reports/graphs/StackedBarGraph.tsx        |  4 +--
 .../reports/graphs/tableGraph/ReportTable.tsx |  5 +--
 .../graphs/tableGraph/ReportTableHeader.tsx   |  5 +--
 .../graphs/tableGraph/ReportTableList.tsx     |  5 +--
 .../graphs/tableGraph/ReportTableRow.tsx      |  4 +--
 .../graphs/tableGraph/ReportTableTotals.tsx   |  4 +--
 .../reports/spreadsheets/calculateLegend.ts   |  6 +++-
 .../loot-core/src/types/models/index.d.ts     |  1 +
 .../src/types/models/reports.d.ts}            | 36 +++++++++++++++----
 upcoming-release-notes/2244.md                |  6 ++++
 15 files changed, 70 insertions(+), 31 deletions(-)
 rename packages/{desktop-client/src/components/reports/entities.d.ts => loot-core/src/types/models/reports.d.ts} (51%)
 create mode 100644 upcoming-release-notes/2244.md

diff --git a/packages/desktop-client/src/components/reports/ChooseGraph.tsx b/packages/desktop-client/src/components/reports/ChooseGraph.tsx
index 2019433b4..2188d075c 100644
--- a/packages/desktop-client/src/components/reports/ChooseGraph.tsx
+++ b/packages/desktop-client/src/components/reports/ChooseGraph.tsx
@@ -1,9 +1,13 @@
 // @ts-strict-ignore
 import React, { useRef } from 'react';
 
+import {
+  type GroupedEntity,
+  type Month,
+} from 'loot-core/src/types/models/reports';
+
 import { View } from '../common/View';
 
-import { type DataEntity, type Month } from './entities';
 import { AreaGraph } from './graphs/AreaGraph';
 import { BarGraph } from './graphs/BarGraph';
 import { BarLineGraph } from './graphs/BarLineGraph';
@@ -16,7 +20,7 @@ import { ReportTableTotals } from './graphs/tableGraph/ReportTableTotals';
 import { ReportOptions } from './ReportOptions';
 
 type ChooseGraphProps = {
-  data: DataEntity;
+  data: GroupedEntity;
   mode: string;
   graphType: string;
   balanceType: string;
diff --git a/packages/desktop-client/src/components/reports/ReportSummary.tsx b/packages/desktop-client/src/components/reports/ReportSummary.tsx
index 2ded9f97d..a8dac85fb 100644
--- a/packages/desktop-client/src/components/reports/ReportSummary.tsx
+++ b/packages/desktop-client/src/components/reports/ReportSummary.tsx
@@ -7,18 +7,17 @@ import {
   integerToCurrency,
   amountToInteger,
 } from 'loot-core/src/shared/util';
+import { type GroupedEntity } from 'loot-core/src/types/models/reports';
 
 import { theme, styles } from '../../style';
 import { Text } from '../common/Text';
 import { View } from '../common/View';
 import { PrivacyFilter } from '../PrivacyFilter';
 
-import { type DataEntity } from './entities';
-
 type ReportSummaryProps = {
   startDate: string;
   endDate: string;
-  data: DataEntity;
+  data: GroupedEntity;
   balanceTypeOp: string;
   monthsCount: number;
 };
diff --git a/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx b/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx
index 6ad6aeede..26faf6cd8 100644
--- a/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/AreaGraph.tsx
@@ -18,13 +18,13 @@ import {
   amountToCurrency,
   amountToCurrencyNoDecimal,
 } from 'loot-core/src/shared/util';
+import { type GroupedEntity } from 'loot-core/src/types/models/reports';
 
 import { theme } from '../../../style';
 import { type CSSProperties } from '../../../style';
 import { AlignedText } from '../../common/AlignedText';
 import { PrivacyFilter } from '../../PrivacyFilter';
 import { Container } from '../Container';
-import { type DataEntity } from '../entities';
 import { numberFormatterTooltip } from '../numberFormatter';
 
 import { adjustTextSize } from './adjustTextSize';
@@ -114,7 +114,7 @@ const customLabel = (props, width, end) => {
 
 type AreaGraphProps = {
   style?: CSSProperties;
-  data: DataEntity;
+  data: GroupedEntity;
   balanceTypeOp: string;
   compact?: boolean;
   viewLabels: boolean;
diff --git a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
index 02a0c7da9..6f34a07b5 100644
--- a/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
@@ -20,13 +20,13 @@ import {
   amountToCurrency,
   amountToCurrencyNoDecimal,
 } from 'loot-core/src/shared/util';
+import { type GroupedEntity } from 'loot-core/src/types/models/reports';
 
 import { theme } from '../../../style';
 import { type CSSProperties } from '../../../style';
 import { AlignedText } from '../../common/AlignedText';
 import { PrivacyFilter } from '../../PrivacyFilter';
 import { Container } from '../Container';
-import { type DataEntity } from '../entities';
 import { getCustomTick } from '../getCustomTick';
 import { numberFormatterTooltip } from '../numberFormatter';
 
@@ -127,7 +127,7 @@ const customLabel = props => {
 
 type BarGraphProps = {
   style?: CSSProperties;
-  data: DataEntity;
+  data: GroupedEntity;
   groupBy: string;
   balanceTypeOp: string;
   compact?: boolean;
diff --git a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
index 0892c5691..e7c70c88b 100644
--- a/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/DonutGraph.tsx
@@ -4,10 +4,10 @@ import React, { useState } from 'react';
 import { PieChart, Pie, Cell, Sector, ResponsiveContainer } from 'recharts';
 
 import { amountToCurrency } from 'loot-core/src/shared/util';
+import { type GroupedEntity } from 'loot-core/src/types/models/reports';
 
 import { theme, type CSSProperties } from '../../../style';
 import { Container } from '../Container';
-import { type DataEntity } from '../entities';
 
 import { adjustTextSize } from './adjustTextSize';
 import { renderCustomLabel } from './renderCustomLabel';
@@ -118,7 +118,7 @@ const customLabel = props => {
 
 type DonutGraphProps = {
   style?: CSSProperties;
-  data: DataEntity;
+  data: GroupedEntity;
   groupBy: string;
   balanceTypeOp: string;
   compact?: boolean;
diff --git a/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx b/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx
index 3cace4e4d..683969f3c 100644
--- a/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/StackedBarGraph.tsx
@@ -18,13 +18,13 @@ import {
   amountToCurrency,
   amountToCurrencyNoDecimal,
 } from 'loot-core/src/shared/util';
+import { type GroupedEntity } from 'loot-core/src/types/models/reports';
 
 import { theme } from '../../../style';
 import { type CSSProperties } from '../../../style';
 import { AlignedText } from '../../common/AlignedText';
 import { PrivacyFilter } from '../../PrivacyFilter';
 import { Container } from '../Container';
-import { type DataEntity } from '../entities';
 import { getCustomTick } from '../getCustomTick';
 import { numberFormatterTooltip } from '../numberFormatter';
 
@@ -122,7 +122,7 @@ const customLabel = props => {
 
 type StackedBarGraphProps = {
   style?: CSSProperties;
-  data: DataEntity;
+  data: GroupedEntity;
   compact?: boolean;
   viewLabels: boolean;
 };
diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTable.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTable.tsx
index d087bea38..b7f34e1f0 100644
--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTable.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTable.tsx
@@ -7,10 +7,11 @@ import React, {
 } from 'react';
 import { type RefProp } from 'react-spring';
 
+import { type DataEntity } from 'loot-core/src/types/models/reports';
+
 import { type CSSProperties } from '../../../../style';
 import { Block } from '../../../common/Block';
 import { View } from '../../../common/View';
-import { type GroupedEntity } from '../../entities';
 
 import { ReportTableList } from './ReportTableList';
 import { ReportTableRow } from './ReportTableRow';
@@ -22,7 +23,7 @@ type ReportTableProps = {
   style?: CSSProperties;
   groupBy: string;
   balanceTypeOp: 'totalDebts' | 'totalTotals' | 'totalAssets';
-  data: GroupedEntity[];
+  data: DataEntity[];
   mode: string;
   monthsCount: number;
 };
diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableHeader.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableHeader.tsx
index 5a16c916b..3abe20775 100644
--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableHeader.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableHeader.tsx
@@ -2,15 +2,16 @@
 import React, { type UIEventHandler } from 'react';
 import { type RefProp } from 'react-spring';
 
+import { type DataEntity } from 'loot-core/src/types/models/reports';
+
 import { styles, theme } from '../../../../style';
 import { View } from '../../../common/View';
 import { Row, Cell } from '../../../table';
-import { type GroupedEntity } from '../../entities';
 
 type ReportTableHeaderProps = {
   scrollWidth?: number;
   groupBy: string;
-  interval?: GroupedEntity[];
+  interval?: DataEntity[];
   balanceType: string;
   headerScrollRef: RefProp<HTMLDivElement>;
   handleScroll: UIEventHandler<HTMLDivElement>;
diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.tsx
index 8d27ccfeb..ec462b611 100644
--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableList.tsx
@@ -1,13 +1,14 @@
 // @ts-strict-ignore
 import React from 'react';
 
+import { type DataEntity } from 'loot-core/src/types/models/reports';
+
 import { type CSSProperties, theme } from '../../../../style';
 import { View } from '../../../common/View';
 import { Cell, Row } from '../../../table';
-import { type GroupedEntity } from '../../entities';
 
 type ReportTableListProps = {
-  data: GroupedEntity[];
+  data: DataEntity[];
   mode?: string;
   monthsCount?: number;
   groupBy: string;
diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx
index 63c275a6e..adf237c47 100644
--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableRow.tsx
@@ -5,13 +5,13 @@ import {
   amountToInteger,
   integerToCurrency,
 } from 'loot-core/src/shared/util';
+import { type DataEntity } from 'loot-core/src/types/models/reports';
 
 import { type CSSProperties, styles, theme } from '../../../../style';
 import { Row, Cell } from '../../../table';
-import { type GroupedEntity } from '../../entities';
 
 type ReportTableRowProps = {
-  item: GroupedEntity;
+  item: DataEntity;
   balanceTypeOp: 'totalAssets' | 'totalDebts' | 'totalTotals';
   groupByItem: 'id' | 'name';
   mode: string;
diff --git a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableTotals.tsx b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableTotals.tsx
index 5b3962025..79e895838 100644
--- a/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableTotals.tsx
+++ b/packages/desktop-client/src/components/reports/graphs/tableGraph/ReportTableTotals.tsx
@@ -7,14 +7,14 @@ import {
   amountToInteger,
   integerToCurrency,
 } from 'loot-core/src/shared/util';
+import { type GroupedEntity } from 'loot-core/src/types/models/reports';
 
 import { styles, theme } from '../../../../style';
 import { View } from '../../../common/View';
 import { Row, Cell } from '../../../table';
-import { type DataEntity } from '../../entities';
 
 type ReportTableTotalsProps = {
-  data: DataEntity;
+  data: GroupedEntity;
   scrollWidth?: number;
   balanceTypeOp: string;
   mode: string;
diff --git a/packages/desktop-client/src/components/reports/spreadsheets/calculateLegend.ts b/packages/desktop-client/src/components/reports/spreadsheets/calculateLegend.ts
index b0acf116a..aacda9799 100644
--- a/packages/desktop-client/src/components/reports/spreadsheets/calculateLegend.ts
+++ b/packages/desktop-client/src/components/reports/spreadsheets/calculateLegend.ts
@@ -1,7 +1,11 @@
 // @ts-strict-ignore
+import {
+  type ItemEntity,
+  type MonthData,
+} from 'loot-core/src/types/models/reports';
+
 import { theme } from '../../../style';
 import { getColorScale } from '../chart-theme';
-import { type ItemEntity, type MonthData } from '../entities';
 
 export function calculateLegend(
   monthData: MonthData[],
diff --git a/packages/loot-core/src/types/models/index.d.ts b/packages/loot-core/src/types/models/index.d.ts
index cceded549..307dac6b6 100644
--- a/packages/loot-core/src/types/models/index.d.ts
+++ b/packages/loot-core/src/types/models/index.d.ts
@@ -3,6 +3,7 @@ export type * from './category';
 export type * from './category-group';
 export type * from './gocardless';
 export type * from './payee';
+export type * from './reports';
 export type * from './rule';
 export type * from './schedule';
 export type * from './transaction';
diff --git a/packages/desktop-client/src/components/reports/entities.d.ts b/packages/loot-core/src/types/models/reports.d.ts
similarity index 51%
rename from packages/desktop-client/src/components/reports/entities.d.ts
rename to packages/loot-core/src/types/models/reports.d.ts
index 753ec938a..7d15406b0 100644
--- a/packages/desktop-client/src/components/reports/entities.d.ts
+++ b/packages/loot-core/src/types/models/reports.d.ts
@@ -1,14 +1,36 @@
-export type DataEntity = {
-  data: GroupedEntity[];
-  monthData: GroupedEntity[];
-  groupedData: GroupedEntity[];
+import { type RuleConditionEntity } from './rule';
+
+export interface CustomReportEntity {
+  reportId?: string;
+  mode: string;
+  groupBy: string;
+  balanceType: string;
+  showEmpty: boolean;
+  showOffBudgetHidden: boolean;
+  showUncategorized: boolean;
+  graphType: string;
+  selectedCategories;
+  filters: RuleConditionEntity;
+  conditionsOp: string;
+  name: string;
+  startDate: string;
+  endDate: string;
+  isDateStatic: boolean;
+  data: GroupedEntity;
+  tombstone?: boolean;
+}
+
+export interface GroupedEntity {
+  data: DataEntity[];
+  monthData: DataEntity[];
+  groupedData: DataEntity[];
   legend: LegendEntity[];
   startDate: string;
   endDate: string;
   totalDebts: number;
   totalAssets: number;
   totalTotals: number;
-};
+}
 
 type LegendEntity = {
   name: string;
@@ -31,7 +53,7 @@ export type MonthData = {
   totalTotals: number;
 };
 
-export type GroupedEntity = {
+export interface DataEntity {
   id: string;
   name: string;
   date?: string;
@@ -40,7 +62,7 @@ export type GroupedEntity = {
   totalAssets: number;
   totalDebts: number;
   totalTotals: number;
-};
+}
 
 export type Month = {
   month: string;
diff --git a/upcoming-release-notes/2244.md b/upcoming-release-notes/2244.md
new file mode 100644
index 000000000..cd2905e18
--- /dev/null
+++ b/upcoming-release-notes/2244.md
@@ -0,0 +1,6 @@
+---
+category: Maintenance
+authors: [carkom]
+---
+
+Moving entities and updating existing for custom reports. Also creating a new entity for the custom report data.
-- 
GitLab