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

Dashboard grid React migration #1 #3722

Merged
merged 23 commits into from
May 16, 2019
Merged

Dashboard grid React migration #1 #3722

merged 23 commits into from
May 16, 2019

Conversation

ranbena
Copy link
Contributor

@ranbena ranbena commented Apr 18, 2019

  • Refactor

Description

Since gridstack has no React implementation, migrated to react-grid-layout.

Closes #3285.

Included

Not included (tests skipped)

  1. Single column breakpoint (upcoming PR)
  2. Widget auto-height (wip)

Changed

  1. Only one resize handle (bottom-right).
  2. Fixes remove widget in dashboard works only once #3202 (test allows opening menu after removal now unskipped)
  3. Fixes Widgets obscured by "Add Widget" bar #3721.

Known Issues

  1. Removing widget in preview mode, generates js error.
  2. Dragging/Resizing but no change - still a saving indication is triggered
  3. Widgets draggable beyond page as reported here. Leaving unattended.

@ranbena ranbena self-assigned this Apr 18, 2019
@ranbena ranbena added Frontend: React Frontend codebase migration to React Feature: Dashboards labels Apr 18, 2019
@ranbena ranbena added this to the Next milestone Apr 18, 2019
@ranbena
Copy link
Contributor Author

ranbena commented Apr 18, 2019

@gabrieldutra widget drag tests fail cause the placeholder now animates and also doesn't react as expected. Fiddling with it I realized there are 2 better ways to go about determining widget position delta:

  1. Disable animations when testing.
  2. Utilize the built-in retry mechanism of cyElement.should to wait until animation settles.
    I like this better. This would require sth like this:
// original
it('moves one column when dragged over snap threshold', () => {
  dragBy(cy.get('@textboxEl'), 110).then((delta) => {
    expect(delta.left).to.eq(200);
  });
});

// suggested
it('moves one column when dragged over snap threshold', () => {
  const drag = () => cy.get('@textboxEl').dragBy(110);
  const getLeft = () => cy.get('@textboxEl').invoke('offset').its('left');

  cy.get('@textboxEl').should(($el) => {
    expect(drag).to.increase(getLeft).by(200);
  });
});

But, it's not possible cause for some reason Cypress doesn't expect increase() argument to be a function, only an object, although Chai API does allow it (introduced long ago).

What am I doing wrong?
Also, did we already talk about this? 🤔

@gabrieldutra
Copy link
Member

What am I doing wrong?

Isn't this getLeft async? (as it uses cy.get) Perhaps if you turn this spec into a jQuery style by getting the element first cy.get().then(($el) => {...}). Then you should be able to run functions and assert with $el (there is a chance that the element in the variable doesn't get updated, if so, assertions won't work).

Also, did we already talk about this?

