Skip to content

Commit

Permalink
Merge pull request #6255 from espoon-voltti/revert-moving-search-filt…
Browse files Browse the repository at this point in the history
…ers-out-of-context

Korjaus talouden hakufiltterien säilymiseen
  • Loading branch information
Joosakur authored Jan 17, 2025
2 parents 0d4af27 + ac610b7 commit f11fd62
Show file tree
Hide file tree
Showing 7 changed files with 277 additions and 238 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
// SPDX-FileCopyrightText: 2017-2024 City of Espoo
// SPDX-FileCopyrightText: 2017-2022 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import React, {
Fragment,
useCallback,
useContext,
useEffect,
useState
} from 'react'
import React, { Fragment, useContext, useEffect } from 'react'
import { useMemo } from 'react'

import { wrapResult } from 'lib-common/api'
Expand All @@ -24,10 +18,7 @@ import { Gap } from 'lib-components/white-space'
import { getUnits } from '../../generated/api-clients/daycare'
import { getFinanceDecisionHandlers } from '../../generated/api-clients/pis'
import { useTranslation } from '../../state/i18n'
import {
FeeDecisionSearchFilters,
InvoicingUiContext
} from '../../state/invoicing-ui'
import { InvoicingUiContext } from '../../state/invoicing-ui'
import {
AreaFilter,
FeeDecisionDifferenceFilter,
Expand All @@ -42,23 +33,14 @@ import {
const getUnitsResult = wrapResult(getUnits)
const getFinanceDecisionHandlersResult = wrapResult(getFinanceDecisionHandlers)

const emptyFilters: FeeDecisionSearchFilters = {
searchTerms: '',
distinctiveDetails: [],
statuses: ['DRAFT'],
area: [],
startDate: undefined,
endDate: LocalDate.todayInSystemTz(),
searchByStartDate: false,
financeDecisionHandlerId: undefined,
difference: []
}

function FeeDecisionFilters() {
const { i18n } = useTranslation()

const {
feeDecisions: { setConfirmedSearchFilters },
feeDecisions: {
searchFilters,
setSearchFilters,
confirmSearchFilters,
clearSearchFilters
},
shared: {
units,
setUnits,
Expand All @@ -68,23 +50,7 @@ function FeeDecisionFilters() {
}
} = useContext(InvoicingUiContext)

const [searchFilters, _setSearchFilters] =
useState<FeeDecisionSearchFilters>(emptyFilters)
const setSearchFilters = useCallback(
(value: React.SetStateAction<FeeDecisionSearchFilters>) => {
_setSearchFilters(value)
setConfirmedSearchFilters(undefined)
},
[setConfirmedSearchFilters]
)
const clearSearchFilters = useCallback(() => {
_setSearchFilters(emptyFilters)
setConfirmedSearchFilters(undefined)
}, [setConfirmedSearchFilters])
const confirmSearchFilters = useCallback(
() => setConfirmedSearchFilters(searchFilters),
[searchFilters, setConfirmedSearchFilters]
)
const { i18n } = useTranslation()

useEffect(() => {
void getUnitsResult({ areaIds: null, type: 'DAYCARE', from: null }).then(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-FileCopyrightText: 2017-2024 City of Espoo
// SPDX-FileCopyrightText: 2017-2022 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import React, { Fragment, useCallback, useContext, useState } from 'react'
import React, { Fragment, useCallback, useContext } from 'react'

import { ProviderType } from 'lib-common/generated/api-types/daycare'
import { DaycareId } from 'lib-common/generated/api-types/shared'
Expand All @@ -13,10 +13,7 @@ import { Label } from 'lib-components/typography'
import { Gap } from 'lib-components/white-space'

import { useTranslation } from '../../state/i18n'
import {
IncomeStatementSearchFilters,
InvoicingUiContext
} from '../../state/invoicing-ui'
import { InvoicingUiContext } from '../../state/invoicing-ui'
import { renderResult } from '../async-rendering'
import {
AreaFilter,
Expand All @@ -27,45 +24,23 @@ import {
} from '../common/Filters'
import { unitFilterQuery } from '../unit/queries'

const emptyFilters: IncomeStatementSearchFilters = {
area: [],
unit: undefined,
providerTypes: [],
sentStartDate: undefined,
sentEndDate: undefined,
placementValidDate: undefined
}

export default React.memo(function IncomeStatementsFilters() {
const { i18n } = useTranslation()

const {
incomeStatements: { setConfirmedSearchFilters },
incomeStatements: {
searchFilters,
setSearchFilters,
clearSearchFilters,
confirmSearchFilters
},
shared: { availableAreas }
} = useContext(InvoicingUiContext)

const [searchFilters, _setSearchFilters] =
useState<IncomeStatementSearchFilters>(emptyFilters)
const setSearchFilters = useCallback(
(value: React.SetStateAction<IncomeStatementSearchFilters>) => {
_setSearchFilters(value)
setConfirmedSearchFilters(undefined)
},
[setConfirmedSearchFilters]
)
const clearSearchFilters = useCallback(() => {
_setSearchFilters(emptyFilters)
setConfirmedSearchFilters(undefined)
}, [setConfirmedSearchFilters])
const confirmSearchFilters = useCallback(
() => setConfirmedSearchFilters(searchFilters),
[searchFilters, setConfirmedSearchFilters]
)

const unitsResult = useQueryResult(
unitFilterQuery({ areaIds: null, type: 'DAYCARE', from: null })
)

const { i18n } = useTranslation()

const toggleArea = useCallback(
(code: string) => () => {
setSearchFilters((old) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
// SPDX-FileCopyrightText: 2017-2024 City of Espoo
// SPDX-FileCopyrightText: 2017-2022 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import React, {
Fragment,
useCallback,
useContext,
useEffect,
useState
} from 'react'
import React, { Fragment, useCallback, useContext, useEffect } from 'react'

import { wrapResult } from 'lib-common/api'
import {
Expand All @@ -21,10 +15,7 @@ import { Gap } from 'lib-components/white-space'

import { getUnits } from '../../generated/api-clients/daycare'
import { useTranslation } from '../../state/i18n'
import {
InvoiceSearchFilters,
InvoicingUiContext
} from '../../state/invoicing-ui'
import { InvoicingUiContext } from '../../state/invoicing-ui'
import {
AreaFilter,
Filters,
Expand All @@ -36,41 +27,18 @@ import {

const getUnitsResult = wrapResult(getUnits)

const emptyFilters: InvoiceSearchFilters = {
searchTerms: '',
distinctiveDetails: [],
area: [],
status: 'DRAFT',
startDate: undefined,
endDate: undefined,
useCustomDatesForInvoiceSending: false
}

export default React.memo(function InvoiceFilters() {
const { i18n } = useTranslation()

const {
invoices: { setConfirmedSearchFilters },
invoices: {
searchFilters,
setSearchFilters,
confirmSearchFilters,
clearSearchFilters
},
shared: { units, setUnits, availableAreas }
} = useContext(InvoicingUiContext)

const [searchFilters, _setSearchFilters] =
useState<InvoiceSearchFilters>(emptyFilters)
const setSearchFilters = useCallback(
(value: React.SetStateAction<InvoiceSearchFilters>) => {
_setSearchFilters(value)
setConfirmedSearchFilters(undefined)
},
[setConfirmedSearchFilters]
)
const clearSearchFilters = useCallback(() => {
_setSearchFilters(emptyFilters)
setConfirmedSearchFilters(undefined)
}, [setConfirmedSearchFilters])
const confirmSearchFilters = useCallback(
() => setConfirmedSearchFilters(searchFilters),
[searchFilters, setConfirmedSearchFilters]
)
const { i18n } = useTranslation()

useEffect(() => {
void getUnitsResult({ areaIds: null, type: 'DAYCARE', from: null }).then(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ import { Label } from 'lib-components/typography'
import { Gap } from 'lib-components/white-space'

import { useTranslation } from '../../state/i18n'
import {
InvoiceSearchFilters,
InvoicingUiContext
} from '../../state/invoicing-ui'
import { InvoicingUiContext } from '../../state/invoicing-ui'
import { renderResult } from '../async-rendering'

import Actions from './Actions'
Expand Down Expand Up @@ -157,9 +154,8 @@ export default React.memo(function InvoicesPage() {
/>
</>
))}
{showModal && searchFilters ? (
{showModal ? (
<Modal
searchFilters={searchFilters}
onClose={closeModal}
onSendDone={() => {
closeModal()
Expand All @@ -174,19 +170,21 @@ export default React.memo(function InvoicesPage() {
})

const Modal = React.memo(function Modal({
searchFilters,
onClose,
onSendDone,
checkedInvoices,
fullAreaSelection
}: {
searchFilters: InvoiceSearchFilters
onClose: () => void
onSendDone: () => void
checkedInvoices: Set<InvoiceId>
fullAreaSelection: boolean
}) {
const { i18n } = useTranslation()
const {
invoices: { searchFilters }
} = useContext(InvoicingUiContext)

const [invoiceDate, setInvoiceDate] = useState(LocalDate.todayInSystemTz())
const [dueDate, setDueDate] = useState(
LocalDate.todayInSystemTz().addBusinessDays(10)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
// SPDX-FileCopyrightText: 2017-2024 City of Espoo
// SPDX-FileCopyrightText: 2017-2022 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import React, {
Fragment,
useCallback,
useContext,
useEffect,
useState
} from 'react'
import React, { Fragment, useCallback, useContext, useEffect } from 'react'

import { wrapResult } from 'lib-common/api'
import {
Expand All @@ -29,50 +23,24 @@ import { fasExclamationTriangle } from 'lib-icons'

import { getUnits } from '../../generated/api-clients/daycare'
import { useTranslation } from '../../state/i18n'
import {
InvoicingUiContext,
PaymentSearchFilters
} from '../../state/invoicing-ui'
import { InvoicingUiContext } from '../../state/invoicing-ui'
import { AreaFilter, Filters, UnitFilter } from '../common/Filters'
import { FlexRow } from '../common/styled/containers'

const getUnitsResult = wrapResult(getUnits)

const emptyFilters: PaymentSearchFilters = {
searchTerms: '',
area: [],
unit: null,
distinctions: [],
status: 'DRAFT',
paymentDateStart: null,
paymentDateEnd: null
}

export default React.memo(function PaymentFilters() {
const { i18n } = useTranslation()

const {
payments: { setConfirmedSearchFilters },
payments: {
searchFilters,
setSearchFilters,
confirmSearchFilters,
clearSearchFilters
},
shared: { units, setUnits, availableAreas }
} = useContext(InvoicingUiContext)

const [searchFilters, _setSearchFilters] =
useState<PaymentSearchFilters>(emptyFilters)
const setSearchFilters = useCallback(
(value: React.SetStateAction<PaymentSearchFilters>) => {
_setSearchFilters(value)
setConfirmedSearchFilters(undefined)
},
[setConfirmedSearchFilters]
)
const clearSearchFilters = useCallback(() => {
_setSearchFilters(emptyFilters)
setConfirmedSearchFilters(undefined)
}, [setConfirmedSearchFilters])
const confirmSearchFilters = useCallback(
() => setConfirmedSearchFilters(searchFilters),
[searchFilters, setConfirmedSearchFilters]
)
const { i18n } = useTranslation()

useEffect(() => {
void getUnitsResult({ areaIds: null, type: 'DAYCARE', from: null }).then(
Expand Down
Loading

0 comments on commit f11fd62

Please sign in to comment.