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

Lisätään esiopetushakemuksien raportti #5830

Merged
merged 1 commit into from
Oct 21, 2024
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
19 changes: 19 additions & 0 deletions frontend/src/e2e-test/pages/employee/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export default class ReportsPage {
return new PreschoolAbsenceReport(this.page)
}

async openPreschoolApplicationReport() {
await this.page.findByDataQa('report-preschool-application').click()
return new PreschoolApplicationReport(this.page)
}

async openHolidayPeriodAttendanceReport() {
await this.page.findByDataQa('report-holiday-period-attendance').click()
return new HolidayPeriodAttendanceReport(this.page)
Expand Down Expand Up @@ -594,6 +599,20 @@ export class PreschoolAbsenceReport {
}
}

export class PreschoolApplicationReport {
constructor(private page: Page) {}

async assertNoResults() {
const noResults = this.page.findByDataQa('no-results')
await noResults.waitUntilVisible()
}

async assertRows(expected: string[]) {
const rows = this.page.findAllByDataQa('row')
await rows.assertTextsEqual(expected)
}
}

export class HolidayPeriodAttendanceReport {
constructor(private page: Page) {}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// SPDX-FileCopyrightText: 2017-2024 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import LocalDate from 'lib-common/local-date'
import LocalTime from 'lib-common/local-time'

import config from '../../config'
import { applicationFixture, Fixture, uuidv4 } from '../../dev-api/fixtures'
import {
createApplications,
resetServiceState
} from '../../generated/api-clients'
import { DevEmployee } from '../../generated/api-types'
import EmployeeNav from '../../pages/employee/employee-nav'
import ReportsPage from '../../pages/employee/reports'
import { Page } from '../../utils/page'
import { employeeLogin } from '../../utils/user'

const mockedToday = LocalDate.of(2024, 10, 16)

beforeEach(resetServiceState)

xdescribe('Preschool application report', () => {
test('no results is shown', async () => {
const admin = await Fixture.employee().admin().save()
const page = await Page.open({
mockedTime: mockedToday.toHelsinkiDateTime(LocalTime.of(8, 0))
})
const report = await navigateToReport(page, admin)
await report.assertNoResults()
})

test('rows are shown', async () => {
const area = await Fixture.careArea().save()
const unit1 = await Fixture.daycare({
areaId: area.id,
name: 'Koulu A'
}).save()
const unit2 = await Fixture.daycare({
areaId: area.id,
name: 'Koulu B'
}).save()

const guardian = await Fixture.person({
lastName: 'Testiläinen',
firstName: 'Matti',
dateOfBirth: LocalDate.of(2000, 1, 1),
ssn: null
}).saveAdult()

const child1 = await Fixture.person({
lastName: 'Testiläinen',
firstName: 'Teppo',
dateOfBirth: LocalDate.of(2019, 1, 1),
ssn: null
}).saveChild()
await Fixture.guardian(child1, guardian).save()
const application1 = {
...applicationFixture(
child1,
guardian,
undefined,
'PRESCHOOL',
null,
[unit1.id],
false,
'WAITING_UNIT_CONFIRMATION'
),
id: uuidv4()
}

const child2 = await Fixture.person({
lastName: 'Testiläinen',
firstName: 'Seppo',
dateOfBirth: LocalDate.of(2019, 1, 2),
ssn: null
}).saveChild()
await Fixture.guardian(child2, guardian).save()
const application2 = {
...applicationFixture(
child2,
guardian,
undefined,
'PRESCHOOL',
null,
[unit2.id],
false,
'WAITING_UNIT_CONFIRMATION'
),
id: uuidv4()
}

await createApplications({ body: [application1, application2] })

const admin = await Fixture.employee().admin().save()
const page = await Page.open({
mockedTime: mockedToday.toHelsinkiDateTime(LocalTime.of(8, 0))
})
const report = await navigateToReport(page, admin)
await report.assertRows([
`${unit1.name}\t${child1.lastName}\t${child1.firstName}\t01.01.2019\t${child1.streetAddress}\t${child1.postalCode}\t\tEi`,
`${unit2.name}\t${child2.lastName}\t${child2.firstName}\t02.01.2019\t${child2.streetAddress}\t${child2.postalCode}\t\tEi`
])
})
})

const navigateToReport = async (page: Page, user: DevEmployee) => {
await employeeLogin(page, user)
await page.goto(config.employeeUrl)
await new EmployeeNav(page).openTab('reports')
return await new ReportsPage(page).openPreschoolApplicationReport()
}
9 changes: 9 additions & 0 deletions frontend/src/employee-frontend/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import PlacementCount from './components/reports/PlacementCount'
import PlacementGuarantee from './components/reports/PlacementGuarantee'
import PlacementSketching from './components/reports/PlacementSketching'
import PreschoolAbsenceReport from './components/reports/PreschoolAbsenceReport'
import PreschoolApplicationReport from './components/reports/PreschoolApplicationReport'
import ReportPresences from './components/reports/PresenceReport'
import ReportRaw from './components/reports/Raw'
import ReportServiceNeeds from './components/reports/ServiceNeeds'
Expand Down Expand Up @@ -790,6 +791,14 @@ export default createBrowserRouter(
</EmployeeRoute>
)
},
{
path: '/reports/preschool-application',
element: (
<EmployeeRoute title="reports">
<PreschoolApplicationReport />
</EmployeeRoute>
)
},
{
path: '/reports/future-preschoolers',
element: (
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/employee-frontend/components/Reports.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,20 @@ export default React.memo(function Reports() {
)
}
: null,
reports.has('PRESCHOOL_APPLICATIONS')
? {
name: i18n.reports.preschoolApplications.title,
item: (
<Report
data-qa="report-preschool-application"
path="/reports/preschool-application"
color={colors.main.m2}
icon={faChild}
i18n={i18n.reports.preschoolApplications}
/>
)
}
: null,
reports.has('FAMILY_DAYCARE_MEAL_REPORT')
? {
name: i18n.reports.familyDaycareMealCount.title,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
// SPDX-FileCopyrightText: 2017-2024 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import orderBy from 'lodash/orderBy'
import React, { useCallback, useMemo, useState } from 'react'
import { Link } from 'react-router-dom'

import { PreschoolApplicationReportRow } from 'lib-common/generated/api-types/reports'
import { useQueryResult } from 'lib-common/query'
import Title from 'lib-components/atoms/Title'
import ReturnButton from 'lib-components/atoms/buttons/ReturnButton'
import Container, { ContentArea } from 'lib-components/layout/Container'
import {
SortableTh,
SortDirection,
Tbody,
Td,
Thead,
Tr
} from 'lib-components/layout/Table'

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

import { TableScrollable } from './common'
import { preschoolApplicationReportQuery } from './queries'

export default React.memo(function PreschoolApplicationReport() {
const { i18n } = useTranslation()
const result = useQueryResult(preschoolApplicationReportQuery())

return (
<Container>
<ReturnButton label={i18n.common.goBack} />
<ContentArea opaque>
<Title size={1}>{i18n.reports.preschoolApplications.title}</Title>
{renderResult(result, (rows) => (
<PreschoolApplicationReportTable rows={rows} />
))}
</ContentArea>
</Container>
)
})

type SortColumn = keyof PreschoolApplicationReportRow

const PreschoolApplicationReportTable = ({
rows
}: {
rows: PreschoolApplicationReportRow[]
}) => {
const { i18n } = useTranslation()
const [sort, setSort] = useState<{
column: SortColumn
direction: SortDirection
}>({ column: 'applicationUnitName', direction: 'ASC' })
const sortedRows = useMemo(
() =>
orderBy(
rows,
[sort.column, 'childLastName', 'childFirstName', 'childDateOfBirth'],
[sort.direction === 'ASC' ? 'asc' : 'desc']
),
[rows, sort.column, sort.direction]
)
const sortBy = useCallback(
(column: SortColumn) => () =>
setSort({
column,
direction:
sort.column === column && sort.direction === 'ASC' ? 'DESC' : 'ASC'
}),
[sort.column, sort.direction]
)
const sorted = useCallback(
(column: SortColumn) =>
sort.column === column ? sort.direction : undefined,
[sort.column, sort.direction]
)

return (
<TableScrollable>
<Thead>
<Tr>
<SortableTh
onClick={sortBy('applicationUnitName')}
sorted={sorted('applicationUnitName')}
>
{i18n.reports.preschoolApplications.columns.applicationUnitName}
</SortableTh>
<SortableTh
onClick={sortBy('childLastName')}
sorted={sorted('childLastName')}
>
{i18n.reports.preschoolApplications.columns.childLastName}
</SortableTh>
<SortableTh
onClick={sortBy('childFirstName')}
sorted={sorted('childFirstName')}
>
{i18n.reports.preschoolApplications.columns.childFirstName}
</SortableTh>
<SortableTh
onClick={sortBy('childDateOfBirth')}
sorted={sorted('childDateOfBirth')}
>
{i18n.reports.preschoolApplications.columns.childDateOfBirth}
</SortableTh>
<SortableTh
onClick={sortBy('childStreetAddress')}
sorted={sorted('childStreetAddress')}
>
{i18n.reports.preschoolApplications.columns.childStreetAddress}
</SortableTh>
<SortableTh
onClick={sortBy('childPostalCode')}
sorted={sorted('childPostalCode')}
>
{i18n.reports.preschoolApplications.columns.childPostalCode}
</SortableTh>
<SortableTh
onClick={sortBy('currentUnitName')}
sorted={sorted('currentUnitName')}
>
{i18n.reports.preschoolApplications.columns.currentUnitName}
</SortableTh>
<SortableTh
onClick={sortBy('isDaycareAssistanceNeed')}
sorted={sorted('isDaycareAssistanceNeed')}
>
{i18n.reports.preschoolApplications.columns.isDaycareAssistanceNeed}
</SortableTh>
</Tr>
</Thead>
<Tbody>
{sortedRows.length === 0 ? (
<Tr>
<Td colSpan={8} align="center" data-qa="no-results">
{i18n.common.noResults}
</Td>
</Tr>
) : (
sortedRows.map((row) => {
return (
<Tr key={row.applicationId} data-qa="row">
<Td>
<Link to={`/units/${row.applicationUnitId}`}>
{row.applicationUnitName}
</Link>
</Td>
<Td>{row.childLastName}</Td>
<Td>
<Link to={`/child-information/${row.childId}`}>
{row.childFirstName}
</Link>
</Td>
<Td>{row.childDateOfBirth.format()}</Td>
<Td>{row.childStreetAddress}</Td>
<Td>{row.childPostalCode}</Td>
<Td>
{row.currentUnitId !== null &&
row.currentUnitName !== null && (
<Link to={`/units/${row.currentUnitId}`}>
{row.currentUnitName}
</Link>
)}
</Td>
<Td>
{row.isDaycareAssistanceNeed
? i18n.common.yes
: i18n.common.no}
</Td>
</Tr>
)
})
)}
</Tbody>
</TableScrollable>
)
}
Loading