Skip to content

Commit bc722f9

Browse files
authored
Merge pull request #51 from advanced-rest-client/W-18562610/fix-design-to-agent-support
W-18562610 Enhance ApiSummary component by adding an agent pill for endpoints wi…
2 parents c8f569c + eec9028 commit bc722f9

File tree

5 files changed

+54
-126
lines changed

5 files changed

+54
-126
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@api-components/api-summary",
33
"description": "A summary view for an API base on AMF data model",
4-
"version": "4.6.10",
4+
"version": "4.6.11",
55
"license": "Apache-2.0",
66
"main": "index.js",
77
"module": "index.js",

src/ApiSummary.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -628,18 +628,22 @@ export class ApiSummary extends AmfHelperMixin(LitElement) {
628628
return html`
629629
<a
630630
href="#${`${endpoint.path}/${item.method}`}"
631-
class="method-label ${item.hasAgent ? "method-label-with-icon" : ""}"
631+
class="method-label"
632632
data-method="${item.method}"
633633
data-id="${item.id}"
634634
data-shape-type="method"
635635
title="Open method documentation"
636-
>${item.method}
637-
${
638-
item.hasAgent
639-
? html`<arc-icon icon="codegenie" class='method-icon'></arc-icon>`
640-
: ""
641-
}
642-
</a>
636+
>${item.method}</a
637+
>
638+
639+
${item.hasAgent
640+
? html`
641+
<span class="agent-pill" title="Enabled for Agent">
642+
Enabled for Agent
643+
<arc-icon icon="infoOutline" class="info-icon"></arc-icon>
644+
</span>
645+
`
646+
: ''}
643647
`;
644648
}
645649

