diff --git a/public/app/features/search/page/components/FolderView.tsx b/public/app/features/search/page/components/FolderView.tsx index 1b236143c5b..5a7c69d17e1 100644 --- a/public/app/features/search/page/components/FolderView.tsx +++ b/public/app/features/search/page/components/FolderView.tsx @@ -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({ diff --git a/public/app/features/search/service/bluge.ts b/public/app/features/search/service/bluge.ts index bdeb9a7ecc5..7dce0584bfb 100644 --- a/public/app/features/search/service/bluge.ts +++ b/public/app/features/search/service/bluge.ts @@ -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 { 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; diff --git a/public/app/features/search/service/frontend.ts b/public/app/features/search/service/frontend.ts index 26aa066d6e1..868651e48c8 100644 --- a/public/app/features/search/service/frontend.ts +++ b/public/app/features/search/service/frontend.ts @@ -65,6 +65,10 @@ export class FrontendSearcher implements GrafanaSearcher { async tags(query: SearchQuery): Promise { return this.parent.tags(query); } + + getFolderViewSort(): string { + return this.parent.getFolderViewSort(); + } } class FullResultCache { diff --git a/public/app/features/search/service/sql.ts b/public/app/features/search/service/sql.ts index f53a7190816..259ba392c30 100644 --- a/public/app/features/search/service/sql.ts +++ b/public/app/features/search/service/sql.ts @@ -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 ''; + }; } diff --git a/public/app/features/search/service/types.ts b/public/app/features/search/service/types.ts index 282772f4777..dbf0518345e 100644 --- a/public/app/features/search/service/types.ts +++ b/public/app/features/search/service/types.ts @@ -71,4 +71,7 @@ export interface GrafanaSearcher { starred: (query: SearchQuery) => Promise; tags: (query: SearchQuery) => Promise; getSortOptions: () => Promise; + + /** Gets the default sort used for the Folder view */ + getFolderViewSort: () => string; }