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

toggling _isAvailable can result in inappropriate locking #164

Open
chris-steele opened this issue Jul 21, 2022 · 2 comments · May be fixed by #224
Open

toggling _isAvailable can result in inappropriate locking #164

chris-steele opened this issue Jul 21, 2022 · 2 comments · May be fixed by #224
Assignees
Labels

Comments

@chris-steele
Copy link
Contributor

chris-steele commented Jul 21, 2022

Subject of the issue/enhancement/features

A custom plugin determines which articles are available based on some criteria. Each of these articles are configured to use trickle. The trickle plugin will set the _isLocked property on the articles and blocks as expected. At some later time all but one of the mentioned articles are set to _isAvailable:false. The article that is set to _isAvailable:true may still retain _isLocked:true. Rendering therefore stops at the article and the first block is not rendered as it should be.

Executing applyLocks does not correct the _isLocked property. Therefore, it is proposed that prior to applyLocks determining which models are locked, the _isLocked property is set to false on all models.

Your environment

  • all frameworks, devices and browsers

Steps to reproduce

See above

Expected behaviour

See above

Actual behaviour

See above

@oliverfoster
Copy link
Member

oliverfoster commented Oct 3, 2022

Chris:

Just to follow up on this. The solution I've used is to reset the _isLocked status as follows in applyLocks prior to determining _isLocked:

Adapt.course.getAllDescendantModels(true).forEach(siteModel => {
    if (siteModel.get('_isTrickled')) {
      siteModel.setOnChildren('_isLocked', false);
    }
  });

I'm not sure if this is ideal, but I've had success with it where _isAvailable is dynamically set on articles.

@danielghost
Copy link
Contributor

danielghost commented Apr 6, 2023

Can confirm I have also seen this as a result of a role selector changing the availability of the first locked model in a page hierarchy. The siteModel updates _isLocked accordingly, but doesn't apply this to its children, so they components remain locked in the PLP. Can be resolved by making https://github.com/adaptlearning/adapt-contrib-trickle/blob/master/js/models.js#L223-L226 into a method which can be run on the siteModel if it isn't found in the locks object, in addition to the subsequentLockingModels. For example:

const setDescendantLocks = ((model, id) => {
  model.getAllDescendantModels().forEach(descendant => {
    const descendantId = descendant.get('_id');
    modelsById[descendantId] = descendant;
    locks[descendantId] = locks[id];
  });
});
if (!locks[id]) setDescendantLocks(siteModel, id);

danielghost added a commit that referenced this issue May 24, 2024
…orrect locking for dynamic children order (fixes #223, fixes #164).
@danielghost danielghost linked a pull request May 24, 2024 that will close this issue
@danielghost danielghost self-assigned this May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment