Skip to content

Commit f7c750a

Browse files
committed
🚧
1 parent 2c9a961 commit f7c750a

File tree

5 files changed

+101
-25
lines changed

5 files changed

+101
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Option } from "@maykin-ui/admin-ui";
2+
import { useEffect, useState } from "react";
3+
4+
import { listBehandelendAfdelingChoices } from "../lib/api/private";
5+
import { useAlertOnError } from "./useAlertOnError";
6+
7+
/**
8+
* Hook to fetch the list of behandelend afdeling choices.
9+
*/
10+
export function useBehandelendAfdelingChoices(): Option[] {
11+
const alertOnError = useAlertOnError(
12+
"Er is een fout opgetreden bij het ophalen van de resultaattypen!",
13+
);
14+
15+
const [valueState, setValueState] = useState<Option[]>([]);
16+
useEffect(() => {
17+
console.log("fd");
18+
listBehandelendAfdelingChoices()
19+
.then((s) => setValueState(s))
20+
.catch(alertOnError);
21+
}, []);
22+
23+
return valueState;
24+
}

frontend/src/hooks/useFields.tsx

+12-25
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ import {
1616
} from "../lib/fieldSelection/fieldSelection";
1717
import { formatDate } from "../lib/format/date";
1818
import { FIELD_SELECTION_STORAGE_KEY } from "../pages/constants";
19-
import { ExpandZaak, Zaak } from "../types";
19+
import { Zaak } from "../types";
20+
import { useBehandelendAfdelingChoices } from "./useBehandelendAfdelingChoices";
21+
import { useInternalResultaatTypeChoices } from "./useListInternalResultaatTypeChoices";
2022
import { useSelectielijstKlasseChoices } from "./useSelectielijstKlasseChoices";
2123
import { useZaaktypeChoices } from "./useZaaktypeChoices";
2224

@@ -66,7 +68,9 @@ export function useFields<T extends Zaak = Zaak>(
6668
review,
6769
searchParams,
6870
);
69-
71+
const behandelenAfdelingChoices = useBehandelendAfdelingChoices();
72+
const resultaattypeChoices = useInternalResultaatTypeChoices();
73+
console.log(resultaattypeChoices);
7074
// The raw, unfiltered configuration of the available base fields.
7175
// Both filterLookup AND filterLookups will be used for clearing filters.
7276
// NOTE: This get filtered by `getActiveFields()`.
@@ -133,25 +137,8 @@ export function useFields<T extends Zaak = Zaak>(
133137
name: "Behandelende afdeling",
134138
type: "string",
135139
filterLookup: "behandelend_afdeling__icontains",
136-
valueTransform: (rowData: object) => {
137-
const rollen = (rowData as ExpandZaak)._expand?.rollen || [];
138-
if (!rollen.length) return "";
139-
const behandelendAfdeling: string[] = [];
140-
// TODO - Understand why the ExpandZaak type doesn't work
141-
rollen.map((role) => {
142-
if (
143-
// @ts-expect-error The type of role is 'never' for some reason
144-
role.betrokkeneType === "organisatorische_eenheid" &&
145-
// @ts-expect-error The type of role is 'never' for some reason
146-
role.betrokkeneIdentificatie?.identificatie
147-
)
148-
behandelendAfdeling.push(
149-
// @ts-expect-error The type of role is 'never' for some reason
150-
role.betrokkeneIdentificatie?.identificatie,
151-
);
152-
});
153-
return behandelendAfdeling.join(", ");
154-
},
140+
valueLookup: "_expand.behandelend_afdeling",
141+
options: behandelenAfdelingChoices,
155142
width: "150px",
156143
},
157144
{
@@ -167,11 +154,11 @@ export function useFields<T extends Zaak = Zaak>(
167154
},
168155
{
169156
name: "resultaat",
170-
filterLookup: "resultaat__resultaattype__omschrijving__icontains",
157+
filterLookup: "resultaat__resultaattype__url__icontains",
171158
filterValue:
172-
searchParams.get("resultaat__resultaattype__omschrijving__icontains") ||
173-
"",
174-
valueLookup: "_expand.resultaat._expand.resultaattype.omschrijving",
159+
searchParams.get("resultaat__resultaattype__url__icontains") || "",
160+
valueLookup: "_expand.resultaat._expand.resultaattype.url",
161+
options: resultaattypeChoices,
175162
type: "string",
176163
width: "150px",
177164
},
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { Option } from "@maykin-ui/admin-ui";
2+
import { useEffect, useState } from "react";
3+
4+
import { listInternalResultaatTypeChoices } from "../lib/api/private";
5+
import { useAlertOnError } from "./useAlertOnError";
6+
7+
/**
8+
* Hook to fetch the internal result type choices.
9+
*/
10+
export function useInternalResultaatTypeChoices(): Option[] {
11+
const alertOnError = useAlertOnError(
12+
"Er is een fout opgetreden bij het ophalen van de resultaattypen!",
13+
);
14+
15+
const [valueState, setValueState] = useState<Option[]>([]);
16+
useEffect(() => {
17+
listInternalResultaatTypeChoices()
18+
.then((s) => setValueState(s))
19+
.catch(alertOnError);
20+
}, []);
21+
22+
return valueState;
23+
}

frontend/src/lib/api/private.ts

+41
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,47 @@ export async function listResultaatTypeChoices(zaaktypeUrl?: string) {
6767
);
6868
}
6969

70+
/**
71+
* Retrieve resultaattypen from Open Zaak and return a value and a label per
72+
* resultaattype. The label is the field 'omschrijving'.
73+
*/
74+
export async function listInternalResultaatTypeChoices(zaaktypeUrl?: string) {
75+
return cacheMemo(
76+
"listInternalResultaatTypeChoices",
77+
async () => {
78+
const response = await request(
79+
"GET",
80+
"/_internal-resultaattype-choices/",
81+
{
82+
zaaktype: zaaktypeUrl,
83+
},
84+
);
85+
const promise: Promise<Option[]> = response.json();
86+
87+
return promise;
88+
},
89+
[zaaktypeUrl],
90+
);
91+
}
92+
93+
export async function listBehandelendAfdelingChoices(
94+
params?:
95+
| URLSearchParams
96+
| {
97+
zaak?: Zaak["url"];
98+
},
99+
) {
100+
return cacheMemo("listBehandelendAfdelingChoices", async () => {
101+
const response = await request(
102+
"GET",
103+
"/_retrieve-behandelend-afdeling-choices-choices/",
104+
params,
105+
);
106+
const promise: Promise<Option[]> = response.json();
107+
return promise;
108+
});
109+
}
110+
70111
/**
71112
* This takes the 'selectielijstprocestype' from the 'zaaktype', then retrieves all the 'resultaten' possible for this
72113
* 'procestype' from the selectielijst API.

frontend/src/pages/destructionlist/abstract/BaseListView.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export function BaseListView<T extends Zaak = Zaak>({
9999
...zaak,
100100
href: formatMessage(REACT_APP_ZAAK_URL_TEMPLATE || "", zaak),
101101
})) as unknown as T[];
102+
console.log(paginatedZaken.results);
102103

103104
// Fields.
104105
const [fields, setFields, filterTransform, activeFilters, resetFilters] =

0 commit comments

Comments
 (0)