import React, { useEffect, useState } from 'react'; import { Handle, Position } from 'reactflow'; import { AsyncAPIDocument } from '@asyncapi/parser'; import type { FunctionComponent } from 'react'; import { ipcRenderer } from 'electron'; interface IData { spec: AsyncAPIDocument } interface IData { messages: any[] channel: string description: string title: string version: string license: string externalDocs: string servers: string defaultContentType: string } interface ApplicationNodeProps { data: IData } const buildNodeData = (spec: AsyncAPIDocument, extraData?: any) => { if (extraData) { return extraData; } const servers = spec.servers(); const mappedServers = Object.keys(servers).reduce((newMappedServers: any[], serverKey) => { const server = servers[String(serverKey)]; newMappedServers.push({ name: serverKey, url: server.url(), description: server.description(), protocol: server.protocol(), protocolVersion: server.protocolVersion(), }); return newMappedServers; }, []); const specInfo = spec.info(); return { defaultContentType: spec.defaultContentType(), description: specInfo.description(), title: specInfo.title(), version: specInfo.version(), license: { name: specInfo.license() && specInfo.license()?.name(), url: specInfo.license() && specInfo.license()?.url(), }, // @ts-ignore externalDocs: spec.externalDocs() && spec.externalDocs().url(), servers: mappedServers, }; }; export const ApplicationNode: FunctionComponent = ({ data: { spec, description, title, version, license, externalDocs, servers, defaultContentType, }, }) => { let combinedData; if (spec) { const generatedData = buildNodeData(spec); combinedData = { ...generatedData }; } else { combinedData = { description, title, version, license, externalDocs, servers, defaultContentType, }; } const handleClick = () => { ipcRenderer.send('start-aedes'); }; const disconnectAedes = () => { ipcRenderer.send('stop-aedes'); } useEffect(() => { return () => { ipcRenderer.send('stop-aedes'); } }, []) const [isConnected, setIsConnected] = useState(false); return (
APPLICATION

{combinedData.title}

v{combinedData.version}
{combinedData.description && (
{combinedData.description}
)} {combinedData.defaultContentType && (

Default ContentType:{' '} {combinedData.defaultContentType}

)}
{combinedData.externalDocs && ( {combinedData.externalDocs} )}
{isConnected ? ( <> ) : ( )}
); }; export default ApplicationNode;