From f57ded2d10bd4ddb23fcd0c10ad2df1ecef9d82d Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 16 Aug 2023 13:11:22 +0300 Subject: [PATCH] Document improvments --- lib/ui/reports/document_report.dart | 96 ++++++--------------------- lib/ui/reports/reports_screen_vm.dart | 8 +-- 2 files changed, 22 insertions(+), 82 deletions(-) diff --git a/lib/ui/reports/document_report.dart b/lib/ui/reports/document_report.dart index 27c25d9b3..991544395 100644 --- a/lib/ui/reports/document_report.dart +++ b/lib/ui/reports/document_report.dart @@ -19,47 +19,28 @@ enum DocumentReportFields { height, file_type, record_type, - record_name, created_at, created_by, updated_at, } -var memoizedDocumentReport = memo10(( +var memoizedDocumentReport = memo4(( UserCompanyEntity userCompany, ReportsUIState reportsUIState, - BuiltMap clientMap, - BuiltMap productMap, - BuiltMap invoiceMap, - BuiltMap quoteMap, - BuiltMap expenseMap, - BuiltMap projectMap, - BuiltMap vendorMap, + BuiltMap documentMap, BuiltMap userMap, ) => documentReport( userCompany, reportsUIState, - clientMap, - productMap, - invoiceMap, - quoteMap, - expenseMap, - projectMap, - vendorMap, + documentMap, userMap, )); ReportResult documentReport( UserCompanyEntity userCompany, ReportsUIState reportsUIState, - BuiltMap clientMap, - BuiltMap productMap, - BuiltMap invoiceMap, - BuiltMap quoteMap, - BuiltMap expenseMap, - BuiltMap projectMap, - BuiltMap vendorMap, + BuiltMap documentMap, BuiltMap userMap, ) { final List> data = []; @@ -76,9 +57,11 @@ ReportResult documentReport( final defaultColumns = [ DocumentReportFields.record_type, - DocumentReportFields.record_name, DocumentReportFields.name, DocumentReportFields.file_type, + DocumentReportFields.size, + DocumentReportFields.width, + DocumentReportFields.height, ]; if (documentReportSettings.columns.isNotEmpty) { @@ -90,7 +73,7 @@ ReportResult documentReport( columns = BuiltList(defaultColumns); } - List _getRow(BaseEntity entity, DocumentEntity document) { + documentMap.values.forEach((document) { bool skip = false; final List row = []; @@ -110,11 +93,8 @@ ReportResult documentReport( case DocumentReportFields.created_by: value = userMap[document.createdUserId]?.listDisplayName ?? ''; break; - case DocumentReportFields.record_name: - value = entity.listDisplayName; - break; case DocumentReportFields.record_type: - value = entity.entityType; + value = document.parentType; break; case DocumentReportFields.updated_at: value = convertTimestampToDateString(document.updatedAt); @@ -141,59 +121,25 @@ ReportResult documentReport( } if (value.runtimeType == bool) { - row.add(entity.getReportBool(value: value)); + row.add(document.getReportBool(value: value)); } else if (value.runtimeType == int) { - row.add(entity.getReportInt(value: value)); + row.add(document.getReportInt(value: value)); } else if (value.runtimeType == double) { - row.add(entity.getReportDouble(value: value)); + row.add(document.getReportDouble(value: value)); } else if (value.runtimeType == EntityType) { - row.add(entity.getReportEntityType()); + row.add(ReportEntityTypeValue( + entityId: document.parentId, + entityType: document.parentType, + value: document.parentType)); } else { - row.add(entity.getReportString(value: value)); + row.add(document.getReportString(value: value)); } } - return skip ? null : row; - } - - clientMap.forEach((clientId, client) { - client.documents.forEach((document) { - final row = _getRow(client, document); - if (row != null) { - data.add(row); - entities.add(document); - } - }); - }); - - productMap.forEach((productId, product) { - product.documents.forEach((document) { - final row = _getRow(product, document); - if (row != null) { - data.add(row); - entities.add(document); - } - }); - }); - - invoiceMap.forEach((invoiceId, invoice) { - invoice.documents.forEach((document) { - final row = _getRow(invoice, document); - if (row != null) { - data.add(row); - entities.add(document); - } - }); - }); - - quoteMap.forEach((quoteId, quote) { - quote.documents.forEach((document) { - final row = _getRow(quote, document); - if (row != null) { - data.add(row); - entities.add(document); - } - }); + if (!skip) { + data.add(row); + entities.add(document); + } }); final selectedColumns = columns.map((item) => EnumUtils.parse(item)).toList(); diff --git a/lib/ui/reports/reports_screen_vm.dart b/lib/ui/reports/reports_screen_vm.dart index 7e59dbe82..a21ab863d 100644 --- a/lib/ui/reports/reports_screen_vm.dart +++ b/lib/ui/reports/reports_screen_vm.dart @@ -147,13 +147,7 @@ class ReportsScreenVM { reportResult = memoizedDocumentReport( state.userCompany, state.uiState.reportsUIState, - state.clientState.map, - state.productState.map, - state.invoiceState.map, - state.quoteState.map, - state.expenseState.map, - state.projectState.map, - state.vendorState.map, + state.documentState.map, state.userState.map, ); break;