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

fix(block-tools): enforce list support in schema #4985

Merged
merged 1 commit into from
Oct 18, 2023
Merged

fix(block-tools): enforce list support in schema #4985

merged 1 commit into from
Oct 18, 2023

Conversation

skogsmaskin
Copy link
Member

@skogsmaskin skogsmaskin commented Oct 10, 2023

Description

This will make sure that HTML is not deserialized to list blocks where there is no such support in the given schema.

What to review

That pasting HTML lists into Portable Text will not produce any list blocks with the current schema:

{
  type: 'block',
  lists: [],
}

Notes for release

  • Fixed a bug where pasting HTML lists into the Portable Text Input would disregard schema configuration for list blocks.

@vercel
Copy link

vercel bot commented Oct 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview Oct 18, 2023 9:01am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 18, 2023 9:01am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Oct 18, 2023 9:01am

@github-actions
Copy link
Contributor

No changes to documentation

@github-actions
Copy link
Contributor

github-actions bot commented Oct 10, 2023

Component Testing Report Updated Oct 18, 2023 9:03 AM (UTC)

File Status Duration Passed Skipped Failed
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 8s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 12s 3 0 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 12s 6 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 17s 9 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 58s 18 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 13s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 8s 3 0 0

Copy link
Contributor

@robinpyon robinpyon left a comment

Choose a reason for hiding this comment

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

Thanks @skogsmaskin – LGTM!

Copy link
Member

@rexxars rexxars left a comment

Choose a reason for hiding this comment

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

Nice. Left some small suggestions on code style.

Comment on lines 21 to 36
let listStyle
switch (listNodeTagName) {
case 'ul':
listStyle = 'bullet'
if (enabledListTypes.includes('bullet')) {
listStyle = 'bullet'
}
break
case 'ol':
listStyle = 'number'
if (enabledListTypes.includes('number')) {
listStyle = 'number'
}
break
default:
listStyle = 'bullet'
listStyle = undefined
}
return listStyle
Copy link
Member

Choose a reason for hiding this comment

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

This function seems a bit cumbersome to me after the conditionals were added, maybe we could simplify it?

  if (listNodeTagName === 'ul' && enabledListTypes.includes('bullet')) {
    return 'bullet'
  }
  if (listNodeTagName === 'ol' && enabledListTypes.includes('number')) {
    return 'number'
  }
  return undefined

Copy link
Member Author

Choose a reason for hiding this comment

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

Better! I've changed it, tnx!

Comment on lines 202 to 195
const enabledListItem = resolveListItem(parentTag, options.enabledListTypes)
if (!listItem || !el.parentNode || !HTML_LIST_CONTAINER_TAGS[parentTag]) {
return undefined
}
Copy link
Member

Choose a reason for hiding this comment

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

This can be moved down below the conditional, in order to not do unnecessary work:

Suggested change
const enabledListItem = resolveListItem(parentTag, options.enabledListTypes)
if (!listItem || !el.parentNode || !HTML_LIST_CONTAINER_TAGS[parentTag]) {
return undefined
}
if (!listItem || !el.parentNode || !HTML_LIST_CONTAINER_TAGS[parentTag]) {
return undefined
}
const enabledListItem = resolveListItem(parentTag, options.enabledListTypes)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, changed this as well!

HTML lists should not be deserialized to list blocks if there is no such support in schema
@skogsmaskin skogsmaskin added this pull request to the merge queue Oct 18, 2023
Merged via the queue into next with commit 318efe4 Oct 18, 2023
14 checks passed
@skogsmaskin skogsmaskin deleted the edx-567 branch October 18, 2023 09:28
rexxars pushed a commit that referenced this pull request Oct 20, 2023
HTML lists should not be deserialized to list blocks if there is no such support in schema
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.

3 participants