Skip to content

Commit

Permalink
Merge branch 'master' into matiss/unused-vars-2
Browse files Browse the repository at this point in the history
  • Loading branch information
MatissJanis committed Jan 20, 2024
2 parents 06a5dd6 + 83f13cb commit 6646331
Show file tree
Hide file tree
Showing 41 changed files with 526 additions and 110 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
packages/api/app/bundle.api.js
packages/api/dist
packages/api/@types
packages/api/migrations

packages/crdt/dist
Expand Down
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ module.exports = {
{ patterns: [...restrictedImportPatterns, ...restrictedImportColors] },
],

'@typescript-eslint/ban-ts-comment': [
'error',
{ 'ts-ignore': 'allow-with-description' },
],

// Rules disable during TS migration
'@typescript-eslint/no-var-requires': 'off',
'prefer-const': 'warn',
Expand Down
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ body:
required: true
validations:
required: true
- type: checkboxes
id: bank-sync-issue
attributes:
label: 'Is this related to GoCardless, Simplefin or another bank-sync provider?'
description: 'Most issues with bank-sync providers are due to a lack of a custom bank-mapper (i.e. payee or other fields not coming through). In such cases you can create a custom bank mapper in [actual-server](https://github.com/actualbudget/actual-server/blob/master/src/app-gocardless/README.md) repository. Other likely issue is misconfigured server - in which case please reach out via the [community Discord](https://discord.gg/pRYNYr4W5A) to get support.'
options:
- label: 'I have checked my server logs and could not see any errors there'
- label: 'I will be attaching my server logs to this issue'
- label: 'I will be attaching my client-side (browser) logs to this issue'
- label: 'I understand that this issue will be automatically closed if insufficient information is provided'
validations:
required: false
- type: textarea
id: what-happened
attributes:
Expand Down
4 changes: 4 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
blank_issues_enabled: false
contact_links:
- name: Support
url: https://discord.gg/pRYNYr4W5A
about: Need help with something? Perhaps having issues setting up bank-sync with GoCardless or SimpleFin? Reach out to the community on Discord.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
!data/.gitkeep
/data2
packages/api/dist
packages/api/@types
packages/crdt/dist
packages/desktop-electron/client-build
packages/desktop-electron/.electron-symbols
Expand Down
38 changes: 0 additions & 38 deletions packages/api/index.js

This file was deleted.

53 changes: 53 additions & 0 deletions packages/api/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import type {
RequestInfo as FetchInfo,
RequestInit as FetchInit,
// @ts-ignore: false-positive commonjs module error on build until typescript 5.3
} from 'node-fetch'; // with { 'resolution-mode': 'import' };

// loot-core types
import type { InitConfig } from 'loot-core/server/main';

// @ts-ignore: bundle not available until we build it
// eslint-disable-next-line import/extensions
import * as bundle from './app/bundle.api.js';
import * as injected from './injected';
import { validateNodeVersion } from './validateNodeVersion';

let actualApp: null | typeof bundle.lib;
export const internal = bundle.lib;

// DEPRECATED: remove the next line in @actual-app/api v7
export * as methods from './methods';

export * from './methods';
export * as utils from './utils';

export async function init(config: InitConfig = {}) {
if (actualApp) {
return;
}

validateNodeVersion();

if (!globalThis.fetch) {
globalThis.fetch = (url: URL | RequestInfo, init?: RequestInit) => {
return import('node-fetch').then(({ default: fetch }) =>
fetch(url as unknown as FetchInfo, init as unknown as FetchInit),
) as unknown as Promise<Response>;
};
}

await bundle.init(config);
actualApp = bundle.lib;

injected.override(bundle.lib.send);
return bundle.lib;
}

export async function shutdown() {
if (actualApp) {
await actualApp.send('sync');
await actualApp.send('close-budget');
actualApp = null;
}
}
18 changes: 12 additions & 6 deletions packages/api/methods.js → packages/api/methods.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
// @ts-strict-ignore
import type { Handlers } from 'loot-core/src/types/handlers';

import * as injected from './injected';

export { q } from './app/query';

