Commit d0a9770b by Marcus Efraimsson

dashboard: fix edge case with keyboard nav in dashboard search. #10100

If expanding a folder using mouse, unselect current keyboard selection
parent 58fb35c5
......@@ -24,7 +24,9 @@
<h6 ng-show="!ctrl.isLoading && ctrl.results.length === 0">No dashboards matching your query were found.</h6>
<dashboard-search-results
results="ctrl.results"
on-tag-selected="ctrl.filterByTag($tag)" />
on-tag-selected="ctrl.filterByTag($tag)"
on-folder-expanding="ctrl.folderExpanding()"
on-folder-expanded="ctrl.folderExpanded($folder)" />
</div>
</div>
......
......@@ -102,6 +102,11 @@ export class SearchCtrl {
}
}
if (direction === 0) {
this.selectedIndex = -1;
return;
}
const max = flattenedResult.length;
let newIndex = this.selectedIndex + direction;
this.selectedIndex = ((newIndex %= max) < 0) ? newIndex + max : newIndex;
......@@ -182,6 +187,10 @@ export class SearchCtrl {
this.searchDashboards();
}
folderExpanding() {
this.moveSelection(0);
}
private getFlattenedResultForNavigation() {
let folderIndex = 0;
......
......@@ -55,21 +55,43 @@ describe('SearchResultsCtrl', () => {
});
});
describe('when toggle a folder', () => {
let folderToggled = false;
describe('when toggle a collapsed folder', () => {
let folderExpanded = false;
beforeEach(() => {
ctrl = new SearchResultsCtrl({});
ctrl.onFolderExpanding = () => { folderExpanded = true; };
let folder = {
toggle: () => {
folderToggled = true;
}
expanded: false,
toggle: () => {}
};
ctrl.toggleFolderExpand(folder);
});
it('should trigger folder expanding callback', () => {
expect(folderExpanded).toBeTruthy();
});
});
describe('when toggle an expanded folder', () => {
let folderExpanded = false;
beforeEach(() => {
ctrl = new SearchResultsCtrl({});
ctrl.onFolderExpanding = () => { folderExpanded = true; };
let folder = {
expanded: true,
toggle: () => {}
};
ctrl.toggleFolderExpand(folder);
});
it('should trigger folder toggle callback', () => {
expect(folderToggled).toBeTruthy();
it('should not trigger folder expanding callback', () => {
expect(folderExpanded).toBeFalsy();
});
});
});
......@@ -5,6 +5,7 @@ export class SearchResultsCtrl {
results: any;
onSelectionChanged: any;
onTagSelected: any;
onFolderExpanding: any;
/** @ngInject */
constructor(private $location) {
......@@ -13,6 +14,10 @@ export class SearchResultsCtrl {
toggleFolderExpand(section) {
if (section.toggle) {
if (!section.expanded && this.onFolderExpanding) {
this.onFolderExpanding();
}
section.toggle(section);
}
}
......@@ -62,7 +67,8 @@ export function searchResultsDirective() {
editable: '@',
results: '=',
onSelectionChanged: '&',
onTagSelected: '&'
onTagSelected: '&',
onFolderExpanding: '&'
},
};
}
......
......@@ -51,7 +51,7 @@ export class SearchSrv {
store.set('search.sections.recent', this.recentIsOpen);
if (!section.expanded || section.items.length) {
return;
return Promise.resolve();
}
return this.queryForRecentDashboards().then(result => {
......@@ -62,6 +62,7 @@ export class SearchSrv {
private toggleStarred(section) {
this.starredIsOpen = section.expanded = !section.expanded;
store.set('search.sections.starred', this.starredIsOpen);
return Promise.resolve();
}
private getStarred(sections) {
......@@ -189,7 +190,7 @@ export class SearchSrv {
section.icon = section.expanded ? 'fa fa-folder-open' : 'fa fa-folder';
if (section.items.length) {
return;
return Promise.resolve();
}
let query = {
......
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