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
d8280b89
Commit
d8280b89
authored
May 14, 2019
by
Ryan McKinley
Committed by
Torkel Ödegaard
May 15, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
InputDataSource: better empty value support (#17075)
parent
238a9292
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
20 deletions
+37
-20
public/app/plugins/datasource/input/InputDatasource.test.ts
+15
-1
public/app/plugins/datasource/input/InputDatasource.ts
+19
-16
public/app/plugins/datasource/input/InputQueryEditor.tsx
+3
-3
No files found.
public/app/plugins/datasource/input/InputDatasource.test.ts
View file @
d8280b89
import
InputDatasource
from
'./InputDatasource'
;
import
InputDatasource
,
{
describeSeriesData
}
from
'./InputDatasource'
;
import
{
InputQuery
,
InputOptions
}
from
'./types'
;
import
{
readCSV
,
DataSourceInstanceSettings
,
PluginMeta
}
from
'@grafana/ui'
;
import
{
getQueryOptions
}
from
'test/helpers/getQueryOptions'
;
...
...
@@ -31,4 +31,18 @@ describe('InputDatasource', () => {
});
});
});
test
(
'SeriesData descriptions'
,
()
=>
{
expect
(
describeSeriesData
([])).
toEqual
(
''
);
expect
(
describeSeriesData
(
null
)).
toEqual
(
''
);
expect
(
describeSeriesData
([
{
name
:
'x'
,
fields
:
[{
name
:
'a'
}],
rows
:
[],
},
])
).
toEqual
(
'1 Fields, 0 Rows'
);
});
});
public/app/plugins/datasource/input/InputDatasource.ts
View file @
d8280b89
...
...
@@ -17,28 +17,14 @@ export class InputDatasource extends DataSourceApi<InputQuery, InputOptions> {
this
.
data
=
instanceSettings
.
jsonData
.
data
?
instanceSettings
.
jsonData
.
data
:
[];
}
getDescription
(
data
:
SeriesData
[]):
string
{
if
(
!
data
)
{
return
''
;
}
if
(
data
.
length
>
1
)
{
const
count
=
data
.
reduce
((
acc
,
series
)
=>
{
return
acc
+
series
.
rows
.
length
;
},
0
);
return
`
${
data
.
length
}
Series,
${
count
}
Rows`
;
}
const
series
=
data
[
0
];
return
`
${
series
.
fields
.
length
}
Fields,
${
series
.
rows
.
length
}
Rows`
;
}
/**
* Convert a query to a simple text string
*/
getQueryDisplayText
(
query
:
InputQuery
):
string
{
if
(
query
.
data
)
{
return
'Panel Data: '
+
this
.
getDescription
(
query
.
data
);
return
'Panel Data: '
+
describeSeriesData
(
query
.
data
);
}
return
`Shared Data From:
${
this
.
name
}
(
${
this
.
getDescription
(
this
.
data
)}
)`
;
return
`Shared Data From:
${
this
.
name
}
(
${
describeSeriesData
(
this
.
data
)}
)`
;
}
metricFindQuery
(
query
:
string
,
options
?:
any
)
{
...
...
@@ -96,4 +82,21 @@ export class InputDatasource extends DataSourceApi<InputQuery, InputOptions> {
}
}
export
function
describeSeriesData
(
data
:
SeriesData
[]):
string
{
if
(
!
data
||
!
data
.
length
)
{
return
''
;
}
if
(
data
.
length
>
1
)
{
const
count
=
data
.
reduce
((
acc
,
series
)
=>
{
return
acc
+
series
.
rows
.
length
;
},
0
);
return
`
${
data
.
length
}
Series,
${
count
}
Rows`
;
}
const
series
=
data
[
0
];
if
(
!
series
.
fields
)
{
return
'Missing Fields'
;
}
return
`
${
series
.
fields
.
length
}
Fields,
${
series
.
rows
.
length
}
Rows`
;
}
export
default
InputDatasource
;
public/app/plugins/datasource/input/InputQueryEditor.tsx
View file @
d8280b89
...
...
@@ -2,7 +2,7 @@
import
React
,
{
PureComponent
}
from
'react'
;
// Types
import
{
InputDatasource
}
from
'./InputDatasource'
;
import
{
InputDatasource
,
describeSeriesData
}
from
'./InputDatasource'
;
import
{
InputQuery
,
InputOptions
}
from
'./types'
;
import
{
FormLabel
,
Select
,
QueryEditorProps
,
SelectOptionItem
,
SeriesData
,
TableInputCSV
,
toCSV
}
from
'@grafana/ui'
;
...
...
@@ -80,10 +80,10 @@ export class InputQueryEditor extends PureComponent<Props, State> {
<
div
className=
"btn btn-link"
>
{
query
.
data
?
(
d
atasource
.
getDescription
(
query
.
data
)
d
escribeSeriesData
(
query
.
data
)
)
:
(
<
a
href=
{
`datasources/edit/${id}/`
}
>
{
name
}
:
{
d
atasource
.
getDescription
(
datasource
.
data
)
}
{
name
}
:
{
d
escribeSeriesData
(
datasource
.
data
)
}
<
i
className=
"fa fa-pencil-square-o"
/>
</
a
>
)
}
...
...
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