Skip to content

Commit

Permalink
Merge branch 'master' into i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
a-gradina authored Nov 19, 2024
2 parents 5b00ab4 + 5cf4398 commit 90f221c
Show file tree
Hide file tree
Showing 22 changed files with 203 additions and 152 deletions.
17 changes: 0 additions & 17 deletions packages/desktop-client/e2e/page-models/settings-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,10 @@ export class SettingsPage {
}

async useBudgetType(budgetType) {
await this.enableExperimentalFeature('Budget mode toggle');

const switchBudgetTypeButton = this.page.getByRole('button', {
name: `Switch to ${budgetType} budgeting`,
});

await switchBudgetTypeButton.click();
}

async enableExperimentalFeature(featureName) {
const advancedSettingsButton = this.page.getByTestId('advanced-settings');
await advancedSettingsButton.click();

const experimentalSettingsButton = this.page.getByTestId(
'experimental-settings',
);
await experimentalSettingsButton.click();

const featureCheckbox = this.page.getByRole('checkbox', {
name: featureName,
});
await featureCheckbox.click();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 44 additions & 40 deletions packages/desktop-client/src/components/mobile/MobileNavTabs.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-strict-ignore
import React, {
useCallback,
type ComponentProps,
type ComponentType,
type CSSProperties,
} from 'react';
Expand Down Expand Up @@ -43,6 +43,43 @@ export function MobileNavTabs() {
padding: 10,
};

const [{ y }, api] = useSpring(() => ({ y: OPEN_DEFAULT_Y }));

const openFull = useCallback(
({ canceled }: { canceled?: boolean }) => {
// when cancel is true, it means that the user passed the upwards threshold
// so we change the spring config to create a nice wobbly effect
api.start({
y: OPEN_FULL_Y,
immediate: false,
config: canceled ? config.wobbly : config.stiff,
});
},
[api, OPEN_FULL_Y],
);

const openDefault = useCallback(
(velocity = 0) => {
api.start({
y: OPEN_DEFAULT_Y,
immediate: false,
config: { ...config.stiff, velocity },
});
},
[api, OPEN_DEFAULT_Y],
);

const hide = useCallback(
(velocity = 0) => {
api.start({
y: HIDDEN_Y,
immediate: false,
config: { ...config.stiff, velocity },
});
},
[api, HIDDEN_Y],
);

const navTabs = [
{
name: 'Budget',
Expand Down Expand Up @@ -92,50 +129,15 @@ export function MobileNavTabs() {
style: navTabStyle,
Icon: SvgCog,
},
].map(tab => <NavTab key={tab.path} {...tab} />);
].map(tab => (
<NavTab key={tab.path} onClick={() => openDefault()} {...tab} />
));

const bufferTabsCount = COLUMN_COUNT - (navTabs.length % COLUMN_COUNT);
const bufferTabs = Array.from({ length: bufferTabsCount }).map((_, idx) => (
<div key={idx} style={navTabStyle} />
));

const [{ y }, api] = useSpring(() => ({ y: OPEN_DEFAULT_Y }));

const openFull = useCallback(
({ canceled }) => {
// when cancel is true, it means that the user passed the upwards threshold
// so we change the spring config to create a nice wobbly effect
api.start({
y: OPEN_FULL_Y,
immediate: false,
config: canceled ? config.wobbly : config.stiff,
});
},
[api, OPEN_FULL_Y],
);

const openDefault = useCallback(
(velocity = 0) => {
api.start({
y: OPEN_DEFAULT_Y,
immediate: false,
config: { ...config.stiff, velocity },
});
},
[api, OPEN_DEFAULT_Y],
);

const hide = useCallback(
(velocity = 0) => {
api.start({
y: HIDDEN_Y,
immediate: false,
config: { ...config.stiff, velocity },
});
},
[api, HIDDEN_Y],
);

useScrollListener(({ isScrolling }) => {
if (isScrolling('down')) {
hide();
Expand Down Expand Up @@ -237,9 +239,10 @@ type NavTabProps = {
path: string;
Icon: ComponentType<NavTabIconProps>;
style?: CSSProperties;
onClick: ComponentProps<typeof NavLink>['onClick'];
};

function NavTab({ Icon: TabIcon, name, path, style }: NavTabProps) {
function NavTab({ Icon: TabIcon, name, path, style, onClick }: NavTabProps) {
return (
<NavLink
to={path}
Expand All @@ -253,6 +256,7 @@ function NavTab({ Icon: TabIcon, name, path, style }: NavTabProps) {
textAlign: 'center',
...style,
})}
onClick={onClick}
>
<TabIcon width={22} height={22} />
{name}
Expand Down
21 changes: 1 addition & 20 deletions packages/desktop-client/src/components/settings/Experimental.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type ReactNode, useState } from 'react';
import { Trans, useTranslation } from 'react-i18next';
import { Trans } from 'react-i18next';

import type { FeatureFlag } from 'loot-core/src/types/prefs';

Expand Down Expand Up @@ -67,23 +67,6 @@ function FeatureToggle({
);
}

function TrackingBudgetFeature() {
const { t } = useTranslation();
const [budgetType = 'rollover'] = useSyncedPref('budgetType');
const enabled = useFeatureFlag('reportBudget');
const blockToggleOff = budgetType === 'report' && enabled;
return (
<FeatureToggle
flag="reportBudget"
disableToggle={blockToggleOff}
error={t('Switch to a envelope budget before turning off this feature')}
feedbackLink="https://github.com/actualbudget/actual/issues/2999"
>
<Trans>Budget mode toggle</Trans>
</FeatureToggle>
);
}

export function ExperimentalFeatures() {
const [expanded, setExpanded] = useState(false);

Expand All @@ -92,8 +75,6 @@ export function ExperimentalFeatures() {
primaryAction={
expanded ? (
<View style={{ gap: '1em' }}>
<TrackingBudgetFeature />

<FeatureToggle flag="goalTemplatesEnabled">
<Trans>Goal templates</Trans>
</FeatureToggle>
Expand Down
3 changes: 1 addition & 2 deletions packages/desktop-client/src/components/settings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { isElectron } from 'loot-core/shared/environment';
import { listen } from 'loot-core/src/platform/client/fetch';

import { useActions } from '../../hooks/useActions';
import { useFeatureFlag } from '../../hooks/useFeatureFlag';
import { useGlobalPref } from '../../hooks/useGlobalPref';
import { useIsOutdated, useLatestVersion } from '../../hooks/useLatestVersion';
import { useMetadataPref } from '../../hooks/useMetadataPref';
Expand Down Expand Up @@ -177,7 +176,7 @@ export function Settings() {
<ThemeSettings />
<FormatSettings />
<EncryptionSettings />
{useFeatureFlag('reportBudget') && <BudgetTypeSettings />}
<BudgetTypeSettings />
{isElectron() && <Backups />}
<ExportBudget />
<AdvancedToggle>
Expand Down
1 change: 0 additions & 1 deletion packages/desktop-client/src/hooks/useFeatureFlag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { FeatureFlag } from 'loot-core/src/types/prefs';
import { useSyncedPref } from './useSyncedPref';

const DEFAULT_FEATURE_FLAG_STATE: Record<FeatureFlag, boolean> = {
reportBudget: false,
goalTemplatesEnabled: false,
dashboards: false,
actionTemplating: false,
Expand Down
2 changes: 1 addition & 1 deletion packages/loot-core/src/client/actions/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export function syncAccounts(id?: string) {

// Perform sync operation
const res = await send('accounts-bank-sync', {
id: accountId,
ids: [accountId],
});

const success = handleSyncResponse(
Expand Down
40 changes: 34 additions & 6 deletions packages/loot-core/src/server/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,41 @@ handlers['api/sync'] = async function () {
};

handlers['api/bank-sync'] = async function (args) {
const { errors } = await handlers['accounts-bank-sync']({
id: args?.accountId,
});
const batchSync = args?.accountId == null;
const allErrors = [];

if (!batchSync) {
const { errors } = await handlers['accounts-bank-sync']({
ids: [args.accountId],
});

allErrors.push(errors);
} else {
const accountsData = await handlers['accounts-get']();
const accountIdsToSync = accountsData.map(a => a.id);
const simpleFinAccounts = accountsData.filter(
a => a.account_sync_source === 'simpleFin',
);
const simpleFinAccountIds = simpleFinAccounts.map(a => a.id);

if (simpleFinAccounts.length > 1) {
const res = await handlers['simplefin-batch-sync']({
ids: simpleFinAccountIds,
});

res.forEach(a => allErrors.push(...a.res.errors));
}

const { errors } = await handlers['accounts-bank-sync']({
ids: accountIdsToSync.filter(a => !simpleFinAccountIds.includes(a)),
});

allErrors.push(...errors);
}

const [firstError] = errors;
if (firstError) {
throw new Error(getBankSyncError(firstError));
const errors = allErrors.filter(e => e != null);
if (errors.length > 0) {
throw new Error(getBankSyncError(errors[0]));
}
};

Expand Down
9 changes: 9 additions & 0 deletions packages/loot-core/src/server/budget/actions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @ts-strict-ignore

import * as monthUtils from '../../shared/months';
import { integerToCurrency, safeNumber } from '../../shared/util';
import * as db from '../db';
Expand All @@ -13,6 +14,14 @@ export async function getSheetValue(
return safeNumber(typeof node.value === 'number' ? node.value : 0);
}

export async function getSheetBoolean(
sheetName: string,
cell: string,
): Promise<boolean> {
const node = await sheet.getCell(sheetName, cell);
return typeof node.value === 'boolean' ? node.value : false;
}

// We want to only allow the positive movement of money back and
// forth. buffered should never be allowed to go into the negative,
// and you shouldn't be allowed to pull non-existent money from
Expand Down
Loading

0 comments on commit 90f221c

Please sign in to comment.