mirror of
https://github.com/apache/superset.git
synced 2026-04-18 23:55:00 +00:00
pass correct report_format (#16306)
This commit is contained in:
committed by
GitHub
parent
7a284bb9e8
commit
4960b5ee2b
@@ -125,7 +125,6 @@ type ReportActionType =
|
||||
type: ActionType.reset;
|
||||
};
|
||||
|
||||
const DEFAULT_NOTIFICATION_FORMAT = 'TEXT';
|
||||
const TEXT_BASED_VISUALIZATION_TYPES = [
|
||||
'pivot_table',
|
||||
'pivot_table_v2',
|
||||
@@ -133,13 +132,18 @@ const TEXT_BASED_VISUALIZATION_TYPES = [
|
||||
'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 || {}),
|
||||
};
|
||||
|
||||
@@ -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 });
|
||||
}, []);
|
||||
@@ -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);
|
||||
@@ -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>
|
||||
@@ -375,7 +385,7 @@ const ReportModal: FunctionComponent<ReportProps> = ({
|
||||
}}
|
||||
timezone={currentReport?.timezone}
|
||||
/>
|
||||
{props.props.chart && renderMessageContentSection}
|
||||
{isChart && renderMessageContentSection}
|
||||
</StyledBottomSection>
|
||||
</StyledModal>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user