This repository was archived by the owner on Oct 29, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 10 files changed +2218
-112
lines changed
react-flow-renderer-nodes
visualiser/react-flow-renderer Expand file tree Collapse file tree 10 files changed +2218
-112
lines changed Original file line number Diff line number Diff line change 44 "private" : true ,
55 "dependencies" : {
66 "@asyncapi/parser" : " ^1.15.0" ,
7- "@lagoni/edavisualiser" : " 0.4.2 " ,
7+ "@lagoni/edavisualiser" : " 0.8.0 " ,
88 "react" : " ^16.8.0" ,
99 "react-dom" : " ^16.8.0" ,
10+ "react-router-dom" : " ^5.3.0" ,
1011 "react-scripts" : " 5.0.1" ,
1112 "web-vitals" : " ^2.1.4"
1213 },
2021 "build" : " react-scripts build" ,
2122 "test" : " react-scripts test" ,
2223 "eject" : " react-scripts eject" ,
23- "build:symlink" : " npm link ../../library/node_modules/react-dom && npm link ../../library/node_modules/react"
24+ "build:symlink" : " npm link ../../library/node_modules/react-dom && npm link ../../library/node_modules/react" ,
25+ "build:link" : " cd ../../library && npm link && cd ../examples/simple-react && npm link @lagoni/edavisualiser"
2426 },
2527 "eslintConfig" : {
2628 "extends" : [
Original file line number Diff line number Diff line change 1+ import React , { useState , useEffect } from 'react' ;
2+ import {
3+ ApplicationView ,
4+ AsyncAPIApplication ,
5+ SystemView ,
6+ } from '@lagoni/edavisualiser' ;
7+ import '@lagoni/edavisualiser/styles/default.css' ;
8+ import '../App.css' ;
9+ import '@asyncapi/parser/dist/bundle' ;
10+ import { useParams } from 'react-router-dom' ;
11+ import { apps } from './apps' ;
12+
13+ const parser = window [ 'AsyncAPIParser' ] ;
14+ function Asyncapi ( ) {
15+ let { application } = useParams ( ) ;
16+ const [ asyncapiDocument , setAsyncapiDocument ] = useState ( undefined ) ;
17+
18+ useEffect ( ( ) => {
19+ // declare the async data fetching function
20+ const fetchData = async ( ) => {
21+ const appLink = apps [ application ] ;
22+ if ( appLink !== undefined ) {
23+ const doc = await parser . parseFromUrl ( appLink ) ;
24+ setAsyncapiDocument ( doc ) ;
25+ }
26+ } ;
27+
28+ // call the function
29+ fetchData ( )
30+ // make sure to catch any error
31+ . catch ( console . error ) ;
32+ } , [ ] ) ;
33+ let something ;
34+ if ( asyncapiDocument !== undefined ) {
35+ something = (
36+ < ApplicationView >
37+ < AsyncAPIApplication document = { asyncapiDocument } />
38+ </ ApplicationView >
39+ ) ;
40+ } else {
41+ something = < h1 > Not loaded</ h1 > ;
42+ }
43+ return < div className = "App" > { something } </ div > ;
44+ }
45+
46+ export default Asyncapi ;
Original file line number Diff line number Diff line change 1+ export const apps = {
2+ rust_public :
3+ 'https://raw.githubusercontent.com/GamingAPI/definitions/main/bundled/rust_public.asyncapi.json' ,
4+ rust :
5+ 'https://raw.githubusercontent.com/GamingAPI/definitions/main/bundled/rust.asyncapi.json' ,
6+ } ;
Original file line number Diff line number Diff line change 1+ import React , { useState , useEffect } from 'react' ;
2+ import { AsyncAPIApplication , SystemView } from '@lagoni/edavisualiser' ;
3+ import '@lagoni/edavisualiser/styles/default.css' ;
4+ import '../App.css' ;
5+ import '@asyncapi/parser/dist/bundle' ;
6+ import { apps } from './apps' ;
7+
8+ const parser = window [ 'AsyncAPIParser' ] ;
9+ function Asyncapi ( ) {
10+ const [ asyncapiDocuments , setAsyncapiDocuments ] = useState ( [ ] ) ;
11+ useEffect ( ( ) => {
12+ // declare the async data fetching function
13+ const fetchData = async ( ) => {
14+ const data = [ ] ;
15+ for ( const [ name , asyncapiUrl ] of Object . entries ( apps ) ) {
16+ const parsedDoc = await parser . parseFromUrl ( asyncapiUrl ) ;
17+ data . push ( { parsedDoc, name } ) ;
18+ }
19+ setAsyncapiDocuments ( data ) ;
20+ } ;
21+
22+ // call the function
23+ fetchData ( )
24+ // make sure to catch any error
25+ . catch ( console . error ) ;
26+ } , [ ] ) ;
27+ let something ;
28+ if ( asyncapiDocuments . length > 0 ) {
29+ something = (
30+ < SystemView >
31+ { asyncapiDocuments . map ( ( { parsedDoc, name } ) => {
32+ return (
33+ < AsyncAPIApplication
34+ document = { parsedDoc }
35+ topExtended = {
36+ < div className = "flex justify-between mb-4" >
37+ < a
38+ className = "block leading-6 text-gray-900 uppercase text-xs font-light"
39+ href = { '/gamingapi/application/' + name }
40+ >
41+ Go to application
42+ </ a >
43+ </ div >
44+ }
45+ />
46+ ) ;
47+ } ) }
48+ </ SystemView >
49+ ) ;
50+ } else {
51+ something = < h1 > Not loaded</ h1 > ;
52+ }
53+ return < div className = "App" > { something } </ div > ;
54+ }
55+
56+ export default Asyncapi ;
Original file line number Diff line number Diff line change @@ -3,16 +3,30 @@ import ReactDOM from 'react-dom';
33import './index.css' ;
44import App from './App' ;
55import SystemView from './SystemView' ;
6- import reportWebVitals from './reportWebVitals' ;
6+ import GamingapiSystem from './gamingapi/system' ;
7+ import GamingapiApplication from './gamingapi/application' ;
8+ import Asyncapi from './Asyncapi' ;
9+ import { Route , BrowserRouter as Router } from 'react-router-dom' ;
710
811ReactDOM . render (
912 < React . StrictMode >
10- < SystemView />
13+ < Router >
14+ < Route exact path = "/" >
15+ < App />
16+ </ Route >
17+ < Route exact path = "/system" >
18+ < SystemView />
19+ </ Route >
20+ < Route exact path = "/asyncapi" >
21+ < Asyncapi />
22+ </ Route >
23+ < Route exact path = "/gamingapi/system" >
24+ < GamingapiSystem />
25+ </ Route >
26+ < Route exact path = "/gamingapi/application/:application" >
27+ < GamingapiApplication />
28+ </ Route >
29+ </ Router >
1130 </ React . StrictMode > ,
1231 document . getElementById ( 'root' ) ,
1332) ;
14-
15- // If you want to start measuring performance in your app, pass a function
16- // to log results (for example: reportWebVitals(console.log))
17- // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
18- reportWebVitals ( ) ;
Original file line number Diff line number Diff line change 1- import React from 'react' ;
1+ import React , { ReactElement } from 'react' ;
22import {
33 ApplicationLicenseData ,
44 ApplicationServerData ,
@@ -11,6 +11,7 @@ import { AsyncAPIDocument } from '@asyncapi/parser';
1111import { Incoming } from './Incoming' ;
1212type AsyncapiApplicationProps = {
1313 document : AsyncAPIDocument ;
14+ topExtended ?: ReactElement ;
1415} ;
1516
1617type ApplicationProps = AsyncapiApplicationProps & InternalProps ;
@@ -85,6 +86,7 @@ export const AsyncAPIApplication: React.FunctionComponent<ApplicationProps> = pr
8586 } ) ;
8687 return (
8788 < Application
89+ topExtended = { props . topExtended }
8890 internal = { props . internal }
8991 defaultContentType = { props . document . defaultContentType ( ) || 'Undefined' }
9092 description = { props . document . info ( ) . description ( ) || 'No description' }
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ export const ApplicationNode: React.FunctionComponent<ApplicationNodeProps> = ({
1313 servers,
1414 defaultContentType,
1515 hideHandlers,
16+ topExtended,
1617 } ,
1718} ) => {
1819 return (
@@ -28,8 +29,9 @@ export const ApplicationNode: React.FunctionComponent<ApplicationNodeProps> = ({
2829
2930 < div >
3031 < div className = "px-4 py-5 sm:px-6" >
32+ { topExtended !== undefined && topExtended }
3133 < div className = "flex justify-between mb-4" >
32- < span className = "block leading-6 text-gray-900 uppercase text-xs font-light" >
34+ < span className = "block leading-6 text-gray-900 uppercase text-xs font-light" >
3335 application
3436 </ span >
3537 </ div >
Original file line number Diff line number Diff line change 1+ import { ReactElement } from 'react' ;
12import { FlowElement } from 'react-flow-renderer' ;
23
34export type InternalProps = {
@@ -29,6 +30,7 @@ export interface ApplicationNodeData {
2930 externalDocs ?: string ;
3031 servers ?: ApplicationServerData [ ] ;
3132 hideHandlers ?: boolean ;
33+ topExtended ?: ReactElement ;
3234}
3335
3436export interface ApplicationNodeProps {
Original file line number Diff line number Diff line change @@ -46,21 +46,23 @@ export const SystemView: React.FunctionComponent<SystemViewProps> = ({
4646 } ;
4747 tempElements . push ( applicationReactFlowRendererNode ) ;
4848 } ;
49+
4950 const addOutgoingCallback = ( node : OutgoingNodeData ) => {
5051 const appId = node . forApplication || '' ;
5152 const uniqueConnectionId = node . channel ;
5253 ! outgoingConnections [ appId ] && ( outgoingConnections [ appId ] = [ ] ) ;
5354 outgoingConnections [ appId ] . push ( uniqueConnectionId ) ;
5455 } ;
56+
5557 const addIncomingCallback = ( node : IncomingNodeData ) => {
5658 const appId = node . forApplication || '' ;
5759 const uniqueConnectionId = node . channel ;
5860 ! incomingConnections [ uniqueConnectionId ] &&
5961 ( incomingConnections [ uniqueConnectionId ] = [ ] ) ;
6062 incomingConnections [ uniqueConnectionId ] . push ( appId ) ;
6163 } ;
62- // for each application, list all applications it connects to based on channel
6364
65+ // for each application, list all applications it connects to based on channel
6466 useEffect ( ( ) => {
6567 for ( const [ appId , uniqueChannels ] of Object . entries ( outgoingConnections ) ) {
6668 for ( const uniqueChannel of uniqueChannels ) {
You can’t perform that action at this time.
0 commit comments