function send(name, args) {
function send<K extends keyof Handlers, T extends Handlers[K]>(
name: K,
args?: Parameters<T>[0],
): Promise<Awaited<ReturnType<T>>> {
return injected.send(name, args);
}

Expand All @@ -21,7 +27,7 @@ export async function loadBudget(budgetId) {
return send('api/load-budget', { id: budgetId });
}

export async function downloadBudget(syncId, { password } = {}) {
export async function downloadBudget(syncId, { password }: { password? } = {}) {
return send('api/download-budget', { syncId, password });
}

Expand Down Expand Up @@ -91,15 +97,15 @@ export function getAccounts() {
return send('api/accounts-get');
}

export function createAccount(account, initialBalance) {
export function createAccount(account, initialBalance?) {
return send('api/account-create', { account, initialBalance });
}

export function updateAccount(id, fields) {
return send('api/account-update', { id, fields });
}

export function closeAccount(id, transferAccountId, transferCategoryId) {
export function closeAccount(id, transferAccountId?, transferCategoryId?) {
return send('api/account-close', {
id,
transferAccountId,
Expand All @@ -123,7 +129,7 @@ export function updateCategoryGroup(id, fields) {
return send('api/category-group-update', { id, fields });
}

export function deleteCategoryGroup(id, transferCategoryId) {
export function deleteCategoryGroup(id, transferCategoryId?) {
return send('api/category-group-delete', { id, transferCategoryId });
}

Expand All @@ -139,7 +145,7 @@ export function updateCategory(id, fields) {
return send('api/category-update', { id, fields });
}

export function deleteCategory(id, transferCategoryId) {
export function deleteCategory(id, transferCategoryId?) {
return send('api/category-delete', { id, transferCategoryId });
}

Expand Down
10 changes: 6 additions & 4 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
"node": ">=18.12.0"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "@types/index.d.ts",
"files": [
"dist"
],
"scripts": {
"build:app": "yarn workspace loot-core build:api",
"build:node": "tsc --p tsconfig.dist.json",
"build:node": "tsc --p tsconfig.dist.json && tsc-alias -p tsconfig.dist.json",
"build:migrations": "cp migrations/*.sql dist/migrations",
"build:default-db": "cp default-db.sqlite dist/",
"build": "rm -rf dist && yarn run build:app && yarn run build:node && yarn run build:migrations && yarn run build:default-db",
"test": "yarn run build:app && jest -c jest.config.js"
"build": "yarn run clean && yarn run build:app && yarn run build:node && yarn run build:migrations && yarn run build:default-db",
"test": "yarn run build:app && jest -c jest.config.js",
"clean": "rm -rf dist @types"
},
"dependencies": {
"better-sqlite3": "^9.2.2",
Expand All @@ -31,6 +32,7 @@
"@types/jest": "^27.5.0",
"@types/uuid": "^9.0.2",
"jest": "^27.0.0",
"tsc-alias": "^1.8.8",
"typescript": "^5.0.2"
}
}
8 changes: 6 additions & 2 deletions packages/api/tsconfig.dist.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
"moduleResolution": "Node16",
"noEmit": false,
"declaration": true,
"outDir": "dist"
"outDir": "dist",
"declarationDir": "@types",
"paths": {
"loot-core/*": ["./@types/loot-core/*"],
}
},
"include": ["."],
"exclude": ["dist"]
"exclude": ["**/node_modules/*", "dist", "@types"]
}
5 changes: 5 additions & 0 deletions packages/desktop-client/src/components/common/AnchorLink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@ import { NavLink, useMatch } from 'react-router-dom';

import { css } from 'glamor';

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

import { type CSSProperties, styles } from '../../style';

type AnchorLinkProps = {
to: string;
style?: CSSProperties;
activeStyle?: CSSProperties;
children?: ReactNode;
report?: CustomReportEntity;
};

export function AnchorLink({
to,
style,
activeStyle,
children,
report,
}: AnchorLinkProps) {
const match = useMatch({ path: to });

return (
<NavLink
to={to}
state={report ? { report } : {}}
className={`${css([
styles.smallText,
style,
Expand Down
5 changes: 4 additions & 1 deletion packages/desktop-client/src/components/reports/Overview.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { useSelector } from 'react-redux';

import { useReports } from 'loot-core/src/client/data-hooks/reports';

import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { styles } from '../../style';
import { View } from '../common/View';
Expand All @@ -12,6 +14,7 @@ import { NetWorthCard } from './reports/NetWorthCard';
import { SankeyCard } from './reports/SankeyCard';

export function Overview() {
const customReports = useReports();
const categorySpendingReportFeatureFlag = useFeatureFlag(
'categorySpendingReport',
);
Expand Down Expand Up @@ -45,7 +48,7 @@ export function Overview() {
{categorySpendingReportFeatureFlag && <CategorySpendingCard />}
{sankeyFeatureFlag && <SankeyCard />}
{customReportsFeatureFlag ? (
<CustomReportCard />
<CustomReportCard reports={customReports} />
) : (
<div style={{ flex: 1 }} />
)}
Expand Down
26 changes: 21 additions & 5 deletions packages/desktop-client/src/components/reports/ReportCard.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
// @ts-strict-ignore
import React from 'react';
import React, { type ReactNode } from 'react';

import { theme } from '../../style';
import { type CustomReportEntity } from 'loot-core/src/types/models';

import { type CSSProperties, theme } from '../../style';
import { AnchorLink } from '../common/AnchorLink';
import { View } from '../common/View';

export function ReportCard({ flex, to, style, children }) {
type ReportCardProps = {
to: string;
report: CustomReportEntity;
children: ReactNode;
flex?: string;
style?: CSSProperties;
};

export function ReportCard({
to,
report,
children,
flex,
style,
}: ReportCardProps) {
const containerProps = { flex, margin: 15 };

const content = (
Expand Down Expand Up @@ -34,7 +49,8 @@ export function ReportCard({ flex, to, style, children }) {
return (
<AnchorLink
to={to}
style={{ textDecoration: 'none', flex, ...containerProps }}
report={report}
style={{ textDecoration: 'none', ...containerProps }}
>
{content}
</AnchorLink>
Expand Down
Loading

0 comments on commit 6646331

Please sign in to comment.