diff --git a/apps/studio/src/components/Content.tsx b/apps/studio/src/components/Content.tsx index cea67ccc6..0f1de056f 100644 --- a/apps/studio/src/components/Content.tsx +++ b/apps/studio/src/components/Content.tsx @@ -1,7 +1,6 @@ import SplitPane from './SplitPane'; import { Editor } from './Editor/Editor'; import { Navigation } from './Navigation'; -import { Navigationv3 } from './Navigationv3'; import { Template } from './Template'; import { VisualiserTemplate } from './Visualiser'; @@ -43,9 +42,7 @@ export const Content: FunctionComponent = () => { // eslint-disabl localStorage.setItem(splitPosLeft, String(size)); }, 100)} > - { - isV3 ? : - } + ); diff --git a/apps/studio/src/components/Navigation.tsx b/apps/studio/src/components/Navigation.tsx index 4a94a1822..2fdbeaf0b 100644 --- a/apps/studio/src/components/Navigation.tsx +++ b/apps/studio/src/components/Navigation.tsx @@ -9,6 +9,7 @@ import type { AsyncAPIDocumentInterface } from '@asyncapi/parser/cjs'; interface NavigationProps { className?: string; + isV3?:boolean; } interface NavigationSectionProps { @@ -67,6 +68,142 @@ const ServersNavigation: React.FunctionComponent = ({ ); }; +const ChannelsNavigation: React.FunctionComponent = ({ + document, + hash, +}) => { + const { navigationSvc } = useServices(); + + const channels = document.channels().all().map( + (channel) => { + return
  • + navigationSvc.scrollTo( + `/channels/${(channel.id() ?? '').replace(/\//g, '~1')}`, + `channels-${channel.id()}`, + ) + } + > +
    +
    + + {channel.id()} + +
    + {channel.address()} +
    +
  • + }, + ); + + return ( + <> +
    + navigationSvc.scrollTo( + '/channels', + 'channels', + ) + } + > + Channels +
    +
      {channels}
    + + ); +}; + +const V3OperationsNavigation: React.FunctionComponent = ({ + document, + hash, +}) => { + const { navigationSvc } = useServices(); + + const operations = document.operations().all().map( + (operation) => { + const operations: React.ReactNode[] = []; + if (operation.isReceive()) { + operations.push( +
  • + navigationSvc.scrollTo( + `/operations/${(operation.id() ?? '').replace(/\//g, '~1')}`, + `operation-receive-${operation.id()}`, + ) + } + > +
    +
    + + Receive + +
    + {operation.id()} +
    +
  • + ); + } + if (operation.isSend()) { + operations.push( +
  • + navigationSvc.scrollTo( + `/operations/${(operation.id() ?? '').replace(/\//g, '~1')}`, + `operation-send-${operation.id()}`, + ) + } + > +
    +
    + + Send + +
    + {operation.id()} +
    +
  • , + ); + } + + return operations; + }, + ); + + return ( + <> +
    + navigationSvc.scrollTo( + '/operations', + 'operations', + ) + } + > + Operations +
    +
      {operations}
    + + ); +}; + const OperationsNavigation: React.FunctionComponent = ({ document, hash, @@ -250,6 +387,7 @@ const SchemasNavigation: React.FunctionComponent = ({ export const Navigation: React.FunctionComponent = ({ className = '', + isV3 = false }) => { const [hash, setHash] = useState(window.location.hash); @@ -306,13 +444,28 @@ export const Navigation: React.FunctionComponent = ({ /> )} + { isV3 &&
  • -
  • + } +
  • + { isV3 + ? + : + } +
  • {!components.messages().isEmpty() && (
  • = ({ - document, - hash, -}) => { - const { navigationSvc } = useServices(); - - return ( - <> -
    - navigationSvc.scrollTo('/servers', 'servers') - } - > - Servers -
    -
      - {document.servers().all().map((server) => { - const serverName = server.id(); - return
    • - navigationSvc.scrollTo( - `/servers/${serverName.replace(/\//g, '~1')}`, - `server-${serverName}`, - ) - } - > -
      -
      - - {server.protocolVersion() - ? `${server.protocol()} ${server.protocolVersion()}` - : server.protocol()} - -
      - {serverName} -
      -
    • - })} -
    - - ); -}; - -const ChannelsNavigation: React.FunctionComponent = ({ - document, - hash, -}) => { - const { navigationSvc } = useServices(); - - const channels = document.channels().all().map( - (channel) => { - return
  • - navigationSvc.scrollTo( - `/channels/${(channel.id() ?? '').replace(/\//g, '~1')}`, - `channels-${channel.id()}`, - ) - } - > -
    -
    - - {channel.id()} - -
    - {channel.address()} -
    -
  • - }, - ); - - return ( - <> -
    - navigationSvc.scrollTo( - '/channels', - 'channels', - ) - } - > - Channels -
    -
      {channels}
    - - ); -}; - -const OperationsNavigation: React.FunctionComponent = ({ - document, - hash, -}) => { - const { navigationSvc } = useServices(); - - const operations = document.operations().all().map( - (operation) => { - const operations: React.ReactNode[] = []; - if (operation.isReceive()) { - operations.push( -
  • - navigationSvc.scrollTo( - `/operations/${(operation.id() ?? '').replace(/\//g, '~1')}`, - `operation-receive-${operation.id()}`, - ) - } - > -
    -
    - - Receive - -
    - {operation.id()} -
    -
  • - ); - } - if (operation.isSend()) { - operations.push( -
  • - navigationSvc.scrollTo( - `/operations/${(operation.id() ?? '').replace(/\//g, '~1')}`, - `operation-send-${operation.id()}`, - ) - } - > -
    -
    - - Send - -
    - {operation.id()} -
    -
  • , - ); - } - - return operations; - }, - ); - - return ( - <> -
    - navigationSvc.scrollTo( - '/operations', - 'operations', - ) - } - > - Operations -
    -
      {operations}
    - - ); -}; - -const MessagesNavigation: React.FunctionComponent = ({ - document, - hash, -}) => { - const { navigationSvc } = useServices(); - - const messages = document.components().messages().all().map( - message => { - const messageName = message.id(); - return
  • - navigationSvc.scrollTo( - `/components/messages/${messageName.replace(/\//g, '~1')}`, - `message-${messageName}`, - ) - } - > - {messageName} -
  • - }, - ); - - return ( - <> -
    - navigationSvc.scrollTo( - '/components/messages', - 'messages', - ) - } - > - Messages -
    -
      {messages}
    - - ); -}; - -const SchemasNavigation: React.FunctionComponent = ({ - document, - hash, -}) => { - const { navigationSvc } = useServices(); - - const schemas = document.components().schemas().all().map( - schema => { - const schemaName = schema.id(); - return
  • - navigationSvc.scrollTo( - `/components/schemas/${schemaName.replace(/\//g, '~1')}`, - `schema-${schemaName}`, - ) - } - > - {schemaName} -
  • - } - ); - - return ( - <> -
    - navigationSvc.scrollTo( - '/components/schemas', - 'schemas', - ) - } - > - Schemas -
    -
      {schemas}
    - - ); -}; - -export const Navigationv3: React.FunctionComponent = ({ - className = '', -}) => { - const [hash, setHash] = useState(window.location.hash); - - const { navigationSvc } = useServices(); - const rawSpec = useFilesState(state => state.files['asyncapi']?.content); - const document = useDocumentsState(state => state.documents['asyncapi']?.document); - - useEffect(() => { - const fn = () => { - // remove `#` char - const h = window.location.hash.startsWith('#') ? window.location.hash.substring(1) : window.location.hash; - setHash(h); - }; - fn(); - window.addEventListener('hashchange', fn); - return () => { - window.removeEventListener('hashchange', fn); - }; - }, []); - - if (!rawSpec || !document) { - return ( -
    - Empty or invalid document. Please fix errors/define AsyncAPI document. -
    - ); - } - - const components = document.components(); - return ( -
    -
      -
    • -
      - navigationSvc.scrollTo( - '/info', - 'introduction', - ) - } - > - Information -
      -
    • - {!document.servers().isEmpty() && ( -
    • - -
    • - )} -
    • - -
    • -
    • - -
    • - {!components.messages().isEmpty() && ( -
    • - -
    • - )} - {!components.schemas().isEmpty() && ( -
    • - -
    • - )} -
    -
    - ); -}; \ No newline at end of file