-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f8faa34
commit 4ecac89
Showing
12 changed files
with
240 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { SystemView, fromURL} from '@asyncapi/edavisualiser'; | ||
import { apps } from './apps'; | ||
import '@asyncapi/edavisualiser/styles/default.css'; | ||
const AsyncapiParser = require('@asyncapi/parser/browser'); | ||
|
||
function Asyncapi() { | ||
const [asyncapiDocuments, setAsyncapiDocuments] = useState<Array<{ parsedDoc: any, name: string }>>([]); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
const data = []; | ||
const parser = new AsyncapiParser.Parser({ | ||
ruleset: { core:false, recommended:false } | ||
}); | ||
for (const [name, asyncapiUrl] of Object.entries(apps)) { | ||
const result = fromURL(parser, asyncapiUrl); | ||
const {document, diagnostics} = await result.parse(); | ||
console.log(diagnostics) | ||
if(document) | ||
data.push({ parsedDoc: document, name }); | ||
} | ||
setAsyncapiDocuments(data); | ||
}; | ||
|
||
fetchData().catch(console.error); | ||
}, []); | ||
|
||
let node; | ||
if (asyncapiDocuments.length > 0) { | ||
node = ( | ||
<SystemView | ||
applications={asyncapiDocuments.map(({ parsedDoc, name }) => { | ||
return { | ||
asyncapi: { | ||
document: parsedDoc, | ||
topExtended: ( | ||
<div className="flex justify-between mb-4"> | ||
<a | ||
className="leading-6 text-gray-900 uppercase text-xs font-light" | ||
href={'/EDAVisualiser/edalearn/' + name} | ||
> | ||
<button | ||
style={{ | ||
backgroundColor: 'rgba(110, 231, 183, 1)', | ||
padding: '0 10px', | ||
}} | ||
> | ||
Focus application | ||
</button> | ||
</a> | ||
</div> | ||
) | ||
}, | ||
} | ||
})} | ||
/> | ||
); | ||
} else { | ||
node = <h1>Wait...</h1>; | ||
} | ||
return <div className="App">{node}</div>; | ||
} | ||
|
||
export default Asyncapi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { useState, useEffect } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { ApplicationFocusView, fromURL } from '@asyncapi/edavisualiser'; | ||
import { apps } from './apps'; | ||
import '@asyncapi/edavisualiser/styles/default.css'; | ||
const AsyncapiParser = require('@asyncapi/parser/browser'); | ||
|
||
|
||
function Asyncapi() { | ||
const [externalApplications, setAsyncapiDocuments] = useState<Array<{ parsedDoc: any, name: string }>>([]); | ||
const [focusedApplication, setFocusedApplication] = useState<{ parsedDoc: any, name: string }>(); | ||
let { application } = useParams<{ application: string }>(); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
const data = []; | ||
const parser = new AsyncapiParser.Parser({ | ||
ruleset: { core: false, recommended: false } | ||
}); | ||
for (const [name, asyncapiUrl] of Object.entries(apps)) { | ||
const result = fromURL(parser, asyncapiUrl); | ||
const {document} = await result.parse(); | ||
if (application === name) { | ||
setFocusedApplication({ parsedDoc: document, name }); | ||
} else { | ||
data.push({ parsedDoc: document, name }); | ||
} | ||
} | ||
setAsyncapiDocuments(data); | ||
}; | ||
|
||
fetchData().catch(console.error); | ||
}, [application]); | ||
|
||
let node; | ||
if (externalApplications.length > 0 && focusedApplication !== undefined) { | ||
node = ( | ||
<ApplicationFocusView | ||
asyncapi={{ document: focusedApplication.parsedDoc }} | ||
external={externalApplications.map(({ parsedDoc, name }) => { | ||
return { | ||
asyncapi: { | ||
document: parsedDoc, | ||
topExtended: ( | ||
<div className="flex justify-between mb-4"> | ||
<a | ||
className="leading-6 text-gray-900 uppercase text-xs font-light" | ||
href={'/EDAVisualiser/edalearn/' + name} | ||
> | ||
<button | ||
style={{ | ||
backgroundColor: 'rgba(110, 231, 183, 1)', | ||
padding: '0 10px', | ||
}} | ||
> | ||
Focus application | ||
</button> | ||
</a> | ||
</div> | ||
) | ||
} | ||
} | ||
})} | ||
/> | ||
); | ||
} else { | ||
node = <h1>Wait...</h1>; | ||
} | ||
return <div className="App">{node}</div>; | ||
} | ||
|
||
export default Asyncapi; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export const apps = { | ||
customers: | ||
'https://raw.githubusercontent.com/EDALearn/FoodDeliveryService-KIT-AsyncAPI-In-Action/main/modules/customers/src/main/resources/apis/asyncapi.yml', | ||
orders: | ||
'https://raw.githubusercontent.com/EDALearn/FoodDeliveryService-KIT-AsyncAPI-In-Action/main/modules/orders/src/main/resources/apis/asyncapi.yml', | ||
restaurants: 'https://raw.githubusercontent.com/EDALearn/FoodDeliveryService-KIT-AsyncAPI-In-Action/main/modules/restaurants/src/main/resources/apis/asyncapi.yml', | ||
delivery: 'https://raw.githubusercontent.com/EDALearn/FoodDeliveryService-KIT-AsyncAPI-In-Action/main/modules/delivery/src/main/resources/apis/asyncapi.yml' | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module '@asyncapi/parser/browser/index'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { | ||
Parser, | ||
ParseOptions, | ||
ParseOutput, | ||
ValidateOptions, | ||
Input, | ||
Diagnostic, | ||
} from '@asyncapi/parser'; | ||
|
||
/** | ||
* Functionality taken from the AsyncAPI parser | ||
*/ | ||
|
||
export interface FromResult { | ||
parse: (options?: ParseOptions) => Promise<ParseOutput>; | ||
validate: (options?: ValidateOptions) => Promise<Diagnostic[]>; | ||
} | ||
|
||
export function fromURL( | ||
parser: Parser, | ||
source: string, | ||
options?: RequestInit, | ||
): FromResult { | ||
async function fetchUrl(): Promise<Input> { | ||
const fetchFn = await getFetch(); | ||
return (await fetchFn(source, options as any)).text(); | ||
} | ||
|
||
return { | ||
async parse(options: ParseOptions = {}) { | ||
const schema = await fetchUrl(); | ||
return parser.parse(schema, { ...options, source }); | ||
}, | ||
async validate(options: ValidateOptions = {}) { | ||
const schema = await fetchUrl(); | ||
return parser.validate(schema, { ...options, source }); | ||
}, | ||
}; | ||
} | ||
|
||
let __fetchFn: typeof fetch | undefined; | ||
async function getFetch(): Promise<typeof fetch> { | ||
if (__fetchFn) { | ||
return __fetchFn; | ||
} | ||
|
||
if (typeof fetch === 'undefined') { | ||
return (__fetchFn = ((await import('node-fetch')) | ||
.default as unknown) as typeof fetch); | ||
} | ||
return (__fetchFn = fetch); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters