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

Optimize lodash. Fixes #6006 #6415

Merged
merged 4 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
18 changes: 16 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"events": "^3.3.0",
"i18next": "^23.2.7",
"i18next-browser-languagedetector": "^7.1.0",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"postcss-loader": "^7.3.3",
"qrcode.react": "^3.1.0",
"raviger": "^4.1.2",
Expand Down Expand Up @@ -113,7 +113,7 @@
"@types/cypress": "^1.1.3",
"@types/echarts": "^4.9.18",
"@types/google.maps": "^3.53.4",
"@types/lodash": "^4.14.195",
"@types/lodash-es": "^4.17.9",
"@types/lodash.get": "^4.4.7",
"@types/node": "^20.4.0",
"@types/prop-types": "*",
Expand Down
2 changes: 1 addition & 1 deletion src/Common/hooks/useAsyncOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { debounce } from "lodash";
import { debounce } from "lodash-es";
import { useMemo, useState } from "react";
import { useDispatch } from "react-redux";

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Common/Uptime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { listAssetAvailability } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import * as Notification from "../../Utils/Notifications.js";
import { AssetStatus, AssetUptimeRecord } from "../Assets/AssetTypes";
import { reverse } from "lodash";
import { reverse } from "lodash-es";
import { classNames } from "../../Utils/utils";
import dayjs from "../../Utils/dayjs";

