Skip to content

Commit

Permalink
fix selector
Browse files Browse the repository at this point in the history
  • Loading branch information
marcjas committed Apr 24, 2023
1 parent c6428c3 commit 2a4f56f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/mocks/data/oppfolging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,38 @@ const oppfolgingsperioder: Oppfolgingsperiode[] = [
aktorId: '1234567988888',
veileder: null,
startDato: '2018-01-31T10:46:10.971+01:00',
kvpPerioder: [
{
opprettetDato: '2017-01-30T10:46:10.971+01:00',
avsluttetDato: '2017-06-01T10:46:10.971+01:00',
},
{
opprettetDato: '2017-06-30T10:46:10.971+01:00',
avsluttetDato: '2017-12-01T10:46:10.971+01:00',
},
],
sluttDato: null,
begrunnelse: null,
},
];

// const oppfolgingsperioder: Oppfolgingsperiode[] = [
// {
// uuid: 'e093a5c9-1d56-4d64-97a8-26d947e1541d',
// aktorId: '2683577964741',
// veileder: null,
// startDato: '2023-04-24T15:52:07.531679+02:00',
// sluttDato: null,
// begrunnelse: null,
// kvpPerioder: [
// {
// opprettetDato: '2023-04-24T15:53:02.432314+02:00',
// avsluttetDato: '2023-04-24T15:53:20.697187+02:00',
// },
// ],
// },
// ];

const oppfolging = {
fnr: null,
aktorId: '1234567988888',
Expand Down
13 changes: 12 additions & 1 deletion src/moduler/oppfolging-status/oppfolging-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createSelector } from 'reselect';

import { HistoriskOppfolgingsperiode, Oppfolgingsperiode } from '../../datatypes/oppfolgingTypes';
import { RootState } from '../../store';
import { selectHistoriskPeriode } from '../filtrering/filter/filter-selector';

export function selectOppfolgingSlice(state: RootState) {
return state.data.oppfolging;
Expand All @@ -25,6 +26,10 @@ export function selectOppfolgingsPerioder(state: RootState): Oppfolgingsperiode[
return selectOppfolgingData(state)?.oppfolgingsPerioder || [];
}

export function selectNyesteOppfolgingsperiode(state: RootState) {
return selectOppfolgingsPerioder(state).find((oppfolgingsperiode) => !oppfolgingsperiode.sluttDato);
}

export type VistOppfolgingsPeriode = HistoriskOppfolgingsperiode & { fra: string; til: string };
export function selectSorterteHistoriskeOppfolgingsPerioder(state: RootState): VistOppfolgingsPeriode[] {
let nesteFra = new Date().toISOString();
Expand All @@ -43,8 +48,14 @@ export function selectSorterteHistoriskeOppfolgingsPerioder(state: RootState): V
.reverse();
}

// TODO refaktorer, må fikse typer oppfolgingsperioder-typene i hele appen
export function selectKvpPeriodeForValgteOppfolging(state: RootState) {
const valgtOppfolging: HistoriskOppfolgingsperiode | null = state.data.filter.historiskPeriode;
let valgtOppfolging: any = selectHistoriskPeriode(state);
if (!valgtOppfolging) {
// valgtOppfolging er null når man ikke har brukt periodefilteret, eller når man ikke har noen historiske oppfolgingsperioder
valgtOppfolging =
selectNyesteOppfolgingsperiode(state) ?? selectSorterteHistoriskeOppfolgingsPerioder(state)[0];
}
const valgtOppfolgingId = valgtOppfolging && valgtOppfolging.uuid;
const oppfolging = selectOppfolgingsPerioder(state).find((p) => p.uuid === valgtOppfolgingId);
return oppfolging && oppfolging.kvpPerioder;
Expand Down

0 comments on commit 2a4f56f

Please sign in to comment.