graceguo-supercat closed pull request #6286: [annotation] Only allow override 
whole time_range
URL: https://github.com/apache/incubator-superset/pull/6286
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/superset/assets/src/chart/chartAction.js 
b/superset/assets/src/chart/chartAction.js
index 771f1590fd..fb4ffd6656 100644
--- a/superset/assets/src/chart/chartAction.js
+++ b/superset/assets/src/chart/chartAction.js
@@ -1,12 +1,12 @@
 /* global window, AbortController */
 /* eslint no-undef: 'error' */
+/* eslint no-param-reassign: ["error", { "props": false }] */
 import { t } from '@superset-ui/translation';
 import { SupersetClient } from '@superset-ui/connection';
 import { getExploreUrlAndPayload, getAnnotationJsonUrl } from 
'../explore/exploreUtils';
 import { requiresQuery, ANNOTATION_SOURCE_TYPES } from 
'../modules/AnnotationTypes';
 import { addDangerToast } from '../messageToasts/actions';
 import { Logger, LOG_ACTIONS_LOAD_CHART } from '../logger';
-import { TIME_RANGE_SEPARATOR } from '../utils/common';
 import getClientErrorObject from '../utils/getClientErrorObject';
 
 export const CHART_UPDATE_STARTED = 'CHART_UPDATE_STARTED';
@@ -77,10 +77,13 @@ export function runAnnotationQuery(annotation, timeout = 
60, formData = null, ke
     const granularity = fd.time_grain_sqla || fd.granularity;
     fd.time_grain_sqla = granularity;
     fd.granularity = granularity;
-    if (fd.time_range) {
-      [fd.since, fd.until] = fd.time_range.split(TIME_RANGE_SEPARATOR);
+    const overridesKeys = Object.keys(annotation.overrides);
+    if (overridesKeys.includes('since') || overridesKeys.includes('until')) {
+      annotation.overrides = {
+        ...annotation.overrides,
+        time_range: null,
+      };
     }
-
     const sliceFormData = Object.keys(annotation.overrides).reduce(
       (d, k) => ({
         ...d,
diff --git 
a/superset/assets/src/explore/components/controls/AnnotationLayer.jsx 
b/superset/assets/src/explore/components/controls/AnnotationLayer.jsx
index a8783451f2..28ddbbe75f 100644
--- a/superset/assets/src/explore/components/controls/AnnotationLayer.jsx
+++ b/superset/assets/src/explore/components/controls/AnnotationLayer.jsx
@@ -97,6 +97,14 @@ export default class AnnotationLayer extends 
React.PureComponent {
       timeColumn,
       intervalEndColumn,
     } = props;
+
+    const overridesKeys = Object.keys(overrides);
+    if (overridesKeys.includes('since') || overridesKeys.includes('until')) {
+      overrides.time_range = null;
+      delete overrides.since;
+      delete overrides.until;
+    }
+
     this.state = {
       // base
       name,
@@ -215,7 +223,7 @@ export default class AnnotationLayer extends 
React.PureComponent {
       intervalEndColumn: null,
       timeColumn: null,
       titleColumn: null,
-      overrides: { since: null, until: null },
+      overrides: { time_range: null },
     });
   }
 
@@ -427,31 +435,15 @@ export default class AnnotationLayer extends 
React.PureComponent {
             <div style={{ marginTop: '1rem' }}>
               <CheckboxControl
                 hovered
-                name="annotation-override-since"
-                label="Override 'Since'"
-                description={`This controls whether the "Since" field from the 
current
-                  view should be passed down to the chart containing the 
annotation data.`}
-                value={!!Object.keys(overrides).find(x => x === 'since')}
-                onChange={(v) => {
-                  delete overrides.since;
-                  if (v) {
-                    this.setState({ overrides: { ...overrides, since: null } 
});
-                  } else {
-                    this.setState({ overrides: { ...overrides } });
-                  }
-                }}
-              />
-              <CheckboxControl
-                hovered
-                name="annotation-override-until"
-                label="Override 'Until'"
-                description={`This controls whether the "Until" field from the 
current
+                name="annotation-override-time_range"
+                label="Override time range"
+                description={`This controls whether the "time_range" field 
from the current
                   view should be passed down to the chart containing the 
annotation data.`}
-                value={!!Object.keys(overrides).find(x => x === 'until')}
+                value={!!Object.keys(overrides).find(x => x === 'time_range')}
                 onChange={(v) => {
-                  delete overrides.until;
+                  delete overrides.time_range;
                   if (v) {
-                    this.setState({ overrides: { ...overrides, until: null } 
});
+                    this.setState({ overrides: { ...overrides, time_range: 
null } });
                   } else {
                     this.setState({ overrides: { ...overrides } });
                   }
diff --git a/superset/assets/src/utils/common.js 
b/superset/assets/src/utils/common.js
index 4d8574df8a..282518f042 100644
--- a/superset/assets/src/utils/common.js
+++ b/superset/assets/src/utils/common.js
@@ -114,6 +114,3 @@ export function optionFromValue(opt) {
   // From a list of options, handles special values & labels
   return { value: optionValue(opt), label: optionLabel(opt) };
 }
-
-// time_range separator
-export const TIME_RANGE_SEPARATOR = ' : ';
diff --git a/superset/views/core.py b/superset/views/core.py
index a16bceb4c2..fd9f8ac9b7 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1032,15 +1032,7 @@ def get_form_data(self, slice_id=None, 
use_slice_data=False):
         if slice_id and (use_slice_data or contains_only_slc_id):
             slc = db.session.query(models.Slice).filter_by(id=slice_id).first()
             slice_form_data = slc.form_data.copy()
-            # allow form_data in request override slice from_data
-            # special treat for since/until and time_range parameter:
-            # we need to breakdown time_range into since/until so request 
parameters
-            # has precedence over slice parameters for time fields.
-            if 'since' in form_data or 'until' in form_data:
-                form_data['since'], form_data['until'] = \
-                    utils.get_since_until(form_data)
-                slice_form_data['since'], slice_form_data['until'] = \
-                    utils.get_since_until(slice_form_data)
+
             slice_form_data.update(form_data)
             form_data = slice_form_data
 


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to