From f38c8a2b2b227315cd0b9afb5def0501a2605529 Mon Sep 17 00:00:00 2001 From: Domas Date: Mon, 13 Sep 2021 16:00:41 +0300 Subject: [PATCH] Chore: infer combined reducer state types (#39118) --- public/app/core/reducers/root.ts | 2 +- public/app/features/plugins/state/reducers.ts | 6 ++- .../app/features/variables/state/reducers.ts | 19 +++----- public/app/types/store.ts | 45 +------------------ 4 files changed, 13 insertions(+), 59 deletions(-) diff --git a/public/app/core/reducers/root.ts b/public/app/core/reducers/root.ts index 49def914a36..536d02e8f16 100644 --- a/public/app/core/reducers/root.ts +++ b/public/app/core/reducers/root.ts @@ -46,7 +46,7 @@ export const createRootReducer = () => { ...addedReducers, }); - return (state: any, action: AnyAction): any => { + return (state: any, action: AnyAction) => { if (action.type !== cleanUpAction.type) { return appReducer(state, action); } diff --git a/public/app/features/plugins/state/reducers.ts b/public/app/features/plugins/state/reducers.ts index 00c3ddd870f..7b366ca208b 100644 --- a/public/app/features/plugins/state/reducers.ts +++ b/public/app/features/plugins/state/reducers.ts @@ -1,4 +1,4 @@ -import { createSlice, PayloadAction } from '@reduxjs/toolkit'; +import { AnyAction, createSlice, PayloadAction, Reducer } from '@reduxjs/toolkit'; import { PluginMeta, PanelPlugin, PluginError } from '@grafana/data'; import { PluginsState } from 'app/types'; import { config } from 'app/core/config'; @@ -52,7 +52,9 @@ export const { panelPluginLoaded, } = pluginsSlice.actions; -export const pluginsReducer = config.pluginAdminEnabled ? pluginCatalogReducer : pluginsSlice.reducer; +export const pluginsReducer: Reducer = config.pluginAdminEnabled + ? ((pluginCatalogReducer as unknown) as Reducer) + : pluginsSlice.reducer; export default { plugins: pluginsReducer, diff --git a/public/app/features/variables/state/reducers.ts b/public/app/features/variables/state/reducers.ts index 9d9cf404950..005e0b9f33e 100644 --- a/public/app/features/variables/state/reducers.ts +++ b/public/app/features/variables/state/reducers.ts @@ -1,18 +1,9 @@ import { combineReducers } from '@reduxjs/toolkit'; -import { optionsPickerReducer, OptionsPickerState } from '../pickers/OptionsPicker/reducer'; -import { variableEditorReducer, VariableEditorState } from '../editor/reducer'; +import { optionsPickerReducer } from '../pickers/OptionsPicker/reducer'; +import { variableEditorReducer } from '../editor/reducer'; import { variablesReducer } from './variablesReducer'; -import { VariableModel } from '../types'; -import { transactionReducer, TransactionState } from './transactionReducer'; -import { variableInspectReducer, VariableInspectState } from '../inspect/reducer'; - -export interface TemplatingState { - variables: Record; - optionsPicker: OptionsPickerState; - editor: VariableEditorState; - transaction: TransactionState; - inspect: VariableInspectState; -} +import { transactionReducer } from './transactionReducer'; +import { variableInspectReducer } from '../inspect/reducer'; export const templatingReducers = combineReducers({ editor: variableEditorReducer, @@ -22,6 +13,8 @@ export const templatingReducers = combineReducers({ inspect: variableInspectReducer, }); +export type TemplatingState = ReturnType; + export default { templating: templatingReducers, }; diff --git a/public/app/types/store.ts b/public/app/types/store.ts index 7c5c245cf74..3db5c2f6b11 100644 --- a/public/app/types/store.ts +++ b/public/app/types/store.ts @@ -1,49 +1,8 @@ import { ThunkAction, ThunkDispatch as GenericThunkDispatch } from 'redux-thunk'; import { Action, PayloadAction } from '@reduxjs/toolkit'; -import { NavIndex } from '@grafana/data'; -import { AlertRulesState, NotificationChannelState } from './alerting'; -import { TeamsState, TeamState } from './teams'; -import { FolderState } from './folders'; -import { DashboardState } from './dashboard'; -import { DataSourceSettingsState, DataSourcesState } from './datasources'; -import { ExploreState } from './explore'; -import { UserAdminState, UserListAdminState, UsersState } from './user'; -import { OrganizationState } from './organization'; -import { AppNotificationsState } from './appNotifications'; -import { PluginsState } from './plugins'; -import { LdapState } from './ldap'; -import { PanelEditorState } from '../features/dashboard/components/PanelEditor/state/reducers'; -import { ApiKeysState } from './apiKeys'; -import { TemplatingState } from '../features/variables/state/reducers'; -import { ImportDashboardState } from '../features/manage-dashboards/state/reducers'; -import { UserState } from 'app/features/profile/state/reducers'; -import { UnifiedAlertingState } from 'app/features/alerting/unified/state/reducers'; +import type { createRootReducer } from 'app/core/reducers/root'; -export interface StoreState { - navIndex: NavIndex; - alertRules: AlertRulesState; - teams: TeamsState; - team: TeamState; - folder: FolderState; - dashboard: DashboardState; - panelEditor: PanelEditorState; - dataSources: DataSourcesState; - dataSourceSettings: DataSourceSettingsState; - explore: ExploreState; - users: UsersState; - organization: OrganizationState; - appNotifications: AppNotificationsState; - user: UserState; - plugins: PluginsState; - ldap: LdapState; - apiKeys: ApiKeysState; - userAdmin: UserAdminState; - userListAdmin: UserListAdminState; - templating: TemplatingState; - importDashboard: ImportDashboardState; - notificationChannel: NotificationChannelState; - unifiedAlerting: UnifiedAlertingState; -} +export type StoreState = ReturnType>; /* * Utility type to get strongly types thunks