Skip to content

Commit

Permalink
new filter for account
Browse files Browse the repository at this point in the history
changed name of the option

md
  • Loading branch information
lelemm committed Nov 26, 2024
1 parent c25e3d4 commit 1b0bebf
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 28 deletions.
24 changes: 13 additions & 11 deletions packages/desktop-client/src/components/filters/FilterExpression.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,19 @@ export function FilterExpression<T extends RuleConditionEntity>({
{mapField(field, options)}
</Text>{' '}
<Text>{friendlyOp(op, null)}</Text>{' '}
<Value
value={value}
field={field}
inline={true}
valueIsRaw={
op === 'contains' ||
op === 'matches' ||
op === 'doesNotContain' ||
op === 'hasTags'
}
/>
{!['onBudget', 'offBudget'].includes(op) && (
<Value
value={value}
field={field}
inline={true}
valueIsRaw={
op === 'contains' ||
op === 'matches' ||
op === 'doesNotContain' ||
op === 'hasTags'
}
/>
)}
</>
)}
</div>
Expand Down
13 changes: 12 additions & 1 deletion packages/desktop-client/src/components/filters/FiltersMenu.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,18 @@ function ConfigureField({
}}
/>
) : (
titleFirst(mapField(field))
<View
style={{
flexDirection: 'row',
width: '100%',
alignItems: 'center',
padding: 0,
}}
>
<View style={{ flexGrow: 1 }}>{titleFirst(mapField(field))}</View>
</View>
)}

<View style={{ flex: 1 }} />
</Stack>
</View>
Expand Down Expand Up @@ -222,6 +232,7 @@ function ConfigureField({
}
value={value}
multi={op === 'oneOf' || op === 'notOneOf'}
op={op}
style={{ marginTop: 10 }}
onChange={v => {
dispatch({ type: 'set-value', value: v });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ export function updateFilterReducer(
action.op === 'is' ||
action.op === 'doesNotContain' ||
action.op === 'isNot' ||
action.op === 'hasTags')
action.op === 'hasTags' ||
action.op === 'onBudget' ||
action.op === 'offBudget')
) {
// Clear out the value if switching between contains or
// is/oneof for the id or string type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ function ConditionEditor({
field={field}
type={type}
value={value}
op={op}
multi={op === 'oneOf' || op === 'notOneOf'}
onChange={v => onChange('value', v)}
numberFormatType="currency"
Expand Down Expand Up @@ -461,6 +462,7 @@ function ActionEditor({ action, editorStyle, onChange, onDelete, onAdd }) {
<GenericInput
key={inputKey}
field={field}
op={op}
type="number"
numberFormatType={
options.method === 'fixed-percent' ? 'percentage' : 'currency'
Expand Down
35 changes: 23 additions & 12 deletions packages/desktop-client/src/components/util/GenericInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function GenericInput({
inputRef,
style,
onChange,
op = undefined,
}) {
const { grouped: categoryGroups } = useCategories();
const { data: savedReports } = useReports();
Expand Down Expand Up @@ -100,18 +101,28 @@ export function GenericInput({
break;

case 'account':
content = (
<AccountAutocomplete
type={autocompleteType}
value={value}
openOnFocus={true}
onSelect={onChange}
inputProps={{
inputRef,
...(showPlaceholder ? { placeholder: 'nothing' } : null),
}}
/>
);
switch (op) {
case 'onBudget':
content = <Input disabled value="on budget" />;
break;
case 'offBudget':
content = <Input disabled value="off budget" />;
break;
default:
content = (
<AccountAutocomplete
type={autocompleteType}
value={value}
openOnFocus={true}
onSelect={onChange}
inputProps={{
inputRef,
...(showPlaceholder ? { placeholder: 'nothing' } : null),
}}
/>
);
break;
}
break;

case 'category':
Expand Down
4 changes: 4 additions & 0 deletions packages/loot-core/src/server/accounts/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ const CONDITION_TYPES = {
'doesNotContain',
'notOneOf',
'and',
'onBudget',
'offBudget',
],
nullable: true,
parse(op, value, fieldName) {
Expand Down Expand Up @@ -948,6 +950,8 @@ const OP_SCORES: Record<RuleConditionEntity['op'], number> = {
doesNotContain: 0,
matches: 0,
hasTags: 0,
onBudget: 0,
offBudget: 0,
};

function computeScore(rule: Rule): number {
Expand Down
6 changes: 6 additions & 0 deletions packages/loot-core/src/server/accounts/transaction-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,12 @@ export function conditionsToAQL(conditions, { recurDateBounds = 100 } = {}) {
return {
$and: getValue(value).map(subExpr => mapConditionToActualQL(subExpr)),
};

case 'onBudget':
return { 'account.offbudget': false };
case 'offBudget':
return { 'account.offbudget': true };

default:
throw new Error('Unhandled operator: ' + op);
}
Expand Down
14 changes: 12 additions & 2 deletions packages/loot-core/src/shared/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const TYPE_INFO = {
'doesNotContain',
'notOneOf',
'hasTags',
'onBudget',
'offBudget',
],
nullable: true,
},
Expand Down Expand Up @@ -66,12 +68,16 @@ const FIELD_INFO = {
type: 'string',
disallowedOps: new Set(['hasTags']),
},
payee: { type: 'id' },
payee: { type: 'id', disallowedOps: new Set(['onBudget', 'offBudget']) },
payee_name: { type: 'string' },
date: { type: 'date' },
notes: { type: 'string' },
amount: { type: 'number' },
category: { type: 'id', internalOps: new Set(['and']) },
category: {
type: 'id',
disallowedOps: new Set(['onBudget', 'offBudget']),
internalOps: new Set(['and']),
},
account: { type: 'id' },
cleared: { type: 'boolean' },
reconciled: { type: 'boolean' },
Expand Down Expand Up @@ -200,6 +206,10 @@ export function friendlyOp(op, type?) {
return t('and');
case 'or':
return 'or';
case 'onBudget':
return 'on budget';
case 'offBudget':
return 'off budget';
default:
return '';
}
Expand Down
6 changes: 5 additions & 1 deletion packages/loot-core/src/types/models/rule.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export type RuleConditionOp =
| 'doesNotContain'
| 'hasTags'
| 'and'
| 'matches';
| 'matches'
| 'onBudget'
| 'offBudget';

type FieldValueTypes = {
account: string;
Expand Down Expand Up @@ -76,6 +78,8 @@ export type RuleConditionEntity =
| 'contains'
| 'doesNotContain'
| 'matches'
| 'onBudget'
| 'offBudget'
>
| BaseConditionEntity<
'category',
Expand Down
6 changes: 6 additions & 0 deletions upcoming-release-notes/3891.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
category: Enhancements
authors: [lelemm]
---

Filter accounts when on budget or off budget

0 comments on commit 1b0bebf

Please sign in to comment.