forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add support for annotations and url params (apache#812)
* feat(core): add support for annotations and url params * add type guards
- Loading branch information
1 parent
af4be3a
commit a84522f
Showing
7 changed files
with
272 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...rary_superset_ui/superset-ui/packages/superset-ui-core/src/query/types/AnnotationLayer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* eslint camelcase: 0 */ | ||
type BaseAnnotationLayer = { | ||
color?: string | null; | ||
name: string; | ||
opacity?: '' | 'opacityLow' | 'opacityMedium' | 'opacityHigh'; | ||
show: boolean; | ||
style: 'dashed' | 'dotted' | 'solid' | 'longDashed'; | ||
width?: number; | ||
}; | ||
|
||
type AnnotationOverrides = { | ||
granularity?: string | null; | ||
time_grain_sqla?: string | null; | ||
time_range?: string | null; | ||
time_shift?: string | null; | ||
}; | ||
|
||
type LineSourceAnnotationLayer = { | ||
hideLine?: boolean; | ||
overrides?: AnnotationOverrides; | ||
sourceType: 'line'; | ||
titleColumn: string; | ||
// viz id | ||
value: number; | ||
}; | ||
|
||
type NativeSourceAnnotationLayer = { | ||
sourceType: 'NATIVE'; | ||
// annotation id | ||
value: number; | ||
}; | ||
|
||
type TableSourceAnnotationLayer = { | ||
descriptionColumns?: string[]; | ||
timeColumn?: string; | ||
intervalEndColumn?: string; | ||
overrides?: AnnotationOverrides; | ||
sourceType: 'table'; | ||
titleColumn?: string; | ||
// viz id | ||
value: number; | ||
}; | ||
|
||
export type EventAnnotationLayer = BaseAnnotationLayer & | ||
(TableSourceAnnotationLayer | NativeSourceAnnotationLayer) & { | ||
annotationType: 'EVENT'; | ||
}; | ||
|
||
export type IntervalAnnotationLayer = BaseAnnotationLayer & | ||
(TableSourceAnnotationLayer | NativeSourceAnnotationLayer) & { | ||
annotationType: 'INTERVAL'; | ||
}; | ||
|
||
export type FormulaAnnotationLayer = BaseAnnotationLayer & { | ||
annotationType: 'FORMULA'; | ||
// the mathjs parseable formula | ||
sourceType?: ''; | ||
value: string; | ||
}; | ||
|
||
export type TimeseriesAnnotationLayer = BaseAnnotationLayer & | ||
LineSourceAnnotationLayer & { | ||
annotationType: 'TIME_SERIES'; | ||
showMarkers?: boolean; | ||
value: number; | ||
}; | ||
|
||
export type AnnotationLayer = | ||
| EventAnnotationLayer | ||
| IntervalAnnotationLayer | ||
| FormulaAnnotationLayer | ||
| TimeseriesAnnotationLayer; | ||
|
||
export function isFormulaAnnotationLayer(layer: AnnotationLayer): layer is FormulaAnnotationLayer { | ||
return layer.annotationType === 'FORMULA'; | ||
} | ||
|
||
export function isEventAnnotationLayer(layer: EventAnnotationLayer): layer is EventAnnotationLayer { | ||
return layer.annotationType === 'EVENT'; | ||
} | ||
|
||
export function isIntervalAnnotationLayer( | ||
layer: IntervalAnnotationLayer, | ||
): layer is IntervalAnnotationLayer { | ||
return layer.annotationType === 'INTERVAL'; | ||
} | ||
|
||
export function isTimeseriesAnnotationLayer( | ||
layer: AnnotationLayer, | ||
): layer is TimeseriesAnnotationLayer { | ||
return layer.annotationType === 'TIME_SERIES'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
...perset_ui/superset-ui/packages/superset-ui-core/test/query/types/AnnotationFilter.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { | ||
isEventAnnotationLayer, | ||
isFormulaAnnotationLayer, | ||
isIntervalAnnotationLayer, | ||
isTimeseriesAnnotationLayer, | ||
} from '@superset-ui/core/src/query/types/AnnotationLayer'; | ||
|
||
describe('AnnotationLayer type guards', () => { | ||
describe('isFormulaAnnotationLayer', () => { | ||
it('should return true when it is the correct type', () => { | ||
expect( | ||
isFormulaAnnotationLayer({ | ||
annotationType: 'FORMULA', | ||
name: 'My Formula', | ||
value: 'sin(2*x)', | ||
style: 'solid', | ||
show: true, | ||
}), | ||
).toEqual(true); | ||
}); | ||
it('should return false otherwise', () => { | ||
expect( | ||
isFormulaAnnotationLayer({ | ||
annotationType: 'EVENT', | ||
name: 'My Event', | ||
value: 1, | ||
style: 'solid', | ||
show: true, | ||
}), | ||
).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('isEventAnnotationLayer', () => { | ||
it('should return true when it is the correct type', () => { | ||
expect( | ||
isEventAnnotationLayer({ | ||
annotationType: 'EVENT', | ||
name: 'My Event', | ||
value: 1, | ||
style: 'solid', | ||
show: true, | ||
}), | ||
).toEqual(true); | ||
}); | ||
it('should return false otherwise', () => { | ||
expect( | ||
isEventAnnotationLayer({ | ||
annotationType: 'FORMULA', | ||
name: 'My Formula', | ||
value: 'sin(2*x)', | ||
style: 'solid', | ||
show: true, | ||
}), | ||
).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('isIntervalAnnotationLayer', () => { | ||
it('should return true when it is the correct type', () => { | ||
expect( | ||
isIntervalAnnotationLayer({ | ||
annotationType: 'INTERVAL', | ||
name: 'My Event', | ||
value: 1, | ||
style: 'solid', | ||
show: true, | ||
}), | ||
).toEqual(true); | ||
}); | ||
it('should return false otherwise', () => { | ||
expect( | ||
isEventAnnotationLayer({ | ||
annotationType: 'FORMULA', | ||
name: 'My Formula', | ||
value: 'sin(2*x)', | ||
style: 'solid', | ||
show: true, | ||
}), | ||
).toEqual(false); | ||
}); | ||
}); | ||
|
||
describe('isTimeseriesAnnotationLayer', () => { | ||
it('should return true when it is the correct type', () => { | ||
expect( | ||
isTimeseriesAnnotationLayer({ | ||
annotationType: 'TIME_SERIES', | ||
name: 'My Event', | ||
value: 1, | ||
style: 'solid', | ||
show: true, | ||
}), | ||
).toEqual(true); | ||
}); | ||
it('should return false otherwise', () => { | ||
expect( | ||
isTimeseriesAnnotationLayer({ | ||
annotationType: 'FORMULA', | ||
name: 'My Formula', | ||
value: 'sin(2*x)', | ||
style: 'solid', | ||
show: true, | ||
}), | ||
).toEqual(false); | ||
}); | ||
}); | ||
}); |