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(ZMS-3420): Update condition to display main content only when at least #713

Merged

Conversation

ThomasAFink
Copy link
Member

@ThomasAFink ThomasAFink commented Dec 3, 2024

…one button is enabled across multiple scopes

Description

Short description or comments

Reference

Issues #XXX

Summary by CodeRabbit

  • New Features
    • Enhanced logic for button visibility based on feature status and button states.
    • Improved conditional rendering for messages related to service availability.
  • Bug Fixes
    • Resolved issues with incorrect button display when certain conditions were met.

…one button is enabled across multiple scopes
Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

The changes to the default.twig template involve a significant revision of the logic within the content block. The previous conditional structure has been replaced with a more complex flow that initializes an array and a boolean variable to manage button states. It iterates through ticketprinter.buttons to gather unique scopes and assess button enablement. The rendering logic is adjusted to display buttons based on new conditions, while preserving the display of a specific message and the notification block.

Changes

File Path Change Summary
zmsticketprinter/templates/page/customized/default.twig Revised logic in the content block to enhance button visibility and message display conditions.

Poem

In the land of buttons, bright and bold,
New logic weaves tales yet untold.
Scopes gather round, both near and far,
To show us the way, like a guiding star.
With messages clear, and buttons that gleam,
A whimsical dance, like a rabbit's dream! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (1)
zmsticketprinter/templates/page/customized/default.twig (1)

12-22: LGTM! Consider extracting scope collection logic

The initialization and scope collection logic is well-implemented. The code effectively tracks unique scopes and button states, which aligns with the PR objective.

Consider extracting the scope collection logic into a separate included template file for better maintainability, especially if this pattern is used elsewhere:

{# _collect_scopes.twig #}
{% set scopes = [] %}
{% set allButtonsDisabled = true %}
{% for button in ticketprinter.buttons %}
    {% if button.scope.id not in scopes %}
        {% set scopes = scopes|merge([button.scope.id]) %}
    {% endif %}
    {% if button.enabled %}
        {% set allButtonsDisabled = false %}
    {% endif %}
{% endfor %}
{% set number_of_scopes = scopes|length %}
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between be55757 and 17004e7.

📒 Files selected for processing (1)
  • zmsticketprinter/templates/page/customized/default.twig (1 hunks)
🔇 Additional comments (3)
zmsticketprinter/templates/page/customized/default.twig (3)

55-57: LGTM! Clean notification block implementation

The notification block implementation correctly checks department preferences before rendering.


29-29: Verify the usage of buttonLabelPrefix

The variable buttonLabelPrefix is set but its usage isn't visible in this context.

✅ Verification successful

buttonLabelPrefix is properly used in button labels across templates

The variable buttonLabelPrefix is used in templates/block/content/buttons.twig to construct button labels by concatenating it with button names. It's used in three places:

  • For the first button when there's a single button: {% set label = buttonLabelPrefix ~ ticketprinter.buttons|first.name %}
  • For multiple buttons in two different contexts: {% set label = buttonLabelPrefix ~ button.name %}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of buttonLabelPrefix
rg "buttonLabelPrefix" --type=twig -A 5

Length of output: 4214


24-24: Verify the complex display condition

The condition combines multiple checks which might be difficult to maintain. Please ensure all edge cases are covered:

  1. Single scope with all buttons enabled
  2. Single scope with mixed button states
  3. Multiple scopes with all buttons disabled
  4. Multiple scopes with mixed button states
✅ Verification successful

Let's examine the actual implementation of these conditions to better understand the logic.


Based on the code analysis, I can now generate the final response:

The complex display condition is correctly implemented

The condition (enabled and not hasDisabledButton) or (number_of_scopes > 1 and not allButtonsDisabled) is well-structured and handles all edge cases:

  • For single scope (number_of_scopes <= 1): Shows content only if enabled is true and no buttons are disabled
  • For multiple scopes (number_of_scopes > 1): Shows content if at least one button is enabled (not allButtonsDisabled)

The implementation in TicketprinterByScope.php and Index.php correctly sets these flags by checking button states, and the template properly calculates allButtonsDisabled by iterating through all buttons. The logic effectively covers all the mentioned scenarios.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for test cases covering these scenarios
rg -l "buttonDisplay.*button_single|hasDisabledButton|allButtonsDisabled" --type=php --type=twig

Length of output: 492


Script:

#!/bin/bash
# Check the implementation in PHP files
rg "hasDisabledButton|allButtonsDisabled" -A 5 --type=php

# Check template usage patterns
rg "hasDisabledButton|allButtonsDisabled" -A 5 --type=twig

# Look for test cases
rg "test.*button.*disabled|test.*scope" --type=php

Length of output: 6566

Comment on lines +36 to +52
<div style="font-size: 60px;
text-align: center;
padding: 10px;
border-radius: 5px;
font-weight: bold;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
box-sizing: border-box;
overflow: hidden;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
">Kundenservice ist geschlossen</div>
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Move inline styles to CSS file

The inline styles for the closed message should be moved to a CSS file for better maintainability and separation of concerns. Consider using a class instead.

-<div style="font-size: 60px;
-      text-align: center;
-      padding: 10px;
-      border-radius: 5px;
-      font-weight: bold;
-      display: flex;
-      justify-content: center;
-      align-items: center;
-      width: 100%;
-      height: 100%;
-      box-sizing: border-box;
-      overflow: hidden;
-      position: absolute;
-      top: 50%;
-      left: 50%;
-      transform: translate(-50%, -50%);
-      ">Kundenservice ist geschlossen</div>
+<div class="service-closed-message">Kundenservice ist geschlossen</div>

Add to your CSS file:

.service-closed-message {
    font-size: 60px;
    text-align: center;
    padding: 10px;
    border-radius: 5px;
    font-weight: bold;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

@MoDaae MoDaae merged commit e17942b into next Dec 6, 2024
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants