From e6e36eee67578e841fc9890b127d1bd24dcdcb0f Mon Sep 17 00:00:00 2001 From: mufazalov Date: Fri, 2 Jun 2023 20:21:10 +0300 Subject: [PATCH] refactor: migrate schemaAcl reducer to ts --- src/containers/Tenant/Tenant.tsx | 2 +- src/store/reducers/index.ts | 2 +- .../{schemaAcl.js => schemaAcl/schemaAcl.ts} | 29 +++++++++++++------ src/store/reducers/schemaAcl/types.ts | 15 ++++++++++ src/types/api/acl.ts | 2 +- 5 files changed, 38 insertions(+), 12 deletions(-) rename src/store/reducers/{schemaAcl.js => schemaAcl/schemaAcl.ts} (53%) create mode 100644 src/store/reducers/schemaAcl/types.ts diff --git a/src/containers/Tenant/Tenant.tsx b/src/containers/Tenant/Tenant.tsx index 0cb7641f62..e59a242e61 100644 --- a/src/containers/Tenant/Tenant.tsx +++ b/src/containers/Tenant/Tenant.tsx @@ -11,7 +11,7 @@ import {useTypedSelector} from '../../utils/hooks'; import routes, {CLUSTER_PAGES, createHref} from '../../routes'; import {setHeader} from '../../store/reducers/header'; import {disableAutorefresh, getSchema, resetLoadingState} from '../../store/reducers/schema'; -import {getSchemaAcl} from '../../store/reducers/schemaAcl'; +import {getSchemaAcl} from '../../store/reducers/schemaAcl/schemaAcl'; import {getTenantInfo, clearTenant} from '../../store/reducers/tenant/tenant'; import SplitPane from '../../components/SplitPane'; diff --git a/src/store/reducers/index.ts b/src/store/reducers/index.ts index c544630916..b97048a3bc 100644 --- a/src/store/reducers/index.ts +++ b/src/store/reducers/index.ts @@ -23,7 +23,7 @@ import settings from './settings/settings'; import preview from './preview'; import nodesList from './nodesList'; import describe from './describe'; -import schemaAcl from './schemaAcl'; +import schemaAcl from './schemaAcl/schemaAcl'; import executeTopQueries from './executeTopQueries'; import healthcheckInfo from './healthcheckInfo'; import shardsWorkload from './shardsWorkload'; diff --git a/src/store/reducers/schemaAcl.js b/src/store/reducers/schemaAcl/schemaAcl.ts similarity index 53% rename from src/store/reducers/schemaAcl.js rename to src/store/reducers/schemaAcl/schemaAcl.ts index a86370739d..62ba7fa644 100644 --- a/src/store/reducers/schemaAcl.js +++ b/src/store/reducers/schemaAcl/schemaAcl.ts @@ -1,10 +1,18 @@ -import {createRequestActionTypes, createApiRequest} from '../utils'; -import '../../services/api'; -import _ from 'lodash'; +import type {Reducer} from 'redux'; -const FETCH_SCHEMA_ACL = createRequestActionTypes('schemaAcl', 'FETCH_SCHEMA_ACL'); +import '../../../services/api'; +import {createRequestActionTypes, createApiRequest} from '../../utils'; -const schemaAcl = function z(state = {loading: false, wasLoaded: false, acl: undefined}, action) { +import type {SchemaAclAction, SchemaAclState} from './types'; + +export const FETCH_SCHEMA_ACL = createRequestActionTypes('schemaAcl', 'FETCH_SCHEMA_ACL'); + +const initialState = { + loading: false, + wasLoaded: false, +}; + +const schemaAcl: Reducer = (state = initialState, action) => { switch (action.type) { case FETCH_SCHEMA_ACL.REQUEST: { return { @@ -13,13 +21,16 @@ const schemaAcl = function z(state = {loading: false, wasLoaded: false, acl: und }; } case FETCH_SCHEMA_ACL.SUCCESS: { + const acl = action.data.Common?.ACL; + const owner = action.data.Common?.Owner; + return { ...state, - error: undefined, - acl: _.get(action.data, 'Common.ACL'), - owner: _.get(action.data, 'Common.Owner'), + acl, + owner, loading: false, wasLoaded: true, + error: undefined, }; } case FETCH_SCHEMA_ACL.FAILURE: { @@ -34,7 +45,7 @@ const schemaAcl = function z(state = {loading: false, wasLoaded: false, acl: und } }; -export function getSchemaAcl({path}) { +export function getSchemaAcl({path}: {path: string}) { return createApiRequest({ request: window.api.getSchemaAcl({path}), actions: FETCH_SCHEMA_ACL, diff --git a/src/store/reducers/schemaAcl/types.ts b/src/store/reducers/schemaAcl/types.ts new file mode 100644 index 0000000000..87955829bb --- /dev/null +++ b/src/store/reducers/schemaAcl/types.ts @@ -0,0 +1,15 @@ +import type {TACE, TMetaInfo} from '../../../types/api/acl'; +import type {IResponseError} from '../../../types/api/error'; +import type {ApiRequestAction} from '../../utils'; + +import {FETCH_SCHEMA_ACL} from './schemaAcl'; + +export interface SchemaAclState { + loading: boolean + wasLoaded: boolean + acl?: TACE[] + owner?: string + error?: IResponseError +} + +export type SchemaAclAction = ApiRequestAction; diff --git a/src/types/api/acl.ts b/src/types/api/acl.ts index 52e527f8c0..ae0bae32ec 100644 --- a/src/types/api/acl.ts +++ b/src/types/api/acl.ts @@ -16,7 +16,7 @@ export interface TMetaCommonInfo { ACL?: TACE[]; } -interface TACE { +export interface TACE { AccessType: string; AccessRights?: string[]; Subject: string;