mirror of
https://github.com/actualbudget/actual.git
synced 2026-03-11 20:44:32 -05:00
[Maintenance] Migrating util.js and chartTheme.js to typescript (#2009)
This commit is contained in:
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
57
packages/desktop-client/src/components/reports/util.ts
Normal file
57
packages/desktop-client/src/components/reports/util.ts
Normal file
@@ -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
upcoming-release-notes/2009.md
Normal file
6
upcoming-release-notes/2009.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
category: Maintenance
|
||||
authors: [ghosetuhin]
|
||||
---
|
||||
|
||||
Migrating the util.js and chartTheme.js files to typescript
|
||||
Reference in New Issue
Block a user