mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Nested folders: remove behaviour where selecting all children selects parent (#68084)
remove behaviour where selecting all children selects parent
This commit is contained in:
parent
dcb3b4d97a
commit
765da9c841
@ -201,56 +201,6 @@ describe('browse-dashboards reducers', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('selects ancestors when all their children are now selected', () => {
|
|
||||||
const state = createInitialState();
|
|
||||||
|
|
||||||
const rootDashboard = wellFormedDashboard(1).item;
|
|
||||||
const parentFolder = wellFormedFolder(2).item;
|
|
||||||
const childDashboard = wellFormedDashboard(3, {}, { parentUID: parentFolder.uid }).item;
|
|
||||||
const childFolder = wellFormedFolder(4, {}, { parentUID: parentFolder.uid }).item;
|
|
||||||
const grandchildDashboard = wellFormedDashboard(5, {}, { parentUID: childFolder.uid }).item;
|
|
||||||
|
|
||||||
state.rootItems = [parentFolder, rootDashboard];
|
|
||||||
state.childrenByParentUID[parentFolder.uid] = [childDashboard, childFolder];
|
|
||||||
state.childrenByParentUID[childFolder.uid] = [grandchildDashboard];
|
|
||||||
|
|
||||||
// Selected the deepest grandchild dashboard
|
|
||||||
setItemSelectionState(state, {
|
|
||||||
type: 'setItemSelectionState',
|
|
||||||
payload: { item: grandchildDashboard, isSelected: true },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(state.selectedItems).toEqual({
|
|
||||||
$all: false,
|
|
||||||
dashboard: {
|
|
||||||
[grandchildDashboard.uid]: true,
|
|
||||||
},
|
|
||||||
folder: {
|
|
||||||
[parentFolder.uid]: false,
|
|
||||||
[childFolder.uid]: true, // is selected because all it's children (grandchildDashboard) is selected
|
|
||||||
},
|
|
||||||
panel: {},
|
|
||||||
});
|
|
||||||
|
|
||||||
setItemSelectionState(state, {
|
|
||||||
type: 'setItemSelectionState',
|
|
||||||
payload: { item: childDashboard, isSelected: true },
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(state.selectedItems).toEqual({
|
|
||||||
$all: false,
|
|
||||||
dashboard: {
|
|
||||||
[childDashboard.uid]: true,
|
|
||||||
[grandchildDashboard.uid]: true,
|
|
||||||
},
|
|
||||||
folder: {
|
|
||||||
[parentFolder.uid]: true, // is now selected because we also selected its other child
|
|
||||||
[childFolder.uid]: true,
|
|
||||||
},
|
|
||||||
panel: {},
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
it('selects the $all header checkbox when all descendants are now selected', () => {
|
it('selects the $all header checkbox when all descendants are now selected', () => {
|
||||||
const state = createInitialState();
|
const state = createInitialState();
|
||||||
|
|
||||||
@ -264,16 +214,16 @@ describe('browse-dashboards reducers', () => {
|
|||||||
|
|
||||||
state.selectedItems.dashboard = { [rootDashboard.uid]: true, [childDashboardA.uid]: true };
|
state.selectedItems.dashboard = { [rootDashboard.uid]: true, [childDashboardA.uid]: true };
|
||||||
|
|
||||||
// Selected the deepest grandchild dashboard
|
// Selects the root folder
|
||||||
setItemSelectionState(state, {
|
setItemSelectionState(state, {
|
||||||
type: 'setItemSelectionState',
|
type: 'setItemSelectionState',
|
||||||
payload: { item: childDashboardB, isSelected: true },
|
payload: { item: rootFolder, isSelected: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(state.selectedItems.$all).toBeTruthy();
|
expect(state.selectedItems.$all).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('unselects the $all header checkbox a descendant is unselected', () => {
|
it('unselects the $all header checkbox if a descendant is unselected', () => {
|
||||||
const state = createInitialState();
|
const state = createInitialState();
|
||||||
|
|
||||||
const rootDashboard = wellFormedDashboard(1).item;
|
const rootDashboard = wellFormedDashboard(1).item;
|
||||||
|
@ -78,14 +78,7 @@ export function setItemSelectionState(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSelected) {
|
if (!isSelected) {
|
||||||
// If we're selecting an item, check all ancestors and see if all their children are
|
|
||||||
// now selected and update them appropriately
|
|
||||||
const children = state.childrenByParentUID[parent.uid];
|
|
||||||
|
|
||||||
const allChildrenSelected = children?.every((v) => state.selectedItems[v.kind][v.uid]) ?? false;
|
|
||||||
state.selectedItems[parent.kind][parent.uid] = allChildrenSelected;
|
|
||||||
} else {
|
|
||||||
// A folder cannot be selected if any of it's children are unselected
|
// A folder cannot be selected if any of it's children are unselected
|
||||||
state.selectedItems[parent.kind][parent.uid] = false;
|
state.selectedItems[parent.kind][parent.uid] = false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user