Skip to content
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

Merged
merged 2 commits into from
Jan 8, 2024

Conversation

JiriLojda
Copy link
Member

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

  • Code follows coding conventions held in this repo
  • Automated tests have been added
  • Tests are passing
  • Docs have been updated (if applicable)
  • Temporary settings (e.g. variables used during development and testing) have been reverted to defaults

How to test

If manual testing is required, what are the steps?

@JiriLojda JiriLojda requested a review from a team as a code owner January 4, 2024 11:25
@IvanKiral
Copy link
Contributor

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

Copy link
Contributor

@IvanKiral IvanKiral left a 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 ?? "")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: contentTypeSnippetContextByOldIds

contentTypeIdsWithElementsByOldIds: new Map(),
contentTypeSnippetContextWithElementsByOldIds: new Map(),
contentItemContextByOldIds: new Map(),
contentTypeContextWithElementsByOldIds: new Map(),
Copy link
Contributor

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(
Copy link
Contributor

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 ?? "")
Copy link
Contributor

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(
Copy link
Contributor

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,
Copy link
Contributor

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

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

@JiriLojda JiriLojda Jan 5, 2024

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 ?? "");
Copy link
Contributor

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

Copy link
Member Author

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())
Copy link
Contributor

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?

Copy link
Contributor

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

Copy link
Member Author

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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use codenames?

Copy link
Member Author

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.

@JiriLojda
Copy link
Member Author

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

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: {type/snippet codename}_{element codename}_{option codename}

@JiriLojda
Copy link
Member Author

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
@JiriLojda JiriLojda force-pushed the DEVREL-1068_import_item_and_variants branch from de2a6f0 to 484fcb0 Compare January 8, 2024 10:44
@JiriLojda JiriLojda merged commit a557c25 into main Jan 8, 2024
1 check passed
@JiriLojda JiriLojda deleted the DEVREL-1068_import_item_and_variants branch January 8, 2024 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants