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
8744ad36
Unverified
Commit
8744ad36
authored
Jan 29, 2021
by
Hugo Häggmark
Committed by
GitHub
Jan 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Variables: Fixes so text format will show All instead of custom all (#30730)
parent
0b1f5c5e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
7 deletions
+29
-7
public/app/features/templating/formatRegistry.ts
+4
-3
public/app/features/templating/template_srv.test.ts
+19
-0
public/app/features/templating/template_srv.ts
+4
-4
public/test/core/utils/silenceConsoleOutput.ts
+2
-0
No files found.
public/app/features/templating/formatRegistry.ts
View file @
8744ad36
import
kbn
from
'app/core/utils/kbn'
;
import
kbn
from
'app/core/utils/kbn'
;
import
{
Registry
,
RegistryItem
,
VariableModel
,
textUtil
,
dateTime
}
from
'@grafana/data'
;
import
{
dateTime
,
Registry
,
RegistryItem
,
textUtil
,
VariableModel
}
from
'@grafana/data'
;
import
{
map
,
isArray
,
replace
}
from
'lodash'
;
import
{
isArray
,
map
,
replace
}
from
'lodash'
;
import
{
formatVariableLabel
}
from
'../variables/shared/formatVariable'
;
import
{
formatVariableLabel
}
from
'../variables/shared/formatVariable'
;
import
{
ALL_VARIABLE_TEXT
,
ALL_VARIABLE_VALUE
}
from
'../variables/state/types'
;
export
interface
FormatOptions
{
export
interface
FormatOptions
{
value
:
any
;
value
:
any
;
...
@@ -204,7 +205,7 @@ export const formatRegistry = new Registry<FormatRegistryItem>(() => {
...
@@ -204,7 +205,7 @@ export const formatRegistry = new Registry<FormatRegistryItem>(() => {
description: 'Format variables in their text representation. Example in multi variable scenario A + B + C.',
description: 'Format variables in their text representation. Example in multi variable scenario A + B + C.',
formatter: (options, variable) => {
formatter: (options, variable) => {
if (typeof options.text === 'string') {
if (typeof options.text === 'string') {
return options.text;
return options.
value === ALL_VARIABLE_VALUE ? ALL_VARIABLE_TEXT : options.
text;
}
}
const current = (variable as any)?.current;
const current = (variable as any)?.current;
...
...
public/app/features/templating/template_srv.test.ts
View file @
8744ad36
import
{
dateTime
,
TimeRange
}
from
'@grafana/data'
;
import
{
dateTime
,
TimeRange
}
from
'@grafana/data'
;
import
{
initTemplateSrv
}
from
'../../../test/helpers/initTemplateSrv'
;
import
{
initTemplateSrv
}
from
'../../../test/helpers/initTemplateSrv'
;
import
{
silenceConsoleOutput
}
from
'../../../test/core/utils/silenceConsoleOutput'
;
describe
(
'templateSrv'
,
()
=>
{
describe
(
'templateSrv'
,
()
=>
{
silenceConsoleOutput
();
let
_templateSrv
:
any
;
let
_templateSrv
:
any
;
describe
(
'init'
,
()
=>
{
describe
(
'init'
,
()
=>
{
...
@@ -253,6 +255,11 @@ describe('templateSrv', () => {
...
@@ -253,6 +255,11 @@ describe('templateSrv', () => {
expect
(
target
).
toBe
(
'this.*.filters'
);
expect
(
target
).
toBe
(
'this.*.filters'
);
});
});
it
(
'should replace ${test:text} with "all" value'
,
()
=>
{
const
target
=
_templateSrv
.
replace
(
'this.${test:text}.filters'
,
{});
expect
(
target
).
toBe
(
'this.All.filters'
);
});
it
(
'should not escape custom all value'
,
()
=>
{
it
(
'should not escape custom all value'
,
()
=>
{
const
target
=
_templateSrv
.
replace
(
'this.$test'
,
{},
'regex'
);
const
target
=
_templateSrv
.
replace
(
'this.$test'
,
{},
'regex'
);
expect
(
target
).
toBe
(
'this.*'
);
expect
(
target
).
toBe
(
'this.*'
);
...
@@ -524,6 +531,13 @@ describe('templateSrv', () => {
...
@@ -524,6 +531,13 @@ describe('templateSrv', () => {
current
:
{
value
:
'$__all'
,
text
:
''
},
current
:
{
value
:
'$__all'
,
text
:
''
},
options
:
[{
value
:
'$__all'
},
{
value
:
'db1'
,
text
:
'Database 1'
},
{
value
:
'db2'
,
text
:
'Database 2'
}],
options
:
[{
value
:
'$__all'
},
{
value
:
'db1'
,
text
:
'Database 1'
},
{
value
:
'db2'
,
text
:
'Database 2'
}],
},
},
{
type
:
'custom'
,
name
:
'custom_all_value'
,
allValue
:
'CUSTOM_ALL'
,
current
:
{
value
:
'$__all'
,
text
:
''
},
options
:
[{
value
:
'$__all'
},
{
value
:
'A-Value'
,
text
:
'This A'
},
{
value
:
'B-Value'
,
text
:
'This B'
}],
},
]);
]);
_templateSrv
.
updateIndex
();
_templateSrv
.
updateIndex
();
});
});
...
@@ -542,6 +556,11 @@ describe('templateSrv', () => {
...
@@ -542,6 +556,11 @@ describe('templateSrv', () => {
const
target
=
_templateSrv
.
replaceWithText
(
'Db: $databases'
);
const
target
=
_templateSrv
.
replaceWithText
(
'Db: $databases'
);
expect
(
target
).
toBe
(
'Db: All'
);
expect
(
target
).
toBe
(
'Db: All'
);
});
});
it
(
'should replace $__all with All for values with custom all'
,
()
=>
{
const
target
=
_templateSrv
.
replaceWithText
(
'Custom: $custom_all_value'
);
expect
(
target
).
toBe
(
'Custom: All'
);
});
});
});
describe
(
'built in interval variables'
,
()
=>
{
describe
(
'built in interval variables'
,
()
=>
{
...
...
public/app/features/templating/template_srv.ts
View file @
8744ad36
...
@@ -5,8 +5,8 @@ import { variableRegex } from '../variables/utils';
...
@@ -5,8 +5,8 @@ import { variableRegex } from '../variables/utils';
import
{
isAdHoc
}
from
'../variables/guard'
;
import
{
isAdHoc
}
from
'../variables/guard'
;
import
{
VariableModel
}
from
'../variables/types'
;
import
{
VariableModel
}
from
'../variables/types'
;
import
{
setTemplateSrv
,
TemplateSrv
as
BaseTemplateSrv
}
from
'@grafana/runtime'
;
import
{
setTemplateSrv
,
TemplateSrv
as
BaseTemplateSrv
}
from
'@grafana/runtime'
;
import
{
formatRegistry
,
FormatOptions
}
from
'./formatRegistry'
;
import
{
FormatOptions
,
formatRegistry
}
from
'./formatRegistry'
;
import
{
ALL_VARIABLE_TEXT
}
from
'../variables/state/types'
;
import
{
ALL_VARIABLE_TEXT
,
ALL_VARIABLE_VALUE
}
from
'../variables/state/types'
;
interface
FieldAccessorCache
{
interface
FieldAccessorCache
{
[
key
:
string
]:
(
obj
:
any
)
=>
any
;
[
key
:
string
]:
(
obj
:
any
)
=>
any
;
...
@@ -282,7 +282,7 @@ export class TemplateSrv implements BaseTemplateSrv {
...
@@ -282,7 +282,7 @@ export class TemplateSrv implements BaseTemplateSrv {
value
=
this
.
getAllValue
(
variable
);
value
=
this
.
getAllValue
(
variable
);
text
=
ALL_VARIABLE_TEXT
;
text
=
ALL_VARIABLE_TEXT
;
// skip formatting of custom all values
// skip formatting of custom all values
if
(
variable
.
allValue
)
{
if
(
variable
.
allValue
&&
fmt
!==
'text'
)
{
return
this
.
replace
(
value
);
return
this
.
replace
(
value
);
}
}
}
}
...
@@ -302,7 +302,7 @@ export class TemplateSrv implements BaseTemplateSrv {
...
@@ -302,7 +302,7 @@ export class TemplateSrv implements BaseTemplateSrv {
}
}
isAllValue
(
value
:
any
)
{
isAllValue
(
value
:
any
)
{
return
value
===
'$__all'
||
(
Array
.
isArray
(
value
)
&&
value
[
0
]
===
'$__all'
);
return
value
===
ALL_VARIABLE_VALUE
||
(
Array
.
isArray
(
value
)
&&
value
[
0
]
===
ALL_VARIABLE_VALUE
);
}
}
replaceWithText
(
target
:
string
,
scopedVars
?:
ScopedVars
)
{
replaceWithText
(
target
:
string
,
scopedVars
?:
ScopedVars
)
{
...
...
public/test/core/utils/silenceConsoleOutput.ts
View file @
8744ad36
...
@@ -4,6 +4,7 @@ export const silenceConsoleOutput = () => {
...
@@ -4,6 +4,7 @@ export const silenceConsoleOutput = () => {
jest
.
spyOn
(
console
,
'error'
).
mockImplementation
(
jest
.
fn
());
jest
.
spyOn
(
console
,
'error'
).
mockImplementation
(
jest
.
fn
());
jest
.
spyOn
(
console
,
'debug'
).
mockImplementation
(
jest
.
fn
());
jest
.
spyOn
(
console
,
'debug'
).
mockImplementation
(
jest
.
fn
());
jest
.
spyOn
(
console
,
'info'
).
mockImplementation
(
jest
.
fn
());
jest
.
spyOn
(
console
,
'info'
).
mockImplementation
(
jest
.
fn
());
jest
.
spyOn
(
console
,
'warn'
).
mockImplementation
(
jest
.
fn
());
});
});
afterEach
(()
=>
{
afterEach
(()
=>
{
...
@@ -11,5 +12,6 @@ export const silenceConsoleOutput = () => {
...
@@ -11,5 +12,6 @@ export const silenceConsoleOutput = () => {
jest
.
spyOn
(
console
,
'error'
).
mockRestore
();
jest
.
spyOn
(
console
,
'error'
).
mockRestore
();
jest
.
spyOn
(
console
,
'debug'
).
mockRestore
();
jest
.
spyOn
(
console
,
'debug'
).
mockRestore
();
jest
.
spyOn
(
console
,
'info'
).
mockRestore
();
jest
.
spyOn
(
console
,
'info'
).
mockRestore
();
jest
.
spyOn
(
console
,
'warn'
).
mockRestore
();
});
});
};
};
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