Skip to content

Commit 0809a3b

Browse files
authored
refactor(plexus): migrate Node to functional component (#3392) (#3531)
## Which problem is this PR solving? - Resolves #3392 ## Description of the changes - Migrated the `Node` component from a class-based component to a functional component with `React.memo()` - Converted `Node` class component extending `React.PureComponent` to a functional component - Wrapped the component with `React.memo()` to preserve the shallow prop comparison behavior of `PureComponent` - Destructured props directly in the function signature - Removed the `render()` method and converted to direct return statement - Maintained generic type support using double type assertion pattern: `as unknown as <T = {}>(props: TProps<T>) => React.ReactElement | null` - Preserved all existing functionality including conditional rendering logic - No changes to component logic or behavior, only structural refactoring ## How was this change tested? - All existing plexus tests pass (18 tests) - TypeScript compilation successful - Prettier formatting verified - Build successful for plexus package - Minimal diff: 18 insertions, 18 deletions ## Proof - <img width="367" height="123" alt="3392 proof" src="https://github.com/user-attachments/assets/85bdb61c-d456-4d66-a121-090e7ee4c11c" /> ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/main/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [x] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully: `make lint test` ## AI Usage in this PR (choose one) See [AI Usage Policy](https://github.com/jaegertracing/jaeger/blob/main/CONTRIBUTING_GUIDELINES.md#ai-usage-policy). - [ ] **None**: No AI tools were used in creating this PR - [ ] **Light**: AI provided minor assistance (formatting, simple suggestions) - [x] **Moderate**: AI helped with code generation or debugging specific parts - [ ] **Heavy**: AI generated most or all of the code changes Signed-off-by: hharshhsaini <sainiharsh3311@gmail.com>
1 parent be1bcad commit 0809a3b

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

packages/plexus/src/Digraph/Node.tsx

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ function getHtmlStyle(lv: TLayoutVertex<any>) {
2626
};
2727
}
2828

29-
export default class Node<T = {}> extends React.PureComponent<TProps<T>> {
30-
render() {
31-
const { getClassName, layerType, renderNode, renderUtils, setOnNode, layoutVertex } = this.props;
32-
const nodeContent = renderNode(layoutVertex, renderUtils);
33-
if (!nodeContent) {
34-
return null;
35-
}
36-
const { left, top } = layoutVertex;
37-
const props = assignMergeCss(
38-
{
39-
className: getClassName('Node'),
40-
style: layerType === ELayerType.Html ? getHtmlStyle(layoutVertex) : null,
41-
transform: layerType === ELayerType.Svg ? `translate(${left.toFixed()},${top.toFixed()})` : null,
42-
},
43-
getProps(setOnNode, layoutVertex, renderUtils)
44-
);
45-
const Wrapper = layerType === ELayerType.Html ? 'div' : 'g';
46-
return <Wrapper {...props}>{nodeContent}</Wrapper>;
29+
function Node<T = {}>(props: TProps<T>) {
30+
const { getClassName, layerType, renderNode, renderUtils, setOnNode, layoutVertex } = props;
31+
const nodeContent = renderNode(layoutVertex, renderUtils);
32+
if (!nodeContent) {
33+
return null;
4734
}
35+
const { left, top } = layoutVertex;
36+
const nodeProps = assignMergeCss(
37+
{
38+
className: getClassName('Node'),
39+
style: layerType === ELayerType.Html ? getHtmlStyle(layoutVertex) : null,
40+
transform: layerType === ELayerType.Svg ? `translate(${left.toFixed()},${top.toFixed()})` : null,
41+
},
42+
getProps(setOnNode, layoutVertex, renderUtils)
43+
);
44+
const Wrapper = layerType === ELayerType.Html ? 'div' : 'g';
45+
return <Wrapper {...nodeProps}>{nodeContent}</Wrapper>;
4846
}
47+
48+
export default React.memo(Node) as typeof Node;

0 commit comments

Comments
 (0)