Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show operation summary on sidebar #595

Merged
merged 5 commits into from
Jan 31, 2023
Merged
Changes from all 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
27 changes: 16 additions & 11 deletions library/src/containers/Sidebar/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,30 +283,33 @@ const OperationsList: React.FunctionComponent = () => {

const operations: Array<TagObject<{
channelName: string;
summary: string;
kind: 'publish' | 'subscribe';
}>> = [];
Object.entries(channels).forEach(([channelName, channel]) => {
if (channel.hasPublish()) {
const operation = channel.publish();
operations.push({
name: `publish-${channelName}`,
object: channel.publish(),
data: { channelName, kind: 'publish' },
object: operation,
data: { channelName, kind: 'publish', summary: operation.summary() },
});
}
if (channel.hasSubscribe()) {
const operation = channel.subscribe();
operations.push({
name: `subscribe-${channelName}`,
object: channel.subscribe(),
data: { channelName, kind: 'subscribe' },
object: operation,
data: { channelName, kind: 'subscribe', summary: operation.summary() },
});
}
});

if (showOperations === 'byDefault') {
return (
<ul className="text-sm mt-2">
{operations.map(({ name, data: { channelName, kind } }) => (
<OperationItem channelName={channelName} kind={kind} key={name} />
{operations.map(({ name, data }) => (
<OperationItem key={name} {...data} />
))}
</ul>
);
Expand Down Expand Up @@ -335,17 +338,17 @@ const OperationsList: React.FunctionComponent = () => {
{Array.from(tagged.entries()).map(([tag, taggedOperations]) => (
<li key={tag}>
<ItemsByTagItem tagName={tag}>
{taggedOperations.map(({ name, data: { kind, channelName } }) => (
<OperationItem channelName={channelName} kind={kind} key={name} />
{taggedOperations.map(({ name, data }) => (
<OperationItem key={name} {...data} />
))}
</ItemsByTagItem>
</li>
))}
{untagged.length > 0 ? (
<li>
<ItemsByTagItem tagName="Untagged">
{untagged.map(({ name, data: { kind, channelName } }) => (
<OperationItem channelName={channelName} kind={kind} key={name} />
{untagged.map(({ name, data }) => (
<OperationItem key={name} {...data} />
))}
</ItemsByTagItem>
</li>
Expand All @@ -356,11 +359,13 @@ const OperationsList: React.FunctionComponent = () => {

interface OperationItemProps {
channelName: string;
summary: string;
kind: 'publish' | 'subscribe';
}

const OperationItem: React.FunctionComponent<OperationItemProps> = ({
channelName,
summary,
kind,
}) => {
const config = useConfig();
Expand Down Expand Up @@ -389,7 +394,7 @@ const OperationItem: React.FunctionComponent<OperationItemProps> = ({
>
{label}
</span>
<span className="break-all inline-block">{channelName}</span>
<span className="break-all inline-block">{summary || channelName}</span>
</a>
</li>
);
Expand Down