-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
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.
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?
There was a problem hiding this comment.
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.
The React version doesn't have the |
|
||
&[data-hide-row-totals] { | ||
td:last-child, th:last-child { | ||
&.pvtTotalLabel:not(:empty), &.pvtTotal, &.pvtGrandTotal { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- cy.all with multiple args - add controls to pivot valid options
There was a problem hiding this 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" |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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).
There was a problem hiding this 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]); |
There was a problem hiding this comment.
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]
);
There was a problem hiding this comment.
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
:
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 😁
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)