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

bump to react-18 #155

Merged
merged 3 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@ workflows:
run-tests:
jobs:
- test
- test-react-18
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source D

- [#145](https://github.com/plotly/dash-ag-grid/pull/145)
- updated AG Grid `29.1.0` -> `29.3.2`

- [#155](https://github.com/plotly/dash-ag-grid/pull/155)
- update React to `18.2.0`
- updated `material-ui` to `@mui` for `rowMenuRenderer`

### Fixed
- [Overhaul commit](https://github.com/plotly/dash-ag-grid/commit/b888d6ab4fcb4afac187492e8b6c9cf0d0f8842b)
Expand All @@ -122,6 +126,10 @@ Links "DE#nnn" prior to version 2.0 point to the Dash Enterprise closed-source D
- fixed `onRowDragEnd` to trigger `virtualRowData` update
- fixed all `virtualRowData` updates to take into account the sorting

- [#155](https://github.com/plotly/dash-ag-grid/pull/155)
- fixed `openGroups` where clearing out the set would cause issues
- fixed `paginationGoTo` to work with a starting page

## [1.3.2] - 2023-01-13

### Updated
Expand Down
7,227 changes: 487 additions & 6,740 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
"author": "Plotly <chris@plot.ly>",
"license": "MIT",
"dependencies": {
"@material-ui/core": "^4.11.4",
"@material-ui/icons": "^4.11.3",
"@mui/material": "^5.12.1",
"@mui/icons-material": "^5.11.16",
"@emotion/styled": "^11.10.6",
"@emotion/react": "^11.10.6",
alexcjohnson marked this conversation as resolved.
Show resolved Hide resolved
"ag-grid-community": "^29.3.2",
"ag-grid-enterprise": "^29.3.2",
"ag-grid-react": "^29.3.2",
Expand Down Expand Up @@ -61,9 +63,9 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
"prop-types": "^15.8.1",
"react": "^16.14.0",
"react": "^18.2.0",
"react-docgen": "^5.4.3",
"react-dom": "^16.14.0",
"react-dom": "^18.2.0",
"style-loader": "^3.3.2",
"styled-jsx": "^5.1.2",
"webpack": "^5.80.0",
Expand Down
181 changes: 94 additions & 87 deletions src/lib/fragments/AgGrid.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ export default class DashAgGrid extends Component {

onFilterChanged() {
const {setProps, rowModelType} = this.props;
if (!this.state.gridApi) {
return;
}
const filterModel = this.state.gridApi.getFilterModel();
const propsToSet = {filterModel};
if (rowModelType === 'clientSide') {
Expand Down Expand Up @@ -512,14 +515,23 @@ export default class DashAgGrid extends Component {
return false;
}

componentDidUpdate(prevProps) {
componentDidUpdate(prevProps, prevState) {
const {
selectedRows,
getDetailResponse,
detailCellRendererParams,
masterDetail,
setProps,
id,
resetColumnState,
csvExportParams,
exportDataAsCsv,
selectAll,
deselectAll,
deleteSelectedRows,
filterModel,
columnState,
paginationGoTo,
} = this.props;

if (id !== prevProps.id) {
Expand All @@ -533,6 +545,72 @@ export default class DashAgGrid extends Component {
}
}

if (this.state.gridApi && this.state.gridApi !== prevState.gridApi) {
const propsToSet = {};
this.updateColumnWidths(false);

if (this.state.rowTransaction) {
this.state.rowTransaction.map((data) =>
this.applyRowTransaction(data, this.state.gridApi)
);
this.setState({rowTransaction: null});
this.syncRowData();
}

// Handles applying selections when a selection was persisted by Dash
this.setSelection(selectedRows);

if (this.reference.current.props.pagination) {
this.onPaginationChanged();
}

if (!isEmpty(filterModel)) {
this.state.gridApi.setFilterModel(filterModel);
}

if (columnState) {
this.setColumnState();
}

if (paginationGoTo) {
this.paginationGoTo(false);
propsToSet.paginationGoTo = null;
}

if (resetColumnState) {
this.resetColumnState(false);
propsToSet.resetColumnState = false;
}

if (exportDataAsCsv) {
this.exportDataAsCsv(csvExportParams, false);
propsToSet.exportDataAsCsv = false;
}

if (selectAll) {
this.selectAll(selectAll, false);
propsToSet.selectAll = false;
}

if (deselectAll) {
this.deselectAll(false);
propsToSet.deselectAll = false;
}

if (deleteSelectedRows) {
this.deleteSelectedRows(false);
propsToSet.deleteSelectedRows = false;
}

if (!isEmpty(propsToSet)) {
setProps(propsToSet);
}
// Hydrate virtualRowData
this.onFilterChanged(true);
this.setState({mounted: true});
this.updateColumnState();
}

if (this.isDatasourceLoadedForInfiniteScrolling()) {
const {rowData, rowCount} = this.props.getRowsResponse;
this.getRowsParams.successCallback(rowData, rowCount);
Expand Down Expand Up @@ -598,13 +676,19 @@ export default class DashAgGrid extends Component {
}

onRowGroupOpened(e) {
this.setState(({openGroups}) => ({
openGroups: e.expanded
this.setState(({openGroups}) => {
let newGroups = e.expanded
? // If the node was just expanded, add it to the list of open nodes
openGroups.add(e.node.key)
: // If it's collapsed, remove it from the list of open nodes
openGroups.delete(e.node.key),
}));
openGroups.delete(e.node.key);
if (newGroups === true || newGroups === false) {
newGroups = new Set();
}
return {
openGroups: newGroups,
};
});
}

onSelectionChanged() {
Expand Down Expand Up @@ -648,93 +732,16 @@ export default class DashAgGrid extends Component {
onGridReady(params) {
// Applying Infinite Row Model
// see: https://www.ag-grid.com/javascript-grid/infinite-scrolling/
const {
rowModelType,
selectedRows,
resetColumnState,
csvExportParams,
exportDataAsCsv,
selectAll,
deselectAll,
deleteSelectedRows,
filterModel,
setProps,
columnState,
paginationGoTo,
} = this.props;
const {rowModelType} = this.props;

const propsToSet = {};
if (rowModelType === 'infinite') {
params.api.setDatasource(this.getDatasource());
}

this.setState({
this.setState(() => ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it necessary to make this a function?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, was trying to solve the bad setState issue, we can revert.

gridApi: params.api,
gridColumnApi: params.columnApi,
});

this.updateColumnWidths();

if (this.reference.current.props.pagination) {
this.onPaginationChanged();
}

if (!isEmpty(filterModel)) {
this.state.gridApi.setFilterModel(filterModel);
}

if (columnState && !this.state.mounted) {
this.setColumnState();
}

if (paginationGoTo) {
this.paginationGoTo(false);
propsToSet.paginationGoTo = null;
}

if (resetColumnState) {
this.resetColumnState(false);
propsToSet.resetColumnState = false;
}

if (exportDataAsCsv) {
this.exportDataAsCsv(csvExportParams, false);
propsToSet.exportDataAsCsv = false;
}

if (selectAll) {
this.selectAll(selectAll, false);
propsToSet.selectAll = false;
}

if (deselectAll) {
this.deselectAll(false);
propsToSet.deselectAll = false;
}

if (deleteSelectedRows) {
this.deleteSelectedRows(false);
propsToSet.deleteSelectedRows = false;
}

if (!isEmpty(propsToSet)) {
setProps(propsToSet);
}

if (this.state.rowTransaction) {
this.state.rowTransaction.map((data) =>
this.applyRowTransaction(data, params.api)
);
this.setState({rowTransaction: null});
this.syncRowData();
}

// Handles applying selections when a selection was persisted by Dash
this.setSelection(selectedRows);
// Hydrate virtualRowData
this.onFilterChanged(true);
this.setState({mounted: true});
this.updateColumnState();
}));
}

onCellClicked({value, column: {colId}, rowIndex, node}) {
Expand Down Expand Up @@ -796,7 +803,7 @@ export default class DashAgGrid extends Component {
}
}

updateColumnWidths() {
updateColumnWidths(setColumns = true) {
const {columnSize, columnSizeOptions, setProps} = this.props;
const {gridApi, gridColumnApi} = this.state;
if (gridApi || gridColumnApi) {
Expand Down Expand Up @@ -826,7 +833,7 @@ export default class DashAgGrid extends Component {
if (columnSize !== 'responsiveSizeToFit') {
setProps({columnSize: null});
}
if (this.state.mounted) {
if (setColumns) {
this.updateColumnState();
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib/renderers/rowMenuRenderer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React, {useCallback, useState} from 'react';
import PropTypes from 'prop-types';

import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import Button from '@material-ui/core/Button';
import AddIcon from '@material-ui/icons/Add';
import Menu from '@mui/material/Menu';
import MenuItem from '@mui/material/MenuItem';
import Button from '@mui/material/Button';
import AddIcon from '@mui/icons-material/Add';

export default function RowMenuRenderer(props) {
const [anchorEl, setAnchorEl] = useState(null);
Expand Down
7 changes: 1 addition & 6 deletions src/lib/utils/propCategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,4 @@ export const OMIT_PROP_RENDER = [
/**
* States to not trigger a render update
*/
export const OMIT_STATE_RENDER = [
'gridApi',
'gridColumnApi',
'mounted',
'openGroups',
];
export const OMIT_STATE_RENDER = ['gridColumnApi', 'mounted', 'openGroups'];
2 changes: 1 addition & 1 deletion tests/test_column_drag.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def addGrid(n, s):
id="middleGrid",
columnDefs=columnDefs,
rowData=df.to_dict("records"),
columnSize="autoSize",
columnSize=None,
defaultColDef=defaultColDef,
dashGridOptions={'alignedGrids': 'bottomGrid'},
columnState = s
Expand Down
8 changes: 5 additions & 3 deletions tests/test_column_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def test_cs001_column_state(dash_duo):
rowData=rowData,
columnState=colState,
),
html.Pre(id="reset-column-state-grid-pre"),
html.Div(id="reset-column-state-grid-pre"),
]
)

Expand All @@ -118,8 +118,9 @@ def reset_column_state(n_reset, n_state):
return no_update

@app.callback(
Output('reset-column-state-grid', 'columnState'),
Input('load-column-state-button', 'n_clicks')
Output('grid', 'columnState'),
Input('load-column-state-button', 'n_clicks'),
prevent_initial_call=True
)
def loadState(n):
if n:
Expand All @@ -141,6 +142,7 @@ def display_column_state(col_state):

grid.wait_for_pinned_cols(2)
grid.wait_for_viewport_cols(1)

until(lambda: json.dumps(colState) in dash_duo.find_element('#reset-column-state-grid-pre').text, timeout=3)

grid.resize_col(1, 50)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def test_pa001_pagination(dash_duo):
columnSize="sizeToFit",
defaultColDef={"resizable": True, "sortable": True, "filter": True},
dashGridOptions={"pagination": True},
paginationGoTo=5,
),
html.Div(id='grid-info'),
html.Button(id='changeSize', children='changeSize')
Expand Down Expand Up @@ -73,9 +74,9 @@ def updatePage(_):

grid = utils.Grid(dash_duo, "grid")

grid.wait_for_cell_text(0,0, 'United States')
oldValue = ''
until(lambda: oldValue != dash_duo.find_element('#grid-info').text, timeout=3)
until(lambda: "Australia" == grid.get_cell(500,0).text, timeout=3)
oldValue = '{"isLastPageFound": true, "pageSize": 100, "currentPage": 5, "totalPages": 87, "rowCount": 8618}'
until(lambda: oldValue == dash_duo.find_element('#grid-info').text, timeout=3)
oldValue = dash_duo.find_element('#grid-info').text
dash_duo.find_element('.ag-paging-button[aria-label="Last Page"]').click()
until(lambda: oldValue != dash_duo.find_element('#grid-info').text, timeout=3)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_row_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def show_click_data(data):

### testing components
grid.element_click_cell_button(0, 3)
assert 'opacity: 1' in dash_duo.find_element('.MuiPopover-root .MuiMenu-paper').get_attribute('style')
dash_duo.find_elements('.MuiPopover-root .MuiMenu-paper .MuiMenu-list .MuiListItem-button')[1].click()
assert 'opacity: 1' in dash_duo.find_element('.MuiMenu-paper').get_attribute('style')
dash_duo.find_elements('.MuiMenu-paper .MuiMenu-list .MuiMenuItem-root')[1].click()
dash_duo.wait_for_text_to_equal('#click-data',
'You selected option 2 from the colId menu, rowIndex 0, rowId Toyota.')
Loading