Commit f87b9aaa by Marcus Efraimsson

dashboard: keyboard nav in dashboard search - closes #10100

Pressing enter/return for a folder toggles it.
Pressing enter/return for a dashboard navigates to it.
parent fe177f19
...@@ -64,18 +64,70 @@ export class SearchCtrl { ...@@ -64,18 +64,70 @@ export class SearchCtrl {
this.moveSelection(-1); this.moveSelection(-1);
} }
if (evt.keyCode === 13) { if (evt.keyCode === 13) {
var selectedDash = this.results[this.selectedIndex]; const flattenedResult = this.getFlattenedResultForNavigation();
const currentItem = flattenedResult[this.selectedIndex];
if (currentItem) {
if (currentItem.dashboardIndex !== undefined) {
const selectedDash = this.results[currentItem.folderIndex].items[currentItem.dashboardIndex];
if (selectedDash) { if (selectedDash) {
this.$location.search({}); this.$location.search({});
this.$location.path(selectedDash.url); this.$location.path(selectedDash.url);
} }
} else {
const selectedFolder = this.results[currentItem.folderIndex];
if (selectedFolder) {
selectedFolder.toggle(selectedFolder);
}
}
}
} }
} }
moveSelection(direction) { moveSelection(direction) {
var max = (this.results || []).length; if (this.results.length === 0) {
var newIndex = this.selectedIndex + direction; return;
}
const flattenedResult = this.getFlattenedResultForNavigation();
const currentItem = flattenedResult[this.selectedIndex];
if (currentItem) {
if (currentItem.dashboardIndex !== undefined) {
this.results[currentItem.folderIndex].items[currentItem.dashboardIndex].selected = false;
} else {
this.results[currentItem.folderIndex].selected = false;
}
}
const max = flattenedResult.length;
let newIndex = this.selectedIndex + direction;
this.selectedIndex = ((newIndex %= max) < 0) ? newIndex + max : newIndex; this.selectedIndex = ((newIndex %= max) < 0) ? newIndex + max : newIndex;
const selectedItem = flattenedResult[this.selectedIndex];
if (selectedItem.dashboardIndex === undefined && this.results[selectedItem.folderIndex].id === 0) {
this.moveSelection(direction);
return;
}
if (selectedItem.dashboardIndex !== undefined) {
if (!this.results[selectedItem.folderIndex].expanded) {
this.moveSelection(direction);
return;
}
this.results[selectedItem.folderIndex].items[selectedItem.dashboardIndex].selected = true;
return;
}
if (this.results[selectedItem.folderIndex].hideHeader) {
this.moveSelection(direction);
return;
}
this.results[selectedItem.folderIndex].selected = true;
} }
searchDashboards() { searchDashboards() {
...@@ -84,8 +136,9 @@ export class SearchCtrl { ...@@ -84,8 +136,9 @@ export class SearchCtrl {
return this.searchSrv.search(this.query).then(results => { return this.searchSrv.search(this.query).then(results => {
if (localSearchId < this.currentSearchId) { return; } if (localSearchId < this.currentSearchId) { return; }
this.results = results; this.results = results || [];
this.isLoading = false; this.isLoading = false;
this.moveSelection(1);
}); });
} }
...@@ -125,12 +178,32 @@ export class SearchCtrl { ...@@ -125,12 +178,32 @@ export class SearchCtrl {
search() { search() {
this.showImport = false; this.showImport = false;
this.selectedIndex = 0; this.selectedIndex = -1;
this.searchDashboards(); this.searchDashboards();
} }
toggleFolder(section) { private getFlattenedResultForNavigation() {
this.searchSrv.toggleSection(section); let folderIndex = 0;
return _.flatMap(this.results, (s) => {
let result = [];
result.push({
folderIndex: folderIndex
});
let dashboardIndex = 0;
result = result.concat(_.map(s.items || [], (i) => {
return {
folderIndex: folderIndex,
dashboardIndex: dashboardIndex++
};
}));
folderIndex++;
return result;
});
} }
} }
......
<div ng-repeat="section in ctrl.results" class="search-section"> <div ng-repeat="section in ctrl.results" class="search-section">
<a class="search-section__header pointer" ng-hide="section.hideHeader" ng-click="ctrl.toggleFolderExpand(section)"> <a class="search-section__header pointer" ng-hide="section.hideHeader" ng-class="{'selected': section.selected}" ng-click="ctrl.toggleFolderExpand(section)">
<div ng-click="ctrl.toggleSelection(section, $event)"> <div ng-click="ctrl.toggleSelection(section, $event)">
<gf-form-switch <gf-form-switch
ng-show="ctrl.editable" ng-show="ctrl.editable"
......
...@@ -201,10 +201,6 @@ export class SearchSrv { ...@@ -201,10 +201,6 @@ export class SearchSrv {
}); });
} }
toggleSection(section) {
section.toggle(section);
}
getDashboardTags() { getDashboardTags() {
return this.backendSrv.get('/api/dashboards/tags'); return this.backendSrv.get('/api/dashboards/tags');
} }
......
...@@ -150,10 +150,6 @@ export class DashboardListCtrl { ...@@ -150,10 +150,6 @@ export class DashboardListCtrl {
}); });
} }
toggleFolder(section) {
return this.searchSrv.toggleSection(section);
}
getTags() { getTags() {
return this.searchSrv.getDashboardTags().then((results) => { return this.searchSrv.getDashboardTags().then((results) => {
this.tagFilterOptions = [{ term: 'Filter By Tag', disabled: true }].concat(results); this.tagFilterOptions = [{ term: 'Filter By Tag', disabled: true }].concat(results);
......
...@@ -537,9 +537,6 @@ function createCtrlWithStubs(searchResponse: any, tags?: any) { ...@@ -537,9 +537,6 @@ function createCtrlWithStubs(searchResponse: any, tags?: any) {
search: (options: any) => { search: (options: any) => {
return q.resolve(searchResponse); return q.resolve(searchResponse);
}, },
toggleSection: (section) => {
return;
},
getDashboardTags: () => { getDashboardTags: () => {
return q.resolve(tags || []); return q.resolve(tags || []);
} }
......
...@@ -120,8 +120,9 @@ ...@@ -120,8 +120,9 @@
display: flex; display: flex;
flex-grow: 1; flex-grow: 1;
&:hover { &:hover, &.selected {
color: $text-color-weak; color: $link-hover-color;
.search-section__header__toggle { .search-section__header__toggle {
background: $tight-form-func-bg; background: $tight-form-func-bg;
color: $link-hover-color; color: $link-hover-color;
...@@ -151,11 +152,8 @@ ...@@ -151,11 +152,8 @@
white-space: nowrap; white-space: nowrap;
padding: 0px; padding: 0px;
&:hover { &:hover, &.selected {
@include left-brand-border-gradient(); @include left-brand-border-gradient();
}
&.selected {
background: $list-item-hover-bg; background: $list-item-hover-bg;
} }
} }
......
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