maykinmedia / open-archiefbeheer

0 stars 0 forks source link

Zaken and destruction list items in edit view are out of sync #420

Closed svenvandescheur closed 1 month ago

svenvandescheur commented 1 month ago

Destruction list edit page doesn't show the correct active selection, possibly due to mismatch between /api/v1/destruction-list-items/ and /api/v1/zaken/ endpoint.

Reproducible test case:

  1. On https://openarchiefbeheer.test.maykin.opengem.nl/: create a new destruction list, add all the items from the first page, and the first item of the second page.
  2. Navigate to the detail page without edit mode turned on (default): on the second page there should be 1 selected zaak.
  3. Turn edit mode on: the zaak is no longer on the second page.

Technical notes:

The view is constructed sing primarily two data sources:

In edit mode the second endpoint is used to populate the datagrid, however the first endpoint is used to check whether zaken should be selected, every Zaak on the current page is matched to a in memory page containing all the selected DestructionListItem's zaken. If both the zaken are truthy (set) and the uuid or url matches, the zaak is selected.

For example:

The database has 5 items:

A destruction list has 3 selected items:

Given that the page size is 2 (instead of 100 on the actual application):

Hypothesis

The above implementation assumes that both the endpoints are in sync and have the same Zaaken on identical positions on the same page. If any of the filtering/ordering is off, the selection may be incomplete.

svenvandescheur commented 1 month ago

Replacing order_by("in_exception_list"), with .order_by("in_exception_list", "pk") seems to to the trick when no custom ordering is active, however with custom ordering the order_by is overridden and the match between zaken and destructionlist items can't be made on the same position on a page.