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

IS-2734: Corrects behaviour of hendelse filter #563

Merged
merged 1 commit into from
Jan 3, 2025
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
7 changes: 3 additions & 4 deletions src/sider/oversikt/filter/HendelseFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { PersonregisterState } from '@/api/types/personregisterTypes';
import { filterOnPersonregister } from '@/utils/hendelseFilteringUtils';
import { filterHendelser } from '@/utils/hendelseFilteringUtils';
import { useFilters } from '@/context/filters/FilterContext';
import { ActionType } from '@/context/filters/filterContextActions';
import {
Expand Down Expand Up @@ -157,9 +157,8 @@ function hendelseCheckboxes(
): CheckboxElement[] {
return Object.entries(HendelseTekster).map(([hendelse, tekst]) => {
const filter = initFilter(hendelse as Hendelse);
const antall = Object.keys(
filterOnPersonregister(personRegister || {}, filter)
).length;
const antall = Object.keys(filterHendelser(personRegister || {}, filter))
.length;
const checked = isChecked(
filterState.selectedHendelseType,
hendelse as Hendelse
Expand Down
6 changes: 2 additions & 4 deletions src/sider/oversikt/sokeresultat/Sokeresultat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { useTildelVeileder } from '@/data/veiledereQueryHooks';
import { PersonregisterState } from '@/api/types/personregisterTypes';
import {
Filterable,
filterHendelser,
filterOnAge,
filterOnBirthDates,
filterOnCompany,
filterOnFodselsnummerOrName,
filterOnFrist,
filterOnPersonregister,
} from '@/utils/hendelseFilteringUtils';
import { useFilters } from '@/context/filters/FilterContext';
import { OversiktTableContainer } from '@/sider/oversikt/sokeresultat/oversikttable/OversiktTableContainer';
Expand Down Expand Up @@ -49,9 +49,7 @@ export default function Sokeresultat({ allEvents }: Props) {
.applyFilter((v) => filterOnBirthDates(v, filterState.selectedBirthDates))
.applyFilter((v) => filterOnFrist(v, filterState.selectedFristFilters))
.applyFilter((v) => filterOnAge(v, filterState.selectedAgeFilters))
.applyFilter((v) =>
filterOnPersonregister(v, filterState.selectedHendelseType)
)
.applyFilter((v) => filterHendelser(v, filterState.selectedHendelseType))
.applyFilter((v) =>
filterUfordelteBrukere(v, filterState.isUfordelteBrukereFilter)
)
Expand Down
79 changes: 33 additions & 46 deletions src/utils/hendelseFilteringUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,53 +183,42 @@ function isAgeInFilters(
});
}

type HendelseTypeFilterKey = keyof HendelseTypeFilter;

const matchesFilter = (
key: HendelseTypeFilterKey,
function isPersonVisible(
filters: HendelseTypeFilter,
personData: PersonData
): boolean => {
switch (key) {
case 'onskerMote':
return !filters[key] || personData.harMotebehovUbehandlet;
case 'arbeidsgiverOnskerMote':
return !filters[key] || personData.harOppfolgingsplanLPSBistandUbehandlet;
case 'dialogmotekandidat':
return !filters[key] || personData.dialogmotekandidat === true;
case 'dialogmotesvar':
return !filters[key] || personData.harDialogmotesvar;
case 'behandlerdialog':
return !filters[key] || personData.harBehandlerdialogUbehandlet;
case 'oppfolgingsoppgave':
return !filters[key] || personData.oppfolgingsoppgave !== null;
case 'behandlerBerOmBistand':
return !filters[key] || personData.behandlerBerOmBistandUbehandlet;
case 'isAktivArbeidsuforhetvurdering':
return !filters[key] || !!personData.arbeidsuforhetvurdering;
case 'harFriskmeldingTilArbeidsformidling':
return !filters[key] || !!personData.friskmeldingTilArbeidsformidlingFom;
case 'isSenOppfolgingChecked':
return !filters[key] || !!personData.senOppfolgingKandidat;
case 'isManglendeMedvirkningChecked':
return !filters[key] || !!personData.manglendeMedvirkning;
case 'isAktivitetskravChecked':
return !filters[key] || personData.aktivitetskravvurdering !== null;
case 'isAktivitetskravVurderStansChecked':
const isExpiredVarsel =
!!personData?.aktivitetskravvurdering?.vurderinger[0]?.varsel
?.svarfrist &&
isPast(
personData?.aktivitetskravvurdering.vurderinger[0]?.varsel?.svarfrist
);
return !filters[key] || isExpiredVarsel;
}
};
): boolean {
const isExpiredVarsel =
!!personData?.aktivitetskravvurdering?.vurderinger[0]?.varsel?.svarfrist &&
isPast(
personData?.aktivitetskravvurdering.vurderinger[0]?.varsel?.svarfrist
);
return (
(filters.onskerMote && personData.harDialogmotesvar) ||
(filters.arbeidsgiverOnskerMote &&
personData.harOppfolgingsplanLPSBistandUbehandlet) ||
(filters.dialogmotekandidat && personData.dialogmotekandidat === true) ||
(filters.dialogmotesvar && personData.harDialogmotesvar) ||
(filters.behandlerdialog && personData.harBehandlerdialogUbehandlet) ||
(filters.oppfolgingsoppgave && personData.oppfolgingsoppgave !== null) ||
(filters.behandlerBerOmBistand &&
personData.behandlerBerOmBistandUbehandlet) ||
(filters.isAktivArbeidsuforhetvurdering &&
!!personData.arbeidsuforhetvurdering) ||
(filters.harFriskmeldingTilArbeidsformidling &&
!!personData.friskmeldingTilArbeidsformidlingFom) ||
(filters.isSenOppfolgingChecked && !!personData.senOppfolgingKandidat) ||
(filters.isManglendeMedvirkningChecked &&
!!personData.manglendeMedvirkning) ||
(filters.isAktivitetskravChecked &&
personData.aktivitetskravvurdering !== null) ||
(filters.isAktivitetskravVurderStansChecked && isExpiredVarsel)
);
}

export const filterOnPersonregister = (
export function filterHendelser(
personregister: PersonregisterState,
filter?: HendelseTypeFilter
): PersonregisterState => {
): PersonregisterState {
if (!filter) return personregister;

const erTomtFilter = Object.entries(filter).every(
Expand All @@ -241,13 +230,11 @@ export const filterOnPersonregister = (
}

const filtered = Object.entries(personregister).filter(([, personData]) => {
return Object.keys(filter).every((key) =>
matchesFilter(key as HendelseTypeFilterKey, filter, personData)
);
return isPersonVisible(filter, personData);
});

return Object.fromEntries(filtered);
};
}

export const filterEventsOnVeileder = (
personregister: PersonregisterState,
Expand Down
13 changes: 6 additions & 7 deletions test/utils/hendelseFilteringUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest';
import {
filterHendelser,
filterOnFrist,
filterOnPersonregister,
FristFilterOption,
getSortedEventsFromSortingType,
} from '@/utils/hendelseFilteringUtils';
Expand Down Expand Up @@ -610,7 +610,7 @@ describe('hendelseFilteringUtils', () => {
const personregister: PersonregisterState = {
'16614407794': createPersonDataWithName('Bjarne Bjarne'),
};
const filteredPersonregister = filterOnPersonregister(
const filteredPersonregister = filterHendelser(
personregister,
defaulthendelseFilter
);
Expand All @@ -635,15 +635,15 @@ describe('hendelseFilteringUtils', () => {
dialogmotesvar: true,
};

const filteredPersonregister = filterOnPersonregister(
const filteredPersonregister = filterHendelser(
personregister,
filterWithDialogmotesvar
);

expect(Object.keys(filteredPersonregister).length).to.equal(0);
});

it('Return only elements matching all active filters', () => {
it('Return elements matching active filters', () => {
const personDataWithAktivitetskrav: PersonData = {
...createPersonDataWithName('Fox Mulder'),
aktivitetskravvurdering: {
Expand All @@ -669,13 +669,12 @@ describe('hendelseFilteringUtils', () => {
isAktivitetskravChecked: true,
};

const filteredPersonregister = filterOnPersonregister(
const filteredPersonregister = filterHendelser(
personregister,
filterWithMotebehovAndAktivitetskrav
);

expect(Object.keys(filteredPersonregister).length).to.equal(1);
expect(Object.keys(filteredPersonregister)[0]).to.equal('09128034883');
expect(Object.keys(filteredPersonregister).length).to.equal(2);
});

describe('Frist filter', () => {
Expand Down
Loading