Skip to content

Commit 78000c8

Browse files
constantantclaude
andcommitted
fix(openapi-resource-mocks): emit reloading event and fix reload control routing
- Add reloading variant to MockEvent union so the bus can emit it - Window entry reload() now emits the reloading event after a successful reload, so DevTools panel history shows the reloading transition immediately instead of waiting for the 120ms get-state poll - DOM control handler 'reload' now routes through the window entry (same as simulateProgress) so the emit closure fires correctly feat(devtools-panel): surface requestCount, sync clearHistory, add reload button - Add requestCount to MockState so the panel tracks request counts from getState() snapshots - applyEvent reloading now also clears the error field, matching ref behaviour - bridge.clearHistory() now posts a clearHistory control to the page bus so panel history and window bus history stay in sync - Add Reload button to mock-table action column: keeps current value, sets status to reloading - Update shared/types.ts in the extension to include requestCount in MockState and missing fields in the mock-event message type Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 959c2fc commit 78000c8

6 files changed

Lines changed: 14 additions & 4 deletions

File tree

apps/devtools-panel/src/app/components/mock-table/mock-table.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
[class.catch-active]="row.catchMode"
5353
[matTooltip]="row.catchMode ? 'Catch mode on — click to disable' : 'Enable catch mode'"
5454
(click)="bridge.setCatchMode(row.key, !row.catchMode)"></button>
55+
<button mat-icon-button matTooltip="Reload (keeps value)"
56+
(click)="bridge.sendControl(row.key, 'reload')"></button>
5557
<button mat-icon-button matTooltip="Set loading"
5658
(click)="bridge.sendControl(row.key, 'setLoading')"></button>
5759
<button mat-icon-button matTooltip="Fail"

apps/devtools-panel/src/app/mock-bridge.token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ export const MOCK_BRIDGE = new InjectionToken<MockBridge>('MOCK_BRIDGE', {
132132
next.set(key, { ...entry, history: [] });
133133
return next;
134134
});
135+
post({ type: 'control', detail: { key, action: 'clearHistory' } });
135136
},
136137
};
137138
},

apps/devtools-panel/src/app/mock-entry.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface MockState {
99
value: unknown;
1010
error: unknown;
1111
progress: { type: string; loaded: number; total?: number } | undefined;
12+
requestCount?: number;
1213
}
1314

1415
export interface HistoryEvent {
@@ -83,7 +84,7 @@ export function applyEvent(
8384
next.state = { ...entry.state, status: 'loading' };
8485
break;
8586
case 'reloading':
86-
next.state = { ...entry.state, status: 'reloading' };
87+
next.state = { ...entry.state, status: 'reloading', error: undefined };
8788
break;
8889
case 'error':
8990
next.pendingRequest = null;

tools/openapi-resource-devtools/src/shared/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export interface MockState {
33
value: unknown;
44
error: unknown;
55
progress: { type: string; loaded: number; total?: number } | undefined;
6+
requestCount?: number;
67
}
78

89
export interface MockEntry {
@@ -16,7 +17,7 @@ export interface MockEntry {
1617
export type PanelMessage =
1718
| { type: 'mock-keys'; keys: string[] }
1819
| { type: 'mock-state'; key: string; state: MockState }
19-
| { type: 'mock-event'; key: string; event: { type: string; value?: unknown; error?: unknown; ts: number } };
20+
| { type: 'mock-event'; key: string; event: { type: string; value?: unknown; error?: unknown; args?: unknown[]; requestId?: string; ts: number } };
2021

2122
/** Messages sent from the panel → background → content script. */
2223
export type ContentMessage =

tools/openapi-resource-mocks/src/lib/mock-events.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type MockEvent =
33
| { type: 'caught'; args: unknown[]; requestId: string; ts: number }
44
| { type: 'resolve'; value: unknown; ts: number }
55
| { type: 'loading'; ts: number }
6+
| { type: 'reloading'; ts: number }
67
| { type: 'error'; error: unknown; ts: number }
78
| { type: 'reset'; ts: number }
89
| { type: 'progress'; progressType: 'upload' | 'download'; loaded: number; total?: number; ts: number };

tools/openapi-resource-mocks/src/lib/mock-resource-bus.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ export class MockResourceBus {
106106
setLoading: () => { ref.setLoading(); emit({ type: 'loading', ts: Date.now() }); },
107107
fail: (e) => { ref.fail(e); emit({ type: 'error', error: e, ts: Date.now() }); },
108108
reset: () => { ref.reset(); emit({ type: 'reset', ts: Date.now() }); },
109-
reload: () => ref.reload(),
109+
reload: () => {
110+
const result = ref.reload();
111+
if (result) emit({ type: 'reloading', ts: Date.now() });
112+
return result;
113+
},
110114
setProgress: (pt, l, t) => {
111115
ref.setProgress(pt, l, t);
112116
emit({ type: 'progress', progressType: pt, loaded: l, total: t, ts: Date.now() });
@@ -191,7 +195,7 @@ export class MockResourceBus {
191195
case 'resolveAfter': ref.resolveAfter(detail.delayMs ?? 0, detail.value); break;
192196
case 'setLoading': ref.setLoading(); break;
193197
case 'fail': ref.fail(detail.value); break;
194-
case 'reload': ref.reload(); break;
198+
case 'reload': window.__openApiMocks__?.[detail.key]?.reload(); break;
195199
case 'reset': {
196200
ref.reset();
197201
// If catch mode is still on, immediately re-intercept the resource.

0 commit comments

Comments
 (0)