Skip to content

Commit

Permalink
🐛 #393 - fix: various UI issues related to the selection state
Browse files Browse the repository at this point in the history
  • Loading branch information
svenvandescheur committed Oct 11, 2024
1 parent 81047c2 commit 3479678
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 35 deletions.
39 changes: 22 additions & 17 deletions frontend/src/pages/destructionlist/abstract/BaseListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,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 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 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
13 changes: 1 addition & 12 deletions frontend/src/pages/destructionlist/hooks/useZaakSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ZaakSelection,
addToZaakSelection,
getAllZakenSelected,
getFilteredZaakSelection,
getZaakSelectionItem,
getZaakSelectionSize,
clearZaakSelection as libClearZaakSelection,
Expand Down Expand Up @@ -63,9 +62,6 @@ export function useZaakSelection<T = unknown>(
// All pages selected.
const [allPagesSelectedState, setAllPagesSelectedState] = useState<boolean>();

// Has selection items.
const [hasSelectionState, setHasSelectionState] = useState<boolean>();

// Selection count
const [selectionSizeState, setSelectionSizeState] = useState<number>(0);

Expand All @@ -82,13 +78,6 @@ export function useZaakSelection<T = unknown>(
}
});

getFilteredZaakSelection(storageKey).then((zs) => {
const hasSelection = Object.keys(zs).length > 0;
if (hasSelection !== hasSelectionState) {
setHasSelectionState(hasSelection);
}
});

getZaakSelectionSize(storageKey).then((size) => {
if (size !== selectionSizeState) {
setSelectionSizeState(size);
Expand Down Expand Up @@ -281,7 +270,7 @@ export function useZaakSelection<T = unknown>(
selectedZakenOnPage,
onSelect,
{
hasSelection: Boolean(hasSelectionState || allPagesSelectedState),
hasSelection: Boolean(selectionSizeState || allPagesSelectedState),
allPagesSelected: Boolean(allPagesSelectedState),
selectionSize: selectionSizeState,
deSelectedZakenOnPage,
Expand Down

0 comments on commit 3479678

Please sign in to comment.