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

[v4] Nested structure loses content #5385

Closed
medienbaecker opened this issue Jul 19, 2023 · 16 comments
Closed

[v4] Nested structure loses content #5385

medienbaecker opened this issue Jul 19, 2023 · 16 comments
Milestone

Comments

@medienbaecker
Copy link
Contributor

Description

When using a structure field inside of a structure field, the content of the entries in the nested structure field seems to get lost.

nested-structure

To reproduce

  1. Create a nested structure field:
structure:
    fields:
      structure:
        label: Nested Structure
        type: structure
        fields:
          text: true
  1. Add a structure entry to the top-level structure field
  2. Add an entry to the nested structure field with some content
  3. Close the drawer, click the little checkmark button or hit ⌘S
  4. The content is gone

Your setup

Kirby Version
4.0.0-alpha.5

Your system (please complete the following information)

  • OS: macOS Ventura 13.4.1
  • Browser: Chrome
  • Version: 115
@bastianallgeier
Copy link
Member

I've just set up a test setup to reproduce it and unfortunately it happens for me as well. Just to confirm, do you already notice that the content will stay as soon as you try again?

@afbora afbora added this to the 4.0.0 milestone Jul 19, 2023
@medienbaecker
Copy link
Contributor Author

Just to confirm, do you already notice that the content will stay as soon as you try again?

@bastianallgeier Sorry, I'm afraid I don't understand your question. It looks like the content is just cosmetic. When editing the nested structure field I don't even get the "Revert/Save" prompt.

@afbora
Copy link
Member

afbora commented Jul 19, 2023

As far as I have tested, the last added row is not emitted. The input is triggered but not saved to localStorage. But I could not find the cause of the issue.

@MathiasGmeiner
Copy link

For me it happens for nested blocks as well.

@bastianallgeier
Copy link
Member

@MathiasGmeiner nested blocks in a structure field?

@MathiasGmeiner
Copy link

MathiasGmeiner commented Jul 20, 2023

@bastianallgeier no, sorry for being so vague. I'm dealing with nested blocks in a blocks field. Could this be a different issue altogether? My first try was a structure field within a block field, and then I tried a block inside a block field.

@bastianallgeier
Copy link
Member

@MathiasGmeiner I'll try to reproduce this, but in our current nested blocks test setup I didn't notice this so far.

@MathiasGmeiner
Copy link

@bastianallgeier ok, let me know if I can help.

@hotdoy
Copy link

hotdoy commented Jul 20, 2023

I have the same issue in nested structures. I can send you my BPs if needed.

@MathiasGmeiner
Copy link

I'm not sure if I'm doing something wrong with the nested block setup.
This is my setup:

test.yml

name: Test
fields:
  blocks:
    type: blocks
    fieldsets:
      - test-item

test-item.yml

name: Test Item
fields:
  text:
    label: Test
    type: text

CleanShot 2023-07-21 at 07 44 37

@iskrisis
Copy link

Can confirm between alpha.4 and alpha.5 there is a problem with saving nested structures. For us it happens in blocks in block that has structure. When the structure is saved it keeps content only of the first row all other rows are empty (but they are there). It's like the content of rows is set to "".
Works on alpha.4.

@afbora
Copy link
Member

afbora commented Jul 22, 2023

After dozens of tests I still can't find out what is causing the problem, but when I edit the code below I see that it works. Maybe it will give you an idea @bastianallgeier @distantnative

add(value = null) {
    if (this.more === false) {
        return false;
    }

    value = value ?? this.$helper.field.form(this.fields);

    let index = 0;

    if (this.prepend === true) {
        this.items.unshift(value);
        index = 0;
    } else {
        this.items.push(value);
        index = this.items.length - 1;
    }

-   this.save();
    this.open(index);
},
close() {
    this.$panel.drawer.close();
},

/**
 * Focuses the add button
 * @public
 */
focus() {
    this.$refs.add?.focus?.();
},
/**
 * Opens form for a specific row at index
 * with field focussed
 * @param {number} index
 * @param {string} field
 */
jump(index, field) {
    this.open(index + this.pagination.offset, field);
},

/**
 * Edit the structure field entry at `index` position
 * in the structure form with field `field` focused
 * @public
 * @param {number} index
 * @param {string} field
 */
open(index, field, replace = false) {
    if (this.disabled === true || !this.items[index]) {
        return false;
    }

    this.$panel.drawer.open({
        component: "k-structure-drawer",
        props: {
            icon: this.icon ?? "list-bullet",
            next: this.items[index + 1],
            prev: this.items[index - 1],
            tabs: {
                content: {
                    fields: this.form
                }
            },
            title: this.label,
            value: this.items[index]
        },
        replace: replace,
        on: {
            input: (value) => {
                this.$set(this.items, index, value);
                this.save();
            },
            next: () => {
                this.open(index + 1, null, true);
            },
            prev: () => {
                this.open(index - 1, null, true);
            },
            remove: () => {
                this.remove(index);
            },
+           submit: () => {
+              this.save();
+              this.close();
+           }
        }
    });
},

https://github.com/getkirby/kirby/blob/4.0.0-alpha.5/panel/src/components/Forms/Field/StructureField.vue#L317-L401

@bastianallgeier
Copy link
Member

Oh man, you are a genius. Indeed it does give me an idea. I think what happens here is a reactivity race condition. Save will emit the input event, which will also update the value prop. But at the same time the drawer opens with the last state of the data array and value and the content of the drawer will be out of sync

@hotdoy
Copy link

hotdoy commented Jul 27, 2023

Happy to see some progress. ☺️

@distantnative
Copy link
Member

distantnative commented Jul 27, 2023

@hotdoy Please keep in
Und that we haven't even reached beta stage with v4.

@hotdoy
Copy link

hotdoy commented Jul 27, 2023

Yeah 😅 sorry. I took the risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

7 participants