Nested folders: remove behaviour where selecting all children selects parent (#68084)

remove behaviour where selecting all children selects parent
This commit is contained in:
Ashley Harrison 2023-05-10 10:51:57 +01:00 committed by GitHub
parent dcb3b4d97a
commit 765da9c841
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 61 deletions

View File

@ -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', () => {
const state = createInitialState();
@ -264,16 +214,16 @@ describe('browse-dashboards reducers', () => {
state.selectedItems.dashboard = { [rootDashboard.uid]: true, [childDashboardA.uid]: true };
// Selected the deepest grandchild dashboard
// Selects the root folder
setItemSelectionState(state, {
type: 'setItemSelectionState',
payload: { item: childDashboardB, isSelected: true },
payload: { item: rootFolder, isSelected: true },
});
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 rootDashboard = wellFormedDashboard(1).item;

View File

@ -78,14 +78,7 @@ export function setItemSelectionState(
break;
}
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 {
if (!isSelected) {
// A folder cannot be selected if any of it's children are unselected
state.selectedItems[parent.kind][parent.uid] = false;
}