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

refactor(@sanity): remove warning for when child within PTE has no key #6565

Merged
merged 8 commits into from
May 6, 2024

Conversation

RitaDias
Copy link
Contributor

@RitaDias RitaDias commented May 3, 2024

Description

Working on removing some warnings from PTE when we can self fix it ourselves.
In this case we are removing the warning when a child doesn't have a _key then the PTE should automatically create one for them.

What to review

Check that it makes sense, there are automated tests.

Testing

If you choose to do it manually you can create a document via de CLI such as:

{
  "_type": "simpleBlock",
  "body": [
    {
      "_key": "a03bf79532e8",
      "_type": "block",
      "children": [
        {
          "_type": "span",
          "marks": [],
          "text": "a test with text"
        }
      ],
      "markDefs": [],
      "style": "normal"
    }
  ],
}

when you enter that document in the test studio you will then be able to see that

  1. the warning doesn't appear
  2. that when inspecting the doc the child in question will have a key

Notes for release

When child within the PTE is created with a _key, we now automatically create one for it avoiding unnecessary warning.

Copy link

vercel bot commented May 3, 2024

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

Name Status Preview Comments Updated (UTC)
performance-studio ✅ Ready (Inspect) Visit Preview May 6, 2024 0:38am
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2024 0:38am
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 6, 2024 0:38am
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview May 6, 2024 0:38am

Copy link
Contributor

github-actions bot commented May 3, 2024

No changes to documentation

@RitaDias RitaDias changed the title Edx 396 refactor(@sanity): remove warning for when child within PTE has no key May 3, 2024
Copy link
Contributor

github-actions bot commented May 3, 2024

Component Testing Report Updated May 6, 2024 12:43 PM (UTC)

File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 42s 14 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 6s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 26s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 20s 6 3 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 36s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 5s 15 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 5s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 7s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 20s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 14s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 22s 9 0 0

@@ -59,6 +60,13 @@ export function createWithSchemaTypes({
const key = span._key || keyGenerator()
Transforms.setNodes(editor, {...span, _type: schemaTypes.span.name, _key: key}, {at: path})
}

// catches cases when the children are missing keys but excludes it when the normalize is running the node as the editor object
if (node._key === undefined && !_.isEqual(node, editor)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@skogsmaskin had to add the condition since the tests showed that the editor itself was falling in this condition (since it has no _key itself)

Copy link
Member

@skogsmaskin skogsmaskin left a comment

Choose a reason for hiding this comment

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

Great with tests for this, and good catch that we need to test the node for what it is.
I have some small comments on this which I'd like to change.

Copy link
Member

@skogsmaskin skogsmaskin left a comment

Choose a reason for hiding this comment

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

Thanks @RitaDias !

@RitaDias RitaDias added this pull request to the merge queue May 6, 2024
Merged via the queue into next with commit e1fc2a0 May 6, 2024
39 checks passed
@RitaDias RitaDias deleted the edx-396 branch May 6, 2024 13:05
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