You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by gr...@apache.org on 2018/11/08 03:26:11 UTC

[incubator-superset] branch master updated: [annotation] Only allow override whole time_range (#6286)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new ede5c71  [annotation] Only allow override whole time_range (#6286)
ede5c71 is described below

commit ede5c710edc28026ec0b1d5b421aa49a4761cdc5
Author: Grace Guo <gr...@airbnb.com>
AuthorDate: Wed Nov 7 19:26:06 2018 -0800

    [annotation] Only allow override whole time_range (#6286)
---
 superset/assets/src/chart/chartAction.js           | 11 ++++---
 .../components/controls/AnnotationLayer.jsx        | 38 +++++++++-------------
 superset/assets/src/utils/common.js                |  3 --
 superset/views/core.py                             | 10 +-----
 4 files changed, 23 insertions(+), 39 deletions(-)

diff --git a/superset/assets/src/chart/chartAction.js b/superset/assets/src/chart/chartAction.js
index 771f159..fb4ffd6 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 a878345..28ddbbe 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 4d8574d..282518f 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 eb1d8d3..ef4c4ec 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1030,15 +1030,7 @@ class Superset(BaseSupersetView):
         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