Expand Down
7 changes: 3 additions & 4 deletions src/Components/ExternalResult/ExternalResultUpload.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import _ from "lodash";
import { navigate } from "raviger";
import { lazy, useState } from "react";
import CSVReader from "react-csv-reader";
Expand Down Expand Up @@ -117,13 +116,13 @@ export default function ExternalResultUpload() {
<div className="mr-2 p-2">{index + 1}</div>
<div className="mr-2 p-2 md:w-1/3">{data.name}</div>

<div className="mr-2 p-2">
<div className="mr-2 p-2 capitalize">
{errors && errors.length !== 0
? errors.map((error: any) => {
return (
<div key={error[0][0]}>
{_.startCase(_.camelCase(error[0][0]))} -{" "}
{error[0][1]}
{error[0][0].toLowerCase()} -{" "}
{error[0][1].toLowerCase()}
</div>
);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import ButtonV2 from "../../Common/components/ButtonV2";
import CareIcon from "../../../CAREUI/icons/CareIcon";
import { SelectFormField } from "../../Form/FormFields/SelectFormField";
import TextFormField from "../../Form/FormFields/TextFormField";
import _ from "lodash";
import { classNames } from "../../../Utils/utils";
import { useState } from "react";

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Facility/Investigations/Reports/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { InvestigationResponse } from "./types";
import Loading from "../../../Common/Loading";
import Page from "../../../Common/components/Page";
import ReportTable from "./ReportTable";
import _ from "lodash";
import { chain } from "lodash-es";
import { useDispatch } from "react-redux";
import { useRef } from "react";

Expand Down Expand Up @@ -175,7 +175,7 @@ const InvestigationReports = ({ id }: any) => {
})
);

const investigationList = _.chain(data)
const investigationList = chain(data)
.compact()
.flatten()
.map((i) => ({
Expand Down
12 changes: 6 additions & 6 deletions src/Components/Facility/Investigations/Reports/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import _ from "lodash";
import { memoize, chain, findIndex } from "lodash-es";
import { InvestigationResponse } from "./types";

export const transformData = _.memoize((data: InvestigationResponse) => {
const sessions = _.chain(data)
export const transformData = memoize((data: InvestigationResponse) => {
const sessions = chain(data)
.map((value) => value.session_object)
.uniqBy("session_external_id")
.orderBy("session_created_date", "desc")
.value();
const groupByInvestigation = _.chain(data)
const groupByInvestigation = chain(data)
.groupBy("investigation_object.external_id")
.values()
.value();
const reqData = groupByInvestigation.map((value) => {
const sessionValues = Array.from({ length: sessions.length });
value.forEach((val) => {
const sessionIndex = _.findIndex(sessions, [
const sessionIndex = findIndex(sessions, [
"session_external_id",
val.session_object.session_external_id,
]);
Expand Down Expand Up @@ -55,7 +55,7 @@ export const transformData = _.memoize((data: InvestigationResponse) => {
return { sessions, data: reqData };
});

export const getColorIndex = _.memoize(
export const getColorIndex = memoize(
({ max, min, value }: { min?: number; max?: number; value?: number }) => {
if (!max && min && value) {
// 1 => yellow color
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import PageTitle from "../../Common/PageTitle";
import InvestigationTable from "./InvestigationTable";

import _ from "lodash";
import { set, chain } from "lodash-es";
import { navigate } from "raviger";
import * as Notification from "../../../Utils/Notifications.js";

Expand Down Expand Up @@ -110,7 +110,7 @@ export default function ShowInvestigation(props: any) {

const handleValueChange = (value: any, name: string) => {
const changedFields = { ...state.changedFields };
_.set(changedFields, name, value);
set(changedFields, name, value);
dispatch({ type: "set_changed_fields", changedFields });
};

Expand Down Expand Up @@ -147,7 +147,7 @@ export default function ShowInvestigation(props: any) {
};

const handleUpdateCancel = useCallback(() => {
const changedValues = _.chain(state.initialValues)
const changedValues = chain(state.initialValues)
.map((val: any, _key: string) => ({
id: val?.id,
initialValue: val?.notes || val?.value || null,
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Facility/Investigations/Table.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { FieldChangeEvent } from "../../Form/FormFields/Utils";
import { SelectFormField } from "../../Form/FormFields/SelectFormField";
import TextFormField from "../../Form/FormFields/TextFormField";
import _ from "lodash";
import { set } from "lodash-es";
import { useState } from "react";

const TestRow = ({ data, value, onChange, i }: any) => {
Expand Down Expand Up @@ -59,7 +59,7 @@ export const TestTable = ({ title, data, state, dispatch }: any) => {

const handleValueChange = (value: any, name: string) => {
const form = { ...state };
_.set(form, name, value);
set(form, name, value);
dispatch({ type: "set_form", form });
};

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Facility/LegacyFacilityCNS.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Pagination from "../Common/Pagination";
import { PatientModel } from "../Patient/models";
import { FacilityModel } from "./models";
import AutocompleteFormField from "../Form/FormFields/Autocomplete";
import { uniqBy } from "lodash";
import { uniqBy } from "lodash-es";
import DialogModal from "../Common/Dialog";
import { LegacyMonitorCard } from "./LegacyMonitorCard";

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Form/AutoCompleteAsync.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState, useMemo } from "react";
import { Combobox } from "@headlessui/react";
import { debounce } from "lodash";
import { debounce } from "lodash-es";
import { DropdownTransition } from "../Common/components/HelperComponents";
import CareIcon from "../../CAREUI/icons/CareIcon";
import {
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Form/Form.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isEmpty, omitBy } from "lodash";
import { isEmpty, omitBy } from "lodash-es";
import { useEffect, useMemo, useState } from "react";
import { classNames } from "../../Utils/utils";
import { Cancel, Submit } from "../Common/components/ButtonV2";
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
import TextFormField from "../Form/FormFields/TextFormField";
import TransferPatientDialog from "../Facility/TransferPatientDialog";
import countryList from "../../Common/static/countries.json";
import { debounce } from "lodash";
import { debounce } from "lodash-es";

import useAppHistory from "../../Common/hooks/useAppHistory";
import useConfig from "../../Common/hooks/useConfig";
Expand Down
33 changes: 20 additions & 13 deletions src/Components/Patient/SampleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import ButtonV2 from "../Common/components/ButtonV2";
import Card from "../../CAREUI/display/Card";
import { FileUpload } from "./FileUpload";
import Page from "../Common/components/Page";
import _ from "lodash";
import { formatAge, formatDateTime } from "../../Utils/utils";
import { getTestSample } from "../../Redux/actions";

Expand Down Expand Up @@ -258,12 +257,16 @@ export const SampleDetails = ({ id }: DetailRoute) => {
<Card key={flow.id}>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<div>
<span className="font-semibold leading-relaxed">Status: </span>{" "}
{_.startCase(_.camelCase(flow.status))}
<span className="font-semibold capitalize leading-relaxed">
Status:{" "}
</span>{" "}
{flow.status}
</div>
<div>
<span className="font-semibold leading-relaxed">Label:</span>{" "}
{_.capitalize(flow.notes)}
<span className="font-semibold capitalize leading-relaxed">
Label:
</span>{" "}
{flow.notes?.toLowerCase()}
</div>
<div>
<span className="font-semibold leading-relaxed">Created On :</span>{" "}
Expand Down Expand Up @@ -301,12 +304,16 @@ export const SampleDetails = ({ id }: DetailRoute) => {
<Card>
<div className="grid grid-cols-1 gap-4 md:grid-cols-2">
<div>
<span className="font-semibold leading-relaxed">Status: </span>
{_.startCase(_.camelCase(sampleDetails.status))}
<span className="font-semibold capitalize leading-relaxed">
Status:{" "}
</span>
{sampleDetails.status}
</div>
<div>
<span className="font-semibold leading-relaxed">Result: </span>
{_.startCase(_.camelCase(sampleDetails.result))}
<span className="font-semibold capitalize leading-relaxed">
Result:{" "}
</span>
{sampleDetails.result}
</div>
<div>
<span className="font-semibold leading-relaxed">Patient: </span>
Expand Down Expand Up @@ -339,11 +346,11 @@ export const SampleDetails = ({ id }: DetailRoute) => {
</div>
)}
{sampleDetails.doctor_name && (
<div className="md:col-span-2">
<div className="capitalize md:col-span-2">
<span className="font-semibold leading-relaxed">
Doctor&apos;s Name:{" "}
</span>
{_.startCase(_.camelCase(sampleDetails.doctor_name))}
{sampleDetails.doctor_name}
</div>
)}
{sampleDetails.diagnosis && (
Expand Down Expand Up @@ -423,10 +430,10 @@ export const SampleDetails = ({ id }: DetailRoute) => {
)}
{sampleDetails.sample_type && (
<div className="md:col-span-2">
<span className="font-semibold leading-relaxed">
<span className="font-semibold capitalize leading-relaxed">
Sample Type:{" "}
</span>
{_.startCase(_.camelCase(sampleDetails.sample_type))}
{sampleDetails.sample_type}
</div>
)}
</div>
Expand Down
16 changes: 8 additions & 8 deletions src/Components/Patient/SampleTestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { SAMPLE_TEST_STATUS } from "../../Common/constants";
import { patchSample } from "../../Redux/actions";
import * as Notification from "../../Utils/Notifications";
import UpdateStatusDialog from "./UpdateStatusDialog";
import _ from "lodash";
import { formatDateTime } from "../../Utils/utils";
import ButtonV2 from "../Common/components/ButtonV2";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
Expand Down Expand Up @@ -91,8 +90,8 @@ export const SampleTestCard = (props: SampleDetailsProps) => {
<div className="text-sm font-semibold leading-5 text-zinc-400">
Status{" "}
</div>
<div className="mt-1 overflow-x-scroll whitespace-normal break-words text-sm font-medium leading-5">
{_.startCase(_.camelCase(itemData.status))}
<div className="mt-1 overflow-x-scroll whitespace-normal break-words text-sm font-medium capitalize leading-5">
{itemData.status?.toLowerCase()}
</div>
</div>
</div>
Expand All @@ -101,10 +100,11 @@ export const SampleTestCard = (props: SampleDetailsProps) => {
<div className="text-sm font-semibold leading-5 text-zinc-400">
Sample Type{" "}
</div>
<div className="mt-1 overflow-x-scroll whitespace-normal break-words text-sm font-medium leading-5">
{itemData.sample_type !== "OTHER TYPE"
<div className="mt-1 overflow-x-scroll whitespace-normal break-words text-sm font-medium capitalize leading-5">
{(itemData.sample_type !== "OTHER TYPE"
? itemData.sample_type
: itemData.sample_type_other}
: itemData.sample_type_other
)?.toLowerCase()}
</div>
</div>
</div>
Expand All @@ -125,8 +125,8 @@ export const SampleTestCard = (props: SampleDetailsProps) => {
<div className="text-sm font-semibold leading-5 text-zinc-400">
Result{" "}
</div>
<div className="mt-1 overflow-x-scroll whitespace-normal break-words text-sm font-medium leading-5">
{_.startCase(_.camelCase(itemData.result))}
<div className="mt-1 overflow-x-scroll whitespace-normal break-words text-sm font-medium capitalize leading-5">
{itemData.result?.toLowerCase()}
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Redux/fireRequest.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Notification from "../Utils/Notifications.js";

import { isEmpty, omitBy } from "lodash";
import { isEmpty, omitBy } from "lodash-es";

import { LocalStorageKeys } from "../Common/constants";
import api from "./api";
Expand Down
4 changes: 2 additions & 2 deletions src/Utils/Notifications.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { alert, Stack, defaultModules } from "@pnotify/core";
import * as PNotifyMobile from "@pnotify/mobile";
import _ from "lodash";
import { startCase, camelCase } from "lodash-es";

defaultModules.set(PNotifyMobile, {});

Expand Down Expand Up @@ -43,7 +43,7 @@ const notifyError = (error) => {
errorMsg = error.detail;
} else {
for (let [key, value] of Object.entries(error)) {
let keyName = _.startCase(_.camelCase(key));
let keyName = startCase(camelCase(key));
if (Array.isArray(value)) {
const uniques = [...new Set(value)];
errorMsg += `${keyName} - ${uniques.splice(0, 5).join(", ")}`;
Expand Down
Loading