-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use query-string to drive page.js #63
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,6 @@ class App extends LitElement { | |
this._fullMode = FULL_MODE.GOLDEN.value; | ||
this._layout = LAYOUTS.SPLIT.value; | ||
this._overlay = true; | ||
this._updateFiles(); | ||
} | ||
connectedCallback() { | ||
super.connectedCallback(); | ||
|
@@ -98,6 +97,13 @@ class App extends LitElement { | |
this._filterFile = undefined; | ||
this._filterTest = undefined; | ||
} | ||
if (searchParams.has('status')) { | ||
this._filterStatus = searchParams.get('status'); | ||
} | ||
if (searchParams.has('browsers')) { | ||
this._filterBrowsers = searchParams.get('browsers').split(','); | ||
} | ||
this._updateFiles(); | ||
}); | ||
page(); | ||
} | ||
|
@@ -141,24 +147,28 @@ class App extends LitElement { | |
`; | ||
} | ||
_goHome() { | ||
page(this._root); | ||
this._updateSearchParams({ file: undefined, test: undefined }); | ||
} | ||
_handleFilterBrowserChange(e) { | ||
const index = this._filterBrowsers.indexOf(e.target.value); | ||
const browsers = [...this._filterBrowsers]; | ||
const index = browsers.indexOf(e.target.value); | ||
if (!e.target.checked && index > -1) { | ||
this._filterBrowsers.splice(index, 1); | ||
browsers.splice(index, 1); | ||
} else if (e.target.checked && index === -1) { | ||
this._filterBrowsers.push(e.target.value); | ||
browsers.push(e.target.value); | ||
} | ||
this._updateFiles(); | ||
this._updateSearchParams({ browsers: browsers.join(',') }); | ||
} | ||
_handleFilterStatusChange(e) { | ||
this._filterStatus = e.target.value; | ||
this._updateFiles(); | ||
this._updateSearchParams({ status: e.target.value }); | ||
} | ||
_handleSettingChange(e) { | ||
this[`_${e.detail.name}`] = e.detail.value; | ||
} | ||
_handleTestClick(e) { | ||
this._updateSearchParams({ file: e.target.dataset.file, test: e.target.dataset.test }); | ||
return false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Returning |
||
} | ||
_renderFile(file) { | ||
const renderBrowserCell = (b) => { | ||
if (!this._filterBrowsers.includes(b.name)) return nothing; | ||
|
@@ -227,15 +237,21 @@ class App extends LitElement { | |
const text = passed ? 'passed' : 'failed'; | ||
return html`<td class="${text}">${text}</td>`; | ||
}); | ||
const searchParams = new URLSearchParams(window.location.search); | ||
searchParams.set('file', file.name); | ||
searchParams.set('test', test.name); | ||
return html` | ||
<tr> | ||
<th style="text-align: left;"><a href="./?file=${encodeURIComponent(file.name)}&test=${encodeURIComponent(test.name)}">${test.name}</a></th> | ||
<th style="text-align: left;"><a href="${this._root}?${searchParams.toString()}" @click="${this._handleTestClick}" data-file="${file.name}" data-test="${test.name}">${test.name}</a></th> | ||
${results} | ||
</tr> | ||
`; | ||
} | ||
_updateFiles() { | ||
|
||
const files = []; | ||
let foundFilterTest = false; | ||
|
||
data.files.forEach(f => { | ||
const tests = []; | ||
f.tests.forEach(t => { | ||
|
@@ -247,13 +263,33 @@ class App extends LitElement { | |
}); | ||
if (results.length > 0) { | ||
tests.push({ ...t, results }); | ||
if (t.name === this._filterTest) { | ||
foundFilterTest = true; | ||
} | ||
} | ||
}); | ||
if (tests.length > 0) { | ||
files.push({ ...f, tests }); | ||
} | ||
}); | ||
|
||
if (this._filterTest !== undefined && !foundFilterTest) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This handles the case where you're viewing a particular test but then apply a filter that will cause that test to be excluded. We zoom back out to app home. |
||
this._updateSearchParams({ file: undefined, test: undefined }); | ||
return; | ||
} | ||
this._files = files; | ||
|
||
} | ||
_updateSearchParams(params) { | ||
const searchParams = new URLSearchParams(window.location.search); | ||
for (const name in params) { | ||
if (params[name] === undefined) { | ||
searchParams.delete(name); | ||
} else { | ||
searchParams.set(name, params[name]); | ||
} | ||
} | ||
page.redirect(`${this._root}?${searchParams.toString()}`); | ||
} | ||
} | ||
customElements.define('d2l-vdiff-report-app', App); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't needed since Page.js's init code will call this.