Skip to content

Commit cf066c9

Browse files
committed
Allow import traces view in extension even spoosh is not detected
1 parent dab935a commit cf066c9

5 files changed

Lines changed: 68 additions & 13 deletions

File tree

browser-extensions/chrome/src/devtools/panel.ts

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,26 @@ class ExtensionPanel {
123123

124124
this.unsubscribe = this.store.subscribe(() => {
125125
const currentState = this.store.state;
126+
const activeView = this.viewModel.getState().activeView;
126127

127128
if (currentState !== this.lastConnectionState) {
128129
this.lastConnectionState = currentState;
129130

130131
if (currentState === "not_detected") {
131-
this.showNotDetected();
132+
if (activeView === "import") {
133+
this.renderScheduler.immediate(() => this.render());
134+
} else {
135+
this.showNotDetected();
136+
}
132137
return;
133138
}
134139

135140
if (currentState === "connecting") {
136-
this.showConnecting();
141+
if (activeView === "import") {
142+
this.renderScheduler.immediate(() => this.render());
143+
} else {
144+
this.showConnecting();
145+
}
137146
return;
138147
}
139148

@@ -273,7 +282,7 @@ class ExtensionPanel {
273282
flex-direction: column;
274283
align-items: center;
275284
justify-content: center;
276-
height: 100%;
285+
flex: 1;
277286
padding: 40px;
278287
text-align: center;
279288
color: var(--spoosh-text-muted);
@@ -323,6 +332,23 @@ class ExtensionPanel {
323332
to { transform: rotate(360deg); }
324333
}
325334
335+
.spoosh-go-import-btn {
336+
margin-top: 16px;
337+
padding: 8px 16px;
338+
background: var(--spoosh-primary);
339+
color: white;
340+
border: none;
341+
border-radius: 6px;
342+
font-size: 13px;
343+
font-weight: 500;
344+
cursor: pointer;
345+
transition: opacity 0.15s;
346+
}
347+
348+
.spoosh-go-import-btn:hover {
349+
opacity: 0.9;
350+
}
351+
326352
/* Remove drag cursors in extension context */
327353
.spoosh-header,
328354
.spoosh-settings-header,
@@ -334,37 +360,47 @@ class ExtensionPanel {
334360
}
335361

336362
private showNotDetected(): void {
337-
const notDetectedHtml = `
363+
const state = this.viewModel.getState();
364+
const html = `
338365
<div class="not-detected">
339366
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
340367
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9.172 16.172a4 4 0 015.656 0M9 10h.01M15 10h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
341368
</svg>
342369
<h2>Spoosh not detected</h2>
343-
<p>This page doesn't appear to be using Spoosh, or the devtool plugin is not enabled. Make sure you have the <code>devtool()</code> plugin registered in your Spoosh instance.</p>
370+
<p>This page doesn't appear to be using Spoosh, or the devtool plugin is not enabled.</p>
371+
<button class="spoosh-go-import-btn" data-action="go-import">Go to Import View</button>
344372
</div>
373+
${renderBottomBar({ activeView: state.activeView, theme: state.theme })}
345374
`;
346375
this.container.textContent = "";
347-
this.container.insertAdjacentHTML("beforeend", notDetectedHtml);
376+
this.container.insertAdjacentHTML("beforeend", html);
377+
this.attachEvents();
348378
}
349379

350380
private showConnecting(): void {
351-
const connectingHtml = `
381+
const state = this.viewModel.getState();
382+
const html = `
352383
<div class="not-detected connecting">
353384
<div class="connecting-spinner"></div>
354385
<h2>Connecting...</h2>
355386
<p>Waiting for Spoosh to initialize on this page.</p>
356387
</div>
388+
${renderBottomBar({ activeView: state.activeView, theme: state.theme })}
357389
`;
358390
this.container.textContent = "";
359-
this.container.insertAdjacentHTML("beforeend", connectingHtml);
391+
this.container.insertAdjacentHTML("beforeend", html);
392+
this.attachEvents();
360393
}
361394

362395
private renderImmediate(): void {
363396
this.renderScheduler.immediate(() => this.render());
364397
}
365398

366399
private render(): void {
367-
if (this.store.state !== "connected") {
400+
const state = this.viewModel.getState();
401+
const isConnected = this.store.state === "connected";
402+
403+
if (!isConnected && state.activeView !== "import") {
368404
if (this.store.state === "connecting") {
369405
this.showConnecting();
370406
} else {
@@ -373,9 +409,10 @@ class ExtensionPanel {
373409
return;
374410
}
375411

376-
this.autoSelectFirst();
412+
if (isConnected) {
413+
this.autoSelectFirst();
414+
}
377415

378-
const state = this.viewModel.getState();
379416
this.lastRenderedTraceId = state.selectedTraceId;
380417
this.lastRenderedStateKey = state.selectedStateKey;
381418
this.lastRenderedInternalTab = state.internalTab;

browser-extensions/chrome/src/devtools/remote-store.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,12 @@ export class RemoteStore implements DevToolStoreInterface {
600600
}
601601

602602
importTraces(data: ExportedItem[], filename: string): void {
603-
this.sendCommand({ type: "IMPORT_TRACES", payload: { data, filename } });
603+
this.importedSession = {
604+
filename,
605+
items: data,
606+
importedAt: Date.now(),
607+
};
608+
this.notify();
604609
}
605610

606611
getImportedSession(): ImportedSession | null {

packages/devtool/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# @spoosh/devtool
22

3+
## 0.7.2
4+
5+
- Fix import traces not working properly for extension
6+
37
## 0.7.1
48

59
- Improve devtool indentation for diff view to enhance readability

packages/devtool/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@spoosh/devtool",
3-
"version": "0.7.1",
3+
"version": "0.7.2",
44
"description": "Visual debugging plugin for Spoosh - floating devtool panel with plugin execution visualization",
55
"license": "MIT",
66
"repository": {

packages/devtool/src/ui/action-router.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export type ActionIntent =
3939
| { type: "delete-state"; key: string }
4040
| { type: "clear-all-state" }
4141
| { type: "import-file" }
42+
| { type: "go-import" }
4243
| { type: "select-imported-trace"; traceId: string }
4344
| { type: "clear-imports" }
4445
| { type: "import-search"; query: string }
@@ -197,6 +198,10 @@ export function createActionRouter(
197198
return { type: "import-file" };
198199
}
199200

201+
if (action === "go-import") {
202+
return { type: "go-import" };
203+
}
204+
200205
if (action === "clear-imports") {
201206
return { type: "clear-imports" };
202207
}
@@ -501,6 +506,10 @@ export function createActionRouter(
501506
onImportFile?.();
502507
return;
503508

509+
case "go-import":
510+
viewModel.setActiveView("import");
511+
break;
512+
504513
case "select-imported-trace":
505514
viewModel.selectImportedTrace(intent.traceId);
506515
break;

0 commit comments

Comments
 (0)