ohcnetwork / care_fe

Care is a Digital Public Good enabling TeleICU & Decentralised Administration of Healthcare Capacity across States.
https://care.ohc.network
MIT License
257 stars 449 forks source link

Back Button is not working proper in the camera configuration page #9233

Closed nihal467 closed 1 day ago

nihal467 commented 2 days ago

Describe the bug

The back button on the Camera Configuration page does not take the user to the previously accessed page.

To Reproduce Steps to reproduce the behavior:

  1. Go to the Assets section.
  2. Click on any camera asset.
  3. Click on the Configuration button, then click on the back button in the breadcrumbs.
  4. See error

Expected behavior

The back button in the breadcrumbs should navigate the user to the previously accessed page.

Screenshots

Image

SwanandBhuskute commented 2 days ago

I would like to work on this @nihal467

SwanandBhuskute commented 2 days ago

@nihal467 @rithviknishad I think this is the error

If the location of the asset has bed in them then an additional query of ?bed=..... is added in the current url (after clicking on Configure, what we see that page) even if no bed if link

but if the asset facility doesn't have any bed in them, then the url is normal like /facility/sdu-sf-dsf-fdf/assets/dsf-sdfds-0dsf0/configure

so if url - facility/abc-xyz-pqr/assets/abc-112-sdf-prd/configure , "Back" works fine if url - facility/abc-xyz-pqr/assets/abc-112-sdf-prd/configure?bed=tru-23-dsf-3e4 , "Back" not working

rithviknishad commented 2 days ago

Yes, we are using the query param to store the state for currently selected bed to be configured. We could skip the setting of query param when the asset bed list request completes initially, instead just use the first bed as the fallback if no query param is set.

SwanandBhuskute commented 2 days ago

This is the error @rithviknishad @nihal467

The history is like this [ "/facility/0c95c7f0-e1d2-4aff-83fa-933cef60d3a8/assets/5b089eb8-0b23-4d47-ae86-337a3902672e/configure?bed=f3323a4f-dae4-4c8a-a3fa-ac980d4adf34", "/facility/0c95c7f0-e1d2-4aff-83fa-933cef60d3a8/assets/5b089eb8-0b23-4d47-ae86-337a3902672e/configure", "/facility/0c95c7f0-e1d2-4aff-83fa-933cef60d3a8/assets/5b089eb8-0b23-4d47-ae86-337a3902672e", "/assets", "/facility" ]

so , when we go on /configure we immediately fetch the first linked bed or unlinked bed (if not) and attach it in the url and thus the history gets updated

then when I click back I do go to /configure again, but as we are by default fetching first bed, again the url gets updated and so is history

so you can see we are stuck in this infinite jumps of history[0] - /configure?bed= and history[1] - /configure

so i think we need to handle this useEffect hook

Image

maybe we can just not change the url on initial render , keep it /configure? it makes sense too

rithviknishad commented 2 days ago

Let's remove that useEffect hook (line 96 to 100) altogether. And modify the selectedAssetBed to first check from query param and if query param not present, fallback to using the firstBedId without needing to set the query.