Skip to content

Commit

Permalink
fix that broken merge
Browse files Browse the repository at this point in the history
  • Loading branch information
youngcw committed Nov 4, 2024
2 parents d9789cd + 29fc22a commit a0c4326
Show file tree
Hide file tree
Showing 24 changed files with 681 additions and 236 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/update-vrt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ jobs:
if: |
github.event.issue.pull_request &&
contains(github.event.comment.body, '/update-vrt')
container:
image: mcr.microsoft.com/playwright:v1.41.1-jammy
steps:
- name: Get PR branch
uses: xt0rted/pull-request-comment-branch@v2
# Until https://github.com/xt0rted/pull-request-comment-branch/issues/322 is resolved we use the forked version
uses: gotson/pull-request-comment-branch@head-repo-owner-dist
id: comment-branch
- uses: actions/checkout@v4
with:
repository: ${{ steps.comment-branch.outputs.head_owner }}/${{ steps.comment-branch.outputs.head_repo }}
ref: ${{ steps.comment-branch.outputs.head_ref }}
- name: Set up environment
uses: ./.github/actions/setup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const BudgetCategories = memo(
onSaveGroup,
onDeleteCategory,
onDeleteGroup,
onApplyBudgetTemplatesInGroup,
onReorderCategory,
onReorderGroup,
}) => {
Expand Down Expand Up @@ -245,6 +246,7 @@ export const BudgetCategories = memo(
onReorderCategory={onReorderCategory}
onToggleCollapse={onToggleCollapse}
onShowNewCategory={onShowNewCategory}
onApplyBudgetTemplatesInGroup={onApplyBudgetTemplatesInGroup}
/>
);
break;
Expand Down
2 changes: 2 additions & 0 deletions packages/desktop-client/src/components/budget/BudgetTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function BudgetTable(props) {
onDeleteCategory,
onSaveGroup,
onDeleteGroup,
onApplyBudgetTemplatesInGroup,
onReorderCategory,
onReorderGroup,
onShowActivity,
Expand Down Expand Up @@ -235,6 +236,7 @@ export function BudgetTable(props) {
onReorderGroup={_onReorderGroup}
onBudgetAction={onBudgetAction}
onShowActivity={onShowActivity}
onApplyBudgetTemplatesInGroup={onApplyBudgetTemplatesInGroup}
/>
</View>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ type ExpenseGroupProps = {
onEditName?: ComponentProps<typeof SidebarGroup>['onEdit'];
onSave?: ComponentProps<typeof SidebarGroup>['onSave'];
onDelete?: ComponentProps<typeof SidebarGroup>['onDelete'];
onApplyBudgetTemplatesInGroup?: ComponentProps<
typeof SidebarGroup
>['onApplyBudgetTemplatesInGroup'];
onDragChange: OnDragChangeCallback<
ComponentProps<typeof SidebarGroup>['group']
>;
Expand All @@ -43,6 +46,7 @@ export function ExpenseGroup({
onEditName,
onSave,
onDelete,
onApplyBudgetTemplatesInGroup,
onDragChange,
onReorderGroup,
onReorderCategory,
Expand Down Expand Up @@ -125,6 +129,7 @@ export function ExpenseGroup({
onEdit={onEditName}
onSave={onSave}
onDelete={onDelete}
onApplyBudgetTemplatesInGroup={onApplyBudgetTemplatesInGroup}
onShowNewCategory={onShowNewCategory}
/>
<RenderMonths component={MonthComponent} args={{ group }} />
Expand Down
17 changes: 17 additions & 0 deletions packages/desktop-client/src/components/budget/SidebarGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type SidebarGroupProps = {
onEdit?: (id: string) => void;
onSave?: (group: object) => Promise<void>;
onDelete?: (id: string) => Promise<void>;
onApplyBudgetTemplatesInGroup?: (categories: object[]) => void;
onShowNewCategory?: (groupId: string) => void;
onHideNewGroup?: () => void;
onToggleCollapse?: (id: string) => void;
Expand All @@ -48,11 +49,13 @@ export function SidebarGroup({
onEdit,
onSave,
onDelete,
onApplyBudgetTemplatesInGroup,
onShowNewCategory,
onHideNewGroup,
onToggleCollapse,
}: SidebarGroupProps) {
const { t } = useTranslation();
const isGoalTemplatesEnabled = useFeatureFlag('goalTemplatesEnabled');

const temporary = group.id === 'new';
const [menuOpen, setMenuOpen] = useState(false);
Expand Down Expand Up @@ -132,6 +135,12 @@ export function SidebarGroup({
onDelete(group.id);
} else if (type === 'toggle-visibility') {
onSave({ ...group, hidden: !group.hidden });
} else if (type === 'apply-multiple-category-template') {
onApplyBudgetTemplatesInGroup?.(
group.categories
.filter(c => !c['hidden'])
.map(c => c['id']),
);
}
setMenuOpen(false);
}}
Expand All @@ -143,6 +152,14 @@ export function SidebarGroup({
text: group.hidden ? t('Show') : t('Hide'),
},
onDelete && { name: 'delete', text: t('Delete') },
...(isGoalTemplatesEnabled
? [
{
name: 'apply-multiple-category-template',
text: t('Apply budget templates'),
},
]
: []),
]}
/>
</Popover>
Expand Down
10 changes: 10 additions & 0 deletions packages/desktop-client/src/components/budget/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,15 @@ function BudgetInner(props: BudgetInnerProps) {
}
};

const onApplyBudgetTemplatesInGroup = async categories => {
dispatch(
applyBudgetAction(startMonth, 'apply-multiple-templates', {
month: startMonth,
categories,
}),
);
};

const onBudgetAction = (month, type, args) => {
dispatch(applyBudgetAction(month, type, args));
};
Expand Down Expand Up @@ -366,6 +375,7 @@ function BudgetInner(props: BudgetInnerProps) {
onMonthSelect={onMonthSelect}
onDeleteCategory={onDeleteCategory}
onDeleteGroup={onDeleteGroup}
onApplyBudgetTemplatesInGroup={onApplyBudgetTemplatesInGroup}
onSaveCategory={onSaveCategory}
onSaveGroup={onSaveGroup}
onBudgetAction={onBudgetAction}
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop-client/src/components/common/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const Tooltip = ({

return (
<View
style={{ minHeight: 'auto', flexShrink: 0 }}
style={{ minHeight: 'auto', flexShrink: 0, maxWidth: '100%' }}
ref={triggerRef}
onMouseEnter={handlePointerEnter}
onMouseLeave={handlePointerLeave}
Expand Down
147 changes: 102 additions & 45 deletions packages/loot-core/src/client/actions/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,67 @@ export function linkAccountSimpleFin(
};
}

function handleSyncResponse(
accountId,
res,
dispatch,
resNewTransactions,
resMatchedTransactions,
resUpdatedAccounts,
) {
const { errors, newTransactions, matchedTransactions, updatedAccounts } = res;

// Mark the account as failed or succeeded (depending on sync output)
const [error] = errors;
if (error) {
// We only want to mark the account as having problem if it
// was a real syncing error.
if (error.type === 'SyncError') {
dispatch(markAccountFailed(accountId, error.category, error.code));
}
} else {
dispatch(markAccountSuccess(accountId));
}

// Dispatch errors (if any)
errors.forEach(error => {
if (error.type === 'SyncError') {
dispatch(
addNotification({
type: 'error',
message: error.message,
}),
);
} else {
dispatch(
addNotification({
type: 'error',
message: error.message,
internal: error.internal,
}),
);
}
});

resNewTransactions.push(...newTransactions);
resMatchedTransactions.push(...matchedTransactions);
resUpdatedAccounts.push(...updatedAccounts);

return newTransactions.length > 0 || matchedTransactions.length > 0;
}

export function syncAccounts(id?: string) {
return async (dispatch: Dispatch, getState: GetState) => {
// Disallow two parallel sync operations
if (getState().account.accountsSyncing.length > 0) {
return false;
}

const batchSync = !id;

// Build an array of IDs for accounts to sync.. if no `id` provided
// then we assume that all accounts should be synced
const accountIdsToSync = id
let accountIdsToSync = !batchSync
? [id]
: getState()
.queries.accounts.filter(
Expand All @@ -113,67 +164,73 @@ export function syncAccounts(id?: string) {

dispatch(setAccountsSyncing(accountIdsToSync));

const accountsData = await send('accounts-get');
const simpleFinAccounts = accountsData.filter(
a => a.account_sync_source === 'simpleFin',
);

let isSyncSuccess = false;
const newTransactions = [];
const matchedTransactions = [];
const updatedAccounts = [];

if (batchSync && simpleFinAccounts.length > 0) {
console.log('Using SimpleFin batch sync');

const res = await send('simplefin-batch-sync', {
ids: simpleFinAccounts.map(a => a.id),
});

for (const account of res) {
const success = handleSyncResponse(
account.accountId,
account.res,
dispatch,
newTransactions,
matchedTransactions,
updatedAccounts,
);
if (success) isSyncSuccess = true;
}

accountIdsToSync = accountIdsToSync.filter(
id => !simpleFinAccounts.find(sfa => sfa.id === id),
);
}

// Loop through the accounts and perform sync operation.. one by one
for (let idx = 0; idx < accountIdsToSync.length; idx++) {
const accountId = accountIdsToSync[idx];

// Perform sync operation
const { errors, newTransactions, matchedTransactions, updatedAccounts } =
await send('accounts-bank-sync', {
id: accountId,
});

// Mark the account as failed or succeeded (depending on sync output)
const [error] = errors;
if (error) {
// We only want to mark the account as having problem if it
// was a real syncing error.
if (error.type === 'SyncError') {
dispatch(markAccountFailed(accountId, error.category, error.code));
}
} else {
dispatch(markAccountSuccess(accountId));
}

// Dispatch errors (if any)
errors.forEach(error => {
if (error.type === 'SyncError') {
dispatch(
addNotification({
type: 'error',
message: error.message,
}),
);
} else {
dispatch(
addNotification({
type: 'error',
message: error.message,
internal: error.internal,
}),
);
}
const res = await send('accounts-bank-sync', {
id: accountId,
});

// Set new transactions
dispatch({
type: constants.SET_NEW_TRANSACTIONS,
const success = handleSyncResponse(
accountId,
res,
dispatch,
newTransactions,
matchedTransactions,
updatedAccounts,
});
);

if (success) isSyncSuccess = true;

// Dispatch the ids for the accounts that are yet to be synced
dispatch(setAccountsSyncing(accountIdsToSync.slice(idx + 1)));

if (newTransactions.length > 0 || matchedTransactions.length > 0) {
isSyncSuccess = true;
}
}

// Rest the sync state back to empty (fallback in case something breaks
// Set new transactions
dispatch({
type: constants.SET_NEW_TRANSACTIONS,
newTransactions,
matchedTransactions,
updatedAccounts,
});

// Reset the sync state back to empty (fallback in case something breaks
// in the logic above)
dispatch(setAccountsSyncing([]));
return isSyncSuccess;
Expand Down
10 changes: 10 additions & 0 deletions packages/loot-core/src/client/actions/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ export function applyBudgetAction(month, type, args) {
category: args.category,
});
break;
case 'apply-multiple-templates':
dispatch(
addNotification(
await send('budget/apply-multiple-templates', {
month,
categoryIds: args.categories,
}),
),
);
break;
case 'set-single-3-avg':
await send('budget/set-n-month-avg', {
month,
Expand Down
Loading

0 comments on commit a0c4326

Please sign in to comment.