Skip to content

Commit

Permalink
Fix bug with numerical meta automations
Browse files Browse the repository at this point in the history
  • Loading branch information
alex6480 committed Sep 24, 2023
1 parent 7105869 commit 28e0630
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 17 deletions.
2 changes: 1 addition & 1 deletion backend.models/Automation/TransactionAutomation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public class ActionSetMetaValue : TransactionAutomationAction
public override string Key => "set-meta-value";
public override int Version => 1;
public required int FieldId { get; set; }
public required object? Value { get; set; }
public required ViewSetMetaField Value { get; set; }
}

#endregion
Expand Down
10 changes: 3 additions & 7 deletions backend/Services/AutomationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,9 @@ private async Task RunAction(TransactionAutomationAction action, Transaction tra
_context.Transactions.Remove(transaction);
break;
case ActionSetMetaValue a:
await _meta.SetTransactionMetaValues(transaction.Id, user.Id, new List<ViewSetMetaField>
{
new ViewSetMetaField {
MetaId = a.FieldId,
Value = a.Value,
}
});
await _meta.SetTransactionMetaValues(
transaction.Id,
user.Id, new List<ViewSetMetaField> { a.Value });
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export function SetMetaValueEditor (props: TransactionActionEditorProps<ActionSe
}, [props.action.fieldId, fields]);

let prettyValue = "";
const value = props.action.value;
if (props.action.value !== null) {
const value = props.action.value?.value ?? null;
if (value !== null) {
switch (field?.valueType) {
case undefined:
prettyValue = "";
Expand Down Expand Up @@ -68,10 +68,17 @@ export function SetMetaValueEditor (props: TransactionActionEditorProps<ActionSe
disabled={false}
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
field={{
value: props.action.value,
value: props.action.value?.value ?? null,
type: field.valueType
} as MetaFieldType}
onChange={value => props.onChange({ ...props.action, value })}
onChange={value => props.onChange({
...props.action,
value: {
metaId: field.id,
type: field.valueType,
value
}
})}
/> }
</DefaultTransactionEditorLayout>;

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/models/automation/transactionAutomation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Decimal from "decimal.js";
import { DateTime } from "luxon";
import { SearchGroup } from "../search";
import { serializeTransactionLine, TransactionLine } from "../transaction";
import { MetaFieldValue } from "../meta";
import { serializeSetMetaFieldValue, SetMetaFieldValue } from "../meta";

export interface TransactionAutomation {
id?: number
Expand Down Expand Up @@ -82,7 +82,7 @@ export interface ActionSetCategory {
export interface ActionSetMetaValue {
key: "set-meta-value"
fieldId: number | null
value: MetaFieldValue["value"] | null
value: SetMetaFieldValue | null
}

export interface ActionDelete {
Expand All @@ -100,8 +100,8 @@ export function serializeTransactionAction (action: TransactionAction): Transact
case "set-lines":
return { ...action, value: action.value.map(serializeTransactionLine) } as any as TransactionAction;
case "set-meta-value":
if (action.value !== null && (action.value as any).id !== undefined) {
return { ...action, value: (action.value as any).id } as any as TransactionAction;
if (action.value !== null) {
return { ...action, value: serializeSetMetaFieldValue(action.value) } as any as TransactionAction;
}
return action;
default:
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/models/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function serializeSetMetaFieldValue (field: SetMetaFieldValue): SetMetaFi
field.value = (field.value as Transaction).id as any;
break;
case FieldValueType.Attachment:
// Attachments are uploaded using a separate call, so non-null values are simply set to truee
// Attachments are uploaded using a separate call, so non-null values are simply set to true
if (field.value !== null) {
field.value = true;
}
Expand Down

0 comments on commit 28e0630

Please sign in to comment.