diff --git a/public/app/features/browse-dashboards/state/actions.ts b/public/app/features/browse-dashboards/state/actions.ts index f41666b0245..fd86390a1eb 100644 --- a/public/app/features/browse-dashboards/state/actions.ts +++ b/public/app/features/browse-dashboards/state/actions.ts @@ -131,13 +131,16 @@ export const selectFolderWithAllDashboards = createAsyncThunk( // Then select all dashboards found // We need to get the parentUID for each dashboard from the state + // If a dashboard isn't in state yet, we still need to select it for (const dashboardUID of dashboardUIDs) { const dashboardItem = findItem(state.rootItems?.items ?? [], state.childrenByParentUID, dashboardUID); + // Even if dashboard isn't in state, we can still select it by UID + // The reducer will handle setting selectedItems.dashboard[dashboardUID] = true dispatch(setItemSelectionState({ item: { kind: 'dashboard', uid: dashboardUID, - parentUID: dashboardItem?.parentUID, + parentUID: dashboardItem?.parentUID ?? folderUID, // Fallback to folderUID if not found managedBy: dashboardItem?.managedBy }, isSelected: true diff --git a/public/app/features/provisioning/utils/collectFolderDashboards.ts b/public/app/features/provisioning/utils/collectFolderDashboards.ts index 2d142753a3f..ea3f542bb41 100644 --- a/public/app/features/provisioning/utils/collectFolderDashboards.ts +++ b/public/app/features/provisioning/utils/collectFolderDashboards.ts @@ -37,20 +37,33 @@ export async function collectAllDashboardsUnderFolder(folderUID: string): Promis // Get child folders and add them to the processing queue // We need to use the search API to find child folders + // Paginate through all folders to ensure we get all child folders const searcher = getGrafanaSearcher(); - - const foldersResults = await searcher.search({ - kind: ['folder'], - query: '*', - location: currentFolderUID || 'general', - limit: 100, - }); + let folderPage = 0; + let hasMoreFolders = true; + const folderPageSize = 100; - for (const folderItem of foldersResults.view) { - const folderUID = folderItem.uid; - if (folderUID && !processedFolders.has(folderUID)) { - foldersToProcess.push(folderUID); + while (hasMoreFolders) { + const foldersResults = await searcher.search({ + kind: ['folder'], + query: '*', + location: currentFolderUID || 'general', + from: folderPage * folderPageSize, + limit: folderPageSize, + }); + + let foundFolders = 0; + for (const folderItem of foldersResults.view) { + const folderUID = folderItem.uid; + if (folderUID && !processedFolders.has(folderUID)) { + foldersToProcess.push(folderUID); + foundFolders++; + } } + + // Check if we've loaded all folders (if we got fewer than pageSize, we're done) + hasMoreFolders = foldersResults.view.length === folderPageSize; + folderPage++; } }