Skip to content

Commit f5045cb

Browse files
authored
Remove lodash and use native methods instead (#1141)
1 parent 10e705a commit f5045cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1371
-677
lines changed

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
"@sentry/react": "^7.72.0",
1414
"@types/jest": "^24.0.11",
1515
"@types/jquery": "^3.3.29",
16-
"@types/lodash": "^4.14.123",
1716
"@types/node": "^11.11.1",
1817
"@types/rc-tooltip": "^3.7.1",
1918
"@types/react": "16.9.34",
@@ -37,7 +36,6 @@
3736
"history": "^4.10.1",
3837
"js-file-download": "^0.4.8",
3938
"loaders.css": "0.1.2",
40-
"lodash": "4.17.21",
4139
"mobx": "^3.1.11",
4240
"mobx-react": "^4.2.1",
4341
"mobx-react-router": "^4.0.7",
@@ -90,7 +88,6 @@
9088
"@types/classnames": "^2.2.9",
9189
"@types/enzyme": "3.10.5",
9290
"@types/jest": "25.2.1",
93-
"@types/lodash": "4.14.150",
9491
"@types/node": "13.13.4",
9592
"@types/pluralize": "0.0.29",
9693
"@types/react": "16.9.34",
@@ -113,7 +110,7 @@
113110
"browser-sync-webpack-plugin": "2.2.2",
114111
"cache-loader": "4.1.0",
115112
"copy-webpack-plugin": "5.1.1",
116-
"core-js": "3.6.5",
113+
"core-js": "3.38.0",
117114
"cross-env": "7.0.2",
118115
"css-loader": "3.5.3",
119116
"enzyme": "3.11.0",

src/main/webapp/app/components/CitationTooltip.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { remoteData } from 'cbioportal-frontend-commons';
44
import request from 'superagent';
55
import LoadingIndicator from 'app/components/loadingIndicator/LoadingIndicator';
66
import { ArticleAbstract } from 'app/shared/api/generated/OncoKbAPI';
7-
import _ from 'lodash';
87
import PmidItem from 'app/components/PmidItem';
98
import ArticleAbstractItem from 'app/components/ArticleAbstractItem';
109
import { TOOLTIP_MAX_HEIGHT } from 'app/config/constants';
@@ -36,7 +35,7 @@ export class CitationTooltip extends React.Component<
3635
key={pmid}
3736
title={data.title}
3837
author={
39-
_.isArray(data.authors) && data.authors.length > 0
38+
Array.isArray(data.authors) && data.authors.length > 0
4039
? data.authors[0].name + ' et al.'
4140
: 'Unknown'
4241
}

src/main/webapp/app/components/LevelWithDescription.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { inject } from 'mobx-react';
33
import React from 'react';
44
import { DefaultTooltip } from 'cbioportal-frontend-commons';
55
import { InfoLevel } from 'app/shared/api/generated/OncoKbAPI';
6-
import _ from 'lodash';
76
import { level2LevelOfEvidence } from 'app/shared/utils/Utils';
87
import ReactHtmlParser from 'react-html-parser';
98
import { LEVELS } from 'app/config/constants';
@@ -19,8 +18,9 @@ export const LevelWithDescription: React.FunctionComponent<{
1918
if (props.description) {
2019
return <span>{props.description}</span>;
2120
}
22-
const match: InfoLevel | undefined = _.find(
23-
props.appStore!.appInfo.result.levels,
21+
const match:
22+
| InfoLevel
23+
| undefined = props.appStore!.appInfo.result.levels.find(
2424
(level: InfoLevel) => level.levelOfEvidence === levelOfEvidence
2525
);
2626
return match ? (

src/main/webapp/app/components/authDownloadButton/AuthDownloadButton.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import { observer, inject } from 'mobx-react';
88
import { observable, action } from 'mobx';
99
import { LoadingButton } from 'app/shared/button/LoadingButton';
1010
import { IDownloadButtonWithPromise } from 'app/components/downloadButtonWithPromise/DownloadButtonWithPromise';
11-
import _ from 'lodash';
1211

1312
interface IAuthDownloadButton extends IDownloadButtonWithPromise {
1413
routing?: RouterStore;
@@ -27,7 +26,7 @@ export class AuthDownloadButton extends React.Component<IAuthDownloadButton> {
2726
this.props
2827
.getDownloadData()
2928
.then(data => {
30-
if (_.isArray(data)) {
29+
if (Array.isArray(data)) {
3130
data = data.join('');
3231
}
3332
fileDownload(data, this.props.fileName, this.props.mime);

src/main/webapp/app/components/barChart/BarChart.tsx

+11-11
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
getTextWidth,
1818
getTextDiagonal,
1919
} from 'cbioportal-frontend-commons';
20-
import _ from 'lodash';
2120
import { PortalAlteration } from 'app/shared/api/generated/OncoKbPrivateAPI';
2221
import { FONT_FAMILY } from 'app/config/constants';
22+
import { uniq } from 'app/shared/utils/LodashUtils';
2323

2424
export type BarChartDatum = {
2525
x: string;
@@ -102,8 +102,8 @@ export default class BarChart extends React.Component<IBarChartProps, {}> {
102102
get bottomPadding(): number {
103103
const MIN_PADDING = 10; // used when tickFormat is empty
104104
const padding =
105-
_.max(
106-
this.props.data.map(datum => {
105+
Math.max(
106+
...this.props.data.map(datum => {
107107
const content = datum.x;
108108
const fontFamily = FONT_FAMILY;
109109
const fontSize = `${FONT_SIZE}px`;
@@ -126,10 +126,10 @@ export default class BarChart extends React.Component<IBarChartProps, {}> {
126126
get rightPadding(): number {
127127
const MIN_PADDING = 10; // used when tickFormat is empty
128128
const MAX_PADDING = 90;
129-
const lastThreeElements = _.takeRight(this.props.data, 3);
129+
const lastThreeElements = this.props.data.slice(-3);
130130
const padding =
131-
_.max(
132-
lastThreeElements.map(datum => {
131+
Math.max(
132+
...lastThreeElements.map(datum => {
133133
const content = datum.x;
134134
const fontFamily = FONT_FAMILY;
135135
const fontSize = `${FONT_SIZE}px`;
@@ -159,14 +159,14 @@ export default class BarChart extends React.Component<IBarChartProps, {}> {
159159
containerComponent={
160160
<VictorySelectionContainer
161161
selectionDimension="x"
162-
onSelection={(points: any, bounds: any, props: any) => {
162+
onSelection={(points: unknown[], bounds: any, props: any) => {
163163
if (this.props.onUserSelection) {
164-
const filters = _.uniq(
165-
_.flatten(
166-
points.map((point: any) =>
164+
const filters = uniq(
165+
points
166+
.map((point: any) =>
167167
point.data.map((dataPoint: any) => dataPoint.xName)
168168
)
169-
)
169+
.flat()
170170
);
171171
// @ts-ignore
172172
this.props.onUserSelection(filters);

src/main/webapp/app/components/barChart/BarChartToolTip.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as React from 'react';
2-
import * as _ from 'lodash';
32
import { computed } from 'mobx';
43
import { Popover } from 'react-bootstrap';
54
import classnames from 'classnames';

src/main/webapp/app/components/downloadButtonWithPromise/DownloadButtonWithPromise.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { ButtonProps } from 'react-bootstrap';
22
import React from 'react';
3-
import classnames from 'classnames';
43
import fileDownload from 'js-file-download';
54
import { observer, inject } from 'mobx-react';
65
import { observable, action } from 'mobx';
76
import { LoadingButton } from 'app/shared/button/LoadingButton';
8-
import _ from 'lodash';
97

108
export interface IDownloadButtonWithPromise extends ButtonProps {
119
getDownloadData: () => Promise<string | Blob | string[]>;
@@ -27,7 +25,7 @@ export class DownloadButtonWithPromise extends React.Component<
2725
this.props
2826
.getDownloadData()
2927
.then(data => {
30-
if (_.isArray(data)) {
28+
if (Array.isArray(data)) {
3129
data = data.join('');
3230
}
3331
fileDownload(data, this.props.fileName, this.props.mime);

src/main/webapp/app/components/newAccountForm/NewAccountForm.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
getSectionClassName,
3535
} from 'app/pages/account/AccountUtils';
3636
import { If, Then } from 'react-if';
37-
import _ from 'lodash';
3837
import { FormSelectWithLabelField } from 'app/shared/select/FormSelectWithLabelField';
3938
import client from 'app/shared/api/clientInstance';
4039
import { notifyError } from 'app/shared/utils/NotificationUtils';
@@ -133,7 +132,7 @@ export class NewAccountForm extends React.Component<INewAccountForm> {
133132
country: values.country,
134133
};
135134
const additionalInfo = this.constructAdditionalInfo(values);
136-
if (_.keys(additionalInfo).length > 0) {
135+
if (Object.keys(additionalInfo).length > 0) {
137136
newUser.additionalInfo = additionalInfo;
138137
}
139138
if (values.tokenValidDays) {
@@ -180,7 +179,7 @@ export class NewAccountForm extends React.Component<INewAccountForm> {
180179
};
181180
}
182181

183-
if (_.keys(additionalInfo.userCompany).length === 0) {
182+
if (Object.keys(additionalInfo.userCompany).length === 0) {
184183
delete additionalInfo.userCompany;
185184
}
186185
return additionalInfo;

src/main/webapp/app/components/newCompanyForm/NewCompanyForm.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
LICENSE_MODEL_DESCRIPTIONS,
2727
} from 'app/config/constants';
2828
import client from 'app/shared/api/clientInstance';
29-
import _ from 'lodash';
3029
import { notifyError } from 'app/shared/utils/NotificationUtils';
3130
import { AdditionalInfoSelect } from 'app/shared/dropdown/AdditionalInfoSelect';
3231
import {

src/main/webapp/app/components/oncokbSearch/OncoKBSearch.tsx

+10-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from 'app/shared/utils/Utils';
1515
import { inject, observer } from 'mobx-react';
1616
import { observable } from 'mobx';
17-
import _ from 'lodash';
1817
import AppStore from 'app/store/AppStore';
1918
import SearchInfoIcon from 'app/components/oncokbSearch/SearchInfoIcon';
2019
import { remoteData } from 'cbioportal-frontend-commons';
@@ -37,21 +36,19 @@ export default class OncoKBSearch extends React.Component<IOncoKBSearch, {}> {
3736
readonly options = remoteData<ExtendedTypeaheadSearchResp[]>({
3837
invoke: async () => {
3938
try {
40-
return _.reduce(
39+
return (
4140
await oncokbPrivateClient.searchTypeAheadGetUsingGET({
4241
query: this.keyword,
4342
limit: 20,
44-
}),
45-
(acc, result) => {
46-
acc.push({
47-
tumorTypesName: getAllTumorTypesName(result.tumorTypes),
48-
alterationsName: getAllAlterationsName(result.variants),
49-
...result,
50-
});
51-
return acc;
52-
},
53-
[] as ExtendedTypeaheadSearchResp[]
54-
);
43+
})
44+
).reduce((acc, result) => {
45+
acc.push({
46+
tumorTypesName: getAllTumorTypesName(result.tumorTypes),
47+
alterationsName: getAllAlterationsName(result.variants),
48+
...result,
49+
});
50+
return acc;
51+
}, [] as ExtendedTypeaheadSearchResp[]);
5552
} catch (error) {
5653
const errorOptions: ExtendedTypeaheadSearchResp[] = [];
5754
if (error) {

src/main/webapp/app/components/userMessager/UserMessage.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
IReactionDisposer,
99
toJS,
1010
} from 'mobx';
11-
import * as _ from 'lodash';
1211
import styles from './styles.module.scss';
1312
import classNames from 'classnames';
1413
import { Container } from 'react-bootstrap';
@@ -193,7 +192,7 @@ export default class UserMessage extends React.Component<UserMessageProps> {
193192
if (localStorage.getItem(DISABLE_BANNER_OPT) === 'true') {
194193
return [];
195194
}
196-
return _.filter(MESSAGE_DATA, message => {
195+
return MESSAGE_DATA.filter(message => {
197196
const notYetShown = !localStorage.getItem(makeMessageKey(message.id));
198197
const toBeShown = message.dateStart
199198
? Date.now() >= message.dateStart

src/main/webapp/app/index.tsx

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as superagent from 'superagent';
66
import * as React from 'react';
77
import * as ReactDOM from 'react-dom';
88
import App from './App';
9-
import registerServiceWorker from './registerServiceWorker';
109
import * as Sentry from '@sentry/react';
1110

1211
import 'font-awesome/css/font-awesome.css';
@@ -25,7 +24,6 @@ import {
2524
getStoredRecaptchaToken,
2625
} from 'app/indexUtils';
2726
import { UNAUTHORIZED_ALLOWED_PATH } from 'app/config/constants';
28-
import _ from 'lodash';
2927
import { AppConfig, AppProfile } from 'app/appConfig';
3028

3129
assignPublicToken();
@@ -81,7 +79,7 @@ superagent.Request.prototype.end = function (callback) {
8179
AppConfig.serverConfig.token &&
8280
AppConfig.serverConfig.appProfile === AppProfile.PROD &&
8381
response.req &&
84-
!_.some(UNAUTHORIZED_ALLOWED_PATH, path =>
82+
UNAUTHORIZED_ALLOWED_PATH.some(path =>
8583
window.location.pathname.endsWith(path)
8684
)
8785
) {

src/main/webapp/app/oncokb-frontend-commons/src/components/ReferenceList.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { ArticleAbstract } from 'oncokb-ts-api-client';
22
import * as React from 'react';
3-
import _ from 'lodash';
43

54
import ArticleAbstractItem from './ArticleAbstractItem';
65
import PmidItem from './PmidItem';
@@ -87,7 +86,7 @@ export const ReferenceList: React.FunctionComponent<ReferenceListProps> = (
8786
<PmidItem
8887
title={articleContent.title}
8988
author={
90-
_.isArray(articleContent.authors) &&
89+
Array.isArray(articleContent.authors) &&
9190
articleContent.authors.length > 0
9291
? articleContent.authors[0].name + ' et al.'
9392
: 'Unknown'

src/main/webapp/app/pages/CancerGenesPage.tsx

+28-41
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { inject, observer } from 'mobx-react';
55
import { defaultSortMethod } from 'app/shared/utils/ReactTableUtils';
66
import { GenePageLink } from 'app/shared/utils/UrlUtils';
77
import { Col, Row } from 'react-bootstrap';
8-
import * as _ from 'lodash';
98
import OncoKBTable, {
109
SearchColumn,
1110
} from 'app/components/oncokbTable/OncoKBTable';
@@ -401,47 +400,35 @@ export default class CancerGenesPage extends React.Component<{
401400
private readonly extendedCancerGene = remoteData<ExtendCancerGene[]>({
402401
await: () => [this.annotatedGenes, this.cancerGenes],
403402
invoke: () => {
404-
const annotatedGenes = _.reduce(
405-
this.annotatedGenes.result,
406-
(acc, next) => {
407-
acc[next.entrezGeneId] = true;
408-
return acc;
409-
},
410-
{} as { [entrezGeneId: number]: boolean }
411-
);
403+
const annotatedGenes = this.annotatedGenes.result.reduce((acc, next) => {
404+
acc[next.entrezGeneId] = true;
405+
return acc;
406+
}, {} as { [entrezGeneId: number]: boolean });
412407
return Promise.resolve(
413-
_.reduce(
414-
this.cancerGenes.result,
415-
(cancerGenesAcc, cancerGene) => {
416-
const sourceKeys: (keyof CancerGene)[] = [
417-
'oncokbAnnotated',
418-
'mSKImpact',
419-
'mSKHeme',
420-
'foundation',
421-
'foundationHeme',
422-
'vogelstein',
423-
'sangerCGC',
424-
];
425-
cancerGenesAcc.push({
426-
...cancerGene,
427-
numOfSources: _.reduce(
428-
sourceKeys,
429-
(numOfSourcesAcc, next) => {
430-
if (cancerGene[next]) {
431-
numOfSourcesAcc++;
432-
}
433-
return numOfSourcesAcc;
434-
},
435-
0
436-
),
437-
geneType: getGeneType(cancerGene.oncogene, cancerGene.tsg),
438-
annotated: !!annotatedGenes[cancerGene.entrezGeneId],
439-
geneAliases: cancerGene.geneAliases,
440-
});
441-
return cancerGenesAcc;
442-
},
443-
[] as ExtendCancerGene[]
444-
)
408+
this.cancerGenes.result.reduce((cancerGenesAcc, cancerGene) => {
409+
const sourceKeys: (keyof CancerGene)[] = [
410+
'oncokbAnnotated',
411+
'mSKImpact',
412+
'mSKHeme',
413+
'foundation',
414+
'foundationHeme',
415+
'vogelstein',
416+
'sangerCGC',
417+
];
418+
cancerGenesAcc.push({
419+
...cancerGene,
420+
numOfSources: sourceKeys.reduce((numOfSourcesAcc, next) => {
421+
if (cancerGene[next]) {
422+
numOfSourcesAcc++;
423+
}
424+
return numOfSourcesAcc;
425+
}, 0),
426+
geneType: getGeneType(cancerGene.oncogene, cancerGene.tsg),
427+
annotated: !!annotatedGenes[cancerGene.entrezGeneId],
428+
geneAliases: cancerGene.geneAliases,
429+
});
430+
return cancerGenesAcc;
431+
}, [] as ExtendCancerGene[])
445432
);
446433
},
447434
default: [],

0 commit comments

Comments
 (0)