From 7a91afc504996e1ec9e0d9585f16ca846fc4d6a7 Mon Sep 17 00:00:00 2001 From: Artur Wierzbicki Date: Tue, 18 Oct 2022 14:50:59 +0800 Subject: [PATCH] Search: Sort alphabetically in the folder view, increase the limit of the folder search from 50 to 1000 (#57078) (#57141) * 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 (cherry picked from commit c26cf6a51791967e1892c8cc2f177401dc4977af) --- public/app/features/search/page/components/FolderView.tsx | 5 ++++- public/app/features/search/service/bluge.ts | 8 +++++++- public/app/features/search/service/frontend.ts | 4 ++++ public/app/features/search/service/sql.ts | 5 +++++ public/app/features/search/service/types.ts | 3 +++ 5 files changed, 23 insertions(+), 2 deletions(-) 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; }