Skip to content

Commit

Permalink
fix: Fix long dashboards screenshot emails (#15954)
Browse files Browse the repository at this point in the history
* create serialize json function

* create new setting for reports

* cleanup

* address comments

* up the attributes
  • Loading branch information
hughhhh authored Aug 2, 2021
1 parent 41e8190 commit 4cb79e5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ max-statements=50
max-parents=7

# Maximum number of attributes for a class (see R0902).
max-attributes=7
max-attributes=8

# Minimum number of public methods for a class (see R0903).
min-public-methods=2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,10 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
rootChildId !== DASHBOARD_GRID_ID
? dashboardLayout[rootChildId]
: undefined;
const isStandalone = getUrlParam(URL_PARAMS.standalone);
const StandaloneMode = getUrlParam(URL_PARAMS.standalone);
const isReport = StandaloneMode === DashboardStandaloneMode.REPORT;
const hideDashboardHeader =
isStandalone === DashboardStandaloneMode.HIDE_NAV_AND_TITLE;
StandaloneMode === DashboardStandaloneMode.HIDE_NAV_AND_TITLE || isReport;

const barTopOffset =
(hideDashboardHeader ? 0 : HEADER_HEIGHT) +
Expand All @@ -210,7 +211,7 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {

const offset =
FILTER_BAR_HEADER_HEIGHT +
(isSticky || isStandalone ? 0 : MAIN_HEADER_HEIGHT) +
(isSticky || StandaloneMode ? 0 : MAIN_HEADER_HEIGHT) +
(filterSetEnabled ? FILTER_BAR_TABS_HEIGHT : 0);

const filterBarHeight = `calc(100vh - ${offset}px)`;
Expand Down Expand Up @@ -255,7 +256,7 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
<div>
{!hideDashboardHeader && <DashboardHeader />}
{dropIndicatorProps && <div {...dropIndicatorProps} />}
{topLevelTabs && (
{!isReport && topLevelTabs && (
<WithPopoverMenu
shouldFocus={shouldFocusTabs}
menuItems={[
Expand Down
1 change: 1 addition & 0 deletions superset-frontend/src/dashboard/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ export const ALL_FILTERS_ROOT = 'ALL_FILTERS_ROOT';
export enum DashboardStandaloneMode {
HIDE_NAV = 1,
HIDE_NAV_AND_TITLE = 2,
REPORT = 3,
}
14 changes: 14 additions & 0 deletions superset/utils/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# under the License.

import logging
from enum import Enum
from time import sleep
from typing import Any, Dict, Optional, Tuple, TYPE_CHECKING

Expand All @@ -42,6 +43,12 @@
from flask_appbuilder.security.sqla.models import User


class DashboardStandaloneMode(Enum):
HIDE_NAV = 1
HIDE_NAV_AND_TITLE = 2
REPORT = 3


class WebDriverProxy:
def __init__(
self, driver_type: str, window: Optional[WindowSize] = None,
Expand Down Expand Up @@ -97,6 +104,13 @@ def get_screenshot(
self, url: str, element_name: str, user: "User",
) -> Optional[bytes]:

from requests.models import PreparedRequest

params = {"standalone": DashboardStandaloneMode.REPORT.value}
req = PreparedRequest()
req.prepare_url(url, params)
url = req.url or ""

driver = self.auth(user)
driver.set_window_size(*self._window)
driver.get(url)
Expand Down

0 comments on commit 4cb79e5

Please sign in to comment.