From 400b4d0eb5bbc64ae3b6142df60dcae0fa69027b Mon Sep 17 00:00:00 2001 From: Kirill Efimov Date: Mon, 1 Apr 2024 12:10:36 +0300 Subject: [PATCH] fix(table of contents): correctly show all operations --- components/TableOfContents.js | 86 ++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 41 deletions(-) diff --git a/components/TableOfContents.js b/components/TableOfContents.js index d63400458..3c2b4d32e 100644 --- a/components/TableOfContents.js +++ b/components/TableOfContents.js @@ -1,64 +1,68 @@ import { Text, Indent, IndentationTypes } from '@asyncapi/generator-react-sdk'; -import { Header, Link, ListItem } from '../components/common'; - import { FormatHelpers } from '../helpers/format'; +import { CommonHelpers } from '../helpers/common'; -export function TableOfContents({ asyncapi }) { - const serversList = asyncapi.servers().all().map(server => { - const serverName = server.id(); - return ( - - - {serverName} - - - ); - }); +import { Header, Link, ListItem } from './common'; - const operationsList = []; - asyncapi.channels().all().map(channel => { - const channelName = channel.address(); - channel.operations().all().forEach(operation => { - if (operation.action() === 'publish') { - operationsList.push( - - - PUB {channelName} - - - ); - } - if (operation.action() === 'subscribe') { - operationsList.push( - - - SUB {channelName} - - - ); - } - }); - }); +export function TableOfContents({asyncapi}) { + const servers = asyncapi.servers().all(); + const operations = asyncapi.operations().all(); return ( <>
Table of Contents
- {serversList.length > 0 && ( + {servers.length > 0 && ( <> Servers - {serversList} + {servers.map((server) => { + const serverName = server.id(); + return ( + + + + {serverName} + + + + ); + })} )} - {operationsList.length > 0 && ( + {operations.length > 0 && ( <> Operations - {operationsList} + {operations.map((operation) => { + const channel = operation.channels().all()[0]; + const channelAddress = channel?.address() ?? ''; + const type = CommonHelpers.getOperationType(operation); + return ( + + + + {type.toUpperCase()} {channelAddress} + + + + ); + })} )}