Skip to content

Commit 95ef486

Browse files
refactor: migrate schemaAcl reducer to ts (#415)
1 parent 08033c2 commit 95ef486

File tree

5 files changed

+38
-12
lines changed

5 files changed

+38
-12
lines changed

src/containers/Tenant/Tenant.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {useTypedSelector} from '../../utils/hooks';
1111
import routes, {CLUSTER_PAGES, createHref} from '../../routes';
1212
import {setHeader} from '../../store/reducers/header';
1313
import {disableAutorefresh, getSchema, resetLoadingState} from '../../store/reducers/schema';
14-
import {getSchemaAcl} from '../../store/reducers/schemaAcl';
14+
import {getSchemaAcl} from '../../store/reducers/schemaAcl/schemaAcl';
1515
import {getTenantInfo, clearTenant} from '../../store/reducers/tenant/tenant';
1616

1717
import SplitPane from '../../components/SplitPane';

src/store/reducers/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import settings from './settings/settings';
2323
import preview from './preview';
2424
import nodesList from './nodesList';
2525
import describe from './describe';
26-
import schemaAcl from './schemaAcl';
26+
import schemaAcl from './schemaAcl/schemaAcl';
2727
import executeTopQueries from './executeTopQueries';
2828
import healthcheckInfo from './healthcheckInfo';
2929
import shardsWorkload from './shardsWorkload';

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
import {createRequestActionTypes, createApiRequest} from '../utils';
2-
import '../../services/api';
3-
import _ from 'lodash';
1+
import type {Reducer} from 'redux';
42

5-
const FETCH_SCHEMA_ACL = createRequestActionTypes('schemaAcl', 'FETCH_SCHEMA_ACL');
3+
import '../../../services/api';
4+
import {createRequestActionTypes, createApiRequest} from '../../utils';
65

7-
const schemaAcl = function z(state = {loading: false, wasLoaded: false, acl: undefined}, action) {
6+
import type {SchemaAclAction, SchemaAclState} from './types';
7+
8+
export const FETCH_SCHEMA_ACL = createRequestActionTypes('schemaAcl', 'FETCH_SCHEMA_ACL');
9+
10+
const initialState = {
11+
loading: false,
12+
wasLoaded: false,
13+
};
14+
15+
const schemaAcl: Reducer<SchemaAclState, SchemaAclAction> = (state = initialState, action) => {
816
switch (action.type) {
917
case FETCH_SCHEMA_ACL.REQUEST: {
1018
return {
@@ -13,13 +21,16 @@ const schemaAcl = function z(state = {loading: false, wasLoaded: false, acl: und
1321
};
1422
}
1523
case FETCH_SCHEMA_ACL.SUCCESS: {
24+
const acl = action.data.Common?.ACL;
25+
const owner = action.data.Common?.Owner;
26+
1627
return {
1728
...state,
18-
error: undefined,
19-
acl: _.get(action.data, 'Common.ACL'),
20-
owner: _.get(action.data, 'Common.Owner'),
29+
acl,
30+
owner,
2131
loading: false,
2232
wasLoaded: true,
33+
error: undefined,
2334
};
2435
}
2536
case FETCH_SCHEMA_ACL.FAILURE: {
@@ -34,7 +45,7 @@ const schemaAcl = function z(state = {loading: false, wasLoaded: false, acl: und
3445
}
3546
};
3647

37-
export function getSchemaAcl({path}) {
48+
export function getSchemaAcl({path}: {path: string}) {
3849
return createApiRequest({
3950
request: window.api.getSchemaAcl({path}),
4051
actions: FETCH_SCHEMA_ACL,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import type {TACE, TMetaInfo} from '../../../types/api/acl';
2+
import type {IResponseError} from '../../../types/api/error';
3+
import type {ApiRequestAction} from '../../utils';
4+
5+
import {FETCH_SCHEMA_ACL} from './schemaAcl';
6+
7+
export interface SchemaAclState {
8+
loading: boolean
9+
wasLoaded: boolean
10+
acl?: TACE[]
11+
owner?: string
12+
error?: IResponseError
13+
}
14+
15+
export type SchemaAclAction = ApiRequestAction<typeof FETCH_SCHEMA_ACL, TMetaInfo, IResponseError>;

src/types/api/acl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface TMetaCommonInfo {
1616
ACL?: TACE[];
1717
}
1818

19-
interface TACE {
19+
export interface TACE {
2020
AccessType: string;
2121
AccessRights?: string[];
2222
Subject: string;

0 commit comments

Comments
 (0)