You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2021/12/22 17:29:32 UTC
[superset] 04/04: feat: configure force_screenshot
This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch ch24621c
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 4ba8331b4a4c4c879dc6d8543c4aab8b7e146a70
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Sun Dec 12 13:51:46 2021 -0800
feat: configure force_screenshot
---
.../src/views/CRUD/alert/AlertReportModal.tsx | 54 ++++++++++++++++------
superset-frontend/src/views/CRUD/alert/types.ts | 1 +
superset/reports/api.py | 2 +
3 files changed, 43 insertions(+), 14 deletions(-)
diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx
index 942389e..a9d8473 100644
--- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx
+++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx
@@ -42,6 +42,7 @@ import Select, { propertyComparator } from 'src/components/Select/Select';
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
import withToasts from 'src/components/MessageToasts/withToasts';
import Owner from 'src/types/Owner';
+import { Checkbox } from 'src/common/components';
import TextAreaControl from 'src/explore/components/controls/TextAreaControl';
import { useCommonConf } from 'src/views/CRUD/data/database/state';
import {
@@ -154,7 +155,6 @@ const DEFAULT_ALERT = {
sql: '',
validator_config_json: {},
validator_type: '',
- force_screenshot: true,
grace_period: undefined,
};
@@ -341,6 +341,10 @@ const StyledRadioGroup = styled(Radio.Group)`
margin-left: ${({ theme }) => theme.gridUnit * 5.5}px;
`;
+const StyledCheckbox = styled(Checkbox)`
+ margin-left: ${({ theme }) => theme.gridUnit * 5.5}px;
+`;
+
// Notification Method components
const StyledNotificationAddButton = styled.div`
color: ${({ theme }) => theme.colors.primary.dark1};
@@ -417,6 +421,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
const [reportFormat, setReportFormat] = useState<string>(
DEFAULT_NOTIFICATION_FORMAT,
);
+ const [forceScreenshot, setForceScreenshot] = useState<boolean>(false);
// Dropdown options
const [conditionNotNull, setConditionNotNull] = useState<boolean>(false);
@@ -513,7 +518,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
const data: any = {
...currentAlert,
type: isReport ? 'Report' : 'Alert',
- force_screenshot: contentType === 'chart' && !isReport ? 'true' : 'false',
+ force_screenshot: forceScreenshot ? 'true' : 'false',
validator_type: conditionNotNull ? 'not null' : 'operator',
validator_config_json: conditionNotNull
? {}
@@ -866,6 +871,10 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
setReportFormat(target.value);
};
+ const onForceScreenshotChange = (event: any) => {
+ setForceScreenshot(event.target.checked);
+ };
+
// Make sure notification settings has the required info
const checkNotificationSettings = () => {
if (!notificationSettings.length) {
@@ -927,6 +936,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
(!currentAlert || currentAlert.id || (isHidden && show))
) {
setCurrentAlert({ ...DEFAULT_ALERT });
+ setForceScreenshot(!isReport);
setNotificationSettings([]);
setNotificationAddState('active');
}
@@ -969,6 +979,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
if (resource.chart) {
setChartVizType((resource.chart as ChartObject).viz_type);
+ setForceScreenshot(resource.force_screenshot);
}
setCurrentAlert({
@@ -1339,18 +1350,33 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
onChange={onDashboardChange}
/>
{formatOptionEnabled && (
- <div className="inline-container">
- <StyledRadioGroup
- onChange={onFormatChange}
- value={reportFormat}
- >
- <StyledRadio value="PNG">{t('Send as PNG')}</StyledRadio>
- <StyledRadio value="CSV">{t('Send as CSV')}</StyledRadio>
- {TEXT_BASED_VISUALIZATION_TYPES.includes(chartVizType) && (
- <StyledRadio value="TEXT">{t('Send as text')}</StyledRadio>
- )}
- </StyledRadioGroup>
- </div>
+ <>
+ <div className="inline-container">
+ <StyledRadioGroup
+ onChange={onFormatChange}
+ value={reportFormat}
+ >
+ <StyledRadio value="PNG">{t('Send as PNG')}</StyledRadio>
+ <StyledRadio value="CSV">{t('Send as CSV')}</StyledRadio>
+ {TEXT_BASED_VISUALIZATION_TYPES.includes(chartVizType) && (
+ <StyledRadio value="TEXT">
+ {t('Send as text')}
+ </StyledRadio>
+ )}
+ </StyledRadioGroup>
+ </div>
+ {isReport && (
+ <div className="inline-container">
+ <StyledCheckbox
+ className="checkbox"
+ checked={forceScreenshot}
+ onChange={onForceScreenshotChange}
+ >
+ Ignore cache when generating screenshot
+ </StyledCheckbox>
+ </div>
+ )}
+ </>
)}
<StyledSectionTitle>
<h4>{t('Notification method')}</h4>
diff --git a/superset-frontend/src/views/CRUD/alert/types.ts b/superset-frontend/src/views/CRUD/alert/types.ts
index 1c40cdb..ef320b5 100644
--- a/superset-frontend/src/views/CRUD/alert/types.ts
+++ b/superset-frontend/src/views/CRUD/alert/types.ts
@@ -68,6 +68,7 @@ export type AlertObject = {
dashboard?: MetaObject;
database?: MetaObject;
description?: string;
+ force_screenshot: boolean;
grace_period?: number;
id: number;
last_eval_dttm?: number;
diff --git a/superset/reports/api.py b/superset/reports/api.py
index 1a5907f..7d8d548 100644
--- a/superset/reports/api.py
+++ b/superset/reports/api.py
@@ -92,6 +92,7 @@ class ReportScheduleRestApi(BaseSupersetModelRestApi):
"database.database_name",
"database.id",
"description",
+ "force_screenshot",
"grace_period",
"last_eval_dttm",
"last_state",
@@ -151,6 +152,7 @@ class ReportScheduleRestApi(BaseSupersetModelRestApi):
"dashboard",
"database",
"description",
+ "force_screenshot",
"grace_period",
"log_retention",
"name",