Skip to content

Commit

Permalink
pass correct report_format (#16306)
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho authored Aug 18, 2021
1 parent 7a284bb commit 4960b5e
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions superset-frontend/src/components/ReportModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,25 @@ type ReportActionType =
type: ActionType.reset;
};

const DEFAULT_NOTIFICATION_FORMAT = 'TEXT';
const TEXT_BASED_VISUALIZATION_TYPES = [
'pivot_table',
'pivot_table_v2',
'table',
'paired_ttest',
];

const NOTIFICATION_FORMATS = {
TEXT: 'TEXT',
PNG: 'PNG',
CSV: 'CSV',
};

const reportReducer = (
state: Partial<ReportObject> | null,
action: ReportActionType,
): Partial<ReportObject> | null => {
const initialState = {
name: state?.name || 'Weekly Report',
report_format: state?.report_format || DEFAULT_NOTIFICATION_FORMAT,
...(state || {}),
};

Expand Down Expand Up @@ -167,9 +171,14 @@ const ReportModal: FunctionComponent<ReportProps> = ({
...props
}) => {
const vizType = props.props.chart?.sliceFormData?.viz_type;
const isChart = !!props.props.chart;
const defaultNotificationFormat =
isChart && TEXT_BASED_VISUALIZATION_TYPES.includes(vizType)
? NOTIFICATION_FORMATS.TEXT
: NOTIFICATION_FORMATS.PNG;
const [currentReport, setCurrentReport] = useReducer<
Reducer<Partial<ReportObject> | null, ReportActionType>
>(reportReducer, null);
>(reportReducer, { report_format: defaultNotificationFormat });
const onChange = useCallback((type: any, payload: any) => {
setCurrentReport({ type, payload });
}, []);
Expand All @@ -179,6 +188,7 @@ const ReportModal: FunctionComponent<ReportProps> = ({
// Report fetch logic
const reports = useSelector<any, AlertObject>(state => state.reports);
const isEditMode = reports && Object.keys(reports).length;

useEffect(() => {
if (isEditMode) {
const reportsIds = Object.keys(reports);
Expand Down Expand Up @@ -271,17 +281,17 @@ const ReportModal: FunctionComponent<ReportProps> = ({
value: event.target.value,
});
}}
value={currentReport?.report_format || DEFAULT_NOTIFICATION_FORMAT}
value={currentReport?.report_format || defaultNotificationFormat}
>
{TEXT_BASED_VISUALIZATION_TYPES.includes(vizType) && (
<StyledRadio value="TEXT">
<StyledRadio value={NOTIFICATION_FORMATS.TEXT}>
{t('Text embedded in email')}
</StyledRadio>
)}
<StyledRadio value="PNG">
<StyledRadio value={NOTIFICATION_FORMATS.PNG}>
{t('Image (PNG) embedded in email')}
</StyledRadio>
<StyledRadio value="CSV">
<StyledRadio value={NOTIFICATION_FORMATS.CSV}>
{t('Formatted CSV attached in email')}
</StyledRadio>
</StyledRadioGroup>
Expand Down Expand Up @@ -375,7 +385,7 @@ const ReportModal: FunctionComponent<ReportProps> = ({
}}
timezone={currentReport?.timezone}
/>
{props.props.chart && renderMessageContentSection}
{isChart && renderMessageContentSection}
</StyledBottomSection>
</StyledModal>
);
Expand Down

0 comments on commit 4960b5e

Please sign in to comment.