Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update to latest KnowledgePanel API changes #294

Merged
merged 45 commits into from Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
cf826ac
Merge pull request #4 from openfoodfacts/master
jasmeet0817 Oct 6, 2021
b637a01
Updates to KnowledgePanel json object to comply to latest BE changes
Oct 6, 2021
11d8e9a
Merge branch 'openfoodfacts:master' into master
jasmeet0817 Oct 6, 2021
3a9186a
Changes to KnowledgePanel to comply to BE
Oct 6, 2021
5e9b5ed
Merge branch 'openfoodfacts:master' into master
jasmeet0817 Oct 6, 2021
835a8bb
Changes to KnowledgePanel to comply to BE
Oct 6, 2021
db1d0ee
Update tests
Oct 7, 2021
8e57e32
format
Oct 7, 2021
cfbc0dc
add a comment
Oct 7, 2021
79e85da
update comment
Oct 7, 2021
c18b3dc
Add Evaluation
Oct 7, 2021
fd02795
Fix tests
Oct 7, 2021
f80c696
Add to KnowledgePanels
Oct 9, 2021
bb1ce13
Merge branch 'openfoodfacts:master' into master
jasmeet0817 Oct 9, 2021
424d2fc
Merge remote-tracking branch 'origin'
Oct 9, 2021
508d27c
Merge branch 'openfoodfacts:master' into master
jasmeet0817 Oct 11, 2021
65dba15
Remove from KnowledgePanel and add a KnowledgePanelGroupElement to p…
Oct 11, 2021
b98839e
Remove from KnowledgePanel and add a KnowledgePanelGroupElement to p…
Oct 11, 2021
45bcdcd
Remove unnecessary comments
Oct 11, 2021
d7aaf85
Fix tests
Oct 11, 2021
ed4466d
Fix build
Oct 11, 2021
a8c888c
Add a new KnowledgePanel type
Oct 12, 2021
d596e48
Add a new KnowledgePanel type
Oct 12, 2021
a0eae4a
Make elements nullable
Oct 12, 2021
5d1538d
Make elements nullable
Oct 12, 2021
c27309f
Cosmetic change
Oct 12, 2021
2724a34
Remove print
Oct 12, 2021
ae2399c
Merge branch 'openfoodfacts:master' into master
jasmeet0817 Oct 12, 2021
3158b3b
Prepare release of version 1.3.7
Oct 12, 2021
c22e5b3
Merge branch 'openfoodfacts:master' into master
jasmeet0817 Oct 19, 2021
f650d9a
Column should not have list<String> text and type
Oct 19, 2021
5a716bf
Column should not have list<String> text and type
Oct 20, 2021
d6ba226
Column should not have list<String> text and type
Oct 20, 2021
6b82401
Changes to KnowledgePanel API to comply to the server response
Oct 20, 2021
121b1ed
Merge branch 'openfoodfacts:master' into master
jasmeet0817 Oct 20, 2021
8805a50
Merge remote-tracking branch 'origin'
Oct 20, 2021
8ba12e1
Changes to KnowledgePanel API to comply to the server response
Oct 20, 2021
1e7e113
Fix tests
Oct 21, 2021
650045b
Merge branch 'openfoodfacts:master' into master
jasmeet0817 Oct 26, 2021
2eb95a3
Update KP
Nov 16, 2021
f4664e3
Merge branch 'master' of https://github.com/openfoodfacts/openfoodfac…
Nov 16, 2021
3e31210
Update KP
Nov 16, 2021
abd8663
Fix KP
Nov 16, 2021
b53b430
Fix KP
Nov 16, 2021
11e100d
Fix KP
Nov 16, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
69 changes: 27 additions & 42 deletions lib/model/KnowledgePanel.dart
Expand Up @@ -5,26 +5,6 @@ import 'KnowledgePanelElement.dart';

part 'KnowledgePanel.g.dart';

/// Type of the KnowledgePanel.
enum KnowledgePanelType {
/// Do you know types informative Knowledge Panels.
@JsonValue('doyouknow')
DO_YOU_KNOW,

/// Knowledge Panel with ecoscore information.
@JsonValue('score')
SCORE,

/// Knowledge Panel with ecoscore LCA.
@JsonValue('ecoscore_lca')
ECOSCORE_LCA,

/// Knowledge Panel which is rendered as a card on the UI.
@JsonValue('card')
CARD,
UNKNOWN,
}

