-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathDiagnostics.tsx
More file actions
211 lines (195 loc) · 7.88 KB
/
Diagnostics.tsx
File metadata and controls
211 lines (195 loc) · 7.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import React from 'react';
import {Tabs} from '@gravity-ui/uikit';
import {Helmet} from 'react-helmet-async';
import {Link} from 'react-router-dom';
import {AutoRefreshControl} from '../../../components/AutoRefreshControl/AutoRefreshControl';
import {DrawerContextProvider} from '../../../components/Drawer/DrawerContext';
import {
useFeatureFlagsAvailable,
useTopicDataAvailable,
} from '../../../store/reducers/capabilities/hooks';
import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../store/reducers/tenant/constants';
import {setDiagnosticsTab} from '../../../store/reducers/tenant/tenant';
import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../../types/additionalProps';
import {cn} from '../../../utils/cn';
import {useTypedDispatch, useTypedSelector} from '../../../utils/hooks';
import {Heatmap} from '../../Heatmap';
import {Nodes} from '../../Nodes/Nodes';
import {Operations} from '../../Operations';
import {PaginatedStorage} from '../../Storage/PaginatedStorage';
import {Tablets} from '../../Tablets/Tablets';
import {SchemaViewer} from '../Schema/SchemaViewer/SchemaViewer';
import {useCurrentSchema} from '../TenantContext';
import {isDatabaseEntityType} from '../utils/schema';
import {AccessRights} from './AccessRights/AccessRights';
import {Configs} from './Configs/Configs';
import {Consumers} from './Consumers';
import Describe from './Describe/Describe';
import DetailedOverview from './DetailedOverview/DetailedOverview';
import {getPagesByType, useDiagnosticsPageLinkGetter} from './DiagnosticsPages';
import {HotKeys} from './HotKeys/HotKeys';
import {NetworkWrapper} from './Network/NetworkWrapper';
import {Partitions} from './Partitions/Partitions';
import {TopQueries} from './TopQueries';
import {TopShards} from './TopShards';
import {TopicData} from './TopicData/TopicData';
import './Diagnostics.scss';
interface DiagnosticsProps {
additionalTenantProps?: AdditionalTenantsProps;
additionalNodesProps?: AdditionalNodesProps;
}
const b = cn('kv-tenant-diagnostics');
function Diagnostics(props: DiagnosticsProps) {
const {path, database, type, subType} = useCurrentSchema();
const containerRef = React.useRef<HTMLDivElement>(null);
const dispatch = useTypedDispatch();
const {diagnosticsTab = TENANT_DIAGNOSTICS_TABS_IDS.overview} = useTypedSelector(
(state) => state.tenant,
);
const getDiagnosticsPageLink = useDiagnosticsPageLinkGetter();
const tenantName = isDatabaseEntityType(type) ? path : database;
const hasFeatureFlags = useFeatureFlagsAvailable();
const hasTopicData = useTopicDataAvailable();
const pages = getPagesByType(type, subType, {
hasFeatureFlags,
hasTopicData,
isTopLevel: path === database,
});
let activeTab = pages.find((el) => el.id === diagnosticsTab);
if (!activeTab) {
activeTab = pages[0];
}
React.useEffect(() => {
if (activeTab && activeTab.id !== diagnosticsTab) {
dispatch(setDiagnosticsTab(activeTab.id));
}
}, [activeTab, diagnosticsTab, dispatch]);
const renderTabContent = () => {
switch (activeTab?.id) {
case TENANT_DIAGNOSTICS_TABS_IDS.overview: {
return (
<DetailedOverview
type={type}
tenantName={tenantName}
path={path}
additionalTenantProps={props.additionalTenantProps}
additionalNodesProps={props.additionalNodesProps}
/>
);
}
case TENANT_DIAGNOSTICS_TABS_IDS.schema: {
return <SchemaViewer path={path} tenantName={tenantName} type={type} extended />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.topQueries: {
return <TopQueries tenantName={tenantName} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.topShards: {
return <TopShards tenantName={tenantName} path={path} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.nodes: {
return (
<Nodes
path={path}
database={tenantName}
additionalNodesProps={props.additionalNodesProps}
scrollContainerRef={containerRef}
/>
);
}
case TENANT_DIAGNOSTICS_TABS_IDS.access: {
return <AccessRights />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.tablets: {
return (
<Tablets scrollContainerRef={containerRef} path={path} database={tenantName} />
);
}
case TENANT_DIAGNOSTICS_TABS_IDS.storage: {
return <PaginatedStorage database={tenantName} scrollContainerRef={containerRef} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.network: {
return (
<NetworkWrapper
path={path}
database={tenantName}
additionalNodesProps={props.additionalNodesProps}
scrollContainerRef={containerRef}
/>
);
}
case TENANT_DIAGNOSTICS_TABS_IDS.describe: {
return <Describe path={path} database={tenantName} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.hotKeys: {
return <HotKeys path={path} database={tenantName} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.graph: {
return <Heatmap path={path} database={tenantName} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.consumers: {
return <Consumers path={path} database={tenantName} type={type} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.partitions: {
return <Partitions path={path} database={tenantName} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.topicData: {
return (
<TopicData
key={path}
path={path}
database={tenantName}
scrollContainerRef={containerRef}
/>
);
}
case TENANT_DIAGNOSTICS_TABS_IDS.configs: {
return <Configs database={tenantName} />;
}
case TENANT_DIAGNOSTICS_TABS_IDS.operations: {
return <Operations database={tenantName} />;
}
default: {
return <div>No data...</div>;
}
}
};
const renderTabs = () => {
return (
<div className={b('header-wrapper')}>
<div className={b('tabs')}>
<Tabs
size="l"
items={pages}
activeTab={activeTab?.id}
wrapTo={({id}, node) => {
const path = getDiagnosticsPageLink(id);
return (
<Link to={path} key={id} className={b('tab')}>
{node}
</Link>
);
}}
allowNotSelected={true}
/>
<AutoRefreshControl />
</div>
</div>
);
};
return (
<div className={b()}>
{activeTab ? (
<Helmet>
<title>{activeTab.title}</title>
</Helmet>
) : null}
{renderTabs()}
<DrawerContextProvider>
<div className={b('page-wrapper')} ref={containerRef}>
{renderTabContent()}
</div>
</DrawerContextProvider>
</div>
);
}
export default Diagnostics;