Skip to content

Commit

Permalink
fix: move an existing item from children if it has to move
Browse files Browse the repository at this point in the history
  • Loading branch information
Plopix committed Jul 3, 2024
1 parent f986b6f commit 0092300
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-eggs-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@crystallize/import-utilities': minor
---

fix the move of an existing item in children
5 changes: 3 additions & 2 deletions src/bootstrap-tenant/bootstrapper/items/createOrUpdateItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EVENT_NAMES,
ItemEventPayloadCreatedOrUpdated,
getItemVersionsForLanguages,
getTenantRootItemId,
getTranslation,
validShapeIdentifier,
} from '../utils'
Expand Down Expand Up @@ -546,7 +547,7 @@ export async function createOrUpdateItem(
context,
})
}

const realRootItemId = await getTenantRootItemId(context)
if (item._options?.moveToRoot) {
if (item._parentId !== rootItemId) {
await context.callPIM({
Expand All @@ -559,7 +560,7 @@ export async function createOrUpdateItem(
item._exists &&
item._parentId !== parentId &&
itemId !== parentId &&
parentId !== rootItemId // Do not move items to root unless _moveToRoot is set
parentId !== realRootItemId // Do not move items to root unless _moveToRoot is set
) {
/**
* Move the item if it is a part of a children array,
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap-tenant/bootstrapper/items/handleItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ export async function handleItem(
if (!item) {
return finishedItems
}

let parentId = rootItemId

// updating the id and parentId of the item from the DB
const itemAndParentId = await getItemId({
context,
externalReference: item.externalReference,
Expand All @@ -33,6 +33,7 @@ export async function handleItem(
item.id = itemAndParentId.itemId
item._parentId = itemAndParentId.parentId

// if that's mention in the spec, we take the parent id
if (item.parentExternalReference || item.parentCataloguePath) {
const parentItemAndParentId = await getItemId({
context,
Expand Down

0 comments on commit 0092300

Please sign in to comment.