Skip to content

Commit

Permalink
Search for multichoice element by codename, Make content group extern…
Browse files Browse the repository at this point in the history
…al ids unique across different types
  • Loading branch information
JiriLojda committed Jan 17, 2024
1 parent e844a55 commit a2482fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/commands/importExportEntities/entities/contentTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const createMakeTypeContextByOldIdEntry = (context: ImportContext) =>
}
case "multiple_choice": {
const typedEl = el as MultiChoiceElement;
const typedProjectEl = projectType.elements.find(e => e.id === el.id) as MultiChoiceElement;
const typedProjectEl = projectType.elements.find(e => e.codename === el.codename) as MultiChoiceElement;

return [[
el.id,
Expand All @@ -130,13 +130,18 @@ const createMakeTypeContextByOldIdEntry = (context: ImportContext) =>
const createInsertTypeFetcher = (params: InsertTypeParams) => (type: Type) => async () => {
logInfo(params.logOptions, "verbose", `Importing: type ${type.id} (${chalk.yellow(type.name)})`);

const makeGroupFallbackExternalId = (groupCodename: string | undefined) => `${type.codename}_${groupCodename}`;

return params.client
.addContentType()
.withData(builder => ({
name: type.name,
codename: type.codename,
external_id: type.external_id ?? type.codename,
content_groups: type.content_groups?.map(g => ({ ...g, external_id: g.external_id ?? g.codename })),
content_groups: type.content_groups?.map(g => ({
...g,
external_id: g.external_id ?? makeGroupFallbackExternalId(g.codename),
})),
elements: type.elements.map(createTransformTypeElement({
...params,
builder,
Expand All @@ -145,7 +150,8 @@ const createInsertTypeFetcher = (params: InsertTypeParams) => (type: Type) => as
type.elements.map(el => [el.id, el.external_id ?? `${type.codename}_${el.codename}`]),
),
contentGroupExternalIdByOldId: new Map(
type.content_groups?.map(g => [g.id, g.external_id ?? g.codename ?? ""] as const) ?? [],
type.content_groups
?.map(g => [g.id, g.external_id ?? makeGroupFallbackExternalId(g.codename)] as const) ?? [],
),
})),
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const makeSnippetContextByOldIdEntry = (

const typedEl = el as MultiChoiceElement;
const projectTypedEl = projectSnippet.elements
.find(e => e.id === el.id) as MultiChoiceElement;
.find(e => e.codename === el.codename) as MultiChoiceElement;
const multiChoiceOptionEntries = zip(typedEl.options, projectTypedEl.options)
.map(([fO, pO]) => [fO.id, pO.id] as const);

Expand Down

0 comments on commit a2482fa

Please sign in to comment.