Skip to content

Commit

Permalink
chore: Update to latest aggrid and remove private method access
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The prop `rowClassName` has been removed
  • Loading branch information
dnlkoch committed Apr 14, 2022
1 parent c26792c commit 6100800
Showing 1 changed file with 15 additions and 74 deletions.
89 changes: 15 additions & 74 deletions src/Grid/AgFeatureGrid/AgFeatureGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable testing-library/render-result-naming-convention */
import * as React from 'react';
import { Key, ReactNode } from 'react';
import { Key } from 'react';

import OlStyle from 'ol/style/Style';
import OlStyleFill from 'ol/style/Fill';
Expand Down Expand Up @@ -102,11 +102,6 @@ interface OwnProps {
* A CSS class which should be added to the table.
*/
className?: string;
/**
* A CSS class to add to each table row or a function that
* is evaluated for each record.
*/
rowClassName?: string | ((record: any) => string);
/**
* The map the features should be rendered on. If not given, the features
* will be rendered in the table only.
Expand Down Expand Up @@ -253,18 +248,6 @@ export class AgFeatureGrid extends React.Component<AgFeatureGridProps, AgFeature
*/
_className = `${CSS_PREFIX}ag-feature-grid`;

/**
* The class name to add to each table row.
* @private
*/
_rowClassName = `${CSS_PREFIX}ag-feature-grid-row`;

/**
* The prefix to use for each table row class.
* @private
*/
_rowKeyClassNamePrefix = 'row-key-';

/**
* The hover class name.
* @private
Expand Down Expand Up @@ -433,60 +416,38 @@ export class AgFeatureGrid extends React.Component<AgFeatureGridProps, AgFeature
grid
} = this.state;

if (!grid || !grid.api) {
return;
}

const selectedRowKeys = this.getSelectedRowKeys();

const selectedFeatures = (map.getFeaturesAtPixel(olEvt.pixel, {
const highlightFeatures = (map.getFeaturesAtPixel(olEvt.pixel, {
layerFilter: layerCand => layerCand === this._layer
}) || []) as OlFeature<OlGeometry>[];

if (!grid || !grid.api) {
return;
}

// @ts-ignore
const rowRenderer = grid.api.rowRenderer;
grid.api?.forEachNode((n) => {
n.setHighlighted(null);
});

features.forEach(feature => {
const key = this.props.keyFunction(feature);

let rc: any;
rowRenderer.forEachRowComp((idx: number, rowComp: any) => {
if (rowComp.getRowNode().data.key === key) {
rc = rowComp;
}
});

if (rc) {
const el = rc.getBodyRowElement();

if (el) {
el.classList.remove(this._rowHoverClassName);
}
}
if (selectedRowKeys.includes(key)) {
feature.setStyle(selectStyle);
} else {
feature.setStyle(undefined);
}
});

selectedFeatures.forEach(feature => {
const key = this.props.keyFunction(feature);
let rc: any;
rowRenderer.forEachRowComp((idx: number, rowComp: any) => {
if (rowComp.getRowNode().data.key === key) {
rc = rowComp;
highlightFeatures.forEach(feat => {
const key = this.props.keyFunction(feat);
grid.api?.forEachNode((n) => {
if (n.data.key === key) {
n.setHighlighted(1);
feat.setStyle(highlightStyle);
}
});

if (rc) {
const el = rc.getBodyRowElement();

if (el) {
el.classList.add(this._rowHoverClassName);
}
}
feature.setStyle(highlightStyle);
});
};

Expand Down Expand Up @@ -933,7 +894,6 @@ export class AgFeatureGrid extends React.Component<AgFeatureGridProps, AgFeature
height,
width,
theme,
rowClassName,
features,
map,
attributeBlacklist,
Expand All @@ -956,24 +916,6 @@ export class AgFeatureGrid extends React.Component<AgFeatureGridProps, AgFeature
? `${className} ${this._className} ${theme}`
: `${this._className} ${theme}`;

// TODO: Not sure, if this is still needed. One may want to get a specific
// row by using getRowFromFeatureKey instead.
let rowClassNameFn;
if (_isFunction(rowClassName)) {
rowClassNameFn = (node: ReactNode) => {
const determinedRowClass = rowClassName((node as { data: string }).data);
return `${this._rowClassName} ${determinedRowClass}`;
};
} else {
const finalRowClassName = rowClassName
? `${rowClassName} ${this._rowClassName}`
: this._rowClassName;
rowClassNameFn = (node: ReactNode) => {
const rowClassSuffix = _kebabCase((node as { data: { key: string } }).data.key);
return `${finalRowClassName} ${this._rowKeyClassNamePrefix}${rowClassSuffix}`;
};
}

return (
<div
className={finalClassName}
Expand All @@ -994,7 +936,6 @@ export class AgFeatureGrid extends React.Component<AgFeatureGridProps, AgFeature
onCellMouseOver={this.onRowMouseOver.bind(this)}
onCellMouseOut={this.onRowMouseOut.bind(this)}
ref={ref => this._ref = ref}
getRowClass={rowClassNameFn}
modules={[
ClientSideRowModelModule
]}
Expand Down

0 comments on commit 6100800

Please sign in to comment.