Improve handling of schedules that are missing a date (#601)

* Fix adding date back to a schedule that lost its date

* Propagate errors when searching matching transactions

* Make the error more visible

* Block removing the date field on schedule-linked rules
This commit is contained in:
Jed Fox
2023-02-01 14:15:36 -05:00
committed by GitHub
parent 53a0ea1b7f
commit 4bc82443fe
4 changed files with 36 additions and 4 deletions

View File

@@ -146,6 +146,7 @@ const TransactionRow = React.memo(function TransactionRow({
export default function SimpleTransactionsTable({
transactions,
schedules,
renderEmpty,
fields = ['date', 'payee', 'amount'],
style
}) {
@@ -185,6 +186,7 @@ export default function SimpleTransactionsTable({
<Table
style={style}
items={serializedTransactions}
renderEmpty={renderEmpty}
headers={
<>
<SelectCell

View File

@@ -172,6 +172,7 @@ export function ConditionEditor({
ops,
condition,
editorStyle,
isSchedule,
onChange,
onDelete,
onAdd
@@ -214,7 +215,10 @@ export function ConditionEditor({
<View style={{ flex: 1 }}>{valueEditor}</View>
<Stack direction="row">
<EditorButtons onAdd={onAdd} onDelete={onDelete} />
<EditorButtons
onAdd={onAdd}
onDelete={isSchedule && field === 'date' ? null : onDelete}
/>
</Stack>
</Editor>
);
@@ -395,6 +399,7 @@ export function ConditionsList({
conditions,
conditionFields,
editorStyle,
isSchedule,
onChangeConditions
}) {
function addCondition(index) {
@@ -523,6 +528,7 @@ export function ConditionsList({
editorStyle={editorStyle}
ops={ops}
condition={cond}
isSchedule={isSchedule}
onChange={(name, value) => {
updateCondition(cond, name, value);
}}
@@ -567,6 +573,8 @@ export default function EditRule({
let dispatch = useDispatch();
let scrollableEl = useRef();
let isSchedule = actions.some(action => action.op === 'link-schedule');
useEffect(() => {
dispatch(initiallyLoadPayees());
@@ -769,6 +777,7 @@ export default function EditRule({
conditions={conditions}
conditionFields={conditionFields}
editorStyle={editorStyle}
isSchedule={isSchedule}
onChangeConditions={conds => setConditions(conds)}
/>
</View>

View File

@@ -290,13 +290,18 @@ export default function ScheduleDetails() {
let unsubscribe;
if (state.schedule && state.transactionsMode === 'matched') {
let { conditions } = updateScheduleConditions(
let { error, conditions } = updateScheduleConditions(
state.schedule,
state.fields
);
dispatch({ type: 'set-transactions', transactions: [] });
if (error) {
dispatch({ type: 'form-error', error });
return;
}
// *Extremely* gross hack because the rules are not mapped to
// public names automatically. We really should be doing that
// at the database layer
@@ -695,6 +700,22 @@ export default function ScheduleDetails() {
)}
<SimpleTransactionsTable
renderEmpty={
state.transactionsMode === 'matched' &&
(() => (
<View
style={{ padding: 20, color: colors.n4, textAlign: 'center' }}
>
{state.error ? (
<Text style={{ color: colors.r4 }}>
Could not search: {state.error}
</Text>
) : (
'No transactions found'
)}
</View>
))
}
transactions={state.transactions}
fields={['date', 'payee', 'amount']}
style={{

View File

@@ -268,8 +268,8 @@ export async function updateSchedule({ schedule, conditions, resetNextDate }) {
oldConditions.find(c => c.field === 'account')
) ||
!deepEqual(
stripType(oldConditions.find(c => c.field === 'date')),
stripType(newConditions.find(c => c.field === 'date'))
stripType(oldConditions.find(c => c.field === 'date') || {}),
stripType(newConditions.find(c => c.field === 'date') || {})
)
) {
await setNextDate({