Skip to content

Commit

Permalink
Select widget in preview when navigating to widget settings
Browse files Browse the repository at this point in the history
REDMINE-20895
  • Loading branch information
tf committed Feb 4, 2025
1 parent b1cfe4c commit 5129f8d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,32 @@ describe('PreviewMessageController', () => {
})).resolves.toMatchObject({type: 'SELECT', payload: {id: 1, type: 'sectionTransition'}});
});

it('sends SELECT message to iframe on selectWidget event on model', async () => {
const entry = factories.entry(ScrolledEntry, {}, {
widgetTypes: factories.widgetTypes([{
role: 'header', name: 'someNavigation'
}]),
widgetsAttributes: [{
type_name: 'someNavigation',
role: 'header'
}],
entryTypeSeed: normalizeSeed()
});
const iframeWindow = createIframeWindow();
controller = new PreviewMessageController({entry, iframeWindow});

await postReadyMessageAndWaitForAcknowledgement(iframeWindow);

return expect(new Promise(resolve => {
iframeWindow.addEventListener('message', event => {
if (event.data.type === 'SELECT') {
resolve(event.data);
}
});
entry.trigger('selectWidget', entry.widgets.first());
})).resolves.toMatchObject({type: 'SELECT', payload: {id: 'header', type: 'widget'}});
});

it('supports sending CONTENT_ELEMENT_EDITOR_COMMAND message to iframe', async () => {
const entry = factories.entry(ScrolledEntry, {}, {
entryTypeSeed: normalizeSeed({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ export const PreviewMessageController = Object.extend({
})
});

this.listenTo(this.entry, 'selectWidget', widget => {
postMessage({
type: 'SELECT',
payload: {
id: widget.get('role'),
type: 'widget'
}
})
});

this.listenTo(this.entry, 'resetSelection', contentElement =>
postMessage({
type: 'SELECT',
Expand Down
6 changes: 5 additions & 1 deletion package/src/editor/controllers/SidebarController.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,13 @@ export const SidebarController = Marionette.Controller.extend({
},

widget: function(id) {
const model = this.entry.widgets.get(id);

this.region.show(new EditWidgetView({
entry: this.entry,
model: this.entry.widgets.get(id)
model
}));

this.entry.trigger('selectWidget', model);
},
});

0 comments on commit 5129f8d

Please sign in to comment.