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

Migrate Pivot Table visualization to React #4133

Merged
merged 14 commits into from
Sep 22, 2019
Merged

Migrate Pivot Table visualization to React #4133

merged 14 commits into from
Sep 22, 2019

Conversation

gabrieldutra
Copy link
Member

@gabrieldutra gabrieldutra commented Sep 11, 2019

What type of PR is this? (check all applicable)

  • Refactor

Description

Migration for the Pivot Table Visualization

  • Render updated Pivot Table
  • Make Editor settings work
  • Clean up old code
  • Add tests
  • Review changes and manual test

Related Tickets & Documents

--

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

react-pivot-visualization

@gabrieldutra gabrieldutra added Frontend Visualizations Frontend: React Frontend codebase migration to React labels Sep 11, 2019
@gabrieldutra gabrieldutra self-assigned this Sep 11, 2019
@arikfr arikfr mentioned this pull request Sep 11, 2019
24 tasks
@@ -1,10 +1,10 @@
import { isArray, indexOf, get, map, includes, every, some, toNumber, toLower } from 'lodash';
import { isArray, indexOf, get, map, includes, every, some, toNumber } from 'lodash';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this related to this PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I faced an issue with the react version, it doesn't handle Moment values as the jQuery version does. The jQuery tries to stringfy it, while the react version just breaks the whole thing.

So I was thinking about moving the logic we have to normalize row values for Filters somewhere shared and use it here as well.

@gabrieldutra
Copy link
Member Author

The React version doesn't have the rowTotals and colTotals options (it seems someone implemented that in plotly/react-pivottable#79, however it also seems inactive 😅), so I went with a css approach to that.


&[data-hide-row-totals] {
td:last-child, th:last-child {
&.pvtTotalLabel:not(:empty), &.pvtTotal, &.pvtGrandTotal {
Copy link
Member Author

Choose a reason for hiding this comment

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

the :not(:empty) here avoids us to hide this cell (that I actually have no idea why it now has .pvtTotalLabel):

image

Copy link
Member Author

@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.

@kravets-levko considering this was my first work related to React Visualizations, lmk if I forgot ath 🙂.

allowClear={filter.multiple}
filterOption={(searchText, option) => includes(toLower(option.props.children), toLower(searchText))}
optionFilterProp="children"
Copy link
Member Author

Choose a reason for hiding this comment

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

Took the opportunity to simplify this

@@ -168,3 +169,18 @@ export function join(arr) {

return arr.join(' / ');
}

export function formatColumnValue(value, columnType = null) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Just moved this from Filters.jsx. This seemed the best place to put it, LMK if you have somewhere else in mind.

@@ -13,16 +29,6 @@
background: #fff;
}

.pvtUi {
td, th {
padding: 5px;
Copy link
Member Author

Choose a reason for hiding this comment

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

5px is the default now

padding: 5px;
}

li.ui-sortable-handle {
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't find any .ui-sortable-handle, also it didn't seem that important

Copy link
Collaborator

Choose a reason for hiding this comment

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

.ui-<whatever> prefixes are related to jQuery.UI - I hope React components don't use it 😁

cy.getByTestId(getWidgetTestId(widget))
.within(() => cy.getByTestId('PivotTableVisualization').should('exist'));
});
cy.percySnapshot('Visualizations - Pivot Table');
Copy link
Member Author

Choose a reason for hiding this comment

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

It seemed too hard to make sure those features won't break by assertions, so I went with Percy for the job and created a Dashboard with different Pivot Tables 😁. Also used the API for everything.

Added a cy.all to work as a Promise.all for Cypress chains (related issue).

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 good 👍 I still want to test it on preview instance, and left a few comments (not a blocker though - everything can be kept as is)


useEffect(() => {
setConfig({ data: formatRows(data), ...options });
}, [data, options]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it could be replaced with useMemo; also, you can remove setConfig from onChange: updated options will do a trip through onOptionsChange and chart editor and return back to the component where useMemo will pick them up (I'm not 100% sure if it will work, but I hope so 😁):

const config = useMemo(
  () => ({ data: formatRows(data), ...options }), 
  [data, options]
);

Copy link
Member Author

Choose a reason for hiding this comment

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

My reasoning for using a state here is that from my understanding onOptionsChange will only "exist" (something else than () => {}) when in Editor context. However, for the Pivot Table it has the possibility of keeping the controls in the visualization, so I wanted to keep them updating internally even though it's not persisted.

In a more practical way, this is what happens when I use useMemo:
pivottable-usememo

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it 👍 Then let's keep as is

padding: 5px;
}

li.ui-sortable-handle {
Copy link
Collaborator

Choose a reason for hiding this comment

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

.ui-<whatever> prefixes are related to jQuery.UI - I hope React components don't use it 😁

@arikfr
Copy link
Member

arikfr commented Sep 22, 2019

From the screenshots it looks like the Pivot table has a different font than the rest of the application. Is it like this for the regular pivot table for you as well?

@arikfr arikfr merged commit fd435d2 into master Sep 22, 2019
@arikfr arikfr deleted the react-pivottable branch September 22, 2019 07:46
@arikfr
Copy link
Member

arikfr commented Sep 22, 2019

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend: React Frontend codebase migration to React Frontend Visualizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants