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
88ec7e09
Unverified
Commit
88ec7e09
authored
Apr 18, 2020
by
Ryan McKinley
Committed by
GitHub
Apr 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
toDataFrame: detect field properties using in rather than hasOwnProperty (#23673)
parent
806dd3f6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
2 deletions
+16
-2
packages/grafana-data/src/dataframe/processDataFrame.test.ts
+14
-0
packages/grafana-data/src/dataframe/processDataFrame.ts
+2
-2
No files found.
packages/grafana-data/src/dataframe/processDataFrame.test.ts
View file @
88ec7e09
...
@@ -10,6 +10,7 @@ import {
...
@@ -10,6 +10,7 @@ import {
import
{
DataFrameDTO
,
FieldType
,
TableData
,
TimeSeries
}
from
'../types/index'
;
import
{
DataFrameDTO
,
FieldType
,
TableData
,
TimeSeries
}
from
'../types/index'
;
import
{
dateTime
}
from
'../datetime/moment_wrapper'
;
import
{
dateTime
}
from
'../datetime/moment_wrapper'
;
import
{
MutableDataFrame
}
from
'./MutableDataFrame'
;
import
{
MutableDataFrame
}
from
'./MutableDataFrame'
;
import
{
ArrayDataFrame
}
from
'./ArrayDataFrame'
;
describe
(
'toDataFrame'
,
()
=>
{
describe
(
'toDataFrame'
,
()
=>
{
it
(
'converts timeseries to series'
,
()
=>
{
it
(
'converts timeseries to series'
,
()
=>
{
...
@@ -73,6 +74,19 @@ describe('toDataFrame', () => {
...
@@ -73,6 +74,19 @@ describe('toDataFrame', () => {
expect
(
again
).
toBe
(
input
);
expect
(
again
).
toBe
(
input
);
});
});
it
(
'Make sure ArrayDataFrame is used as a DataFrame without modification'
,
()
=>
{
const
orig
=
[
{
a
:
1
,
b
:
2
},
{
a
:
3
,
b
:
4
},
];
const
array
=
new
ArrayDataFrame
(
orig
);
const
frame
=
toDataFrame
(
array
);
expect
(
frame
).
toEqual
(
array
);
expect
(
frame
instanceof
ArrayDataFrame
).
toEqual
(
true
);
expect
(
frame
.
length
).
toEqual
(
orig
.
length
);
expect
(
frame
.
fields
.
map
(
f
=>
f
.
name
)).
toEqual
([
'a'
,
'b'
]);
});
it
(
'throws when table rows is not array'
,
()
=>
{
it
(
'throws when table rows is not array'
,
()
=>
{
expect
(()
=>
expect
(()
=>
toDataFrame
({
toDataFrame
({
...
...
packages/grafana-data/src/dataframe/processDataFrame.ts
View file @
88ec7e09
...
@@ -261,9 +261,9 @@ export const isTableData = (data: any): data is DataFrame => data && data.hasOwn
...
@@ -261,9 +261,9 @@ export const isTableData = (data: any): data is DataFrame => data && data.hasOwn
export
const
isDataFrame
=
(
data
:
any
):
data
is
DataFrame
=>
data
&&
data
.
hasOwnProperty
(
'fields'
);
export
const
isDataFrame
=
(
data
:
any
):
data
is
DataFrame
=>
data
&&
data
.
hasOwnProperty
(
'fields'
);
export
const
toDataFrame
=
(
data
:
any
):
DataFrame
=>
{
export
const
toDataFrame
=
(
data
:
any
):
DataFrame
=>
{
if
(
data
.
hasOwnProperty
(
'fields'
)
)
{
if
(
'fields'
in
data
)
{
// DataFrameDTO does not have length
// DataFrameDTO does not have length
if
(
data
.
hasOwnProperty
(
'length'
)
)
{
if
(
'length'
in
data
)
{
return
data
as
DataFrame
;
return
data
as
DataFrame
;
}
}
...
...
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