fix(projects): make sure the project hierarchy is properly updated when moving projects between parents

This commit is contained in:
kolaente 2023-03-28 14:44:07 +02:00
parent be2a38b48e
commit f7629c28f4
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 13 additions and 1 deletions

View File

@ -72,7 +72,19 @@ export const useProjectStore = defineStore('project', () => {
// if the project is a child project, we need to also set it in the parent
if (project.parentProjectId) {
const parent = projects.value[project.parentProjectId]
parent.childProjects = parent.childProjects?.map(p => p.id === project.id ? project : p)
let foundProject = false
parent.childProjects = parent.childProjects?.map(p => {
if(p.id === project.id) {
foundProject = true
return project
}
return p
})
// If we hit this, the project now has a new parent project which it did not have before
if (!foundProject) {
parent.childProjects.push(project)
}
setProject(parent, false)
}
}