Skip to content

Commit a1f55ef

Browse files
Merge master into dependabot/npm_and_yarn/library/webpack-5.104.1
2 parents b010476 + 374fb4e commit a1f55ef

File tree

2 files changed

+60
-41
lines changed

2 files changed

+60
-41
lines changed

library/src/containers/Operations/Operation.tsx

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { CommonHelpers, SchemaHelpers } from '../../helpers';
1616
import { EXTERAL_DOCUMENTATION_TEXT } from '../../constants';
1717
import { PayloadType, PluginSlot } from '../../types';
1818
import { PluginManager } from '../../helpers/pluginManager';
19+
import { ServersList } from './ServersList';
1920
import { SlotRenderer } from '../../components/PluginSlotRenderer';
2021
import { usePlugin } from '../../contexts/usePlugin';
2122

@@ -26,6 +27,13 @@ interface Props {
2627
channel: ChannelInterface;
2728
}
2829

30+
// Construct the full relative URL, including path, query parameters to avoid path overwrite when
31+
// location.hash is included
32+
const location = globalThis.location;
33+
const relativePathname = location
34+
? `${location.pathname}${location.search}`
35+
: '';
36+
2937
export const Operation: React.FunctionComponent<Props> = (props) => {
3038
const { type = PayloadType.SEND, operation, channelName, channel } = props;
3139
const config = useConfig();
@@ -43,31 +51,16 @@ export const Operation: React.FunctionComponent<Props> = (props) => {
4351
channel.parameters() !== undefined
4452
? SchemaHelpers.parametersToSchema(channel.parameters())
4553
: undefined;
46-
4754
return (
4855
<div>
4956
<div className="panel-item--center px-8">
5057
<OperationInfo {...props} />
51-
{servers && servers.length > 0 ? (
52-
<div className="mt-2 text-sm">
53-
<p>Available only on servers:</p>
54-
<ul className="flex flex-wrap leading-normal">
55-
{servers.map((server) => (
56-
<li className="inline-block mt-2 mr-2" key={server.id()}>
57-
<a
58-
href={`${window.location.pathname}#${CommonHelpers.getIdentifier(
59-
'server-' + server.id(),
60-
config,
61-
)}`}
62-
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"
63-
>
64-
<span className="underline">{server.id()}</span>
65-
</a>
66-
</li>
67-
))}
68-
</ul>
69-
</div>
70-
) : null}
58+
59+
<ServersList
60+
servers={servers || []}
61+
config={config}
62+
relativePathname={relativePathname}
63+
/>
7164

7265
{parameters && (
7366
<div
@@ -411,26 +404,11 @@ export const OperationReplyChannelInfo: React.FunctionComponent<Props> = ({
411404
<Markdown>{channel.description()}</Markdown>
412405
</div>
413406
)}
414-
{servers && servers.length > 0 ? (
415-
<div className="mt-2 text-sm">
416-
<p>Available only on servers:</p>
417-
<ul className="flex flex-wrap leading-normal">
418-
{servers.map((server) => (
419-
<li className="inline-block mt-2 mr-2" key={server.id()}>
420-
<a
421-
href={`${window.location.pathname}#${CommonHelpers.getIdentifier(
422-
'server-' + server.id(),
423-
config,
424-
)}`}
425-
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"
426-
>
427-
<span className="underline">{server.id()}</span>
428-
</a>
429-
</li>
430-
))}
431-
</ul>
432-
</div>
433-
) : null}
407+
<ServersList
408+
servers={servers || []}
409+
config={config}
410+
relativePathname={relativePathname}
411+
/>
434412
{channel.messages().all().length > 1 ? (
435413
<div className="mt-2">
436414
<span className="text-xs text-gray-700">Messages:</span>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import React from 'react';
2+
import { ServerInterface } from '@asyncapi/parser';
3+
import { CommonHelpers } from '../../helpers';
4+
import { ConfigInterface } from '../../config';
5+
6+
interface ServersListProps {
7+
servers: ServerInterface[];
8+
config: ConfigInterface;
9+
relativePathname: string;
10+
}
11+
12+
export const ServersList: React.FC<ServersListProps> = ({
13+
servers,
14+
config,
15+
relativePathname,
16+
}) => {
17+
if (!servers || servers.length === 0) {
18+
return null;
19+
}
20+
21+
return (
22+
<div className="mt-2 text-sm">
23+
<p>Available only on servers:</p>
24+
<ul className="flex flex-wrap leading-normal">
25+
{servers.map((server) => (
26+
<li className="inline-block mt-2 mr-2" key={server.id()}>
27+
<a
28+
href={`${relativePathname}#${CommonHelpers.getIdentifier(
29+
'server-' + server.id(),
30+
config,
31+
)}`}
32+
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"
33+
>
34+
<span className="underline">{server.id()}</span>
35+
</a>
36+
</li>
37+
))}
38+
</ul>
39+
</div>
40+
);
41+
};

0 commit comments

Comments
 (0)