Skip to content

Commit f0534e8

Browse files
committed
Complete the view-row layout for built-in APIs
1 parent c989448 commit f0534e8

File tree

7 files changed

+30
-12
lines changed

7 files changed

+30
-12
lines changed

extra-apis/ethereum.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"url": "https://creativecommons.org/publicdomain/zero/1.0/legalcode"
99
},
1010
"version": "0.0.0",
11-
"x-httptoolkit-builtin-api": true
11+
"x-httptoolkit-builtin-api": true,
12+
"x-httptoolkit-short-name": "Eth"
1213
},
1314
"servers": [
1415
{ "url": "http://localhost:8545" },

extra-apis/ipfs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"x-logo": {
99
"url": "https://raw.githubusercontent.com/ipfs/ipfs-docs/55fe8bc6a53ba3b9023951fb4b432efbbc81fba5/docs/.vuepress/public/images/ipfs-logo.svg"
1010
},
11-
"x-httptoolkit-builtin-api": true
11+
"x-httptoolkit-builtin-api": true,
12+
"x-httptoolkit-short-name": "IPFS"
1213
},
1314
"servers": [
1415
{

src/components/view/view-event-list.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ const EventRow = observer((props: EventRowProps) => {
320320
failure={event}
321321
/>;
322322
} else if (event.isHttp()) {
323-
if (event.api?.isBuiltInApi) {
323+
if (event.api?.isBuiltInApi && event.api.matchedOperation()) {
324324
return <BuiltInApiRow
325325
index={index}
326326
isSelected={isSelected}
@@ -554,9 +554,6 @@ const BuiltInApiRow = observer((p: {
554554
} = p.exchange;
555555
const api = p.exchange.api!; // Only shown for built-in APIs, so this must be set
556556

557-
// Quick hack, but it works for our only two current examples:
558-
const name = api.service.name.split(' ')[0];
559-
560557
return <TrafficEventListRow
561558
role="row"
562559
aria-label='row'
@@ -569,20 +566,27 @@ const BuiltInApiRow = observer((p: {
569566
>
570567
<RowPin pinned={pinned}/>
571568
<RowMarker category={category} title={describeEventCategory(category)} />
572-
<EventTypeColumn>{ name }</EventTypeColumn>
569+
<EventTypeColumn>
570+
{ api.service.shortName }: {
571+
_.startCase(
572+
api.operation.name
573+
.replace('eth_', '') // One-off hack for Ethereum, but result looks much nicer.
574+
)
575+
}
576+
</EventTypeColumn>
573577
<Source title={request.source.summary}>
574578
<Icon
575579
{...request.source.icon}
576580
fixedWidth={true}
577581
/>
578582
</Source>
579583
<BuiltInApiRequestDetails>
580-
{ api.operation.name }({
584+
{
581585
api.request.parameters
582-
.filter(param => param.value !== undefined)
583-
.map(param => `${param.name}=${JSON.stringify(param.value)}`)
584-
.join(', ')
585-
})
586+
.filter(param => param.value !== undefined)
587+
.map(param => `${param.name}=${JSON.stringify(param.value)}`)
588+
.join(', ')
589+
}
586590
</BuiltInApiRequestDetails>
587591
</TrafficEventListRow>
588592
});

src/model/api/api-interfaces.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface ApiExchange {
4040
}
4141

4242
export interface ApiService {
43+
readonly shortName: string;
4344
readonly name: string;
4445
readonly logoUrl?: string;
4546
readonly description?: Html;

src/model/api/jsonrpc.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,15 @@ export class JsonRpcApiService implements ApiService {
121121

122122
constructor(api: OpenRpcMetadata) {
123123
this.name = api.spec.info.title;
124+
this.shortName = api.spec.info['x-httptoolkit-short-name']
125+
?? this.name.split(' ')[0];
126+
124127
this.logoUrl = api.spec.info['x-logo']?.url;
125128
this.description = fromMarkdown(api.spec.info.description);
126129
this.docsUrl = api.spec.externalDocs?.url;
127130
}
128131

132+
readonly shortName: string;
129133
readonly name: string;
130134
readonly logoUrl?: string | undefined;
131135
readonly description?: Html | undefined;

src/model/api/openapi-schema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export const openApiSchema = {
109109
"x-httptoolkit-builtin-api": {
110110
"type": "boolean",
111111
"default": false
112+
},
113+
"x-httptoolkit-short-name": {
114+
"type": "string"
112115
}
113116
},
114117
"additionalProperties": false

src/model/api/openapi.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,15 @@ class OpenApiService implements ApiService {
318318
const { info: service } = spec;
319319

320320
this.name = service.title;
321+
this.shortName = service['x-httptoolkit-short-name']
322+
?? this.name.split(' ')[0];
323+
321324
this.logoUrl = service['x-logo']?.url;
322325
this.description = fromMarkdown(service.description);
323326
this.docsUrl = spec?.externalDocs?.url;
324327
}
325328

329+
public readonly shortName: string;
326330
public readonly name: string;
327331
public readonly logoUrl?: string;
328332
public readonly description?: Html;

0 commit comments

Comments
 (0)