Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 18 additions & 41 deletions library/src/containers/Operations/Operation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { useConfig, useSpec } from '../../contexts';
import { CommonHelpers, SchemaHelpers } from '../../helpers';
import { EXTERAL_DOCUMENTATION_TEXT } from '../../constants';
import { PayloadType } from '../../types';
import { ServersList } from './ServersList';

interface Props {
type: PayloadType;
Expand All @@ -23,6 +24,13 @@ interface Props {
channel: ChannelInterface;
}

// Construct the full relative URL, including path, query parameters to avoid path overwrite when
// location.hash is included
const location = globalThis.location;
const relativePathname = location
? `${location.pathname}${location.search}`
: '';

export const Operation: React.FunctionComponent<Props> = (props) => {
const { type = PayloadType.SEND, operation, channelName, channel } = props;
const config = useConfig();
Expand All @@ -40,32 +48,16 @@ export const Operation: React.FunctionComponent<Props> = (props) => {
channel.parameters() !== undefined
? SchemaHelpers.parametersToSchema(channel.parameters())
: undefined;

return (
<div>
<div className="panel-item--center px-8">
<OperationInfo {...props} />

{servers && servers.length > 0 ? (
<div className="mt-2 text-sm">
<p>Available only on servers:</p>
<ul className="flex flex-wrap leading-normal">
{servers.map((server) => (
<li className="inline-block mt-2 mr-2" key={server.id()}>
<a
href={`${window.location.pathname}#${CommonHelpers.getIdentifier(
'server-' + server.id(),
config,
)}`}
className="border border-solid border-blue-300 hover:bg-blue-300 hover:text-blue-600 text-blue-500 font-bold no-underline text-xs rounded px-3 py-1 cursor-pointer"
>
<span className="underline">{server.id()}</span>
</a>
</li>
))}
</ul>
</div>
) : null}
<ServersList
servers={servers || []}
config={config}
relativePathname={relativePathname}
/>

{parameters && (
<div
Expand Down Expand Up @@ -399,26 +391,11 @@ export const OperationReplyChannelInfo: React.FunctionComponent<Props> = ({
<Markdown>{channel.description()}</Markdown>
</div>
)}
{servers && servers.length > 0 ? (
<div className="mt-2 text-sm">
<p>Available only on servers:</p>
<ul className="flex flex-wrap leading-normal">
{servers.map((server) => (
<li className="inline-block mt-2 mr-2" key={server.id()}>
<a
href={`${window.location.pathname}#${CommonHelpers.getIdentifier(
'server-' + server.id(),
config,
)}`}
className="border border-solid border-blue-300 hover:bg-blue-300 hover:text-blue-600 text-blue-500 font-bold no-underline text-xs rounded px-3 py-1 cursor-pointer"
>
<span className="underline">{server.id()}</span>
</a>
</li>
))}
</ul>
</div>
) : null}
<ServersList
servers={servers || []}
config={config}
relativePathname={relativePathname}
/>
{channel.messages().all().length > 1 ? (
<div className="mt-2">
<span className="text-xs text-gray-700">Messages:</span>
Expand Down
41 changes: 41 additions & 0 deletions library/src/containers/Operations/ServersList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { ServerInterface } from '@asyncapi/parser';
import { CommonHelpers } from '../../helpers';
import { ConfigInterface } from '../../config';

interface ServersListProps {
servers: ServerInterface[];
config: ConfigInterface;
relativePathname: string;
}

export const ServersList: React.FC<ServersListProps> = ({
servers,
config,
relativePathname,
}) => {
if (!servers || servers.length === 0) {
return null;
}

return (
<div className="mt-2 text-sm">
<p>Available only on servers:</p>
<ul className="flex flex-wrap leading-normal">
{servers.map((server) => (
<li className="inline-block mt-2 mr-2" key={server.id()}>
<a
href={`${relativePathname}#${CommonHelpers.getIdentifier(
'server-' + server.id(),
config,
)}`}
className="border border-solid border-blue-300 hover:bg-blue-300 hover:text-blue-600 text-blue-500 font-bold no-underline text-xs rounded px-3 py-1 cursor-pointer"
>
<span className="underline">{server.id()}</span>
</a>
</li>
))}
</ul>
</div>
);
};

Check failure on line 41 in library/src/containers/Operations/ServersList.tsx

View workflow job for this annotation

GitHub Actions / Test NodeJS PR - ubuntu-latest

Insert `⏎`
Loading