Commit 55886771 authored by Cecilia Ni's avatar Cecilia Ni Committed by Commit Bot

[App Management] Integrate search view with dom-switch

This CL integrates search view with dom-switch by letting selectedRouteId_ directly watch the
existence of search term rather than delegating to reducer.currentPageState to handle search.

This way, after users clear search, they will go back to the page they were on rather than main
page.

Bug: 906508
Change-Id: I75aabf2ccfdadc48093062b48adf85932c2b9606
Reviewed-on: https://chromium-review.googlesource.com/c/1459868Reviewed-by: default avatarcalamity <calamity@chromium.org>
Commit-Queue: Cecilia Ni <ceciliani@google.com>
Cr-Commit-Position: refs/heads/master@{#630699}
parent 79c8fcf3
......@@ -48,10 +48,6 @@ cr.define('app_management.actions', function() {
'Tried to load app detail page without providing an app id.');
}
if (PageType == PageType.SEARCH) {
console.warn('This should not be invoked');
}
return {
name: 'change-page',
pageType: pageType,
......
......@@ -34,7 +34,7 @@
on-search-changed="onSearchChanged_">
</cr-toolbar>
<app-management-dom-switch id="view-selector"
route="[[selectedRouteId_(currentPage_)]]">
route="[[selectedRouteId_(currentPage_, searchTerm_)]]">
<template>
<app-management-main-view route-id="main-view">
</app-management-main-view>
......
......@@ -47,36 +47,40 @@ Polymer({
/**
* @param {Page} currentPage
* @param {String} searchTerm
* @private
*/
selectedRouteId_: function(currentPage) {
switch (currentPage.pageType) {
case (PageType.MAIN):
return 'main-view';
case (PageType.NOTIFICATIONS):
return 'notifications-view';
selectedRouteId_: function(currentPage, searchTerm) {
if (searchTerm) {
return 'search-view';
}
// This is to prevent console error caused by currentPage being undefined.
if (currentPage) {
switch (currentPage.pageType) {
case (PageType.MAIN):
return 'main-view';
case (PageType.SEARCH):
return 'search-view';
case (PageType.NOTIFICATIONS):
return 'notifications-view';
case (PageType.DETAIL):
const state = this.getState();
const selectedAppType =
state.apps[assert(state.currentPage.selectedAppId)].type;
switch (selectedAppType) {
case (AppType.kWeb):
return 'pwa-permission-view';
case (AppType.kExtension):
return 'chrome-app-permission-view';
case (AppType.kArc):
return 'arc-permission-view';
default:
assertNotReached();
}
case (PageType.DETAIL):
const state = this.getState();
const selectedAppType =
state.apps[assert(state.currentPage.selectedAppId)].type;
switch (selectedAppType) {
case (AppType.kWeb):
return 'pwa-permission-view';
case (AppType.kExtension):
return 'chrome-app-permission-view';
case (AppType.kArc):
return 'arc-permission-view';
default:
assertNotReached();
}
default:
assertNotReached();
default:
assertNotReached();
}
}
},
});
......@@ -23,7 +23,6 @@ const PageType = {
MAIN: 0,
DETAIL: 1,
NOTIFICATIONS: 2,
SEARCH: 3,
};
/**
......
......@@ -94,25 +94,7 @@ cr.define('app_management', function() {
}
};
/**
* TODO(ceciliani) Delete search page type and navigate router by calculating
* if there is search.term.
* @param {Object} action
* @return {Page}
*/
CurrentPageState.changeForSearch = function(action) {
if (action.term) {
return {
pageType: PageType.SEARCH,
selectedAppId: null,
};
} else {
return {
pageType: PageType.MAIN,
selectedAppId: null,
};
}
};
/**
* @param {Page} currentPage
* @param {Object} action
......@@ -138,10 +120,6 @@ cr.define('app_management', function() {
*/
CurrentPageState.updateCurrentPage = function(apps, currentPage, action) {
switch (action.name) {
case 'start-search':
return CurrentPageState.changeForSearch(action);
case 'clear-search':
return CurrentPageState.changeForSearch(action);
case 'change-page':
return CurrentPageState.changePage(apps, action);
case 'remove-app':
......
......@@ -5,9 +5,21 @@
'use strict';
suite('<app-management-app>', function() {
let app;
setup(function() {
app = document.createElement('app-management-app');
document.body.appendChild(app);
});
test('loads', async function() {
// Check that the browser responds to the getApps() message.
const {apps: initialApps} =
await app_management.BrowserProxy.getInstance().handler.getApps();
});
test('Searching switches to search page', async function() {
app.$$('cr-toolbar').fire('search-changed', 'SearchTest');
assert(app.$$('app-management-search-view'));
});
});
......@@ -136,7 +136,6 @@ suite('app state', function() {
state = app_management.reduceAction(state, action);
assertEquals('searchTerm', state.search.term);
assertEquals(PageType.SEARCH, state.currentPage.pageType);
// Search disappears when there is no term entered.
action = app_management.actions.clearSearch();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment