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

Put cloneData function for slate block, in order to change the uuids of fragments #5518

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6cdacde
Put cloneData function for slate block, in order to change the uuids …
dobri1408 Dec 12, 2023
ff4d5b7
Update index.js
dobri1408 Dec 13, 2023
a687633
Create 5518.feature
dobri1408 Dec 13, 2023
2018042
Create 5518.feature
dobri1408 Dec 13, 2023
707fb03
Update index.js
dobri1408 Dec 13, 2023
ed7f975
Delete packages/volto/news/5518.feature
dobri1408 Dec 13, 2023
c616845
Create 5518.bugfix
dobri1408 Dec 13, 2023
aff3697
Delete packages/volto-slate/news/5518.feature
dobri1408 Dec 13, 2023
511e99d
Update packages/volto-slate/news/5518.bugfix
dobri1408 Dec 13, 2023
6d2af88
Merge branch 'main' into cloneData-slate
dobri1408 Dec 13, 2023
122322b
Merge branch 'main' into cloneData-slate
dobri1408 Dec 13, 2023
b756359
Create a better cloneData, that doesn't add new properties
dobri1408 Dec 13, 2023
a5ffdba
Merge branch 'main' into cloneData-slate
dobri1408 Dec 13, 2023
4892569
Merge branch 'main' into cloneData-slate
dobri1408 Dec 13, 2023
8803484
Merge branch 'main' into cloneData-slate
dobri1408 Dec 14, 2023
8ba748d
Merge branch 'main' into cloneData-slate
dobri1408 Dec 15, 2023
6e4c175
Merge branch 'main' into cloneData-slate
dobri1408 Dec 16, 2023
d29d9d9
Merge branch 'main' into cloneData-slate
dobri1408 Dec 17, 2023
6d67579
Merge branch 'main' into cloneData-slate
dobri1408 Dec 18, 2023
fdec971
Merge branch 'main' into cloneData-slate
dobri1408 Dec 27, 2023
5df64d1
Merge branch 'main' into cloneData-slate
dobri1408 Dec 28, 2023
c74033c
Merge branch 'main' into cloneData-slate
dobri1408 Jan 8, 2024
f3cef86
Merge branch 'main' into cloneData-slate
dobri1408 Jan 10, 2024
2b66e67
Merge branch 'main' into cloneData-slate
dobri1408 Jan 11, 2024
f193a9f
Merge branch 'main' into cloneData-slate
dobri1408 Jan 14, 2024
c55caae
Merge branch 'main' into cloneData-slate
dobri1408 Jan 22, 2024
ee15648
Merge branch 'main' into cloneData-slate
dobri1408 Jan 29, 2024
05aabd6
Merge branch 'main' into cloneData-slate
dobri1408 Feb 26, 2024
20680f6
Merge branch 'main' into cloneData-slate
dobri1408 Feb 28, 2024
d3ae95e
add test
dobri1408 Mar 1, 2024
c6e7ef4
Merge branch 'main' into cloneData-slate
dobri1408 Mar 1, 2024
f98b7a6
Merge branch 'main' into cloneData-slate
dobri1408 Mar 1, 2024
d62d505
fail test
dobri1408 Mar 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/volto-slate/news/5518.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When copying a text block—implemented in Slate—using the sidebar that contains UUIDs attached to elements in the data, the UUIDs get copied into the new block, making them not unique. Now instead of duplicating the UUIDs, a unique nanoid will be generated and assigned to the copy, preserving uniqueness. @dobr1408
dobri1408 marked this conversation as resolved.
Show resolved Hide resolved
24 changes: 24 additions & 0 deletions packages/volto-slate/src/blocks/Text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import TextBlockView from './TextBlockView';
import TextBlockEdit from './TextBlockEdit';
import TextBlockSchema from './TextBlockSchema';

import { nanoid } from '@plone/volto-slate/utils';
import { v4 as uuid } from 'uuid';

import {
goDown,
goUp,
Expand Down Expand Up @@ -118,6 +121,27 @@ export default function applyConfig(config) {
addPermission: [],
view: [],
},
cloneData: (data) => {
return [
uuid(),
{
...data,
value: [
...(data?.value || []).map((c) => {
return {
...c,
children: (c?.children || []).map((childrenData) => {
Copy link
Member

Choose a reason for hiding this comment

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

Won't this add children to nodes that should not have it, like text nodes?

I would really like to see a test for this feature.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes this is true, I will modify, and add tests

return {
...childrenData,
data: { ...childrenData.data, uid: nanoid(5) },
Copy link
Member

Choose a reason for hiding this comment

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

This will add a uid even if there wasn't one there before; is that what we want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think that all children have uid by default

Copy link
Member

Choose a reason for hiding this comment

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

No, I don't think so. I have not seen it before.

};
}),
};
}),
],
},
];
},
blockHasValue: (data) => {
// TODO: this should be handled better
return data && !!data.plaintext?.trim();
Expand Down