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
f9bab958
Commit
f9bab958
authored
Jan 31, 2019
by
Dominik Prokop
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip
parent
6c1f8a9c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
4 deletions
+31
-4
public/app/core/utils/explore.test.ts
+8
-1
public/app/core/utils/explore.ts
+16
-3
public/app/types/explore.ts
+7
-0
No files found.
public/app/core/utils/explore.test.ts
View file @
f9bab958
...
...
@@ -13,6 +13,11 @@ const DEFAULT_EXPLORE_STATE: ExploreUrlState = {
datasource
:
null
,
queries
:
[],
range
:
DEFAULT_RANGE
,
ui
:
{
showingGraph
:
true
,
showingTable
:
true
,
showingLogs
:
true
,
}
};
describe
(
'state functions'
,
()
=>
{
...
...
@@ -69,9 +74,11 @@ describe('state functions', () => {
to
:
'now'
,
},
};
expect
(
serializeStateToUrlParam
(
state
)).
toBe
(
'{"datasource":"foo","queries":[{"expr":"metric{test=
\\
"a/b
\\
"}"},'
+
'{"expr":"super{foo=
\\
"x/z
\\
"}"}],"range":{"from":"now-5h","to":"now"}}'
'{"expr":"super{foo=
\\
"x/z
\\
"}"}],"range":{"from":"now-5h","to":"now"},'
+
'"ui":{"showingGraph":true,"showingTable":true,"showingLogs":true}}'
);
});
...
...
public/app/core/utils/explore.ts
View file @
f9bab958
...
...
@@ -20,6 +20,7 @@ import {
ResultType
,
QueryIntervals
,
QueryOptions
,
ExploreUrlUIState
,
}
from
'app/types/explore'
;
export
const
DEFAULT_RANGE
=
{
...
...
@@ -27,6 +28,12 @@ export const DEFAULT_RANGE = {
to
:
'now'
,
};
export
const
DEFAULT_UI_STATE
=
{
showingTable
:
true
,
showingGraph
:
true
,
showingLogs
:
true
,
};
const
MAX_HISTORY_ITEMS
=
100
;
export
const
LAST_USED_DATASOURCE_KEY
=
'grafana.explore.datasource'
;
...
...
@@ -151,6 +158,7 @@ export function parseUrlState(initial: string | undefined): ExploreUrlState {
if
(
initial
)
{
try
{
const
parsed
=
JSON
.
parse
(
decodeURI
(
initial
));
// debugger
if
(
Array
.
isArray
(
parsed
))
{
if
(
parsed
.
length
<=
3
)
{
throw
new
Error
(
'Error parsing compact URL state for Explore.'
);
...
...
@@ -161,19 +169,24 @@ export function parseUrlState(initial: string | undefined): ExploreUrlState {
};
const
datasource
=
parsed
[
2
];
const
queries
=
parsed
.
slice
(
3
);
return
{
datasource
,
queries
,
range
};
return
{
datasource
,
queries
,
range
,
ui
:
DEFAULT_UI_STATE
};
}
return
parsed
;
}
catch
(
e
)
{
console
.
error
(
e
);
}
}
return
{
datasource
:
null
,
queries
:
[],
range
:
DEFAULT_RANGE
};
return
{
datasource
:
null
,
queries
:
[],
range
:
DEFAULT_RANGE
,
ui
:
DEFAULT_UI_STATE
};
}
const
serializeUIState
=
(
state
:
ExploreUrlUIState
)
=>
{
return
Object
.
keys
(
state
).
map
((
key
)
=>
({
[
key
]:
state
[
key
]
}));
};
export
function
serializeStateToUrlParam
(
urlState
:
ExploreUrlState
,
compact
?:
boolean
):
string
{
if
(
compact
)
{
return
JSON
.
stringify
([
urlState
.
range
.
from
,
urlState
.
range
.
to
,
urlState
.
datasource
,
...
urlState
.
queries
]);
return
JSON
.
stringify
([
urlState
.
range
.
from
,
urlState
.
range
.
to
,
urlState
.
datasource
,
...
urlState
.
queries
,
...
serializeUIState
(
urlState
.
ui
)
]);
}
return
JSON
.
stringify
(
urlState
);
}
...
...
public/app/types/explore.ts
View file @
f9bab958
...
...
@@ -231,10 +231,17 @@ export interface ExploreItemState {
tableResult
?:
TableModel
;
}
export
interface
ExploreUrlUIState
{
showingTable
:
boolean
;
showingGraph
:
boolean
;
showingLogs
:
boolean
;
}
export
interface
ExploreUrlState
{
datasource
:
string
;
queries
:
any
[];
// Should be a DataQuery, but we're going to strip refIds, so typing makes less sense
range
:
RawTimeRange
;
ui
:
ExploreUrlUIState
;
}
export
interface
HistoryItem
<
TQuery
extends
DataQuery
=
DataQuery
>
{
...
...
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