History fixes

This commit is contained in:
Hillel Coren 2020-02-20 22:22:49 +02:00
parent d64754864e
commit 2bd9513050
9 changed files with 105 additions and 56 deletions

View File

@ -13,6 +13,10 @@ class EntityType extends EnumClass {
static Serializer<EntityType> get serializer => _$entityTypeSerializer;
static const EntityType dashboard = _$dashboard;
static const EntityType reports = _$reports;
static const EntityType settings = _$settings;
static const EntityType taxRate = _$taxRate;
static const EntityType companyGateway = _$companyGateway;
static const EntityType invoice = _$invoice;

View File

@ -6,6 +6,9 @@ part of 'entities.dart';
// BuiltValueGenerator
// **************************************************************************
const EntityType _$dashboard = const EntityType._('dashboard');
const EntityType _$reports = const EntityType._('reports');
const EntityType _$settings = const EntityType._('settings');
const EntityType _$taxRate = const EntityType._('taxRate');
const EntityType _$companyGateway = const EntityType._('companyGateway');
const EntityType _$invoice = const EntityType._('invoice');
@ -43,6 +46,12 @@ const EntityType _$font = const EntityType._('font');
EntityType _$typeValueOf(String name) {
switch (name) {
case 'dashboard':
return _$dashboard;
case 'reports':
return _$reports;
case 'settings':
return _$settings;
case 'taxRate':
return _$taxRate;
case 'companyGateway':
@ -118,6 +127,9 @@ EntityType _$typeValueOf(String name) {
final BuiltSet<EntityType> _$typeValues =
new BuiltSet<EntityType>(const <EntityType>[
_$dashboard,
_$reports,
_$settings,
_$taxRate,
_$companyGateway,
_$invoice,

View File

@ -450,7 +450,8 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
//return 'History: $historyList';
//return 'Report State: ${uiState.reportsUIState}, Settings: ${userCompany.settings}';
//return 'UserCompany Settngs: ${userCompany.settings}, User Settings: ${user.userCompany.settings}';
return 'Currency Map: ${staticState.currencyMap}';
//return 'Currency Map: ${staticState.currencyMap}';
//return 'History: $historyList';
return 'Layout: ${prefState.appLayout}, Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
}
}

View File

@ -7,6 +7,7 @@ import 'package:invoiceninja_flutter/redux/client/client_actions.dart';
import 'package:invoiceninja_flutter/redux/company/company_actions.dart';
import 'package:invoiceninja_flutter/redux/company/company_state.dart';
import 'package:invoiceninja_flutter/redux/company_gateway/company_gateway_actions.dart';
import 'package:invoiceninja_flutter/redux/dashboard/dashboard_actions.dart';
import 'package:invoiceninja_flutter/redux/expense/expense_actions.dart';
import 'package:invoiceninja_flutter/redux/group/group_actions.dart';
import 'package:invoiceninja_flutter/redux/invoice/invoice_actions.dart';
@ -14,6 +15,7 @@ import 'package:invoiceninja_flutter/redux/payment/payment_actions.dart';
import 'package:invoiceninja_flutter/redux/product/product_actions.dart';
import 'package:invoiceninja_flutter/redux/project/project_actions.dart';
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/settings/settings_actions.dart'
as prefix0;
@ -297,6 +299,15 @@ Reducer<BuiltList<HistoryRecord>> historyReducer = combineReducers([
}
},
),
TypedReducer<BuiltList<HistoryRecord>, ViewDashboard>((historyList, action) =>
_addToHistory(
historyList, HistoryRecord(entityType: EntityType.dashboard))),
TypedReducer<BuiltList<HistoryRecord>, ViewReports>((historyList, action) =>
_addToHistory(
historyList, HistoryRecord(entityType: EntityType.reports))),
TypedReducer<BuiltList<HistoryRecord>, ViewSettings>((historyList, action) =>
_addToHistory(
historyList, HistoryRecord(entityType: EntityType.settings))),
TypedReducer<BuiltList<HistoryRecord>, ViewClient>((historyList, action) =>
_addToHistory(historyList,
HistoryRecord(id: action.clientId, entityType: EntityType.client))),
@ -391,7 +402,7 @@ Reducer<BuiltList<HistoryRecord>> historyReducer = combineReducers([
BuiltList<HistoryRecord> _addToHistory(
BuiltList<HistoryRecord> list, HistoryRecord record) {
// don't track new records
if (record.id == null || record.id.startsWith('-')) {
if (record.id != null && record.id.startsWith('-')) {
return list;
}

View File

@ -171,8 +171,8 @@ class AppSidebarMode extends EnumClass {
abstract class HistoryRecord
implements Built<HistoryRecord, HistoryRecordBuilder> {
factory HistoryRecord({
@required String id,
@required EntityType entityType,
String id,
}) {
return _$HistoryRecord._(
id: id,

View File

@ -1,4 +1,3 @@
import 'package:built_collection/built_collection.dart';
import 'package:invoiceninja_flutter/data/models/entities.dart';
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/redux/client/client_actions.dart';
@ -14,7 +13,6 @@ import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_state.dart';
import 'package:invoiceninja_flutter/redux/product/product_reducer.dart';
import 'package:invoiceninja_flutter/redux/invoice/invoice_reducer.dart';
import 'package:invoiceninja_flutter/ui/app/screen_imports.dart';
import 'package:redux/redux.dart';
import 'package:invoiceninja_flutter/redux/document/document_reducer.dart';
import 'package:invoiceninja_flutter/redux/expense/expense_reducer.dart';
@ -23,7 +21,6 @@ import 'package:invoiceninja_flutter/redux/project/project_reducer.dart';
import 'package:invoiceninja_flutter/redux/quote/quote_reducer.dart';
import 'package:invoiceninja_flutter/redux/task/task_reducer.dart';
import 'package:invoiceninja_flutter/redux/vendor/vendor_reducer.dart';
// STARTER: import - do not remove comment
import 'package:invoiceninja_flutter/redux/user/user_reducer.dart';
import 'package:invoiceninja_flutter/redux/tax_rate/tax_rate_reducer.dart';
@ -66,12 +63,6 @@ UIState uiReducer(UIState state, dynamic action) {
.replace(settingsUIReducer(state.settingsUIState, action)));
}
Reducer<BuiltList<String>> routeHistoryReducer = combineReducers([
TypedReducer<BuiltList<String>, ViewDashboard>((history, action) {
return history.rebuild((b) => b..add(DashboardScreenBuilder.route));
}),
]);
Reducer<String> filterReducer = combineReducers([
TypedReducer<String, FilterCompany>((filter, action) {
return action.filter;

View File

@ -34,12 +34,15 @@ class HistoryDrawer extends StatelessWidget {
final widgets = <Widget>[];
for (var history in state.historyList) {
final entity =
state.getEntityMap(history.entityType)[history.id] as BaseEntity;
final entityMap = state.getEntityMap(history.entityType);
if (entity == null || (entity.isDeleted ?? false)) {
if (entityMap != null) {
final entity = entityMap[history.id] as BaseEntity;
if (entity?.isDeleted == true) {
continue;
}
}
widgets.add(HistoryListTile(
history: history,
@ -104,10 +107,24 @@ class _HistoryListTileState extends State<HistoryListTile> {
final state = store.state;
final history = widget.history;
final entity =
state.getEntityMap(history.entityType)[history.id] as BaseEntity;
Widget text;
String clientId;
BaseEntity entity;
if ([
EntityType.dashboard,
EntityType.reports,
EntityType.settings,
].contains(history.entityType)) {
text = Text(localization.lookup(history.entityType.toString()));
} else {
entity = state.getEntityMap(history.entityType)[history.id] as BaseEntity;
if (entity == null) {
return SizedBox();
}
switch (history.entityType) {
case EntityType.invoice:
clientId = (entity as InvoiceEntity).clientId;
@ -126,17 +143,22 @@ class _HistoryListTileState extends State<HistoryListTile> {
break;
}
text = Text(entity.listDisplayName.isEmpty
? formatNumber(entity.listDisplayAmount, context,
formatNumberType: entity.listDisplayAmountType)
: entity.listDisplayName);
}
return Container(
//onEnter: (event) => setState(() => _isHovered = true),
//onExit: (event) => setState(() => _isHovered = false),
child: ListTile(
key: ValueKey('__${history.id}_${history.entityType}__'),
leading: Icon(getEntityIcon(history.entityType)),
title: Text(entity.listDisplayName.isEmpty
? formatNumber(entity.listDisplayAmount, context,
formatNumberType: entity.listDisplayAmountType)
: entity.listDisplayName),
subtitle: Text(localization.lookup('${history.entityType}')),
title: text,
subtitle: history.id == null
? null
: Text(localization.lookup('${history.entityType}')),
// TODO this needs to be localized
trailing: LiveText(
() => timeago.format(history.dateTime, locale: 'en_short'),
@ -191,7 +213,9 @@ class _HistoryListTileState extends State<HistoryListTile> {
entityId: history.id,
entityType: history.entityType);
},
onLongPress: () {
onLongPress: entity == null
? null
: () {
showEntityActionsDialog(
context: context,
entities: [entity],

View File

@ -191,9 +191,7 @@ class MenuDrawer extends StatelessWidget {
children: <Widget>[
DrawerTile(
company: company,
icon: kIsWeb
? Icons.dashboard
: FontAwesomeIcons.tachometerAlt,
icon: getEntityIcon(EntityType.dashboard),
title: localization.dashboard,
onTap: () => store.dispatch(
ViewDashboard(navigator: Navigator.of(context))),
@ -257,7 +255,7 @@ class MenuDrawer extends StatelessWidget {
// STARTER: menu - do not remove comment
DrawerTile(
company: company,
icon: FontAwesomeIcons.chartLine,
icon: getEntityIcon(EntityType.reports),
title: localization.reports,
onTap: () {
store.dispatch(
@ -266,7 +264,7 @@ class MenuDrawer extends StatelessWidget {
),
DrawerTile(
company: company,
icon: FontAwesomeIcons.cog,
icon: getEntityIcon(EntityType.settings),
title: localization.settings,
onTap: () {
store.dispatch(ViewSettings(
@ -338,7 +336,9 @@ class _DrawerTileState extends State<DrawerTile> {
? kDashboard
: widget.title == localization.settings
? kSettings
: widget.title == localization.reports ? kReports : widget.entityType.name;
: widget.title == localization.reports
? kReports
: widget.entityType.name;
Widget trailingWidget;
if (!state.prefState.isMenuCollapsed) {

View File

@ -55,6 +55,12 @@ IconData getEntityActionIcon(EntityAction entityAction) {
IconData getEntityIcon(EntityType entityType) {
switch (entityType) {
case EntityType.dashboard:
return FontAwesomeIcons.tachometerAlt;
case EntityType.reports:
return FontAwesomeIcons.chartLine;
case EntityType.settings:
return FontAwesomeIcons.cog;
case EntityType.product:
return FontAwesomeIcons.cube;
case EntityType.project: