Skip to content

Commit

Permalink
fix getBatchAncestryWithSelfQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangohjw committed Dec 25, 2024
1 parent f9d476d commit caf24be
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions apps/studio/src/server/modules/resource/resource.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -484,18 +484,23 @@ export const getBatchAncestryWithSelfQuery = async ({
if (!currentResource) break

// Group all resources that are found in the current resource's path
const group = currentResource.path
.map(
(childId) =>
remainingResources.find((item) => item.id === childId) ??
currentResource,
)
.filter(Boolean)
const group = [currentResource].concat(
currentResource.path
.slice(1) // without the current resource
.map(
(childId) =>
remainingResources.find((item) => item.id === childId) ??
currentResource,
)
.filter(Boolean),
)

// Remove all items in this group from remainingResources
group.forEach((node) => {
const index = remainingResources.findIndex(
(resource) => resource.id === node.id,
(resource) =>
resource.id === node.id &&
JSON.stringify(resource.path) === JSON.stringify(node.path),
)
if (index !== -1) remainingResources.splice(index, 1)
})
Expand Down

0 comments on commit caf24be

Please sign in to comment.