Search: Sort alphabetically in the folder view, increase the limit of the folder search from 50 to 1000 (#57078)

* search: sort folders

* search: increase the limit for folder search to 1000

* add folder view sort test

* search: getFolderViewSort

* search: revert test

Co-authored-by: Todd Treece <todd.treece@grafana.com>
This commit is contained in:
Artur Wierzbicki
2022-10-18 14:10:53 +08:00
committed by GitHub
co-authored by Todd Treece
parent 0db339d82f
commit c26cf6a517
6 changed files with 27 additions and 2 deletions
@@ -46,9 +46,12 @@ export const FolderView = ({
}
folders.push({ title: 'General', url: '/dashboards', kind: 'folder', uid: GENERAL_FOLDER_UID });
const rsp = await getGrafanaSearcher().search({
const searcher = getGrafanaSearcher();
const rsp = await searcher.search({
query: '*',
kind: ['folder'],
sort: searcher.getFolderViewSort(),
limit: 1000,
});
for (const row of rsp.view) {
folders.push({
+7 -1
View File
@@ -24,6 +24,8 @@ type SearchAPIResponse = {
frames: DataFrameJSON[];
};
const folderViewSort = 'name_sort';
export class BlugeSearcher implements GrafanaSearcher {
constructor(private fallbackSearcher: GrafanaSearcher) {}
@@ -75,7 +77,7 @@ export class BlugeSearcher implements GrafanaSearcher {
// This should eventually be filled by an API call, but hardcoded is a good start
getSortOptions(): Promise<SelectableValue[]> {
const opts: SelectableValue[] = [
{ value: 'name_sort', label: 'Alphabetically (A-Z)' },
{ value: folderViewSort, label: 'Alphabetically (A-Z)' },
{ value: '-name_sort', label: 'Alphabetically (Z-A)' },
];
@@ -199,6 +201,10 @@ export class BlugeSearcher implements GrafanaSearcher {
},
};
}
getFolderViewSort(): string {
return 'name_sort';
}
}
const firstPageSize = 50;
@@ -34,4 +34,8 @@ export class DummySearcher implements GrafanaSearcher {
async tags(query: SearchQuery): Promise<TermCount[]> {
return Promise.resolve(this.expectedTagsResponse);
}
getFolderViewSort(): string {
return '';
}
}
@@ -75,6 +75,10 @@ export class FrontendSearcher implements GrafanaSearcher {
async tags(query: SearchQuery): Promise<TermCount[]> {
return this.parent.tags(query);
}
getFolderViewSort(): string {
return this.parent.getFolderViewSort();
}
}
class FullResultCache {
@@ -224,4 +224,9 @@ export class SQLSearcher implements GrafanaSearcher {
isItemLoaded: (index: number): boolean => true,
};
}
getFolderViewSort = () => {
// sorts alphabetically in memory after retrieving the folders from the database
return '';
};
}
@@ -72,4 +72,7 @@ export interface GrafanaSearcher {
tags: (query: SearchQuery) => Promise<TermCount[]>;
getSortOptions: () => Promise<SelectableValue[]>;
sortPlaceholder?: string;
/** Gets the default sort used for the Folder view */
getFolderViewSort: () => string;
}