From 4c67359d230a47e61241eaf2d3f571544348bfbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Odd=20Andreas=20S=C3=B8rs=C3=A6ther?= Date: Fri, 1 Nov 2024 15:30:36 +0100 Subject: [PATCH] Fjern lodash.omit og pickBy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reduserer størrelse på pakken vår, både ved å droppe avhengighetene, og ved endringen i hvordan vi importerer moment i BannerNAVAnsatt. Før 1,799.26 kB │ gzip: 543.99 kB Etter 1,716.17 kB │ gzip: 515.39 kB --- package-lock.json | 32 ------------------- package.json | 4 --- src/AvtaleOversikt/AvtaleOversikt.tsx | 8 ++--- .../Filtrering/FiltreringProvider.tsx | 2 +- src/komponenter/Banner/BannerNAVAnsatt.tsx | 2 +- .../lagreOgAvbrytKnapp/LagreOgAvbrytKnapp.tsx | 5 ++- src/utils/stringUtils.ts | 4 --- src/utils/utils.ts | 15 +++++++++ 8 files changed, 23 insertions(+), 49 deletions(-) diff --git a/package-lock.json b/package-lock.json index 75303a57e..ee8a9fcd4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,8 +22,6 @@ "classnames": "^2.5.1", "lodash.debounce": "^4.0.8", "lodash.isequal": "^4.5.0", - "lodash.omit": "^4.5.0", - "lodash.pickby": "^4.6.0", "lodash.sortby": "^4.7.0", "moment": "^2.30.1", "prop-types": "^15.7.2", @@ -51,8 +49,6 @@ "@types/amplitude-js": "^8.16.5", "@types/lodash.debounce": "^4.0.9", "@types/lodash.isequal": "^4.5.8", - "@types/lodash.omit": "^4.5.9", - "@types/lodash.pickby": "^4.6.9", "@types/lodash.sortby": "^4.7.9", "@types/node": "^20.11.17", "@types/react": "18.3.11", @@ -3315,24 +3311,6 @@ "@types/lodash": "*" } }, - "node_modules/@types/lodash.omit": { - "version": "4.5.9", - "resolved": "https://registry.npmjs.org/@types/lodash.omit/-/lodash.omit-4.5.9.tgz", - "integrity": "sha512-zuAVFLUPJMOzsw6yawshsYGgq2hWUHtsZgeXHZmSFhaQQFC6EQ021uDKHkSjOpNhSvtNSU9165/o3o/Q51GpTw==", - "dev": true, - "dependencies": { - "@types/lodash": "*" - } - }, - "node_modules/@types/lodash.pickby": { - "version": "4.6.9", - "resolved": "https://registry.npmjs.org/@types/lodash.pickby/-/lodash.pickby-4.6.9.tgz", - "integrity": "sha512-SPI248FYnyd3jOxDeJq2vX2UKQnDzqacuqdeOVqwE1MPSk8gN8TA3FcHSMQWLlpBnuHgXvgKInvywbOFbidpJA==", - "dev": true, - "dependencies": { - "@types/lodash": "*" - } - }, "node_modules/@types/lodash.sortby": { "version": "4.7.9", "resolved": "https://registry.npmjs.org/@types/lodash.sortby/-/lodash.sortby-4.7.9.tgz", @@ -6376,16 +6354,6 @@ "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==" }, - "node_modules/lodash.omit": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/lodash.omit/-/lodash.omit-4.5.0.tgz", - "integrity": "sha512-XeqSp49hNGmlkj2EJlfrQFIzQ6lXdNro9sddtQzcJY8QaoC2GO0DT7xaIokHeyM+mIT0mPMlPvkYzg2xCuHdZg==" - }, - "node_modules/lodash.pickby": { - "version": "4.6.0", - "resolved": "https://registry.npmjs.org/lodash.pickby/-/lodash.pickby-4.6.0.tgz", - "integrity": "sha512-AZV+GsS/6ckvPOVQPXSiFFacKvKB4kOQu6ynt9wz0F3LO4R9Ij4K1ddYsIytDpSgLz88JHd9P+oaLeej5/Sl7Q==" - }, "node_modules/lodash.sortby": { "version": "4.7.0", "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", diff --git a/package.json b/package.json index fc45724cf..bd9a5e068 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,6 @@ "classnames": "^2.5.1", "lodash.debounce": "^4.0.8", "lodash.isequal": "^4.5.0", - "lodash.omit": "^4.5.0", - "lodash.pickby": "^4.6.0", "lodash.sortby": "^4.7.0", "moment": "^2.30.1", "prop-types": "^15.7.2", @@ -63,8 +61,6 @@ "@types/amplitude-js": "^8.16.5", "@types/lodash.debounce": "^4.0.9", "@types/lodash.isequal": "^4.5.8", - "@types/lodash.omit": "^4.5.9", - "@types/lodash.pickby": "^4.6.9", "@types/lodash.sortby": "^4.7.9", "@types/node": "^20.11.17", "@types/react": "18.3.11", diff --git a/src/AvtaleOversikt/AvtaleOversikt.tsx b/src/AvtaleOversikt/AvtaleOversikt.tsx index d590411ad..953d9d551 100644 --- a/src/AvtaleOversikt/AvtaleOversikt.tsx +++ b/src/AvtaleOversikt/AvtaleOversikt.tsx @@ -1,7 +1,6 @@ import { FunctionComponent, useContext, useEffect, useState } from 'react'; import { useSearchParams } from 'react-router-dom'; -import { Pagination, Select } from '@navikt/ds-react'; -import omit from 'lodash.omit'; +import { omit, Pagination, Select } from '@navikt/ds-react'; import isEqual from 'lodash.isequal'; import './AvtaleOversikt.less'; @@ -24,13 +23,14 @@ import { InnloggetBrukerContext } from '@/InnloggingBoundary/InnloggingBoundary' import { Path } from '@/Router'; import { Status } from '@/types/nettressurs'; import { Varsel } from '@/types/varsel'; -import { fjernTommeFelterFraObjekt, litenForbokstav } from '@/utils/stringUtils'; +import { litenForbokstav } from '@/utils/stringUtils'; import { useFilter } from '@/AvtaleOversikt/Filtrering/useFilter'; import { hentAvtalerForInnloggetBrukerMedPost, hentAvtalerForInnloggetBrukerMedSokId, hentUlesteVarsler, } from '@/services/rest-service'; +import { fjernTommeFelterFraObjekt } from '@/utils/utils'; const cls = BEMHelper('avtaleoversikt'); const clsPagination = BEMHelper('avtaleoversikt-pagination'); @@ -46,7 +46,7 @@ const AvtaleOversikt: FunctionComponent = () => { useEffect(() => { if (nettressursCtx.status !== Status.Lastet) return; - const filtreUtenPage = omit(filtre, 'page', 'sorteringskolonne', 'sorteringOrder'); + const filtreUtenPage = omit(filtre, ['page', 'sorteringskolonne', 'sorteringOrder']); const erFiltreLikeNettressursFiltre = isEqual( fjernTommeFelterFraObjekt(nettressursCtx.data.sokeParametere), fjernTommeFelterFraObjekt(filtreUtenPage), diff --git a/src/AvtaleOversikt/Filtrering/FiltreringProvider.tsx b/src/AvtaleOversikt/Filtrering/FiltreringProvider.tsx index 6e4884bc8..4bac4f83b 100644 --- a/src/AvtaleOversikt/Filtrering/FiltreringProvider.tsx +++ b/src/AvtaleOversikt/Filtrering/FiltreringProvider.tsx @@ -3,7 +3,7 @@ import { InnloggetBrukerContext } from '@/InnloggingBoundary/InnloggingBoundary' import { hentAvtalerForInnloggetBrukerMedPost, hentAvtalerForInnloggetBrukerMedSokId } from '@/services/rest-service'; import { Avtale, PageableAvtale, PageableAvtalelisteRessurs } from '@/types/avtale'; import { Status } from '@/types/nettressurs'; -import { fjernTommeFelterFraObjekt } from '@/utils/stringUtils'; +import { fjernTommeFelterFraObjekt } from '@/utils/utils'; import { Dispatch, FunctionComponent, diff --git a/src/komponenter/Banner/BannerNAVAnsatt.tsx b/src/komponenter/Banner/BannerNAVAnsatt.tsx index df164e45f..e813f4234 100644 --- a/src/komponenter/Banner/BannerNAVAnsatt.tsx +++ b/src/komponenter/Banner/BannerNAVAnsatt.tsx @@ -7,7 +7,7 @@ import VerticalSpacer from '../layout/VerticalSpacer'; import nyheter from '../NyttIAppen/nyheter'; import Nytt from '../NyttIAppen/Nytt'; import './Banner.less'; -import moment from 'moment/moment'; +import moment from 'moment'; import { useAvtale } from '@/AvtaleProvider'; import { useFeatureToggles } from '@/FeatureToggleProvider'; diff --git a/src/komponenter/lagreOgAvbrytKnapp/LagreOgAvbrytKnapp.tsx b/src/komponenter/lagreOgAvbrytKnapp/LagreOgAvbrytKnapp.tsx index d97ad7376..7694d3554 100644 --- a/src/komponenter/lagreOgAvbrytKnapp/LagreOgAvbrytKnapp.tsx +++ b/src/komponenter/lagreOgAvbrytKnapp/LagreOgAvbrytKnapp.tsx @@ -1,7 +1,6 @@ import { Nettressurs, Status } from '@/types/nettressurs'; import { handterFeil } from '@/utils/apiFeilUtils'; -import { Alert } from '@navikt/ds-react'; -import omit from 'lodash.omit'; +import { Alert, omit } from '@navikt/ds-react'; import { Button, ButtonProps } from '@navikt/ds-react'; import { FunctionComponent, HTMLAttributes, useEffect, useRef, useState } from 'react'; import BEMHelper from '@/utils/bem'; @@ -19,7 +18,7 @@ const LagreOgAvbrytKnapp: FunctionComponent = (props) => { const [feilmelding, setFeilmelding] = useState(''); // Fjerner ikke-standard knapp-props før de spreades inn i KnappBase. - const knappBaseProps: ButtonProps = omit(props, ['lagreFunksjon', 'avbryt', 'lagreTekst']); + const knappBaseProps: ButtonProps = omit(props, ['lagreFunksjon', 'avbryt', 'lagretekst']); const feilRef = useRef(null); diff --git a/src/utils/stringUtils.ts b/src/utils/stringUtils.ts index e17289f50..cc907cf77 100644 --- a/src/utils/stringUtils.ts +++ b/src/utils/stringUtils.ts @@ -1,5 +1,3 @@ -import pickBy from 'lodash.pickby'; - export const storForbokstav = (tekst: string) => { return tekst ? tekst.toLowerCase().replace(/\b\w/, (v) => v.toUpperCase()) : tekst; }; @@ -14,5 +12,3 @@ export const kunStorForbokstav = (tekst: string) => { // https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex export const escapeRegExp = (streng: string) => streng.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - -export const fjernTommeFelterFraObjekt = (objekt: any) => pickBy(objekt); diff --git a/src/utils/utils.ts b/src/utils/utils.ts index fd4318b87..ff3064704 100644 --- a/src/utils/utils.ts +++ b/src/utils/utils.ts @@ -10,3 +10,18 @@ export const miljo = () => { return 'local'; } }; + +type RemoveUndefined = { + [P in keyof T]: undefined extends T[P] ? never : null extends T[P] ? never : P; +}[keyof T]; + +export const fjernTommeFelterFraObjekt = (objekt: T): Pick> => { + const copy = { ...objekt }; + const keys = Object.keys(copy) as Array; + keys.forEach((key) => { + if (copy[key] === undefined || copy[key] === null) { + delete copy[key]; + } + }); + return copy as Pick>; +};