|
|
@@ -38,6 +38,7 @@ import {
|
|
|
ResultType,
|
|
|
QueryOptions,
|
|
|
QueryTransaction,
|
|
|
+ ExploreUIState,
|
|
|
} from 'app/types/explore';
|
|
|
|
|
|
import {
|
|
|
@@ -78,7 +79,15 @@ export function changeDatasource(exploreId: ExploreId, datasource: string): Thun
|
|
|
await dispatch(importQueries(exploreId, modifiedQueries, currentDataSourceInstance, newDataSourceInstance));
|
|
|
|
|
|
dispatch(updateDatasourceInstance(exploreId, newDataSourceInstance));
|
|
|
- dispatch(loadDatasource(exploreId, newDataSourceInstance));
|
|
|
+
|
|
|
+ try {
|
|
|
+ await dispatch(loadDatasource(exploreId, newDataSourceInstance));
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ dispatch(runQueries(exploreId));
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -154,7 +163,8 @@ export function initializeExplore(
|
|
|
queries: DataQuery[],
|
|
|
range: RawTimeRange,
|
|
|
containerWidth: number,
|
|
|
- eventBridge: Emitter
|
|
|
+ eventBridge: Emitter,
|
|
|
+ ui: ExploreUIState
|
|
|
): ThunkResult<void> {
|
|
|
return async dispatch => {
|
|
|
const exploreDatasources: DataSourceSelectItem[] = getDatasourceSrv()
|
|
|
@@ -175,6 +185,7 @@ export function initializeExplore(
|
|
|
exploreDatasources,
|
|
|
queries,
|
|
|
range,
|
|
|
+ ui,
|
|
|
},
|
|
|
});
|
|
|
|
|
|
@@ -194,7 +205,14 @@ export function initializeExplore(
|
|
|
}
|
|
|
|
|
|
dispatch(updateDatasourceInstance(exploreId, instance));
|
|
|
- dispatch(loadDatasource(exploreId, instance));
|
|
|
+
|
|
|
+ try {
|
|
|
+ await dispatch(loadDatasource(exploreId, instance));
|
|
|
+ } catch (error) {
|
|
|
+ console.error(error);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ dispatch(runQueries(exploreId, true));
|
|
|
} else {
|
|
|
dispatch(loadDatasourceMissing(exploreId));
|
|
|
}
|
|
|
@@ -258,10 +276,7 @@ export const queriesImported = (exploreId: ExploreId, queries: DataQuery[]): Que
|
|
|
* run datasource-specific code. Existing queries are imported to the new datasource if an importer exists,
|
|
|
* e.g., Prometheus -> Loki queries.
|
|
|
*/
|
|
|
-export const loadDatasourceSuccess = (
|
|
|
- exploreId: ExploreId,
|
|
|
- instance: any,
|
|
|
-): LoadDatasourceSuccessAction => {
|
|
|
+export const loadDatasourceSuccess = (exploreId: ExploreId, instance: any): LoadDatasourceSuccessAction => {
|
|
|
// Capabilities
|
|
|
const supportsGraph = instance.meta.metrics;
|
|
|
const supportsLogs = instance.meta.logs;
|
|
|
@@ -343,8 +358,8 @@ export function loadDatasource(exploreId: ExploreId, instance: DataSourceApi): T
|
|
|
|
|
|
// Keep ID to track selection
|
|
|
dispatch(loadDatasourcePending(exploreId, datasourceName));
|
|
|
-
|
|
|
let datasourceError = null;
|
|
|
+
|
|
|
try {
|
|
|
const testResult = await instance.testDatasource();
|
|
|
datasourceError = testResult.status === 'success' ? null : testResult.message;
|
|
|
@@ -354,7 +369,7 @@ export function loadDatasource(exploreId: ExploreId, instance: DataSourceApi): T
|
|
|
|
|
|
if (datasourceError) {
|
|
|
dispatch(loadDatasourceFailure(exploreId, datasourceError));
|
|
|
- return;
|
|
|
+ return Promise.reject(`${datasourceName} loading failed`);
|
|
|
}
|
|
|
|
|
|
if (datasourceName !== getState().explore[exploreId].requestedDatasourceName) {
|
|
|
@@ -372,7 +387,7 @@ export function loadDatasource(exploreId: ExploreId, instance: DataSourceApi): T
|
|
|
}
|
|
|
|
|
|
dispatch(loadDatasourceSuccess(exploreId, instance));
|
|
|
- dispatch(runQueries(exploreId));
|
|
|
+ return Promise.resolve();
|
|
|
};
|
|
|
}
|
|
|
|
|
|
@@ -572,7 +587,7 @@ export function removeQueryRow(exploreId: ExploreId, index: number): ThunkResult
|
|
|
/**
|
|
|
* Main action to run queries and dispatches sub-actions based on which result viewers are active
|
|
|
*/
|
|
|
-export function runQueries(exploreId: ExploreId) {
|
|
|
+export function runQueries(exploreId: ExploreId, ignoreUIState = false) {
|
|
|
return (dispatch, getState) => {
|
|
|
const {
|
|
|
datasourceInstance,
|
|
|
@@ -596,7 +611,7 @@ export function runQueries(exploreId: ExploreId) {
|
|
|
const interval = datasourceInstance.interval;
|
|
|
|
|
|
// Keep table queries first since they need to return quickly
|
|
|
- if (showingTable && supportsTable) {
|
|
|
+ if ((ignoreUIState || showingTable) && supportsTable) {
|
|
|
dispatch(
|
|
|
runQueriesForType(
|
|
|
exploreId,
|
|
|
@@ -611,7 +626,7 @@ export function runQueries(exploreId: ExploreId) {
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
- if (showingGraph && supportsGraph) {
|
|
|
+ if ((ignoreUIState || showingGraph) && supportsGraph) {
|
|
|
dispatch(
|
|
|
runQueriesForType(
|
|
|
exploreId,
|
|
|
@@ -625,9 +640,10 @@ export function runQueries(exploreId: ExploreId) {
|
|
|
)
|
|
|
);
|
|
|
}
|
|
|
- if (showingLogs && supportsLogs) {
|
|
|
+ if ((ignoreUIState || showingLogs) && supportsLogs) {
|
|
|
dispatch(runQueriesForType(exploreId, 'Logs', { interval, format: 'logs' }));
|
|
|
}
|
|
|
+
|
|
|
dispatch(stateSave());
|
|
|
};
|
|
|
}
|
|
|
@@ -766,6 +782,11 @@ export function stateSave() {
|
|
|
datasource: left.datasourceInstance.name,
|
|
|
queries: left.modifiedQueries.map(clearQueryKeys),
|
|
|
range: left.range,
|
|
|
+ ui: {
|
|
|
+ showingGraph: left.showingGraph,
|
|
|
+ showingLogs: left.showingLogs,
|
|
|
+ showingTable: left.showingTable,
|
|
|
+ },
|
|
|
};
|
|
|
urlStates.left = serializeStateToUrlParam(leftUrlState, true);
|
|
|
if (split) {
|
|
|
@@ -773,48 +794,64 @@ export function stateSave() {
|
|
|
datasource: right.datasourceInstance.name,
|
|
|
queries: right.modifiedQueries.map(clearQueryKeys),
|
|
|
range: right.range,
|
|
|
+ ui: {
|
|
|
+ showingGraph: right.showingGraph,
|
|
|
+ showingLogs: right.showingLogs,
|
|
|
+ showingTable: right.showingTable,
|
|
|
+ },
|
|
|
};
|
|
|
+
|
|
|
urlStates.right = serializeStateToUrlParam(rightUrlState, true);
|
|
|
}
|
|
|
+
|
|
|
dispatch(updateLocation({ query: urlStates }));
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Expand/collapse the graph result viewer. When collapsed, graph queries won't be run.
|
|
|
+ * Creates action to collapse graph/logs/table panel. When panel is collapsed,
|
|
|
+ * queries won't be run
|
|
|
*/
|
|
|
-export function toggleGraph(exploreId: ExploreId): ThunkResult<void> {
|
|
|
+const togglePanelActionCreator = (type: ActionTypes.ToggleGraph | ActionTypes.ToggleTable | ActionTypes.ToggleLogs) => (
|
|
|
+ exploreId: ExploreId
|
|
|
+) => {
|
|
|
return (dispatch, getState) => {
|
|
|
- dispatch({ type: ActionTypes.ToggleGraph, payload: { exploreId } });
|
|
|
- if (getState().explore[exploreId].showingGraph) {
|
|
|
+ let shouldRunQueries;
|
|
|
+ dispatch({ type, payload: { exploreId } });
|
|
|
+ dispatch(stateSave());
|
|
|
+
|
|
|
+ switch (type) {
|
|
|
+ case ActionTypes.ToggleGraph:
|
|
|
+ shouldRunQueries = getState().explore[exploreId].showingGraph;
|
|
|
+ break;
|
|
|
+ case ActionTypes.ToggleLogs:
|
|
|
+ shouldRunQueries = getState().explore[exploreId].showingLogs;
|
|
|
+ break;
|
|
|
+ case ActionTypes.ToggleTable:
|
|
|
+ shouldRunQueries = getState().explore[exploreId].showingTable;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (shouldRunQueries) {
|
|
|
dispatch(runQueries(exploreId));
|
|
|
}
|
|
|
};
|
|
|
-}
|
|
|
+};
|
|
|
+
|
|
|
+/**
|
|
|
+ * Expand/collapse the graph result viewer. When collapsed, graph queries won't be run.
|
|
|
+ */
|
|
|
+export const toggleGraph = togglePanelActionCreator(ActionTypes.ToggleGraph);
|
|
|
|
|
|
/**
|
|
|
* Expand/collapse the logs result viewer. When collapsed, log queries won't be run.
|
|
|
*/
|
|
|
-export function toggleLogs(exploreId: ExploreId): ThunkResult<void> {
|
|
|
- return (dispatch, getState) => {
|
|
|
- dispatch({ type: ActionTypes.ToggleLogs, payload: { exploreId } });
|
|
|
- if (getState().explore[exploreId].showingLogs) {
|
|
|
- dispatch(runQueries(exploreId));
|
|
|
- }
|
|
|
- };
|
|
|
-}
|
|
|
+export const toggleLogs = togglePanelActionCreator(ActionTypes.ToggleLogs);
|
|
|
|
|
|
/**
|
|
|
* Expand/collapse the table result viewer. When collapsed, table queries won't be run.
|
|
|
*/
|
|
|
-export function toggleTable(exploreId: ExploreId): ThunkResult<void> {
|
|
|
- return (dispatch, getState) => {
|
|
|
- dispatch({ type: ActionTypes.ToggleTable, payload: { exploreId } });
|
|
|
- if (getState().explore[exploreId].showingTable) {
|
|
|
- dispatch(runQueries(exploreId));
|
|
|
- }
|
|
|
- };
|
|
|
-}
|
|
|
+export const toggleTable = togglePanelActionCreator(ActionTypes.ToggleTable);
|
|
|
|
|
|
/**
|
|
|
* Resets state for explore.
|