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
662eb650
Unverified
Commit
662eb650
authored
Dec 16, 2020
by
Hugo Häggmark
Committed by
GitHub
Dec 16, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Variables: Fixes so numerical sortorder works for options with null values (#29846)
parent
6cc6a782
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
3 deletions
+29
-3
public/app/features/variables/query/reducer.test.ts
+24
-2
public/app/features/variables/query/reducer.ts
+5
-1
No files found.
public/app/features/variables/query/reducer.test.ts
View file @
662eb650
import
{
reducerTester
}
from
'../../../../test/core/redux/reducerTester'
;
import
{
queryVariableReducer
,
updateVariableOptions
,
updateVariableTags
}
from
'./reducer'
;
import
{
QueryVariableModel
}
from
'../types'
;
import
{
queryVariableReducer
,
sortVariableValues
,
updateVariableOptions
,
updateVariableTags
}
from
'./reducer'
;
import
{
QueryVariableModel
,
VariableSort
}
from
'../types'
;
import
cloneDeep
from
'lodash/cloneDeep'
;
import
{
VariablesState
}
from
'../state/variablesReducer'
;
import
{
getVariableTestContext
}
from
'../state/helpers'
;
...
...
@@ -260,6 +260,28 @@ describe('queryVariableReducer', () => {
});
});
describe
(
'sortVariableValues'
,
()
=>
{
describe
(
'when using any sortOrder with an option with null as text'
,
()
=>
{
it
.
each
`
options | sortOrder | expected
${[{
text
:
'1'
},
{
text
:
null
},
{
text
:
'2'
}]}
|
${
VariableSort
.
disabled
}
|
${[{
text
:
'1'
},
{
text
:
null
},
{
text
:
'2'
}]}
${[{
text
:
'a'
},
{
text
:
null
},
{
text
:
'b'
}]}
|
${
VariableSort
.
alphabeticalAsc
}
|
${[{
text
:
'a'
},
{
text
:
'b'
},
{
text
:
null
}]}
${[{
text
:
'a'
},
{
text
:
null
},
{
text
:
'b'
}]}
|
${
VariableSort
.
alphabeticalDesc
}
|
${[{
text
:
null
},
{
text
:
'b'
},
{
text
:
'a'
}]}
${[{
text
:
'1'
},
{
text
:
null
},
{
text
:
'2'
}]}
|
${
VariableSort
.
numericalAsc
}
|
${[{
text
:
null
},
{
text
:
'1'
},
{
text
:
'2'
}]}
${[{
text
:
'1'
},
{
text
:
null
},
{
text
:
'2'
}]}
|
${
VariableSort
.
numericalDesc
}
|
${[{
text
:
'2'
},
{
text
:
'1'
},
{
text
:
null
}]}
${[{
text
:
'a'
},
{
text
:
null
},
{
text
:
'b'
}]}
|
${
VariableSort
.
alphabeticalCaseInsensitiveAsc
}
|
${[{
text
:
null
},
{
text
:
'a'
},
{
text
:
'b'
}]}
${[{
text
:
'a'
},
{
text
:
null
},
{
text
:
'b'
}]}
|
${
VariableSort
.
alphabeticalCaseInsensitiveDesc
}
|
${[{
text
:
'b'
},
{
text
:
'a'
},
{
text
:
null
}]}
`
(
'then it should sort the options correctly without throwing (sortOrder:$sortOrder)'
,
({
options
,
sortOrder
,
expected
})
=>
{
const
result
=
sortVariableValues
(
options
,
sortOrder
);
expect
(
result
).
toEqual
(
expected
);
}
);
});
});
function
createMetric
(
value
:
string
)
{
return
{
text
:
value
,
...
...
public/app/features/variables/query/reducer.ts
View file @
662eb650
...
...
@@ -52,7 +52,7 @@ export const initialQueryVariableModelState: QueryVariableModel = {
definition
:
''
,
};
const
sortVariableValues
=
(
options
:
any
[],
sortOrder
:
VariableSort
)
=>
{
export
const
sortVariableValues
=
(
options
:
any
[],
sortOrder
:
VariableSort
)
=>
{
if
(
sortOrder
===
VariableSort
.
disabled
)
{
return
options
;
}
...
...
@@ -64,6 +64,10 @@ const sortVariableValues = (options: any[], sortOrder: VariableSort) => {
options
=
_
.
sortBy
(
options
,
'text'
);
}
else
if
(
sortType
===
2
)
{
options
=
_
.
sortBy
(
options
,
opt
=>
{
if
(
!
opt
.
text
)
{
return
-
1
;
}
const
matches
=
opt
.
text
.
match
(
/.*
?(\d
+
)
.*/
);
if
(
!
matches
||
matches
.
length
<
2
)
{
return
-
1
;
...
...
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