Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix: Update to latest KnowledgePanel API changes (#294)
  • Loading branch information
jasmeet0817 committed Nov 16, 2021
1 parent 797339d commit 5163db5
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 93 deletions.
67 changes: 27 additions & 40 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 @@ -62,63 +42,57 @@ enum Evaluation {
GOOD,
@JsonValue('neutral')
NEUTRAL,
@JsonValue('average')
AVERAGE,
@JsonValue('bad')
BAD,
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 +113,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 +137,8 @@ class TitleElement extends JsonObject {
const TitleElement({
required this.title,
this.subtitle,
this.grade,
this.type,
this.iconUrl,
this.iconColorFromEvaluation,
});
Expand Down
69 changes: 34 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

0 comments on commit 5163db5

Please sign in to comment.