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

feat: 5700 - no click for KP title without additional elements #5709

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ class KnowledgePanelCard extends StatelessWidget {
);
}

// in some cases there's nothing to click about.
// cf. https://github.com/openfoodfacts/smooth-app/issues/5700
final bool improvedIsClickable = isClickable &&
KnowledgePanelsBuilder.hasSomethingToDisplay(
product,
panelId,
);
return Padding(
padding: const EdgeInsets.symmetric(vertical: SMALL_SPACE),
child: InkWell(
borderRadius: ANGULAR_BORDER_RADIUS,
onTap: !isClickable
onTap: !improvedIsClickable
? null
: () async => Navigator.push<Widget>(
context,
Expand All @@ -64,7 +71,7 @@ class KnowledgePanelCard extends StatelessWidget {
),
child: KnowledgePanelsBuilder.getPanelSummaryWidget(
panel,
isClickable: isClickable,
isClickable: improvedIsClickable,
margin: EdgeInsets.zero,
) ??
const SizedBox(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ class KnowledgePanelsBuilder {
return elements.first;
}

/// Returns true if there are elements to display for that panel.
static bool hasSomethingToDisplay(
final Product product,
final String panelId,
) {
final KnowledgePanel panel =
KnowledgePanelsBuilder.getKnowledgePanel(product, panelId)!;
if (panel.elements == null) {
return false;
}
for (final KnowledgePanelElement element in panel.elements!) {
if (_hasSomethingToDisplay(element: element, product: product)) {
return true;
}
}
return false;
}

/// Returns a padded widget that displays the KP element, or rarely null.
static Widget? getElementWidget({
required final KnowledgePanelElement knowledgePanelElement,
Expand Down Expand Up @@ -180,6 +198,8 @@ class KnowledgePanelsBuilder {
}

/// Returns the widget that displays the KP element, or rarely null.
///
/// cf. [_hasSomethingToDisplay].
static Widget? _getElementWidget({
required final KnowledgePanelElement element,
required final Product product,
Expand Down Expand Up @@ -244,10 +264,33 @@ class KnowledgePanelsBuilder {
element.actionElement!,
product,
);
}
}

default:
Logs.e('unexpected element type: ${element.elementType}');
return null;
/// Returns true if the element has something to display.
///
/// cf. [_getElementWidget].
static bool _hasSomethingToDisplay({
required final KnowledgePanelElement element,
required final Product product,
}) {
switch (element.elementType) {
case KnowledgePanelElementType.TEXT:
case KnowledgePanelElementType.IMAGE:
case KnowledgePanelElementType.PANEL_GROUP:
case KnowledgePanelElementType.TABLE:
case KnowledgePanelElementType.MAP:
case KnowledgePanelElementType.ACTION:
return true;
case KnowledgePanelElementType.UNKNOWN:
return false;
case KnowledgePanelElementType.PANEL:
final String panelId = element.panelElement!.panelId;
final KnowledgePanel? panel = getKnowledgePanel(product, panelId);
if (panel == null) {
return false;
}
return true;
}
}

Expand Down
Loading