2023-06-06 09:31:39 -05:00
|
|
|
import { configureStore as reduxConfigureStore, createListenerMiddleware } from '@reduxjs/toolkit';
|
2023-07-05 05:22:48 -05:00
|
|
|
import { setupListeners } from '@reduxjs/toolkit/query';
|
2019-10-04 07:24:47 -05:00
|
|
|
|
2023-08-03 13:17:00 -05:00
|
|
|
import { togglesApi } from 'app/features/admin/AdminFeatureTogglesAPI';
|
2023-04-12 04:44:01 -05:00
|
|
|
import { browseDashboardsAPI } from 'app/features/browse-dashboards/api/browseDashboardsAPI';
|
2022-09-22 07:35:04 -05:00
|
|
|
import { publicDashboardApi } from 'app/features/dashboard/api/publicDashboardApi';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { StoreState } from 'app/types/store';
|
|
|
|
|
|
|
|
import { buildInitialState } from '../core/reducers/navModel';
|
|
|
|
import { addReducer, createRootReducer } from '../core/reducers/root';
|
2022-08-16 09:01:57 -05:00
|
|
|
import { alertingApi } from '../features/alerting/unified/api/alertingApi';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
|
|
|
import { setStore } from './store';
|
|
|
|
|
2019-10-04 07:24:47 -05:00
|
|
|
export function addRootReducer(reducers: any) {
|
2019-10-08 23:37:07 -05:00
|
|
|
// this is ok now because we add reducers before configureStore is called
|
|
|
|
// in the future if we want to add reducers during runtime
|
|
|
|
// we'll have to solve this in a more dynamic way
|
|
|
|
addReducer(reducers);
|
2019-10-04 07:24:47 -05:00
|
|
|
}
|
2018-10-16 08:36:33 -05:00
|
|
|
|
2023-06-06 09:31:39 -05:00
|
|
|
const listenerMiddleware = createListenerMiddleware();
|
|
|
|
|
2021-02-10 08:23:19 -06:00
|
|
|
export function configureStore(initialState?: Partial<StoreState>) {
|
2022-08-16 09:01:57 -05:00
|
|
|
const store = reduxConfigureStore({
|
2020-01-13 01:03:22 -06:00
|
|
|
reducer: createRootReducer(),
|
2021-09-07 03:44:47 -05:00
|
|
|
middleware: (getDefaultMiddleware) =>
|
2022-08-16 09:01:57 -05:00
|
|
|
getDefaultMiddleware({ thunk: true, serializableCheck: false, immutableCheck: false }).concat(
|
2023-06-06 09:31:39 -05:00
|
|
|
listenerMiddleware.middleware,
|
2022-09-22 07:35:04 -05:00
|
|
|
alertingApi.middleware,
|
2023-04-12 04:44:01 -05:00
|
|
|
publicDashboardApi.middleware,
|
2023-08-03 13:17:00 -05:00
|
|
|
browseDashboardsAPI.middleware,
|
|
|
|
togglesApi.middleware
|
2022-08-16 09:01:57 -05:00
|
|
|
),
|
2020-01-13 01:03:22 -06:00
|
|
|
devTools: process.env.NODE_ENV !== 'production',
|
|
|
|
preloadedState: {
|
|
|
|
navIndex: buildInitialState(),
|
2021-02-10 08:23:19 -06:00
|
|
|
...initialState,
|
2020-01-13 01:03:22 -06:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2023-07-05 05:22:48 -05:00
|
|
|
// this enables "refetchOnFocus" and "refetchOnReconnect" for RTK Query
|
|
|
|
setupListeners(store.dispatch);
|
|
|
|
|
2019-06-04 09:20:55 -05:00
|
|
|
setStore(store);
|
|
|
|
return store;
|
2018-07-09 02:17:38 -05:00
|
|
|
}
|
2020-04-10 03:08:42 -05:00
|
|
|
|
2022-09-19 04:49:35 -05:00
|
|
|
export type RootState = ReturnType<ReturnType<typeof configureStore>['getState']>;
|
|
|
|
export type AppDispatch = ReturnType<typeof configureStore>['dispatch'];
|
|
|
|
|
2021-02-10 08:23:19 -06:00
|
|
|
/*
|
2020-04-10 03:08:42 -05:00
|
|
|
function getActionsToIgnoreSerializableCheckOn() {
|
|
|
|
return [
|
|
|
|
'dashboard/setPanelAngularComponent',
|
|
|
|
'dashboard/panelModelAndPluginReady',
|
|
|
|
'dashboard/dashboardInitCompleted',
|
|
|
|
'plugins/panelPluginLoaded',
|
|
|
|
'explore/initializeExplore',
|
|
|
|
'explore/changeRange',
|
|
|
|
'explore/updateDatasourceInstance',
|
|
|
|
'explore/queryStoreSubscription',
|
|
|
|
'explore/queryStreamUpdated',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
function getPathsToIgnoreMutationAndSerializableCheckOn() {
|
2021-02-10 08:23:19 -06:00
|
|
|
return [
|
2020-04-10 03:08:42 -05:00
|
|
|
'plugins.panels',
|
|
|
|
'dashboard.panels',
|
|
|
|
'dashboard.getModel',
|
|
|
|
'payload.plugin',
|
|
|
|
'panelEditorNew.getPanel',
|
|
|
|
'panelEditorNew.getSourcePanel',
|
|
|
|
'panelEditorNew.getData',
|
|
|
|
'explore.left.queryResponse',
|
|
|
|
'explore.right.queryResponse',
|
|
|
|
'explore.left.datasourceInstance',
|
|
|
|
'explore.right.datasourceInstance',
|
|
|
|
'explore.left.range',
|
|
|
|
'explore.left.eventBridge',
|
|
|
|
'explore.right.eventBridge',
|
|
|
|
'explore.right.range',
|
|
|
|
'explore.left.querySubscription',
|
2021-02-10 08:23:19 -06:00
|
|
|
'explore.right.querySubscription',
|
2020-04-10 03:08:42 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
*/
|