fix(provisioning): ensure all dashboards are selected when selecting a folder

- Add fallback for parentUID when dashboard isn't in state yet
- Add pagination for folder search to ensure all child folders are found
- This fixes an issue where only some dashboards were being exported when selecting a folder
This commit is contained in:
Roberto Jimenez Sanchez
2025-12-02 19:15:33 +01:00
parent 388e57b5f1
commit 18f95ee511
2 changed files with 28 additions and 12 deletions
@@ -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
@@ -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++;
}
}