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

🐛 #393 - fix: prevent API calls from being made when selecting za… #418

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 6 additions & 2 deletions frontend/src/pages/destructionlist/abstract/BaseListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export type BaseListViewProps = React.PropsWithChildren<{

dataGridProps?: Partial<DataGridProps>;

onClearZaakSelection?: () => void; // FIXME: REMOVE?
onClearZaakSelection?: () => void;
onSelectionChange?: (rows: AttributeData[]) => void;
}>;

export function BaseListView({
Expand All @@ -78,6 +79,7 @@ export function BaseListView({
children,

onClearZaakSelection,
onSelectionChange,
}: BaseListViewProps) {
const { state } = useNavigation();
const [page, setPage] = usePage();
Expand Down Expand Up @@ -182,7 +184,8 @@ export function BaseListView({
allowSelectAllPages,
allPagesSelected,
count: paginatedZaken.count,
equalityChecker: (a, b) => a.uuid === b.uuid || a.url === b.url,
equalityChecker: (a, b) =>
a && b && (a.uuid === b.uuid || a.url === b.url),
fields,
filterTransform,
loading: state === "loading",
Expand All @@ -199,6 +202,7 @@ export function BaseListView({
onPageChange: setPage,
onSelect: handleSelect,
onSelectAllPages: handleSelectAllPages,
onSelectionChange: onSelectionChange,
onSort: setSort,

...dataGridProps,
Expand Down
6 changes: 0 additions & 6 deletions frontend/src/pages/destructionlist/hooks/useZaakSelection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { AttributeData } from "@maykin-ui/admin-ui";
import { useEffect, useMemo, useState } from "react";
import { useRevalidator } from "react-router-dom";

import {
ZaakSelection,
Expand Down Expand Up @@ -61,8 +60,6 @@ export function useZaakSelection<T = unknown>(
clearZaakSelection: ZaakSelectionClearer;
},
] {
const revalidator = useRevalidator();

// All pages selected.
const [allPagesSelectedState, setAllPagesSelectedState] = useState<boolean>();

Expand Down Expand Up @@ -255,7 +252,6 @@ export function useZaakSelection<T = unknown>(

await _updatePageSpecificZaakSelectionState();
await _updateSelectionSizeState();
revalidator.revalidate();
};

/**
Expand All @@ -270,7 +266,6 @@ export function useZaakSelection<T = unknown>(

_updatePageSpecificZaakSelectionState();
await _updateAllPagesSelectedState(selected);
revalidator.revalidate();
};

/**
Expand All @@ -280,7 +275,6 @@ export function useZaakSelection<T = unknown>(
await libClearZaakSelection(storageKey);
await _updateAllPagesSelectedState(false);
setZaakSelectionState({});
revalidator.revalidate();
};

return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
usePrompt,
} from "@maykin-ui/admin-ui";
import React, { useMemo } from "react";
import { useLoaderData } from "react-router-dom";
import { useLoaderData, useRevalidator } from "react-router-dom";

import { useSubmitAction } from "../../../hooks";
import { ZaakReview } from "../../../lib/api/review";
Expand All @@ -28,6 +28,7 @@ export const getDestructionListReviewKey = (id: string) =>
*/
export function DestructionListReviewPage() {
const prompt = usePrompt();
const revalidator = useRevalidator();

// rows: AttributeData[], selected: boolean
const {
Expand All @@ -48,7 +49,6 @@ export function DestructionListReviewPage() {

// The object list of the current page with review actions appended.
const objectList = useMemo(() => {
// console.log("objectList");
return paginatedZaken.results.map((zaak) => {
const badge = zaakReviewStatusBadges[zaak.url as string].badge;
const actions = getActionsToolbarForZaak(zaak);
Expand Down Expand Up @@ -282,6 +282,14 @@ export function DestructionListReviewPage() {
return { approved };
};

/**
* Gets called when the selection changes outside of the per-zaak toolbar.
* Revalidates the loader so the selection is up2date.
*/
const handleSelectionChange = () => {
revalidator.revalidate();
};

return (
<BaseListView
storageKey={destructionListReviewKey}
Expand All @@ -300,6 +308,8 @@ export function DestructionListReviewPage() {
labelSelect: "Markeren als (on)gezien",
labelSelectAll: "Alles als (on)gezien markeren",
}}
onSelectionChange={handleSelectionChange}
onClearZaakSelection={handleSelectionChange}
></BaseListView>
);
}
Loading