Skip to content
This repository was archived by the owner on Oct 29, 2022. It is now read-only.

Commit 173adb9

Browse files
committed
fix: add unique keys
1 parent ac5e3ea commit 173adb9

File tree

6 files changed

+30
-28
lines changed

6 files changed

+30
-28
lines changed

examples/simple-react/src/Asyncapi.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,9 @@ components:
188188
}, []);
189189
let something;
190190
if (data !== undefined) {
191-
something = (
192-
<ApplicationView>
193-
<AsyncAPIApplication document={data} />
194-
</ApplicationView>
195-
);
191+
something = <ApplicationView>
192+
<AsyncAPIApplication document={data} />
193+
</ApplicationView>;
196194
} else {
197195
something = <h1>Not loaded</h1>;
198196
}

examples/simple-react/src/social_media/application.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ function Asyncapi() {
4141
if (externalApplications.length > 0 && focusedApplication !== undefined) {
4242
something = (
4343
<ApplicationFocusView sideMenu={Menu}>
44-
<AsyncAPIApplication document={focusedApplication.parsedDoc} />
44+
<AsyncAPIApplication key={focusedApplication.parsedDoc.info().title()} document={focusedApplication.parsedDoc} />
4545
{externalApplications.map(({ parsedDoc, name }) => {
4646
return (
4747
<AsyncAPIApplication
48+
key={parsedDoc.info().title()}
4849
document={parsedDoc}
4950
topExtended={
5051
<div className="flex justify-between mb-4">
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React from 'react';
22
import { ApplicationNodeData, InternalProps } from '../../types';
33

44
type ApplicationProps = ApplicationNodeData & InternalProps;
@@ -9,28 +9,24 @@ type ApplicationProps = ApplicationNodeData & InternalProps;
99
* What you define as an instance can be application, grouped or single server less function, etc.
1010
*/
1111
export const Application: React.FunctionComponent<ApplicationProps> = props => {
12-
const [temp, setTemp] = useState<any>(undefined);
1312
const nodeData = {
1413
...props,
1514
};
1615
delete nodeData.children;
1716
delete nodeData.internal;
1817
const applicationNodeData: ApplicationNodeData = nodeData;
1918

20-
useEffect(() => {
21-
props.internal?.addApplicationCallback(applicationNodeData);
19+
props.internal?.addApplicationCallback(applicationNodeData);
2220

23-
const childrenWithProps = React.Children.map(props.children, child => {
24-
if (React.isValidElement(child)) {
25-
return React.cloneElement(child, {
26-
forApplication: applicationNodeData.id,
27-
internal: props.internal,
28-
});
29-
}
30-
return child;
31-
});
32-
setTemp(childrenWithProps);
33-
}, []);
21+
const childrenWithProps = React.Children.map(props.children, child => {
22+
if (React.isValidElement(child)) {
23+
return React.cloneElement(child, {
24+
forApplication: applicationNodeData.id,
25+
internal: props.internal,
26+
});
27+
}
28+
return child;
29+
});
3430

35-
return <div key={applicationNodeData.id}>{temp}</div>;
31+
return <>{childrenWithProps}</>;
3632
};

library/src/components/nodes/AsyncAPIApplication.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export const AsyncAPIApplication: React.FunctionComponent<ApplicationProps> = pr
2323
props.document.channels(),
2424
)) {
2525
if (channel.hasPublish()) {
26-
const channelId = props.document.info().title() + channelPath;
26+
const channelId = `incoming_${props.document
27+
.info()
28+
.title()}_${channelPath}`;
2729
const messages: MessageData[] = channel
2830
.publish()
2931
.messages()
@@ -32,14 +34,17 @@ export const AsyncAPIApplication: React.FunctionComponent<ApplicationProps> = pr
3234
});
3335
incomingNodes.push(
3436
<Incoming
37+
key={channelId}
3538
channel={channelPath}
3639
description={channel.description() || 'No description'}
3740
id={channelId}
3841
messages={messages}
3942
/>,
4043
);
4144
} else if (channel.hasSubscribe()) {
42-
const channelId = props.document.info().title() + channelPath;
45+
const channelId = `outgoing_${props.document
46+
.info()
47+
.title()}_${channelPath}`;
4348
const messages: MessageData[] = channel
4449
.subscribe()
4550
.messages()
@@ -48,6 +53,7 @@ export const AsyncAPIApplication: React.FunctionComponent<ApplicationProps> = pr
4853
});
4954
outgoingNodes.push(
5055
<Outgoing
56+
key={channelId}
5157
channel={channelPath}
5258
description={channel.description() || 'No description'}
5359
id={channelId}
@@ -84,6 +90,7 @@ export const AsyncAPIApplication: React.FunctionComponent<ApplicationProps> = pr
8490
});
8591
return (
8692
<Application
93+
key={props.document.info().title()}
8794
topExtended={props.topExtended}
8895
internal={props.internal}
8996
defaultContentType={props.document.defaultContentType() || undefined}

library/src/visualiser/react-flow-renderer/ApplicationFocusView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const ApplicationFocusView: React.FunctionComponent<ApplicationFocusViewP
9090
leadApplicationIncomingChannels.push(node.id);
9191
tempElements.push(incomingReactFlowRendererNode, connectionEdge);
9292
} else {
93-
const source = `${leadApplication.id}${node.channel}`;
93+
const source = `outgoing_${leadApplication.id}_${node.channel}`;
9494
if (leadApplicationOutgoingChannels.includes(source)) {
9595
const connectionEdge = {
9696
id: `incoming-${appId}-${node.id}`,
@@ -122,7 +122,7 @@ export const ApplicationFocusView: React.FunctionComponent<ApplicationFocusViewP
122122
leadApplicationOutgoingChannels.push(node.id);
123123
tempElements.push(outgoingNode, connectionEdge);
124124
} else {
125-
const target = `${leadApplication.id}${node.channel}`;
125+
const target = `incoming_${leadApplication.id}_${node.channel}`;
126126
if (leadApplicationIncomingChannels.includes(target)) {
127127
const connectionEdge = {
128128
id: `outgoing-${appId}-${node.id}`,

library/src/visualiser/react-flow-renderer/ApplicationView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const ApplicationView: React.FunctionComponent<ApplicationViewProps> = ({
5555
position: { x: 0, y: 0 },
5656
};
5757
const connectionEdge = {
58-
id: `incoming-${appId}-${node.id}`,
58+
id: `connection-${appId}-${node.id}`,
5959
type: 'smoothstep',
6060
style: { stroke: '#7ee3be', strokeWidth: 4 },
6161
target: appId,
@@ -72,7 +72,7 @@ export const ApplicationView: React.FunctionComponent<ApplicationViewProps> = ({
7272
position: { x: 0, y: 0 },
7373
};
7474
const connectionEdge = {
75-
id: `outgoing-${appId}-${node.id}`,
75+
id: `connection-${appId}-${node.id}`,
7676
type: 'smoothstep',
7777
style: { stroke: 'orange', strokeWidth: 4 },
7878
source: appId,

0 commit comments

Comments
 (0)