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

UIIN-2784: Set central tenant id in the request when Member tenant deletes a shared record #2416

Merged
merged 11 commits into from
Mar 25, 2024

Conversation

OleksandrHladchenko1
Copy link
Contributor

Purpose

  • If user try to delete shared record from Member tenant, error message appeared. In DevTools he will see 404 error. The task is to remove this errror.

Approach

  • When member tenant is setting shared instance for deletion, pass central tenant id in the request.
  • Created separate function setRecordForDeletion which performs setting record for deletion using dynamically passed tenantId
  • Updated unit tests

Refs

UIIN-2784

Screenshots

UIIN-2784.mp4

@OleksandrHladchenko1 OleksandrHladchenko1 requested review from mariia-aloshyna and a team March 19, 2024 16:09
Copy link

github-actions bot commented Mar 19, 2024

Jest Unit Test Statistics

    1 files  ±0  230 suites  ±0   15m 51s ⏱️ +3s
931 tests +2  929 ✔️ +2  2 💤 ±0  0 ±0 
937 runs  +2  935 ✔️ +2  2 💤 ±0  0 ±0 

Results for commit 3f220a3. ± Comparison against base commit 1477513.

♻️ This comment has been updated with latest results.

Copy link
Member

@zburke zburke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a few questions:

  1. Rather than directly calling fetch(), what about wrapping ViewInstance with withOkapiKy and passing okapiKy to setRecordForDeletion()? That will let you avoid a lot of the boilerplate of x-okapi-this and x-okapi-that. **
  2. What's the value of wrapping the fetch in try/catch and throwing given you just catch and return the error? If you want to return the Error, just return it. Feels like a weird pattern though, since it doesn't alert the calling function that anything has gone wrong unless it inspects the type of the returned value, which it doesn't.

** OK, it's not quite that easy since we missed updating withOkapiKy in folio-org/stripes-core#1348 / STCOR-747 when you added the tenant prop to useOkapiKy. We should add it now so withOkapiKy and useOkapiKy have parity, agreed?

@OleksandrHladchenko1
Copy link
Contributor Author

I have a few questions:

  1. Rather than directly calling fetch(), what about wrapping ViewInstance with withOkapiKy and passing okapiKy to setRecordForDeletion()? That will let you avoid a lot of the boilerplate of x-okapi-this and x-okapi-that. **
  2. What's the value of wrapping the fetch in try/catch and throwing given you just catch and return the error? If you want to return the Error, just return it. Feels like a weird pattern though, since it doesn't alert the calling function that anything has gone wrong unless it inspects the type of the returned value, which it doesn't.

** OK, it's not quite that easy since we missed updating withOkapiKy in folio-org/stripes-core#1348 / STCOR-747 when you added the tenant prop to useOkapiKy. We should add it now so withOkapiKy and useOkapiKy have parity, agreed?

Hi @zburke
I fixed the second part. As for the first one, I totally agree that we need to make changes in withOkapiKy, but there is not so much time before the release to make this changes. What about leaving the implementation using fetch as is and create a ticket for making chenges in withOkapiKy and plan it for Ramsons. What do you think?

@mariia-aloshyna
Copy link
Contributor

@OleksandrHladchenko1 add handling of an error, please. Show unsuccessful toast for the case when the request failed or any error occurred

Copy link
Member

@zburke zburke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different but I'm not sure it's better. The calling code does fx().then().catch(). Previously, your fx() implementation included try/catch, but caught and returned the error, so the parent catch block would never be invoked. Now you removed the try/catch, but also removed its throw, so again the parent catch block will never be invoked.

Am I misunderstanding something here? IIUC, the bug report identified a 404 that was causing an error toast. Sending the correct (central) x-okapi-tenant in the request header fixes the 404 (good!) ... but I think we should keep the error-handling in place in case of some other problem with the request. Agreed?

Copy link
Member

@zburke zburke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes LGTM now. @mariia-aloshyna , do you agree that we have resolved both problems?

  1. correctly set the central tenant id in the request
  2. continue to provide error handling in case the request fails

Copy link

sonarcloud bot commented Mar 25, 2024

@OleksandrHladchenko1 OleksandrHladchenko1 merged commit 0ca01a0 into master Mar 25, 2024
5 checks passed
@OleksandrHladchenko1 OleksandrHladchenko1 deleted the UIIN-2784 branch March 25, 2024 15:01
mariia-aloshyna pushed a commit that referenced this pull request Apr 11, 2024
…letes a shared record (#2416)

* UIIN-2784: Set central tenant id in the request when Member tenant deletes a shared record

* UIIN-2784: Set central tenant id in the request when Member tenant deletes a shared record

* Update utils.test.js

* UIIN-2784: Throw error in catch block

* UIIN-2784: Remove try catch

* UIIN-2784: Throw exception if response is failed

* UIIN-2784: Fix tests

(cherry picked from commit 0ca01a0)
mariia-aloshyna added a commit that referenced this pull request Apr 12, 2024
* UIIN-2802 Retain browse query when switching Inventory browse options (#2417)

* UIIN-2802 Keep query when changing Browse options

* UIIN-2802 Update changelog

* UIIN-2802 Remove unneeded mock code

* UIIN-2802 Update changelog

(cherry picked from commit 1477513)

* UIIN-2802 Set prevSearchIndex when perfoming Browse, not when changing option (#2424)

(cherry picked from commit fdbf09e)

* UIIN-2784: Set central tenant id in the request when Member tenant deletes a shared record (#2416)

* UIIN-2784: Set central tenant id in the request when Member tenant deletes a shared record

* UIIN-2784: Set central tenant id in the request when Member tenant deletes a shared record

* Update utils.test.js

* UIIN-2784: Throw error in catch block

* UIIN-2784: Remove try catch

* UIIN-2784: Throw exception if response is failed

* UIIN-2784: Fix tests

(cherry picked from commit 0ca01a0)

* UIIN-2814 Apply staffSuppress.false in Holdings/Items search (#2420)

* UIIN-2814 Fix staff suppress false not applied for first holdings/items search

* UIIN-2814 Update changelog

* UIIN-2814 fix issue with crash when filters are empty

* UIIN-2814 Added tests for holdings staff suppress

* UIIN-2814 Fix tests

(cherry picked from commit 144db41)

* UIIN-2814 Clear USER_TOUCHED_STAFF_SUPPRESS_STORAGE_KEY flag when switching between search segments (follow-up) (#2435)

* UIIN-2814 Clear USER_TOUCHED_STAFF_SUPPRESS_STORAGE_KEY flag when switching between search segments

* UIIN-2814 fix eslint

(cherry picked from commit 4512f51)

* UIIN-2815: Pass tenantId when open holding details during moving holdings/items (#2427)

(cherry picked from commit cf33184)

* UIIN-2780: ECS - Member consortial accordion is not displaying when user have according affiliation but don't have permissions for view holdings (#2429)

(cherry picked from commit 7e785df)

* Release v11.0.1

---------

Co-authored-by: Denys Bohdan <[email protected]>
Co-authored-by: Oleksandr Hladchenko <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants