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 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
107 changes: 93 additions & 14 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@maykin-ui/admin-ui": "^0.0.35",
"@maykin-ui/admin-ui": "^0.0.36",
"@storybook/test-runner": "^0.18.2",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/user-event": "^13.5.0",
Expand Down
47 changes: 28 additions & 19 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 @@ -142,23 +144,28 @@ export function BaseListView({

// Selection actions.
const getSelectionActions = useCallback(() => {
const fixedItems =
selectable && hasSelection
? ([
{
children: (
<>
<Solid.ExclamationTriangleIcon />
Huidige selectie wissen
</>
),
variant: "warning",
wrap: false,
onClick: handleClearZaakSelection,
},
] as ButtonProps[])
: [];
return [...(selectionActions || []), ...fixedItems];
const disabled = selectable && hasSelection;
const dynamicItems = (selectionActions || []).map((props) =>
Object.hasOwn(props, "disabled")
? props
: { ...props, disabled: selectable && !hasSelection },
);
const fixedItems = disabled
? ([
{
children: (
<>
<Solid.ExclamationTriangleIcon />
Huidige selectie wissen
</>
),
variant: "warning",
wrap: false,
onClick: handleClearZaakSelection,
},
] as ButtonProps[])
: [];
return [...dynamicItems, ...fixedItems];
}, [selectable, hasSelection, selectedZakenOnPage, selectionActions]);

return (
Expand All @@ -182,7 +189,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 +207,7 @@ export function BaseListView({
onPageChange: setPage,
onSelect: handleSelect,
onSelectAllPages: handleSelectAllPages,
onSelectionChange: onSelectionChange,
onSort: setSort,

...dataGridProps,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ export function DestructionListCreatePage() {
Vernietigingslijst opstellen
</>
),
disabled: !allPagesSelected && !hasSelection,

variant: "primary",
wrap: false,
onClick: handleClick,
Expand All @@ -131,6 +129,7 @@ export function DestructionListCreatePage() {
<Body>
<Form
fields={modalFormFields}
justify="stretch"
onSubmit={handleSubmit}
validateOnChange={true}
labelSubmit="Vernietigingslijst opstellen"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export function DestructionListEdit() {
Annuleren
</>
),
disabled: false, // Set explicitly to prevent automatic value based on selection presence.
wrap: false,
onClick: () => handleSetEditing(false),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,6 @@ export function DestructionListProcessReview() {
};
}, [reviewItems, objectList]);

// Selection actions based on `editingState`.
const selectionActions: ButtonProps[] = useMemo(() => [], []);

/**
* Gets called when te selection is cleared.
*/
Expand Down Expand Up @@ -227,7 +224,6 @@ export function DestructionListProcessReview() {
paginatedZaken={paginatedZaken}
secondaryNavigationItems={secondaryNavigationItems}
selectable="visible"
selectionActions={selectionActions}
storageKey={storageKey}
onClearZaakSelection={handleClearSelection}
>
Expand Down
Loading
Loading