mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Search: Only move dashboards into expanded folders UI-wise (#25363)
* Search: Ony move dashboards into expanded folders UI-wise * Search: Add tests
This commit is contained in:
parent
acae33edf9
commit
1790ece4d5
@ -1,7 +1,7 @@
|
|||||||
import { TOGGLE_ALL_CHECKED, TOGGLE_CHECKED, DELETE_ITEMS, MOVE_ITEMS } from './actionTypes';
|
import { TOGGLE_ALL_CHECKED, TOGGLE_CHECKED, DELETE_ITEMS, MOVE_ITEMS } from './actionTypes';
|
||||||
import { manageDashboardsReducer as reducer, manageDashboardsState as state } from './manageDashboards';
|
import { manageDashboardsReducer as reducer, manageDashboardsState as state } from './manageDashboards';
|
||||||
import { sections } from '../testData';
|
import { sections } from '../testData';
|
||||||
import { UidsToDelete } from '../types';
|
import { DashboardSection, UidsToDelete } from '../types';
|
||||||
|
|
||||||
// Remove Recent and Starred sections as they're not used in manage dashboards
|
// Remove Recent and Starred sections as they're not used in manage dashboards
|
||||||
const results = sections.slice(2);
|
const results = sections.slice(2);
|
||||||
@ -84,4 +84,12 @@ describe('Manage dashboards reducer', () => {
|
|||||||
expect(newState.results[3].items).toHaveLength(1);
|
expect(newState.results[3].items).toHaveLength(1);
|
||||||
expect(newState.results[3].items[0].uid).toEqual('LCFWfl9Zz');
|
expect(newState.results[3].items[0].uid).toEqual('LCFWfl9Zz');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not display dashboards in a non-expanded folder', () => {
|
||||||
|
const general = results.find(res => res.id === 0);
|
||||||
|
const toMove = { dashboards: general.items, folder: { id: 4074 } };
|
||||||
|
const newState = reducer({ ...state, results }, { type: MOVE_ITEMS, payload: toMove });
|
||||||
|
expect(newState.results.find((res: DashboardSection) => res.id === 4074).items).toHaveLength(0);
|
||||||
|
expect(newState.results.find((res: DashboardSection) => res.id === 0).items).toHaveLength(0);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -53,11 +53,13 @@ const reducer = (state: ManageDashboardsState, action: SearchAction) => {
|
|||||||
...state,
|
...state,
|
||||||
results: state.results.map(result => {
|
results: state.results.map(result => {
|
||||||
if (folder.id === result.id) {
|
if (folder.id === result.id) {
|
||||||
return {
|
return result.expanded
|
||||||
|
? {
|
||||||
...result,
|
...result,
|
||||||
items: [...result.items, ...dashboards.map(db => ({ ...db, checked: false }))],
|
items: [...result.items, ...dashboards.map(db => ({ ...db, checked: false }))],
|
||||||
checked: false,
|
checked: false,
|
||||||
};
|
}
|
||||||
|
: result;
|
||||||
} else {
|
} else {
|
||||||
return { ...result, items: result.items.filter(item => !uids.includes(item.uid)) };
|
return { ...result, items: result.items.filter(item => !uids.includes(item.uid)) };
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ export const sections = [
|
|||||||
id: 2,
|
id: 2,
|
||||||
uid: 'JB_zdOUWk',
|
uid: 'JB_zdOUWk',
|
||||||
title: 'gdev dashboards',
|
title: 'gdev dashboards',
|
||||||
expanded: false,
|
expanded: true,
|
||||||
url: '/dashboards/f/JB_zdOUWk/gdev-dashboards',
|
url: '/dashboards/f/JB_zdOUWk/gdev-dashboards',
|
||||||
icon: 'folder',
|
icon: 'folder',
|
||||||
score: 2,
|
score: 2,
|
||||||
|
Loading…
Reference in New Issue
Block a user