-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[internals] Add a basic implementation of the launcher internals page.
This is a first-pass implementation of the launcher internals page. The page consists of two tables, which keep track of the most recent zero-state results and query search results respectively. The page is not yet hooked up to any backend. A C++ page handler will be added in a follow-up CL. Bug: 1211232 Change-Id: I237a2a38aebc418b62facbeb4aa55a9f5fea1194 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2916777 Reviewed-by: Sam McNally <sammc@chromium.org> Reviewed-by: dpapad <dpapad@chromium.org> Reviewed-by: Tony Yeoman <tby@chromium.org> Commit-Queue: Rachel Wong <wrong@chromium.org> Cr-Commit-Position: refs/heads/master@{#892410}
- Loading branch information
Rachel Wong
authored and
Chromium LUCI CQ
committed
Jun 15, 2021
1 parent
85a21fd
commit 0bd1172
Showing
9 changed files
with
252 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
chrome/browser/resources/chromeos/launcher_internals/browser_proxy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {PageCallbackRouter} from './launcher_internals.mojom-webui.js'; | ||
|
||
export class BrowserProxy { | ||
callbackRouter: PageCallbackRouter = new PageCallbackRouter(); | ||
// TODO(crbug.com/1211232): Use PageHandlerFactory to create a page handler. | ||
|
||
static getInstance(): BrowserProxy { | ||
return instance || (instance = new BrowserProxy()); | ||
} | ||
|
||
static setInstance(obj: BrowserProxy) { | ||
instance = obj; | ||
} | ||
} | ||
|
||
let instance: BrowserProxy|null = null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
chrome/browser/resources/chromeos/launcher_internals/launcher_internals.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<h1>Zero state</h1> | ||
<launcher-results-table id="zeroStateResults"></launcher-results-table> | ||
|
||
<h1>Search</h1> | ||
Query: [[query]] | ||
<launcher-results-table id="searchResults"></launcher-results-table> |
73 changes: 73 additions & 0 deletions
73
chrome/browser/resources/chromeos/launcher_internals/launcher_internals.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import './results_table.js'; | ||
|
||
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; | ||
|
||
import {BrowserProxy} from './browser_proxy.js'; | ||
import {PageCallbackRouter, Result} from './launcher_internals.mojom-webui.js'; | ||
import {LauncherResultsTableElement} from './results_table.js'; | ||
|
||
interface LauncherInternalsElement { | ||
$: { | ||
'zeroStateResults': LauncherResultsTableElement, | ||
'searchResults': LauncherResultsTableElement, | ||
}; | ||
} | ||
|
||
class LauncherInternalsElement extends PolymerElement { | ||
static get is() { | ||
return 'launcher-internals'; | ||
} | ||
|
||
static get template() { | ||
return html`{__html_template__}`; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
query: String, | ||
}; | ||
} | ||
|
||
private query: string; | ||
private listenerIds: Array<number>; | ||
private router: PageCallbackRouter; | ||
|
||
constructor() { | ||
super(); | ||
this.query = ''; | ||
this.listenerIds = []; | ||
this.router = BrowserProxy.getInstance().callbackRouter; | ||
} | ||
|
||
connectedCallback() { | ||
super.connectedCallback(); | ||
this.listenerIds.push( | ||
this.router.updateResults.addListener(this.updateResults.bind(this))); | ||
} | ||
|
||
disconnectedCallback() { | ||
super.disconnectedCallback(); | ||
this.listenerIds.forEach(id => this.router.removeListener(id)); | ||
} | ||
|
||
private updateResults(query: string, results: Array<Result>) { | ||
if (query === '') { | ||
this.$.zeroStateResults.clearResults(); | ||
this.$.zeroStateResults.addResults(results); | ||
return; | ||
} | ||
|
||
if (this.query != query) { | ||
// Reset the results table whenever the query changes. | ||
this.$.searchResults.clearResults(); | ||
this.query = query; | ||
} | ||
this.$.searchResults.addResults(results); | ||
} | ||
} | ||
|
||
customElements.define(LauncherInternalsElement.is, LauncherInternalsElement); |
13 changes: 13 additions & 0 deletions
13
chrome/browser/resources/chromeos/launcher_internals/results_table.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<table> | ||
<thead> | ||
<tr> | ||
<td>ID</td> | ||
<td>Title</td> | ||
<td>Description</td> | ||
<td>Result type</td> | ||
<td>Display type</td> | ||
<td>Score</td> | ||
</tr> | ||
</thead> | ||
<tbody id="resultsSection"></tbody> | ||
</table> |
57 changes: 57 additions & 0 deletions
57
chrome/browser/resources/chromeos/launcher_internals/results_table.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {html, PolymerElement} from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js'; | ||
|
||
import {Result} from './launcher_internals.mojom-webui.js'; | ||
|
||
export interface LauncherResultsTableElement { | ||
$: { | ||
'resultsSection': HTMLTableSectionElement, | ||
}; | ||
} | ||
|
||
export class LauncherResultsTableElement extends PolymerElement { | ||
static get is() { | ||
return 'launcher-results-table'; | ||
} | ||
|
||
static get template() { | ||
return html`{__html_template__}`; | ||
} | ||
|
||
private idSet: Set<string> = new Set(); | ||
|
||
clearResults() { | ||
this.idSet.clear(); | ||
this.$.resultsSection.innerHTML = ''; | ||
} | ||
|
||
addResults(results: Array<Result>) { | ||
for (const result of results) { | ||
if (this.idSet.has(result.id)) { | ||
continue; | ||
} | ||
this.idSet.add(result.id); | ||
|
||
const newRow = this.$.resultsSection.insertRow(); | ||
[result.id, | ||
result.title, | ||
result.description, | ||
result.resultType, | ||
result.displayType, | ||
result.score.toString(), | ||
].forEach(field => { | ||
const newCell = newRow.insertCell(); | ||
newCell.textContent = field; | ||
}); | ||
|
||
// TODO(crbug.com/1211232): Handle other ranker scores and allow sorting | ||
// by the chosen score. | ||
} | ||
} | ||
} | ||
|
||
customElements.define( | ||
LauncherResultsTableElement.is, LauncherResultsTableElement); |
6 changes: 6 additions & 0 deletions
6
chrome/browser/resources/chromeos/launcher_internals/tsconfig_base.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../../../../tools/typescript/tsconfig_base.json", | ||
"compilerOptions": { | ||
"allowJs": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters