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
5efa7372
Unverified
Commit
5efa7372
authored
Mar 06, 2019
by
Torkel Ödegaard
Committed by
GitHub
Mar 06, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #15814 from ryantxu/replace-scoped-vars
add ScopedVars to props.replaceVariables()
parents
176315cf
3dd7d407
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
5 deletions
+46
-5
packages/grafana-ui/src/types/panel.ts
+2
-1
public/app/features/dashboard/dashgrid/PanelChrome.test.tsx
+35
-0
public/app/features/dashboard/dashgrid/PanelChrome.tsx
+7
-2
public/app/features/templating/template_srv.ts
+2
-2
No files found.
packages/grafana-ui/src/types/panel.ts
View file @
5efa7372
import
{
ComponentClass
}
from
'react'
;
import
{
TimeSeries
,
LoadingState
,
TableData
}
from
'./data'
;
import
{
TimeRange
}
from
'./time'
;
import
{
ScopedVars
}
from
'./datasource'
;
export
type
InterpolateFunction
=
(
value
:
string
,
format
?:
string
|
Function
)
=>
string
;
export
type
InterpolateFunction
=
(
value
:
string
,
scopedVars
?:
ScopedVars
,
format
?:
string
|
Function
)
=>
string
;
export
interface
PanelProps
<
T
=
any
>
{
panelData
:
PanelData
;
...
...
public/app/features/dashboard/dashgrid/PanelChrome.test.tsx
0 → 100644
View file @
5efa7372
import
{
PanelChrome
}
from
'./PanelChrome'
;
jest
.
mock
(
'sass/_variables.generated.scss'
,
()
=>
({
panelhorizontalpadding
:
10
,
panelVerticalPadding
:
10
,
}));
describe
(
'PanelChrome'
,
()
=>
{
let
chrome
:
PanelChrome
;
beforeEach
(()
=>
{
chrome
=
new
PanelChrome
({
panel
:
{
scopedVars
:
{
aaa
:
{
value
:
'AAA'
,
text
:
'upperA'
},
bbb
:
{
value
:
'BBB'
,
text
:
'upperB'
},
},
},
dashboard
:
{},
plugin
:
{},
isFullscreen
:
false
,
});
});
it
(
'Should replace a panel variable'
,
()
=>
{
const
out
=
chrome
.
replaceVariables
(
'hello $aaa'
);
expect
(
out
).
toBe
(
'hello AAA'
);
});
it
(
'But it should prefer the local variable value'
,
()
=>
{
const
extra
=
{
aaa
:
{
text
:
'???'
,
value
:
'XXX'
}
};
const
out
=
chrome
.
replaceVariables
(
'hello $aaa and $bbb'
,
extra
);
expect
(
out
).
toBe
(
'hello XXX and BBB'
);
});
});
public/app/features/dashboard/dashgrid/PanelChrome.tsx
View file @
5efa7372
...
...
@@ -19,6 +19,7 @@ import { profiler } from 'app/core/profiler';
import
{
DashboardModel
,
PanelModel
}
from
'../state'
;
import
{
PanelPlugin
}
from
'app/types'
;
import
{
DataQueryResponse
,
TimeRange
,
LoadingState
,
PanelData
,
DataQueryError
}
from
'@grafana/ui'
;
import
{
ScopedVars
}
from
'@grafana/ui'
;
import
variables
from
'sass/_variables.generated.scss'
;
import
templateSrv
from
'app/features/templating/template_srv'
;
...
...
@@ -85,8 +86,12 @@ export class PanelChrome extends PureComponent<Props, State> {
});
};
replaceVariables
=
(
value
:
string
,
format
?:
string
)
=>
{
return
templateSrv
.
replace
(
value
,
this
.
props
.
panel
.
scopedVars
,
format
);
replaceVariables
=
(
value
:
string
,
extraVars
?:
ScopedVars
,
format
?:
string
)
=>
{
let
vars
=
this
.
props
.
panel
.
scopedVars
;
if
(
extraVars
)
{
vars
=
vars
?
{
...
vars
,
...
extraVars
}
:
extraVars
;
}
return
templateSrv
.
replace
(
value
,
vars
,
format
);
};
onDataResponse
=
(
dataQueryResponse
:
DataQueryResponse
)
=>
{
...
...
public/app/features/templating/template_srv.ts
View file @
5efa7372
import
kbn
from
'app/core/utils/kbn'
;
import
_
from
'lodash'
;
import
{
variableRegex
}
from
'app/features/templating/variable'
;
import
{
TimeRange
}
from
'@grafana/ui/src'
;
import
{
TimeRange
,
ScopedVars
}
from
'@grafana/ui/src'
;
function
luceneEscape
(
value
)
{
return
value
.
replace
(
/
([\!\*\+\-\=
<>
\s\&\|\(\)\[\]\{\}\^\~\?\:\\/
"
])
/g
,
'
\\
$1'
);
...
...
@@ -220,7 +220,7 @@ export class TemplateSrv {
return
values
;
}
replace
(
target
,
scopedVars
?,
format
?
)
{
replace
(
target
:
string
,
scopedVars
?:
ScopedVars
,
format
?:
string
|
Function
)
{
if
(
!
target
)
{
return
target
;
}
...
...
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