Skip to content

Commit

Permalink
Merge pull request #6202 from espoon-voltti/varda-errors-ma003
Browse files Browse the repository at this point in the history
Lisätään MA003-suodatin Varda-lapsivirheet -raportille
  • Loading branch information
akheron authored Jan 2, 2025
2 parents 707f4cb + ce0bc6d commit c099f8b
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 99 deletions.
36 changes: 1 addition & 35 deletions frontend/src/e2e-test/pages/employee/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ApplicationStatus } from 'lib-common/generated/api-types/application'
import LocalDate from 'lib-common/local-date'

import { captureTextualDownload } from '../../browser'
import { waitUntilEqual, waitUntilTrue } from '../../utils'
import { waitUntilEqual } from '../../utils'
import {
Checkbox,
Combobox,
Expand Down Expand Up @@ -76,11 +76,6 @@ export default class ReportsPage {
return new HolidayPeriodAttendanceReport(this.page)
}

async openVardaErrorsReport() {
await this.page.findByDataQa('report-varda-child-errors').click()
return new VardaErrorsReport(this.page)
}

async openStartingPlacementsReport() {
await this.page.findByDataQa('report-starting-placements').click()
return new StartingPlacementsReport(this.page)
Expand Down Expand Up @@ -418,35 +413,6 @@ export class ManualDuplicationReport {
}
}

export class VardaErrorsReport {
#errorsTable: Element
#errorRows: ElementCollection

constructor(private page: Page) {
this.#errorsTable = page.findByDataQa('varda-errors-table')
this.#errorRows = page.findAll('[data-qa="varda-error-row"]')
}

#errors = (childId: string) => this.page.findByDataQa(`errors-${childId}`)
#resetChild = (childId: string) =>
this.page.findByDataQa(`reset-button-${childId}`)

async assertErrorsContains(childId: string, expected: string) {
await waitUntilTrue(async () =>
((await this.#errors(childId).text) || '').includes(expected)
)
}

async resetChild(childId: string) {
await this.#resetChild(childId).click()
}

async assertErrorRowCount(expected: number) {
await waitUntilTrue(() => this.#errorsTable.visible)
await waitUntilEqual(() => this.#errorRows.count(), expected)
}
}

export class AssistanceNeedDecisionsReport {
rows: ElementCollection

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import React from 'react'
import React, { useMemo, useState } from 'react'
import { Link } from 'react-router'
import styled from 'styled-components'

Expand All @@ -13,26 +13,33 @@ import { useQueryResult } from 'lib-common/query'
import Title from 'lib-components/atoms/Title'
import { MutateButton } from 'lib-components/atoms/buttons/MutateButton'
import ReturnButton from 'lib-components/atoms/buttons/ReturnButton'
import Select from 'lib-components/atoms/dropdowns/Select'
import { Container, ContentArea } from 'lib-components/layout/Container'
import { Tbody, Td, Th, Thead, Tr } from 'lib-components/layout/Table'
import { Table, Tbody, Td, Th, Thead, Tr } from 'lib-components/layout/Table'
import { Gap } from 'lib-components/white-space'

import { useTranslation } from '../../state/i18n'
import { renderResult } from '../async-rendering'

import { TableScrollable } from './common'
import { resetVardaChildMutation, vardaChildErrorsQuery } from './queries'

const FlatList = styled.ul`
list-style: none;
padding-left: 0;
margin-top: 0;
`

export default React.memo(function VardaChildErrors() {
const { i18n } = useTranslation()
const [ma003, setMa003] = useState<'exclude' | 'include' | 'only'>('exclude')
const vardaErrorsResult = useQueryResult(vardaChildErrorsQuery())

const filteredRows = useMemo(
() =>
ma003 === 'include'
? vardaErrorsResult
: vardaErrorsResult.map((rows) =>
rows.filter(
(row) => row.error.includes('"MA003"') === (ma003 === 'only')
)
),
[vardaErrorsResult, ma003]
)

const ageInDays = (timestamp: HelsinkiDateTime): number =>
LocalDate.todayInHelsinkiTz().differenceInDays(timestamp.toLocalDate())

Expand All @@ -42,22 +49,30 @@ export default React.memo(function VardaChildErrors() {
<ContentArea opaque>
<Title size={1}>{i18n.reports.vardaChildErrors.title}</Title>
<Gap size="xxs" />
{renderResult(vardaErrorsResult, (rows) => (
<Select
items={['exclude', 'include', 'only'] as const}
getItemLabel={(item) => i18n.reports.vardaChildErrors.ma003[item]}
selectedItem={ma003}
onChange={(value) => {
if (value !== null) setMa003(value)
}}
/>
<Gap size="s" />
{renderResult(filteredRows, (rows) => (
<>
<TableScrollable data-qa="varda-errors-table">
<Table data-qa="varda-errors-table">
<Thead>
<Tr>
<Th>{i18n.reports.vardaChildErrors.age}</Th>
<Th>{i18n.reports.vardaChildErrors.child}</Th>
<Th>{i18n.reports.vardaChildErrors.error}</Th>
<Th>{i18n.reports.vardaChildErrors.serviceNeed}</Th>
<Th>{i18n.reports.vardaChildErrors.updated}</Th>
<Th>{i18n.reports.vardaChildErrors.childLastReset}</Th>
<Th />
</Tr>
</Thead>
<Tbody>
{rows.map((row: VardaChildErrorReportRow) => (
<Tr data-qa="varda-error-row" key={row.serviceNeedId}>
<Tr data-qa="varda-error-row" key={row.childId}>
<Td data-qa={`age-${row.childId}`}>
{ageInDays(row.created)}
</Td>
Expand All @@ -68,38 +83,24 @@ export default React.memo(function VardaChildErrors() {
</Td>

<Td data-qa={`errors-${row.childId}`}>
<BreakAll>{row.errors.join('\n')}</BreakAll>
</Td>
<Td>
<FlatList>
<li>{row.serviceNeedOptionName}</li>
<li>{row.serviceNeedValidity?.format()}</li>
<li>{row.serviceNeedId}</li>
</FlatList>
<BreakAll>{row.error}</BreakAll>
</Td>
<Td data-qa={`updated-${row.childId}`}>
{row.updated.format()}
</Td>
<Td data-qa={`last-reset-${row.childId}`}>
<>
<span>
{row.resetTimeStamp
? row.resetTimeStamp.format()
: ''}
</span>
<MutateButton
primary
text={i18n.reports.vardaChildErrors.resetChild}
mutation={resetVardaChildMutation}
onClick={() => ({ childId: row.childId })}
data-qa={`reset-button-${row.childId}`}
/>
</>
<MutateButton
primary
text={i18n.reports.vardaChildErrors.updateChild}
mutation={resetVardaChildMutation}
onClick={() => ({ childId: row.childId })}
data-qa={`reset-button-${row.childId}`}
/>
</Td>
</Tr>
))}
</Tbody>
</TableScrollable>
</Table>
</>
))}
</ContentArea>
Expand Down
9 changes: 1 addition & 8 deletions frontend/src/lib-common/generated/api-types/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { PlacementId } from './shared'
import { PlacementType } from './placement'
import { PreschoolAssistanceLevel } from './assistance'
import { ProviderType } from './daycare'
import { ServiceNeedId } from './shared'
import { ServiceNeedOption } from './application'
import { TitaniaErrorsId } from './shared'
import { UUID } from '../../types'
Expand Down Expand Up @@ -1042,11 +1041,7 @@ export interface UnitsReportRow {
export interface VardaChildErrorReportRow {
childId: PersonId
created: HelsinkiDateTime
errors: string[]
resetTimeStamp: HelsinkiDateTime | null
serviceNeedId: ServiceNeedId | null
serviceNeedOptionName: string | null
serviceNeedValidity: FiniteDateRange | null
error: string
updated: HelsinkiDateTime
}

Expand Down Expand Up @@ -1322,8 +1317,6 @@ export function deserializeJsonVardaChildErrorReportRow(json: JsonOf<VardaChildE
return {
...json,
created: HelsinkiDateTime.parseIso(json.created),
resetTimeStamp: (json.resetTimeStamp != null) ? HelsinkiDateTime.parseIso(json.resetTimeStamp) : null,
serviceNeedValidity: (json.serviceNeedValidity != null) ? FiniteDateRange.parseJson(json.serviceNeedValidity) : null,
updated: HelsinkiDateTime.parseIso(json.updated)
}
}
Expand Down
13 changes: 6 additions & 7 deletions frontend/src/lib-customizations/defaults/employee/i18n/fi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4120,18 +4120,17 @@ export const fi = {
},
vardaChildErrors: {
title: 'Varda-lapsivirheet',
vardaUpdateButton: 'Aloita päivitys',
vardaResetButton: 'Aloita uudelleenvienti',
ma003: {
include: 'Sisällytä MA003-virheet',
exclude: 'Piilota MA003-virheet',
only: 'Näytä vain MA003-virheet'
},
description: 'Varda-lasten päivityksissä tapahtuneet virheet',
updated: 'Päivitetty viimeksi',
age: 'Ikä (päivää)',
child: 'Lapsi',
serviceNeed: 'Palveluntarve',
error: 'Virhe',
childLastReset: 'Uudelleenviety viimeksi',
childMarkedForRest: 'Lapsen tiedot nollataan seuraavalla ajolla',
resetChild: 'Uudelleenvie',
updating: 'Päivittää'
updateChild: 'Uudelleenvie'
},
vardaUnitErrors: {
title: 'Varda-yksikkövirheet',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ package fi.espoo.evaka.reports
import fi.espoo.evaka.Audit
import fi.espoo.evaka.shared.ChildId
import fi.espoo.evaka.shared.DaycareId
import fi.espoo.evaka.shared.ServiceNeedId
import fi.espoo.evaka.shared.auth.AuthenticatedUser
import fi.espoo.evaka.shared.db.Database
import fi.espoo.evaka.shared.domain.EvakaClock
import fi.espoo.evaka.shared.domain.FiniteDateRange
import fi.espoo.evaka.shared.domain.HelsinkiDateTime
import fi.espoo.evaka.shared.security.AccessControl
import fi.espoo.evaka.shared.security.Action
Expand Down Expand Up @@ -68,14 +66,10 @@ private fun Database.Read.getVardaChildErrors(): List<VardaChildErrorReportRow>
sql(
"""
SELECT
NULL AS service_need_id,
NULL AS service_need_validity,
NULL AS service_need_option_name,
child_id,
errored_at AS updated,
coalesce(last_success_at, created_at) AS created,
ARRAY[error] AS errors,
NULL AS reset_timestamp
error
FROM varda_state
WHERE errored_at IS NOT NULL
ORDER BY updated DESC
Expand All @@ -85,14 +79,10 @@ ORDER BY updated DESC
.toList<VardaChildErrorReportRow>()

data class VardaChildErrorReportRow(
val serviceNeedId: ServiceNeedId?,
val serviceNeedValidity: FiniteDateRange?,
val serviceNeedOptionName: String?,
val childId: ChildId,
val updated: HelsinkiDateTime,
val created: HelsinkiDateTime,
val errors: List<String>,
val resetTimeStamp: HelsinkiDateTime?,
val error: String,
)

private fun Database.Read.getVardaUnitErrors(): List<VardaUnitErrorReportRow> =
Expand Down

0 comments on commit c099f8b

Please sign in to comment.