Feature Request: Filter Payments #542

This commit is contained in:
Hillel Coren 2023-01-24 15:51:46 +02:00
parent 45cc0a3ccd
commit 92bda9742e
4 changed files with 43 additions and 12 deletions

View File

@ -358,6 +358,21 @@ abstract class PaymentEntity extends Object
return response;
}
@override
bool matchesStatuses(BuiltList<EntityStatus> statuses) {
if (statuses.isEmpty) {
return true;
}
for (final status in statuses) {
if (status.id == statusId || status.id == calculatedStatusId) {
return true;
}
}
return false;
}
@override
bool matchesFilter(String filter) {
return matchesStrings(

View File

@ -55,6 +55,7 @@ Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, SortPayments>((selectedId, action) => ''),
TypedReducer<String, FilterPayments>((selectedId, action) => ''),
TypedReducer<String, FilterPaymentsByState>((selectedId, action) => ''),
TypedReducer<String, FilterPaymentsByStatus>((selectedId, action) => ''),
TypedReducer<String, FilterPaymentsByCustom1>((selectedId, action) => ''),
TypedReducer<String, FilterPaymentsByCustom2>((selectedId, action) => ''),
TypedReducer<String, FilterPaymentsByCustom3>((selectedId, action) => ''),
@ -100,6 +101,7 @@ PaymentEntity _updateEditing(PaymentEntity payment, dynamic action) {
final paymentListReducer = combineReducers<ListUIState>([
TypedReducer<ListUIState, SortPayments>(_sortPayments),
TypedReducer<ListUIState, FilterPaymentsByState>(_filterPaymentsByState),
TypedReducer<ListUIState, FilterPaymentsByStatus>(_filterPaymentsByStatus),
TypedReducer<ListUIState, FilterPayments>(_filterPayments),
TypedReducer<ListUIState, FilterPaymentsByCustom1>(_filterPaymentsByCustom1),
TypedReducer<ListUIState, FilterPaymentsByCustom2>(_filterPaymentsByCustom2),
@ -171,6 +173,16 @@ ListUIState _filterPaymentsByState(
}
}
ListUIState _filterPaymentsByStatus(
ListUIState paymentListState, FilterPaymentsByStatus action) {
if (paymentListState.statusFilters.contains(action.status)) {
return paymentListState
.rebuild((b) => b..statusFilters.remove(action.status));
} else {
return paymentListState.rebuild((b) => b..statusFilters.add(action.status));
}
}
ListUIState _filterPayments(
ListUIState paymentListState, FilterPayments action) {
return paymentListState.rebuild((b) => b

View File

@ -110,6 +110,10 @@ List<String> filteredPaymentsSelector(
return false;
}
if (!payment.matchesStatuses(paymentListState.statusFilters)) {
return false;
}
final client =
clientMap[payment.clientId] ?? ClientEntity(id: payment.clientId);

View File

@ -38,13 +38,8 @@ class PaymentScreen extends StatelessWidget {
final statuses = [
PaymentStatusEntity().rebuild(
(b) => b
..id = kPaymentStatusPartiallyUnapplied
..name = localization.partiallyUnapplied,
),
PaymentStatusEntity().rebuild(
(b) => b
..id = kPaymentStatusUnapplied
..name = localization.unapplied,
..id = kPaymentStatusCompleted
..name = localization.completed,
),
PaymentStatusEntity().rebuild(
(b) => b
@ -61,11 +56,6 @@ class PaymentScreen extends StatelessWidget {
..id = kPaymentStatusFailed
..name = localization.failed,
),
PaymentStatusEntity().rebuild(
(b) => b
..id = kPaymentStatusCompleted
..name = localization.completed,
),
PaymentStatusEntity().rebuild(
(b) => b
..id = kPaymentStatusPartiallyRefunded
@ -76,6 +66,16 @@ class PaymentScreen extends StatelessWidget {
..id = kPaymentStatusRefunded
..name = localization.refunded,
),
PaymentStatusEntity().rebuild(
(b) => b
..id = kPaymentStatusUnapplied
..name = localization.unapplied,
),
PaymentStatusEntity().rebuild(
(b) => b
..id = kPaymentStatusPartiallyUnapplied
..name = localization.partiallyUnapplied,
),
];
return ListScaffold(