Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
1e4846d4
Unverified
Commit
1e4846d4
authored
Sep 15, 2020
by
Ryan McKinley
Committed by
GitHub
Sep 15, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Annotation: use DataFrame[] rather than a single DataFrame (#27587)
parent
e04e3e7d
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
21 additions
and
25 deletions
+21
-25
packages/grafana-data/src/types/annotations.ts
+1
-1
public/app/features/annotations/annotations_srv.ts
+3
-4
public/app/features/annotations/components/AnnotationResultMapper.tsx
+1
-1
public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx
+3
-1
public/app/features/annotations/standardAnnotationSupport.test.ts
+3
-3
public/app/features/annotations/standardAnnotationSupport.ts
+9
-9
public/app/features/annotations/types.ts
+1
-6
No files found.
packages/grafana-data/src/types/annotations.ts
View file @
1e4846d4
...
@@ -78,7 +78,7 @@ export interface AnnotationSupport<TQuery extends DataQuery = DataQuery, TAnno =
...
@@ -78,7 +78,7 @@ export interface AnnotationSupport<TQuery extends DataQuery = DataQuery, TAnno =
/**
/**
* When the standard frame > event processing is insufficient, this allows explicit control of the mappings
* When the standard frame > event processing is insufficient, this allows explicit control of the mappings
*/
*/
processEvents
?(
anno
:
TAnno
,
data
:
DataFrame
):
AnnotationEvent
[]
|
undefined
;
processEvents
?(
anno
:
TAnno
,
data
:
DataFrame
[]
):
AnnotationEvent
[]
|
undefined
;
/**
/**
* Specify a custom QueryEditor for the annotation page. If not specified, the standard one will be used
* Specify a custom QueryEditor for the annotation page. If not specified, the standard one will be used
...
...
public/app/features/annotations/annotations_srv.ts
View file @
1e4846d4
...
@@ -24,7 +24,7 @@ import { getTimeSrv } from '../dashboard/services/TimeSrv';
...
@@ -24,7 +24,7 @@ import { getTimeSrv } from '../dashboard/services/TimeSrv';
import
{
Observable
,
of
}
from
'rxjs'
;
import
{
Observable
,
of
}
from
'rxjs'
;
import
{
map
}
from
'rxjs/operators'
;
import
{
map
}
from
'rxjs/operators'
;
import
{
AnnotationQueryResponse
,
AnnotationQueryOptions
}
from
'./types'
;
import
{
AnnotationQueryResponse
,
AnnotationQueryOptions
}
from
'./types'
;
import
{
standardAnnotationSupport
,
singleFrameFromPanelData
}
from
'./standardAnnotationSupport'
;
import
{
standardAnnotationSupport
}
from
'./standardAnnotationSupport'
;
import
{
runRequest
}
from
'../dashboard/state/runRequest'
;
import
{
runRequest
}
from
'../dashboard/state/runRequest'
;
let
counter
=
100
;
let
counter
=
100
;
...
@@ -263,9 +263,8 @@ export function executeAnnotationQuery(
...
@@ -263,9 +263,8 @@ export function executeAnnotationQuery(
return
runRequest
(
datasource
,
queryRequest
).
pipe
(
return
runRequest
(
datasource
,
queryRequest
).
pipe
(
map
(
panelData
=>
{
map
(
panelData
=>
{
const
frame
=
singleFrameFromPanelData
(
panelData
);
const
events
=
panelData
.
series
?
processor
.
processEvents
!
(
annotation
,
panelData
.
series
)
:
[];
const
events
=
frame
?
processor
.
processEvents
!
(
annotation
,
frame
)
:
[];
return
{
panelData
,
events
};
return
{
panelData
,
frame
,
events
};
})
})
);
);
}
}
...
...
public/app/features/annotations/components/AnnotationResultMapper.tsx
View file @
1e4846d4
...
@@ -42,7 +42,7 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
...
@@ -42,7 +42,7 @@ export class AnnotationFieldMapper extends PureComponent<Props, State> {
}
}
updateFields
=
()
=>
{
updateFields
=
()
=>
{
const
frame
=
this
.
props
.
response
?.
frame
;
const
frame
=
this
.
props
.
response
?.
panelData
?.
series
[
0
]
;
if
(
frame
&&
frame
.
fields
)
{
if
(
frame
&&
frame
.
fields
)
{
const
fieldNames
=
frame
.
fields
.
map
(
f
=>
{
const
fieldNames
=
frame
.
fields
.
map
(
f
=>
{
const
name
=
getFieldDisplayName
(
f
,
frame
);
const
name
=
getFieldDisplayName
(
f
,
frame
);
...
...
public/app/features/annotations/components/StandardAnnotationQueryEditor.tsx
View file @
1e4846d4
...
@@ -97,7 +97,7 @@ export default class StandardAnnotationQueryEditor extends PureComponent<Props,
...
@@ -97,7 +97,7 @@ export default class StandardAnnotationQueryEditor extends PureComponent<Props,
if
(
running
||
response
?.
panelData
?.
state
===
LoadingState
.
Loading
||
!
response
)
{
if
(
running
||
response
?.
panelData
?.
state
===
LoadingState
.
Loading
||
!
response
)
{
text
=
'loading...'
;
text
=
'loading...'
;
}
else
{
}
else
{
const
{
events
,
panelData
,
frame
}
=
response
;
const
{
events
,
panelData
}
=
response
;
if
(
panelData
?.
error
)
{
if
(
panelData
?.
error
)
{
rowStyle
=
'alert-error'
;
rowStyle
=
'alert-error'
;
...
@@ -108,6 +108,8 @@ export default class StandardAnnotationQueryEditor extends PureComponent<Props,
...
@@ -108,6 +108,8 @@ export default class StandardAnnotationQueryEditor extends PureComponent<Props,
icon
=
'exclamation-triangle'
;
icon
=
'exclamation-triangle'
;
text
=
'No events found'
;
text
=
'No events found'
;
}
else
{
}
else
{
const
frame
=
panelData
?.
series
[
0
];
text
=
`
${
events
.
length
}
events (from
${
frame
?.
fields
.
length
}
fields
)
`;
text
=
`
${
events
.
length
}
events (from
${
frame
?.
fields
.
length
}
fields
)
`;
}
}
}
}
...
...
public/app/features/annotations/standardAnnotationSupport.test.ts
View file @
1e4846d4
import
{
toDataFrame
,
FieldType
}
from
'@grafana/data'
;
import
{
toDataFrame
,
FieldType
}
from
'@grafana/data'
;
import
{
getAnnotationsFrom
Frame
}
from
'./standardAnnotationSupport'
;
import
{
getAnnotationsFrom
Data
}
from
'./standardAnnotationSupport'
;
describe
(
'DataFrame to annotations'
,
()
=>
{
describe
(
'DataFrame to annotations'
,
()
=>
{
test
(
'simple conversion'
,
()
=>
{
test
(
'simple conversion'
,
()
=>
{
...
@@ -11,7 +11,7 @@ describe('DataFrame to annotations', () => {
...
@@ -11,7 +11,7 @@ describe('DataFrame to annotations', () => {
],
],
});
});
const
events
=
getAnnotationsFrom
Frame
(
frame
);
const
events
=
getAnnotationsFrom
Data
([
frame
]
);
expect
(
events
).
toMatchInlineSnapshot
(
`
expect
(
events
).
toMatchInlineSnapshot
(
`
Array [
Array [
Object {
Object {
...
@@ -51,7 +51,7 @@ describe('DataFrame to annotations', () => {
...
@@ -51,7 +51,7 @@ describe('DataFrame to annotations', () => {
],
],
});
});
const
events
=
getAnnotationsFrom
Frame
(
frame
,
{
const
events
=
getAnnotationsFrom
Data
([
frame
]
,
{
text
:
{
value
:
'bbbbb'
},
text
:
{
value
:
'bbbbb'
},
time
:
{
value
:
'time2'
},
time
:
{
value
:
'time2'
},
timeEnd
:
{
value
:
'time1'
},
timeEnd
:
{
value
:
'time1'
},
...
...
public/app/features/annotations/standardAnnotationSupport.ts
View file @
1e4846d4
...
@@ -2,7 +2,6 @@ import {
...
@@ -2,7 +2,6 @@ import {
DataFrame
,
DataFrame
,
AnnotationQuery
,
AnnotationQuery
,
AnnotationSupport
,
AnnotationSupport
,
PanelData
,
transformDataFrame
,
transformDataFrame
,
FieldType
,
FieldType
,
Field
,
Field
,
...
@@ -43,20 +42,20 @@ export const standardAnnotationSupport: AnnotationSupport = {
...
@@ -43,20 +42,20 @@ export const standardAnnotationSupport: AnnotationSupport = {
/**
/**
* When the standard frame > event processing is insufficient, this allows explicit control of the mappings
* When the standard frame > event processing is insufficient, this allows explicit control of the mappings
*/
*/
processEvents
:
(
anno
:
AnnotationQuery
,
data
:
DataFrame
)
=>
{
processEvents
:
(
anno
:
AnnotationQuery
,
data
:
DataFrame
[]
)
=>
{
return
getAnnotationsFrom
Frame
(
data
,
anno
.
mappings
);
return
getAnnotationsFrom
Data
(
data
,
anno
.
mappings
);
},
},
};
};
/**
/**
* Flatten all panel data into a single frame
* Flatten all panel data into a single frame
*/
*/
export
function
singleFrameFromPanelData
(
rsp
:
PanelData
):
DataFrame
|
undefined
{
export
function
singleFrameFromPanelData
(
data
:
DataFrame
[]
):
DataFrame
|
undefined
{
if
(
!
rsp
?.
series
?.
length
)
{
if
(
!
data
?.
length
)
{
return
undefined
;
return
undefined
;
}
}
if
(
rsp
.
series
.
length
===
1
)
{
if
(
data
.
length
===
1
)
{
return
rsp
.
series
[
0
];
return
data
[
0
];
}
}
return
transformDataFrame
(
return
transformDataFrame
(
...
@@ -66,7 +65,7 @@ export function singleFrameFromPanelData(rsp: PanelData): DataFrame | undefined
...
@@ -66,7 +65,7 @@ export function singleFrameFromPanelData(rsp: PanelData): DataFrame | undefined
options
:
{
byField
:
'Time'
},
options
:
{
byField
:
'Time'
},
},
},
],
],
rsp
.
series
data
)[
0
];
)[
0
];
}
}
...
@@ -108,7 +107,8 @@ export const annotationEventNames: AnnotationFieldInfo[] = [
...
@@ -108,7 +107,8 @@ export const annotationEventNames: AnnotationFieldInfo[] = [
// { key: 'email' },
// { key: 'email' },
];
];
export
function
getAnnotationsFromFrame
(
frame
:
DataFrame
,
options
?:
AnnotationEventMappings
):
AnnotationEvent
[]
{
export
function
getAnnotationsFromData
(
data
:
DataFrame
[],
options
?:
AnnotationEventMappings
):
AnnotationEvent
[]
{
const
frame
=
singleFrameFromPanelData
(
data
);
if
(
!
frame
?.
length
)
{
if
(
!
frame
?.
length
)
{
return
[];
return
[];
}
}
...
...
public/app/features/annotations/types.ts
View file @
1e4846d4
import
{
PanelData
,
DataFrame
,
AnnotationEvent
,
TimeRange
}
from
'@grafana/data'
;
import
{
PanelData
,
AnnotationEvent
,
TimeRange
}
from
'@grafana/data'
;
import
{
DashboardModel
,
PanelModel
}
from
'../dashboard/state'
;
import
{
DashboardModel
,
PanelModel
}
from
'../dashboard/state'
;
export
interface
AnnotationQueryOptions
{
export
interface
AnnotationQueryOptions
{
...
@@ -9,11 +9,6 @@ export interface AnnotationQueryOptions {
...
@@ -9,11 +9,6 @@ export interface AnnotationQueryOptions {
export
interface
AnnotationQueryResponse
{
export
interface
AnnotationQueryResponse
{
/**
/**
* All the data flattened to a single frame
*/
frame
?:
DataFrame
;
/**
* The processed annotation events
* The processed annotation events
*/
*/
events
?:
AnnotationEvent
[];
events
?:
AnnotationEvent
[];
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment