Skip to content

Commit d39d268

Browse files
committed
fix types
1 parent f79c022 commit d39d268

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/components/Graph/treeLayout.ts

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ class TreeLayoutEngine {
7575
}
7676

7777
// Группировка узлов по уровням
78-
groupByLevels(node = this.tree, levels = []) {
78+
groupByLevels(node: TreeNode | null = this.tree, levels: TreeNode[][] = []): TreeNode[][] {
79+
if (!node) {
80+
return levels;
81+
}
82+
7983
if (!levels[node.level]) {
8084
levels[node.level] = [];
8185
}
@@ -117,6 +121,10 @@ class TreeLayoutEngine {
117121

118122
// Размещение узлов по позициям
119123
positionNodes() {
124+
if (!this.tree) {
125+
return;
126+
}
127+
120128
// Вычисляем Y координаты для каждого уровня
121129
let currentY = 0;
122130
const levelY: number[] = [];
@@ -175,9 +183,13 @@ class TreeLayoutEngine {
175183

176184
// Нормализация координат (чтобы минимальные координаты были >= 0)
177185
normalizeCoordinates() {
178-
const allNodes = [];
186+
if (!this.tree) {
187+
return;
188+
}
179189

180-
const collectNodes = (node) => {
190+
const allNodes: TreeNode[] = [];
191+
192+
const collectNodes = (node: TreeNode) => {
181193
allNodes.push(node);
182194
for (const child of node.children) {
183195
collectNodes(child);
@@ -211,10 +223,14 @@ class TreeLayoutEngine {
211223
}
212224

213225
// Получение результата компоновки
214-
getLayoutResult() {
226+
getLayoutResult(): ExtendedTBlock[] {
227+
if (!this.tree) {
228+
return [];
229+
}
230+
215231
const result: ExtendedTBlock[] = [];
216232

217-
const collectResults = (node) => {
233+
const collectResults = (node: TreeNode) => {
218234
result.push({
219235
id: node.id,
220236
x: node.x,
@@ -257,7 +273,12 @@ function calculateTreeEdges(layoutResult: ExtendedTBlock[], connections: TConnec
257273
connectionsByParent.get(parentId).push(connection);
258274
}
259275

260-
const connectionPaths = [];
276+
const connectionPaths: {
277+
connectionId: string | undefined;
278+
sourceBlockId: string | number;
279+
targetBlockId: string | number;
280+
points: {x: number; y: number}[];
281+
}[] = [];
261282

262283
// Для каждого родительского блока рассчитываем пути к детям
263284
for (const [parentId, parentConnections] of connectionsByParent) {
@@ -294,15 +315,18 @@ function calculateTreeEdges(layoutResult: ExtendedTBlock[], connections: TConnec
294315

295316
// Находим вертикальное расстояние между родителем и ближайшим ребенком
296317
const children = parentConnections
297-
.map((conn) => positionMap.get(conn.targetBlockId))
298-
.filter((child) => child !== undefined);
318+
.map((conn: TConnection) => positionMap.get(conn.targetBlockId))
319+
.filter(
320+
(child: ExtendedTBlock | undefined): child is ExtendedTBlock =>
321+
child !== undefined,
322+
);
299323

300324
if (children.length === 0) {
301325
continue;
302326
}
303327

304328
// Находим минимальное расстояние до детей по Y
305-
const minChildY = Math.min(...children.map((child) => child.y));
329+
const minChildY = Math.min(...children.map((child: ExtendedTBlock) => child.y));
306330

307331
// Точка разветвления - посередине между родителем и детьми
308332
const branchY = startY + (minChildY - startY) / 2;

src/components/Graph/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export interface Link {
2121
to: string;
2222
}
2323
export interface Data<TData = any> {
24-
links?: Link[];
24+
links: Link[];
2525
nodes: GraphNode<TData>[];
2626
}
2727
export interface Metric {

src/containers/Tenant/Query/QueryResult/QueryResultViewer.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ export function QueryResultViewer({
272272
if (!preparedPlan?.nodes?.length) {
273273
return renderStubMessage();
274274
}
275-
276275
return <Graph theme={theme} explain={preparedPlan} />;
277276
}
278277
if (activeSection === RESULT_OPTIONS_IDS.json) {

0 commit comments

Comments
 (0)