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
ad870c07
Unverified
Commit
ad870c07
authored
May 25, 2020
by
Dominik Prokop
Committed by
GitHub
May 25, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DataLinks: Bring back variables interpolation in title (#24970)
parent
8c1307e7
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
5 deletions
+45
-5
packages/grafana-data/src/field/fieldOverrides.test.ts
+39
-1
packages/grafana-data/src/field/fieldOverrides.ts
+6
-4
No files found.
packages/grafana-data/src/field/fieldOverrides.test.ts
View file @
ad870c07
...
...
@@ -4,6 +4,7 @@ import {
setFieldConfigDefaults
,
setDynamicConfigValue
,
applyFieldOverrides
,
getLinksSupplier
,
}
from
'./fieldOverrides'
;
import
{
MutableDataFrame
,
toDataFrame
}
from
'../dataframe'
;
import
{
...
...
@@ -20,7 +21,7 @@ import { mockStandardProperties } from '../utils/tests/mockStandardProperties';
import
{
FieldMatcherID
}
from
'../transformations'
;
import
{
FieldConfigOptionsRegistry
}
from
'./FieldConfigOptionsRegistry'
;
import
{
getFieldDisplayName
}
from
'./fieldState'
;
import
{
locationUtil
}
from
'../utils'
;
const
property1
=
{
id
:
'custom.property1'
,
// Match field properties
path
:
'property1'
,
// Match field properties
...
...
@@ -418,3 +419,40 @@ describe('setDynamicConfigValue', () => {
expect
(
config
.
displayName
).
toBeUndefined
();
});
});
describe
(
'getLinksSupplier'
,
()
=>
{
it
(
'will replace variables in url and title of the data link'
,
()
=>
{
locationUtil
.
initialize
({
getConfig
:
()
=>
({}
as
any
),
buildParamsFromVariables
:
(()
=>
{})
as
any
,
getTimeRangeForUrl
:
(()
=>
{})
as
any
,
});
const
f0
=
new
MutableDataFrame
({
name
:
'A'
,
fields
:
[
{
name
:
'message'
,
type
:
FieldType
.
string
,
values
:
[
10
,
20
],
config
:
{
links
:
[
{
url
:
'url to be interpolated'
,
title
:
'title to be interpolated'
,
},
],
},
},
],
});
const
replaceSpy
=
jest
.
fn
();
const
supplier
=
getLinksSupplier
(
f0
,
f0
.
fields
[
0
],
{},
replaceSpy
,
{
theme
:
{}
as
GrafanaTheme
});
supplier
({});
expect
(
replaceSpy
).
toBeCalledTimes
(
2
);
expect
(
replaceSpy
.
mock
.
calls
[
0
][
0
]).
toEqual
(
'url to be interpolated'
);
expect
(
replaceSpy
.
mock
.
calls
[
1
][
0
]).
toEqual
(
'title to be interpolated'
);
});
});
packages/grafana-data/src/field/fieldOverrides.ts
View file @
ad870c07
...
...
@@ -343,7 +343,7 @@ export function validateFieldConfig(config: FieldConfig) {
}
}
const
getLinksSupplier
=
(
export
const
getLinksSupplier
=
(
frame
:
DataFrame
,
field
:
Field
,
fieldScopedVars
:
ScopedVars
,
...
...
@@ -366,7 +366,7 @@ const getLinksSupplier = (
const
info
:
LinkModel
<
Field
>
=
{
href
:
locationUtil
.
assureBaseUrl
(
href
.
replace
(
/
\n
/g
,
''
)),
title
:
replaceVariables
(
link
.
title
||
''
)
,
title
:
link
.
title
||
''
,
target
:
link
.
targetBlank
?
'_blank'
:
'_self'
,
origin
:
field
,
};
...
...
@@ -402,7 +402,7 @@ const getLinksSupplier = (
}
}
info
.
href
=
replaceVariables
(
info
.
href
,
{
const
variables
=
{
...
fieldScopedVars
,
__value
:
{
text
:
'Value'
,
...
...
@@ -417,8 +417,10 @@ const getLinksSupplier = (
text
:
variablesQuery
,
value
:
variablesQuery
,
},
}
)
;
};
info
.
href
=
replaceVariables
(
info
.
href
,
variables
);
info
.
title
=
replaceVariables
(
info
.
title
,
variables
);
info
.
href
=
locationUtil
.
processUrl
(
info
.
href
);
return
info
;
...
...
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