|
|
@@ -3,11 +3,41 @@ import {
|
|
|
generateEmptyQuery,
|
|
|
getIntervals,
|
|
|
ensureQueries,
|
|
|
+ getQueryKeys,
|
|
|
} from 'app/core/utils/explore';
|
|
|
import { ExploreItemState, ExploreState, QueryTransaction } from 'app/types/explore';
|
|
|
import { DataQuery } from '@grafana/ui/src/types';
|
|
|
|
|
|
-import { Action, ActionTypes } from './actionTypes';
|
|
|
+import { HigherOrderAction, ActionTypes } from './actionTypes';
|
|
|
+import { reducerFactory } from 'app/core/redux';
|
|
|
+import {
|
|
|
+ addQueryRowAction,
|
|
|
+ changeQueryAction,
|
|
|
+ changeSizeAction,
|
|
|
+ changeTimeAction,
|
|
|
+ clearQueriesAction,
|
|
|
+ highlightLogsExpressionAction,
|
|
|
+ initializeExploreAction,
|
|
|
+ updateDatasourceInstanceAction,
|
|
|
+ loadDatasourceFailureAction,
|
|
|
+ loadDatasourceMissingAction,
|
|
|
+ loadDatasourcePendingAction,
|
|
|
+ loadDatasourceSuccessAction,
|
|
|
+ modifyQueriesAction,
|
|
|
+ queryTransactionFailureAction,
|
|
|
+ queryTransactionStartAction,
|
|
|
+ queryTransactionSuccessAction,
|
|
|
+ removeQueryRowAction,
|
|
|
+ runQueriesEmptyAction,
|
|
|
+ scanRangeAction,
|
|
|
+ scanStartAction,
|
|
|
+ scanStopAction,
|
|
|
+ setQueriesAction,
|
|
|
+ toggleGraphAction,
|
|
|
+ toggleLogsAction,
|
|
|
+ toggleTableAction,
|
|
|
+ queriesImportedAction,
|
|
|
+} from './actionTypes';
|
|
|
|
|
|
export const DEFAULT_RANGE = {
|
|
|
from: 'now-6h',
|
|
|
@@ -30,9 +60,8 @@ export const makeExploreItemState = (): ExploreItemState => ({
|
|
|
datasourceMissing: false,
|
|
|
exploreDatasources: [],
|
|
|
history: [],
|
|
|
- initialQueries: [],
|
|
|
+ queries: [],
|
|
|
initialized: false,
|
|
|
- modifiedQueries: [],
|
|
|
queryTransactions: [],
|
|
|
queryIntervals: { interval: '15s', intervalMs: DEFAULT_GRAPH_INTERVAL },
|
|
|
range: DEFAULT_RANGE,
|
|
|
@@ -44,6 +73,7 @@ export const makeExploreItemState = (): ExploreItemState => ({
|
|
|
supportsGraph: null,
|
|
|
supportsLogs: null,
|
|
|
supportsTable: null,
|
|
|
+ queryKeys: [],
|
|
|
});
|
|
|
|
|
|
/**
|
|
|
@@ -58,21 +88,15 @@ export const initialExploreState: ExploreState = {
|
|
|
/**
|
|
|
* Reducer for an Explore area, to be used by the global Explore reducer.
|
|
|
*/
|
|
|
-export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
- switch (action.type) {
|
|
|
- case ActionTypes.AddQueryRow: {
|
|
|
- const { initialQueries, modifiedQueries, queryTransactions } = state;
|
|
|
+export const itemReducer = reducerFactory<ExploreItemState>({} as ExploreItemState)
|
|
|
+ .addMapper({
|
|
|
+ filter: addQueryRowAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
+ const { queries, queryTransactions } = state;
|
|
|
const { index, query } = action.payload;
|
|
|
|
|
|
- // Add new query row after given index, keep modifications of existing rows
|
|
|
- const nextModifiedQueries = [
|
|
|
- ...modifiedQueries.slice(0, index + 1),
|
|
|
- { ...query },
|
|
|
- ...initialQueries.slice(index + 1),
|
|
|
- ];
|
|
|
-
|
|
|
- // Add to initialQueries, which will cause a new row to be rendered
|
|
|
- const nextQueries = [...initialQueries.slice(0, index + 1), { ...query }, ...initialQueries.slice(index + 1)];
|
|
|
+ // Add to queries, which will cause a new row to be rendered
|
|
|
+ const nextQueries = [...queries.slice(0, index + 1), { ...query }, ...queries.slice(index + 1)];
|
|
|
|
|
|
// Ongoing transactions need to update their row indices
|
|
|
const nextQueryTransactions = queryTransactions.map(qt => {
|
|
|
@@ -87,48 +111,38 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
|
|
|
return {
|
|
|
...state,
|
|
|
- initialQueries: nextQueries,
|
|
|
+ queries: nextQueries,
|
|
|
logsHighlighterExpressions: undefined,
|
|
|
- modifiedQueries: nextModifiedQueries,
|
|
|
queryTransactions: nextQueryTransactions,
|
|
|
+ queryKeys: getQueryKeys(nextQueries, state.datasourceInstance),
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ChangeQuery: {
|
|
|
- const { initialQueries, queryTransactions } = state;
|
|
|
- let { modifiedQueries } = state;
|
|
|
- const { query, index, override } = action.payload;
|
|
|
-
|
|
|
- // Fast path: only change modifiedQueries to not trigger an update
|
|
|
- modifiedQueries[index] = query;
|
|
|
- if (!override) {
|
|
|
- return {
|
|
|
- ...state,
|
|
|
- modifiedQueries,
|
|
|
- };
|
|
|
- }
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: changeQueryAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
+ const { queries, queryTransactions } = state;
|
|
|
+ const { query, index } = action.payload;
|
|
|
|
|
|
// Override path: queries are completely reset
|
|
|
- const nextQuery: DataQuery = {
|
|
|
- ...query,
|
|
|
- ...generateEmptyQuery(index),
|
|
|
- };
|
|
|
- const nextQueries = [...initialQueries];
|
|
|
+ const nextQuery: DataQuery = { ...query, ...generateEmptyQuery(index) };
|
|
|
+ const nextQueries = [...queries];
|
|
|
nextQueries[index] = nextQuery;
|
|
|
- modifiedQueries = [...nextQueries];
|
|
|
|
|
|
// Discard ongoing transaction related to row query
|
|
|
const nextQueryTransactions = queryTransactions.filter(qt => qt.rowIndex !== index);
|
|
|
|
|
|
return {
|
|
|
...state,
|
|
|
- initialQueries: nextQueries,
|
|
|
- modifiedQueries: nextQueries.slice(),
|
|
|
+ queries: nextQueries,
|
|
|
queryTransactions: nextQueryTransactions,
|
|
|
+ queryKeys: getQueryKeys(nextQueries, state.datasourceInstance),
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ChangeSize: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: changeSizeAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { range, datasourceInstance } = state;
|
|
|
let interval = '1s';
|
|
|
if (datasourceInstance && datasourceInstance.interval) {
|
|
|
@@ -137,32 +151,37 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
const containerWidth = action.payload.width;
|
|
|
const queryIntervals = getIntervals(range, interval, containerWidth);
|
|
|
return { ...state, containerWidth, queryIntervals };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ChangeTime: {
|
|
|
- return {
|
|
|
- ...state,
|
|
|
- range: action.payload.range,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ClearQueries: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: changeTimeAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
+ return { ...state, range: action.payload.range };
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: clearQueriesAction,
|
|
|
+ mapper: (state): ExploreItemState => {
|
|
|
const queries = ensureQueries();
|
|
|
return {
|
|
|
...state,
|
|
|
- initialQueries: queries.slice(),
|
|
|
- modifiedQueries: queries.slice(),
|
|
|
+ queries: queries.slice(),
|
|
|
queryTransactions: [],
|
|
|
showingStartPage: Boolean(state.StartPage),
|
|
|
+ queryKeys: getQueryKeys(queries, state.datasourceInstance),
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.HighlightLogsExpression: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: highlightLogsExpressionAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { expressions } = action.payload;
|
|
|
return { ...state, logsHighlighterExpressions: expressions };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.InitializeExplore: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: initializeExploreAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { containerWidth, eventBridge, exploreDatasources, queries, range, ui } = action.payload;
|
|
|
return {
|
|
|
...state,
|
|
|
@@ -170,35 +189,41 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
eventBridge,
|
|
|
exploreDatasources,
|
|
|
range,
|
|
|
- initialQueries: queries,
|
|
|
+ queries,
|
|
|
initialized: true,
|
|
|
- modifiedQueries: queries.slice(),
|
|
|
+ queryKeys: getQueryKeys(queries, state.datasourceInstance),
|
|
|
...ui,
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.UpdateDatasourceInstance: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: updateDatasourceInstanceAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { datasourceInstance } = action.payload;
|
|
|
- return {
|
|
|
- ...state,
|
|
|
- datasourceInstance,
|
|
|
- datasourceName: datasourceInstance.name,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.LoadDatasourceFailure: {
|
|
|
+ return { ...state, datasourceInstance, queryKeys: getQueryKeys(state.queries, datasourceInstance) };
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: loadDatasourceFailureAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
return { ...state, datasourceError: action.payload.error, datasourceLoading: false };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.LoadDatasourceMissing: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: loadDatasourceMissingAction,
|
|
|
+ mapper: (state): ExploreItemState => {
|
|
|
return { ...state, datasourceMissing: true, datasourceLoading: false };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.LoadDatasourcePending: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: loadDatasourcePendingAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
return { ...state, datasourceLoading: true, requestedDatasourceName: action.payload.requestedDatasourceName };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.LoadDatasourceSuccess: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: loadDatasourceSuccessAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { containerWidth, range } = state;
|
|
|
const {
|
|
|
StartPage,
|
|
|
@@ -227,32 +252,29 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
logsHighlighterExpressions: undefined,
|
|
|
queryTransactions: [],
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ModifyQueries: {
|
|
|
- const { initialQueries, modifiedQueries, queryTransactions } = state;
|
|
|
- const { modification, index, modifier } = action.payload as any;
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: modifyQueriesAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
+ const { queries, queryTransactions } = state;
|
|
|
+ const { modification, index, modifier } = action.payload;
|
|
|
let nextQueries: DataQuery[];
|
|
|
let nextQueryTransactions;
|
|
|
if (index === undefined) {
|
|
|
// Modify all queries
|
|
|
- nextQueries = initialQueries.map((query, i) => ({
|
|
|
- ...modifier(modifiedQueries[i], modification),
|
|
|
+ nextQueries = queries.map((query, i) => ({
|
|
|
+ ...modifier({ ...query }, modification),
|
|
|
...generateEmptyQuery(i),
|
|
|
}));
|
|
|
// Discard all ongoing transactions
|
|
|
nextQueryTransactions = [];
|
|
|
} else {
|
|
|
// Modify query only at index
|
|
|
- nextQueries = initialQueries.map((query, i) => {
|
|
|
+ nextQueries = queries.map((query, i) => {
|
|
|
// Synchronize all queries with local query cache to ensure consistency
|
|
|
// TODO still needed?
|
|
|
- return i === index
|
|
|
- ? {
|
|
|
- ...modifier(modifiedQueries[i], modification),
|
|
|
- ...generateEmptyQuery(i),
|
|
|
- }
|
|
|
- : query;
|
|
|
+ return i === index ? { ...modifier({ ...query }, modification), ...generateEmptyQuery(i) } : query;
|
|
|
});
|
|
|
nextQueryTransactions = queryTransactions
|
|
|
// Consume the hint corresponding to the action
|
|
|
@@ -267,22 +289,22 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
}
|
|
|
return {
|
|
|
...state,
|
|
|
- initialQueries: nextQueries,
|
|
|
- modifiedQueries: nextQueries.slice(),
|
|
|
+ queries: nextQueries,
|
|
|
+ queryKeys: getQueryKeys(nextQueries, state.datasourceInstance),
|
|
|
queryTransactions: nextQueryTransactions,
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.QueryTransactionFailure: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: queryTransactionFailureAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { queryTransactions } = action.payload;
|
|
|
- return {
|
|
|
- ...state,
|
|
|
- queryTransactions,
|
|
|
- showingStartPage: false,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.QueryTransactionStart: {
|
|
|
+ return { ...state, queryTransactions, showingStartPage: false };
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: queryTransactionStartAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { queryTransactions } = state;
|
|
|
const { resultType, rowIndex, transaction } = action.payload;
|
|
|
// Discarding existing transactions of same type
|
|
|
@@ -293,14 +315,12 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
// Append new transaction
|
|
|
const nextQueryTransactions: QueryTransaction[] = [...remainingTransactions, transaction];
|
|
|
|
|
|
- return {
|
|
|
- ...state,
|
|
|
- queryTransactions: nextQueryTransactions,
|
|
|
- showingStartPage: false,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.QueryTransactionSuccess: {
|
|
|
+ return { ...state, queryTransactions: nextQueryTransactions, showingStartPage: false };
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: queryTransactionSuccessAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { datasourceInstance, queryIntervals } = state;
|
|
|
const { history, queryTransactions } = action.payload;
|
|
|
const results = calculateResultsFromQueryTransactions(
|
|
|
@@ -309,30 +329,24 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
queryIntervals.intervalMs
|
|
|
);
|
|
|
|
|
|
- return {
|
|
|
- ...state,
|
|
|
- ...results,
|
|
|
- history,
|
|
|
- queryTransactions,
|
|
|
- showingStartPage: false,
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.RemoveQueryRow: {
|
|
|
- const { datasourceInstance, initialQueries, queryIntervals, queryTransactions } = state;
|
|
|
- let { modifiedQueries } = state;
|
|
|
+ return { ...state, ...results, history, queryTransactions, showingStartPage: false };
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: removeQueryRowAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
+ const { datasourceInstance, queries, queryIntervals, queryTransactions, queryKeys } = state;
|
|
|
const { index } = action.payload;
|
|
|
|
|
|
- modifiedQueries = [...modifiedQueries.slice(0, index), ...modifiedQueries.slice(index + 1)];
|
|
|
-
|
|
|
- if (initialQueries.length <= 1) {
|
|
|
+ if (queries.length <= 1) {
|
|
|
return state;
|
|
|
}
|
|
|
|
|
|
- const nextQueries = [...initialQueries.slice(0, index), ...initialQueries.slice(index + 1)];
|
|
|
+ const nextQueries = [...queries.slice(0, index), ...queries.slice(index + 1)];
|
|
|
+ const nextQueryKeys = [...queryKeys.slice(0, index), ...queryKeys.slice(index + 1)];
|
|
|
|
|
|
// Discard transactions related to row query
|
|
|
- const nextQueryTransactions = queryTransactions.filter(qt => qt.rowIndex !== index);
|
|
|
+ const nextQueryTransactions = queryTransactions.filter(qt => nextQueries.some(nq => nq.key === qt.query.key));
|
|
|
const results = calculateResultsFromQueryTransactions(
|
|
|
nextQueryTransactions,
|
|
|
datasourceInstance,
|
|
|
@@ -342,26 +356,34 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
return {
|
|
|
...state,
|
|
|
...results,
|
|
|
- initialQueries: nextQueries,
|
|
|
+ queries: nextQueries,
|
|
|
logsHighlighterExpressions: undefined,
|
|
|
- modifiedQueries: nextQueries.slice(),
|
|
|
queryTransactions: nextQueryTransactions,
|
|
|
+ queryKeys: nextQueryKeys,
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.RunQueriesEmpty: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: runQueriesEmptyAction,
|
|
|
+ mapper: (state): ExploreItemState => {
|
|
|
return { ...state, queryTransactions: [] };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ScanRange: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: scanRangeAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
return { ...state, scanRange: action.payload.range };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ScanStart: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: scanStartAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
return { ...state, scanning: true, scanner: action.payload.scanner };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ScanStop: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: scanStopAction,
|
|
|
+ mapper: (state): ExploreItemState => {
|
|
|
const { queryTransactions } = state;
|
|
|
const nextQueryTransactions = queryTransactions.filter(qt => qt.scanning && !qt.done);
|
|
|
return {
|
|
|
@@ -371,14 +393,22 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
scanRange: undefined,
|
|
|
scanner: undefined,
|
|
|
};
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.SetQueries: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: setQueriesAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
const { queries } = action.payload;
|
|
|
- return { ...state, initialQueries: queries.slice(), modifiedQueries: queries.slice() };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ToggleGraph: {
|
|
|
+ return {
|
|
|
+ ...state,
|
|
|
+ queries: queries.slice(),
|
|
|
+ queryKeys: getQueryKeys(queries, state.datasourceInstance),
|
|
|
+ };
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: toggleGraphAction,
|
|
|
+ mapper: (state): ExploreItemState => {
|
|
|
const showingGraph = !state.showingGraph;
|
|
|
let nextQueryTransactions = state.queryTransactions;
|
|
|
if (!showingGraph) {
|
|
|
@@ -386,9 +416,11 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
nextQueryTransactions = state.queryTransactions.filter(qt => qt.resultType !== 'Graph');
|
|
|
}
|
|
|
return { ...state, queryTransactions: nextQueryTransactions, showingGraph };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ToggleLogs: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: toggleLogsAction,
|
|
|
+ mapper: (state): ExploreItemState => {
|
|
|
const showingLogs = !state.showingLogs;
|
|
|
let nextQueryTransactions = state.queryTransactions;
|
|
|
if (!showingLogs) {
|
|
|
@@ -396,9 +428,11 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
nextQueryTransactions = state.queryTransactions.filter(qt => qt.resultType !== 'Logs');
|
|
|
}
|
|
|
return { ...state, queryTransactions: nextQueryTransactions, showingLogs };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.ToggleTable: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: toggleTableAction,
|
|
|
+ mapper: (state): ExploreItemState => {
|
|
|
const showingTable = !state.showingTable;
|
|
|
if (showingTable) {
|
|
|
return { ...state, showingTable, queryTransactions: state.queryTransactions };
|
|
|
@@ -413,25 +447,26 @@ export const itemReducer = (state, action: Action): ExploreItemState => {
|
|
|
);
|
|
|
|
|
|
return { ...state, ...results, queryTransactions: nextQueryTransactions, showingTable };
|
|
|
- }
|
|
|
-
|
|
|
- case ActionTypes.QueriesImported: {
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .addMapper({
|
|
|
+ filter: queriesImportedAction,
|
|
|
+ mapper: (state, action): ExploreItemState => {
|
|
|
+ const { queries } = action.payload;
|
|
|
return {
|
|
|
...state,
|
|
|
- initialQueries: action.payload.queries,
|
|
|
- modifiedQueries: action.payload.queries.slice(),
|
|
|
+ queries,
|
|
|
+ queryKeys: getQueryKeys(queries, state.datasourceInstance),
|
|
|
};
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return state;
|
|
|
-};
|
|
|
+ },
|
|
|
+ })
|
|
|
+ .create();
|
|
|
|
|
|
/**
|
|
|
* Global Explore reducer that handles multiple Explore areas (left and right).
|
|
|
* Actions that have an `exploreId` get routed to the ExploreItemReducer.
|
|
|
*/
|
|
|
-export const exploreReducer = (state = initialExploreState, action: Action): ExploreState => {
|
|
|
+export const exploreReducer = (state = initialExploreState, action: HigherOrderAction): ExploreState => {
|
|
|
switch (action.type) {
|
|
|
case ActionTypes.SplitClose: {
|
|
|
return { ...state, split: false };
|
|
|
@@ -454,10 +489,7 @@ export const exploreReducer = (state = initialExploreState, action: Action): Exp
|
|
|
const { exploreId } = action.payload as any;
|
|
|
if (exploreId !== undefined) {
|
|
|
const exploreItemState = state[exploreId];
|
|
|
- return {
|
|
|
- ...state,
|
|
|
- [exploreId]: itemReducer(exploreItemState, action),
|
|
|
- };
|
|
|
+ return { ...state, [exploreId]: itemReducer(exploreItemState, action) };
|
|
|
}
|
|
|
}
|
|
|
|