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 71e1eea DB migration of annotation_layers on slice objects and
slimming down annotation object. (#4072)
71e1eea is described below
commit 71e1eea9f4799dbede5b97097fcec8184194583d
Author: fabianmenges <[email protected]>
AuthorDate: Mon Dec 18 16:11:06 2017 -0500
DB migration of annotation_layers on slice objects and slimming down
annotation object. (#4072)
---
.../components/controls/AnnotationLayer.jsx | 11 +++-
.../versions/21e88bc06c02_annotation_migration.py | 60 ++++++++++++++++++++++
2 files changed, 69 insertions(+), 2 deletions(-)
diff --git
a/superset/assets/javascripts/explore/components/controls/AnnotationLayer.jsx
b/superset/assets/javascripts/explore/components/controls/AnnotationLayer.jsx
index aa34fb0..f6c6103 100644
---
a/superset/assets/javascripts/explore/components/controls/AnnotationLayer.jsx
+++
b/superset/assets/javascripts/explore/components/controls/AnnotationLayer.jsx
@@ -104,6 +104,7 @@ export default class AnnotationLayer extends
React.PureComponent {
isNew: !this.props.name,
isLoadingOptions: true,
valueOptions: [],
+ validationErrors: {},
};
this.submitAnnotation = this.submitAnnotation.bind(this);
this.deleteAnnotation = this.deleteAnnotation.bind(this);
@@ -235,11 +236,17 @@ export default class AnnotationLayer extends
React.PureComponent {
applyAnnotation() {
if (this.state.name.length) {
- const annotation = { ...this.state };
- annotation.color = annotation.color === AUTOMATIC_COLOR ? null :
annotation.color;
+ const annotation = {};
+ Object.keys(this.state).forEach((k) => {
+ if (this.state[k] !== null) {
+ annotation[k] = this.state[k];
+ }
+ });
delete annotation.isNew;
delete annotation.valueOptions;
delete annotation.isLoadingOptions;
+ delete annotation.validationErrors;
+ annotation.color = annotation.color === AUTOMATIC_COLOR ? null :
annotation.color;
this.props.addAnnotationLayer(annotation);
this.setState({ isNew: false, oldName: this.state.name });
}
diff --git a/superset/migrations/versions/21e88bc06c02_annotation_migration.py
b/superset/migrations/versions/21e88bc06c02_annotation_migration.py
new file mode 100644
index 0000000..77c6453
--- /dev/null
+++ b/superset/migrations/versions/21e88bc06c02_annotation_migration.py
@@ -0,0 +1,60 @@
+import json
+
+from alembic import op
+from sqlalchemy import (
+ Column, Integer, or_, String, Text)
+from sqlalchemy.ext.declarative import declarative_base
+
+from superset import db
+
+"""migrate_old_annotation_layers
+
+Revision ID: 21e88bc06c02
+Revises: 67a6ac9b727b
+Create Date: 2017-12-17 11:06:30.180267
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '21e88bc06c02'
+down_revision = '67a6ac9b727b'
+
+Base = declarative_base()
+
+
+class Slice(Base):
+ __tablename__ = 'slices'
+ id = Column(Integer, primary_key=True)
+ viz_type = Column(String(250))
+ params = Column(Text)
+
+
+def upgrade():
+ bind = op.get_bind()
+ session = db.Session(bind=bind)
+
+ for slc in session.query(Slice).filter(or_(
+ Slice.viz_type.like('line'), Slice.viz_type.like('bar'))):
+ params = json.loads(slc.params)
+ layers = params.get('annotation_layers', [])
+ new_layers = []
+ if len(layers) and isinstance(layers[0], int):
+ for layer in layers:
+ new_layers.append(
+ {
+ 'annotationType': 'INTERVAL',
+ 'style': 'solid',
+ 'name': 'Layer {}'.format(layer),
+ 'show': True,
+ 'overrides': {'since': None, 'until': None},
+ 'value': 1, 'width': 1, 'sourceType': 'NATIVE',
+ })
+ params['annotation_layers'] = new_layers
+ slc.params = json.dumps(params)
+ session.merge(slc)
+ session.commit()
+ session.close()
+
+
+def downgrade():
+ pass
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].