Skip to content

Commit 8a5e451

Browse files
committed
refactor(Tenant): move entity type determination to utils
1 parent a6b0913 commit 8a5e451

File tree

11 files changed

+47
-55
lines changed

11 files changed

+47
-55
lines changed

src/containers/Tenant/Diagnostics/DetailedOverview/DetailedOverview.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import {useSelector} from 'react-redux';
33
import cn from 'bem-cn-lite';
44

55
import {Button, Modal} from '@yandex-cloud/uikit';
6+
7+
import type {EPathType} from '../../../../types/api/schema';
68
//@ts-ignore
79
import Icon from '../../../../components/Icon/Icon';
810
import Overview from '../Overview/Overview';
@@ -14,7 +16,7 @@ import TenantOverview from '../TenantOverview/TenantOverview';
1416
import './DetailedOverview.scss';
1517

1618
interface DetailedOverviewProps {
17-
type: string;
19+
type?: EPathType;
1820
className?: string;
1921
tenantName: string;
2022
additionalTenantInfo?: any;

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ import Compute from './Compute/Compute';
2929
import Tablets from '../../Tablets/Tablets';
3030

3131
import routes, {createHref} from '../../../routes';
32-
import {OLAP_TABLE_TYPE, TABLE_TYPE} from '../Tenant';
32+
import type {EPathType} from '../../../types/api/schema';
33+
import {isTableType} from '../utils/schema';
3334
import {TenantGeneralTabsIds, TenantTabsGroups} from '../TenantPages';
3435
import {GeneralPagesIds, DATABASE_PAGES, TABLE_PAGES, DIR_PAGES} from './DiagnosticsPages';
3536
//@ts-ignore
@@ -39,7 +40,7 @@ import {setTopLevelTab, setDiagnosticsTab} from '../../../store/reducers/tenant'
3940
import './Diagnostics.scss';
4041

4142
interface DiagnosticsProps {
42-
type: string;
43+
type?: EPathType;
4344
additionalTenantInfo?: any;
4445
additionalNodesInfo?: any;
4546
}
@@ -68,8 +69,7 @@ function Diagnostics(props: DiagnosticsProps) {
6869
const isDatabase = currentSchemaPath === tenantName;
6970

7071
const pages = useMemo(() => {
71-
const {type} = props;
72-
const isTable = type === TABLE_TYPE || type === OLAP_TABLE_TYPE;
72+
const isTable = isTableType(props.type);
7373

7474
let pages = DIR_PAGES;
7575

src/containers/Tenant/Diagnostics/HotKeys/HotKeys.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Icon from '../../../../components/Icon/Icon';
88

99
import {AutoFetcher} from '../../../../utils/autofetcher';
1010
import {getHotKeys, setHotKeysOptions} from '../../../../store/reducers/hotKeys';
11-
import {TABLE_TYPE} from '../../Tenant';
11+
import {EPathType} from '../../../../types/api/schema';
1212
import {prepareQueryError} from '../../../../utils';
1313

1414
import './HotKeys.scss';
@@ -42,7 +42,8 @@ function HotKeys({
4242
type,
4343
}) {
4444
const fetchData = () => {
45-
if (type === TABLE_TYPE) {
45+
// ColumnTables excluded intentionally
46+
if (type === EPathType.EPathTypeTable) {
4647
getHotKeys(currentSchemaPath);
4748
}
4849
};

src/containers/Tenant/Diagnostics/Overview/Overview.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {Loader} from '@yandex-cloud/uikit';
77
//@ts-ignore
88
import SchemaInfoViewer from '../../Schema/SchemaInfoViewer/SchemaInfoViewer';
99

10-
import {OLAP_TABLE_TYPE} from '../../Tenant';
10+
import type {EPathType} from '../../../../types/api/schema';
11+
import {isColumnEntityType, isTableType} from '../../utils/schema';
1112
import {AutoFetcher} from '../../../../utils/autofetcher';
1213
//@ts-ignore
1314
import {getSchema} from '../../../../store/reducers/schema';
@@ -44,7 +45,7 @@ function prepareOlapTableGeneral(tableData: any, olapStats: any[]) {
4445
}
4546

4647
interface OverviewProps {
47-
type: string;
48+
type?: EPathType;
4849
className?: string;
4950
tenantName?: string;
5051
}
@@ -70,7 +71,7 @@ function Overview(props: OverviewProps) {
7071
const schemaPath = currentSchemaPath || tenantName;
7172
dispatch(getSchema({path: schemaPath}));
7273

73-
if (type === OLAP_TABLE_TYPE) {
74+
if (isTableType(type) && isColumnEntityType(type)) {
7475
dispatch(getOlapStats({path: schemaPath}));
7576
}
7677
};
@@ -98,7 +99,7 @@ function Overview(props: OverviewProps) {
9899
currentItem?.PathDescription?.Table || currentItem?.PathDescription?.ColumnTableDescription;
99100

100101
const schemaData = useMemo(() => {
101-
return props.type === OLAP_TABLE_TYPE
102+
return isTableType(props.type) && isColumnEntityType(props.type)
102103
? prepareOlapTableGeneral(tableSchema, olapStats)
103104
: currentItem;
104105
}, [props.type, tableSchema, olapStats, currentItem]);

src/containers/Tenant/Diagnostics/TopQueries/TopQueries.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {changeUserInput} from '../../../../store/reducers/executeQuery';
99
import {sendQuery, setQueryOptions} from '../../../../store/reducers/executeTopQueries';
1010
import TruncatedQuery from '../../../../components/TruncatedQuery/TruncatedQuery';
1111
import {AutoFetcher} from '../../../../utils/autofetcher';
12-
import {OLAP_STORE_TYPE, OLAP_TABLE_TYPE} from '../../Tenant';
12+
import {isColumnEntityType} from '../../utils/schema';
1313

1414
import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants';
1515
import {TenantGeneralTabsIds} from '../../TenantPages';
@@ -149,7 +149,7 @@ class TopQueries extends React.Component {
149149

150150
let message;
151151

152-
if (type === OLAP_STORE_TYPE || type === OLAP_TABLE_TYPE) {
152+
if (isColumnEntityType(type)) {
153153
message = 'No data';
154154
} else if (error && !error.isCancelled) {
155155
message = prepareQueryError(error).slice(0, 300);

src/containers/Tenant/Diagnostics/TopShards/TopShards.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {setCurrentSchemaPath, getSchema} from '../../../../store/reducers/schema
1212
import {AutoFetcher} from '../../../../utils/autofetcher';
1313
import HistoryContext from '../../../../contexts/HistoryContext';
1414
import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants';
15-
import {OLAP_STORE_TYPE, OLAP_TABLE_TYPE} from '../../Tenant';
15+
import {isColumnEntityType} from '../../utils/schema';
1616
import {prepareQueryError} from '../../../../utils';
1717

1818
import './TopShards.scss';
@@ -120,7 +120,7 @@ function TopShards({
120120
};
121121

122122
const renderContent = () => {
123-
if (type === OLAP_STORE_TYPE || type === OLAP_TABLE_TYPE) {
123+
if (isColumnEntityType(type)) {
124124
return 'No data';
125125
}
126126
if (error) {

src/containers/Tenant/ObjectGeneral/ObjectGeneral.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ import {TenantGeneralTabsIds, TenantTabsGroups, TENANT_GENERAL_TABS} from '../Te
1414
import routes, {createHref} from '../../../routes';
1515
import {setSettingValue} from '../../../store/reducers/settings';
1616
import {TENANT_INITIAL_TAB_KEY} from '../../../utils/constants';
17+
import type {EPathType} from '../../../types/api/schema';
1718

1819
import './ObjectGeneral.scss';
1920

2021
const b = cn('object-general');
2122

2223
interface ObjectGeneralProps {
23-
type: string;
24+
type?: EPathType;
2425
additionalTenantInfo?: any;
2526
additionalNodesInfo?: any;
2627
setSettingValue: (name: string, value: string) => void;

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import CopyToClipboard from '../../../components/CopyToClipboard/CopyToClipboard
1616
import InfoViewer from '../../../components/InfoViewer/InfoViewer';
1717
import Icon from '../../../components/Icon/Icon';
1818

19-
import {OLAP_TABLE_TYPE, TABLE_TYPE} from '../Tenant';
19+
import type {EPathType} from '../../../types/api/schema';
20+
import {isColumnEntityType, isTableType} from '../utils/schema';
2021

2122
import {
2223
DEFAULT_IS_TENANT_COMMON_INFO_COLLAPSED,
@@ -69,7 +70,7 @@ function prepareOlapTableSchema(tableSchema: any) {
6970
}
7071

7172
interface ObjectSummaryProps {
72-
type: string;
73+
type?: EPathType;
7374
onCollapseSummary: VoidFunction;
7475
onExpandSummary: VoidFunction;
7576
isCollapsed: boolean;
@@ -104,12 +105,13 @@ function ObjectSummary(props: ObjectSummaryProps) {
104105
const tableSchema =
105106
currentItem?.PathDescription?.Table || currentItem?.PathDescription?.ColumnTableDescription;
106107

107-
const schema =
108-
props.type === OLAP_TABLE_TYPE ? prepareOlapTableSchema(tableSchema) : tableSchema;
108+
const schema = isTableType(props.type) && isColumnEntityType(props.type)
109+
? prepareOlapTableSchema(tableSchema)
110+
: tableSchema;
109111

110112
useEffect(() => {
111113
const {type} = props;
112-
const isTable = type === TABLE_TYPE || type === OLAP_TABLE_TYPE;
114+
const isTable = isTableType(type);
113115

114116
if (type && !isTable && !TENANT_INFO_TABS.find((el) => el.id === infoTab)) {
115117
history.push({
@@ -120,8 +122,7 @@ function ObjectSummary(props: ObjectSummaryProps) {
120122
}, [props.type]);
121123

122124
const renderTabs = () => {
123-
const {type} = props;
124-
const isTable = type === TABLE_TYPE || type === OLAP_TABLE_TYPE;
125+
const isTable = isTableType(props.type);
125126
const tabsItems = isTable ? [...TENANT_INFO_TABS, ...TENANT_SCHEMA_TAB] : TENANT_INFO_TABS;
126127

127128
return (
@@ -228,8 +229,7 @@ function ObjectSummary(props: ObjectSummaryProps) {
228229
};
229230

230231
const renderCommonInfoControls = () => {
231-
const {type} = props;
232-
const isTable = type === TABLE_TYPE || type === OLAP_TABLE_TYPE;
232+
const isTable = isTableType(props.type);
233233
return (
234234
<React.Fragment>
235235
{isTable && (
@@ -257,8 +257,8 @@ function ObjectSummary(props: ObjectSummaryProps) {
257257
message = `${Status}: ${Reason}`;
258258
}
259259

260-
return props.type ? (
261-
<div className={b('entity-type')}>{type}</div>
260+
return type ? (
261+
<div className={b('entity-type')}>{type.replace('EPathType', '')}</div>
262262
) : (
263263
<div className={b('entity-type', {error: true})}>
264264
<HelpPopover content={message} offset={{left: 0}} />

src/containers/Tenant/Preview/Preview.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {sendQuery, setQueryOptions} from '../../../store/reducers/preview';
1313
import {showTooltip, hideTooltip} from '../../../store/reducers/tooltip';
1414
import {prepareQueryError, prepareQueryResponse} from '../../../utils/index';
1515

16-
import {OLAP_TABLE_TYPE, TABLE_TYPE} from '../Tenant';
16+
import {isTableType} from '../utils/schema';
1717
import {AutoFetcher} from '../../../utils/autofetcher';
1818
import EnableFullscreenButton from '../../../components/EnableFullscreenButton/EnableFullscreenButton';
1919
import {DEFAULT_TABLE_SETTINGS} from '../../../utils/constants';
@@ -82,7 +82,7 @@ class Preview extends React.Component {
8282
sendQueryForPreview = () => {
8383
const {sendQuery, database, table, type} = this.props;
8484

85-
if (type !== TABLE_TYPE && type !== OLAP_TABLE_TYPE) {
85+
if (!isTableType(type)) {
8686
return;
8787
}
8888

@@ -150,7 +150,7 @@ class Preview extends React.Component {
150150

151151
let message;
152152

153-
if (type !== TABLE_TYPE && type !== OLAP_TABLE_TYPE) {
153+
if (!isTableType(type)) {
154154
message = <div className={b('message-container')}>Not available</div>;
155155
}
156156

src/containers/Tenant/Tenant.tsx

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useEffect, useMemo, useReducer} from 'react';
1+
import {useEffect, useReducer} from 'react';
22
import {useDispatch, useSelector} from 'react-redux';
33
import cn from 'bem-cn-lite';
44
import {useLocation} from 'react-router';
@@ -22,28 +22,12 @@ import {
2222
//@ts-ignore
2323
import {getTenantInfo, clearTenant} from '../../store/reducers/tenant';
2424
import routes, {CLUSTER_PAGES, createHref} from '../../routes';
25+
import type {TEvDescribeSchemeResult} from '../../types/api/schema';
2526

2627
import './Tenant.scss';
2728

2829
const b = cn('tenant-page');
2930

30-
export const TABLE_TYPE = 'Table';
31-
export const OLAP_TABLE_TYPE = 'ColumnTable';
32-
export const OLAP_STORE_TYPE = 'ColumnStore';
33-
34-
export function calcEntityType(currentPathType?: string) {
35-
return currentPathType && currentPathType.replace('EPathType', '');
36-
}
37-
38-
export function isTableType(currentPathType?: string) {
39-
const type = calcEntityType(currentPathType);
40-
41-
if (type === TABLE_TYPE || type === OLAP_TABLE_TYPE) {
42-
return true;
43-
}
44-
return false;
45-
}
46-
4731
const getInitialIsSummaryCollapsed = () => {
4832
return Boolean(localStorage.getItem(DEFAULT_IS_TENANT_SUMMARY_COLLAPSED));
4933
};
@@ -114,11 +98,7 @@ function Tenant(props: TenantProps) {
11498
};
11599
}, [tenantName, dispatch]);
116100

117-
const currentPathType = currentItem.PathDescription?.Self?.PathType;
118-
119-
const entityType = useMemo(() => {
120-
return calcEntityType(currentPathType);
121-
}, [currentPathType]);
101+
const currentPathType = (currentItem as TEvDescribeSchemeResult).PathDescription?.Self?.PathType;
122102

123103
const onCollapseSummaryHandler = () => {
124104
dispatchSummaryVisibilityAction(PaneVisibilityActionTypes.triggerCollapse);
@@ -142,14 +122,14 @@ function Tenant(props: TenantProps) {
142122
onSplitStartDragAdditional={onSplitStartDragAdditional}
143123
>
144124
<ObjectSummary
145-
type={entityType as string}
125+
type={currentPathType}
146126
onCollapseSummary={onCollapseSummaryHandler}
147127
onExpandSummary={onExpandSummaryHandler}
148128
isCollapsed={summaryVisibilityState.collapsed}
149129
additionalTenantInfo={props.additionalTenantInfo}
150130
/>
151131
<ObjectGeneral
152-
type={entityType as string}
132+
type={currentPathType}
153133
additionalTenantInfo={props.additionalTenantInfo}
154134
additionalNodesInfo={props.additionalNodesInfo}
155135
/>

0 commit comments

Comments
 (0)