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

✨ Support selecting zaaktype from list in filter in destruct… #36

Merged
merged 1 commit into from
May 17, 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
1 change: 1 addition & 0 deletions backend/src/openarchiefbeheer/zaken/api/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Meta:
"vertrouwelijkheidaanduiding": ["exact", "icontains"],
"uiterlijke_einddatum_afdoening": ["exact", "gt", "lt"],
"verantwoordelijke_organisatie": ["exact", "icontains"],
"zaaktype": ["exact", "icontains"],
# TODO Decide what to do with these fields and if/how we want to filter them
# # Array Fields
# "rollen": ["exact", "icontains"],
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/lib/api/private.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { request } from "./request";

export type ZaaktypeChoice = {
/** The description field of the zaaktype. */
label: string;

/** The URL field of the zaaktype. */
value: string;

/** A combination of the identification and the date on which the zaaktype will no longer be valid (if present). */
extra: string;
};

/**
* Retrieve zaaktypen from Open Zaak and return a value and a label per zaaktype. The label is the 'omschrijving' field
* an the value is the URL. The response is cached for 15 minutes.
*/
export async function listZaaktypeChoices() {
const response = await request("GET", "/_zaaktypen-choices");
const promise: Promise<ZaaktypeChoice[]> = response.json();
return promise;
}
32 changes: 22 additions & 10 deletions frontend/src/pages/destructionlist/DestructionListCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,29 @@ import {
} from "react-router-dom";

import { loginRequired } from "../../lib/api/loginRequired";
import { ZaaktypeChoice, listZaaktypeChoices } from "../../lib/api/private";
import { PaginatedZaken, listZaken } from "../../lib/api/zaken";
import { Zaak } from "../../types";
import "./DestructionListCreate.css";

export type DestructionListCreateContext = {
zaken: PaginatedZaken;
zaaktypeChoices: ZaaktypeChoice[];
};

/**
* React Router loader.
* @param request
* TOOD: Requires destruction list lists endpoint.
*/
export const destructionListCreateLoader = loginRequired(({ request }) => {
const searchParams = new URL(request.url).searchParams;
return listZaken(searchParams);
});
export const destructionListCreateLoader = loginRequired(
async ({ request }) => {
const searchParams = new URL(request.url).searchParams;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the old version, the query params used here were:

        'archiefnominatie': 'vernietigen',
        'archiefactiedatum__lt': currentDate,

We also wanted the already used zaken to be filtered out, so the param not_in_destruction_list should be used. Not sure if this was already taken into account, so I thought that I would mention it 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SilviaAmAm nice catch, this was indeed left out. I've added this line to introduce it:

searchParams.set("not_in_destruction_list", "true");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets discuss the other fields later on (and possibly create and issue out of it). I'll merge this to support ongoing efforts.

searchParams.set("not_in_destruction_list", "true");
const zaken = await listZaken(searchParams);
const zaaktypeChoices = await listZaaktypeChoices();
return { zaken, zaaktypeChoices };
},
);

export type DestructionListCreateProps = Omit<
React.ComponentProps<"main">,
Expand All @@ -37,9 +47,10 @@ export type DestructionListCreateProps = Omit<
export function DestructionListCreatePage({
...props
}: DestructionListCreateProps) {
const { count, results } = useLoaderData() as PaginatedZaken;
const { zaken, zaaktypeChoices } =
useLoaderData() as DestructionListCreateContext;
const [searchParams, setSearchParams] = useSearchParams();
const objectList = results as unknown as AttributeData[];
const objectList = zaken.results as unknown as AttributeData[];
const { state } = useNavigation();

const fields: TypedField[] = [
Expand All @@ -51,9 +62,10 @@ export function DestructionListCreatePage({
},
{
name: "zaaktype",
filterLookup: "zaaktype__omschrijving__icontains",
filterValue: searchParams.get("zaaktype__omschrijving__icontains") || "",
filterLookup: "zaaktype",
filterValue: searchParams.get("zaaktype") || "",
valueLookup: "_expand.zaaktype.omschrijving",
options: zaaktypeChoices,
type: "string",
},
{
Expand Down Expand Up @@ -139,7 +151,7 @@ export function DestructionListCreatePage({
<ListTemplate
dataGridProps={
{
count: count,
count: zaken.count,
fields: fields,
loading: state === "loading",
objectList: objectList,
Expand Down
Loading