mirror of
https://github.com/grafana/grafana.git
synced 2024-11-26 19:00:54 -06:00
dashboard: fix edge case with keyboard nav in dashboard search. #10100
If expanding a folder using mouse, unselect current keyboard selection
This commit is contained in:
parent
58fb35c5cb
commit
d0a9770b8b
@ -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;
|
||||
let folder = {
|
||||
toggle: () => {
|
||||
folderToggled = true;
|
||||
}
|
||||
};
|
||||
describe('when toggle a collapsed folder', () => {
|
||||
let folderExpanded = false;
|
||||
|
||||
beforeEach(() => {
|
||||
ctrl = new SearchResultsCtrl({});
|
||||
ctrl.onFolderExpanding = () => { folderExpanded = true; };
|
||||
|
||||
let folder = {
|
||||
expanded: false,
|
||||
toggle: () => {}
|
||||
};
|
||||
|
||||
ctrl.toggleFolderExpand(folder);
|
||||
});
|
||||
|
||||
it('should trigger folder toggle callback', () => {
|
||||
expect(folderToggled).toBeTruthy();
|
||||
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 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 = {
|
||||
|
Loading…
Reference in New Issue
Block a user