Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 5ff6867

Browse files
authored
Merge pull request #292 from City-of-Helsinki/TILA-1391
TILA-1391 filter by units
2 parents d1c9cad + b1f92a9 commit 5ff6867

8 files changed

Lines changed: 131 additions & 31 deletions

File tree

ui/components/application/Page1.tsx

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useEffect, useState } from "react";
33
import { useTranslation } from "react-i18next";
44
import { useForm } from "react-hook-form";
55
import { useQuery } from "@apollo/client";
6-
import { sortBy } from "lodash";
6+
import { sortBy, uniq } from "lodash";
77
import { useRouter } from "next/router";
88
import ApplicationEvent from "../applicationEvent/ApplicationEvent";
99
import {
@@ -24,7 +24,10 @@ import {
2424
ApplicationRoundType,
2525
ReservationUnitType,
2626
} from "../../modules/gql-types";
27-
import { RESERVATION_PURPOSES } from "../../modules/queries/params";
27+
import {
28+
RESERVATION_PURPOSES,
29+
SEARCH_FORM_PARAMS_UNIT,
30+
} from "../../modules/queries/params";
2831

2932
type Props = {
3033
applicationRound: ApplicationRoundType;
@@ -62,13 +65,29 @@ const Page1 = ({
6265
const [options, setOptions] = useState<OptionTypes>();
6366

6467
const [purposeOptions, setPurposeOptions] = useState<OptionType[]>([]);
68+
const [unitOptions, setUnitOptions] = useState<OptionType[]>([]);
6569

6670
const history = useRouter();
6771

6872
const { t } = useTranslation();
6973

7074
const { application } = editorState;
7175

76+
useQuery<Query>(SEARCH_FORM_PARAMS_UNIT, {
77+
onCompleted: (res) => {
78+
const unitsInApplicationRound = uniq(
79+
applicationRound.reservationUnits.flatMap((resUnit) => resUnit.unit.pk)
80+
);
81+
const units = res?.units?.edges
82+
?.filter(({ node }) => unitsInApplicationRound.includes(node.pk))
83+
.map(({ node }) => ({
84+
id: String(node.pk),
85+
name: getTranslation(node, "name"),
86+
}));
87+
setUnitOptions(mapOptions(sortBy(units, "name") as StringParameter[]));
88+
},
89+
});
90+
7291
useQuery<Query>(RESERVATION_PURPOSES, {
7392
onCompleted: (res) => {
7493
const purposes = res?.reservationPurposes?.edges?.map(({ node }) => ({
@@ -79,6 +98,7 @@ const Page1 = ({
7998
mapOptions(sortBy(purposes, "name") as StringParameter[])
8099
);
81100
},
101+
skip: unitOptions.length < 1,
82102
});
83103

84104
const form = useForm({
@@ -218,6 +238,7 @@ const Page1 = ({
218238
optionTypes={{
219239
...options,
220240
purposeOptions,
241+
unitOptions,
221242
}}
222243
selectedReservationUnits={selectedReservationUnits}
223244
onSave={form.handleSubmit((app: Application) =>

ui/components/applicationEvent/ApplicationEvent.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ type OptionTypes = {
4848
abilityGroupOptions: OptionType[];
4949
reservationUnitTypeOptions: OptionType[];
5050
participantCountOptions: OptionType[];
51+
unitOptions: OptionType[];
5152
};
5253

5354
type Props = {
@@ -171,6 +172,7 @@ const ApplicationEvent = ({
171172
purposeOptions,
172173
reservationUnitTypeOptions,
173174
participantCountOptions,
175+
unitOptions,
174176
} = optionTypes;
175177

176178
const { t, i18n } = useTranslation();
@@ -307,6 +309,7 @@ const ApplicationEvent = ({
307309
purposeOptions,
308310
reservationUnitTypeOptions,
309311
participantCountOptions,
312+
unitOptions,
310313
}}
311314
/>
312315
<SubHeadLine>

ui/components/reservation-unit/ReservationUnitList.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type OptionTypes = {
2424
purposeOptions: OptionType[];
2525
reservationUnitTypeOptions: OptionType[];
2626
participantCountOptions: OptionType[];
27+
unitOptions: OptionType[];
2728
};
2829

2930
type Props = {

ui/components/reservation-unit/ReservationUnitModal.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ type OptionsType = {
268268
purposeOptions: OptionType[];
269269
reservationUnitTypeOptions: OptionType[];
270270
participantCountOptions: OptionType[];
271+
unitOptions: OptionType[];
271272
};
272273

273274
const emptyOption = {
@@ -291,6 +292,7 @@ const ReservationUnitModal = ({
291292
const [reservationUnitType, setReservationUnitType] = useState<
292293
OptionType | undefined
293294
>(undefined);
295+
const [unit, setUnit] = useState<OptionType | undefined>(undefined);
294296
const [results, setResults] = useState<ReservationUnitType[]>([]);
295297
const [maxPersons, setMaxPersons] = useState<OptionType | undefined>(
296298
undefined
@@ -304,6 +306,8 @@ const ReservationUnitModal = ({
304306
options.participantCountOptions
305307
);
306308

309+
const unitOptions = [emptyOption].concat(options.unitOptions);
310+
307311
const { t } = useTranslation();
308312

309313
const { data, refetch, loading } = useQuery<Query, QueryReservationUnitsArgs>(
@@ -316,6 +320,7 @@ const ReservationUnitModal = ({
316320
? [reservationUnitType?.value?.toString()]
317321
: [],
318322
applicationRound: [applicationRound.pk.toString()],
323+
unit: unit?.value ? [unit?.value?.toString()] : [],
319324
orderBy: "nameFi",
320325
isDraft: false,
321326
isVisible: true,
@@ -370,6 +375,16 @@ const ReservationUnitModal = ({
370375
}}
371376
defaultValue={emptyOption}
372377
/>
378+
<Select
379+
id="reservationUnitSearch.unit"
380+
placeholder={t("common:select")}
381+
options={unitOptions}
382+
label={t("reservationUnitModal:searchReservationUnitTypeLabel")}
383+
onChange={(selection: OptionType): void => {
384+
setUnit(selection);
385+
}}
386+
defaultValue={emptyOption}
387+
/>
373388
</Filters>
374389
<ButtonContainer>
375390
<SearchButton

ui/cypress/integration/applications.ts

Lines changed: 0 additions & 24 deletions
This file was deleted.

ui/mocks/handlers/applicationRound.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ const applicationRoundsGQL = graphql.query<Query, QueryApplicationRoundsArgs>(
3737
reservationUnits: [
3838
{
3939
pk: 2,
40+
unit: {
41+
pk: 3,
42+
},
4043
} as ReservationUnitType,
4144
{
4245
pk: 6,
46+
unit: {
47+
pk: 2,
48+
},
4349
} as ReservationUnitType,
4450
],
4551
allocating: false,
@@ -70,9 +76,15 @@ const applicationRoundsGQL = graphql.query<Query, QueryApplicationRoundsArgs>(
7076
reservationUnits: [
7177
{
7278
pk: 7,
79+
unit: {
80+
pk: 5,
81+
},
7382
} as ReservationUnitType,
7483
{
7584
pk: 1,
85+
unit: {
86+
pk: 3,
87+
},
7688
} as ReservationUnitType,
7789
],
7890
allocating: false,
@@ -103,6 +115,9 @@ const applicationRoundsGQL = graphql.query<Query, QueryApplicationRoundsArgs>(
103115
reservationUnits: [
104116
{
105117
pk: 7,
118+
unit: {
119+
pk: 5,
120+
},
106121
} as ReservationUnitType,
107122
],
108123
allocating: false,
@@ -133,12 +148,21 @@ const applicationRoundsGQL = graphql.query<Query, QueryApplicationRoundsArgs>(
133148
reservationUnits: [
134149
{
135150
pk: 9,
151+
unit: {
152+
pk: 5,
153+
},
136154
} as ReservationUnitType,
137155
{
138156
pk: 6,
157+
unit: {
158+
pk: 5,
159+
},
139160
} as ReservationUnitType,
140161
{
141162
pk: 7,
163+
unit: {
164+
pk: 5,
165+
},
142166
} as ReservationUnitType,
143167
],
144168
allocating: false,
@@ -169,12 +193,21 @@ const applicationRoundsGQL = graphql.query<Query, QueryApplicationRoundsArgs>(
169193
reservationUnits: [
170194
{
171195
pk: 9,
196+
unit: {
197+
pk: 5,
198+
},
172199
} as ReservationUnitType,
173200
{
174201
pk: 6,
202+
unit: {
203+
pk: 5,
204+
},
175205
} as ReservationUnitType,
176206
{
177207
pk: 7,
208+
unit: {
209+
pk: 5,
210+
},
178211
} as ReservationUnitType,
179212
],
180213
allocating: false,
@@ -202,12 +235,21 @@ const applicationRoundsGQL = graphql.query<Query, QueryApplicationRoundsArgs>(
202235
reservationUnits: [
203236
{
204237
pk: 2,
238+
unit: {
239+
pk: 1,
240+
},
205241
} as ReservationUnitType,
206242
{
207243
pk: 6,
244+
unit: {
245+
pk: 2,
246+
},
208247
} as ReservationUnitType,
209248
{
210249
pk: 7,
250+
unit: {
251+
pk: 3,
252+
},
211253
} as ReservationUnitType,
212254
],
213255
allocating: false,
@@ -235,12 +277,21 @@ const applicationRoundsGQL = graphql.query<Query, QueryApplicationRoundsArgs>(
235277
reservationUnits: [
236278
{
237279
pk: 9,
280+
unit: {
281+
pk: 5,
282+
},
238283
} as ReservationUnitType,
239284
{
240285
pk: 6,
286+
unit: {
287+
pk: 5,
288+
},
241289
} as ReservationUnitType,
242290
{
243291
pk: 7,
292+
unit: {
293+
pk: 5,
294+
},
244295
} as ReservationUnitType,
245296
],
246297
allocating: false,
@@ -271,12 +322,21 @@ const applicationRoundsGQL = graphql.query<Query, QueryApplicationRoundsArgs>(
271322
reservationUnits: [
272323
{
273324
pk: 9,
325+
unit: {
326+
pk: 5,
327+
},
274328
} as ReservationUnitType,
275329
{
276330
pk: 6,
331+
unit: {
332+
pk: 5,
333+
},
277334
} as ReservationUnitType,
278335
{
279336
pk: 7,
337+
unit: {
338+
pk: 5,
339+
},
280340
} as ReservationUnitType,
281341
],
282342
allocating: false,

ui/modules/queries/applicationRound.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export const APPLICATION_ROUNDS = gql`
2121
criteriaSv
2222
reservationUnits {
2323
pk
24+
unit {
25+
pk
26+
}
2427
}
2528
}
2629
}

0 commit comments

Comments
 (0)