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

Widgets API is called when loading a dashboard #4341

Closed
arikfr opened this issue Nov 10, 2019 · 5 comments · Fixed by #4228
Closed

Widgets API is called when loading a dashboard #4341

arikfr opened this issue Nov 10, 2019 · 5 comments · Fixed by #4228

Comments

@arikfr
Copy link
Member

arikfr commented Nov 10, 2019

Issue Summary

On some dashboards it happens more often than other, but I noticed that in some cases a POST request is made to some of the widgets on a dashboard when loading it.

Here's an example: https://redash-preview.netlify.com/dashboard/now-param

Technical details:

  • Redash Version: v9
  • Browser/OS: Chrome
@gabrieldutra
Copy link
Member

Those POST requests come from the DashboardGrid onLayoutChange, I think the idea is to save widgets position after they "flow". One issue is that this is currently happening in view and in edit mode, we can change that and then those requests would only happen in edit mode.

@arikfr
Copy link
Member Author

arikfr commented Nov 10, 2019

But why they happen on every load? Shouldn't it happen once, get updated, and then not happen again until something changes with the layout?

@gabrieldutra
Copy link
Member

You have a point, the function that seems to be triggering changes in the layout is this one:

function prepareWidgetsForDashboard(widgets) {
// Default height for auto-height widgets.
// Compute biggest widget size and choose between it and some magic number.
// This value should be big enough so auto-height widgets will not overlap other ones.
const defaultWidgetSizeY =
Math.max(
_
.chain(widgets)
.map(w => w.options.position.sizeY)
.max()
.value(),
20,
) + 5;
// Fix layout:
// 1. sort and group widgets by row
// 2. update position of widgets in each row - place it right below
// biggest widget from previous row
_.chain(widgets)
.sortBy(widget => widget.options.position.row)
.groupBy(widget => widget.options.position.row)
.reduce((row, widgetsAtRow) => {
let height = 1;
_.each(widgetsAtRow, (widget) => {
height = Math.max(
height,
widget.options.position.autoHeight ? defaultWidgetSizeY : widget.options.position.sizeY,
);
widget.options.position.row = row;
if (widget.options.position.sizeY < 1) {
widget.options.position.sizeY = defaultWidgetSizeY;
}
});
return row + height;
}, 0)
.value();
// Sort widgets by updated column and row value
widgets = _.sortBy(widgets, widget => widget.options.position.col);
widgets = _.sortBy(widgets, widget => widget.options.position.row);
return widgets;
}

I'll investigate this further, but so far it seems to be updating the row for widgets that are not in the first row.

@arikfr
Copy link
Member Author

arikfr commented Nov 11, 2019

You have a point, the function that seems to be triggering changes in the layout is this one:

Maybe we should remove this functionality, because layout might change often when auto-height is used and there is no harm in /not/ preserving it.

@gabrieldutra
Copy link
Member

Removed it in #4228, there indeed seems to be no harm in removing it and those POST requests stopped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants