Skip to content

Commit

Permalink
remove most of lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Nov 14, 2024
1 parent 1475f37 commit 2ccfdb4
Show file tree
Hide file tree
Showing 46 changed files with 175 additions and 174 deletions.
2 changes: 1 addition & 1 deletion components/form/CheckboxGroup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import isEqual from 'lodash/isEqual';
import isEqual from 'react-fast-compare';
import { injectIntl } from 'react-intl';

import Checkbox from './Checkbox';
Expand Down
3 changes: 2 additions & 1 deletion components/form/File.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import omit from 'lodash/omit';

import { omit } from 'utils/general';

// Intl
import { injectIntl } from 'react-intl';
Expand Down
2 changes: 1 addition & 1 deletion components/form/FmusCheckboxGroup.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import isEqual from 'lodash/isEqual';
import isEqual from 'react-fast-compare';
import { injectIntl } from 'react-intl';

// Utils
Expand Down
9 changes: 3 additions & 6 deletions components/form/FormElement.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import pick from 'lodash/pick';
import isEqual from 'react-fast-compare';

import Validator from './Validator';

Expand Down Expand Up @@ -30,10 +29,8 @@ class FormElement extends React.Component {
}

componentDidUpdate(prevProps) {
const prevPropsParsed = pick(prevProps, ['properties', 'validations']);
const currentPropsParsed = pick(this.props, ['properties', 'validations']);

if (!isEqual(prevPropsParsed, currentPropsParsed)) {
if (!isEqual(prevProps.properties, this.props.properties) ||
!isEqual(prevProps.validations, this.props.validations)) {
this.triggerValidate();
}

Expand Down
2 changes: 1 addition & 1 deletion components/form/Validator.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import isEmpty from "lodash/isEmpty";
import { isEmpty } from "utils/general";

class Validator {
constructor(intl) {
Expand Down
4 changes: 2 additions & 2 deletions components/map/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import classnames from 'classnames';
import PropTypes from 'prop-types';
import * as Sentry from "@sentry/nextjs";

import isEqual from 'lodash/isEqual';
import isEmpty from 'lodash/isEmpty';
import isEqual from 'react-fast-compare';
import { isEmpty } from 'utils/general';

import ReactMapGL, { FlyToInterpolator } from 'react-map-gl';
import { fitBounds } from 'viewport-mercator-project';
Expand Down
5 changes: 3 additions & 2 deletions components/map/layer-manager/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import PropTypes from 'prop-types';
import { LayerManager, Layer } from 'layer-manager/dist/components';
import { PluginMapboxGl, fetch } from 'layer-manager';

import omit from 'lodash/omit';
import { omit } from 'utils/general';

import slugify from 'slugify';

class LayerManagerComponent extends PureComponent {
Expand Down Expand Up @@ -147,4 +148,4 @@ class LayerManagerComponent extends PureComponent {
}
}

export default LayerManagerComponent;
export default LayerManagerComponent;
2 changes: 1 addition & 1 deletion components/map/popup/component.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';

import isEmpty from 'lodash/isEmpty';
import { isEmpty } from 'utils/general';
import isEqual from 'react-fast-compare';

import { Popup } from 'react-map-gl';
Expand Down
7 changes: 3 additions & 4 deletions components/map/popup/templates/fmu-aac/component.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import trim from 'lodash/trim';

// Intl
import { injectIntl } from 'react-intl';
Expand All @@ -21,10 +20,10 @@ class FMUAACTemplatePopup extends PureComponent {
<div className="c-layer-popup">
{!!fmu && <h3>{fmu.data.data.fmu_name}</h3>}

{!!aac && (!!trim(aac.data.data.period_val) || aac.data.data.nom_aac) &&
{!!aac && (!!String(aac.data.data.period_val || '').trim() || aac.data.data.nom_aac) &&
<ul className="layer-popup--list">
{!!trim(aac.data.data.nom_aac) && <li>Name: {aac.data.data.nom_aac}</li>}
{!!trim(aac.data.data.period_val) && <li>Period: {aac.data.data.period_val}</li>}
{!!String(aac.data.data.nom_aac || '').trim() && <li>Name: {aac.data.data.nom_aac}</li>}
{!!String(aac.data.data.period_val || '').trim() && <li>Period: {aac.data.data.period_val}</li>}
</ul>
}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useState } from 'react';
import PropTypes from 'prop-types';
import sortBy from 'lodash/sortBy';
import groupBy from 'lodash/groupBy';
import uniq from 'lodash/uniq';
import cx from 'classnames';
import { injectIntl } from 'react-intl';
import Fuse from 'fuse.js';

import { groupBy } from 'utils/general';

// Redux
import { connect } from 'react-redux';

Expand Down Expand Up @@ -52,7 +52,7 @@ function DocumentsByOperator({ groupedByCategory, searchText, user, id, intl, ..

const exactSearchResults = searchText.length > 2 ? documents.filter(exactSearch) : [];
const fuseSearchResults = fuse.search(searchText).map(r => r.item);
return uniq([...exactSearchResults, ...fuseSearchResults]);
return [...new Set([...exactSearchResults, ...fuseSearchResults])];
}

const results = Object.keys(groupedByCategory).map((category) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from 'utils/general';

// Redux
import { connect } from 'react-redux';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import omit from 'lodash/omit';
import { omit } from 'utils/general';
import { useRouter } from 'next/router';

// Redux
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import PropTypes from 'prop-types';
import { Area, AreaChart, ResponsiveContainer, Tooltip, XAxis } from 'recharts';
import { injectIntl } from 'react-intl';
import dayjs from 'dayjs';
import groupBy from 'lodash/groupBy';

// Utils
import { PALETTE } from 'utils/documentation';
import { groupBy } from 'utils/general';

function CustomTooltip({ active, payload, label: timestamp, intl }) {
if (active) {
Expand Down
2 changes: 1 addition & 1 deletion components/operators-detail/fmus.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';

import isEqual from 'lodash/isEqual';
import isEqual from 'react-fast-compare';
import debounce from 'lodash/debounce';

import getBBox from '@turf/bbox';
Expand Down
2 changes: 1 addition & 1 deletion components/operators-detail/layout.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from 'utils/general';

// Utils
import { HELPERS_DOC } from 'utils/documentation';
Expand Down
5 changes: 2 additions & 3 deletions components/operators/table.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import sortBy from 'lodash/sortBy';
import uniq from 'lodash/uniq';
import { connect } from 'react-redux';

// Next
Expand Down Expand Up @@ -43,9 +42,9 @@ class OperatorsTable extends React.Component {
});
} else {
this.setState({
expandedOperatorIds: uniq(
expandedOperatorIds: [...new Set(
[id, ...this.state.expandedOperatorIds].sort()
),
)],
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion components/ui/card.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import dynamic from 'next/dynamic';
import Link from 'next/link';

import classnames from 'classnames';
import omit from 'lodash/omit';
import { omit } from 'utils/general';

const Truncate = dynamic(() => import('react-truncate'));

Expand Down
2 changes: 1 addition & 1 deletion components/ui/filters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import isEqual from 'react-fast-compare';

class Filters extends React.Component {
componentDidUpdate(prevProps) {
Expand Down
1 change: 0 additions & 1 deletion components/ui/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { injectIntl } from 'react-intl';
import Spinner from 'components/ui/spinner';
import modal from 'services/modal';
import { getNotifications, dismissAll } from 'modules/notifications';
import { groupBy } from 'lodash';

function isBeforeToday(date) {
const today = new Date();
Expand Down
1 change: 0 additions & 1 deletion components/ui/sawmill-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import LocationSearch from 'components/map/location-search';

import { transformRequest } from 'utils/map';
import CancelButton from '../form/CancelButton';
import { set } from 'lodash';

class SawmillModal extends React.Component {
static propTypes = {
Expand Down
1 change: 0 additions & 1 deletion components/ui/user-menu-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react';
import { useIntl } from 'react-intl';
import { connect } from 'react-redux';
import Link from 'next/link';
import uniq from 'lodash/uniq';
import uniqBy from 'lodash/uniqBy';

import Notifications from 'components/ui/notifications';
Expand Down
3 changes: 2 additions & 1 deletion components/users/newsletter.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import React, { useEffect, useRef, useState } from 'react';
import PropTypes from 'prop-types';
import sortBy from 'lodash/sortBy';
import groupBy from 'lodash/groupBy';

// Intl
import { useIntl } from 'react-intl';
import { connect } from 'react-redux';

import API from 'services/api';

import { groupBy } from 'utils/general';

// Components
import Form, { FormProvider } from 'components/form/Form';
import Field from 'components/form/Field';
Expand Down
4 changes: 1 addition & 3 deletions modules/documents-database.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import isEmpty from 'lodash/isEmpty';

import API from 'services/api';

// Utils
import { encode, decode, parseObjectSelectOptions } from 'utils/general';
import { encode, decode, parseObjectSelectOptions, isEmpty } from 'utils/general';
import { setUrlParam } from 'utils/url';

/* Constants */
Expand Down
4 changes: 1 addition & 3 deletions modules/observations.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import isEmpty from 'lodash/isEmpty';

import API from 'services/api';

// Utils
import { encode, decode, parseObjectSelectOptions } from 'utils/general';
import { encode, decode, parseObjectSelectOptions, isEmpty } from 'utils/general';
import { setUrlParam } from 'utils/url';

/* Constants */
Expand Down
7 changes: 3 additions & 4 deletions modules/operators-detail-fmus.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sumBy from 'lodash/sumBy';
import uniq from 'lodash/uniq';
import dayjs from 'dayjs';

import { fetchIntegratedAlertsMetadata } from 'services/layers';
import { sumBy } from 'utils/general';

const GET_FMU_ANALYSIS_SUCCESS = 'GET_FMU_ANALYSIS_SUCCESS';
const GET_FMU_ANALYSIS_LOADING = 'GET_FMU_ANALYSIS_LOADING';
Expand Down Expand Up @@ -430,11 +429,11 @@ export function getIntegratedAlertsMetadata() {
// put integrated-alerts before fmusdetail
dispatch({
type: SET_OPERATORS_DETAIL_MAP_LAYERS_ACTIVE,
payload: uniq([
payload: [... new Set([
...activeLayers.slice(0, activeLayers.indexOf('fmusdetail')),
'integrated-alerts',
...activeLayers.slice(activeLayers.indexOf('fmusdetail'))
])
])]
});
})
};
Expand Down
13 changes: 5 additions & 8 deletions modules/operators-ranking.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import Router from 'next/router';

import groupBy from 'lodash/groupBy';
import flatten from 'lodash/flatten';
import uniq from 'lodash/uniq';

import dayjs from 'dayjs';

import API from 'services/api';
import { fetchIntegratedAlertsMetadata } from 'services/layers';
import { groupBy } from 'utils/general';

import { CERTIFICATIONS } from 'constants/fmu';

Expand Down Expand Up @@ -246,12 +243,12 @@ export function getOperatorsRanking() {
return o['percentage-valid-documents-all'];
});
const groupByDocPercentageKeys = Object.keys(groupByDocPercentage).sort().reverse();
const rankedData = flatten(groupByDocPercentageKeys.map((k, i) => {
const rankedData = groupByDocPercentageKeys.map((k, i) => {
return groupByDocPercentage[k].map(o => ({
...o,
ranking: i
}));
}));
}).flat();

dispatch({
type: GET_OPERATORS_RANKING_SUCCESS,
Expand Down Expand Up @@ -386,11 +383,11 @@ export function getIntegratedAlertsMetadata() {
// put integrated-alerts before fmus
dispatch({
type: SET_OPERATORS_MAP_LAYERS_ACTIVE,
payload: uniq([
payload: [...new Set([
...activeLayers.slice(0, activeLayers.indexOf('fmus')),
'integrated-alerts',
...activeLayers.slice(activeLayers.indexOf('fmus'))
])
])]
});
})
};
Expand Down
3 changes: 1 addition & 2 deletions modules/user.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import omitBy from 'lodash/omitBy';
import isEmpty from 'lodash/isEmpty';
import { omitBy, isEmpty } from 'utils/general';

import API, { NEXTAPIClient } from 'services/api'

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"react-datepicker": "^4.11.0",
"react-dom": "18",
"react-dropzone": "^14.2.3",
"react-fast-compare": "^3.2.1",
"react-fast-compare": "^3.2.2",
"react-geosuggest": "^2.7.0",
"react-intl": "^6.8.4",
"react-map-gl": "^5.2.1",
Expand Down
4 changes: 2 additions & 2 deletions pages/database.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import isEmpty from 'lodash/isEmpty';
import isEqual from 'lodash/isEqual';
import { isEmpty } from 'utils/general';
import isEqual from 'react-fast-compare';

// Redux
import { connect } from 'react-redux';
Expand Down
2 changes: 1 addition & 1 deletion pages/observations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Fragment } from 'react';
import PropTypes from 'prop-types';
import isEqual from 'lodash/isEqual';
import isEqual from 'react-fast-compare';
import orderBy from 'lodash/orderBy';
import debounce from 'lodash/debounce';
import { connect } from 'react-redux';
Expand Down
2 changes: 1 addition & 1 deletion pages/operator/edit/[[...id]].js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import PropTypes from 'prop-types';
import isEmpty from 'lodash/isEmpty';
import { isEmpty } from 'utils/general';

// Next
import Link from 'next/link';
Expand Down
Loading

0 comments on commit 2ccfdb4

Please sign in to comment.