Skip to content

Commit

Permalink
Override time grain in annotations (apache#5084)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored and mistercrunch committed May 30, 2018
1 parent 72554a8 commit 0d223a2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
4 changes: 4 additions & 0 deletions superset/assets/src/chart/chartAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ export function runAnnotationQuery(annotation, timeout = 60, formData = null, ke
return Promise.resolve();
}

const granularity = fd.time_grain_sqla || fd.granularity;
fd.time_grain_sqla = granularity;
fd.granularity = granularity;

const sliceFormData = Object.keys(annotation.overrides)
.reduce((d, k) => ({
...d,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ export default class AnnotationLayer extends React.PureComponent {
} else {
label = 'Slice';
description = `Use a pre defined Superset Slice as a source for annotations and overlays.
'your Slice must be one of these visualization types:
'[${getSupportedSourceTypes(sourceType)
'your chart must be one of these visualization types:
'[${getSupportedSourceTypes(annotationType)
.map(x => vizTypes[x].label).join(', ')}]'`;
}
} else if (annotationType === AnnotationTypes.FORMULA) {
Expand Down Expand Up @@ -400,7 +400,7 @@ export default class AnnotationLayer extends React.PureComponent {
name="annotation-override-since"
label="Override 'Since'"
description={`This controls whether the "Since" field from the current
view should be passed down to the slice containing the annotation data.`}
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;
Expand All @@ -416,7 +416,7 @@ export default class AnnotationLayer extends React.PureComponent {
name="annotation-override-until"
label="Override 'Until'"
description={`This controls whether the "Until" field from the current
view should be passed down to the slice containing the annotation data.`}
view should be passed down to the chart containing the annotation data.`}
value={!!Object.keys(overrides).find(x => x === 'until')}
onChange={(v) => {
delete overrides.until;
Expand All @@ -427,6 +427,29 @@ export default class AnnotationLayer extends React.PureComponent {
}
}}
/>
<CheckboxControl
hovered
name="annotation-override-timegrain"
label="Override time grain"
description={`This controls whether the time grain field from the current
view should be passed down to the chart containing the annotation data.`}
value={!!Object.keys(overrides).find(x => x === 'time_grain_sqla')}
onChange={(v) => {
delete overrides.time_grain_sqla;
delete overrides.granularity;
if (v) {
this.setState({
overrides: {
...overrides,
time_grain_sqla: null,
granularity: null,
},
});
} else {
this.setState({ overrides: { ...overrides } });
}
}}
/>
<TextControl
hovered
name="annotation-layer-timeshift"
Expand Down

0 comments on commit 0d223a2

Please sign in to comment.