Skip to content

Commit

Permalink
Handle null widgets when filtering for scrolled seed
Browse files Browse the repository at this point in the history
  • Loading branch information
tf committed Jul 2, 2024
1 parent 3e76439 commit b00862f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 15 additions & 0 deletions package/spec/editor/collections/widgetsCollection-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,19 @@ describe('WidgetsCollection', () => {

expect(subsetCollection.pluck('type_name')).toEqual(['consent_bar']);
});

it('ignores null widgets', () => {
const widgetTypes = factories.widgetTypes([
{role: 'consent', name: 'consent_bar', insertPoint: 'react'}
]);
const widgets = new WidgetsCollection([
{type_name: 'consent_bar', role: 'consent'},
{type_name: null, role: 'other'},
], {widgetTypes});
widgets.subject = factories.entry();

const subsetCollection = widgets.withInsertPoint('react');

expect(subsetCollection.pluck('type_name')).toEqual(['consent_bar']);
});
});
4 changes: 3 additions & 1 deletion package/src/editor/collections/WidgetsCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ export const WidgetsCollection = Backbone.Collection.extend({
return new SubsetCollection({
parent: this,
watchAttribute: 'type_name',
filter: widget => widget.widgetType().insertPoint === insertPoint
filter: widget => (
widget.widgetType() && widget.widgetType().insertPoint === insertPoint
)
});
}
});

0 comments on commit b00862f

Please sign in to comment.