Skip to content

Commit 69e7c7b

Browse files
authored
fix: sidebar navigation problems (#887)
1 parent 75fe2a8 commit 69e7c7b

File tree

10 files changed

+573
-2589
lines changed

10 files changed

+573
-2589
lines changed

docs/configuration/config-modification.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ interface ConfigInterface {
3030
parserOptions?: ParserOptions;
3131
publishLabel?: string;
3232
subscribeLabel?: string;
33+
sendLabel?: string;
34+
receiveLabel?: string;
35+
requestLabel?: string;
36+
replyLabel?: string;
3337
}
3438
```
3539

@@ -61,14 +65,34 @@ interface ConfigInterface {
6165

6266
- **publishLabel?: string**
6367

64-
This field contains configuration responsible for customizing the label for publish operations.
65-
This field is set to `PUB` by default.
68+
This field contains configuration responsible for customizing the label for publish operations.This take effect for AsyncAPI v2 documents.
69+
This field is set to `PUB` by default.
6670

6771
- **subscribeLabel?: string**
6872

69-
This field contains configuration responsible for customizing the label for subscribe operations.
73+
This field contains configuration responsible for customizing the label for subscribe operations. This take effect for AsyncAPI v2 documents.
7074
This field is set to `SUB` by default.
7175

76+
- **sendLabel?: string**
77+
78+
This field contains configuration responsible for customizing the label for send operation. This takes effect when rendering AsyncAPI v3 documents.
79+
This field is set to `SEND` by default.
80+
81+
- **receiveLabel?: string**
82+
83+
This field contains configuration responsible for customizing the label for receive operation. This takes effect when rendering AsyncAPI v3 documents.
84+
This field is set to `RECEIVE` by default.
85+
86+
- **requestLabel?: string**
87+
88+
This field contains configuration responsible for customizing the label for request operation. This takes effect when rendering AsyncAPI v3 documents.
89+
This field is set to `REQUEST` by default.
90+
91+
- **replyLabel?: string**
92+
93+
This field contains configuration responsible for customizing the label for response operation. This takes effect when rendering AsyncAPI v3 documents.
94+
This field is set to `REPLY` by default.
95+
7296
## Examples
7397

7498
See exemplary component configuration in TypeScript and JavaScript.
@@ -154,5 +178,9 @@ In the above examples, after concatenation with the default configuration, the r
154178
},
155179
publishLabel: 'PUB',
156180
subscribeLabel: 'SUB',
181+
sendLabel: 'SEND',
182+
receiveLabel: 'RECEIVE',
183+
requestLabel: 'REQUEST',
184+
replyLabel: 'REPLY'
157185
}
158186
```

library/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@asyncapi/react-component",
3-
"version": "1.2.12",
3+
"version": "1.2.13",
44
"private": false,
55
"description": "A React component for AsyncAPI specification.",
66
"repository": {

library/src/config/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export interface ConfigInterface {
55
sidebar?: SideBarConfig;
66
parserOptions?: any;
77
publishLabel?: string;
8-
sendLabel?: string;
98
subscribeLabel?: string;
9+
sendLabel?: string;
1010
receiveLabel?: string;
1111
requestLabel?: string;
1212
replyLabel?: string;

library/src/config/default.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { ConfigInterface } from './config';
22
import {
33
PUBLISH_LABEL_DEFAULT_TEXT,
4+
RECEIVE_TEXT_LABEL_DEFAULT_TEXT,
5+
REPLIER_LABEL_DEFAULT_TEXT,
6+
REQUEST_LABEL_DEFAULT_TEXT,
7+
SEND_LABEL_DEFAULT_TEXT,
48
SUBSCRIBE_LABEL_DEFAULT_TEXT,
59
} from '../constants';
610

@@ -24,4 +28,8 @@ export const defaultConfig: ConfigInterface = {
2428
},
2529
publishLabel: PUBLISH_LABEL_DEFAULT_TEXT,
2630
subscribeLabel: SUBSCRIBE_LABEL_DEFAULT_TEXT,
31+
sendLabel: SEND_LABEL_DEFAULT_TEXT,
32+
receiveLabel: RECEIVE_TEXT_LABEL_DEFAULT_TEXT,
33+
requestLabel: REQUEST_LABEL_DEFAULT_TEXT,
34+
replyLabel: REPLIER_LABEL_DEFAULT_TEXT,
2735
};

library/src/containers/Operations/Operation.tsx

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useState } from 'react';
22
import { ChannelInterface, OperationInterface } from '@asyncapi/parser';
3-
43
import { Message } from '../Messages/Message';
54
import { Security } from '../Servers/Security';
65
import {
@@ -12,20 +11,11 @@ import {
1211
CollapseButton,
1312
} from '../../components';
1413
import { Href } from '../../components/Href';
15-
1614
import { useConfig, useSpec } from '../../contexts';
1715
import { CommonHelpers, SchemaHelpers } from '../../helpers';
18-
import {
19-
EXTERAL_DOCUMENTATION_TEXT,
20-
PUBLISH_LABEL_DEFAULT_TEXT,
21-
RECEIVE_TEXT_LABEL_DEFAULT_TEXT,
22-
REPLIER_LABEL_DEFAULT_TEXT,
23-
REQUEST_LABEL_DEFAULT_TEXT,
24-
SEND_LABEL_DEFAULT_TEXT,
25-
SUBSCRIBE_LABEL_DEFAULT_TEXT,
26-
} from '../../constants';
16+
import { EXTERAL_DOCUMENTATION_TEXT } from '../../constants';
2717
import { PayloadType } from '../../types';
28-
import { ConfigInterface } from '../../config/config';
18+
2919
interface Props {
3020
type: PayloadType;
3121
operation: OperationInterface;
@@ -34,8 +24,8 @@ interface Props {
3424
}
3525

3626
export const Operation: React.FunctionComponent<Props> = props => {
37-
const config = useConfig();
3827
const { type = PayloadType.SEND, operation, channelName, channel } = props;
28+
const config = useConfig();
3929
if (!operation || !channel) {
4030
return null;
4131
}
@@ -178,61 +168,22 @@ export const Operation: React.FunctionComponent<Props> = props => {
178168
);
179169
};
180170

181-
function getTypeInformation({
182-
typeRes = PayloadType.SEND,
183-
config,
184-
version,
185-
}: {
186-
typeRes: PayloadType;
187-
config: ConfigInterface;
188-
version: number;
189-
}): { borderColor: string; typeLabel: string } {
190-
if (typeRes === PayloadType.RECEIVE) {
191-
return {
192-
borderColor: 'border-green-600 text-green-600',
193-
typeLabel:
194-
version === 1
195-
? config.receiveLabel ?? RECEIVE_TEXT_LABEL_DEFAULT_TEXT
196-
: config.publishLabel ?? PUBLISH_LABEL_DEFAULT_TEXT,
197-
};
198-
}
199-
if (typeRes === PayloadType.REPLY) {
200-
return {
201-
borderColor: 'border-orange-600 text-orange-600',
202-
typeLabel: config.replyLabel ?? REPLIER_LABEL_DEFAULT_TEXT,
203-
};
204-
}
205-
if (typeRes === PayloadType.REQUEST) {
206-
return {
207-
borderColor: 'border-red-600 text-red-600',
208-
typeLabel: config.requestLabel ?? REQUEST_LABEL_DEFAULT_TEXT,
209-
};
210-
}
211-
return {
212-
borderColor: 'border-blue-600 text-blue-500',
213-
typeLabel:
214-
version === 1
215-
? config.sendLabel ?? SEND_LABEL_DEFAULT_TEXT
216-
: config.subscribeLabel ?? SUBSCRIBE_LABEL_DEFAULT_TEXT,
217-
};
218-
}
219-
220171
export const OperationInfo: React.FunctionComponent<Props> = props => {
221172
const { type = PayloadType.SEND, operation, channelName, channel } = props;
222-
const specV = useSpec().version();
223-
const version = specV.localeCompare('2.6.0', undefined, { numeric: true });
224173
const config = useConfig();
225174
const operationSummary = operation.summary();
226175
const externalDocs = operation.externalDocs();
227176
const operationId = operation.id();
228-
let typeRes = type;
229-
if (version === 1 && operation.action() !== typeRes) {
230-
typeRes = PayloadType.RECEIVE;
231-
}
232-
const { borderColor, typeLabel } = getTypeInformation({
233-
typeRes,
177+
const specV = useSpec().version();
178+
const version = specV.localeCompare('2.6.0', undefined, { numeric: true });
179+
const isAsyncAPIv2 = version === 0;
180+
const {
181+
borderColor,
182+
typeLabel,
183+
} = CommonHelpers.getOperationDesignInformation({
184+
type,
234185
config,
235-
version,
186+
isAsyncAPIv2,
236187
});
237188
return (
238189
<>
@@ -429,9 +380,7 @@ export const OperationReplyChannelInfo: React.FunctionComponent<Props> = ({
429380
operation,
430381
}) => {
431382
const reply = operation.reply();
432-
433383
const channel = reply?.channel();
434-
435384
const channelName = channel?.address() ?? '';
436385

437386
const config = useConfig();

library/src/containers/Operations/Operations.tsx

Lines changed: 16 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
import React from 'react';
2-
32
import { Operation } from './Operation';
43
import { useConfig, useSpec } from '../../contexts';
54
import { CommonHelpers } from '../../helpers';
65
import { OPERATIONS_TEXT } from '../../constants';
7-
import { PayloadType } from '../../types';
86

97
export const Operations: React.FunctionComponent = () => {
108
const operations = useSpec()
@@ -16,88 +14,24 @@ export const Operations: React.FunctionComponent = () => {
1614
return null;
1715
}
1816

19-
const operationsList: React.ReactNodeArray = [];
20-
operations.forEach(operation => {
17+
const operationsList: React.ReactNodeArray = operations.map(operation => {
2118
const channel = operation.channels().all()[0];
2219
const channelAddress = channel?.address() ?? '';
23-
if (operation.isSend()) {
24-
if (operation.reply() !== undefined) {
25-
operationsList.push(
26-
<li
27-
className="mb-12"
28-
key={`req-${operation.id()}`}
29-
id={CommonHelpers.getIdentifier(
30-
`operation-${PayloadType.REQUEST}-${operation.id()}`,
31-
config,
32-
)}
33-
>
34-
<Operation
35-
type={PayloadType.REQUEST}
36-
operation={operation}
37-
channelName={channelAddress}
38-
channel={channel}
39-
/>
40-
</li>,
41-
);
42-
} else {
43-
operationsList.push(
44-
<li
45-
className="mb-12"
46-
key={`pub-${operation.id()}`}
47-
id={CommonHelpers.getIdentifier(
48-
`operation-${PayloadType.SEND}-${operation.id()}`,
49-
config,
50-
)}
51-
>
52-
<Operation
53-
type={PayloadType.SEND}
54-
operation={operation}
55-
channelName={channelAddress}
56-
channel={channel}
57-
/>
58-
</li>,
59-
);
60-
}
61-
}
62-
if (operation.isReceive()) {
63-
if (operation.reply() !== undefined) {
64-
operationsList.push(
65-
<li
66-
className="mb-12"
67-
key={`replier-${operation.id()}`}
68-
id={CommonHelpers.getIdentifier(
69-
`operation-${PayloadType.REPLY}-${operation.id()}`,
70-
config,
71-
)}
72-
>
73-
<Operation
74-
type={PayloadType.REPLY}
75-
operation={operation}
76-
channelName={channelAddress}
77-
channel={channel}
78-
/>
79-
</li>,
80-
);
81-
} else {
82-
operationsList.push(
83-
<li
84-
className="mb-12"
85-
key={`sub-${operation.id()}`}
86-
id={CommonHelpers.getIdentifier(
87-
`operation-${PayloadType.RECEIVE}-${operation.id()}`,
88-
config,
89-
)}
90-
>
91-
<Operation
92-
type={PayloadType.RECEIVE}
93-
operation={operation}
94-
channelName={channelAddress}
95-
channel={channel}
96-
/>
97-
</li>,
98-
);
99-
}
100-
}
20+
const operationId = CommonHelpers.getOperationIdentifier({
21+
operation,
22+
config,
23+
});
24+
const type = CommonHelpers.getOperationType(operation);
25+
return (
26+
<li className="mb-12" key={`${type}-${operation.id()}`} id={operationId}>
27+
<Operation
28+
type={type}
29+
operation={operation}
30+
channelName={channelAddress}
31+
channel={channel}
32+
/>
33+
</li>
34+
);
10135
});
10236
return (
10337
<section

0 commit comments

Comments
 (0)