-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate Pivot Table visualization to React (#4133)
* npm install react-pivottable * Initiate Pivot Table Migration * Update renderer with editor options * Clean up * Remove old pivottable from package.json * Test Percy Snapshot with Pivot Table in a Dashboard * Tmp: use cy.wait to make sure dashboard is loaded * Clean up Percy snapshot test * Small improvements - cy.all with multiple args - add controls to pivot valid options * Watch for options in the Renderer
- Loading branch information
1 parent
cb654b3
commit fd435d2
Showing
13 changed files
with
259 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.pivot-table-renderer > table, | ||
.pivot-table-visualization-container > table, | ||
.visualization-renderer > .visualization-renderer-wrapper { | ||
overflow: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
import { get, find, pick, map, mapValues } from 'lodash'; | ||
import PivotTableUI from 'react-pivottable/PivotTableUI'; | ||
import { RendererPropTypes } from '@/visualizations'; | ||
import { formatColumnValue } from '@/filters'; | ||
|
||
import 'react-pivottable/pivottable.css'; | ||
import './renderer.less'; | ||
|
||
const VALID_OPTIONS = [ | ||
'data', | ||
'rows', | ||
'cols', | ||
'vals', | ||
'aggregatorName', | ||
'valueFilter', | ||
'sorters', | ||
'rowOrder', | ||
'colOrder', | ||
'derivedAttributes', | ||
'rendererName', | ||
'hiddenAttributes', | ||
'hiddenFromAggregators', | ||
'hiddenFromDragDrop', | ||
'menuLimit', | ||
'unusedOrientationCutoff', | ||
'controls', | ||
'rendererOptions', | ||
]; | ||
|
||
function formatRows({ rows, columns }) { | ||
return map(rows, row => mapValues(row, (value, key) => formatColumnValue(value, find(columns, { name: key }).type))); | ||
} | ||
|
||
export default function Renderer({ data, options, onOptionsChange }) { | ||
const [config, setConfig] = useState({ data: formatRows(data), ...options }); | ||
|
||
useEffect(() => { | ||
setConfig({ data: formatRows(data), ...options }); | ||
}, [data, options]); | ||
|
||
const onChange = (updatedOptions) => { | ||
const validOptions = pick(updatedOptions, VALID_OPTIONS); | ||
setConfig(validOptions); | ||
onOptionsChange(validOptions); | ||
}; | ||
|
||
// Legacy behavior: hideControls when controls.enabled is true | ||
const hideControls = get(options, 'controls.enabled'); | ||
const hideRowTotals = !get(options, 'rendererOptions.table.rowTotals'); | ||
const hideColumnTotals = !get(options, 'rendererOptions.table.colTotals'); | ||
return ( | ||
<div | ||
className="pivot-table-visualization-container" | ||
data-hide-controls={hideControls || null} | ||
data-hide-row-totals={hideRowTotals || null} | ||
data-hide-column-totals={hideColumnTotals || null} | ||
data-test="PivotTableVisualization" | ||
> | ||
<PivotTableUI {...pick(config, VALID_OPTIONS)} onChange={onChange} /> | ||
</div> | ||
); | ||
} | ||
|
||
Renderer.propTypes = RendererPropTypes; | ||
Renderer.defaultProps = { onOptionsChange: () => {} }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.