Skip to content

Commit

Permalink
Merge pull request #418 from maykinmedia/issue/#393-frontend
Browse files Browse the repository at this point in the history
🐛 #393 - fix: prevent API calls from being made when selecting za…
  • Loading branch information
SilviaAmAm authored Oct 11, 2024
2 parents 5857064 + 3479678 commit 0774660
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 60 deletions.
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

0 comments on commit 0774660

Please sign in to comment.