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
cf55d688
Commit
cf55d688
authored
Mar 14, 2019
by
Peter Holmberg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
using refId from panel model
parent
5f059038
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
36 additions
and
32 deletions
+36
-32
public/app/core/utils/explore.ts
+5
-8
public/app/core/utils/query.ts
+12
-0
public/app/features/dashboard/state/PanelModel.ts
+3
-12
public/app/features/explore/state/actions.ts
+11
-9
public/app/features/explore/state/reducers.ts
+5
-3
No files found.
public/app/core/utils/explore.ts
View file @
cf55d688
...
@@ -23,6 +23,7 @@ import {
...
@@ -23,6 +23,7 @@ import {
ResultGetter
,
ResultGetter
,
}
from
'app/types/explore'
;
}
from
'app/types/explore'
;
import
{
LogsDedupStrategy
}
from
'app/core/logs_model'
;
import
{
LogsDedupStrategy
}
from
'app/core/logs_model'
;
import
{
getNextQueryLetter
}
from
'./query'
;
export
const
DEFAULT_RANGE
=
{
export
const
DEFAULT_RANGE
=
{
from
:
'now-6h'
,
from
:
'now-6h'
,
...
@@ -225,12 +226,8 @@ export function generateKey(index = 0): string {
...
@@ -225,12 +226,8 @@ export function generateKey(index = 0): string {
return
`Q-
${
Date
.
now
()}
-
${
Math
.
random
()}
-
${
index
}
`
;
return
`Q-
${
Date
.
now
()}
-
${
Math
.
random
()}
-
${
index
}
`
;
}
}
export
function
generateRefId
(
index
=
0
):
string
{
export
function
generateEmptyQuery
(
queries
:
DataQuery
[],
index
=
0
):
{
refId
:
string
;
key
:
string
}
{
return
`
${
index
+
1
}
`
;
return
{
refId
:
getNextQueryLetter
(
queries
),
key
:
generateKey
(
index
)
};
}
export
function
generateEmptyQuery
(
index
=
0
):
{
refId
:
string
;
key
:
string
}
{
return
{
refId
:
generateRefId
(
index
),
key
:
generateKey
(
index
)
};
}
}
/**
/**
...
@@ -238,9 +235,9 @@ export function generateEmptyQuery(index = 0): { refId: string; key: string } {
...
@@ -238,9 +235,9 @@ export function generateEmptyQuery(index = 0): { refId: string; key: string } {
*/
*/
export
function
ensureQueries
(
queries
?:
DataQuery
[]):
DataQuery
[]
{
export
function
ensureQueries
(
queries
?:
DataQuery
[]):
DataQuery
[]
{
if
(
queries
&&
typeof
queries
===
'object'
&&
queries
.
length
>
0
)
{
if
(
queries
&&
typeof
queries
===
'object'
&&
queries
.
length
>
0
)
{
return
queries
.
map
((
query
,
i
)
=>
({
...
query
,
...
generateEmptyQuery
(
i
)
}));
return
queries
.
map
((
query
,
i
)
=>
({
...
query
,
...
generateEmptyQuery
(
queries
,
i
)
}));
}
}
return
[{
...
generateEmptyQuery
()
}];
return
[{
...
generateEmptyQuery
(
queries
)
}];
}
}
/**
/**
...
...
public/app/core/utils/query.ts
0 → 100644
View file @
cf55d688
import
_
from
'lodash'
;
import
{
DataQuery
}
from
'@grafana/ui/'
;
export
const
getNextQueryLetter
=
(
queries
:
DataQuery
[]):
string
=>
{
const
letters
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
return
_
.
find
(
letters
,
refId
=>
{
return
_
.
every
(
queries
,
other
=>
{
return
other
.
refId
!==
refId
;
});
});
};
public/app/features/dashboard/state/PanelModel.ts
View file @
cf55d688
...
@@ -5,6 +5,7 @@ import _ from 'lodash';
...
@@ -5,6 +5,7 @@ import _ from 'lodash';
import
{
Emitter
}
from
'app/core/utils/emitter'
;
import
{
Emitter
}
from
'app/core/utils/emitter'
;
import
{
DataQuery
,
TimeSeries
,
Threshold
,
ScopedVars
,
PanelTypeChangedHook
}
from
'@grafana/ui'
;
import
{
DataQuery
,
TimeSeries
,
Threshold
,
ScopedVars
,
PanelTypeChangedHook
}
from
'@grafana/ui'
;
import
{
TableData
}
from
'@grafana/ui/src'
;
import
{
TableData
}
from
'@grafana/ui/src'
;
import
{
getNextQueryLetter
}
from
'../../../core/utils/query'
;
export
interface
GridPos
{
export
interface
GridPos
{
x
:
number
;
x
:
number
;
...
@@ -128,7 +129,7 @@ export class PanelModel {
...
@@ -128,7 +129,7 @@ export class PanelModel {
if
(
this
.
targets
)
{
if
(
this
.
targets
)
{
for
(
const
query
of
this
.
targets
)
{
for
(
const
query
of
this
.
targets
)
{
if
(
!
query
.
refId
)
{
if
(
!
query
.
refId
)
{
query
.
refId
=
this
.
getNextQueryLetter
(
);
query
.
refId
=
getNextQueryLetter
(
this
.
targets
);
}
}
}
}
}
}
...
@@ -266,20 +267,10 @@ export class PanelModel {
...
@@ -266,20 +267,10 @@ export class PanelModel {
addQuery
(
query
?:
Partial
<
DataQuery
>
)
{
addQuery
(
query
?:
Partial
<
DataQuery
>
)
{
query
=
query
||
{
refId
:
'A'
};
query
=
query
||
{
refId
:
'A'
};
query
.
refId
=
this
.
getNextQueryLetter
(
);
query
.
refId
=
getNextQueryLetter
(
this
.
targets
);
this
.
targets
.
push
(
query
as
DataQuery
);
this
.
targets
.
push
(
query
as
DataQuery
);
}
}
getNextQueryLetter
():
string
{
const
letters
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
;
return
_
.
find
(
letters
,
refId
=>
{
return
_
.
every
(
this
.
targets
,
other
=>
{
return
other
.
refId
!==
refId
;
});
});
}
changeQuery
(
query
:
DataQuery
,
index
:
number
)
{
changeQuery
(
query
:
DataQuery
,
index
:
number
)
{
// ensure refId is maintained
// ensure refId is maintained
query
.
refId
=
this
.
targets
[
index
].
refId
;
query
.
refId
=
this
.
targets
[
index
].
refId
;
...
...
public/app/features/explore/state/actions.ts
View file @
cf55d688
...
@@ -60,7 +60,6 @@ import {
...
@@ -60,7 +60,6 @@ import {
splitCloseAction
,
splitCloseAction
,
splitOpenAction
,
splitOpenAction
,
addQueryRowAction
,
addQueryRowAction
,
AddQueryRowPayload
,
toggleGraphAction
,
toggleGraphAction
,
toggleLogsAction
,
toggleLogsAction
,
toggleTableAction
,
toggleTableAction
,
...
@@ -87,9 +86,12 @@ const updateExploreUIState = (exploreId, uiStateFragment: Partial<ExploreUIState
...
@@ -87,9 +86,12 @@ const updateExploreUIState = (exploreId, uiStateFragment: Partial<ExploreUIState
/**
/**
* Adds a query row after the row with the given index.
* Adds a query row after the row with the given index.
*/
*/
export
function
addQueryRow
(
exploreId
:
ExploreId
,
index
:
number
):
ActionOf
<
AddQueryRowPayload
>
{
export
function
addQueryRow
(
exploreId
:
ExploreId
,
index
:
number
):
ThunkResult
<
void
>
{
const
query
=
generateEmptyQuery
(
index
+
1
);
return
(
dispatch
,
getState
)
=>
{
return
addQueryRowAction
({
exploreId
,
index
,
query
});
const
query
=
generateEmptyQuery
(
getState
().
explore
[
exploreId
].
queries
,
index
);
dispatch
(
addQueryRowAction
({
exploreId
,
index
,
query
}));
};
}
}
/**
/**
...
@@ -126,10 +128,10 @@ export function changeQuery(
...
@@ -126,10 +128,10 @@ export function changeQuery(
index
:
number
,
index
:
number
,
override
:
boolean
override
:
boolean
):
ThunkResult
<
void
>
{
):
ThunkResult
<
void
>
{
return
dispatch
=>
{
return
(
dispatch
,
getState
)
=>
{
// Null query means reset
// Null query means reset
if
(
query
===
null
)
{
if
(
query
===
null
)
{
query
=
{
...
generateEmptyQuery
(
index
)
};
query
=
{
...
generateEmptyQuery
(
getState
().
explore
[
exploreId
].
queries
)
};
}
}
dispatch
(
changeQueryAction
({
exploreId
,
query
,
index
,
override
}));
dispatch
(
changeQueryAction
({
exploreId
,
query
,
index
,
override
}));
...
@@ -287,7 +289,7 @@ export function importQueries(
...
@@ -287,7 +289,7 @@ export function importQueries(
const
nextQueries
=
importedQueries
.
map
((
q
,
i
)
=>
({
const
nextQueries
=
importedQueries
.
map
((
q
,
i
)
=>
({
...
q
,
...
q
,
...
generateEmptyQuery
(
i
),
...
generateEmptyQuery
(
queries
),
}));
}));
dispatch
(
queriesImportedAction
({
exploreId
,
queries
:
nextQueries
}));
dispatch
(
queriesImportedAction
({
exploreId
,
queries
:
nextQueries
}));
...
@@ -629,9 +631,9 @@ export function scanStart(exploreId: ExploreId, scanner: RangeScanner): ThunkRes
...
@@ -629,9 +631,9 @@ export function scanStart(exploreId: ExploreId, scanner: RangeScanner): ThunkRes
* Use this action for clicks on query examples. Triggers a query run.
* Use this action for clicks on query examples. Triggers a query run.
*/
*/
export
function
setQueries
(
exploreId
:
ExploreId
,
rawQueries
:
DataQuery
[]):
ThunkResult
<
void
>
{
export
function
setQueries
(
exploreId
:
ExploreId
,
rawQueries
:
DataQuery
[]):
ThunkResult
<
void
>
{
return
dispatch
=>
{
return
(
dispatch
,
getState
)
=>
{
// Inject react keys into query objects
// Inject react keys into query objects
const
queries
=
rawQueries
.
map
(
q
=>
({
...
q
,
...
generateEmptyQuery
()
}));
const
queries
=
rawQueries
.
map
(
q
=>
({
...
q
,
...
generateEmptyQuery
(
getState
().
explore
[
exploreId
].
queries
)
}));
dispatch
(
setQueriesAction
({
exploreId
,
queries
}));
dispatch
(
setQueriesAction
({
exploreId
,
queries
}));
dispatch
(
runQueries
(
exploreId
));
dispatch
(
runQueries
(
exploreId
));
};
};
...
...
public/app/features/explore/state/reducers.ts
View file @
cf55d688
...
@@ -127,7 +127,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
...
@@ -127,7 +127,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
const
{
query
,
index
}
=
action
.
payload
;
const
{
query
,
index
}
=
action
.
payload
;
// Override path: queries are completely reset
// Override path: queries are completely reset
const
nextQuery
:
DataQuery
=
{
...
query
,
...
generateEmptyQuery
(
index
)
};
const
nextQuery
:
DataQuery
=
{
...
query
,
...
generateEmptyQuery
(
state
.
queries
)
};
const
nextQueries
=
[...
queries
];
const
nextQueries
=
[...
queries
];
nextQueries
[
index
]
=
nextQuery
;
nextQueries
[
index
]
=
nextQuery
;
...
@@ -267,7 +267,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
...
@@ -267,7 +267,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
// Modify all queries
// Modify all queries
nextQueries
=
queries
.
map
((
query
,
i
)
=>
({
nextQueries
=
queries
.
map
((
query
,
i
)
=>
({
...
modifier
({
...
query
},
modification
),
...
modifier
({
...
query
},
modification
),
...
generateEmptyQuery
(
i
),
...
generateEmptyQuery
(
state
.
queries
),
}));
}));
// Discard all ongoing transactions
// Discard all ongoing transactions
nextQueryTransactions
=
[];
nextQueryTransactions
=
[];
...
@@ -276,7 +276,9 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
...
@@ -276,7 +276,9 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
nextQueries
=
queries
.
map
((
query
,
i
)
=>
{
nextQueries
=
queries
.
map
((
query
,
i
)
=>
{
// Synchronize all queries with local query cache to ensure consistency
// Synchronize all queries with local query cache to ensure consistency
// TODO still needed?
// TODO still needed?
return
i
===
index
?
{
...
modifier
({
...
query
},
modification
),
...
generateEmptyQuery
(
i
)
}
:
query
;
return
i
===
index
?
{
...
modifier
({
...
query
},
modification
),
...
generateEmptyQuery
(
state
.
queries
)
}
:
query
;
});
});
nextQueryTransactions
=
queryTransactions
nextQueryTransactions
=
queryTransactions
// Consume the hint corresponding to the action
// Consume the hint corresponding to the action
...
...
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