Migrate Pivot Table visualization to React#4133
Conversation
| @@ -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'; | |||
There was a problem hiding this comment.
Is this related to this PR?
There was a problem hiding this comment.
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.
|
The React version doesn't have the |
|
|
||
| &[data-hide-row-totals] { | ||
| td:last-child, th:last-child { | ||
| &.pvtTotalLabel:not(:empty), &.pvtTotal, &.pvtGrandTotal { |
- cy.all with multiple args - add controls to pivot valid options
gabrieldutra
left a comment
There was a problem hiding this comment.
@kravets-levko considering this was my first work related to React Visualizations, lmk if I forgot ath 🙂.
| ({ key: `${indexOf(filter.values, filter.current)}`, label: formatColumnValue(filter.current) })} | ||
| allowClear={filter.multiple} | ||
| filterOption={(searchText, option) => includes(toLower(option.props.children), toLower(searchText))} | ||
| optionFilterProp="children" |
There was a problem hiding this comment.
Took the opportunity to simplify this
| return arr.join(' / '); | ||
| } | ||
|
|
||
| export function formatColumnValue(value, columnType = null) { |
There was a problem hiding this comment.
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; | |||
There was a problem hiding this comment.
5px is the default now
| padding: 5px; | ||
| } | ||
|
|
||
| li.ui-sortable-handle { |
There was a problem hiding this comment.
I didn't find any .ui-sortable-handle, also it didn't seem that important
There was a problem hiding this comment.
.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'); |
There was a problem hiding this comment.
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).
kravets-levko
left a comment
There was a problem hiding this comment.
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]); |
There was a problem hiding this comment.
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]
);There was a problem hiding this comment.
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:

There was a problem hiding this comment.
Got it 👍 Then let's keep as is
| padding: 5px; | ||
| } | ||
|
|
||
| li.ui-sortable-handle { |
There was a problem hiding this comment.
.ui-<whatever> prefixes are related to jQuery.UI - I hope React components don't use it 😁
|
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? |
|
👍 |

What type of PR is this? (check all applicable)
Description
Migration for the Pivot Table Visualization
Related Tickets & Documents
--
Mobile & Desktop Screenshots/Recordings (if there are UI changes)