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
9872ea7d
Commit
9872ea7d
authored
Oct 31, 2018
by
Erik Sundell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
stackdriver: extract common function
parent
c993a4d2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
31 deletions
+38
-31
public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx
+25
-31
public/app/plugins/datasource/stackdriver/functions.ts
+13
-0
No files found.
public/app/plugins/datasource/stackdriver/components/TemplateQueryComponent.tsx
View file @
9872ea7d
import
React
,
{
PureComponent
}
from
'react'
;
import
SimpleDropdown
from
'./SimpleDropdown'
;
import
{
TemplateQueryProps
}
from
'app/types/plugins'
;
import
{
getMetricTypes
ByService
,
extractServicesFromMetricDescriptors
}
from
'../functions'
;
import
{
getMetricTypes
,
extractServicesFromMetricDescriptors
}
from
'../functions'
;
import
defaultsDeep
from
'lodash/defaultsDeep'
;
import
{
MetricFindQueryTypes
}
from
'../types'
;
...
...
@@ -43,12 +43,8 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
value
:
m
.
service
,
name
:
m
.
serviceShortName
,
}));
const
service
=
this
.
state
.
service
||
services
[
0
].
value
;
const
metricTypes
=
getMetricTypesByService
(
metricDescriptors
,
service
).
map
(
m
=>
({
value
:
m
.
type
,
name
:
m
.
displayName
,
}));
const
metricType
=
this
.
state
.
metricType
||
metricTypes
[
0
].
value
;
const
service
=
services
.
some
(
s
=>
s
.
value
===
this
.
state
.
service
)
?
this
.
state
.
service
:
services
[
0
].
value
;
const
{
metricTypes
,
metricType
}
=
getMetricTypes
(
metricDescriptors
,
this
.
state
.
metricType
,
service
);
const
state
:
any
=
{
services
,
service
,
...
...
@@ -66,13 +62,17 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
}
async
onServiceChange
(
event
)
{
const
metricTypes
=
getMetricTypesByService
(
this
.
state
.
metricDescriptors
,
event
.
target
.
value
).
map
(
m
=>
({
value
:
m
.
type
,
name
:
m
.
displayName
,
}));
const
metricTypeExistInArray
=
metricTypes
.
find
(
m
=>
m
.
value
===
this
.
state
.
metricType
);
const
metricType
=
metricTypeExistInArray
?
metricTypeExistInArray
.
value
:
metricTypes
[
0
].
value
;
const
state
:
any
=
{
service
:
event
.
target
.
value
,
metricTypes
,
metricType
,
...
await
this
.
getLabels
(
metricType
)
};
const
{
metricTypes
,
metricType
}
=
getMetricTypes
(
this
.
state
.
metricDescriptors
,
this
.
state
.
metricType
,
event
.
target
.
value
);
const
state
:
any
=
{
service
:
event
.
target
.
value
,
metricTypes
,
metricType
,
...
await
this
.
getLabels
(
metricType
),
};
this
.
setState
(
state
);
}
...
...
@@ -81,10 +81,17 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
this
.
setState
(
state
);
}
async
getLabelKeys
(
metricType
,
type
=
this
.
state
.
type
)
{
const
refId
=
'StackdriverTemplateQueryComponent'
;
const
response
=
await
this
.
props
.
datasource
.
getLabels
(
metricType
,
refId
);
return
Object
.
keys
(
response
.
meta
[
type
]);
onLabelKeyChange
(
event
)
{
this
.
setState
({
labelKey
:
event
.
target
.
value
});
}
componentDidUpdate
()
{
const
{
metricDescriptors
,
metricLabels
,
resourceLabels
,
...
queryModel
}
=
this
.
state
;
this
.
props
.
onChange
(
queryModel
);
}
isLabelQuery
(
queryType
)
{
return
[
MetricFindQueryTypes
.
MetricLabels
,
MetricFindQueryTypes
.
ResourceLabels
].
indexOf
(
queryType
)
!==
-
1
;
}
async
getLabels
(
metricType
,
type
=
this
.
state
.
type
)
{
...
...
@@ -99,19 +106,6 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
return
result
;
}
onLabelKeyChange
(
event
)
{
this
.
setState
({
labelKey
:
event
.
target
.
value
});
}
componentDidUpdate
()
{
const
{
metricDescriptors
,
metricLabels
,
resourceLabels
,
...
queryModel
}
=
this
.
state
;
this
.
props
.
onChange
(
queryModel
);
}
isLabelQuery
(
queryType
)
{
return
[
MetricFindQueryTypes
.
MetricLabels
,
MetricFindQueryTypes
.
ResourceLabels
].
indexOf
(
queryType
)
!==
-
1
;
}
renderQueryTypeSwitch
(
queryType
)
{
switch
(
queryType
)
{
case
MetricFindQueryTypes
.
MetricTypes
:
...
...
public/app/plugins/datasource/stackdriver/functions.ts
View file @
9872ea7d
...
...
@@ -6,6 +6,19 @@ export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(
export
const
getMetricTypesByService
=
(
metricDescriptors
,
service
)
=>
metricDescriptors
.
filter
(
m
=>
m
.
service
===
service
);
export
const
getMetricTypes
=
(
metricDescriptors
,
selectedMetricType
,
service
)
=>
{
const
metricTypes
=
getMetricTypesByService
(
metricDescriptors
,
service
).
map
(
m
=>
({
value
:
m
.
type
,
name
:
m
.
displayName
,
}));
const
metricTypeExistInArray
=
metricTypes
.
some
(
m
=>
m
.
value
===
selectedMetricType
);
const
metricType
=
metricTypeExistInArray
?
metricTypeExistInArray
.
value
:
metricTypes
[
0
].
value
;
return
{
metricTypes
,
metricType
,
};
};
export
const
getAlignmentOptionsByMetric
=
(
metricValueType
,
metricKind
)
=>
{
return
!
metricValueType
?
[]
...
...
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