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

[Maintenance] Migrating util.js and chartTheme.js to typescript #2009

Merged
merged 31 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
579cfea
change file type to ts
ghosetuhin Dec 2, 2023
f6b151f
added types to fromDateRepr, runAll and index functions
ghosetuhin Dec 2, 2023
30316d6
added types to indexStack and indexCashFlow
ghosetuhin Dec 2, 2023
1128b0e
added release note file
ghosetuhin Dec 2, 2023
9b134c2
ran prettier
ghosetuhin Dec 2, 2023
7aa57f4
fixed lint errors
ghosetuhin Dec 2, 2023
5f0eea4
fixed remaining lint errors
ghosetuhin Dec 2, 2023
ff83de0
Merge branch 'master' into master
ghosetuhin Dec 3, 2023
b131597
added ColorFades interface
ghosetuhin Dec 3, 2023
8a15ea4
Merge branch 'master' of https://github.com/ghosetuhin/actual
ghosetuhin Dec 3, 2023
67bbd71
added LabelStyles interface
ghosetuhin Dec 3, 2023
0e4156a
added interface for AxisBaseStyle and ChartTheme
ghosetuhin Dec 3, 2023
6dfadbb
added types to getColorScale
ghosetuhin Dec 3, 2023
5cc8e4d
fixed lint error by changing interface to type
ghosetuhin Dec 4, 2023
324e22c
fixed remaining lint errors
ghosetuhin Dec 4, 2023
3d14f32
incorporated pr review suggestions for chart-theme.js
ghosetuhin Dec 4, 2023
c696bf3
implemented suggested change to generics for index and indexStack
ghosetuhin Dec 4, 2023
e394ca5
small changes to use record
ghosetuhin Dec 4, 2023
141bd12
tried implementing generics for indexCashFlow
ghosetuhin Dec 4, 2023
20090ea
fixed lint erros
ghosetuhin Dec 4, 2023
563d87e
Merge branch 'master' into master
ghosetuhin Dec 4, 2023
748ba85
fixed typecheck errors
ghosetuhin Dec 4, 2023
49703be
Merge branch 'master' of https://github.com/ghosetuhin/actual
ghosetuhin Dec 4, 2023
91dce18
tried fixing typecheck errors again
ghosetuhin Dec 4, 2023
1ae9b7f
typecasting to string to avoid issue with never
ghosetuhin Dec 4, 2023
febc0f8
fixed lint errors
ghosetuhin Dec 4, 2023
cdf7b02
Merge branch 'master' into master
ghosetuhin Dec 5, 2023
6061adc
implemented suggested changes and converted functions to generics
ghosetuhin Dec 5, 2023
4d3ccdb
added chart-theme.js and util.js to resolve merge conflicts
ghosetuhin Dec 5, 2023
ea8cfbd
Merge branch 'master' into master
ghosetuhin Dec 5, 2023
6930cf4
deleted .js files and fixed lint errors
ghosetuhin Dec 5, 2023
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 @@ -112,8 +112,8 @@ export const chartTheme = {
},
};

export function getColorScale(name) {
const scales = {
export function getColorScale(name: string): string[] {
const scales: Record<string, string[]> = {
grayscale: ['#cccccc', '#969696', '#636363', '#252525'],
qualitative: [
'#45B29D', //Dark Teal
Expand Down
44 changes: 0 additions & 44 deletions packages/desktop-client/src/components/reports/util.js

This file was deleted.

57 changes: 57 additions & 0 deletions packages/desktop-client/src/components/reports/util.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { runQuery } from 'loot-core/src/client/query-helpers';
import type { Query } from 'loot-core/src/shared/query';

export function fromDateRepr(date: string): string {
return date.slice(0, 7);
}

export async function runAll(
queries: Query[],
cb: (data) => void,
): Promise<void> {
const data = await Promise.all(
queries.map(q => {
return runQuery(q).then(({ data }) => data);
}),
);
cb(data);
}

export function index<
T extends Record<string, string | number>,
K extends keyof T,
>(data: T[], field: K) {
const result: Record<string | number, T> = {};
data.forEach(item => {
const key = item[field];
result[key] = item;
});
return result;
}

export function indexStack<
T extends Record<string, string | number>,
K extends keyof T,
>(data: T[], fieldName: K, field: K) {
const result: Record<string | number, T[K]> = {};
data.forEach(item => {
result[item[fieldName]] = item[field];
});
return result;
}

export function indexCashFlow<
T extends { date: string; isTransfer: boolean; amount: number },
>(data: T[], date: string, isTransfer: string) {
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;
}
6 changes: 6 additions & 0 deletions upcoming-release-notes/2009.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Maintenance
authors: [ghosetuhin]
---

Migrating the util.js and chartTheme.js files to typescript