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
637b91ab
Commit
637b91ab
authored
Oct 24, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: conditional template component rendering
parent
0792c182
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
22 deletions
+53
-22
public/app/features/plugins/all.ts
+1
-1
public/app/features/plugins/pluginTemplateQueryComponentLoader.tsx
+14
-20
public/app/features/templating/defaultTemplateQueryCtrl.tsx
+32
-0
public/app/features/templating/partials/editor.html
+0
-0
public/app/plugins/datasource/stackdriver/templateQueryCtrl.tsx
+6
-1
No files found.
public/app/features/plugins/all.ts
View file @
637b91ab
...
...
@@ -4,4 +4,4 @@ import './import_list/import_list';
import
'./ds_edit_ctrl'
;
import
'./datasource_srv'
;
import
'./plugin_component'
;
import
'./plugin
_react_component
'
;
import
'./plugin
TemplateQueryComponentLoader
'
;
public/app/features/plugins/plugin
_react_component
.tsx
→
public/app/features/plugins/plugin
TemplateQueryComponentLoader
.tsx
View file @
637b91ab
...
...
@@ -4,6 +4,7 @@ import { importPluginModule } from './plugin_loader';
import
React
from
'react'
;
import
ReactDOM
from
'react-dom'
;
import
{
Provider
}
from
'react-redux'
;
import
DefaultTemplateQueryCtrl
from
'../templating/defaultTemplateQueryCtrl'
;
function
WrapInProvider
(
Component
,
props
)
{
return
(
...
...
@@ -13,30 +14,23 @@ function WrapInProvider(Component, props) {
);
}
/** @ngInject */
function
pluginReactDirectiveLoader
(
$compile
,
datasourceSrv
,
$rootScope
,
$q
,
$http
,
$templateCache
,
$timeout
)
{
async
function
getModule
(
scope
,
attrs
)
{
switch
(
attrs
.
type
)
{
case
'template-query-ctrl'
:
{
const
dsModule
=
await
importPluginModule
(
scope
.
currentDatasource
.
meta
.
module
);
console
.
log
(
dsModule
);
return
dsModule
.
TemplateQueryCtrl
;
}
default
:
{
return
$q
.
reject
({
message
:
'Could not find component type: '
+
attrs
.
type
,
});
}
}
async
function
loadComponent
(
module
)
{
const
component
=
await
importPluginModule
(
module
);
if
(
!
component
.
TemplateQueryCtrl
)
{
return
DefaultTemplateQueryCtrl
;
}
else
{
return
component
.
TemplateQueryCtrl
;
}
}
/** @ngInject */
function
pluginTemplateQueryComponentLoader
(
datasourceSrv
)
{
return
{
restrict
:
'E'
,
link
:
async
(
scope
,
elem
,
attrs
)
=>
{
const
component
=
await
getModule
(
scope
,
attrs
);
const
props
=
{
datasourceSrv
};
link
:
async
(
scope
,
elem
)
=>
{
const
component
=
await
loadComponent
(
scope
.
currentDatasource
.
meta
.
module
);
const
props
=
{
datasourceSrv
,
query
:
scope
.
current
.
query
,
isValid
:
scope
.
current
.
isValid
};
ReactDOM
.
render
(
WrapInProvider
(
component
,
props
),
elem
[
0
]);
scope
.
$on
(
'$destroy'
,
()
=>
{
ReactDOM
.
unmountComponentAtNode
(
elem
[
0
]);
});
...
...
@@ -44,4 +38,4 @@ function pluginReactDirectiveLoader($compile, datasourceSrv, $rootScope, $q, $ht
};
}
coreModule
.
directive
(
'plugin
ReactComponent'
,
pluginReactDirective
Loader
);
coreModule
.
directive
(
'plugin
TemplateQueryComponent'
,
pluginTemplateQueryComponent
Loader
);
public/app/features/templating/defaultTemplateQueryCtrl.tsx
0 → 100644
View file @
637b91ab
import
React
,
{
PureComponent
}
from
'react'
;
interface
Props
{
query
:
string
;
}
export
default
class
DefaultTemplateQueryCtrl
extends
PureComponent
<
Props
>
{
constructor
(
props
)
{
super
(
props
);
}
componentDidMount
()
{
console
.
log
(
'componentDidMount'
);
}
render
()
{
return
(
<
div
className=
"gf-form"
>
<
span
className=
"gf-form-label width-7"
>
Query
</
span
>
<
input
type=
"text"
className=
"gf-form-input"
ng
-
model=
"current.query"
placeholder=
"metric name or tags query"
ng
-
model
-
onblur
ng
-
change=
"runQuery()"
required
/>
</
div
>
);
}
}
public/app/features/templating/partials/editor.html
View file @
637b91ab
This diff is collapsed.
Click to expand it.
public/app/plugins/datasource/stackdriver/templateQueryCtrl.tsx
View file @
637b91ab
import
React
,
{
PureComponent
}
from
'react'
;
import
DatasourceSrv
from
'app/features/plugins/datasource_srv'
;
interface
Props
{}
interface
Props
{
query
:
string
;
datasourceSrv
:
DatasourceSrv
;
isValid
:
any
;
}
export
class
StackdriverTemplateQueryCtrl
extends
PureComponent
<
Props
>
{
constructor
(
props
)
{
...
...
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