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

Filter is overzealous in Adapt.findRelativeModel #3031

Closed
tomgreenfield opened this issue Feb 11, 2021 · 0 comments · Fixed by #3033
Closed

Filter is overzealous in Adapt.findRelativeModel #3031

tomgreenfield opened this issue Feb 11, 2021 · 0 comments · Fixed by #3033
Assignees
Labels

Comments

@tomgreenfield
Copy link
Contributor

Subject of the issue/enhancement/features

options.filter in Adapt.findRelativeModel erroneously filters out the current model producing inconsistencies:

// filter if opinionated
if (typeof options.filter === 'function') {
pageDescendants = pageDescendants.filter(options.filter);
}

Your environment

Framework 5.10

Steps to reproduce

In the core-bundled course, run the following in the console to make co-10 optional and attempt to retrieve its previous (mandatory) page ID:

require('core/js/adapt').findById('co-10')
  .set('_isOptional', true)
  .findRelativeModel('contentobject -1', {
    filter: model => !model.get('_isOptional')
  }).get('_id');

Expected behaviour

"co-05" should be returned from the above code.

Actual behaviour

The following is returned because co-10 filters itself out:

adaptModel.js:527 Uncaught TypeError: Cannot read property 'isTypeGroup' of undefined
    at PageModel.findRelativeModel (adaptModel.js:527)
    at <anonymous>:3:4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant