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
20c8b9c4
Commit
20c8b9c4
authored
Jan 17, 2019
by
Torkel Ödegaard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
began work on react query editor props and integration
parent
205e2acd
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
43 deletions
+123
-43
packages/grafana-ui/src/types/datasource.ts
+1
-37
packages/grafana-ui/src/types/plugin.ts
+45
-1
public/app/features/dashboard/panel_editor/QueryEditorRow.tsx
+18
-1
public/app/plugins/datasource/testdata/QueryEditor.tsx
+57
-3
public/app/plugins/datasource/testdata/module.ts
+2
-1
No files found.
packages/grafana-ui/src/types/datasource.ts
View file @
20c8b9c4
import
{
TimeRange
,
RawTimeRange
}
from
'./time'
;
import
{
TimeSeries
}
from
'./series'
;
import
{
Plugin
Exports
,
Plugin
Meta
}
from
'./plugin'
;
import
{
PluginMeta
}
from
'./plugin'
;
export
interface
DataQueryResponse
{
data
:
TimeSeries
[];
...
...
@@ -43,42 +43,6 @@ export interface QueryHint {
fix
?:
QueryFix
;
}
export
interface
DataSourceApi
{
name
:
string
;
meta
:
PluginMeta
;
pluginExports
:
PluginExports
;
/**
* min interval range
*/
interval
?:
string
;
/**
* Imports queries from a different datasource
*/
importQueries
?(
queries
:
DataQuery
[],
originMeta
:
PluginMeta
):
Promise
<
DataQuery
[]
>
;
/**
* Initializes a datasource after instantiation
*/
init
?:
()
=>
void
;
/**
* Main metrics / data query action
*/
query
(
options
:
DataQueryOptions
):
Promise
<
DataQueryResponse
>
;
/**
* Test & verify datasource settings & connection details
*/
testDatasource
():
Promise
<
any
>
;
/**
* Get hints for query improvements
*/
getQueryHints
(
query
:
DataQuery
,
results
:
any
[],
...
rest
:
any
):
QueryHint
[];
}
export
interface
DataSourceSettings
{
id
:
number
;
orgId
:
number
;
...
...
packages/grafana-ui/src/types/plugin.ts
View file @
20c8b9c4
import
{
ComponentClass
}
from
'react'
;
import
{
PanelProps
,
PanelOptionsProps
}
from
'./panel'
;
import
{
DataQueryOptions
,
DataQuery
,
DataQueryResponse
,
QueryHint
}
from
'./datasource'
;
export
interface
DataSourceApi
{
name
:
string
;
meta
:
PluginMeta
;
pluginExports
:
PluginExports
;
/**
* min interval range
*/
interval
?:
string
;
/**
* Imports queries from a different datasource
*/
importQueries
?(
queries
:
DataQuery
[],
originMeta
:
PluginMeta
):
Promise
<
DataQuery
[]
>
;
/**
* Initializes a datasource after instantiation
*/
init
?:
()
=>
void
;
/**
* Main metrics / data query action
*/
query
(
options
:
DataQueryOptions
):
Promise
<
DataQueryResponse
>
;
/**
* Test & verify datasource settings & connection details
*/
testDatasource
():
Promise
<
any
>
;
/**
* Get hints for query improvements
*/
getQueryHints
(
query
:
DataQuery
,
results
:
any
[],
...
rest
:
any
):
QueryHint
[];
}
export
interface
QueryEditorProps
{
datasource
:
DataSourceApi
;
query
:
DataQuery
;
onExecuteQuery
?:
()
=>
void
;
onQueryChange
?:
(
value
:
DataQuery
)
=>
void
;
}
export
interface
PluginExports
{
Datasource
?:
any
;
QueryCtrl
?:
any
;
QueryEditor
?:
any
;
QueryEditor
?:
ComponentClass
<
QueryEditorProps
>
;
ConfigCtrl
?:
any
;
AnnotationsQueryCtrl
?:
any
;
VariableQueryEditor
?:
any
;
...
...
public/app/features/dashboard/panel_editor/QueryEditorRow.tsx
View file @
20c8b9c4
...
...
@@ -103,7 +103,17 @@ export class QueryEditorRow extends PureComponent<Props, State> {
this
.
setState
({
isCollapsed
:
!
this
.
state
.
isCollapsed
});
};
onQueryChange
=
(
query
:
DataQuery
)
=>
{
Object
.
assign
(
this
.
props
.
query
,
query
);
this
.
onExecuteQuery
();
};
onExecuteQuery
=
()
=>
{
this
.
props
.
panel
.
refresh
();
};
renderPluginEditor
()
{
const
{
query
}
=
this
.
props
;
const
{
datasource
}
=
this
.
state
;
if
(
datasource
.
pluginExports
.
QueryCtrl
)
{
...
...
@@ -112,7 +122,14 @@ export class QueryEditorRow extends PureComponent<Props, State> {
if
(
datasource
.
pluginExports
.
QueryEditor
)
{
const
QueryEditor
=
datasource
.
pluginExports
.
QueryEditor
;
return
<
QueryEditor
/>;
return
(
<
QueryEditor
query=
{
query
}
datasource=
{
datasource
}
onQueryChange=
{
this
.
onQueryChange
}
onExecuteQuery=
{
this
.
onExecuteQuery
}
/>
);
}
return
<
div
>
Data source plugin does not export any Query Editor component
</
div
>;
...
...
public/app/plugins/datasource/testdata/QueryEditor.tsx
View file @
20c8b9c4
// Libraries
import
React
,
{
PureComponent
}
from
'react'
;
import
_
from
'lodash'
;
interface
Props
{
// Services & Utils
import
{
getBackendSrv
,
BackendSrv
}
from
'app/core/services/backend_srv'
;
// Components
import
{
FormLabel
,
Select
,
SelectOptionItem
}
from
'@grafana/ui'
;
// Types
import
{
QueryEditorProps
}
from
'@grafana/ui/src/types'
;
interface
Scenario
{
id
:
string
;
name
:
string
;
}
interface
State
{
scenarioList
:
Scenario
[];
current
:
Scenario
|
null
;
}
export
class
QueryEditor
extends
PureComponent
<
Props
>
{
export
class
QueryEditor
extends
PureComponent
<
QueryEditorProps
>
{
backendSrv
:
BackendSrv
=
getBackendSrv
();
state
:
State
=
{
scenarioList
:
[],
current
:
null
,
};
async
componentDidMount
()
{
const
{
query
}
=
this
.
props
;
query
.
scenarioId
=
query
.
scenarioId
||
'random_walk'
;
const
scenarioList
=
await
this
.
backendSrv
.
get
(
'/api/tsdb/testdata/scenarios'
);
const
current
=
_
.
find
(
scenarioList
,
{
id
:
query
.
scenarioId
});
this
.
setState
({
scenarioList
:
scenarioList
,
current
:
current
});
}
onScenarioChange
=
(
item
:
SelectOptionItem
)
=>
{
this
.
props
.
onQueryChange
({
scenarioId
:
item
.
value
,
...
this
.
props
.
query
});
}
render
()
{
const
{
query
}
=
this
.
props
;
const
options
=
this
.
state
.
scenarioList
.
map
(
item
=>
({
label
:
item
.
name
,
value
:
item
.
id
}));
const
current
=
options
.
find
(
item
=>
item
.
value
===
query
.
scenarioId
);
return
(
<
h2
>
Test data
</
h2
>
<
div
className=
"gf-form-inline"
>
<
div
className=
"gf-form"
>
<
FormLabel
className=
"query-keyword"
width=
{
7
}
>
Scenario
</
FormLabel
>
<
Select
options=
{
options
}
value=
{
current
}
onChange=
{
this
.
onScenarioChange
}
/>
</
div
>
</
div
>
);
}
}
public/app/plugins/datasource/testdata/module.ts
View file @
20c8b9c4
import
{
TestDataDatasource
}
from
'./datasource'
;
import
{
TestDataQueryCtrl
}
from
'./query_ctrl'
;
// import { QueryEditor } from './QueryEditor';
class
TestDataAnnotationsQueryCtrl
{
annotation
:
any
;
...
...
@@ -10,7 +11,7 @@ class TestDataAnnotationsQueryCtrl {
}
export
{
TestDataDatasource
,
// QueryEditor
,
TestDataDatasource
as
Datasource
,
TestDataQueryCtrl
as
QueryCtrl
,
TestDataAnnotationsQueryCtrl
as
AnnotationsQueryCtrl
,
...
...
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