Skip to content

Commit

Permalink
endrer litt på hast og paginering
Browse files Browse the repository at this point in the history
skjuler kolonnen hast hvis ikke pilot
  • Loading branch information
di0nys1us committed Jun 3, 2024
1 parent 08c9800 commit ca9a9dc
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 49 deletions.
1 change: 1 addition & 0 deletions client/src/felleskomponenter/table/Tabellkolonne.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface Tabellkolonne<T> {
name?: string
width?: number
sortable?: boolean
hide?: boolean

header?(): ReactNode
render(verdi: T): ReactNode
Expand Down
7 changes: 3 additions & 4 deletions client/src/mocks/handlers/oppgaver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,10 @@ export const oppgaveHandlers: StoreHandlersFactory = ({

const response: OppgavelisteResponse = {
oppgaver: !filterApplied ? oppgaver.slice(startIndex, endIndex) : filtrerteOppgaver.slice(startIndex, endIndex),
pageNumber,
pageSize,
totalPages: 1,
totalElements: !filterApplied ? oppgaver.length : filtrerteOppgaver.length,
pageRequest: {
pageNumber,
pageSize,
},
antallHaster: !filterApplied ? oppgaver.filter(haster).length : filtrerteOppgaver.filter(haster).length,
}

Expand Down
18 changes: 10 additions & 8 deletions client/src/oppgavebenk/useOppgavelisteV2.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import useSwr from 'swr'

import { httpGet } from '../io/http'

import { OppgaveV2 } from '../types/types.internal'
import { PAGE_SIZE } from '../oppgaveliste/paging/Paging'
import { OppgaveV2 } from '../types/types.internal'

interface DataResponse {
oppgaver: OppgaveV2[]
totalCount: number
currentPage: number
pageNumber: number
pageSize: number
totalPages: number
totalElements: number
isLoading: boolean
error: unknown
mutate: (...args: any[]) => any
Expand All @@ -35,9 +35,10 @@ interface Filters {

interface OppgavelisteResponse {
oppgaver: OppgaveV2[]
totalCount: number
pageNumber: number
pageSize: number
currentPage: number
totalPages: number
totalElements: number
}

/*
Expand Down Expand Up @@ -94,9 +95,10 @@ export function useOppgavelisteV2(currentPage: number /*, sort: SortState, filte

return {
oppgaver: data?.data.oppgaver || [],
totalCount: data?.data.totalCount || 0,
pageNumber: data?.data.pageNumber || currentPage,
pageSize: data?.data.pageSize || PAGE_SIZE,
currentPage: data?.data.currentPage || currentPage,
totalPages: data?.data.totalPages || 0,
totalElements: data?.data.totalElements || 0,
isLoading: !error && !data,
error,
mutate,
Expand Down
13 changes: 10 additions & 3 deletions client/src/oppgaveliste/Oppgaveliste.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import styled from 'styled-components'

import { DataCell, KolonneHeader } from '../felleskomponenter/table/KolonneHeader'
import { LinkRow } from '../felleskomponenter/table/LinkRow'
import { useSaksbehandlerTilhørerEnhet } from '../state/authentication.ts'
import { formaterFødselsnummer, formaterNavn, storForbokstavIAlleOrd } from '../utils/formater'
import { isError } from '../utils/type'

Expand Down Expand Up @@ -48,6 +49,9 @@ export function Oppgaveliste() {
områdeFilter,
})

// NAV IT, Vestland-Bergen, Trøndelag
const pilotHast = useSaksbehandlerTilhørerEnhet('2970', '4712', '4716')

const handleFilter = (handler: (...args: any[]) => any, value: SakerFilter | OppgaveStatusType | OmrådeFilter) => {
handler(value)
setCurrentPage(1)
Expand Down Expand Up @@ -102,6 +106,7 @@ export function Oppgaveliste() {
{
key: 'HAST',
width: 105,
hide: !pilotHast,
header() {
return (
<>
Expand Down Expand Up @@ -209,6 +214,8 @@ export function Oppgaveliste() {

const hasData = oppgaver && oppgaver.length > 0

const filterHide = ({ hide }: Tabellkolonne<Oppgave>): boolean => hide !== true

return (
<>
<Skjermlesertittel>Oppgaveliste</Skjermlesertittel>
Expand Down Expand Up @@ -272,7 +279,7 @@ export function Oppgaveliste() {
<caption className="sr-only">Oppgaveliste</caption>
<Table.Header>
<Table.Row>
{kolonner.map(({ key, name, width, sortable = true, header }) => (
{kolonner.filter(filterHide).map(({ key, name, width, sortable = true, header }) => (
<KolonneHeader key={key} sortable={sortable} sortKey={key} width={width}>
{header ? header() : name}
</KolonneHeader>
Expand All @@ -289,7 +296,7 @@ export function Oppgaveliste() {
: `/sak/${oppgave.sakId}`
}
>
{kolonner.map(({ key, width, render }) => (
{kolonner.filter(filterHide).map(({ key, width, render }) => (
<DataCell
key={key}
width={width}
Expand All @@ -305,7 +312,7 @@ export function Oppgaveliste() {
</Table.Body>
</Table>
<Paging
totalCount={totalElements}
totalElements={totalElements}
currentPage={currentPage}
onPageChange={(page: number) => setCurrentPage(page)}
/>
Expand Down
8 changes: 4 additions & 4 deletions client/src/oppgaveliste/paging/PageCounter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import styled from 'styled-components'
import { Tekst } from '../../felleskomponenter/typografi'

interface PageCounterProps {
totalCount: number
totalElements: number
pageSize: number
currentPage: number
}

export function PageCounter({ pageSize, totalCount, currentPage }: PageCounterProps) {
export function PageCounter({ pageSize, totalElements, currentPage }: PageCounterProps) {
const førsteSynligeOppgave = pageSize * (currentPage - 1) + 1
const sisteOppgave = førsteSynligeOppgave + pageSize - 1

Expand All @@ -17,8 +17,8 @@ export function PageCounter({ pageSize, totalCount, currentPage }: PageCounterPr
<Container>
<Tekst>
{`Viser ${førsteSynligeOppgave} - ${
sisteOppgave > totalCount ? totalCount : sisteOppgave
} av ${totalCount} saker`}
sisteOppgave > totalElements ? totalElements : sisteOppgave
} av ${totalElements} saker`}
</Tekst>
</Container>
</>
Expand Down
10 changes: 5 additions & 5 deletions client/src/oppgaveliste/paging/Paging.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ const Container = styled.div`
export const PAGE_SIZE = 25

interface PagingProps {
totalCount: number
totalElements: number
currentPage: number
onPageChange: (...args: any[]) => any
onPageChange(...args: any[]): any
}

export function Paging({ totalCount, currentPage, onPageChange }: PagingProps) {
const totalNumberOfPages = Math.ceil(totalCount / PAGE_SIZE)
export function Paging({ totalElements, currentPage, onPageChange }: PagingProps) {
const totalNumberOfPages = Math.ceil(totalElements / PAGE_SIZE)
const hasMultiplePages = totalNumberOfPages > 1

return (
Expand All @@ -35,7 +35,7 @@ export function Paging({ totalCount, currentPage, onPageChange }: PagingProps) {
/>
)}
</Container>
<PageCounter pageSize={PAGE_SIZE} currentPage={currentPage} totalCount={totalCount} />
<PageCounter pageSize={PAGE_SIZE} currentPage={currentPage} totalElements={totalElements} />
</>
)
}
23 changes: 11 additions & 12 deletions client/src/oppgaveliste/useOppgaveliste.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { SortState } from '@navikt/ds-react'
import { useEffect } from 'react'
import useSwr from 'swr'

import { SortState } from '@navikt/ds-react'

import { httpGet } from '../io/http'
import { amplitude_taxonomy, logAmplitudeEvent } from '../utils/amplitude'

import { OmrådeFilter, Oppgave, OppgaveStatusType, SakerFilter, SakstypeFilter } from '../types/types.internal'
import { amplitude_taxonomy, logAmplitudeEvent } from '../utils/amplitude'
import { PAGE_SIZE } from './paging/Paging'

interface DataResponse {
oppgaver: Oppgave[]
totalElements: number
currentPage: number
pageNumber: number
pageSize: number
totalPages: number
totalElements: number
antallHaster: number
isLoading: boolean
error: unknown
Expand All @@ -36,11 +35,10 @@ interface OppgavelisteFilters {

export interface OppgavelisteResponse {
oppgaver: Oppgave[]
pageNumber: number
pageSize: number
totalPages: number
totalElements: number
pageRequest: {
pageNumber: number
pageSize: number
}
antallHaster: number
}

Expand Down Expand Up @@ -92,9 +90,10 @@ export function useOppgaveliste(currentPage: number, sort: SortState, filters: O

return {
oppgaver: data?.data.oppgaver || [],
pageNumber: data?.data.pageNumber || currentPage,
pageSize: data?.data.pageSize || PAGE_SIZE,
totalPages: data?.data.totalPages || 0,
totalElements: data?.data.totalElements || 0,
currentPage: data?.data.pageRequest.pageNumber || currentPage,
pageSize: data?.data.pageRequest.pageSize || PAGE_SIZE,
antallHaster: data?.data.antallHaster || 0,
isLoading: !error && !data,
error,
Expand Down
26 changes: 13 additions & 13 deletions client/src/saksbilde/hjelpemidler/Hastesak.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Hast, Hasteårsak } from '../../types/types.internal.ts'
import { Alert, Box, List } from '@navikt/ds-react'
import { Etikett } from '../../felleskomponenter/typografi.tsx'
import { Hast, Hasteårsak } from '../../types/types.internal.ts'
import { Fremhev, HjelpemiddelGrid } from './HjelpemiddelGrid.tsx'

export function Hastesak(props: { hast?: Hast }) {
Expand All @@ -14,18 +15,17 @@ export function Hastesak(props: { hast?: Hast }) {
<Box paddingBlock="3">
<HjelpemiddelGrid>
<Fremhev />
<List title="Årsak til at det haster" size="small" headingTag="h2">
{årsaker
.map((årsak) => {
const tekst = tekstByHasteårsak[årsak]
return årsak === Hasteårsak.ANNET && begrunnelse
? `${tekst} Formidlers begrunnelse: ${begrunnelse}`
: tekst
})
.map((tekst) => (
<List.Item key={tekst}>{tekst}</List.Item>
))}
</List>
<div>
<Etikett>Årsak til at det haster:</Etikett>
<List size="small" headingTag="h2">
{årsaker
.map((årsak) => tekstByHasteårsak[årsak])
.map((tekst) => (
<List.Item key={tekst}>{tekst}</List.Item>
))}
{begrunnelse && <List.Item>{begrunnelse}</List.Item>}
</List>
</div>
</HjelpemiddelGrid>
</Box>
</>
Expand Down
5 changes: 5 additions & 0 deletions client/src/state/authentication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ export function useInnloggetSaksbehandler(): InnloggetSaksbehandler {
return useRecoilValue<InnloggetSaksbehandler>(innloggetSaksbehandlerState)
}

export function useSaksbehandlerTilhørerEnhet(...enhet: string[]): boolean {
const { enhetsnumre } = useInnloggetSaksbehandler()
return enhet.some((it) => enhetsnumre.includes(it))
}

export function useVisOppgavelisteTabs() {
return useRecoilValue<boolean>(visOppgavelisteTabsState)
}
Expand Down

0 comments on commit ca9a9dc

Please sign in to comment.