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

Clone row on duplicate In structure field #6073

Closed
georgobermayr opened this issue Dec 17, 2023 · 1 comment · Fixed by #6094
Closed

Clone row on duplicate In structure field #6073

georgobermayr opened this issue Dec 17, 2023 · 1 comment · Fixed by #6094
Assignees
Milestone

Comments

@georgobermayr
Copy link

Description

I have a very strange issue in a custom field implementation: I moved the actual editing of the blocks field into a drawer. This works fine. However, if have an issue with structure fields inside of a block, when using my custom field:

  • I'm duplicating an existing structure row with content
  • I edit the new row
  • Changes I do in the duplicated row are also made in the original row. This is the case for all fields with arrays or objects as data structures, e.g. blocks, files, …. But not for simple text fields.
  • Once I reload the Panel, everything works fine and my changes are only happening in the row I'm currently working on.

With the original Kirby implementation everything works fine. But for some reason it occurs with my custom field.

Expected behavior
The content of the duplicated structure should only be changed in the duplicated row and not also in the original row.

Sugessted fix
After a lot of digging I didn't find the issue witting my field implementation. However I found a way to fix it within Kirby. In the Structure field component (https://github.com/getkirby/kirby/blob/main/panel/src/components/Forms/Field/StructureField.vue#L458) instead of doing:

case "duplicate":
	this.add({
		...row,
		_id: this.$helper.uuid()
	});
	break;

doing this:

case "duplicate":
	this.add({
		...this.$helper.clone(row),
		_id: this.$helper.uuid()
	});
	break;

is fixing the issue with row duplication/editing in my custom field. I don't know what the real root cause for the issue in my field is, but this seems to be a plausible fix for me. The same is already done for block duplication, so would it be possible, to do the cloning for structures as well?

Your setup

Kirby Version 4.0.0

distantnative added a commit that referenced this issue Dec 27, 2023
@distantnative distantnative self-assigned this Dec 27, 2023
@distantnative distantnative added this to the 4.1.0 milestone Dec 27, 2023
@distantnative distantnative linked a pull request Dec 27, 2023 that will close this issue
1 task
@bastianallgeier
Copy link
Member

Will be fixed in 4.1

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 a pull request may close this issue.

3 participants