Skip to content

Commit

Permalink
fix: 4595 - no fast track if nutriscore is not applicable (openfoodfa…
Browse files Browse the repository at this point in the history
…cts#4599)

* fix: 4595 - no fast track if nutriscore is not applicable

* fix: 4595 - added ecoscore check, and matomo
  • Loading branch information
monsieurtanuki authored Aug 26, 2023
1 parent d804222 commit 5bac720
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/smooth_app/lib/helpers/analytics_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ enum AnalyticsEvent {
tag: 'showed fast-track product edit card',
category: AnalyticsCategory.productFastTrackEdit,
),
notShowFastTrackProductEditCardNutriscore(
tag: 'nutriscore not applicable - no fast-track product edit card',
category: AnalyticsCategory.productFastTrackEdit,
),
notShowFastTrackProductEditCardEcoscore(
tag: 'ecoscore not applicable - no fast-track product edit card',
category: AnalyticsCategory.productFastTrackEdit,
),
categoriesFastTrackProductPage(
tag: 'set categories on fast track product page',
category: AnalyticsCategory.productFastTrackEdit,
Expand Down
47 changes: 47 additions & 0 deletions packages/smooth_app/lib/pages/product/product_incomplete_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/pages/product/add_new_product_page.dart';
import 'package:smooth_app/pages/product/product_field_editor.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';
Expand All @@ -20,6 +21,24 @@ class ProductIncompleteCard extends StatelessWidget {
final bool isLoggedInMandatory;

static bool isProductIncomplete(final Product product) {
bool checkScores = true;
if (_isNutriscoreNotApplicable(product)) {
AnalyticsHelper.trackEvent(
AnalyticsEvent.notShowFastTrackProductEditCardNutriscore,
barcode: product.barcode,
);
checkScores = false;
}
if (_isEcoscoreNotApplicable(product)) {
AnalyticsHelper.trackEvent(
AnalyticsEvent.notShowFastTrackProductEditCardEcoscore,
barcode: product.barcode,
);
checkScores = false;
}
if (!checkScores) {
return false;
}
final List<ProductFieldEditor> editors = <ProductFieldEditor>[
ProductFieldSimpleEditor(SimpleInputPageCategoryHelper()),
ProductFieldNutritionEditor(),
Expand All @@ -34,6 +53,34 @@ class ProductIncompleteCard extends StatelessWidget {
return false;
}

static bool _isNutriscoreNotApplicable(final Product product) =>
_isScoreNotApplicable(product, 'nutriscore');

static bool _isEcoscoreNotApplicable(final Product product) =>
_isScoreNotApplicable(product, 'ecoscore');

static bool _isScoreNotApplicable(final Product product, final String tag) =>
_getAttribute(product, tag)?.iconUrl ==
'https://static.openfoodfacts.org/images/attributes/$tag-not-applicable.svg';

// TODO(monsieurtanuki): move to off-dart (or find it there)
static Attribute? _getAttribute(final Product product, final String id) {
if (product.attributeGroups == null) {
return null;
}
for (final AttributeGroup attributeGroup in product.attributeGroups!) {
if (attributeGroup.attributes == null) {
continue;
}
for (final Attribute attribute in attributeGroup.attributes!) {
if (attribute.id == id) {
return attribute;
}
}
}
return null;
}

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
Expand Down

0 comments on commit 5bac720

Please sign in to comment.