Skip to content

Commit 147d945

Browse files
feat: show title/name of message instead index in channel spec (#156)
1 parent 9c8d80a commit 147d945

File tree

4 files changed

+36
-14
lines changed

4 files changed

+36
-14
lines changed

library/src/containers/Channels/Channel.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Parameters as ParametersComponent } from './Parameters';
66
import { Badge, BadgeType, Markdown, Toggle } from '../../components';
77
import { bemClasses, removeSpecialChars } from '../../helpers';
88
import { MESSAGE_TEXT, ITEM_LABELS, CONTAINER_LABELS } from '../../constants';
9-
import { Channel, isRawMessage, PayloadType } from '../../types';
9+
import { Channel, RawMessage, isRawMessage, PayloadType } from '../../types';
1010

1111
interface Props {
1212
name: string;
@@ -26,6 +26,10 @@ export const ChannelComponent: React.FunctionComponent<Props> = ({
2626
removeSpecialChars(name),
2727
]);
2828

29+
const message =
30+
(channel.publish && channel.publish.message) ||
31+
(channel.subscribe && channel.subscribe.message);
32+
2933
const oneOfPublish =
3034
channel.publish &&
3135
channel.publish.message &&
@@ -97,7 +101,11 @@ export const ChannelComponent: React.FunctionComponent<Props> = ({
97101
className={bemClasses.element(`${className}-operations-header`)}
98102
>
99103
<h4>
100-
<span>{MESSAGE_TEXT}</span>
104+
<span>
105+
{(message as RawMessage)?.title ||
106+
(message as RawMessage)?.name ||
107+
MESSAGE_TEXT}
108+
</span>
101109
</h4>
102110
</header>
103111
)}

library/src/containers/Messages/Message.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export const MessageComponent: React.FunctionComponent<Props> = ({
7171
);
7272
}
7373

74+
title = title || message.title || message.name;
75+
7476
const summary = message.summary && (
7577
<div className={bemClasses.element(`${className}-summary`)}>
7678
<Markdown>{message.summary}</Markdown>

library/src/containers/Messages/Messages.tsx

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { MessageComponent } from './Message';
55
import { ExpandNestedConfig } from '../../config';
66
import { bemClasses } from '../../helpers';
77
import { Toggle } from '../../components';
8-
import { Message } from '../../types';
8+
import { Message, RawMessage } from '../../types';
99
import { MESSAGES_TEXT, CONTAINER_LABELS } from '../../constants';
1010

1111
interface Props {
@@ -36,17 +36,28 @@ export const MessagesComponent: React.FunctionComponent<Props> = ({
3636
const header = <h2>{MESSAGES_TEXT}</h2>;
3737
const content = (
3838
<ul className={bemClasses.element(`${className}-list`)}>
39-
{Object.entries(messages).map(([key, message]) => (
40-
<li key={key} className={bemClasses.element(`${className}-list-item`)}>
41-
<MessageComponent
42-
title={messagesLength < 2 && inChannel ? '' : key}
43-
message={message}
44-
hideTags={true}
45-
inChannel={false}
46-
toggleExpand={expand && expand.elements}
47-
/>
48-
</li>
49-
))}
39+
{Object.entries(messages).map(([key, message]) => {
40+
const title =
41+
messagesLength < 2 && inChannel
42+
? ''
43+
: (message as RawMessage).title ||
44+
(message as RawMessage).name ||
45+
key;
46+
return (
47+
<li
48+
key={key}
49+
className={bemClasses.element(`${className}-list-item`)}
50+
>
51+
<MessageComponent
52+
title={title}
53+
message={message}
54+
hideTags={true}
55+
inChannel={false}
56+
toggleExpand={expand && expand.elements}
57+
/>
58+
</li>
59+
);
60+
})}
5061
</ul>
5162
);
5263

library/src/styles/fiori.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@
153153

154154
.asyncapi__toggle-button {
155155
border: none;
156+
background: none;
156157
height: 100%;
157158
cursor: pointer;
158159
}

0 commit comments

Comments
 (0)