Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 1 addition & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@
"source-map-explorer": "^2.5.3",
"stylelint": "^16.20.0",
"ts-jest": "^29.2.5",
"typescript": "^5.8.3",
"workerize-loader": "^2.0.2"
"typescript": "^5.8.3"
},
"peerDependencies": {
"monaco-yql-languages": ">=1.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const StageBlockComponent = ({className, block}: Props) => {
? block.operators.map((item) => <div key={item}>{item}</div>)
: block.name}
{block.tables ? (
<div style={{overflow: 'hidden', textOverflow: 'ellipsis'}}>
<div>
<Text color="secondary">{i18n('label_tables')}: </Text>
{block.tables.join(', ')}
</div>
Expand Down
34 changes: 18 additions & 16 deletions src/components/Graph/GravityGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import React from 'react';
import {GraphState} from '@gravity-ui/graph';
import type {HookGraphParams} from '@gravity-ui/graph/react';
import {GraphBlock, GraphCanvas, useGraph, useGraphEvent} from '@gravity-ui/graph/react';
// @ts-ignore - workerize-loader syntax
import createWorker from 'workerize-loader!./treeLayout.worker';

import {cn} from '../../utils/cn';

Expand Down Expand Up @@ -68,21 +66,25 @@ export function GravityGraph<T>({data, theme}: Props<T>) {
const {graph, start} = useGraph(config);

React.useEffect(() => {
// Using workerize-loader to inline the worker and avoid CORS issues
const worker = createWorker();

// Call the exported function from the worker
worker
.calculateLayout(data.nodes, data.links)
.then((result: {layout: any; edges: any}) => {
graph.setEntities({
blocks: result.layout,
connections: result.edges,
});
})
.catch((err: Error) => {
console.error('Worker error:', err);
// Just in case, although mounting takes more time than calculation
const worker = new Worker(new URL('./treeLayout', import.meta.url));
worker.postMessage({
nodes: data.nodes,
links: data.links,
});

worker.onmessage = function (e) {
const {layout, edges} = e.data;

graph.setEntities({
blocks: layout,
connections: edges,
});
};

worker.onerror = (err) => {
console.error(err);
};

return () => {
worker.terminate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,15 @@ function calculateTreeEdges(layoutResult: ExtendedTBlock[], connections: TConnec
return connectionPaths;
}

// Export function for workerize-loader
export function calculateLayout(nodes: any[], links: any[]) {
onmessage = function (e) {
const {nodes, links} = e.data;
const blocks = prepareBlocks(nodes);
const connections = prepareConnections(links);
const layout = calculateTreeLayout(blocks, connections);
const edges = calculateTreeEdges(layout, connections);

return {
postMessage({
layout,
edges,
};
}
});
};
Loading