-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Devrel 1068 import item and variants #15
Conversation
let's test the situation when having option of multiple choice element with name same as some other element in the same content_type.. external_ids might collide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, there might be problem with external ids. Otherwise the logic looks good, however, I would do some refactoring, code is hard to follow, I would extract some variables of functions
if (el.type === "snippet") { | ||
const typedEl = el as unknown as ContentTypeElements.ISnippetElement; | ||
return [ | ||
...context.contentTypeSnippetContextWithElementsByOldIds.get(typedEl.snippet.id ?? "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: contentTypeSnippetContextByOldIds
src/commands/import.ts
Outdated
contentTypeIdsWithElementsByOldIds: new Map(), | ||
contentTypeSnippetContextWithElementsByOldIds: new Map(), | ||
contentItemContextByOldIds: new Map(), | ||
contentTypeContextWithElementsByOldIds: new Map(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ContentTypeContextByOldIds
@@ -18,13 +18,58 @@ export const contentTypesEntity: EntityDefinition<ReadonlyArray<ContentTypeContr | |||
|
|||
return { | |||
...context, | |||
contentTypeIdsWithElementsByOldIds: new Map( | |||
contentTypeContextWithElementsByOldIds: new Map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is getting kind of hard to read.. let's extract those maps into variables
The other option is to create functions for map lambdas to kind of getting easier for eyes
@@ -92,7 +137,7 @@ const createUpdateTypeItemReferencesFetcher = | |||
|
|||
return params.client | |||
.modifyContentType() | |||
.byTypeId(params.context.contentTypeIdsWithElementsByOldIds.get(type.id)?.selfId ?? "") | |||
.byTypeId(params.context.contentTypeContextWithElementsByOldIds.get(type.id)?.selfId ?? "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use codename if i understand this correctly :)
@@ -21,15 +21,42 @@ export const contentTypesSnippetsEntity: EntityDefinition< | |||
|
|||
return { | |||
...context, | |||
contentTypeSnippetIdsWithElementsByOldIds: new Map( | |||
contentTypeSnippetContextWithElementsByOldIds: new Map( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's refactor this a bit... mayb extracting maps into variables?
.withData(builder => ({ | ||
workflow: { | ||
workflow_identifier: { | ||
id: newWfContext.wfId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: i would use workflowId
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, but isn't wf an obvious abbreviation in this context?
.byLanguageId(variant.language.id ?? ""); | ||
|
||
return scheduleTo | ||
? await sharedRequest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need await here, when you are awaiting when using the publishVariant function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I do not. 👍
( | ||
fileElement: ElementContracts.IContentItemElementContract, | ||
): LanguageVariantElements.ILanguageVariantElementBase | null => { | ||
const elementType = params.elementTypeByOldId.get(fileElement.element.id ?? ""); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use as string to indicate that fileElement.element must have an id
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the other comment I made.
context.worfklowStepsIdsWithTransitionsByOldIds.get(stepId)?.selfId ?? ""; | ||
|
||
const getProjectElementId = (params: TransformElementParams, fileId: string): string | null => | ||
Array.from(params.context.contentTypeSnippetContextWithElementsByOldIds.values()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this use only contentTypeSnippets and no also contentTypes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nwm I see it now, but it's kind of hard to follow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I managed to inline the snippets here as well. The snippet elements don't need an update later on so I don't need their ids anyway.
@@ -272,7 +273,7 @@ export const createPatchItemAndTypeReferencesInTypeElement = | |||
op: "replace" as const, | |||
path: `/elements/id:${newElementId}/allowed_content_types`, | |||
value: typedElement.allowed_content_types.map(ref => ({ | |||
id: context.contentTypeIdsWithElementsByOldIds.get(ref.id ?? "")?.selfId, | |||
id: context.contentTypeContextWithElementsByOldIds.get(ref.id ?? "")?.selfId, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use codenames?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codenames are not in scope. I would have to add them into the context, but the ids are already there so I can as well use them.
It seems that the external id of a multi-choice element's option must be unique even across multiple types. I changed it to use external ids like so: |
Since Ivan is on a long vacation, I will merge this for now. We can talk about the comments later. |
Change fallback multi-choice option externalId so it is unique across multiple types
de2a6f0
to
484fcb0
Compare
Motivation
Which issue does this fix? Fixes #
issue number
If no issue exists, what is the fix or new feature? Were there any reasons to fix/implement things that are not obvious?
Checklist
How to test
If manual testing is required, what are the steps?