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
2c255fd8
Commit
2c255fd8
authored
Feb 05, 2019
by
Hugo Häggmark
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed initialQueries to queries
parent
f74ebdad
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
54 additions
and
68 deletions
+54
-68
packages/grafana-ui/src/types/plugin.ts
+1
-1
public/app/features/explore/QueryRow.tsx
+7
-7
public/app/features/explore/state/actions.ts
+8
-19
public/app/features/explore/state/reducers.ts
+25
-22
public/app/plugins/datasource/loki/components/LokiQueryEditor.tsx
+1
-1
public/app/plugins/datasource/loki/components/LokiQueryField.tsx
+5
-8
public/app/plugins/datasource/prometheus/components/PromQueryField.tsx
+5
-8
public/app/types/explore.ts
+2
-2
No files found.
packages/grafana-ui/src/types/plugin.ts
View file @
2c255fd8
...
...
@@ -56,7 +56,7 @@ export interface QueryEditorProps<DSType extends DataSourceApi, TQuery extends D
export
interface
ExploreQueryFieldProps
<
DSType
extends
DataSourceApi
,
TQuery
extends
DataQuery
>
{
datasource
:
DSType
;
initialQ
uery
:
TQuery
;
q
uery
:
TQuery
;
error
?:
string
|
JSX
.
Element
;
hint
?:
QueryHint
;
history
:
any
[];
...
...
public/app/features/explore/QueryRow.tsx
View file @
2c255fd8
...
...
@@ -35,7 +35,7 @@ interface QueryRowProps {
highlightLogsExpressionAction
:
typeof
highlightLogsExpressionAction
;
history
:
HistoryItem
[];
index
:
number
;
initialQ
uery
:
DataQuery
;
q
uery
:
DataQuery
;
modifyQueries
:
typeof
modifyQueries
;
queryTransactions
:
QueryTransaction
[];
exploreEvents
:
Emitter
;
...
...
@@ -95,7 +95,7 @@ export class QueryRow extends PureComponent<QueryRowProps> {
},
500
);
render
()
{
const
{
datasourceInstance
,
history
,
index
,
initialQ
uery
,
queryTransactions
,
exploreEvents
,
range
}
=
this
.
props
;
const
{
datasourceInstance
,
history
,
index
,
q
uery
,
queryTransactions
,
exploreEvents
,
range
}
=
this
.
props
;
const
transactions
=
queryTransactions
.
filter
(
t
=>
t
.
rowIndex
===
index
);
const
transactionWithError
=
transactions
.
find
(
t
=>
t
.
error
!==
undefined
);
const
hint
=
getFirstHintFromTransactions
(
transactions
);
...
...
@@ -110,7 +110,7 @@ export class QueryRow extends PureComponent<QueryRowProps> {
{
QueryField
?
(
<
QueryField
datasource=
{
datasourceInstance
}
initialQuery=
{
initialQ
uery
}
query=
{
q
uery
}
error=
{
queryError
}
hint=
{
hint
}
history=
{
history
}
...
...
@@ -124,7 +124,7 @@ export class QueryRow extends PureComponent<QueryRowProps> {
error=
{
queryError
}
onQueryChange=
{
this
.
onChangeQuery
}
onExecuteQuery=
{
this
.
onExecuteQuery
}
initialQuery=
{
initialQ
uery
}
initialQuery=
{
q
uery
}
exploreEvents=
{
exploreEvents
}
range=
{
range
}
/>
...
...
@@ -155,9 +155,9 @@ export class QueryRow extends PureComponent<QueryRowProps> {
function
mapStateToProps
(
state
:
StoreState
,
{
exploreId
,
index
})
{
const
explore
=
state
.
explore
;
const
item
:
ExploreItemState
=
explore
[
exploreId
];
const
{
datasourceInstance
,
history
,
initialQ
ueries
,
queryTransactions
,
range
}
=
item
;
const
initialQuery
=
initialQ
ueries
[
index
];
return
{
datasourceInstance
,
history
,
initialQ
uery
,
queryTransactions
,
range
};
const
{
datasourceInstance
,
history
,
q
ueries
,
queryTransactions
,
range
}
=
item
;
const
query
=
q
ueries
[
index
];
return
{
datasourceInstance
,
history
,
q
uery
,
queryTransactions
,
range
};
}
const
mapDispatchToProps
=
{
...
...
public/app/features/explore/state/actions.ts
View file @
2c255fd8
...
...
@@ -87,7 +87,7 @@ export function changeDatasource(exploreId: ExploreId, datasource: string): Thun
return
async
(
dispatch
,
getState
)
=>
{
const
newDataSourceInstance
=
await
getDatasourceSrv
().
get
(
datasource
);
const
currentDataSourceInstance
=
getState
().
explore
[
exploreId
].
datasourceInstance
;
const
queries
=
getState
().
explore
[
exploreId
].
initialQ
ueries
;
const
queries
=
getState
().
explore
[
exploreId
].
q
ueries
;
await
dispatch
(
importQueries
(
exploreId
,
queries
,
currentDataSourceInstance
,
newDataSourceInstance
));
...
...
@@ -494,7 +494,7 @@ export function runQueries(exploreId: ExploreId, ignoreUIState = false) {
return
(
dispatch
,
getState
)
=>
{
const
{
datasourceInstance
,
initialQ
ueries
,
q
ueries
,
showingLogs
,
showingGraph
,
showingTable
,
...
...
@@ -503,7 +503,7 @@ export function runQueries(exploreId: ExploreId, ignoreUIState = false) {
supportsTable
,
}
=
getState
().
explore
[
exploreId
];
if
(
!
hasNonEmptyQuery
(
initialQ
ueries
))
{
if
(
!
hasNonEmptyQuery
(
q
ueries
))
{
dispatch
(
runQueriesEmptyAction
({
exploreId
}));
dispatch
(
stateSave
());
// Remember to saves to state and update location
return
;
...
...
@@ -565,14 +565,7 @@ function runQueriesForType(
resultGetter
?:
any
)
{
return
async
(
dispatch
,
getState
)
=>
{
const
{
datasourceInstance
,
eventBridge
,
initialQueries
:
queries
,
queryIntervals
,
range
,
scanning
,
}
=
getState
().
explore
[
exploreId
];
const
{
datasourceInstance
,
eventBridge
,
queries
,
queryIntervals
,
range
,
scanning
}
=
getState
().
explore
[
exploreId
];
const
datasourceId
=
datasourceInstance
.
meta
.
id
;
// Run all queries concurrently
...
...
@@ -653,7 +646,7 @@ export function splitOpen(): ThunkResult<void> {
const
itemState
=
{
...
leftState
,
queryTransactions
:
[],
initialQueries
:
leftState
.
initialQ
ueries
.
slice
(),
queries
:
leftState
.
q
ueries
.
slice
(),
};
dispatch
(
splitOpenAction
({
itemState
}));
dispatch
(
stateSave
());
...
...
@@ -670,7 +663,7 @@ export function stateSave() {
const
urlStates
:
{
[
index
:
string
]:
string
}
=
{};
const
leftUrlState
:
ExploreUrlState
=
{
datasource
:
left
.
datasourceInstance
.
name
,
queries
:
left
.
initialQ
ueries
.
map
(
clearQueryKeys
),
queries
:
left
.
q
ueries
.
map
(
clearQueryKeys
),
range
:
left
.
range
,
ui
:
{
showingGraph
:
left
.
showingGraph
,
...
...
@@ -682,13 +675,9 @@ export function stateSave() {
if
(
split
)
{
const
rightUrlState
:
ExploreUrlState
=
{
datasource
:
right
.
datasourceInstance
.
name
,
queries
:
right
.
initialQ
ueries
.
map
(
clearQueryKeys
),
queries
:
right
.
q
ueries
.
map
(
clearQueryKeys
),
range
:
right
.
range
,
ui
:
{
showingGraph
:
right
.
showingGraph
,
showingLogs
:
right
.
showingLogs
,
showingTable
:
right
.
showingTable
,
},
ui
:
{
showingGraph
:
right
.
showingGraph
,
showingLogs
:
right
.
showingLogs
,
showingTable
:
right
.
showingTable
},
};
urlStates
.
right
=
serializeStateToUrlParam
(
rightUrlState
,
true
);
...
...
public/app/features/explore/state/reducers.ts
View file @
2c255fd8
...
...
@@ -60,7 +60,7 @@ export const makeExploreItemState = (): ExploreItemState => ({
datasourceMissing
:
false
,
exploreDatasources
:
[],
history
:
[],
initialQ
ueries
:
[],
q
ueries
:
[],
initialized
:
false
,
queryTransactions
:
[],
queryIntervals
:
{
interval
:
'15s'
,
intervalMs
:
DEFAULT_GRAPH_INTERVAL
},
...
...
@@ -92,23 +92,26 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
.
addMapper
({
filter
:
addQueryRowAction
,
mapper
:
(
state
,
action
):
ExploreItemState
=>
{
const
{
initialQ
ueries
,
queryTransactions
}
=
state
;
const
{
q
ueries
,
queryTransactions
}
=
state
;
const
{
index
,
query
}
=
action
.
payload
;
// Add to
initialQ
ueries, which will cause a new row to be rendered
const
nextQueries
=
[...
initialQueries
.
slice
(
0
,
index
+
1
),
{
...
query
},
...
initialQ
ueries
.
slice
(
index
+
1
)];
// Add to
q
ueries, which will cause a new row to be rendered
const
nextQueries
=
[...
queries
.
slice
(
0
,
index
+
1
),
{
...
query
},
...
q
ueries
.
slice
(
index
+
1
)];
// Ongoing transactions need to update their row indices
const
nextQueryTransactions
=
queryTransactions
.
map
(
qt
=>
{
if
(
qt
.
rowIndex
>
index
)
{
return
{
...
qt
,
rowIndex
:
qt
.
rowIndex
+
1
};
return
{
...
qt
,
rowIndex
:
qt
.
rowIndex
+
1
,
};
}
return
qt
;
});
return
{
...
state
,
initialQ
ueries
:
nextQueries
,
q
ueries
:
nextQueries
,
logsHighlighterExpressions
:
undefined
,
queryTransactions
:
nextQueryTransactions
,
queryKeys
:
getQueryKeys
(
nextQueries
,
state
.
datasourceInstance
),
...
...
@@ -118,12 +121,12 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
.
addMapper
({
filter
:
changeQueryAction
,
mapper
:
(
state
,
action
):
ExploreItemState
=>
{
const
{
initialQ
ueries
,
queryTransactions
}
=
state
;
const
{
q
ueries
,
queryTransactions
}
=
state
;
const
{
query
,
index
}
=
action
.
payload
;
// Override path: queries are completely reset
const
nextQuery
:
DataQuery
=
{
...
query
,
...
generateEmptyQuery
(
index
)
};
const
nextQueries
=
[...
initialQ
ueries
];
const
nextQueries
=
[...
q
ueries
];
nextQueries
[
index
]
=
nextQuery
;
// Discard ongoing transaction related to row query
...
...
@@ -131,7 +134,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
return
{
...
state
,
initialQ
ueries
:
nextQueries
,
q
ueries
:
nextQueries
,
queryTransactions
:
nextQueryTransactions
,
queryKeys
:
getQueryKeys
(
nextQueries
,
state
.
datasourceInstance
),
};
...
...
@@ -162,7 +165,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
const
queries
=
ensureQueries
();
return
{
...
state
,
initialQ
ueries
:
queries
.
slice
(),
q
ueries
:
queries
.
slice
(),
queryTransactions
:
[],
showingStartPage
:
Boolean
(
state
.
StartPage
),
queryKeys
:
getQueryKeys
(
queries
,
state
.
datasourceInstance
),
...
...
@@ -186,7 +189,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
eventBridge
,
exploreDatasources
,
range
,
initialQueries
:
queries
,
queries
,
initialized
:
true
,
queryKeys
:
getQueryKeys
(
queries
,
state
.
datasourceInstance
),
...
ui
,
...
...
@@ -197,7 +200,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
filter
:
updateDatasourceInstanceAction
,
mapper
:
(
state
,
action
):
ExploreItemState
=>
{
const
{
datasourceInstance
}
=
action
.
payload
;
return
{
...
state
,
datasourceInstance
,
queryKeys
:
getQueryKeys
(
state
.
initialQ
ueries
,
datasourceInstance
)
};
return
{
...
state
,
datasourceInstance
,
queryKeys
:
getQueryKeys
(
state
.
q
ueries
,
datasourceInstance
)
};
},
})
.
addMapper
({
...
...
@@ -254,13 +257,13 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
.
addMapper
({
filter
:
modifyQueriesAction
,
mapper
:
(
state
,
action
):
ExploreItemState
=>
{
const
{
initialQ
ueries
,
queryTransactions
}
=
state
;
const
{
q
ueries
,
queryTransactions
}
=
state
;
const
{
modification
,
index
,
modifier
}
=
action
.
payload
;
let
nextQueries
:
DataQuery
[];
let
nextQueryTransactions
;
if
(
index
===
undefined
)
{
// Modify all queries
nextQueries
=
initialQ
ueries
.
map
((
query
,
i
)
=>
({
nextQueries
=
q
ueries
.
map
((
query
,
i
)
=>
({
...
modifier
({
...
query
},
modification
),
...
generateEmptyQuery
(
i
),
}));
...
...
@@ -268,7 +271,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
nextQueryTransactions
=
[];
}
else
{
// Modify query only at index
nextQueries
=
initialQ
ueries
.
map
((
query
,
i
)
=>
{
nextQueries
=
q
ueries
.
map
((
query
,
i
)
=>
{
// Synchronize all queries with local query cache to ensure consistency
// TODO still needed?
return
i
===
index
?
{
...
modifier
({
...
query
},
modification
),
...
generateEmptyQuery
(
i
)
}
:
query
;
...
...
@@ -286,7 +289,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
}
return
{
...
state
,
initialQ
ueries
:
nextQueries
,
q
ueries
:
nextQueries
,
queryKeys
:
getQueryKeys
(
nextQueries
,
state
.
datasourceInstance
),
queryTransactions
:
nextQueryTransactions
,
};
...
...
@@ -332,14 +335,14 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
.
addMapper
({
filter
:
removeQueryRowAction
,
mapper
:
(
state
,
action
):
ExploreItemState
=>
{
const
{
datasourceInstance
,
initialQ
ueries
,
queryIntervals
,
queryTransactions
,
queryKeys
}
=
state
;
const
{
datasourceInstance
,
q
ueries
,
queryIntervals
,
queryTransactions
,
queryKeys
}
=
state
;
const
{
index
}
=
action
.
payload
;
if
(
initialQ
ueries
.
length
<=
1
)
{
if
(
q
ueries
.
length
<=
1
)
{
return
state
;
}
const
nextQueries
=
[...
initialQueries
.
slice
(
0
,
index
),
...
initialQ
ueries
.
slice
(
index
+
1
)];
const
nextQueries
=
[...
queries
.
slice
(
0
,
index
),
...
q
ueries
.
slice
(
index
+
1
)];
const
nextQueryKeys
=
[...
queryKeys
.
slice
(
0
,
index
),
...
queryKeys
.
slice
(
index
+
1
)];
// Discard transactions related to row query
...
...
@@ -353,7 +356,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
return
{
...
state
,
...
results
,
initialQ
ueries
:
nextQueries
,
q
ueries
:
nextQueries
,
logsHighlighterExpressions
:
undefined
,
queryTransactions
:
nextQueryTransactions
,
queryKeys
:
nextQueryKeys
,
...
...
@@ -398,7 +401,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
const
{
queries
}
=
action
.
payload
;
return
{
...
state
,
initialQ
ueries
:
queries
.
slice
(),
q
ueries
:
queries
.
slice
(),
queryKeys
:
getQueryKeys
(
queries
,
state
.
datasourceInstance
),
};
},
...
...
@@ -452,7 +455,7 @@ export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemSta
const
{
queries
}
=
action
.
payload
;
return
{
...
state
,
initialQueries
:
queries
,
queries
,
queryKeys
:
getQueryKeys
(
queries
,
state
.
datasourceInstance
),
};
},
...
...
public/app/plugins/datasource/loki/components/LokiQueryEditor.tsx
View file @
2c255fd8
...
...
@@ -59,7 +59,7 @@ export class LokiQueryEditor extends PureComponent<Props> {
<
div
>
<
LokiQueryField
datasource=
{
datasource
}
initialQ
uery=
{
query
}
q
uery=
{
query
}
onQueryChange=
{
this
.
onFieldChange
}
onExecuteQuery=
{
this
.
onRunQuery
}
history=
{
[]
}
...
...
public/app/plugins/datasource/loki/components/LokiQueryField.tsx
View file @
2c255fd8
...
...
@@ -162,13 +162,10 @@ export class LokiQueryField extends React.PureComponent<LokiQueryFieldProps, Lok
onChangeQuery
=
(
value
:
string
,
override
?:
boolean
)
=>
{
// Send text change to parent
const
{
initialQ
uery
,
onQueryChange
,
onExecuteQuery
}
=
this
.
props
;
const
{
q
uery
,
onQueryChange
,
onExecuteQuery
}
=
this
.
props
;
if
(
onQueryChange
)
{
const
query
=
{
...
initialQuery
,
expr
:
value
,
};
onQueryChange
(
query
);
const
nextQuery
=
{
...
query
,
expr
:
value
};
onQueryChange
(
nextQuery
);
if
(
override
&&
onExecuteQuery
)
{
onExecuteQuery
();
...
...
@@ -217,7 +214,7 @@ export class LokiQueryField extends React.PureComponent<LokiQueryFieldProps, Lok
};
render
()
{
const
{
error
,
hint
,
initialQ
uery
}
=
this
.
props
;
const
{
error
,
hint
,
q
uery
}
=
this
.
props
;
const
{
logLabelOptions
,
syntaxLoaded
}
=
this
.
state
;
const
cleanText
=
this
.
languageProvider
?
this
.
languageProvider
.
cleanText
:
undefined
;
const
hasLogLabels
=
logLabelOptions
&&
logLabelOptions
.
length
>
0
;
...
...
@@ -237,7 +234,7 @@ export class LokiQueryField extends React.PureComponent<LokiQueryFieldProps, Lok
<
QueryField
additionalPlugins=
{
this
.
plugins
}
cleanText=
{
cleanText
}
initialQuery=
{
initialQ
uery
.
expr
}
initialQuery=
{
q
uery
.
expr
}
onTypeahead=
{
this
.
onTypeahead
}
onWillApplySuggestion=
{
willApplySuggestion
}
onQueryChange=
{
this
.
onChangeQuery
}
...
...
public/app/plugins/datasource/prometheus/components/PromQueryField.tsx
View file @
2c255fd8
...
...
@@ -168,13 +168,10 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
onChangeQuery
=
(
value
:
string
,
override
?:
boolean
)
=>
{
// Send text change to parent
const
{
initialQ
uery
,
onQueryChange
,
onExecuteQuery
}
=
this
.
props
;
const
{
q
uery
,
onQueryChange
,
onExecuteQuery
}
=
this
.
props
;
if
(
onQueryChange
)
{
const
query
:
PromQuery
=
{
...
initialQuery
,
expr
:
value
,
};
onQueryChange
(
query
);
const
nextQuery
:
PromQuery
=
{
...
query
,
expr
:
value
};
onQueryChange
(
nextQuery
);
if
(
override
&&
onExecuteQuery
)
{
onExecuteQuery
();
...
...
@@ -240,7 +237,7 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
};
render
()
{
const
{
error
,
hint
,
initialQ
uery
}
=
this
.
props
;
const
{
error
,
hint
,
q
uery
}
=
this
.
props
;
const
{
metricsOptions
,
syntaxLoaded
}
=
this
.
state
;
const
cleanText
=
this
.
languageProvider
?
this
.
languageProvider
.
cleanText
:
undefined
;
const
chooserText
=
syntaxLoaded
?
'Metrics'
:
'Loading metrics...'
;
...
...
@@ -259,7 +256,7 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
<
QueryField
additionalPlugins=
{
this
.
plugins
}
cleanText=
{
cleanText
}
initialQuery=
{
initialQ
uery
.
expr
}
initialQuery=
{
q
uery
.
expr
}
onTypeahead=
{
this
.
onTypeahead
}
onWillApplySuggestion=
{
willApplySuggestion
}
onQueryChange=
{
this
.
onChangeQuery
}
...
...
public/app/types/explore.ts
View file @
2c255fd8
...
...
@@ -153,10 +153,10 @@ export interface ExploreItemState {
*/
history
:
HistoryItem
[];
/**
*
Initial q
ueries for this Explore, e.g., set via URL. Each query will be
*
Q
ueries for this Explore, e.g., set via URL. Each query will be
* converted to a query row.
*/
initialQ
ueries
:
DataQuery
[];
q
ueries
:
DataQuery
[];
/**
* True if this Explore area has been initialized.
* Used to distinguish URL state injection versus split view state injection.
...
...
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