Kind of, I wanted before to use Chai with elements directly (it doesn't work at all), this is a bit different 🙂.

@gabrieldutra
Copy link
Member

I've noticed this one while playing:
to-the-infinite

@ranbena
Copy link
Contributor Author

ranbena commented Apr 19, 2019

I've noticed this one while playing:

10x @gabrieldutra, that's a grid feature I don't care for either.
Fixed in react-grid-layout/react-grid-layout#549 but not merged yet :/

It's possible we'll have to have our own fork, since the original repo is not very responsive.

@ranbena ranbena marked this pull request as ready for review April 23, 2019 06:07
Copy link
Collaborator

@kravets-levko kravets-levko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really cool 👍 (and I'm so happy that we removed that ugly old grid code). I still need to try it, but right now there are some notes about the code.

client/app/components/dashboards/dashboard-grid.jsx Outdated Show resolved Hide resolved
client/app/components/dashboards/lazyInjector.js Outdated Show resolved Hide resolved
client/app/config/dashboard-grid-options.js Outdated Show resolved Hide resolved
Copy link
Member

@gabrieldutra gabrieldutra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around a bit with the migrated features, didn't find any new issues 🙂.

+367 −727 LOC? 😮

BTW, Why dashboard-grid.jsx and not DashboardGrid.jsx?

@ranbena
Copy link
Contributor Author

ranbena commented Apr 24, 2019

I played around a bit with the migrated features, didn't find any new issues 🙂.

10x!

+367 −727 LOC? 😮

There's still 2 upcoming PRs so don't believe it yet!

BTW, Why dashboard-grid.jsx and not DashboardGrid.jsx?

Right - I started work on this PR quite long ago before we had definitive standards.

@arikfr
Copy link
Member

arikfr commented Apr 24, 2019

While trying it with the deploy preview Viz demo dashboard I noticed there is considerable lag when going into edit mode and when exiting edit mode (even when not doing any changes).

Any idea why is this?

@ranbena
Copy link
Contributor Author

ranbena commented Apr 24, 2019

While trying it with the deploy preview Viz demo dashboard I noticed there is considerable lag when going into edit mode and when exiting edit mode (even when not doing any changes).

Any idea why is this?

@arikfr when clicking "Edit", all grid item's isDraggable and isResizable props are set to true, which renders each with a react-draggable wrapper and a react-resizable wrapper. It makes sense that the more grid items, the more time it would take to init them.

Tested these props with persistent false and lag disappeared.
Didn't find related open issue in repo.
I have no simple solution in mind.

One way is to introduce lazy loaded grid items according to viewport (using the Intersection Observer API).
@kravets-levko @gabrieldutra any suggestions?

@kravets-levko kravets-levko requested review from gabrieldutra and kravets-levko and removed request for gabrieldutra May 13, 2019 09:26
Copy link
Collaborator

@kravets-levko kravets-levko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since now I'm,responsible of merging this - it looks good for me. @arikfr, @ranbena, @gabrieldutra - if you have any notices/suggestions - please leave your comments. If everyone is happy with this code - I'll merge it.

@arikfr
Copy link
Member

arikfr commented May 13, 2019

I just opened the last version on Netlify, and:

  1. The delete ('X') button is always visible.
  2. Considering you can only resize from the bottom-right corner, maybe the indicator there should be more prominent?

(2 is NTH, but 1 is a blocker of course)

@arikfr
Copy link
Member

arikfr commented May 13, 2019

Also the performance on huge dashboards isn't great, but I guess there isn't much we can do aside from pushing forward with converting widgets and visualizations to React?

@arikfr
Copy link
Member

arikfr commented May 13, 2019

Few more things:

  1. The widget dropdown menu isn't seen if the widget is too short, see the text box here: https://redash-preview.netlify.com/dashboard/short-widget.
  2. When the widget is too high, it overlaps with the bottom help box and you can't resize it. See the Albums widget on the dashboard above.
  3. The trigger to open the widget menu is vertical on widgets and horizontal on text boxes. We should pick one :)

@kravets-levko
Copy link
Collaborator

@arikfr I tested it on our React migration dashboard (which I think is pretty large): it is a bit slower when moving/resizing widgets comparing to gridster-based variant, but not too slow. I think we should migrate everything to React first, and only then test it again to decide what to do with it. Issue with lag when entering/leaving editing mode is completely fixed.

For "X" button - yeah, don't know how did I miss that. Will fix now.

@arikfr
Copy link
Member

arikfr commented May 13, 2019

Ignore 2 in my last comment -- it's actually fixed in this PR :)

@ranbena
Copy link
Contributor Author

ranbena commented May 13, 2019

@kravets-levko can you rebase with master?

@kravets-levko
Copy link
Collaborator

kravets-levko commented May 13, 2019

@ranbena Done

@ranbena
Copy link
Contributor Author

ranbena commented May 13, 2019

@kravets-levko I thought it wasn't cause it's missing the grid markings #3656 but it's actually a bug.
I can work on it and push to this branch.

@ranbena
Copy link
Contributor Author

ranbena commented May 13, 2019

@kravets-levko I pushed the fix. Tested on Chrome/FF/Safari on Mac. Tested public dashboard.
Added one change: markings now appear also when there are no widgets in dashboard yet 🤟

@ranbena
Copy link
Contributor Author

ranbena commented May 13, 2019

@arikfr

Before After
Screen Shot 2019-05-13 at 17 27 47 Screen Shot 2019-05-13 at 17 28 23

@arikfr arikfr merged commit 606cf12 into master May 16, 2019
@arikfr arikfr deleted the 1-grid-migration branch May 16, 2019 12:43
@arikfr
Copy link
Member

arikfr commented May 16, 2019

Merged 🚀

harveyrendell pushed a commit to pushpay/redash that referenced this pull request Nov 14, 2019
* Dashboard grid React migration

* Updated tests

* Fixes comments

* One col layout

* Tests unskipped

* Test fixes

* Test fix

* AutoHeight feature

* Kebab-cased

* Get rid of lazyInjector

* Replace react-grid-layout with patched fork to fix performance issues

* Fix issue with initial layout when page has a scrollbar

* Decrease polling interval (500ms is too slow)

* Rename file to match it's contents

* Added some notes and very minor fixes

* Fix Remove widget button (should be visible only in editing mode); fix widget actions menu

* Fixed missing grid markings

* Enhanced resize handle

* Updated placeholder color

* Render DashboardGrid only when dashboard is loaded
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature: Dashboards Frontend: React Frontend codebase migration to React
Projects
None yet
4 participants