From 579cfea021a5ba32effb7bcde5c8ce47a3ab8038 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sat, 2 Dec 2023 15:10:20 -0500 Subject: [PATCH 01/25] change file type to ts --- .../desktop-client/src/components/reports/{util.js => util.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename packages/desktop-client/src/components/reports/{util.js => util.ts} (100%) diff --git a/packages/desktop-client/src/components/reports/util.js b/packages/desktop-client/src/components/reports/util.ts similarity index 100% rename from packages/desktop-client/src/components/reports/util.js rename to packages/desktop-client/src/components/reports/util.ts From f6b151f561d95a2b30cd64ef5c243d7ad0f2e4ac Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sat, 2 Dec 2023 15:25:37 -0500 Subject: [PATCH 02/25] added types to fromDateRepr, runAll and index functions --- packages/desktop-client/src/components/reports/util.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index b3cb72c85ad..ca3e29b3cbc 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -1,10 +1,10 @@ import { runQuery } from 'loot-core/src/client/query-helpers'; -export function fromDateRepr(date) { +export function fromDateRepr(date: string): string { return date.slice(0, 7); } -export async function runAll(queries, cb) { +export async function runAll(queries: any[], cb: (data: any[]) => void): Promise { let data = await Promise.all( queries.map(q => { return runQuery(q).then(({ data }) => data); @@ -13,7 +13,7 @@ export async function runAll(queries, cb) { cb(data); } -export function index(data, field, mapper) { +export function index(data: any[], field: string, mapper?: (input: any) => any): { [key: string]: any } { const result = {}; data.forEach(item => { result[mapper ? mapper(item[field]) : item[field]] = item; From 30316d6a739bce80d15a29ca7bc75ad625fc6415 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sat, 2 Dec 2023 15:29:04 -0500 Subject: [PATCH 03/25] added types to indexStack and indexCashFlow --- packages/desktop-client/src/components/reports/util.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index ca3e29b3cbc..67edfa8f1f6 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -14,23 +14,23 @@ export async function runAll(queries: any[], cb: (data: any[]) => void): Promise } export function index(data: any[], field: string, mapper?: (input: any) => any): { [key: string]: any } { - const result = {}; + const result: { [key: string]: any } = {}; data.forEach(item => { result[mapper ? mapper(item[field]) : item[field]] = item; }); return result; } -export function indexStack(data, fieldName, field) { - const result = {}; +export function indexStack(data: any[], fieldName: string, field: string): { [key: string]: any } { + const result: { [key: string]: any } = {}; data.forEach(item => { result[item[fieldName]] = item[field]; }); return result; } -export function indexCashFlow(data, date, isTransfer) { - const results = {}; +export function indexCashFlow(data: any[], date: string, isTransfer: string): { [key: string]: any } { + const results: { [key: string]: any } = {}; data.forEach(item => { let findExisting = results[item.date] ? results[item.date][item.isTransfer] From 1128b0e4008354d66777032431983e7753705bd6 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sat, 2 Dec 2023 15:49:39 -0500 Subject: [PATCH 04/25] added release note file --- upcoming-release-notes/2009.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 upcoming-release-notes/2009.md diff --git a/upcoming-release-notes/2009.md b/upcoming-release-notes/2009.md new file mode 100644 index 00000000000..43b60f981d9 --- /dev/null +++ b/upcoming-release-notes/2009.md @@ -0,0 +1,6 @@ +--- +category: Maintenance +authors: [ghosetuhin] +--- + +Migrating the util.js and chartTheme.js files to typescript \ No newline at end of file From 9b134c2acf260a5feefe36fe69a14380cd2edb88 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sat, 2 Dec 2023 15:55:11 -0500 Subject: [PATCH 05/25] ran prettier --- .../src/components/reports/util.ts | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index 67edfa8f1f6..edf4dbfdb82 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -4,7 +4,10 @@ export function fromDateRepr(date: string): string { return date.slice(0, 7); } -export async function runAll(queries: any[], cb: (data: any[]) => void): Promise { +export async function runAll( + queries: any[], + cb: (data: any[]) => void, +): Promise { let data = await Promise.all( queries.map(q => { return runQuery(q).then(({ data }) => data); @@ -13,7 +16,11 @@ export async function runAll(queries: any[], cb: (data: any[]) => void): Promise cb(data); } -export function index(data: any[], field: string, mapper?: (input: any) => any): { [key: string]: any } { +export function index( + data: any[], + field: string, + mapper?: (input: any) => any, +): { [key: string]: any } { const result: { [key: string]: any } = {}; data.forEach(item => { result[mapper ? mapper(item[field]) : item[field]] = item; @@ -21,7 +28,11 @@ export function index(data: any[], field: string, mapper?: (input: any) => any): return result; } -export function indexStack(data: any[], fieldName: string, field: string): { [key: string]: any } { +export function indexStack( + data: any[], + fieldName: string, + field: string, +): { [key: string]: any } { const result: { [key: string]: any } = {}; data.forEach(item => { result[item[fieldName]] = item[field]; @@ -29,7 +40,11 @@ export function indexStack(data: any[], fieldName: string, field: string): { [ke return result; } -export function indexCashFlow(data: any[], date: string, isTransfer: string): { [key: string]: any } { +export function indexCashFlow( + data: any[], + date: string, + isTransfer: string, +): { [key: string]: any } { const results: { [key: string]: any } = {}; data.forEach(item => { let findExisting = results[item.date] From 7aa57f40ef59bdec28000c29ad7b9c6eca11514b Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sat, 2 Dec 2023 16:08:18 -0500 Subject: [PATCH 06/25] fixed lint errors --- .../src/components/reports/util.ts | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index edf4dbfdb82..e0ba6de61e9 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -1,12 +1,13 @@ import { runQuery } from 'loot-core/src/client/query-helpers'; +import { Query } from 'loot-core/src/shared/query'; export function fromDateRepr(date: string): string { return date.slice(0, 7); } export async function runAll( - queries: any[], - cb: (data: any[]) => void, + queries: Query[], + cb: (data) => void, ): Promise { let data = await Promise.all( queries.map(q => { @@ -16,36 +17,24 @@ export async function runAll( cb(data); } -export function index( - data: any[], - field: string, - mapper?: (input: any) => any, -): { [key: string]: any } { - const result: { [key: string]: any } = {}; +export function index(data, field: string, mapper?: (input) => any) { + const result = {}; data.forEach(item => { result[mapper ? mapper(item[field]) : item[field]] = item; }); return result; } -export function indexStack( - data: any[], - fieldName: string, - field: string, -): { [key: string]: any } { - const result: { [key: string]: any } = {}; +export function indexStack(data, fieldName: string, field: string) { + const result = {}; data.forEach(item => { result[item[fieldName]] = item[field]; }); return result; } -export function indexCashFlow( - data: any[], - date: string, - isTransfer: string, -): { [key: string]: any } { - const results: { [key: string]: any } = {}; +export function indexCashFlow(data, date: string, isTransfer: string) { + const results = {}; data.forEach(item => { let findExisting = results[item.date] ? results[item.date][item.isTransfer] From 5f0eea48b602e377083d718cf7b64913c2f7a21f Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sat, 2 Dec 2023 16:13:10 -0500 Subject: [PATCH 07/25] fixed remaining lint errors --- packages/desktop-client/src/components/reports/util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index e0ba6de61e9..f0ff9652d5e 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -1,5 +1,5 @@ import { runQuery } from 'loot-core/src/client/query-helpers'; -import { Query } from 'loot-core/src/shared/query'; +import type { Query } from 'loot-core/src/shared/query'; export function fromDateRepr(date: string): string { return date.slice(0, 7); @@ -17,7 +17,7 @@ export async function runAll( cb(data); } -export function index(data, field: string, mapper?: (input) => any) { +export function index(data, field: string, mapper?: (input) => unknown) { const result = {}; data.forEach(item => { result[mapper ? mapper(item[field]) : item[field]] = item; From b131597931cd7117c6e0200935076a9bf8a217de Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sun, 3 Dec 2023 18:41:04 -0500 Subject: [PATCH 08/25] added ColorFades interface --- .../reports/{chart-theme.js => chart-theme.ts} | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) rename packages/desktop-client/src/components/reports/{chart-theme.js => chart-theme.ts} (95%) diff --git a/packages/desktop-client/src/components/reports/chart-theme.js b/packages/desktop-client/src/components/reports/chart-theme.ts similarity index 95% rename from packages/desktop-client/src/components/reports/chart-theme.js rename to packages/desktop-client/src/components/reports/chart-theme.ts index 140b1c63d2a..d720f3b3ac8 100644 --- a/packages/desktop-client/src/components/reports/chart-theme.js +++ b/packages/desktop-client/src/components/reports/chart-theme.ts @@ -1,6 +1,13 @@ import { theme } from '../../style'; -let colorFades = { +interface ColorFades { + blueFadeStart: string; + blueFadeEnd: string; + redFadeStart: string; + redFadeEnd: string; +} + +let colorFades: ColorFades = { blueFadeStart: 'rgba(229, 245, 255, 1)', blueFadeEnd: 'rgba(229, 245, 255, 0)', redFadeStart: 'rgba(255, 243, 242, 1)', From 67bbd71a2c37cd5dcff3fd5116ce7bfff340d33a Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sun, 3 Dec 2023 18:42:58 -0500 Subject: [PATCH 09/25] added LabelStyles interface --- .../src/components/reports/chart-theme.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/desktop-client/src/components/reports/chart-theme.ts b/packages/desktop-client/src/components/reports/chart-theme.ts index d720f3b3ac8..5b490ecbbbd 100644 --- a/packages/desktop-client/src/components/reports/chart-theme.ts +++ b/packages/desktop-client/src/components/reports/chart-theme.ts @@ -15,13 +15,21 @@ let colorFades: ColorFades = { }; // Typography -const sansSerif = +const sansSerif: string = 'Inter var, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, Helvetica, Arial, sans-serif'; -const letterSpacing = 'normal'; -const fontSize = 13; +const letterSpacing: string = 'normal'; +const fontSize: number = 13; // Labels -const baseLabelStyles = { +interface LabelStyles { + fontFamily: string; + fontSize: number; + letterSpacing: string; + fill: string; + stroke: string; +} + +const baseLabelStyles: LabelStyles = { fontFamily: sansSerif, fontSize, letterSpacing, From 0e4156a360ee279cf5c1c7f1693aba548e5fb7e1 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sun, 3 Dec 2023 18:54:29 -0500 Subject: [PATCH 10/25] added interface for AxisBaseStyle and ChartTheme --- .../src/components/reports/chart-theme.ts | 100 +++++++++++++++++- 1 file changed, 97 insertions(+), 3 deletions(-) diff --git a/packages/desktop-client/src/components/reports/chart-theme.ts b/packages/desktop-client/src/components/reports/chart-theme.ts index 5b490ecbbbd..10458bc480a 100644 --- a/packages/desktop-client/src/components/reports/chart-theme.ts +++ b/packages/desktop-client/src/components/reports/chart-theme.ts @@ -37,7 +37,26 @@ const baseLabelStyles: LabelStyles = { stroke: 'transparent', }; -const axisBaseStyles = { +interface AxisBaseStyles { + axis: { + fill: string; + stroke: string; + }; + grid: { + fill: string; + stroke: string; + pointerEvents: string; + }; + ticks: { + fill: string; + size: number; + stroke: string; + }; + axisLabel: LabelStyles; + tickLabels: LabelStyles; +} + +const axisBaseStyles: AxisBaseStyles = { axis: { fill: 'transparent', stroke: 'none', @@ -56,7 +75,82 @@ const axisBaseStyles = { tickLabels: baseLabelStyles, }; -export const chartTheme = { +interface ChartTheme { + colors: { + [key: string]: string; + }; + area: { + style: { + labels: LabelStyles; + data: { + stroke: string; + strokeWidth: number; + strokeLinejoin: string; + strokeLinecap: string; + }; + }; + }; + axis: { + style: AxisBaseStyles; + }; + dependentAxis: { + style: { + grid: { + stroke: string; + strokeDasharray: string; + }; + tickLabels: { + padding: number; + }; + }; + }; + independentAxis: { + style: { + axis: { + stroke: string; + }; + tickLabels: { + padding: number; + }; + }; + }; + bar: { + style: { + labels: LabelStyles; + data: { + fill: string; + stroke: string; + }; + }; + }; + line: { + style: { + labels: LabelStyles; + data: { + fill: string; + stroke: string; + strokeWidth: number; + strokeLinejoin: string; + strokeLinecap: string; + }; + }; + }; + voronoi: { + style: { + labels: LabelStyles; + }; + }; + chart: { + padding: { + top: number; + left: number; + right: number; + bottom: number; + }; + }; +} + +export const chartTheme: ChartTheme = { colors: { ...colorFades, red: theme.reportsRed, @@ -127,7 +221,7 @@ export const chartTheme = { }, }; -export function getColorScale(name) { +export function getColorScale(name: string) { const scales = { grayscale: ['#cccccc', '#969696', '#636363', '#252525'], qualitative: [ From 6dfadbb44be1a41e116feba1ce926bb27b71a9a2 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sun, 3 Dec 2023 18:56:25 -0500 Subject: [PATCH 11/25] added types to getColorScale --- .../desktop-client/src/components/reports/chart-theme.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/desktop-client/src/components/reports/chart-theme.ts b/packages/desktop-client/src/components/reports/chart-theme.ts index 10458bc480a..dfad378cfb3 100644 --- a/packages/desktop-client/src/components/reports/chart-theme.ts +++ b/packages/desktop-client/src/components/reports/chart-theme.ts @@ -221,8 +221,12 @@ export const chartTheme: ChartTheme = { }, }; -export function getColorScale(name: string) { - const scales = { +interface ColorScales { + [key: string]: string[]; +}; + +export function getColorScale(name: string): string[] { + const scales: ColorScales = { grayscale: ['#cccccc', '#969696', '#636363', '#252525'], qualitative: [ '#45B29D', //Dark Teal From 5cc8e4d0fa56ff3bd467ab55449fb006e181ee2c Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sun, 3 Dec 2023 19:00:27 -0500 Subject: [PATCH 12/25] fixed lint error by changing interface to type --- .../src/components/reports/chart-theme.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/desktop-client/src/components/reports/chart-theme.ts b/packages/desktop-client/src/components/reports/chart-theme.ts index dfad378cfb3..b7b1fe0a478 100644 --- a/packages/desktop-client/src/components/reports/chart-theme.ts +++ b/packages/desktop-client/src/components/reports/chart-theme.ts @@ -1,6 +1,6 @@ import { theme } from '../../style'; -interface ColorFades { +type ColorFades = { blueFadeStart: string; blueFadeEnd: string; redFadeStart: string; @@ -21,7 +21,7 @@ const letterSpacing: string = 'normal'; const fontSize: number = 13; // Labels -interface LabelStyles { +type LabelStyles = { fontFamily: string; fontSize: number; letterSpacing: string; @@ -37,7 +37,7 @@ const baseLabelStyles: LabelStyles = { stroke: 'transparent', }; -interface AxisBaseStyles { +type AxisBaseStyles = { axis: { fill: string; stroke: string; @@ -75,7 +75,7 @@ const axisBaseStyles: AxisBaseStyles = { tickLabels: baseLabelStyles, }; -interface ChartTheme { +type ChartTheme = { colors: { [key: string]: string; }; @@ -221,7 +221,7 @@ export const chartTheme: ChartTheme = { }, }; -interface ColorScales { +type ColorScales = { [key: string]: string[]; }; From 324e22c695f17de299a090b45fc42cb16e36b35c Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Sun, 3 Dec 2023 19:02:13 -0500 Subject: [PATCH 13/25] fixed remaining lint errors --- .../src/components/reports/chart-theme.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/desktop-client/src/components/reports/chart-theme.ts b/packages/desktop-client/src/components/reports/chart-theme.ts index b7b1fe0a478..b2560fa2b35 100644 --- a/packages/desktop-client/src/components/reports/chart-theme.ts +++ b/packages/desktop-client/src/components/reports/chart-theme.ts @@ -5,7 +5,7 @@ type ColorFades = { blueFadeEnd: string; redFadeStart: string; redFadeEnd: string; -} +}; let colorFades: ColorFades = { blueFadeStart: 'rgba(229, 245, 255, 1)', @@ -15,10 +15,10 @@ let colorFades: ColorFades = { }; // Typography -const sansSerif: string = +const sansSerif = 'Inter var, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, Helvetica, Arial, sans-serif'; -const letterSpacing: string = 'normal'; -const fontSize: number = 13; +const letterSpacing = 'normal'; +const fontSize = 13; // Labels type LabelStyles = { @@ -27,7 +27,7 @@ type LabelStyles = { letterSpacing: string; fill: string; stroke: string; -} +}; const baseLabelStyles: LabelStyles = { fontFamily: sansSerif, @@ -54,7 +54,7 @@ type AxisBaseStyles = { }; axisLabel: LabelStyles; tickLabels: LabelStyles; -} +}; const axisBaseStyles: AxisBaseStyles = { axis: { @@ -148,7 +148,7 @@ type ChartTheme = { bottom: number; }; }; -} +}; export const chartTheme: ChartTheme = { colors: { From 3d14f32a3c17c1714a5856855858f7b83327e3e3 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 14:12:08 -0500 Subject: [PATCH 14/25] incorporated pr review suggestions for chart-theme.js --- .../src/components/reports/chart-theme.ts | 123 +----------------- 1 file changed, 5 insertions(+), 118 deletions(-) diff --git a/packages/desktop-client/src/components/reports/chart-theme.ts b/packages/desktop-client/src/components/reports/chart-theme.ts index b2560fa2b35..80aea4c255e 100644 --- a/packages/desktop-client/src/components/reports/chart-theme.ts +++ b/packages/desktop-client/src/components/reports/chart-theme.ts @@ -1,13 +1,6 @@ import { theme } from '../../style'; -type ColorFades = { - blueFadeStart: string; - blueFadeEnd: string; - redFadeStart: string; - redFadeEnd: string; -}; - -let colorFades: ColorFades = { +let colorFades = { blueFadeStart: 'rgba(229, 245, 255, 1)', blueFadeEnd: 'rgba(229, 245, 255, 0)', redFadeStart: 'rgba(255, 243, 242, 1)', @@ -21,15 +14,7 @@ const letterSpacing = 'normal'; const fontSize = 13; // Labels -type LabelStyles = { - fontFamily: string; - fontSize: number; - letterSpacing: string; - fill: string; - stroke: string; -}; - -const baseLabelStyles: LabelStyles = { +const baseLabelStyles = { fontFamily: sansSerif, fontSize, letterSpacing, @@ -37,26 +22,7 @@ const baseLabelStyles: LabelStyles = { stroke: 'transparent', }; -type AxisBaseStyles = { - axis: { - fill: string; - stroke: string; - }; - grid: { - fill: string; - stroke: string; - pointerEvents: string; - }; - ticks: { - fill: string; - size: number; - stroke: string; - }; - axisLabel: LabelStyles; - tickLabels: LabelStyles; -}; - -const axisBaseStyles: AxisBaseStyles = { +const axisBaseStyles = { axis: { fill: 'transparent', stroke: 'none', @@ -75,82 +41,7 @@ const axisBaseStyles: AxisBaseStyles = { tickLabels: baseLabelStyles, }; -type ChartTheme = { - colors: { - [key: string]: string; - }; - area: { - style: { - labels: LabelStyles; - data: { - stroke: string; - strokeWidth: number; - strokeLinejoin: string; - strokeLinecap: string; - }; - }; - }; - axis: { - style: AxisBaseStyles; - }; - dependentAxis: { - style: { - grid: { - stroke: string; - strokeDasharray: string; - }; - tickLabels: { - padding: number; - }; - }; - }; - independentAxis: { - style: { - axis: { - stroke: string; - }; - tickLabels: { - padding: number; - }; - }; - }; - bar: { - style: { - labels: LabelStyles; - data: { - fill: string; - stroke: string; - }; - }; - }; - line: { - style: { - labels: LabelStyles; - data: { - fill: string; - stroke: string; - strokeWidth: number; - strokeLinejoin: string; - strokeLinecap: string; - }; - }; - }; - voronoi: { - style: { - labels: LabelStyles; - }; - }; - chart: { - padding: { - top: number; - left: number; - right: number; - bottom: number; - }; - }; -}; - -export const chartTheme: ChartTheme = { +export const chartTheme = { colors: { ...colorFades, red: theme.reportsRed, @@ -221,12 +112,8 @@ export const chartTheme: ChartTheme = { }, }; -type ColorScales = { - [key: string]: string[]; -}; - export function getColorScale(name: string): string[] { - const scales: ColorScales = { + const scales: Record = { grayscale: ['#cccccc', '#969696', '#636363', '#252525'], qualitative: [ '#45B29D', //Dark Teal From c696bf3b850829d7a703ffd5b8137f3758f63184 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 14:24:20 -0500 Subject: [PATCH 15/25] implemented suggested change to generics for index and indexStack --- .../desktop-client/src/components/reports/util.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index f0ff9652d5e..10d0fbe3dcf 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -17,18 +17,18 @@ export async function runAll( cb(data); } -export function index(data, field: string, mapper?: (input) => unknown) { - const result = {}; +export function index(data: T[], field: K, mapper?: (input: T[K]) => string) { + const result: { [key: string]: T } = {}; data.forEach(item => { - result[mapper ? mapper(item[field]) : item[field]] = item; + result[mapper ? mapper(item[field]) : item[field] as unknown as string] = item; }); return result; } -export function indexStack(data, fieldName: string, field: string) { - const result = {}; +export function indexStack(data: T[], fieldName: K, field: K) { + const result: { [key: string]: T[K] } = {}; data.forEach(item => { - result[item[fieldName]] = item[field]; + result[item[fieldName] as string] = item[field]; }); return result; } From e394ca5af2a998d3fefbc900699cf1cb284e261c Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 14:51:00 -0500 Subject: [PATCH 16/25] small changes to use record --- .../src/components/reports/util.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index 10d0fbe3dcf..b0e68607890 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -17,16 +17,25 @@ export async function runAll( cb(data); } -export function index(data: T[], field: K, mapper?: (input: T[K]) => string) { - const result: { [key: string]: T } = {}; +export function index( + data: T[], + field: K, + mapper?: (input: T[K]) => string, +) { + const result: Record = {} as Record; data.forEach(item => { - result[mapper ? mapper(item[field]) : item[field] as unknown as string] = item; + result[mapper ? mapper(item[field]) : (item[field] as unknown as string)] = + item; }); return result; } -export function indexStack(data: T[], fieldName: K, field: K) { - const result: { [key: string]: T[K] } = {}; +export function indexStack( + data: T[], + fieldName: K, + field: K, +) { + const result: Record = {} as Record; data.forEach(item => { result[item[fieldName] as string] = item[field]; }); From 141bd1290da7017eb723cccc4641f174a38cb3b7 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 15:43:52 -0500 Subject: [PATCH 17/25] tried implementing generics for indexCashFlow --- packages/desktop-client/src/components/reports/util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index b0e68607890..032bb9a041d 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -24,7 +24,7 @@ export function index( ) { const result: Record = {} as Record; data.forEach(item => { - result[mapper ? mapper(item[field]) : (item[field] as unknown as string)] = + result[mapper ? mapper(item[field]) : (item[field] as string)] = item; }); return result; @@ -42,7 +42,7 @@ export function indexStack( return result; } -export function indexCashFlow(data, date: string, isTransfer: string) { +export function indexCashFlow(data, date: K, isTransfer: K) { const results = {}; data.forEach(item => { let findExisting = results[item.date] From 20090ea40d1a3c90f6c773340a9f34ac8934cd54 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 15:46:00 -0500 Subject: [PATCH 18/25] fixed lint erros --- packages/desktop-client/src/components/reports/util.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index 032bb9a041d..a9482d97c56 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -24,8 +24,7 @@ export function index( ) { const result: Record = {} as Record; data.forEach(item => { - result[mapper ? mapper(item[field]) : (item[field] as string)] = - item; + result[mapper ? mapper(item[field]) : (item[field] as string)] = item; }); return result; } @@ -42,7 +41,11 @@ export function indexStack( return result; } -export function indexCashFlow(data, date: K, isTransfer: K) { +export function indexCashFlow( + data, + date: K, + isTransfer: K, +) { const results = {}; data.forEach(item => { let findExisting = results[item.date] From 748ba85a397150741223d617c813cd4ad4e0d682 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 16:08:07 -0500 Subject: [PATCH 19/25] fixed typecheck errors --- packages/desktop-client/src/components/reports/util.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index a9482d97c56..5ec7daa21a3 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -22,7 +22,7 @@ export function index( field: K, mapper?: (input: T[K]) => string, ) { - const result: Record = {} as Record; + const result: Record = {} as Record; data.forEach(item => { result[mapper ? mapper(item[field]) : (item[field] as string)] = item; }); @@ -34,7 +34,7 @@ export function indexStack( fieldName: K, field: K, ) { - const result: Record = {} as Record; + const result: Record = {} as Record; data.forEach(item => { result[item[fieldName] as string] = item[field]; }); From 91dce186764d41675be3ac74725835c530bd59aa Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 16:18:10 -0500 Subject: [PATCH 20/25] tried fixing typecheck errors again --- .../desktop-client/src/components/reports/util.ts | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index 5ec7daa21a3..22d03e840bb 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -22,9 +22,9 @@ export function index( field: K, mapper?: (input: T[K]) => string, ) { - const result: Record = {} as Record; + const result: Record = {}; data.forEach(item => { - result[mapper ? mapper(item[field]) : (item[field] as string)] = item; + result[mapper ? mapper(item[field]) : (item[field] as unknown as string)] = item; }); return result; } @@ -34,18 +34,14 @@ export function indexStack( fieldName: K, field: K, ) { - const result: Record = {} as Record; + const result: Record = {}; data.forEach(item => { - result[item[fieldName] as string] = item[field]; + result[item[fieldName] as unknown as string] = item[field]; }); return result; } -export function indexCashFlow( - data, - date: K, - isTransfer: K, -) { +export function indexCashFlow(data, date, isTransfer) { const results = {}; data.forEach(item => { let findExisting = results[item.date] From 1ae9b7fcdd9a881a03649ceecf758b3ef57e4dfc Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 16:51:52 -0500 Subject: [PATCH 21/25] typecasting to string to avoid issue with never --- .../src/components/reports/util.ts | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index 22d03e840bb..5229e57f8b7 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -17,31 +17,32 @@ export async function runAll( cb(data); } -export function index( +export function index( data: T[], - field: K, - mapper?: (input: T[K]) => string, + field: string, + mapper?: (input) => string, ) { const result: Record = {}; data.forEach(item => { - result[mapper ? mapper(item[field]) : (item[field] as unknown as string)] = item; + const key = mapper ? mapper(item[field]) : (item[field]); + result[key] = item; }); return result; } -export function indexStack( +export function indexStack( data: T[], - fieldName: K, - field: K, + fieldName: string, + field: string, ) { - const result: Record = {}; + const result = {}; data.forEach(item => { - result[item[fieldName] as unknown as string] = item[field]; + result[item[fieldName]] = item[field]; }); return result; } -export function indexCashFlow(data, date, isTransfer) { +export function indexCashFlow(data, date: string, isTransfer: string) { const results = {}; data.forEach(item => { let findExisting = results[item.date] From febc0f83af05b19f65ac9d7004f9bb1c562c77a3 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Mon, 4 Dec 2023 16:55:36 -0500 Subject: [PATCH 22/25] fixed lint errors --- .../desktop-client/src/components/reports/util.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index 5229e57f8b7..0b212f49491 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -17,24 +17,16 @@ export async function runAll( cb(data); } -export function index( - data: T[], - field: string, - mapper?: (input) => string, -) { +export function index(data: T[], field: string, mapper?: (input) => string) { const result: Record = {}; data.forEach(item => { - const key = mapper ? mapper(item[field]) : (item[field]); + const key = mapper ? mapper(item[field]) : item[field]; result[key] = item; }); return result; } -export function indexStack( - data: T[], - fieldName: string, - field: string, -) { +export function indexStack(data: T[], fieldName: string, field: string) { const result = {}; data.forEach(item => { result[item[fieldName]] = item[field]; From 6061adc6d04c082a98d13cc231f329b282c2fe90 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Tue, 5 Dec 2023 17:03:22 -0500 Subject: [PATCH 23/25] implemented suggested changes and converted functions to generics --- .../src/components/reports/util.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index 0b212f49491..4231f0b8711 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -17,24 +17,32 @@ export async function runAll( cb(data); } -export function index(data: T[], field: string, mapper?: (input) => string) { - const result: Record = {}; +export function index< + T extends Record, + K extends keyof T, +>(data: T[], field: K) { + const result: Record = {}; data.forEach(item => { - const key = mapper ? mapper(item[field]) : item[field]; + const key = item[field]; result[key] = item; }); return result; } -export function indexStack(data: T[], fieldName: string, field: string) { - const result = {}; +export function indexStack< + T extends Record, + K extends keyof T, +>(data: T[], fieldName: K, field: K) { + const result: Record = {}; data.forEach(item => { result[item[fieldName]] = item[field]; }); return result; } -export function indexCashFlow(data, date: string, isTransfer: string) { +export function indexCashFlow< + T extends { date: string; isTransfer: boolean; amount: number }, +>(data: T[], date: string, isTransfer: string) { const results = {}; data.forEach(item => { let findExisting = results[item.date] From 4d3ccdbad15da4a7dce0de48c293247a14fc8cab Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Tue, 5 Dec 2023 17:52:32 -0500 Subject: [PATCH 24/25] added chart-theme.js and util.js to resolve merge conflicts --- .../src/components/reports/chart-theme.js | 137 ++++++++++++++++++ .../src/components/reports/util.js | 44 ++++++ 2 files changed, 181 insertions(+) create mode 100644 packages/desktop-client/src/components/reports/chart-theme.js create mode 100644 packages/desktop-client/src/components/reports/util.js diff --git a/packages/desktop-client/src/components/reports/chart-theme.js b/packages/desktop-client/src/components/reports/chart-theme.js new file mode 100644 index 00000000000..f525d3c0cd8 --- /dev/null +++ b/packages/desktop-client/src/components/reports/chart-theme.js @@ -0,0 +1,137 @@ +import { theme } from '../../style'; + +const colorFades = { + blueFadeStart: 'rgba(229, 245, 255, 1)', + blueFadeEnd: 'rgba(229, 245, 255, 0)', + redFadeStart: 'rgba(255, 243, 242, 1)', + redFadeEnd: 'rgba(255, 243, 242, 0)', +}; + +// Typography +const sansSerif = + 'Inter var, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, Helvetica, Arial, sans-serif'; +const letterSpacing = 'normal'; +const fontSize = 13; + +// Labels +const baseLabelStyles = { + fontFamily: sansSerif, + fontSize, + letterSpacing, + fill: theme.reportsLabel, + stroke: 'transparent', +}; + +const axisBaseStyles = { + axis: { + fill: 'transparent', + stroke: 'none', + }, + grid: { + fill: 'none', + stroke: 'none', + pointerEvents: 'none', + }, + ticks: { + fill: 'transparent', + size: 1, + stroke: 'none', + }, + axisLabel: baseLabelStyles, + tickLabels: baseLabelStyles, +}; + +export const chartTheme = { + colors: { + ...colorFades, + red: theme.reportsRed, + blue: theme.reportsBlue, + }, + area: { + style: { + labels: baseLabelStyles, + data: { + stroke: theme.reportsBlue, + strokeWidth: 2, + strokeLinejoin: 'round', + strokeLinecap: 'round', + }, + }, + }, + axis: { + style: axisBaseStyles, + }, + dependentAxis: { + style: { + ...axisBaseStyles, + grid: { + ...axisBaseStyles.grid, + stroke: theme.pageTextSubdued, + strokeDasharray: '1,1', + }, + tickLabels: { ...baseLabelStyles, padding: 5 }, + }, + }, + independentAxis: { + style: { + ...axisBaseStyles, + axis: { ...axisBaseStyles.axis, stroke: theme.pageTextSubdued }, + tickLabels: { ...baseLabelStyles, padding: 10 }, + }, + }, + bar: { + style: { + labels: baseLabelStyles, + data: { fill: theme.reportsBlue, stroke: 'none' }, + }, + }, + line: { + style: { + labels: baseLabelStyles, + data: { + fill: 'none', + stroke: theme.reportsBlue, + strokeWidth: 2, + strokeLinejoin: 'round', + strokeLinecap: 'round', + }, + }, + }, + voronoi: { + style: { + labels: baseLabelStyles, + }, + }, + chart: { + padding: { + top: 20, + left: 65, + right: 20, + bottom: 50, + }, + }, +}; + +export function getColorScale(name) { + const scales = { + grayscale: ['#cccccc', '#969696', '#636363', '#252525'], + qualitative: [ + '#45B29D', //Dark Teal + '#EFC94C', //Yellow + '#E27A3F', //Orange + '#DF5A49', //Light Red + '#5F91B8', //Blue + '#E2A37F', //Peach + '#55DBC1', //Light Teal + '#EFDA97', //Light Yellow + '#DF948A', //Light Red + ], + heatmap: ['#428517', '#77D200', '#D6D305', '#EC8E19', '#C92B05'], + warm: ['#940031', '#C43343', '#DC5429', '#FF821D', '#FFAF55'], + cool: ['#2746B9', '#0B69D4', '#2794DB', '#31BB76', '#60E83B'], + red: ['#FCAE91', '#FB6A4A', '#DE2D26', '#A50F15', '#750B0E'], + blue: ['#002C61', '#004B8F', '#006BC9', '#3795E5', '#65B4F4'], + green: ['#354722', '#466631', '#649146', '#8AB25C', '#A9C97E'], + }; + return name ? scales[name] : scales.grayscale; +} diff --git a/packages/desktop-client/src/components/reports/util.js b/packages/desktop-client/src/components/reports/util.js new file mode 100644 index 00000000000..d6ad29ffa14 --- /dev/null +++ b/packages/desktop-client/src/components/reports/util.js @@ -0,0 +1,44 @@ +import { runQuery } from 'loot-core/src/client/query-helpers'; + +export function fromDateRepr(date) { + return date.slice(0, 7); +} + +export async function runAll(queries, cb) { + const data = await Promise.all( + queries.map(q => { + return runQuery(q).then(({ data }) => data); + }), + ); + cb(data); +} + +export function index(data, field, mapper) { + const result = {}; + data.forEach(item => { + result[mapper ? mapper(item[field]) : item[field]] = item; + }); + return result; +} + +export function indexStack(data, fieldName, field) { + const result = {}; + data.forEach(item => { + result[item[fieldName]] = item[field]; + }); + return result; +} + +export function indexCashFlow(data, date, isTransfer) { + const results = {}; + data.forEach(item => { + const findExisting = results[item.date] + ? results[item.date][item.isTransfer] + ? results[item.date][item.isTransfer] + : 0 + : 0; + const result = { [item[isTransfer]]: item.amount + findExisting }; + results[item[date]] = { ...results[item[date]], ...result }; + }); + return results; +} From 6930cf409e94d5425feb9f0bdd11305e6a22b247 Mon Sep 17 00:00:00 2001 From: Tuhin Ghose Date: Tue, 5 Dec 2023 18:00:07 -0500 Subject: [PATCH 25/25] deleted .js files and fixed lint errors --- .../src/components/reports/chart-theme.js | 137 ------------------ .../src/components/reports/chart-theme.ts | 2 +- .../src/components/reports/util.js | 44 ------ .../src/components/reports/util.ts | 6 +- 4 files changed, 4 insertions(+), 185 deletions(-) delete mode 100644 packages/desktop-client/src/components/reports/chart-theme.js delete mode 100644 packages/desktop-client/src/components/reports/util.js diff --git a/packages/desktop-client/src/components/reports/chart-theme.js b/packages/desktop-client/src/components/reports/chart-theme.js deleted file mode 100644 index f525d3c0cd8..00000000000 --- a/packages/desktop-client/src/components/reports/chart-theme.js +++ /dev/null @@ -1,137 +0,0 @@ -import { theme } from '../../style'; - -const colorFades = { - blueFadeStart: 'rgba(229, 245, 255, 1)', - blueFadeEnd: 'rgba(229, 245, 255, 0)', - redFadeStart: 'rgba(255, 243, 242, 1)', - redFadeEnd: 'rgba(255, 243, 242, 0)', -}; - -// Typography -const sansSerif = - 'Inter var, -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, Fira Sans, Droid Sans, Helvetica Neue, Helvetica, Arial, sans-serif'; -const letterSpacing = 'normal'; -const fontSize = 13; - -// Labels -const baseLabelStyles = { - fontFamily: sansSerif, - fontSize, - letterSpacing, - fill: theme.reportsLabel, - stroke: 'transparent', -}; - -const axisBaseStyles = { - axis: { - fill: 'transparent', - stroke: 'none', - }, - grid: { - fill: 'none', - stroke: 'none', - pointerEvents: 'none', - }, - ticks: { - fill: 'transparent', - size: 1, - stroke: 'none', - }, - axisLabel: baseLabelStyles, - tickLabels: baseLabelStyles, -}; - -export const chartTheme = { - colors: { - ...colorFades, - red: theme.reportsRed, - blue: theme.reportsBlue, - }, - area: { - style: { - labels: baseLabelStyles, - data: { - stroke: theme.reportsBlue, - strokeWidth: 2, - strokeLinejoin: 'round', - strokeLinecap: 'round', - }, - }, - }, - axis: { - style: axisBaseStyles, - }, - dependentAxis: { - style: { - ...axisBaseStyles, - grid: { - ...axisBaseStyles.grid, - stroke: theme.pageTextSubdued, - strokeDasharray: '1,1', - }, - tickLabels: { ...baseLabelStyles, padding: 5 }, - }, - }, - independentAxis: { - style: { - ...axisBaseStyles, - axis: { ...axisBaseStyles.axis, stroke: theme.pageTextSubdued }, - tickLabels: { ...baseLabelStyles, padding: 10 }, - }, - }, - bar: { - style: { - labels: baseLabelStyles, - data: { fill: theme.reportsBlue, stroke: 'none' }, - }, - }, - line: { - style: { - labels: baseLabelStyles, - data: { - fill: 'none', - stroke: theme.reportsBlue, - strokeWidth: 2, - strokeLinejoin: 'round', - strokeLinecap: 'round', - }, - }, - }, - voronoi: { - style: { - labels: baseLabelStyles, - }, - }, - chart: { - padding: { - top: 20, - left: 65, - right: 20, - bottom: 50, - }, - }, -}; - -export function getColorScale(name) { - const scales = { - grayscale: ['#cccccc', '#969696', '#636363', '#252525'], - qualitative: [ - '#45B29D', //Dark Teal - '#EFC94C', //Yellow - '#E27A3F', //Orange - '#DF5A49', //Light Red - '#5F91B8', //Blue - '#E2A37F', //Peach - '#55DBC1', //Light Teal - '#EFDA97', //Light Yellow - '#DF948A', //Light Red - ], - heatmap: ['#428517', '#77D200', '#D6D305', '#EC8E19', '#C92B05'], - warm: ['#940031', '#C43343', '#DC5429', '#FF821D', '#FFAF55'], - cool: ['#2746B9', '#0B69D4', '#2794DB', '#31BB76', '#60E83B'], - red: ['#FCAE91', '#FB6A4A', '#DE2D26', '#A50F15', '#750B0E'], - blue: ['#002C61', '#004B8F', '#006BC9', '#3795E5', '#65B4F4'], - green: ['#354722', '#466631', '#649146', '#8AB25C', '#A9C97E'], - }; - return name ? scales[name] : scales.grayscale; -} diff --git a/packages/desktop-client/src/components/reports/chart-theme.ts b/packages/desktop-client/src/components/reports/chart-theme.ts index 80aea4c255e..b34f6f62033 100644 --- a/packages/desktop-client/src/components/reports/chart-theme.ts +++ b/packages/desktop-client/src/components/reports/chart-theme.ts @@ -1,6 +1,6 @@ import { theme } from '../../style'; -let colorFades = { +const colorFades = { blueFadeStart: 'rgba(229, 245, 255, 1)', blueFadeEnd: 'rgba(229, 245, 255, 0)', redFadeStart: 'rgba(255, 243, 242, 1)', diff --git a/packages/desktop-client/src/components/reports/util.js b/packages/desktop-client/src/components/reports/util.js deleted file mode 100644 index d6ad29ffa14..00000000000 --- a/packages/desktop-client/src/components/reports/util.js +++ /dev/null @@ -1,44 +0,0 @@ -import { runQuery } from 'loot-core/src/client/query-helpers'; - -export function fromDateRepr(date) { - return date.slice(0, 7); -} - -export async function runAll(queries, cb) { - const data = await Promise.all( - queries.map(q => { - return runQuery(q).then(({ data }) => data); - }), - ); - cb(data); -} - -export function index(data, field, mapper) { - const result = {}; - data.forEach(item => { - result[mapper ? mapper(item[field]) : item[field]] = item; - }); - return result; -} - -export function indexStack(data, fieldName, field) { - const result = {}; - data.forEach(item => { - result[item[fieldName]] = item[field]; - }); - return result; -} - -export function indexCashFlow(data, date, isTransfer) { - const results = {}; - data.forEach(item => { - const findExisting = results[item.date] - ? results[item.date][item.isTransfer] - ? results[item.date][item.isTransfer] - : 0 - : 0; - const result = { [item[isTransfer]]: item.amount + findExisting }; - results[item[date]] = { ...results[item[date]], ...result }; - }); - return results; -} diff --git a/packages/desktop-client/src/components/reports/util.ts b/packages/desktop-client/src/components/reports/util.ts index 4231f0b8711..4d28f2ee4d4 100644 --- a/packages/desktop-client/src/components/reports/util.ts +++ b/packages/desktop-client/src/components/reports/util.ts @@ -9,7 +9,7 @@ export async function runAll( queries: Query[], cb: (data) => void, ): Promise { - let data = await Promise.all( + const data = await Promise.all( queries.map(q => { return runQuery(q).then(({ data }) => data); }), @@ -45,12 +45,12 @@ export function indexCashFlow< >(data: T[], date: string, isTransfer: string) { const results = {}; data.forEach(item => { - let findExisting = results[item.date] + const findExisting = results[item.date] ? results[item.date][item.isTransfer] ? results[item.date][item.isTransfer] : 0 : 0; - let result = { [item[isTransfer]]: item.amount + findExisting }; + const result = { [item[isTransfer]]: item.amount + findExisting }; results[item[date]] = { ...results[item[date]], ...result }; }); return results;