feat: configure force_screenshot (#17855)

* Update existing tests

* Add backend test

* feat: add force option to report screenshots

* Add tests

* Rebase fixes

* Do not force screenshot on dashboard alerts

* feat: bypass cache on screenshots for alerts

* Update existing tests

* Add tests

* feat: configure force_screenshot
This commit is contained in:
Beto Dealmeida 2021-12-22 13:46:00 -08:00 committed by GitHub
parent 2cd8054358
commit 9baeafec93
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 15 deletions

View File

@ -42,6 +42,7 @@ import Select, { propertyComparator } from 'src/components/Select/Select';
import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags'; import { FeatureFlag, isFeatureEnabled } from 'src/featureFlags';
import withToasts from 'src/components/MessageToasts/withToasts'; import withToasts from 'src/components/MessageToasts/withToasts';
import Owner from 'src/types/Owner'; import Owner from 'src/types/Owner';
import { Checkbox } from 'src/common/components';
import TextAreaControl from 'src/explore/components/controls/TextAreaControl'; import TextAreaControl from 'src/explore/components/controls/TextAreaControl';
import { useCommonConf } from 'src/views/CRUD/data/database/state'; import { useCommonConf } from 'src/views/CRUD/data/database/state';
import { import {
@ -341,6 +342,10 @@ const StyledRadioGroup = styled(Radio.Group)`
margin-left: ${({ theme }) => theme.gridUnit * 5.5}px; margin-left: ${({ theme }) => theme.gridUnit * 5.5}px;
`; `;
const StyledCheckbox = styled(Checkbox)`
margin-left: ${({ theme }) => theme.gridUnit * 5.5}px;
`;
// Notification Method components // Notification Method components
const StyledNotificationAddButton = styled.div` const StyledNotificationAddButton = styled.div`
color: ${({ theme }) => theme.colors.primary.dark1}; color: ${({ theme }) => theme.colors.primary.dark1};
@ -417,6 +422,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
const [reportFormat, setReportFormat] = useState<string>( const [reportFormat, setReportFormat] = useState<string>(
DEFAULT_NOTIFICATION_FORMAT, DEFAULT_NOTIFICATION_FORMAT,
); );
const [forceScreenshot, setForceScreenshot] = useState<boolean>(false);
// Dropdown options // Dropdown options
const [conditionNotNull, setConditionNotNull] = useState<boolean>(false); const [conditionNotNull, setConditionNotNull] = useState<boolean>(false);
@ -513,7 +519,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
const data: any = { const data: any = {
...currentAlert, ...currentAlert,
type: isReport ? 'Report' : 'Alert', type: isReport ? 'Report' : 'Alert',
force_screenshot: contentType === 'chart' && !isReport ? 'true' : 'false', force_screenshot: forceScreenshot ? 'true' : 'false',
validator_type: conditionNotNull ? 'not null' : 'operator', validator_type: conditionNotNull ? 'not null' : 'operator',
validator_config_json: conditionNotNull validator_config_json: conditionNotNull
? {} ? {}
@ -866,6 +872,10 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
setReportFormat(target.value); setReportFormat(target.value);
}; };
const onForceScreenshotChange = (event: any) => {
setForceScreenshot(event.target.checked);
};
// Make sure notification settings has the required info // Make sure notification settings has the required info
const checkNotificationSettings = () => { const checkNotificationSettings = () => {
if (!notificationSettings.length) { if (!notificationSettings.length) {
@ -927,6 +937,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
(!currentAlert || currentAlert.id || (isHidden && show)) (!currentAlert || currentAlert.id || (isHidden && show))
) { ) {
setCurrentAlert({ ...DEFAULT_ALERT }); setCurrentAlert({ ...DEFAULT_ALERT });
setForceScreenshot(contentType === 'chart' && !isReport);
setNotificationSettings([]); setNotificationSettings([]);
setNotificationAddState('active'); setNotificationAddState('active');
} }
@ -970,6 +981,7 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
if (resource.chart) { if (resource.chart) {
setChartVizType((resource.chart as ChartObject).viz_type); setChartVizType((resource.chart as ChartObject).viz_type);
} }
setForceScreenshot(resource.force_screenshot);
setCurrentAlert({ setCurrentAlert({
...resource, ...resource,
@ -1339,18 +1351,33 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
onChange={onDashboardChange} onChange={onDashboardChange}
/> />
{formatOptionEnabled && ( {formatOptionEnabled && (
<div className="inline-container"> <>
<StyledRadioGroup <div className="inline-container">
onChange={onFormatChange} <StyledRadioGroup
value={reportFormat} onChange={onFormatChange}
> value={reportFormat}
<StyledRadio value="PNG">{t('Send as PNG')}</StyledRadio> >
<StyledRadio value="CSV">{t('Send as CSV')}</StyledRadio> <StyledRadio value="PNG">{t('Send as PNG')}</StyledRadio>
{TEXT_BASED_VISUALIZATION_TYPES.includes(chartVizType) && ( <StyledRadio value="CSV">{t('Send as CSV')}</StyledRadio>
<StyledRadio value="TEXT">{t('Send as text')}</StyledRadio> {TEXT_BASED_VISUALIZATION_TYPES.includes(chartVizType) && (
)} <StyledRadio value="TEXT">
</StyledRadioGroup> {t('Send as text')}
</div> </StyledRadio>
)}
</StyledRadioGroup>
</div>
{isReport && (
<div className="inline-container">
<StyledCheckbox
className="checkbox"
checked={forceScreenshot}
onChange={onForceScreenshotChange}
>
Ignore cache when generating screenshot
</StyledCheckbox>
</div>
)}
</>
)} )}
<StyledSectionTitle> <StyledSectionTitle>
<h4>{t('Notification method')}</h4> <h4>{t('Notification method')}</h4>

View File

@ -68,6 +68,7 @@ export type AlertObject = {
dashboard?: MetaObject; dashboard?: MetaObject;
database?: MetaObject; database?: MetaObject;
description?: string; description?: string;
force_screenshot: boolean;
grace_period?: number; grace_period?: number;
id: number; id: number;
last_eval_dttm?: number; last_eval_dttm?: number;

View File

@ -92,6 +92,7 @@ class ReportScheduleRestApi(BaseSupersetModelRestApi):
"database.database_name", "database.database_name",
"database.id", "database.id",
"description", "description",
"force_screenshot",
"grace_period", "grace_period",
"last_eval_dttm", "last_eval_dttm",
"last_state", "last_state",
@ -151,6 +152,7 @@ class ReportScheduleRestApi(BaseSupersetModelRestApi):
"dashboard", "dashboard",
"database", "database",
"description", "description",
"force_screenshot",
"grace_period", "grace_period",
"log_retention", "log_retention",
"name", "name",

View File

@ -146,8 +146,6 @@ class BaseReportState:
""" """
Get the url for this report schedule: chart or dashboard Get the url for this report schedule: chart or dashboard
""" """
# For alerts we always want to send a fresh screenshot, bypassing
# the cache.
force = "true" if self._report_schedule.force_screenshot else "false" force = "true" if self._report_schedule.force_screenshot else "false"
if self._report_schedule.chart: if self._report_schedule.chart: