Skip to content

Commit

Permalink
fix(charts,table): replace or use exact lodash imports (patternfly#4830)
Browse files Browse the repository at this point in the history
* fix(charts,table): replace or use exact lodash imports

* fix lint

* replace assign with Object.assign

* handle empty object case
  • Loading branch information
redallen authored Sep 21, 2020
1 parent 6c5df2a commit 63a8259
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Helpers, CommonProps, Path } from 'victory-core';
import { isPlainObject, assign } from 'lodash';
import isPlainObject from 'lodash/isPlainObject';

const getVerticalPath = (props: any) => {
const { pointerWidth, cornerRadius, orientation, width, height, center } = props;
Expand Down Expand Up @@ -89,7 +89,7 @@ const evaluateProps = (props: any) => {
const id = Helpers.evaluateProp(props.id, props);
const style = Helpers.evaluateStyle(props.style, props);

return assign({}, props, { id, style });
return Object.assign({}, props, { id, style });
};

const ChartCursorFlyout = (props: any) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { orderBy } from 'lodash';
import orderBy from 'lodash/orderBy';
import {
AnimatePropTypeInterface,
CategoryPropType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { defaults } from 'lodash';
import defaults from 'lodash/defaults';
import {
LabelOrientationType,
OriginType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { defaults } from 'lodash';
import defaults from 'lodash/defaults';
import {
Helpers,
LabelOrientationType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { range } from 'lodash';

export interface PathHelpersInterface {
circle: Function;
dash: Function;
Expand Down Expand Up @@ -104,7 +102,7 @@ export const PathHelpers: PathHelpersInterface = {
star: (x: number, y: number, size: number) => {
const baseSize = 1.35 * size;
const angle = Math.PI / 5;
const starCoords = range(10).map(index => {
const starCoords = [...Array(10).keys()].map(index => {
const length = index % 2 === 0 ? baseSize : baseSize / 2;
return `${length * Math.sin(angle * (index + 1)) + x},
${length * Math.cos(angle * (index + 1)) + y}`;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import { cloneDeep } from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import {
AnimatePropTypeInterface,
CategoryPropType,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defaults } from 'lodash';
import defaults from 'lodash/defaults';
import { Helpers, PaddingProps, TextSize } from 'victory-core';
import { VictoryLegend } from 'victory-legend';
import { ChartLegendOrientation, ChartLegendPosition, ChartLegendProps } from '../ChartLegend';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import { get, isEmpty, isFinite } from 'lodash';
import { PaddingProps } from 'victory-core';

export const getPaddingForSide = (
side: 'bottom' | 'left' | 'right' | 'top',
padding: PaddingProps,
fallback: PaddingProps
): number => {
if (!isEmpty(padding)) {
return get(padding, side, 0);
}

if (isFinite(padding)) {
if (typeof padding == 'number') {
return padding as number;
} else if (typeof padding == 'object' && Object.keys(padding).length > 0) {
return padding[side] || 0;
}

return getPaddingForSide(side, fallback, 0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { cloneDeep, merge } from 'lodash';
import cloneDeep from 'lodash/cloneDeep';
import merge from 'lodash/merge';
import { DarkBlueColorTheme } from '../ChartTheme/themes/dark/blue-color-theme';
import { DarkCyanColorTheme } from '../ChartTheme/themes/dark/cyan-color-theme';
import { DarkGoldColorTheme } from '../ChartTheme/themes/dark/gold-color-theme';
Expand Down
4 changes: 2 additions & 2 deletions packages/react-table/src/components/Table/base/body-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Forked from reactabular-table version 8.14.0
* https://github.com/reactabular/reactabular/tree/v8.14.0/packages/reactabular-table/src
*/
import { isEqual, isFunction } from 'lodash';
import isEqual from 'lodash/isEqual';
import * as React from 'react';
import { columnsAreEqual } from './columns-are-equal';
import { evaluateFormatters } from './evaluate-formatters';
Expand Down Expand Up @@ -35,7 +35,7 @@ export class BodyRow extends React.Component<BodyRowProps, {}> {
const { renderers } = nextProps;

if (renderers && renderers.row && (renderers.row as React.Component).shouldComponentUpdate) {
if (isFunction((renderers.row as React.Component).shouldComponentUpdate)) {
if (typeof (renderers.row as React.Component).shouldComponentUpdate === 'function') {
return (renderers.row as React.Component).shouldComponentUpdate.call(this, nextProps, {}, {});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/react-table/src/components/Table/base/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* https://github.com/reactabular/reactabular/tree/v8.14.0/packages/reactabular-table/src
*/
import * as React from 'react';
import { isEqual, isFunction } from 'lodash';
import isEqual from 'lodash/isEqual';
import { RowsType, RowType, RowKeyType, RenderersTypes, createElementType, ColumnsType } from './types';
import { resolveRowKey } from './resolve-row-key';
import { BodyRow } from './body-row';
Expand Down Expand Up @@ -40,7 +40,7 @@ class BaseBody extends React.Component<BodyProps, {}> {
renderers.body.wrapper &&
(renderers.body.wrapper as React.Component).shouldComponentUpdate
) {
if (isFunction((renderers.body.wrapper as React.Component).shouldComponentUpdate)) {
if (typeof (renderers.body.wrapper as React.Component).shouldComponentUpdate === 'function') {
return (renderers.body.wrapper as React.Component).shouldComponentUpdate.call(this, nextProps, {}, {});
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Forked from reactabular-table version 8.14.0
* https://github.com/reactabular/reactabular/tree/v8.14.0/packages/reactabular-table/src
*/
import { isFunction, isEqualWith } from 'lodash';
import isEqualWith from 'lodash/isEqualWith';
import { ColumnsType } from './types';

/**
Expand All @@ -13,7 +13,7 @@ import { ColumnsType } from './types';
*/
export function columnsAreEqual(oldColumns: ColumnsType, newColumns: ColumnsType) {
return isEqualWith(oldColumns, newColumns, (a, b) => {
if (isFunction(a) && isFunction(b)) {
if (typeof a === 'function' && typeof b === 'function') {
return a === b;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* Forked from reactabular-table version 8.14.0
* https://github.com/reactabular/reactabular/tree/v8.14.0/packages/reactabular-table/src
*/
import { isFunction } from 'lodash';
import { mergeProps } from './merge-props';
import { transformsType, ExtraParamsType } from './types';

Expand All @@ -19,7 +18,7 @@ export function evaluateTransforms(
extraParameters: ExtraParamsType = {}
) {
if (process.env.NODE_ENV !== 'production') {
if (!transforms.every(isFunction)) {
if (!transforms.every(f => typeof f === 'function')) {
throw new Error("All transforms weren't functions!");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Forked from reactabular-table version 8.14.0
* https://github.com/reactabular/reactabular/tree/v8.14.0/packages/reactabular-table/src
*/
import { mergeWith } from 'lodash';
import mergeWith from 'lodash/mergeWith';
import { css } from '@patternfly/react-styles';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* https://github.com/reactabular/reactabular/tree/v8.14.0/packages/reactabular-table/src
*/

import { isArray } from 'lodash';
import { RowType, RowKeyType } from './types';

/**
Expand All @@ -24,7 +23,7 @@ export function resolveRowKey({
return `${rowKey({ rowData, rowIndex })}-row`;
} else if (process.env.NODE_ENV !== 'production') {
// Arrays cannot have rowKeys by definition so we have to go by index there.
if (!isArray(rowData) && (rowData as any)[rowKey] === undefined) {
if (!Array.isArray(rowData) && (rowData as any)[rowKey] === undefined) {
// eslint-disable-next-line no-console
console.warn('Table.Body - Missing valid rowKey!', rowData, rowKey);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class VirtualizedExample extends React.Component {
### Sortable
```js
import React from 'react';
import { debounce } from 'lodash';
import { debounce } from '@patternfly/react-core';
import { Table, TableHeader, sortable, SortByDirection, TableGridBreakpoint } from '@patternfly/react-table';
import { CellMeasurerCache, CellMeasurer } from 'react-virtualized';
import { AutoSizer, VirtualTableBody } from '@patternfly/react-virtualized-extension';
Expand Down Expand Up @@ -323,7 +323,7 @@ class SortableExample extends React.Component {
### Selectable
```js
import React from 'react';
import { debounce } from 'lodash';
import { debounce } from '@patternfly/react-core';
import { Table, TableHeader, headerCol, TableGridBreakpoint } from '@patternfly/react-table';
import { CellMeasurerCache, CellMeasurer } from 'react-virtualized';
import { AutoSizer, VirtualTableBody } from '@patternfly/react-virtualized-extension';
Expand Down Expand Up @@ -480,7 +480,7 @@ class SelectableExample extends React.Component {
### Actions
```js
import React from 'react';
import { debounce } from 'lodash';
import { debounce } from '@patternfly/react-core';
import { ActionsColumn, Table, TableHeader, TableGridBreakpoint } from '@patternfly/react-table';
import { CellMeasurerCache, CellMeasurer } from 'react-virtualized';
import { AutoSizer, VirtualTableBody } from '@patternfly/react-virtualized-extension';
Expand Down Expand Up @@ -656,7 +656,7 @@ import {
EmptyStateBody,
EmptyStateSecondaryActions
} from '@patternfly/react-core';
import { debounce } from 'lodash';
import { debounce } from '@patternfly/react-core';
import SearchIcon from '@patternfly/react-icons/dist/js/icons/search-icon';
import FilterIcon from '@patternfly/react-icons/dist/js/icons/filter-icon';
import { ActionsColumn, Table, TableHeader, TableGridBreakpoint, TextInput } from '@patternfly/react-table';
Expand Down

0 comments on commit 63a8259

Please sign in to comment.