Skip to content

Commit f9fc55a

Browse files
refactor: update reducers types and redefine IRootState
1 parent 03dbd8e commit f9fc55a

File tree

9 files changed

+38
-26
lines changed

9 files changed

+38
-26
lines changed

src/containers/Tenant/Diagnostics/Consumers/Consumers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import block from 'bem-cn-lite';
44

55
import DataTable, {Column} from '@yandex-cloud/react-data-table';
66

7-
import {IRootState} from '../../../../types/store';
7+
import {IRootState} from '../../../../store/reducers';
88
import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants';
99
import {useAutofetcher} from '../../../../utils/hooks';
1010
import {Search} from '../../../../components/Search';

src/containers/Tenant/Diagnostics/Healthcheck/Healthcheck.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import cn from 'bem-cn-lite';
55
import {Loader} from '@gravity-ui/uikit';
66

77
import {SelfCheckResult} from '../../../../types/api/healthcheck';
8-
import {IRootState} from '../../../../types/store';
8+
import {IRootState} from '../../../../store/reducers';
99
import {
1010
getHealthcheckInfo,
1111
selectIssuesTreeById,

src/store/reducers/describe.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import {createSelector, Selector} from 'reselect';
2+
import {Reducer} from 'redux';
23

34
import '../../services/api';
45
import {TEvDescribeSchemeResult} from '../../types/api/schema';
56
import {IConsumer} from '../../types/api/consumers';
67
import {IDescribeRootStateSlice, IDescribeState} from '../../types/store/describe';
8+
import {IResponseError} from '../../types/api/error';
79
import {createRequestActionTypes, createApiRequest, ApiRequestAction} from '../utils';
810

911
const FETCH_DESCRIBE = createRequestActionTypes('describe', 'FETCH_DESCRIBE');
1012

11-
const initialState: IDescribeState = {
13+
const initialState = {
1214
loading: false,
1315
wasLoaded: false,
1416
data: {},
1517
};
1618

17-
const describe = (
18-
state = initialState,
19-
action: ApiRequestAction<typeof FETCH_DESCRIBE, TEvDescribeSchemeResult, unknown>,
20-
) => {
19+
const describe: Reducer<
20+
IDescribeState,
21+
ApiRequestAction<typeof FETCH_DESCRIBE, TEvDescribeSchemeResult, IResponseError>
22+
> = (state = initialState, action) => {
2123
switch (action.type) {
2224
case FETCH_DESCRIBE.REQUEST: {
2325
return {

src/store/reducers/header.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import {Reducer} from 'redux';
2+
13
const SET_HEADER = 'SET_HEADER';
24

5+
type IHeaderAction = ReturnType<typeof setHeader>;
36
export type HeaderItemType = {text: string; link?: string};
47

58
const initialState: HeaderItemType[] = [];
69

7-
const header = function (state = initialState, action: ReturnType<typeof setHeader>) {
10+
const header: Reducer<HeaderItemType[], IHeaderAction> = function (state = initialState, action) {
811
switch (action.type) {
912
case SET_HEADER:
1013
return action.data;

src/store/reducers/healthcheckInfo.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@ import _sortBy from 'lodash/fp/sortBy';
33
import _uniqBy from 'lodash/fp/uniqBy';
44
import _omit from 'lodash/omit';
55
import {createSelector, Selector} from 'reselect';
6+
import {Reducer} from 'redux';
67

78
import {
89
IHealthcheckInfoState,
910
IHealthcheckInfoRootStateSlice,
1011
IIssuesTree,
1112
} from '../../types/store/healthcheck';
1213
import {HealthCheckAPIResponse, IssueLog, StatusFlag} from '../../types/api/healthcheck';
14+
import {IResponseError} from '../../types/api/error';
1315

1416
import '../../services/api';
1517
import {createRequestActionTypes, createApiRequest, ApiRequestAction} from '../utils';
1618

1719
const FETCH_HEALTHCHECK = createRequestActionTypes('cluster', 'FETCH_HEALTHCHECK');
1820

19-
const initialState: IHealthcheckInfoState = {loading: false, wasLoaded: false};
21+
const initialState = {loading: false, wasLoaded: false};
2022

21-
const healthcheckInfo = function (
22-
state = initialState,
23-
action: ApiRequestAction<typeof FETCH_HEALTHCHECK, HealthCheckAPIResponse, unknown>,
24-
) {
23+
const healthcheckInfo: Reducer<
24+
IHealthcheckInfoState,
25+
ApiRequestAction<typeof FETCH_HEALTHCHECK, HealthCheckAPIResponse, IResponseError>
26+
> = function (state = initialState, action) {
2527
switch (action.type) {
2628
case FETCH_HEALTHCHECK.REQUEST: {
2729
return {

src/store/reducers/index.js renamed to src/store/reducers/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@ import authentication from './authentication';
3434
import header from './header';
3535
import saveQuery from './saveQuery';
3636
import fullscreen from './fullscreen';
37-
38-
function singleClusterMode(state = true) {
39-
return state;
40-
}
37+
import singleClusterMode from './singleClusterMode';
4138

4239
export const rootReducer = {
4340
singleClusterMode,
@@ -77,6 +74,11 @@ export const rootReducer = {
7774
fullscreen,
7875
};
7976

80-
export default combineReducers({
77+
const combinedReducer = combineReducers({
8178
...rootReducer,
8279
});
80+
81+
export type IRootReducer = typeof combinedReducer;
82+
export type IRootState = ReturnType<IRootReducer>;
83+
84+
export default combinedReducer;

src/store/reducers/saveQuery.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
import {Reducer} from 'redux';
2+
13
const SET_QUERY_NAME_TO_EDIT = 'SET_QUERY_NAME_TO_EDIT';
24
const CLEAR_QUERY_NAME_TO_EDIT = 'CLEAR_QUERY_NAME_TO_EDIT';
35

6+
type IAction = ReturnType<typeof setQueryNameToEdit> | ReturnType<typeof clearQueryNameToEdit>;
7+
type ISaveQueryState = string | null;
8+
49
const initialState = null;
510

6-
const saveQuery = function (
7-
state = initialState,
8-
action: ReturnType<typeof setQueryNameToEdit> | ReturnType<typeof clearQueryNameToEdit>,
9-
) {
11+
const saveQuery: Reducer<ISaveQueryState, IAction> = function (state = initialState, action) {
1012
switch (action.type) {
1113
case SET_QUERY_NAME_TO_EDIT:
1214
return action.data;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function singleClusterMode(state = true) {
2+
return state;
3+
}
4+
5+
export default singleClusterMode;

src/types/store/index.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)