Fix bug with groups not being removed when deleting
This commit is contained in:
parent
4bdf147e2b
commit
b28896db12
@ -29,7 +29,16 @@ export function GroupProvider({
|
|||||||
const [openGroupItems, setOpenGroupItems] = useState([]);
|
const [openGroupItems, setOpenGroupItems] = useState([]);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (openGroupId) {
|
if (openGroupId) {
|
||||||
setOpenGroupItems(getGroupItems(groupsFromIds([openGroupId], groups)[0]));
|
const openGroups = groupsFromIds([openGroupId], groups);
|
||||||
|
if (openGroups.length === 1) {
|
||||||
|
const openGroup = openGroups[0];
|
||||||
|
setOpenGroupItems(getGroupItems(openGroup));
|
||||||
|
} else {
|
||||||
|
// Close group if we can't find it
|
||||||
|
// This can happen if it was deleted or all it's items were deleted
|
||||||
|
setOpenGroupItems([]);
|
||||||
|
setOpenGroupId();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
setOpenGroupItems([]);
|
setOpenGroupItems([]);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,6 @@ export function TileDragProvider({
|
|||||||
selectedGroupIds,
|
selectedGroupIds,
|
||||||
onGroupsChange,
|
onGroupsChange,
|
||||||
onGroupSelect,
|
onGroupSelect,
|
||||||
onGroupClose,
|
|
||||||
filter,
|
filter,
|
||||||
} = useGroup();
|
} = useGroup();
|
||||||
|
|
||||||
@ -147,10 +146,6 @@ export function TileDragProvider({
|
|||||||
onGroupSelect();
|
onGroupSelect();
|
||||||
// Handle tile ungroup
|
// Handle tile ungroup
|
||||||
const newGroups = ungroup(groups, openGroupId, selectedIndices);
|
const newGroups = ungroup(groups, openGroupId, selectedIndices);
|
||||||
// Close group if it was removed
|
|
||||||
if (!newGroups.find((group) => group.id === openGroupId)) {
|
|
||||||
onGroupClose();
|
|
||||||
}
|
|
||||||
onGroupsChange(newGroups);
|
onGroupsChange(newGroups);
|
||||||
} else if (over.id === ADD_TO_MAP_ID) {
|
} else if (over.id === ADD_TO_MAP_ID) {
|
||||||
onDragAdd &&
|
onDragAdd &&
|
||||||
|
@ -31,7 +31,9 @@ export function groupsFromIds(groupIds, groups) {
|
|||||||
const groupsByIds = keyBy(groups, "id");
|
const groupsByIds = keyBy(groups, "id");
|
||||||
const filteredGroups = [];
|
const filteredGroups = [];
|
||||||
for (let groupId of groupIds) {
|
for (let groupId of groupIds) {
|
||||||
filteredGroups.push(groupsByIds[groupId]);
|
if (groupId in groupsByIds) {
|
||||||
|
filteredGroups.push(groupsByIds[groupId]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return filteredGroups;
|
return filteredGroups;
|
||||||
}
|
}
|
||||||
@ -259,6 +261,10 @@ export function removeGroupsItems(groups, itemIds) {
|
|||||||
newGroups[i].items.splice(j, 1);
|
newGroups[i].items.splice(j, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Remove group if no items are left
|
||||||
|
if (newGroups[i].items.length === 0) {
|
||||||
|
newGroups.splice(i, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user