Skip to content

Commit 6ca1d60

Browse files
committed
refactor: cover api call json/describe with types
1 parent 09792aa commit 6ca1d60

File tree

4 files changed

+148
-20
lines changed

4 files changed

+148
-20
lines changed

src/containers/Tenant/Schema/SchemaTree/SchemaTree.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ import {NavigationTree} from 'ydb-ui-components';
55
import {setCurrentSchemaPath, getSchema} from '../../../../store/reducers/schema';
66
import {getDescribe} from '../../../../store/reducers/describe';
77
import {getSchemaAcl} from '../../../../store/reducers/schemaAcl';
8+
import type {EPathType} from '../../../../types/api/schema';
89

9-
import {calcNavigationTreeType} from '../../utils/schema';
10+
import {mapPathTypeToNavigationTreeType} from '../../utils/schema';
1011
import {getActions} from '../../utils/schemaActions';
1112

1213
interface SchemaTreeProps {
1314
rootPath: string;
1415
rootName: string;
15-
rootType: string;
16+
rootType: EPathType;
1617
currentPath: string;
1718
}
1819

@@ -31,9 +32,9 @@ export function SchemaTree(props: SchemaTreeProps) {
3132
{concurrentId: `NavigationTree.getSchema|${path}`},
3233
)
3334
.then(({PathDescription: {Children = []} = {}}) => {
34-
return Children.map(({Name, PathType}) => ({
35+
return Children.map(({Name = '', PathType}) => ({
3536
name: Name,
36-
type: calcNavigationTreeType(PathType),
37+
type: mapPathTypeToNavigationTreeType(PathType),
3738
}));
3839
});
3940

@@ -49,7 +50,7 @@ export function SchemaTree(props: SchemaTreeProps) {
4950
rootState={{
5051
path: rootPath,
5152
name: rootName,
52-
type: calcNavigationTreeType(rootType),
53+
type: mapPathTypeToNavigationTreeType(rootType),
5354
collapsed: false,
5455
}}
5556
fetchPath={fetchPath}

src/containers/Tenant/utils/schema.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import type {NavigationTreeNodeType} from "ydb-ui-components";
1+
import type {NavigationTreeNodeType} from 'ydb-ui-components';
2+
import {EPathType} from '../../../types/api/schema';
23

3-
const DB_TYPES = new Set(['EPathTypeSubDomain']);
4-
const TABLE_TYPES = new Set(['EPathTypeTable', 'EPathTypeOlapTable']);
5-
const DIR_TYPES = new Set(['EPathTypeDir', 'EPathTypeOlapStore']);
6-
7-
export const calcNavigationTreeType = (type: string): NavigationTreeNodeType => {
8-
if (DIR_TYPES.has(type)) {
9-
return 'directory';
10-
} else if (TABLE_TYPES.has(type)) {
11-
return 'table';
12-
} else if (DB_TYPES.has(type)) {
13-
return 'database';
4+
export const mapPathTypeToNavigationTreeType = (
5+
type: EPathType = EPathType.EPathTypeDir,
6+
defaultType: NavigationTreeNodeType = 'directory'
7+
): NavigationTreeNodeType => {
8+
switch (type) {
9+
case EPathType.EPathTypeSubDomain:
10+
return 'database';
11+
case EPathType.EPathTypeTable:
12+
case EPathType.EPathTypeColumnTable:
13+
return 'table';
14+
case EPathType.EPathTypeDir:
15+
case EPathType.EPathTypeColumnStore:
16+
return 'directory';
17+
default:
18+
return defaultType;
1419
}
15-
16-
return 'directory';
1720
};

src/services/api.d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
interface Window {
2-
api: any;
2+
api: {
3+
getSchema: (
4+
params: {path: string},
5+
axiosOptions?: {concurrentId?: string},
6+
) => Promise<import('../types/api/schema').TEvDescribeSchemeResult>;
7+
[method: string]: Function;
8+
};
39
}

src/types/api/schema.ts

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
export interface TEvDescribeSchemeResult {
2+
Status?: EStatus;
3+
Reason?: string;
4+
Path?: string;
5+
PathDescription?: TPathDescription;
6+
/** fixed64 */
7+
PathOwner?: string;
8+
/** fixed64 */
9+
PathId?: string;
10+
11+
LastExistedPrefixPath?: string;
12+
/** fixed64 */
13+
LastExistedPrefixPathId?: string;
14+
LastExistedPrefixDescription?: TPathDescription;
15+
/** fixed64 */
16+
PathOwnerId?: string;
17+
}
18+
19+
enum EStatus {
20+
StatusSuccess = 'StatusSuccess',
21+
StatusAccepted = 'StatusAccepted',
22+
StatusPathDoesNotExist = 'StatusPathDoesNotExist',
23+
StatusPathIsNotDirectory = 'StatusPathIsNotDirectory',
24+
StatusAlreadyExists = 'StatusAlreadyExists',
25+
StatusSchemeError = 'StatusSchemeError',
26+
StatusNameConflict = 'StatusNameConflict',
27+
StatusInvalidParameter = 'StatusInvalidParameter',
28+
StatusMultipleModifications = 'StatusMultipleModifications',
29+
StatusReadOnly = 'StatusReadOnly',
30+
StatusTxIdNotExists = 'StatusTxIdNotExists',
31+
StatusTxIsNotCancellable = 'StatusTxIsNotCancellable',
32+
StatusAccessDenied = 'StatusAccessDenied',
33+
StatusNotAvailable = 'StatusNotAvailable',
34+
StatusPreconditionFailed = 'StatusPreconditionFailed',
35+
StatusRedirectDomain = 'StatusRedirectDomain',
36+
StatusQuotaExceeded = 'StatusQuotaExceeded',
37+
StatusResourceExhausted = 'StatusResourceExhausted',
38+
}
39+
40+
// incomplete interface, only currently used fields are covered
41+
interface TPathDescription {
42+
/** info about the path itself */
43+
Self?: TDirEntry;
44+
DomainDescription?: unknown;
45+
46+
// for directory
47+
Children?: TDirEntry[];
48+
49+
// for table
50+
Table?: unknown;
51+
TableStats?: unknown;
52+
TabletMetrics?: unknown;
53+
TablePartitions?: unknown[];
54+
55+
ColumnStoreDescription?: unknown;
56+
ColumnTableDescription?: unknown;
57+
}
58+
59+
interface TDirEntry {
60+
Name?: string;
61+
/** uint64 */
62+
PathId?: string;
63+
/** uint64 */
64+
SchemeshardId?: string;
65+
PathType?: EPathType;
66+
CreateFinished?: boolean;
67+
/** uint64 */
68+
CreateTxId?: string;
69+
/** uint64 */
70+
CreateStep?: string;
71+
/** uint64 */
72+
ParentPathId?: string;
73+
PathState?: EPathState;
74+
Owner?: string;
75+
ACL?: string;
76+
EffectiveACL?: string;
77+
/** uint64 */
78+
PathVersion?: string;
79+
PathSubType?: EPathSubType;
80+
Version?: TPathVersion;
81+
}
82+
83+
// incomplete
84+
export enum EPathType {
85+
EPathTypeInvalid = 'EPathTypeInvalid',
86+
EPathTypeDir = 'EPathTypeDir',
87+
EPathTypeTable = 'EPathTypeTable',
88+
EPathTypeSubDomain = 'EPathTypeSubDomain',
89+
EPathTypeColumnStore = 'EPathTypeColumnStore',
90+
EPathTypeColumnTable = 'EPathTypeColumnTable',
91+
}
92+
93+
enum EPathSubType {
94+
EPathSubTypeEmpty = 'EPathSubTypeEmpty',
95+
EPathSubTypeSyncIndexImplTable = 'EPathSubTypeSyncIndexImplTable',
96+
EPathSubTypeAsyncIndexImplTable = 'EPathSubTypeAsyncIndexImplTable',
97+
EPathSubTypeStreamImpl = 'EPathSubTypeStreamImpl',
98+
}
99+
100+
enum EPathState {
101+
EPathStateNotExist = 'EPathStateNotExist',
102+
EPathStateNoChanges = 'EPathStateNoChanges',
103+
EPathStateCreate = 'EPathStateCreate',
104+
EPathStateAlter = 'EPathStateAlter',
105+
EPathStateDrop = 'EPathStateDrop',
106+
EPathStateCopying = 'EPathStateCopying',
107+
EPathStateBackup = 'EPathStateBackup',
108+
EPathStateUpgrade = 'EPathStateUpgrade',
109+
EPathStateMigrated = 'EPathStateMigrated',
110+
EPathStateRestore = 'EPathStateRestore',
111+
EPathStateMoving = 'EPathStateMoving',
112+
}
113+
114+
// incomplete
115+
interface TPathVersion {
116+
/** uint64 */
117+
GeneralVersion?: string;
118+
}

0 commit comments

Comments
 (0)