fixed some issues and added label and, or capability

This commit is contained in:
davmar
2026-09-10 22:45:25 +02:00
parent b4d367f056
commit 6cc0de8945
14 changed files with 217 additions and 39 deletions
+1
View File
@@ -95,6 +95,7 @@ Migrations live in [`pocketbase/pb_migrations/`](pocketbase/pb_migrations/). The
| `1740000003` | `overview_favourites` | | `1740000003` | `overview_favourites` |
| `1740000004`–`0006` | `home_filter_widgets` (+ half width, budget fields) | | `1740000004`–`0006` | `home_filter_widgets` (+ half width, budget fields) |
| `1740000007` | `app_prefs` (Home section toggles + Look ahead years) | | `1740000007` | `app_prefs` (Home section toggles + Look ahead years) |
| `1740000008` | `home_filter_widgets.label_match` (AND/OR) |
Built-in labels stay in the app; only **custom** labels sync. Rows are scoped per user (`user = @request.auth.id`). Built-in labels stay in the app; only **custom** labels sync. Rows are scoped per user (`user = @request.auth.id`).
+14
View File
@@ -86,6 +86,7 @@ class HomeFilterWidget {
this.budgetFixedAmount = 0, this.budgetFixedAmount = 0,
this.budgetAverageMonths = 3, this.budgetAverageMonths = 3,
this.labelIds = const [], this.labelIds = const [],
this.labelMatch = LabelMatchMode.and,
this.flow = TxFlowFilter.all, this.flow = TxFlowFilter.all,
this.amountRange = const TxAmountRange(), this.amountRange = const TxAmountRange(),
this.query = '', this.query = '',
@@ -115,6 +116,10 @@ class HomeFilterWidget {
final int budgetAverageMonths; final int budgetAverageMonths;
final List<String> labelIds; final List<String> labelIds;
/// AND vs OR when multiple [labelIds] are selected.
final LabelMatchMode labelMatch;
final TxFlowFilter flow; final TxFlowFilter flow;
final TxAmountRange amountRange; final TxAmountRange amountRange;
final String query; final String query;
@@ -128,6 +133,7 @@ class HomeFilterWidget {
TransactionFilterSelection get filter => TransactionFilterSelection( TransactionFilterSelection get filter => TransactionFilterSelection(
labelIds: labelIds.toSet(), labelIds: labelIds.toSet(),
labelMatch: labelMatch,
flow: flow, flow: flow,
amountRange: amountRange, amountRange: amountRange,
query: query, query: query,
@@ -147,6 +153,7 @@ class HomeFilterWidget {
double? budgetFixedAmount, double? budgetFixedAmount,
int? budgetAverageMonths, int? budgetAverageMonths,
List<String>? labelIds, List<String>? labelIds,
LabelMatchMode? labelMatch,
TxFlowFilter? flow, TxFlowFilter? flow,
TxAmountRange? amountRange, TxAmountRange? amountRange,
String? query, String? query,
@@ -168,6 +175,7 @@ class HomeFilterWidget {
budgetFixedAmount: budgetFixedAmount ?? this.budgetFixedAmount, budgetFixedAmount: budgetFixedAmount ?? this.budgetFixedAmount,
budgetAverageMonths: budgetAverageMonths ?? this.budgetAverageMonths, budgetAverageMonths: budgetAverageMonths ?? this.budgetAverageMonths,
labelIds: labelIds ?? this.labelIds, labelIds: labelIds ?? this.labelIds,
labelMatch: labelMatch ?? this.labelMatch,
flow: flow ?? this.flow, flow: flow ?? this.flow,
amountRange: amountRange ?? this.amountRange, amountRange: amountRange ?? this.amountRange,
query: query ?? this.query, query: query ?? this.query,
@@ -192,6 +200,7 @@ class HomeFilterWidget {
display: display, display: display,
sortOrder: sortOrder, sortOrder: sortOrder,
labelIds: filter.labelIds.toList(growable: false), labelIds: filter.labelIds.toList(growable: false),
labelMatch: filter.labelMatch,
flow: filter.flow, flow: filter.flow,
amountRange: filter.amountRange, amountRange: filter.amountRange,
query: filter.query, query: filter.query,
@@ -215,6 +224,7 @@ class HomeFilterWidget {
'budgetFixedAmount': budgetFixedAmount, 'budgetFixedAmount': budgetFixedAmount,
'budgetAverageMonths': budgetAverageMonths, 'budgetAverageMonths': budgetAverageMonths,
'labelIds': labelIds, 'labelIds': labelIds,
'labelMatch': labelMatch.name,
'flow': flow.name, 'flow': flow.name,
'amountRange': { 'amountRange': {
if (amountRange.exact != null) 'exact': amountRange.exact, if (amountRange.exact != null) 'exact': amountRange.exact,
@@ -274,6 +284,10 @@ class HomeFilterWidget {
for (final id in (json['labelIds'] as List? ?? const [])) for (final id in (json['labelIds'] as List? ?? const []))
if (id is String && id.isNotEmpty) id, if (id is String && id.isNotEmpty) id,
], ],
labelMatch: LabelMatchMode.values.firstWhere(
(e) => e.name == json['labelMatch'],
orElse: () => LabelMatchMode.and,
),
flow: TxFlowFilter.values.firstWhere( flow: TxFlowFilter.values.firstWhere(
(e) => e.name == json['flow'], (e) => e.name == json['flow'],
orElse: () => TxFlowFilter.all, orElse: () => TxFlowFilter.all,
+9
View File
@@ -134,6 +134,15 @@ int labelVisibleDepth(
/// Filter-only id for txs with no labels (not an assignable category). /// Filter-only id for txs with no labels (not an assignable category).
const String kUncategorizedFilterId = '__uncategorized__'; const String kUncategorizedFilterId = '__uncategorized__';
/// How multiple selected labels combine in a transaction filter.
enum LabelMatchMode {
/// Tx must include every selected label.
and,
/// Tx must include at least one selected label.
or,
}
/// Chip presentation for [kUncategorizedFilterId] refine filters. /// Chip presentation for [kUncategorizedFilterId] refine filters.
const TxLabel kUncategorizedFilterLabel = TxLabel( const TxLabel kUncategorizedFilterLabel = TxLabel(
id: kUncategorizedFilterId, id: kUncategorizedFilterId,
+32 -9
View File
@@ -800,6 +800,7 @@ class TxMetaController extends ChangeNotifier {
List<BankTransaction> txs, List<BankTransaction> txs,
String query, { String query, {
Set<String> labelIds = const {}, Set<String> labelIds = const {},
LabelMatchMode labelMatch = LabelMatchMode.and,
}) { }) {
final needle = query.trim().toLowerCase(); final needle = query.trim().toLowerCase();
final hasText = needle.isNotEmpty; final hasText = needle.isNotEmpty;
@@ -809,7 +810,15 @@ class TxMetaController extends ChangeNotifier {
final labelIndex = _labelById; final labelIndex = _labelById;
return [ return [
for (final tx in txs) for (final tx in txs)
if (_matchesSearch(tx, needle, hasText, labelIds, hasLabels, labelIndex)) if (_matchesSearch(
tx,
needle,
hasText,
labelIds,
hasLabels,
labelMatch,
labelIndex,
))
tx, tx,
]; ];
} }
@@ -820,10 +829,11 @@ class TxMetaController extends ChangeNotifier {
bool hasText, bool hasText,
Set<String> labelIds, Set<String> labelIds,
bool hasLabels, bool hasLabels,
LabelMatchMode labelMatch,
Map<String, TxLabel> labelIndex, Map<String, TxLabel> labelIndex,
) { ) {
final meta = metaFor(tx); final meta = metaFor(tx);
if (hasLabels && !_matchesLabelFilter(meta, labelIds)) { if (hasLabels && !_matchesLabelFilter(meta, labelIds, labelMatch)) {
return false; return false;
} }
if (!hasText) return true; if (!hasText) return true;
@@ -838,20 +848,33 @@ class TxMetaController extends ChangeNotifier {
return false; return false;
} }
/// AND filter: every selected label must be on the tx. /// AND: every selected label must be on the tx.
/// OR: at least one selected label (or unlabeled, if that filter is set).
/// ///
/// Uncategorized alone matches unlabeled txs. Uncategorized combined with /// Uncategorized alone matches unlabeled txs. Uncategorized + others with
/// other labels matches nothing (a tx cannot be both). /// AND matches nothing; with OR matches unlabeled or any of the labels.
bool _matchesLabelFilter(TxMeta meta, Set<String> labelIds) { bool _matchesLabelFilter(
TxMeta meta,
Set<String> labelIds,
LabelMatchMode mode,
) {
final wantUncategorized = labelIds.contains(kUncategorizedFilterId); final wantUncategorized = labelIds.contains(kUncategorizedFilterId);
final required = <String>[ final required = <String>[
for (final id in labelIds) for (final id in labelIds)
if (id != kUncategorizedFilterId) id, if (id != kUncategorizedFilterId) id,
]; ];
if (wantUncategorized) { if (required.isEmpty) {
if (required.isNotEmpty) return false; if (wantUncategorized) return !meta.hasLabel;
return !meta.hasLabel; return true;
} }
if (mode == LabelMatchMode.or) {
if (wantUncategorized && !meta.hasLabel) return true;
for (final id in required) {
if (meta.labelIds.contains(id)) return true;
}
return false;
}
if (wantUncategorized) return false;
for (final id in required) { for (final id in required) {
if (!meta.labelIds.contains(id)) return false; if (!meta.labelIds.contains(id)) return false;
} }
+42 -21
View File
@@ -9,7 +9,7 @@ import '../models/transaction_meta.dart';
import '../providers/bank_provider.dart'; import '../providers/bank_provider.dart';
import '../providers/preferences_provider.dart'; import '../providers/preferences_provider.dart';
import '../providers/tx_meta_provider.dart'; import '../providers/tx_meta_provider.dart';
import '../screens/transaction_detail_screen.dart'; import '../screens/transactions_screen.dart';
import '../utils/app_theme.dart'; import '../utils/app_theme.dart';
import '../utils/helpers.dart'; import '../utils/helpers.dart';
import '../utils/look_ahead.dart'; import '../utils/look_ahead.dart';
@@ -337,17 +337,6 @@ class _LookAheadScreenState extends State<LookAheadScreen> {
), ),
], ],
), ),
const SizedBox(height: 4),
Text(
items.isEmpty
? 'Create a spending from a transaction, or tap New.'
: '${items.length} spending${items.length == 1 ? '' : 's'} · '
'projected income ${formatMoney(income, currency)} · '
'expenses ${formatMoney(expenses, currency)}.',
style: theme.textTheme.bodySmall?.copyWith(
color: colors.onSurfaceVariant,
),
),
const SizedBox(height: 10), const SizedBox(height: 10),
Row( Row(
children: [ children: [
@@ -622,6 +611,46 @@ class _TemplateTile extends StatelessWidget {
return null; return null;
} }
void _openTransactions(BuildContext context) {
final labelIds = item.labelIds.toSet();
SimilarMatchCriteria? similar;
TxFlowFilter? flow;
String? query;
if (labelIds.isEmpty) {
final tx = _sourceTx;
if (tx != null) {
// Same matching as Look ahead / apply-to-similar for this source tx.
similar = SimilarMatchCriteria(
pattern: defaultSimilarPattern(tx.description),
flow: tx.amount < 0
? TxFlowFilter.expense
: tx.amount > 0
? TxFlowFilter.income
: TxFlowFilter.all,
);
flow = similar.flow;
} else if (template != null && template!.merchantKey.isNotEmpty) {
query = template!.merchantKey;
} else {
query = item.description;
}
}
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => TransactionsScreen(
initialLabelIds: labelIds,
initialLabelMatch: LabelMatchMode.or,
initialQuery: query,
initialFlow: flow,
initialSimilarMatch: similar,
initialSearchInMonthOnly: false,
),
),
);
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final theme = Theme.of(context); final theme = Theme.of(context);
@@ -658,15 +687,7 @@ class _TemplateTile extends StatelessWidget {
color: income ? AppTheme.accent : AppTheme.expense, color: income ? AppTheme.accent : AppTheme.expense,
), ),
), ),
onTap: () { onTap: () => _openTransactions(context),
final tx = _sourceTx;
if (tx == null) return;
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => TransactionDetailScreen(tx: tx),
),
);
},
); );
} }
} }
+5 -4
View File
@@ -628,11 +628,11 @@ class _OverviewScreenState extends State<OverviewScreen> {
currency, currency,
), ),
label: switch (_labelFlow) { label: switch (_labelFlow) {
TxFlowFilter.income => 'Labeled income · $_periodTitle', TxFlowFilter.income => 'Income · $_periodTitle',
TxFlowFilter.expense => 'Labeled spend · $_periodTitle', TxFlowFilter.expense => 'Spend · $_periodTitle',
TxFlowFilter.all => _labelInvertChart TxFlowFilter.all => _labelInvertChart
? 'Labeled net (expense view) · $_periodTitle' ? 'Net (expense view) · $_periodTitle'
: 'Labeled net · $_periodTitle', : 'Net · $_periodTitle',
}, },
), ),
], ],
@@ -753,6 +753,7 @@ class _OverviewScreenState extends State<OverviewScreen> {
builder: (_) => TransactionsScreen( builder: (_) => TransactionsScreen(
initialMonth: initial, initialMonth: initial,
initialLabelIds: labelIds, initialLabelIds: labelIds,
initialLabelMatch: LabelMatchMode.or,
initialSearchInMonthOnly: !yearly && labelIds.isNotEmpty, initialSearchInMonthOnly: !yearly && labelIds.isNotEmpty,
initialYear: yearly ? period.year : null, initialYear: yearly ? period.year : null,
), ),
+43 -4
View File
@@ -30,11 +30,13 @@ class TransactionsScreen extends StatefulWidget {
super.key, super.key,
this.initialMonth, this.initialMonth,
this.initialLabelIds = const {}, this.initialLabelIds = const {},
this.initialLabelMatch = LabelMatchMode.and,
this.initialSearchInMonthOnly, this.initialSearchInMonthOnly,
this.initialYear, this.initialYear,
this.initialQuery, this.initialQuery,
this.initialFlow, this.initialFlow,
this.initialAmountRange, this.initialAmountRange,
this.initialSimilarMatch,
}); });
/// When set, opens on this calendar month instead of the current month. /// When set, opens on this calendar month instead of the current month.
@@ -43,6 +45,9 @@ class TransactionsScreen extends StatefulWidget {
/// Pre-select these label filters (e.g. from overview history). /// Pre-select these label filters (e.g. from overview history).
final Set<String> initialLabelIds; final Set<String> initialLabelIds;
/// AND vs OR for [initialLabelIds] (and later filter edits).
final LabelMatchMode initialLabelMatch;
/// When set, overrides the default "search in month" checkbox. /// When set, overrides the default "search in month" checkbox.
final bool? initialSearchInMonthOnly; final bool? initialSearchInMonthOnly;
@@ -55,6 +60,9 @@ class TransactionsScreen extends StatefulWidget {
final TxFlowFilter? initialFlow; final TxFlowFilter? initialFlow;
final TxAmountRange? initialAmountRange; final TxAmountRange? initialAmountRange;
/// Match txs the same way as “apply to similar” / Look ahead transaction source.
final SimilarMatchCriteria? initialSimilarMatch;
@override @override
State<TransactionsScreen> createState() => _TransactionsScreenState(); State<TransactionsScreen> createState() => _TransactionsScreenState();
} }
@@ -68,6 +76,8 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
DateTime? _selectedDay; DateTime? _selectedDay;
late bool _searchInMonthOnly; late bool _searchInMonthOnly;
late final Set<String> _labelFilters; late final Set<String> _labelFilters;
late LabelMatchMode _labelMatch;
SimilarMatchCriteria? _similarMatch;
int? _yearFilter; int? _yearFilter;
var _showCalendar = false; var _showCalendar = false;
var _flowFilter = TxFlowFilter.all; var _flowFilter = TxFlowFilter.all;
@@ -89,6 +99,8 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
_month = start.isAfter(now) ? now : start; _month = start.isAfter(now) ? now : start;
} }
_labelFilters = Set<String>.of(widget.initialLabelIds); _labelFilters = Set<String>.of(widget.initialLabelIds);
_labelMatch = widget.initialLabelMatch;
_similarMatch = widget.initialSimilarMatch;
// Default to current month so the list, navigator, and filter popup agree. // Default to current month so the list, navigator, and filter popup agree.
_searchInMonthOnly = widget.initialSearchInMonthOnly ?? true; _searchInMonthOnly = widget.initialSearchInMonthOnly ?? true;
_yearFilter = widget.initialYear; _yearFilter = widget.initialYear;
@@ -98,6 +110,11 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
if (initialQuery.isNotEmpty) { if (initialQuery.isNotEmpty) {
_searchController.text = initialQuery; _searchController.text = initialQuery;
_activeQuery = initialQuery; _activeQuery = initialQuery;
} else if (_similarMatch != null &&
_similarMatch!.pattern.trim().isNotEmpty) {
// Show the similar pattern in the search field for context; filtering
// uses [txMatchesSimilarCriteria], not plain text contains.
_searchController.text = _similarMatch!.pattern;
} }
} }
@@ -109,16 +126,23 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
} }
bool get _isSearching => bool get _isSearching =>
_activeQuery.trim().isNotEmpty || _labelFilters.isNotEmpty; _activeQuery.trim().isNotEmpty ||
_labelFilters.isNotEmpty ||
_similarMatch != null;
bool get _hasListFilters => bool get _hasListFilters =>
_labelFilters.isNotEmpty || _labelFilters.isNotEmpty ||
_flowFilter != TxFlowFilter.all || _flowFilter != TxFlowFilter.all ||
_amountRange.isActive; _amountRange.isActive ||
_similarMatch != null;
bool _matchesExtraFilters(BankTransaction tx, TxMetaController meta) { bool _matchesExtraFilters(BankTransaction tx, TxMetaController meta) {
if (!txMatchesFlow(tx, _flowFilter)) return false; if (!txMatchesFlow(tx, _flowFilter)) return false;
if (!txMatchesAmountRange(tx, _amountRange)) return false; if (!txMatchesAmountRange(tx, _amountRange)) return false;
final similar = _similarMatch;
if (similar != null && !txMatchesSimilarCriteria(tx, similar)) {
return false;
}
return true; return true;
} }
@@ -147,6 +171,11 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
final trimmed = value.trim(); final trimmed = value.trim();
_searchDebounceTimer?.cancel(); _searchDebounceTimer?.cancel();
// Editing the box leaves “similar match” mode and uses plain text search.
if (_similarMatch != null) {
setState(() => _similarMatch = null);
}
if (trimmed.length >= _minLiveSearchChars) { if (trimmed.length >= _minLiveSearchChars) {
// TextField updates via the controller; only rebuild the list after debounce. // TextField updates via the controller; only rebuild the list after debounce.
_searchDebounceTimer = Timer(_searchDebounce, () { _searchDebounceTimer = Timer(_searchDebounce, () {
@@ -165,13 +194,19 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
void _onSearchSubmitted(String value) { void _onSearchSubmitted(String value) {
_searchDebounceTimer?.cancel(); _searchDebounceTimer?.cancel();
setState(() => _activeQuery = value.trim()); setState(() {
_similarMatch = null;
_activeQuery = value.trim();
});
} }
void _clearSearch() { void _clearSearch() {
_searchDebounceTimer?.cancel(); _searchDebounceTimer?.cancel();
_searchController.clear(); _searchController.clear();
setState(() => _activeQuery = ''); setState(() {
_activeQuery = '';
_similarMatch = null;
});
} }
Future<void> _pickFilters(List<TxLabel> available) async { Future<void> _pickFilters(List<TxLabel> available) async {
@@ -183,6 +218,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
currentMonth: _month, currentMonth: _month,
initial: TransactionFilterSelection( initial: TransactionFilterSelection(
labelIds: Set<String>.of(_labelFilters), labelIds: Set<String>.of(_labelFilters),
labelMatch: _labelMatch,
flow: _flowFilter, flow: _flowFilter,
amountRange: _amountRange, amountRange: _amountRange,
query: _activeQuery, query: _activeQuery,
@@ -195,6 +231,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
_labelFilters _labelFilters
..clear() ..clear()
..addAll(result.labelIds); ..addAll(result.labelIds);
_labelMatch = result.labelMatch;
_flowFilter = result.flow; _flowFilter = result.flow;
_amountRange = result.amountRange; _amountRange = result.amountRange;
_searchInMonthOnly = result.monthOnly; _searchInMonthOnly = result.monthOnly;
@@ -246,6 +283,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
context, context,
initialFilter: TransactionFilterSelection( initialFilter: TransactionFilterSelection(
labelIds: Set<String>.of(_labelFilters), labelIds: Set<String>.of(_labelFilters),
labelMatch: _labelMatch,
flow: _flowFilter, flow: _flowFilter,
amountRange: _amountRange, amountRange: _amountRange,
query: _activeQuery, query: _activeQuery,
@@ -386,6 +424,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
searchPool, searchPool,
_activeQuery, _activeQuery,
labelIds: _labelFilters, labelIds: _labelFilters,
labelMatch: _labelMatch,
)) ))
if (_matchesExtraFilters(tx, metaController)) tx, if (_matchesExtraFilters(tx, metaController)) tx,
]; ];
+6
View File
@@ -534,6 +534,7 @@ class PbSyncService {
}, },
'budgetAverageMonths': r.getIntValue('budget_average_months', 3), 'budgetAverageMonths': r.getIntValue('budget_average_months', 3),
'labelIds': _jsonStringList(r.get<dynamic>('label_ids')), 'labelIds': _jsonStringList(r.get<dynamic>('label_ids')),
'labelMatch': r.getStringValue('label_match'),
'flow': r.getStringValue('flow'), 'flow': r.getStringValue('flow'),
'amountRange': rangeRaw is Map 'amountRange': rangeRaw is Map
? Map<String, dynamic>.from(rangeRaw) ? Map<String, dynamic>.from(rangeRaw)
@@ -1259,6 +1260,7 @@ class PbSyncService {
'budget_fixed_amount': w.budgetFixedAmount, 'budget_fixed_amount': w.budgetFixedAmount,
'budget_average_months': w.budgetAverageMonths, 'budget_average_months': w.budgetAverageMonths,
'label_ids': w.labelIds, 'label_ids': w.labelIds,
'label_match': w.labelMatch.name,
'flow': w.flow.name, 'flow': w.flow.name,
'amount_range': { 'amount_range': {
if (w.amountRange.exact != null) 'exact': w.amountRange.exact, if (w.amountRange.exact != null) 'exact': w.amountRange.exact,
@@ -1402,6 +1404,10 @@ class PbSyncService {
remote.getIntValue('budget_average_months', 3) == remote.getIntValue('budget_average_months', 3) ==
w.budgetAverageMonths && w.budgetAverageMonths &&
_sameIdList(remoteIds, w.labelIds) && _sameIdList(remoteIds, w.labelIds) &&
(remote.getStringValue('label_match').isEmpty
? 'and'
: remote.getStringValue('label_match')) ==
w.labelMatch.name &&
remote.getStringValue('flow') == w.flow.name && remote.getStringValue('flow') == w.flow.name &&
asDouble(rangeMap['exact']) == w.amountRange.exact && asDouble(rangeMap['exact']) == w.amountRange.exact &&
asDouble(rangeMap['min']) == w.amountRange.min && asDouble(rangeMap['min']) == w.amountRange.min &&
+1
View File
@@ -69,6 +69,7 @@ List<BankTransaction> applyTransactionFilter({
pool, pool,
filter.query, filter.query,
labelIds: filter.labelIds, labelIds: filter.labelIds,
labelMatch: filter.labelMatch,
)) ))
if (txMatchesFlow(tx, filter.flow) && if (txMatchesFlow(tx, filter.flow) &&
txMatchesAmountRange(tx, filter.amountRange)) txMatchesAmountRange(tx, filter.amountRange))
+1
View File
@@ -37,6 +37,7 @@ class HomeFilterWidgetCard extends StatelessWidget {
MaterialPageRoute<void>( MaterialPageRoute<void>(
builder: (_) => TransactionsScreen( builder: (_) => TransactionsScreen(
initialLabelIds: filter.labelIds, initialLabelIds: filter.labelIds,
initialLabelMatch: filter.labelMatch,
initialSearchInMonthOnly: initialSearchInMonthOnly:
widgetConfig.type == HomeWidgetType.budget || filter.monthOnly, widgetConfig.type == HomeWidgetType.budget || filter.monthOnly,
initialQuery: filter.query, initialQuery: filter.query,
+1
View File
@@ -55,6 +55,7 @@ Future<HomeFilterWidget?> composeHomeFilterWidget(
? HomeFilterWidget.fromFilter(name: 'Filter', filter: filter) ? HomeFilterWidget.fromFilter(name: 'Filter', filter: filter)
: existing.copyWith( : existing.copyWith(
labelIds: filter.labelIds.toList(growable: false), labelIds: filter.labelIds.toList(growable: false),
labelMatch: filter.labelMatch,
flow: filter.flow, flow: filter.flow,
amountRange: filter.amountRange, amountRange: filter.amountRange,
query: filter.query, query: filter.query,
+33 -1
View File
@@ -15,6 +15,7 @@ import 'label_parent_picker.dart';
class TransactionFilterSelection { class TransactionFilterSelection {
const TransactionFilterSelection({ const TransactionFilterSelection({
required this.labelIds, required this.labelIds,
this.labelMatch = LabelMatchMode.and,
this.flow = TxFlowFilter.all, this.flow = TxFlowFilter.all,
this.amountRange = const TxAmountRange(), this.amountRange = const TxAmountRange(),
this.query = '', this.query = '',
@@ -22,6 +23,10 @@ class TransactionFilterSelection {
}); });
final Set<String> labelIds; final Set<String> labelIds;
/// AND vs OR when more than one label is selected.
final LabelMatchMode labelMatch;
final TxFlowFilter flow; final TxFlowFilter flow;
final TxAmountRange amountRange; final TxAmountRange amountRange;
final String query; final String query;
@@ -497,6 +502,7 @@ class _TransactionFilterDialog extends StatefulWidget {
class _TransactionFilterDialogState extends State<_TransactionFilterDialog> { class _TransactionFilterDialogState extends State<_TransactionFilterDialog> {
late final Set<String> _selected; late final Set<String> _selected;
late LabelMatchMode _labelMatch;
late TxFlowFilter _flow; late TxFlowFilter _flow;
late bool _monthOnly; late bool _monthOnly;
late final TextEditingController _queryController; late final TextEditingController _queryController;
@@ -510,6 +516,7 @@ class _TransactionFilterDialogState extends State<_TransactionFilterDialog> {
super.initState(); super.initState();
final initial = widget.initial; final initial = widget.initial;
_selected = Set<String>.of(initial.labelIds); _selected = Set<String>.of(initial.labelIds);
_labelMatch = initial.labelMatch;
_flow = initial.flow; _flow = initial.flow;
_monthOnly = initial.monthOnly; _monthOnly = initial.monthOnly;
_queryController = TextEditingController(text: initial.query); _queryController = TextEditingController(text: initial.query);
@@ -593,6 +600,7 @@ class _TransactionFilterDialogState extends State<_TransactionFilterDialog> {
context, context,
TransactionFilterSelection( TransactionFilterSelection(
labelIds: Set<String>.of(_selected), labelIds: Set<String>.of(_selected),
labelMatch: _labelMatch,
flow: _flow, flow: _flow,
amountRange: _amountResult, amountRange: _amountResult,
query: _queryController.text.trim(), query: _queryController.text.trim(),
@@ -840,7 +848,10 @@ class _TransactionFilterDialogState extends State<_TransactionFilterDialog> {
), ),
onChanged: (_) => setState(() {}), onChanged: (_) => setState(() {}),
), ),
Row( Wrap(
spacing: 0,
runSpacing: 4,
crossAxisAlignment: WrapCrossAlignment.center,
children: [ children: [
TextButton( TextButton(
onPressed: () { onPressed: () {
@@ -859,6 +870,27 @@ class _TransactionFilterDialogState extends State<_TransactionFilterDialog> {
onPressed: () => setState(() => _selected.clear()), onPressed: () => setState(() => _selected.clear()),
child: const Text('No labels'), child: const Text('No labels'),
), ),
SegmentedButton<LabelMatchMode>(
style: const ButtonStyle(
visualDensity: VisualDensity.compact,
tapTargetSize: MaterialTapTargetSize.shrinkWrap,
),
showSelectedIcon: false,
segments: const [
ButtonSegment(
value: LabelMatchMode.and,
label: Text('AND'),
),
ButtonSegment(
value: LabelMatchMode.or,
label: Text('OR'),
),
],
selected: {_labelMatch},
onSelectionChanged: (selection) {
setState(() => _labelMatch = selection.first);
},
),
], ],
), ),
const SizedBox(height: 4), const SizedBox(height: 4),
@@ -0,0 +1,22 @@
/// PocketBase migration: label_match (AND/OR) on home_filter_widgets.
migrate((app) => {
const col = app.findCollectionByNameOrId("home_filter_widgets");
if (col.fields.getByName("label_match")) return;
col.fields.add(new Field({
type: "text",
name: "label_match",
required: false,
max: 16,
}));
app.save(col);
}, (app) => {
try {
const col = app.findCollectionByNameOrId("home_filter_widgets");
const field = col.fields.getByName("label_match");
if (field) {
col.fields.removeById(field.id);
app.save(col);
}
} catch (_) {}
});
+7
View File
@@ -19,12 +19,19 @@ void main() {
expect(restored.flow, TxFlowFilter.expense); expect(restored.flow, TxFlowFilter.expense);
expect(restored.monthOnly, isTrue); expect(restored.monthOnly, isTrue);
expect(restored.labelIds, ['groceries']); expect(restored.labelIds, ['groceries']);
expect(restored.labelMatch, LabelMatchMode.and);
expect(restored.showAmountOut, isTrue); expect(restored.showAmountOut, isTrue);
expect(restored.showAmountIn, isFalse); expect(restored.showAmountIn, isFalse);
expect(restored.showCount, isTrue); expect(restored.showCount, isTrue);
expect(restored.halfWidth, isFalse); expect(restored.halfWidth, isFalse);
expect(restored.type, HomeWidgetType.stats); expect(restored.type, HomeWidgetType.stats);
final withOr = widget.copyWith(labelMatch: LabelMatchMode.or);
expect(
HomeFilterWidget.fromJson(withOr.toJson()).labelMatch,
LabelMatchMode.or,
);
final budget = widget.copyWith( final budget = widget.copyWith(
halfWidth: true, halfWidth: true,
type: HomeWidgetType.budget, type: HomeWidgetType.budget,