src/Styles.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,25 +116,11 @@ export default css`
116116
text-decoration: none;
117117
}
118118
119-
.method-label-with-icon {
120-
display: inline-flex;
121-
align-items: center;
122-
justify-content: space-between;
123-
}
124-
125119
.method-label:hover,
126120
.method-label:focus {
127121
text-decoration: underline;
128122
}
129123
130-
.method-icon {
131-
display: inline-flex;
132-
width: 14px;
133-
height: 14px;
134-
padding-left: 3px;
135-
padding-bottom: 2px;
136-
padding-left: 7px;
137-
}
138124
139125
.endpoint-path {
140126
display: block;
@@ -224,4 +210,28 @@ export default css`
224210
font-size: var(--api-summary-server-description-font-size, 12px);
225211
font-weight: var(--api-summary-server-description-font-weight, 600);
226212
}
213+
214+
.endpoint-header {
215+
display: flex;
216+
align-items: flex-start;
217+
}
218+
219+
.agent-pill {
220+
display: flex;
221+
align-items: center;
222+
padding: 2px 8px;
223+
border-radius: 16px;
224+
background-color: var(--agent-pill-background-color, #e0e0e0);
225+
color: var(--agent-pill-color, #455a64);
226+
font-size: 12px;
227+
margin-left: 8px;
228+
font-weight: 500;
229+
}
230+
231+
.info-icon {
232+
color: var(--agent-pill-info-icon-color, #757575);
233+
width: 16px;
234+
height: 16px;
235+
margin-left: 8px;
236+
}
227237
`;

test/api-summary.test.js

Lines changed: 15 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ describe('ApiSummary', () => {
1414
return fixture(html`<api-summary></api-summary>`);
1515
}
1616

17+
/**
18+
* @returns {Promise<ApiSummary>}
19+
*/
20+
async function agentFixture() {
21+
const amf = await AmfLoader.load(false, 'agents-api');
22+
return fixture(html`<api-summary .amf="${amf}"></api-summary>`);
23+
}
24+
1725
/**
1826
* @param {any} amf
1927
* @returns {Promise<ApiSummary>}
@@ -349,116 +357,22 @@ describe('ApiSummary', () => {
349357
});
350358
});
351359

352-
describe('Endpoints rendering with agents', () => {
360+
describe("Endpoints rendering with agents", () => {
353361
let element = /** @type ApiSummary */ (null);
354-
let amf;
355-
356-
before(async () => {
357-
amf = await AmfLoader.load(compact,'agents-api');
358-
});
359362

360363
beforeEach(async () => {
361-
element = await basicFixture();
362-
element.amf = amf;
364+
element = await agentFixture();
363365
await aTimeout(0);
364366
});
365367

366-
it('adds separator', () => {
367-
const node = element.shadowRoot.querySelector('.separator');
368-
assert.ok(node);
369-
});
370-
371-
it('renders all endpoints', () => {
372-
const nodes = element.shadowRoot.querySelectorAll('.endpoint-item');
368+
it("renders the list of endpoints", async () => {
369+
const nodes = element.shadowRoot.querySelectorAll(".endpoint-item");
373370
assert.lengthOf(nodes, 2);
374371
});
375372

376-
it('renders endpoint name', () => {
377-
const node = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelector('.endpoint-path');
378-
assert.dom.equal(
379-
node,
380-
`<a
381-
class="endpoint-path"
382-
data-shape-type="endpoint"
383-
href="#/reservations/reservationlookup"
384-
title="Open endpoint documentation"
385-
>
386-
/reservations/reservationlookup
387-
</a>`,
388-
{
389-
ignoreAttributes: ['data-id']
390-
}
391-
);
392-
});
393-
394-
it('sets data-id on name', () => {
395-
const node = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelector('.endpoint-path');
396-
assert.ok(node.getAttribute('data-id'));
397-
});
398-
399-
it('sets data-id on path', () => {
400-
const node = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelector('.endpoint-path');
401-
assert.ok(node.getAttribute('data-id'));
402-
});
403-
404-
it('renders list of operations', () => {
405-
const nodes = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelectorAll('.method-label');
406-
assert.lengthOf(nodes, 1);
407-
});
408-
409-
it('renders operation method', () => {
410-
const node = element.shadowRoot.querySelectorAll('.endpoint-item')[1].querySelector('.method-label');
411-
assert.dom.equal(
412-
node,
413-
`<a
414-
class="method-label method-label-with-icon"
415-
data-method="get"
416-
data-shape-type="method"
417-
href="#/reservations/reservationlookup/get"
418-
title="Open method documentation"
419-
>get
420-
<arc-icon class="method-icon" icon="codegenie"></arc-icon>
421-
</a>`,
422-
{
423-
ignoreAttributes: ['data-id']
424-
}
425-
);
426-
});
427-
428-
it('Click on an endpoint dispatches navigation event', (done) => {
429-
const node = element.shadowRoot.querySelector(`.endpoint-path[data-id]`);
430-
element.addEventListener('api-navigation-selection-changed', (e) => {
431-
// @ts-ignore
432-
const {detail} = e;
433-
assert.typeOf(detail.selected, 'string');
434-
assert.equal(detail.type, 'endpoint');
435-
done();
436-
});
437-
/** @type HTMLElement */ (node).click();
438-
});
439-
440-
it('Click on an endpoint path dispatches navigation event', (done) => {
441-
const node = element.shadowRoot.querySelector(`.endpoint-path[data-id]`);
442-
element.addEventListener('api-navigation-selection-changed', (e) => {
443-
// @ts-ignore
444-
const {detail} = e;
445-
assert.typeOf(detail.selected, 'string');
446-
assert.equal(detail.type, 'endpoint');
447-
done();
448-
});
449-
/** @type HTMLElement */ (node).click();
450-
});
451-
452-
it('Click on a method dispatches navigation event', (done) => {
453-
const node = element.shadowRoot.querySelector(`.method-label[data-id]`);
454-
element.addEventListener('api-navigation-selection-changed', (e) => {
455-
// @ts-ignore
456-
const {detail} = e;
457-
assert.typeOf(detail.selected, 'string');
458-
assert.equal(detail.type, 'method');
459-
done();
460-
});
461-
/** @type HTMLElement */ (node).click();
373+
it('renders the agent pill', async () => {
374+
const node = element.shadowRoot.querySelector('.agent-pill');
375+
assert.ok(node);
462376
});
463377
});
464378

0 commit comments

Comments
 (0)