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

Bug: Adding document with a slice doesn't work #245

Open
bobsingor opened this issue Jun 24, 2019 · 3 comments
Open

Bug: Adding document with a slice doesn't work #245

bobsingor opened this issue Jun 24, 2019 · 3 comments

Comments

@bobsingor
Copy link

I tried to add a slice to the document and when I am saving the slice and refresh the document the slice is gone and not saved.

@irisjae
Copy link

irisjae commented Sep 12, 2019

This problem occurs when slices are not marked as 'Allow multiple slices'. Isolated the problem to this code fragment in prime-core/src/utils/DocumentTransformer.ts. For some reason, even though 'Allow multiple slices' is disabled, the value of the field is an array with one value, so the else case is triggered; and value.__inputname is undefined, causing the save to fail.

      if (field.type === 'slice') {
        if (options.multiple && Array.isArray(value)) {
          value = (await Promise.all(
            value.map(async item => {
              const sfields = await this.getFields({ id: item.__inputname } as any);
              if (sfields) {
                return await this.transform(sfields, item, schema, io, Types.SLICE);
              }
              return {};
            })
          )).filter(item => Object.keys(item).length > 0);
        } else {
          const sfields = await this.getFields({ id: value.__inputname } as any);
          value = await this.transform(sfields, value, schema, io, Types.SLICE);
          if (Object.keys(value).length === 0) {
            continue;
          }
        }
      }

@irisjae
Copy link

irisjae commented Sep 12, 2019

Same as #244 ?

@swim
Copy link
Contributor

swim commented Oct 8, 2019

Was looking at this the other night. Transform is a recursive method that iterates over all the fields and resolves their value. Both groups and slices are handled in a very similar manner and both contain an option which allows or restricts repeated / multiples. However, both handle the side effects of toggling this option quite differently. The following steps can be followed to reproduce issue described in part here:

  1. Create new slice
  2. Add slice to a content type
  3. Set allow multiple
  4. Add multiple slices to a document
  5. Update the slice to *not allow multiple
  6. When viewing the document or document list the following error is thrown "The loader.load() function must be called with a value,but got: undefined."

When following the same steps for groups we reach a different outcome; when the repeated option is toggled with data already entered only the first value (of the array) is rendered. When the repeated option is toggled back we see the previously entered data, no loss no hard fail etc.

The following PR #361 361 aims to handle slices and groups in a similar manner.

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

No branches or pull requests

3 participants