codeant-ai-for-open-source[bot] commented on code in PR #43755:
URL: https://github.com/apache/superset/pull/43755#discussion_r3903977484


##########
superset/utils/screenshots.py:
##########
@@ -491,3 +491,107 @@ def get_cache_key(
             "permalink_key": permalink_key,
         }
         return hash_from_dict(args)
+
+
+class DashboardPrintScreenshot(DashboardScreenshot):
+    """
+    Extends DashboardScreenshot for the browser-print PDF path.
+    Appends ?print=1 to trigger print-mode CSS and force all
+    charts to render regardless of viewport position.
+
+    Optionally accepts a font_size ('small' | 'medium' | 'large') that is
+    forwarded to the frontend via ?print_font_size=<value>.  When omitted or
+    'small', no font-size param is appended ('small' is the no-override 
default).
+
+    Optionally accepts a print_layout ('2col') that is forwarded to the
+    frontend via ?print_layout=<value>.  When omitted or '1col', no param is
+    appended (single-column is the default).
+
+    Optionally accepts a print_orientation ('portrait' | 'landscape' | 'auto')
+    that is forwarded to the frontend via ?print_orientation=<value>.
+    'portrait' (default / None) appends no param.
+    'landscape' โ†’ page.pdf(landscape=True) full-document landscape.
+    'auto' โ†’ CSS @page named pages with prefer_css_page_size=True so wide
+    tables automatically render in landscape while other pages stay portrait.
+    """
+
+    def __init__(
+        self,
+        url: str,
+        digest: str | None,
+        window_size: WindowSize | None = None,
+        thumb_size: WindowSize | None = None,
+        font_size: str | None = None,
+        print_layout: str | None = None,
+        print_orientation: str | None = None,
+    ):
+        # DashboardScreenshot.__init__ already adds standalone=3
+        super().__init__(url, digest, window_size, thumb_size)
+        # Add print=1 so the frontend applies print-mode CSS and
+        # bypasses DashboardVirtualization for all chart rows.
+        self.url = modify_url_query(self.url, print=1)
+        # Forward the font-size tier to the frontend when non-default.
+        # 'small' (or None) is the no-override tier; 'medium' and 'large'
+        # apply progressively larger CSS overrides.
+        if font_size and font_size in ("medium", "large"):
+            self.url = modify_url_query(self.url, print_font_size=font_size)
+        # Forward the layout tier to the frontend so the CSS is injected.
+        # '2col' triggers two-column adaptive layout; '1col'/None is default.
+        if print_layout == "2col":
+            self.url = modify_url_query(self.url, print_layout=print_layout)
+        # Forward the orientation to the frontend.
+        # 'portrait' (default/None) needs no URL param.
+        if print_orientation in ("landscape", "auto"):
+            self.url = modify_url_query(self.url, 
print_orientation=print_orientation)
+
+    def get_print_pdf(
+        self,
+        user: "User",
+        window_size: WindowSize | None = None,
+        log_context: str | None = None,
+        report_execution_context: ReportExecutionContext | None = None,
+        header_title: str | None = None,
+        font_size: str | None = None,
+        print_layout: str | None = None,
+        print_orientation: str | None = None,
+        tab_ids: list[str] | None = None,
+        header_content: dict[str, str] | None = None,
+        footer_content: dict[str, str] | None = None,
+    ) -> bytes | None:
+        """
+        Use Playwright's page.pdf() for native print output.
+        Returns None on any failure so callers can fall back.
+        The font_size tier is embedded in self.url (CSS overrides) via __init__
+        AND passed to the webdriver (JS overrides for inline-styled elements).
+        header_title, when provided, stamps a header and footer on every page.
+        print_layout ('2col') enables two-column adaptive layout; the URL param
+        injects the CSS and the webdriver runs ANNOTATE_PRINT_COLUMNS_JS before
+        page.pdf() to set data-print-col-span attributes on grid columns.
+        print_orientation ('portrait'|'landscape'|'auto') controls page 
rotation.
+        tab_ids, when provided (list of Superset TAB-xxx component IDs), causes
+        the webdriver to render each tab separately using a URL hash fragment
+        and merge the resulting PDFs via pypdf.
+        header_content / footer_content, when provided, override the global
+        BROWSER_PRINT_PDF_HEADER_CONTENT / BROWSER_PRINT_PDF_FOOTER_CONTENT
+        config for this specific report.
+        """
+        if not feature_flag_manager.is_feature_enabled(
+            "PLAYWRIGHT_REPORTS_AND_THUMBNAILS"
+        ):
+            return None
+        if not PLAYWRIGHT_AVAILABLE:
+            return None
+        driver = WebDriverPlaywright(self.driver_type, window_size or 
self.window_size)
+        return driver.get_print_pdf(
+            self.url,
+            user=user,
+            log_context=log_context,
+            report_execution_context=report_execution_context,
+            header_title=header_title,
+            font_size=font_size,
+            print_layout=print_layout,
+            print_orientation=print_orientation,
+            tab_ids=tab_ids,
+            header_content=header_content,
+            footer_content=footer_content,
+        )

Review Comment:
   **Suggestion:** `get_print_pdf` promises to return `None` on failures, but 
Playwright construction or PDF errors escape directly and can crash direct 
callers such as `extract_pdf.py`. [error handling]
   
   **Assessment:** ๐ŸŸ  `Major` ยท ๐Ÿ” `Occurrence: Sometimes`
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
 [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=0c339684c4274ecc9644a5d50d740111&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=0c339684c4274ecc9644a5d50d740111&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/utils/screenshots.py
   **Line:** 584:597
   **Comment:**
        *Error Handling: `get_print_pdf` promises to return `None` on failures, 
but Playwright construction or PDF errors escape directly and can crash direct 
callers such as `extract_pdf.py`.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43755&comment_hash=99ede419c88f4148ba7b539ea5d095657a95d0119ba5aacf71835f1f3c4bb86a&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43755&comment_hash=99ede419c88f4148ba7b539ea5d095657a95d0119ba5aacf71835f1f3c4bb86a&reaction=dislike'>๐Ÿ‘Ž</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to