Skip to content

Commit

Permalink
Fjern lodash.omit og pickBy
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oddsor committed Nov 7, 2024
1 parent 5023696 commit 4c67359
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 49 deletions.
32 changes: 0 additions & 32 deletions package-lock.json

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

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions src/AvtaleOversikt/AvtaleOversikt.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand All @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/AvtaleOversikt/Filtrering/FiltreringProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/komponenter/Banner/BannerNAVAnsatt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
5 changes: 2 additions & 3 deletions src/komponenter/lagreOgAvbrytKnapp/LagreOgAvbrytKnapp.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -19,7 +18,7 @@ const LagreOgAvbrytKnapp: FunctionComponent<Props & ButtonProps> = (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<HTMLDivElement>(null);

Expand Down
4 changes: 0 additions & 4 deletions src/utils/stringUtils.ts
Original file line number Diff line number Diff line change
@@ -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;
};
Expand All @@ -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);
15 changes: 15 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,18 @@ export const miljo = () => {
return 'local';
}
};

type RemoveUndefined<T> = {
[P in keyof T]: undefined extends T[P] ? never : null extends T[P] ? never : P;
}[keyof T];

export const fjernTommeFelterFraObjekt = <T extends object>(objekt: T): Pick<T, RemoveUndefined<T>> => {
const copy = { ...objekt };
const keys = Object.keys(copy) as Array<keyof T>;
keys.forEach((key) => {
if (copy[key] === undefined || copy[key] === null) {
delete copy[key];
}
});
return copy as Pick<T, RemoveUndefined<T>>;
};

0 comments on commit 4c67359

Please sign in to comment.