Persist table sorting
This commit is contained in:
parent
faba03b94f
commit
d8fe1c4573
|
|
@ -234,7 +234,7 @@ class FilterClients implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortClients implements PersistUI {
|
||||
class SortClients implements PersistUI, PersistPrefs {
|
||||
SortClients(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@ class FilterCompanyGateways implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortCompanyGateways implements PersistUI {
|
||||
class SortCompanyGateways implements PersistUI, PersistPrefs {
|
||||
SortCompanyGateways(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ class FilterCredits implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortCredits implements PersistUI {
|
||||
class SortCredits implements PersistUI, PersistPrefs {
|
||||
SortCredits(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class FilterDesigns implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortDesigns implements PersistUI {
|
||||
class SortDesigns implements PersistUI, PersistPrefs {
|
||||
SortDesigns(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -206,7 +206,7 @@ class FilterDocuments implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortDocuments implements PersistUI {
|
||||
class SortDocuments implements PersistUI, PersistPrefs {
|
||||
SortDocuments(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ class FilterExpenses implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortExpenses implements PersistUI {
|
||||
class SortExpenses implements PersistUI, PersistPrefs {
|
||||
SortExpenses(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class FilterExpenseCategories implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortExpenseCategories implements PersistUI {
|
||||
class SortExpenseCategories implements PersistUI, PersistPrefs {
|
||||
SortExpenseCategories(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -200,7 +200,7 @@ class FilterGroups implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortGroups implements PersistUI {
|
||||
class SortGroups implements PersistUI, PersistPrefs {
|
||||
SortGroups(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -410,7 +410,7 @@ class FilterInvoices implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortInvoices implements PersistUI {
|
||||
class SortInvoices implements PersistUI, PersistPrefs {
|
||||
SortInvoices(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ class FilterPayments implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortPayments implements PersistUI {
|
||||
class SortPayments implements PersistUI, PersistPrefs {
|
||||
SortPayments(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ class FilterPaymentTerms implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortPaymentTerms implements PersistUI {
|
||||
class SortPaymentTerms implements PersistUI, PersistPrefs {
|
||||
SortPaymentTerms(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -188,7 +188,7 @@ class FilterProducts implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortProducts implements PersistUI {
|
||||
class SortProducts implements PersistUI, PersistPrefs {
|
||||
SortProducts(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ class FilterProjects implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortProjects implements PersistUI {
|
||||
class SortProjects implements PersistUI, PersistPrefs {
|
||||
SortProjects(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -347,7 +347,7 @@ class FilterQuotes implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortQuotes implements PersistUI {
|
||||
class SortQuotes implements PersistUI, PersistPrefs {
|
||||
SortQuotes(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -308,7 +308,7 @@ class FilterRecurringInvoices implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortRecurringInvoices implements PersistUI {
|
||||
class SortRecurringInvoices implements PersistUI, PersistPrefs {
|
||||
SortRecurringInvoices(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class FilterSubscriptions implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortSubscriptions implements PersistUI {
|
||||
class SortSubscriptions implements PersistUI, PersistPrefs {
|
||||
SortSubscriptions(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -257,7 +257,7 @@ class FilterTasks implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortTasks implements PersistUI {
|
||||
class SortTasks implements PersistUI, PersistPrefs {
|
||||
SortTasks(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -202,7 +202,7 @@ class FilterTaskStatuses implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortTaskStatuses implements PersistUI {
|
||||
class SortTaskStatuses implements PersistUI, PersistPrefs {
|
||||
SortTaskStatuses(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ class FilterTaxRates implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortTaxRates implements PersistUI {
|
||||
class SortTaxRates implements PersistUI, PersistPrefs {
|
||||
SortTaxRates(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ class FilterTokens implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortTokens implements PersistUI {
|
||||
class SortTokens implements PersistUI, PersistPrefs {
|
||||
SortTokens(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import 'package:invoiceninja_flutter/redux/quote/quote_actions.dart';
|
|||
import 'package:invoiceninja_flutter/redux/reports/reports_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/settings/settings_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/task/task_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/tax_rate/tax_rate_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
|
||||
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
||||
import 'package:invoiceninja_flutter/redux/user/user_actions.dart';
|
||||
|
|
@ -62,11 +63,86 @@ PrefState prefReducer(
|
|||
..requireAuthentication =
|
||||
requireAuthenticationReducer(state.requireAuthentication, action)
|
||||
..colorTheme = colorThemeReducer(state.colorTheme, action)
|
||||
..useSidebarEditor
|
||||
.replace(sidebarEditorReducer(state.useSidebarEditor, action)),
|
||||
..useSidebarEditor.replace(
|
||||
sidebarEditorReducer(state.useSidebarEditor, action),
|
||||
)
|
||||
..sortFields.replace(sortFieldsReducer(state.sortFields, action)),
|
||||
);
|
||||
}
|
||||
|
||||
BuiltMap<EntityType, PrefStateSortField> _resortFields(
|
||||
BuiltMap<EntityType, PrefStateSortField> value,
|
||||
EntityType entityType,
|
||||
String field) {
|
||||
final sortField = value[entityType] ?? PrefStateSortField(field);
|
||||
final directon = sortField.rebuild((b) => b
|
||||
..ascending = sortField.field != field || !sortField.ascending
|
||||
..field = field);
|
||||
return value.rebuild((b) => b..[entityType] = directon);
|
||||
}
|
||||
|
||||
Reducer<BuiltMap<EntityType, PrefStateSortField>> sortFieldsReducer =
|
||||
combineReducers([
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortClients>(
|
||||
(value, action) => _resortFields(value, EntityType.client, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortProducts>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.product, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortInvoices>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.invoice, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortPayments>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.payment, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortRecurringInvoices>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.recurringInvoice, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortQuotes>(
|
||||
(value, action) => _resortFields(value, EntityType.quote, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortCredits>(
|
||||
(value, action) => _resortFields(value, EntityType.credit, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortProjects>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.project, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortTasks>(
|
||||
(value, action) => _resortFields(value, EntityType.task, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortVendors>(
|
||||
(value, action) => _resortFields(value, EntityType.vendor, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortExpenses>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.expense, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortPaymentTerms>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.payment, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortTaxRates>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.taxRate, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortCompanyGateways>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.companyGateway, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortUsers>(
|
||||
(value, action) => _resortFields(value, EntityType.user, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortGroups>(
|
||||
(value, action) => _resortFields(value, EntityType.group, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortDesigns>(
|
||||
(value, action) => _resortFields(value, EntityType.design, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortTokens>(
|
||||
(value, action) => _resortFields(value, EntityType.token, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortWebhooks>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.webhook, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortExpenseCategories>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.expenseCategory, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortTaskStatuses>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.taskStatus, action.field)),
|
||||
TypedReducer<BuiltMap<EntityType, PrefStateSortField>, SortSubscriptions>(
|
||||
(value, action) =>
|
||||
_resortFields(value, EntityType.subscription, action.field)),
|
||||
// TODO add to starter.sh
|
||||
]);
|
||||
|
||||
Reducer<BuiltMap<EntityType, bool>> sidebarEditorReducer = combineReducers([
|
||||
TypedReducer<BuiltMap<EntityType, bool>, ToggleEditorLayout>((value, action) {
|
||||
final entityType = action.entityType;
|
||||
|
|
|
|||
|
|
@ -131,10 +131,10 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
|
|||
|
||||
abstract class PrefStateSortField
|
||||
implements Built<PrefStateSortField, PrefStateSortFieldBuilder> {
|
||||
factory PrefStateSortField() {
|
||||
factory PrefStateSortField(String field) {
|
||||
return _$PrefStateSortField._(
|
||||
field: '',
|
||||
ascending: false,
|
||||
field: field ?? '',
|
||||
ascending: true,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ class FilterUsers {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortUsers implements PersistUI {
|
||||
class SortUsers implements PersistUI, PersistPrefs {
|
||||
SortUsers(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -229,7 +229,7 @@ class FilterVendors implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortVendors implements PersistUI {
|
||||
class SortVendors implements PersistUI, PersistPrefs {
|
||||
SortVendors(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ class FilterWebhooks implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortWebhooks implements PersistUI {
|
||||
class SortWebhooks implements PersistUI, PersistPrefs {
|
||||
SortWebhooks(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
|
|
@ -210,7 +210,7 @@ class FilterStubs implements PersistUI {
|
|||
final String filter;
|
||||
}
|
||||
|
||||
class SortStubs implements PersistUI {
|
||||
class SortStubs implements PersistUI, PersistPrefs {
|
||||
SortStubs(this.field);
|
||||
|
||||
final String field;
|
||||
|
|
|
|||
Loading…
Reference in New Issue