Skip to content

Commit 38a42bb

Browse files
authored
feat(hub): open in editor, dock group, messages and badges, and mcp --print-config (#378)
Refs #340.
1 parent 832a5a8 commit 38a42bb

47 files changed

Lines changed: 2685 additions & 166 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎app/src/__tests__/full-panel-link.test.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ const capacitorPage = {
3333
dropped: 0,
3434
};
3535

36-
function fakeClient(capacitorPages: Record<string, unknown>) {
36+
function fakeClient(capacitorPages: Record<string, unknown>, calls: unknown[][] = []) {
3737
const rpc = {
38-
call: () => new Promise(() => {}),
38+
call: (...args: unknown[]) => {
39+
calls.push(args);
40+
return new Promise(() => {});
41+
},
3942
callEvent: () => Promise.resolve(),
4043
sharedState: (name: string) =>
4144
Promise.resolve(
@@ -82,11 +85,15 @@ async function settle(fixture: ComponentFixture<unknown>) {
8285
}
8386
}
8487

85-
async function open(path: string, capacitorPages: Record<string, unknown> = {}) {
88+
async function open(
89+
path: string,
90+
capacitorPages: Record<string, unknown> = {},
91+
calls: unknown[][] = [],
92+
) {
8693
history.replaceState(null, '', path);
8794
const fixture = TestBed.createComponent(App);
8895
await settle(fixture);
89-
connection.resolve(fakeClient(capacitorPages));
96+
connection.resolve(fakeClient(capacitorPages, calls));
9097
await settle(fixture);
9198
return { fixture, el: fixture.nativeElement as HTMLElement };
9299
}
@@ -177,6 +184,22 @@ describe('Hub rail and the full panel', () => {
177184
});
178185
});
179186

187+
describe('Hub dock badges', () => {
188+
it('tells the server which dock is open, on load and on each switch, to clear its count', async () => {
189+
const hub = fakeHub('pangular:ngrx');
190+
const calls: unknown[][] = [];
191+
const { fixture } = await open(`${BASE}?view=ngrx`, {}, calls);
192+
const seen = () => calls.filter(([name]) => name === 'hub-dock-seen').map(([, dock]) => dock);
193+
expect(seen()).toEqual(['pangular:ngrx']);
194+
195+
await hub.activate('pangular:all');
196+
await settle(fixture);
197+
await hub.activate('pangular:all');
198+
await settle(fixture);
199+
expect(seen()).toEqual(['pangular:ngrx', 'pangular:all', 'pangular:all']);
200+
});
201+
});
202+
180203
describe('fullPanelHref', () => {
181204
it('drops the view and sets or clears the tab', () => {
182205
expect(fullPanelHref(`http://localhost${BASE}?view=ngrx#tab=store`, 'store')).toBe(

‎app/src/__tests__/hub-rail-style.test.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ describe('styleHubRail', () => {
5555
expect(styleTags[0].textContent).toContain('#ffffff');
5656
});
5757

58+
it('dims the icon of an inactive dock but not its badge, and darkens the badge palette', () => {
59+
makeDock();
60+
styleHubRail(document, 'dark');
61+
const css = document
62+
.querySelector('devframes-dock-standalone')!
63+
.shadowRoot!.querySelector<HTMLStyleElement>('style[data-pangular]')!.textContent!;
64+
expect(css).toContain('button:not(.scale-120) > :not(.absolute)');
65+
expect(css).not.toMatch(/button:not\(\.scale-120\) \{/);
66+
expect(css).toMatch(/\[style\*="59, 130, 246"\] \{\s*background-color: #2563eb !important;/);
67+
expect(css).toMatch(/\[style\*="239, 68, 68"\] \{\s*background-color: #dc2626 !important;/);
68+
});
69+
5870
it('retries when the shadow host is not yet in the DOM', () => {
5971
vi.useFakeTimers();
6072
styleHubRail(document, 'dark');
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { Component, signal } from '@angular/core';
2+
import { TestBed } from '@angular/core/testing';
3+
import type { DevframeRpcClient } from 'devframe/client';
4+
import { afterEach, describe, expect, it, vi } from 'vitest';
5+
import { EditorOpener, SourceLink } from '../ui/source-link';
6+
7+
@Component({
8+
imports: [SourceLink],
9+
template: `
10+
<p class="plain"><app-source-link file="src/app/app.ts" [line]="12" /></p>
11+
<p class="custom">
12+
<app-source-link file="/src/app/pages/index.page.ts"
13+
><span class="dir">pages/</span>index.page.ts</app-source-link
14+
>
15+
</p>
16+
`,
17+
})
18+
class Host {}
19+
20+
function client(answer: unknown, backend = 'websocket') {
21+
const call = vi.fn(async () => answer);
22+
const fake = {
23+
connectionMeta: { backend, configs: {} },
24+
scope: () => ({ rpc: { call } }),
25+
} as unknown as DevframeRpcClient;
26+
return { fake, call };
27+
}
28+
29+
async function render(rpc: DevframeRpcClient | null) {
30+
TestBed.inject(EditorOpener).use(signal(rpc));
31+
const fixture = TestBed.createComponent(Host);
32+
await fixture.whenStable();
33+
return fixture.nativeElement as HTMLElement;
34+
}
35+
36+
describe('SourceLink', () => {
37+
afterEach(() => TestBed.resetTestingModule());
38+
39+
it('shows plain text when no server is connected', async () => {
40+
const el = await render(null);
41+
expect(el.querySelector('button')).toBeNull();
42+
expect(el.querySelector('[role="alert"], [role="status"]')).toBeNull();
43+
expect(el.querySelector('.plain')!.textContent!.trim()).toBe('src/app/app.ts:12');
44+
expect(el.querySelector('.custom')!.textContent!.trim()).toBe('pages/index.page.ts');
45+
});
46+
47+
it('shows plain text in a static report', async () => {
48+
const el = await render(client({ ok: true }, 'static').fake);
49+
expect(el.querySelector('button')).toBeNull();
50+
});
51+
52+
it('is a button named after the file that opens it at its line', async () => {
53+
const { fake, call } = client({ ok: true, file: '/w/src/app/app.ts' });
54+
const el = await render(fake);
55+
const button = el.querySelector<HTMLButtonElement>('.plain button')!;
56+
expect(button.type).toBe('button');
57+
expect(button.getAttribute('aria-label')).toBe('Open src/app/app.ts:12 in your editor');
58+
expect(button.textContent!.trim()).toBe('src/app/app.ts:12');
59+
button.click();
60+
await vi.waitFor(() =>
61+
expect(call).toHaveBeenCalledWith('open-in-editor', { file: 'src/app/app.ts', line: 12 }),
62+
);
63+
expect(el.querySelector('[role="alert"], [role="status"]')).toBeNull();
64+
});
65+
66+
it('keeps projected text, whose words are part of the accessible name', async () => {
67+
const { fake, call } = client({ ok: true });
68+
const el = await render(fake);
69+
const button = el.querySelector<HTMLButtonElement>('.custom button')!;
70+
expect(button.textContent!.trim()).toBe('pages/index.page.ts');
71+
expect(button.getAttribute('aria-label')).toContain('pages/index.page.ts');
72+
button.click();
73+
await vi.waitFor(() =>
74+
expect(call).toHaveBeenCalledWith('open-in-editor', {
75+
file: '/src/app/pages/index.page.ts',
76+
}),
77+
);
78+
});
79+
80+
it('says why the server did not open it', async () => {
81+
const { fake } = client({ ok: false, error: 'src/app/app.ts is outside the project root.' });
82+
const el = await render(fake);
83+
el.querySelector<HTMLButtonElement>('.plain button')!.click();
84+
expect(TestBed.inject(EditorOpener).available()).toBe(true);
85+
await vi.waitFor(() => {
86+
TestBed.tick();
87+
expect(el.querySelector('.plain [role="alert"]')!.textContent).toBe(
88+
'Not opened: src/app/app.ts is outside the project root.',
89+
);
90+
});
91+
});
92+
93+
it('reports a server without the RPC', async () => {
94+
const fake = {
95+
connectionMeta: { backend: 'websocket', configs: {} },
96+
scope: () => ({ rpc: { call: async () => Promise.reject(new Error('unknown')) } }),
97+
} as unknown as DevframeRpcClient;
98+
TestBed.inject(EditorOpener).use(signal(fake));
99+
expect(await TestBed.inject(EditorOpener).open('a.ts', 1)).toEqual({
100+
ok: false,
101+
error: 'The server did not open it.',
102+
});
103+
});
104+
});

‎app/src/app.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ import { hostPageId, scopeToPage } from './page-id';
4040
import { angularNativePage, type PlatformPage } from './native-page';
4141
import { initialTab, storeTab, storedTab } from './tab-memory';
4242
import { detectBaseURL } from './base-url';
43-
import { clearHighlightsOnHide } from './rpc';
43+
import { clearHighlightsOnHide, rpcTry } from './rpc';
44+
import { EditorOpener } from './ui/source-link';
4445
import { viewAccent } from './view-accents';
4546
import {
4647
HUB_ALL_TOOLS,
@@ -992,6 +993,8 @@ export class App implements OnInit, OnDestroy {
992993
return (view && (VIEW_TAB[view] ?? VIEW_TABS[view]?.[0])) || 'dashboard';
993994
});
994995
rpc = signal<DevframeRpcClient | null>(null);
996+
/** The hub dock opened last, a new object each time, so opening it again counts. */
997+
private readonly openedDock = signal<{ dock: string } | null>(null);
995998
connected = signal(false);
996999
readonly connectionFailed = signal(false);
9971000
private readonly hiddenPages = signal<string[]>([]);
@@ -1020,6 +1023,7 @@ export class App implements OnInit, OnDestroy {
10201023
readonly navFade = signal({ start: false, end: false });
10211024

10221025
constructor() {
1026+
inject(EditorOpener).use(this.rpc);
10231027
afterNextRender(() => {
10241028
const nav = this.nav()?.nativeElement;
10251029
if (!nav || typeof ResizeObserver === 'undefined') return;
@@ -1034,6 +1038,13 @@ export class App implements OnInit, OnDestroy {
10341038
this.measureNav();
10351039
});
10361040
});
1041+
// Opening a dock clears the count of unseen messages on it.
1042+
effect(() => {
1043+
const opened = this.openedDock();
1044+
const client = this.rpc();
1045+
if (!opened || !client) return;
1046+
untracked(() => void rpcTry(client, 'hub-dock-seen', hubDockId(opened.dock)));
1047+
});
10371048
effect(() => {
10381049
const theme = this.themeService.current();
10391050
untracked(() => {
@@ -1070,9 +1081,11 @@ export class App implements OnInit, OnDestroy {
10701081
ngOnInit() {
10711082
// The views and the full panel share one hub frame, so whichever loaded
10721083
// first follows the rail.
1073-
this.stopFollowing = followHubDocks(HUB_DOCKS, (dock) =>
1074-
dock === ALL_TOOLS ? this.showFullPanel() : this.showView(dock),
1075-
);
1084+
this.stopFollowing = followHubDocks(HUB_DOCKS, (dock) => {
1085+
this.openedDock.set({ dock });
1086+
if (dock === ALL_TOOLS) this.showFullPanel();
1087+
else this.showView(dock);
1088+
});
10761089
const restored = initialTab(
10771090
location.hash,
10781091
storedTab(this.tabScope()),

‎app/src/hub-rail-style.ts‎

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,38 @@ function activeDockStyle(theme: 'dark' | 'light'): string {
55
const accentGlow = theme === 'light' ? 'rgba(146, 64, 14, 0.50)' : 'rgba(245, 165, 36, 0.60)';
66
return `
77
.devframes-dock-entry button {
8-
transition: opacity 0.2s, filter 0.2s, background-color 0.2s, transform 0.3s;
8+
transition: background-color 0.2s, transform 0.3s;
99
}
10-
.devframes-dock-entry button:not(.scale-120) {
10+
/* Dim the icon of an inactive dock, never its badge, so the count keeps
11+
its contrast. hub-ui's own dim classes would fade the whole button. */
12+
.devframes-dock-entry button.op50,
13+
.devframes-dock-entry button.saturate-0 {
14+
opacity: 1;
15+
filter: none;
16+
}
17+
.devframes-dock-entry button > * {
18+
transition: opacity 0.2s, filter 0.2s;
19+
}
20+
.devframes-dock-entry button:not(.scale-120) > :not(.absolute) {
1121
opacity: 0.45;
1222
filter: saturate(0);
1323
}
14-
.devframes-dock-entry button:not(.scale-120):hover,
15-
.devframes-dock-entry button:not(.scale-120):focus-visible {
24+
.devframes-dock-entry button:not(.scale-120):hover > :not(.absolute),
25+
.devframes-dock-entry button:not(.scale-120):focus-visible > :not(.absolute) {
1626
opacity: 1;
1727
filter: none;
1828
}
29+
/* hub-ui's badge palette (blue-500 and red-500 on a pale tint) is below
30+
4.5:1, and it sets the colors inline, hence the attribute selectors and
31+
!important. blue-600 and red-600 with white text pass. */
32+
.devframes-dock-entry .absolute[style*="59, 130, 246"] {
33+
background-color: #2563eb !important;
34+
color: #ffffff !important;
35+
}
36+
.devframes-dock-entry .absolute[style*="239, 68, 68"] {
37+
background-color: #dc2626 !important;
38+
color: #ffffff !important;
39+
}
1940
.devframes-dock-entry button:focus-visible {
2041
outline: 2px solid ${accent};
2142
outline-offset: 2px;
@@ -30,7 +51,8 @@ function activeDockStyle(theme: 'dark' | 'light'): string {
3051
color-scheme: ${theme};
3152
}
3253
@media (prefers-reduced-motion: reduce) {
33-
.devframes-dock-entry button {
54+
.devframes-dock-entry button,
55+
.devframes-dock-entry button > * {
3456
transition: none;
3557
}
3658
}

0 commit comments

Comments
 (0)