/// Level of information conveyed by this KnowledgePanel.
///
/// Client may choose to display the panel based on the level.
Expand Down Expand Up @@ -60,65 +40,57 @@ enum Grade {
enum Evaluation {
@JsonValue('good')
GOOD,
@JsonValue('neutral')
NEUTRAL,
@JsonValue('average')
AVERAGE,
@JsonValue('bad')
BAD,
UNKNOWN,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why no @JsonValue('unknown') ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more value is "neutral" if I remember correctly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right: environment/packaging_recycling.tt.json: "evaluation": "neutral",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the difference between "average" and "neutral"? Can't we collapse them into one ?

Unknown: the object gets a value of enum type UNKNOWN when the json parser encounters a value from the server that isn't mappable to anything else in this enum (specifically if server responds with something other than Good, bad, average, the variable is assigned UNKNOWN).

}

/// Type of title element.
enum TitleElementType {
// Title Element depicts a grade like 'Ecoscore' or 'Nutriscore'.
@JsonValue('grade')
GRADE,
UNKNOWN,
}

/// KnowledgePanels are a standardized and generic units of information that
/// the client can display on the product page.
///
/// See http://shorturl.at/oxRS9 for details.
// NOTE: This is WIP, do not use and expect changes.
@JsonSerializable()
class KnowledgePanel extends JsonObject {
/// Panel id of the parent panel.
@JsonKey(name: 'parent_panel_id')
final String parentPanelId;

/// Title of the KnowledgePanel.
@JsonKey(name: 'title_element')
final TitleElement titleElement;
final TitleElement? titleElement;

/// Level of this KnowledgePanel. Client may choose to display the panel based
/// on the level.
@JsonKey(unknownEnumValue: Level.UNKNOWN)
final Level level;
final Level? level;

final bool? expanded;

/// KnowledgePanelElement is a single unit of KnowledgePanel that can be
/// rendered on the client.
final List<KnowledgePanelElement>? elements;

final KnowledgePanelType? type;

/// The topics discussed in this knowledge panel, example: 'Environment'.
final List<String>? topics;

/// Grade of the panel, depicting the level of impact the product has for the
/// corresponding topics. Client can choose to color code the panel depending
/// on how good/bad the grade is.
/// Scale: 'A' -> 'E'
@JsonKey(unknownEnumValue: Grade.UNKNOWN)
final Grade? grade;

/// Evaluation of the panel, depicting whether the content of the panel is
/// good/bad/neutral for the topic to which the panel applies.
@JsonKey(unknownEnumValue: Evaluation.UNKNOWN)
final Evaluation? evaluation;

const KnowledgePanel({
required this.parentPanelId,
required this.titleElement,
required this.level,
this.titleElement,
this.level,
this.expanded,
this.elements,
this.type,
this.topics,
this.grade,
this.evaluation,
});

Expand All @@ -139,6 +111,17 @@ class TitleElement extends JsonObject {
/// Subtitle of the panel. Example - 'High environmental impact'.
final String? subtitle;

/// Grade of the panel, depicting the level of impact the product has for the
/// corresponding topics. Client can choose to color code the panel depending
/// on how good/bad the grade is.
/// Scale: 'A' -> 'E'
@JsonKey(unknownEnumValue: Grade.UNKNOWN)
final Grade? grade;

/// Type of the TitleElement.
@JsonKey(unknownEnumValue: TitleElementType.UNKNOWN)
final TitleElementType? type;

/// URL of an icon representing the Panel.
@JsonKey(name: 'icon_url')
final String? iconUrl;
Expand All @@ -152,6 +135,8 @@ class TitleElement extends JsonObject {
const TitleElement({
required this.title,
this.subtitle,
this.grade,
this.type,
this.iconUrl,
this.iconColorFromEvaluation,
});
Expand Down
68 changes: 33 additions & 35 deletions lib/model/KnowledgePanel.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 15 additions & 8 deletions lib/model/KnowledgePanelElement.dart
Expand Up @@ -20,7 +20,17 @@ enum KnowledgePanelTextElementType {
/// Default type of the text element, this is just a normal description.
@JsonValue('notes')
DEFAULT,
UNKNOWN,
}

/// The type of Knowledge panel table column.
enum KnowledgePanelColumnType {
/// The column contains text elements.
@JsonValue('text')
TEXT,

/// The column has percentages.
@JsonValue('percent')
PERCENT,
}

/// Description element of the Knowledge panel.
Expand All @@ -33,7 +43,7 @@ class KnowledgePanelTextElement extends JsonObject {
/// depending upon the type.
@JsonKey(
name: 'text_type',
unknownEnumValue: KnowledgePanelTextElementType.UNKNOWN)
unknownEnumValue: KnowledgePanelTextElementType.DEFAULT)
final KnowledgePanelTextElementType? type;

const KnowledgePanelTextElement({required this.html, this.type});
Expand Down Expand Up @@ -158,7 +168,8 @@ class KnowledgePanelTableRowElement extends JsonObject {
class KnowledgePanelTableColumn extends JsonObject {
final String text;

final String type;
@JsonKey(unknownEnumValue: KnowledgePanelColumnType.TEXT)
final KnowledgePanelColumnType? type;

const KnowledgePanelTableColumn({required this.text, required this.type});

Expand All @@ -174,9 +185,6 @@ class KnowledgePanelTableColumn extends JsonObject {
class KnowledgePanelTableElement extends JsonObject {
final String id;

@JsonKey(name: 'type')
final String type;

final String title;

@JsonKey(name: 'columns')
Expand All @@ -186,7 +194,6 @@ class KnowledgePanelTableElement extends JsonObject {

const KnowledgePanelTableElement({
required this.id,
required this.type,
required this.title,
required this.columns,
required this.rows,
Expand Down Expand Up @@ -241,7 +248,7 @@ class KnowledgePanelElement extends JsonObject {
@JsonKey(name: 'panel_element')
final KnowledgePanelPanelIdElement? panelElement;

@JsonKey(name: 'panel_group')
@JsonKey(name: 'panel_group_element')
final KnowledgePanelPanelGroupElement? panelGroupElement;

/// Id of a KnowledgePanel embedded inside [this] KnowledgePanel.
Expand Down