Skip to content
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

Merged
merged 2 commits into from
Jul 11, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 45 additions & 9 deletions src/server/report/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ class App extends LitElement {
this._fullMode = FULL_MODE.GOLDEN.value;
this._layout = LAYOUTS.SPLIT.value;
this._overlay = true;
this._updateFiles();
Copy link
Member Author

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.

}
connectedCallback() {
super.connectedCallback();
Expand All @@ -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();
}
Expand Down Expand Up @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning false from a click handler cases the href to not navigate. The href is still useful for opening links in new tabs.

}
_renderFile(file) {
const renderBrowserCell = (b) => {
if (!this._filterBrowsers.includes(b.name)) return nothing;
Expand Down Expand Up @@ -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 => {
Expand All @@ -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) {
Copy link
Member Author

Choose a reason for hiding this comment

The 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);