Skip to content

Commit d40e045

Browse files
populate data into UI
1 parent 65573f6 commit d40e045

File tree

15 files changed

+182
-108
lines changed

15 files changed

+182
-108
lines changed

packages/app/src/components/browser/snapshot.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ const COMPONENT = 'wdio-devtools-browser'
3636
@customElement(COMPONENT)
3737
export class DevtoolsBrowser extends Element {
3838
#vdom = document.createDocumentFragment()
39-
#activeUrl = ''
39+
#activeUrl?: string
4040

41-
@consume({ context: metadataContext })
41+
@consume({ context: metadataContext, subscribe: true })
4242
metadata: Metadata | undefined = undefined
4343

44-
@consume({ context: mutationContext })
44+
@consume({ context: mutationContext, subscribe: true })
4545
mutations: TraceMutation[] = []
4646

4747
static styles = [...Element.styles, css`
@@ -79,12 +79,6 @@ export class DevtoolsBrowser extends Element {
7979
window.addEventListener('app-mutation-highlight', this.#highlightMutation.bind(this))
8080
window.addEventListener('app-mutation-select', (ev) => this.#renderBrowserState(ev.detail))
8181
await this.updateComplete
82-
this.#setIframeSize()
83-
84-
/**
85-
* Render initial document
86-
*/
87-
this.#renderBrowserState()
8882
}
8983

9084
#setIframeSize () {
@@ -258,7 +252,7 @@ export class DevtoolsBrowser extends Element {
258252

259253
async #renderBrowserState (mutationEntry?: TraceMutation) {
260254
const mutations = this.mutations
261-
if (!mutations) {
255+
if (!mutations || !mutations.length) {
262256
return
263257
}
264258

@@ -298,6 +292,14 @@ export class DevtoolsBrowser extends Element {
298292
}
299293

300294
render() {
295+
/**
296+
* render a browser state if it hasn't before
297+
*/
298+
if (this.mutations && this.mutations.length && !this.#activeUrl) {
299+
this.#setIframeSize()
300+
this.#renderBrowserState()
301+
}
302+
301303
return html`
302304
<section class="w-full bg-sideBarBackground rounded-t-md shadow-md">
303305
<header class="flex block mx-2">
@@ -309,7 +311,7 @@ export class DevtoolsBrowser extends Element {
309311
${this.#activeUrl}
310312
</div>
311313
</header>
312-
${this.mutations
314+
${this.mutations && this.mutations.length
313315
? html`<iframe class="origin-top-left"></iframe>`
314316
: html`<wdio-devtools-placeholder style="height: 100%"></wdio-devtools-placeholder>`
315317
}

packages/app/src/components/sidebar/explorer.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Element } from '@core/element'
22
import { html, css, nothing, type TemplateResult } from 'lit'
33
import { customElement } from 'lit/decorators.js'
44
import { consume } from '@lit/context'
5-
import { type SuiteStats } from '@wdio/reporter'
5+
import type { TestStats, SuiteStats } from '@wdio/reporter'
66

77
import { TestState } from './test-suite.js'
88
import { suiteContext } from '../../controller/DataManager.js'
@@ -36,8 +36,8 @@ export class DevtoolsSidebarExplorer extends CollapseableEntry {
3636
}
3737
`]
3838

39-
@consume({ context: suiteContext })
40-
suites: Record<string, SuiteStats> = {}
39+
@consume({ context: suiteContext, subscribe: true })
40+
suites: Record<string, SuiteStats>[] | undefined = undefined
4141

4242
connectedCallback(): void {
4343
super.connectedCallback()
@@ -84,31 +84,39 @@ export class DevtoolsSidebarExplorer extends CollapseableEntry {
8484
)
8585
}
8686

87-
render() {
88-
if (typeof this.suites !== 'object') {
89-
return
87+
#getTestEntry (entry: TestStats | SuiteStats): TestEntry {
88+
if ('tests' in entry) {
89+
const entries = [...entry.tests, ...entry.suites]
90+
return {
91+
label: entry.title,
92+
state: entry.tests.some((t) => !t.end)
93+
? TestState.RUNNING
94+
: entry.tests.find((t) => t.state === 'failed')
95+
? TestState.FAILED
96+
: TestState.PASSED,
97+
children: Object.values(entries)
98+
.map(this.#getTestEntry.bind(this))
99+
.filter(this.#filterEntry.bind(this))
100+
}
90101
}
91-
const suites = Object.values(this.suites[0]).map((suite: SuiteStats) => {
92-
const state = !suite.tests.find((t) => t.end)
102+
return {
103+
label: entry.title,
104+
state: !entry.end
93105
? TestState.RUNNING
94-
: suite.tests.find((t) => t.state === 'failed')
106+
: entry.state === 'failed'
95107
? TestState.FAILED
96-
: TestState.PASSED
108+
: TestState.PASSED,
109+
children: []
110+
}
111+
}
97112

98-
return {
99-
label: suite.title,
100-
state,
101-
children: Object.values(suite.tests).map((test) => ({
102-
label: test.title,
103-
state: !test.end
104-
? TestState.RUNNING
105-
: test.state === 'failed'
106-
? TestState.FAILED
107-
: TestState.PASSED,
108-
children: []
109-
})).filter(this.#filterEntry.bind(this))
110-
}
111-
}).filter(this.#filterEntry.bind(this))
113+
render() {
114+
if (!this.suites) {
115+
return
116+
}
117+
const suites = Object.values(this.suites[0])
118+
.map(this.#getTestEntry.bind(this))
119+
.filter(this.#filterEntry.bind(this))
112120

113121
return html`
114122
<header class="pl-4 py-2 flex shadow-md pr-2">

packages/app/src/components/sidebar/test-suite.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const TEST_ENTRY = 'wdio-test-entry'
4343
@customElement(TEST_ENTRY)
4444
export class ExplorerTestEntry extends CollapseableEntry {
4545
@property({ attribute: 'is-collapsed' })
46-
isCollapsed = 'true'
46+
isCollapsed = 'false'
4747

4848
@property({ type: String })
4949
state?: TestState

packages/app/src/components/workbench/actions.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { customElement } from 'lit/decorators.js'
44
import { consume } from '@lit/context'
55

66
import { mutationContext, type TraceMutation, commandContext, type CommandLog } from '../../controller/DataManager.js'
7-
import { type ActionEntry } from './actionItems/item.js'
87

98
import '~icons/mdi/pencil.js'
109
import '~icons/mdi/family-tree.js'
@@ -20,8 +19,6 @@ const SOURCE_COMPONENT = 'wdio-devtools-actions'
2019

2120
@customElement(SOURCE_COMPONENT)
2221
export class DevtoolsActions extends Element {
23-
#entries: ActionEntry[] = []
24-
2522
static styles = [...Element.styles, css`
2623
:host {
2724
display: flex;
@@ -30,25 +27,23 @@ export class DevtoolsActions extends Element {
3027
}
3128
`]
3229

33-
@consume({ context: mutationContext })
30+
@consume({ context: mutationContext, subscribe: true })
3431
mutations: TraceMutation[] = []
3532

36-
@consume({ context: commandContext })
33+
@consume({ context: commandContext, subscribe: true })
3734
commands: CommandLog[] = []
3835

39-
connectedCallback(): void {
40-
super.connectedCallback()
41-
this.#entries = [...this.mutations || [], ...this.commands || []]
42-
.sort((a, b) => a.timestamp - b.timestamp)
43-
}
44-
4536
render() {
4637
const mutations = this.mutations || []
47-
if (!this.#entries.length || !mutations.length) {
38+
const commands = this.commands || []
39+
const entries = [...mutations, ...commands]
40+
.sort((a, b) => a.timestamp - b.timestamp)
41+
42+
if (!entries.length || !mutations.length) {
4843
return html`<wdio-devtools-placeholder></wdio-devtools-placeholder>`
4944
}
5045

51-
return this.#entries.map((entry) => {
46+
return entries.map((entry) => {
5247
const elapsedTime = entry.timestamp - mutations[0].timestamp
5348

5449
if ('command' in entry) {

packages/app/src/components/workbench/console.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/// <reference types="../../../script" />
22

33
import { Element } from '@core/element'
4-
import { html, css } from 'lit'
4+
import { html, css, nothing } from 'lit'
55
import { customElement } from 'lit/decorators.js'
66
import { consume } from '@lit/context'
77

@@ -27,23 +27,28 @@ export class DevtoolsConsoleLogs extends Element {
2727
height: 100%;
2828
flex-direction: column;
2929
padding: 5px;
30+
min-height: 200px;
3031
}
3132
`]
3233

33-
@consume({ context: consoleLogContext })
34-
logs: Partial<ConsoleLogs> = {}
34+
@consume({ context: consoleLogContext, subscribe: true })
35+
logs: ConsoleLogs[] | undefined = undefined
3536

3637
render() {
37-
if (!this.logs || this.logs.length === 0) {
38+
if (!this.logs) {
3839
return html`<wdio-devtools-placeholder></wdio-devtools-placeholder>`
3940
}
4041

42+
const logs = this.logs.length === 0
43+
? [{ args: '' }]
44+
: this.logs
45+
4146
return html`
42-
${Object.values(this.logs).map((log: any) => html`
47+
${Object.values(logs).map((log: any) => html`
4348
<dl class="w-full flex grow-0">
4449
<dt class="flex">
4550
<icon-mdi-chevron-right class="text-base transition-transform block"></icon-mdi-chevron-right>
46-
<span class="block bg-${BG[log.type]} rounded text-sm py-[1px] px-[5px] my-1">${log.type}</span>
51+
${log.type ? html`<span class="block bg-${BG[log.type]} rounded text-sm py-[1px] px-[5px] my-1">${log.type}</span>` : nothing}
4752
</dt>
4853
<dd class="flex justify-center items-center mx-2">${log.args}</dd>
4954
</dl>

packages/app/src/components/workbench/logs.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export class DevtoolsSource extends Element {
2323
display: block;
2424
width: 100%;
2525
height: 100%;
26+
min-height: 200px;
2627
}
2728
`]
2829

@@ -53,7 +54,11 @@ export class DevtoolsSource extends Element {
5354

5455
render() {
5556
if (!this.command) {
56-
return html`<section class="flex items-center justify-center text-sm w-full h-full">Please select a command to view details!</section>`
57+
return html`
58+
<section class="flex items-center justify-center text-sm w-full h-full">
59+
Please select a command to view details!
60+
</section>
61+
`
5762
}
5863

5964
return html`

packages/app/src/components/workbench/metadata.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import '~icons/mdi/chevron-right.js'
1212
const SOURCE_COMPONENT = 'wdio-devtools-metadata'
1313
@customElement(SOURCE_COMPONENT)
1414
export class DevtoolsMetadata extends Element {
15-
@consume({ context: metadataContext })
16-
metadata: Partial<Metadata> = {}
15+
@consume({ context: metadataContext, subscribe: true })
16+
metadata: Partial<Metadata> | undefined = undefined
1717

1818
static styles = [...Element.styles, css`
1919
:host {

packages/app/src/components/workbench/source.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,12 @@ export class DevtoolsSource extends Element {
3131
}
3232
`]
3333

34-
@consume({ context: sourceContext })
34+
@consume({ context: sourceContext, subscribe: true })
3535
sources: Record<string, string> = {}
3636

3737
connectedCallback(): void {
3838
super.connectedCallback()
3939
window.addEventListener('app-source-highlight', this.#highlightCallSource.bind(this))
40-
setTimeout(() => this.#renderEditor(Object.keys(this.sources || {})[0]))
4140
}
4241

4342
#renderEditor (filePath: string, highlightLine?: number) {
@@ -81,8 +80,14 @@ export class DevtoolsSource extends Element {
8180
}
8281

8382
render() {
83+
const sourceFileNames = Object.keys(this.sources || {})
84+
if (sourceFileNames.length === 0) {
85+
return html`<wdio-devtools-placeholder></wdio-devtools-placeholder>`
86+
}
87+
88+
this.#renderEditor(sourceFileNames[0])
8489
return html`
85-
<wdio-devtools-placeholder></wdio-devtools-placeholder>
90+
<section class="p-2">loading...</section>
8691
`
8792
}
8893
}

0 commit comments

Comments
 (0)