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/08/18 01:32:43 UTC

[superset] branch master updated: pass correct report_format (#16306)

This is an automated email from the ASF dual-hosted git repository.

beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 4960b5e  pass correct report_format (#16306)
4960b5e is described below

commit 4960b5ee2bba5b933fa3d67341675a7ec4a63ba4
Author: Elizabeth Thompson <es...@gmail.com>
AuthorDate: Tue Aug 17 18:31:38 2021 -0700

    pass correct report_format (#16306)
---
 .../src/components/ReportModal/index.tsx           | 26 +++++++++++++++-------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/superset-frontend/src/components/ReportModal/index.tsx b/superset-frontend/src/components/ReportModal/index.tsx
index 7ec4681..3770aad 100644
--- a/superset-frontend/src/components/ReportModal/index.tsx
+++ b/superset-frontend/src/components/ReportModal/index.tsx
@@ -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>
   );