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

update lodash imports to be tree shakable #8962

Merged
merged 1 commit into from
Oct 30, 2024
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
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-es";
import { startCase, camelCase } from "lodash-es";

defaultModules.set(PNotifyMobile, {});

Expand Down Expand Up @@ -44,7 +44,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
4 changes: 2 additions & 2 deletions src/components/Common/ExcelFIleDragAndDrop.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as _ from "lodash-es";
import { forIn } from "lodash-es";
import { useEffect, useRef, useState } from "react";
import * as Notification from "../../Utils/Notifications";
import { useTranslation } from "react-i18next";
Expand Down Expand Up @@ -63,7 +63,7 @@ export default function ExcelFileDragAndDrop({
const data = XLSX.utils.sheet_to_json(worksheet, { defval: "" });
//converts the date to string
data.forEach((row: any) => {
_.forIn(row, (value: any, key: string) => {
forIn(row, (value: any, key: string) => {
if (value instanceof Date) {
row[key] = value.toISOString().split("T")[0];
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as _ from "lodash-es";
import { lazy } from "react";
import routes from "../../../Redux/api";
import useQuery from "../../../Utils/request/useQuery";
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
@@ -1,7 +1,7 @@
import { useCallback, useReducer, useState } from "react";
import { InvestigationGroup, InvestigationType } from "..";

import _ from "lodash";
import { chain } from "lodash-es";
import { useTranslation } from "react-i18next";
import routes from "../../../../Redux/api";
import * as Notification from "../../../../Utils/Notifications";
Expand Down Expand Up @@ -172,7 +172,7 @@ const InvestigationReports = ({ id }: any) => {
),
);

const investigationList = _.chain(data)
const investigationList = chain(data)
.flatMap((i) => i?.data?.results)
.compact()
.flatten()
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,8 +1,8 @@
import * as _ from "lodash-es";
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: any) => {
return {
...value.session_object,
Expand All @@ -13,14 +13,14 @@ export const transformData = _.memoize((data: InvestigationResponse) => {
.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: any) => {
const sessionValues = Array.from({ length: sessions.length });
value.forEach((val: any) => {
const sessionIndex = _.findIndex(sessions, [
const sessionIndex = findIndex(sessions, [
"session_external_id",
val.session_object.session_external_id,
]);
Expand Down Expand Up @@ -59,7 +59,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
@@ -1,4 +1,4 @@
import * as _ from "lodash-es";
import { set, chain } from "lodash-es";
import { useCallback, useReducer } from "react";
import routes from "../../../Redux/api";
import * as Notification from "../../../Utils/Notifications";
Expand Down Expand Up @@ -89,7 +89,7 @@ export default function ShowInvestigation(props: ShowInvestigationProps) {

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: ShowInvestigationProps) {
};

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/Patient/PatientRegister.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import Spinner from "@/components/Common/Spinner";
import TextAreaFormField from "../Form/FormFields/TextAreaFormField";
import TextFormField from "../Form/FormFields/TextFormField";
import TransferPatientDialog from "../Facility/TransferPatientDialog";
import _ from "lodash";
import { startCase, toLower } from "lodash-es";
import countryList from "@/common/static/countries.json";
import { debounce } from "lodash-es";
import request from "../../Utils/request/request";
Expand Down Expand Up @@ -635,7 +635,7 @@ export const PatientRegister = (props: PatientRegisterProps) => {
? formData.last_vaccinated_date
: null
: null,
name: _.startCase(_.toLower(formData.name)),
name: startCase(toLower(formData.name)),
pincode: formData.pincode ? formData.pincode : undefined,
gender: Number(formData.gender),
nationality: formData.nationality,
Expand Down
10 changes: 5 additions & 5 deletions src/components/Patient/SampleDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ButtonV2 from "@/components/Common/components/ButtonV2";
import Card from "../../CAREUI/display/Card";
import { FileUpload } from "../Files/FileUpload";
import Page from "@/components/Common/components/Page";
import * as _ from "lodash-es";
import { startCase, camelCase, capitalize } from "lodash-es";
import { formatDateTime, formatPatientAge } from "../../Utils/utils";

import { navigate } from "raviger";
Expand Down Expand Up @@ -244,11 +244,11 @@ export const SampleDetails = ({ id }: DetailRoute) => {
<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))}
{startCase(camelCase(flow.status))}
</div>
<div>
<span className="font-semibold leading-relaxed">Label:</span>{" "}
{_.capitalize(flow.notes)}
{capitalize(flow.notes)}
</div>
<div>
<span className="font-semibold leading-relaxed">Created On :</span>{" "}
Expand Down Expand Up @@ -332,7 +332,7 @@ export const SampleDetails = ({ id }: DetailRoute) => {
<span className="font-semibold leading-relaxed">
Doctor&apos;s Name:{" "}
</span>
{_.startCase(_.camelCase(sampleDetails.doctor_name))}
{startCase(camelCase(sampleDetails.doctor_name))}
</div>
)}
{sampleDetails?.diagnosis && (
Expand Down Expand Up @@ -415,7 +415,7 @@ export const SampleDetails = ({ id }: DetailRoute) => {
<span className="font-semibold capitalize leading-relaxed">
Sample Type:{" "}
</span>
{_.startCase(_.camelCase(sampleDetails.sample_type))}
{startCase(camelCase(sampleDetails.sample_type))}
</div>
)}
</div>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Patient/SampleTestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SampleTestModel } from "./models";
import { SAMPLE_TEST_STATUS } from "@/common/constants";
import * as Notification from "../../Utils/Notifications";
import UpdateStatusDialog from "./UpdateStatusDialog";
import * as _ from "lodash-es";
import { startCase, camelCase } from "lodash-es";
import { formatDateTime } from "../../Utils/utils";
import ButtonV2 from "@/components/Common/components/ButtonV2";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
Expand Down Expand Up @@ -98,7 +98,7 @@ export const SampleTestCard = (props: SampleDetailsProps) => {
Status{" "}
</div>
<div className="mt-1 overflow-x-scroll whitespace-normal break-words text-sm font-medium leading-5">
{_.startCase(_.camelCase(itemData.status))}
{startCase(camelCase(itemData.status))}
</div>
</div>
</div>
Expand Down Expand Up @@ -133,7 +133,7 @@ export const SampleTestCard = (props: SampleDetailsProps) => {
Result{" "}
</div>
<div className="mt-1 overflow-x-scroll whitespace-normal break-words text-sm font-medium leading-5">
{_.startCase(_.camelCase(itemData.result))}
{startCase(camelCase(itemData.result))}
</div>
</div>
</div>
Expand Down
Loading