-
Notifications
You must be signed in to change notification settings - Fork 345
feat(content-sharing): Define sharing service for shared link and access #4340
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
feat(content-sharing): Define sharing service for shared link and access #4340
Conversation
WalkthroughcreateSharingService splits the single onSuccess callback into onUpdateSharedLink and onRemoveSharedLink, adds createSharedLink/changeSharedLinkAccess/deleteSharedLink methods, updates hook wiring and tests to use the new callbacks, and uses ACCESS_NONE for deletion flows. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor User
participant Hook as useSharingService
participant Service as createSharingService
participant ItemAPI
rect rgba(227,242,253,0.5)
note right of Hook: Initialization
User->>Hook: useSharingService()
Hook->>Service: createSharingService({ onUpdateSharedLink, onRemoveSharedLink })
end
rect rgba(232,245,233,0.5)
note left of User: Create / Update shared link
User->>Hook: createSharedLink() / updateSharedLink(...)
Hook->>Service: createSharedLink()/updateSharedLink(...)
Service->>ItemAPI: share(..., onUpdateSharedLink, CONTENT_SHARING_SHARED_LINK_UPDATE_PARAMS)
ItemAPI-->>Service: itemData
Service-->>Hook: onUpdateSharedLink(itemData)
end
rect rgba(255,243,224,0.5)
note right of User: Change access
User->>Hook: changeSharedLinkAccess(access)
Hook->>Service: changeSharedLinkAccess(access)
Service->>ItemAPI: share(access, onUpdateSharedLink, CONTENT_SHARING_SHARED_LINK_UPDATE_PARAMS)
ItemAPI-->>Service: itemData
Service-->>Hook: onUpdateSharedLink(itemData)
end
rect rgba(255,235,238,0.6)
note right of User: Delete shared link
User->>Hook: deleteSharedLink()
Hook->>Service: deleteSharedLink()
Service->>ItemAPI: share(ACCESS_NONE, onRemoveSharedLink, CONTENT_SHARING_SHARED_LINK_UPDATE_PARAMS)
ItemAPI-->>Service: itemData
Service-->>Hook: onRemoveSharedLink(itemData)
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/elements/content-sharing/__tests__/sharingService.test.ts(7 hunks)src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts(7 hunks)src/elements/content-sharing/hooks/useSharingService.ts(1 hunks)src/elements/content-sharing/sharingService.ts(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/elements/content-sharing/hooks/useSharingService.ts (2)
src/elements/content-sharing/utils/convertItemResponse.ts (1)
convertItemResponse(8-109)src/elements/content-sharing/sharingService.ts (1)
createSharingService(31-94)
src/elements/content-sharing/__tests__/sharingService.test.ts (1)
src/elements/content-sharing/sharingService.ts (1)
createSharingService(31-94)
src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts (2)
src/elements/content-sharing/utils/convertItemResponse.ts (1)
convertItemResponse(8-109)src/elements/content-sharing/sharingService.ts (1)
createSharingService(31-94)
src/elements/content-sharing/sharingService.ts (2)
src/elements/content-sharing/__tests__/useSharedLink.test.js (2)
handleUpdateSharedLinkSuccess(21-21)handleRemoveSharedLinkSuccess(20-20)src/elements/content-sharing/utils/convertSharingServiceData.ts (1)
convertSharedLinkPermissions(16-25)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: lint_test_build
- GitHub Check: Summary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/elements/content-sharing/hooks/useSharingService.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/elements/content-sharing/hooks/useSharingService.ts (3)
src/elements/content-sharing/__tests__/useSharedLink.test.js (2)
handleUpdateSharedLinkSuccess(21-21)handleRemoveSharedLinkSuccess(20-20)src/elements/content-sharing/utils/convertItemResponse.ts (1)
convertItemResponse(8-109)src/elements/content-sharing/sharingService.ts (1)
createSharingService(31-94)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: lint_test_build
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Summary
🔇 Additional comments (3)
src/elements/content-sharing/hooks/useSharingService.ts (3)
46-50: LGTM!The rename from
handleSuccesstohandleUpdateSharedLinkSuccessclarifies the handler's purpose. The logic correctly merges previous and updated shared link data.
58-61: LGTM!The
onSuccessobject structure correctly matches the updatedcreateSharingServiceAPI expectations, providing bothhandleUpdateSharedLinkSuccessandhandleRemoveSharedLinkSuccesshandlers.
63-63: LGTM!The
createSharingServiceinvocation correctly passes theonSuccessobject containing both handlers, aligning with the updated service API.
src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts
Outdated
Show resolved
Hide resolved
4e682a5 to
020f1aa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
src/elements/content-sharing/sharingService.ts (1)
89-95: Consider alphabetical ordering for consistency.The returned methods are almost alphabetically ordered, but
createSharedLinkappears first. Consider this ordering for consistency:return { - createSharedLink, changeSharedLinkAccess, changeSharedLinkPermission, + createSharedLink, deleteSharedLink, updateSharedLink, };However, this is purely a stylistic preference and not required.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/elements/content-sharing/__tests__/sharingService.test.ts(8 hunks)src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts(7 hunks)src/elements/content-sharing/hooks/useSharingService.ts(1 hunks)src/elements/content-sharing/sharingService.ts(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- src/elements/content-sharing/hooks/useSharingService.ts
🧰 Additional context used
🧬 Code graph analysis (3)
src/elements/content-sharing/__tests__/sharingService.test.ts (1)
src/elements/content-sharing/sharingService.ts (1)
createSharingService(29-96)
src/elements/content-sharing/sharingService.ts (1)
src/elements/content-sharing/utils/convertSharingServiceData.ts (1)
convertSharedLinkPermissions(16-25)
src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts (2)
src/elements/content-sharing/utils/convertItemResponse.ts (1)
convertItemResponse(8-109)src/elements/content-sharing/sharingService.ts (1)
createSharingService(29-96)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: lint_test_build
- GitHub Check: Summary
🔇 Additional comments (14)
src/elements/content-sharing/__tests__/sharingService.test.ts (4)
1-23: LGTM! Clean test setup with good patterns.The test file setup is well-structured:
- ACCESS_NONE import supports deletion flows
- Mock callbacks clearly separate update vs. remove concerns
- The wrapper function eliminates duplication across tests
68-90: Good test coverage for changeSharedLinkAccess.The parameterized test covers multiple access levels and properly validates the share API call with the correct parameters.
92-111: createSharedLink test validates undefined access behavior.The test correctly verifies that
undefinedis passed as the access parameter, allowing the backend to set the default access level.
113-132: deleteSharedLink test properly validates removal flow.The test correctly verifies:
- ACCESS_NONE is used for deletion
- onRemoveSharedLink callback is invoked instead of onUpdateSharedLink
src/elements/content-sharing/sharingService.ts (5)
2-2: LGTM! ACCESS_NONE import supports deletion flows.
22-27: LGTM! Callback split enables distinct update and removal handling.The split from a single
onSuccesscallback intoonUpdateSharedLinkandonRemoveSharedLinkprovides better semantic clarity and allows different handling for update vs. delete operations.
37-45: LGTM! changeSharedLinkAccess properly invokes share API.
69-77: Good practice documenting undefined behavior.The inline comment clearly explains that
undefinedallows the backend to set the default access level, which addresses the previous reviewer's feedback.
79-87: LGTM! deleteSharedLink correctly uses ACCESS_NONE and removal callback.The implementation properly:
- Uses ACCESS_NONE to signal deletion to the backend
- Invokes onRemoveSharedLink for distinct removal handling
src/elements/content-sharing/hooks/__tests__/useSharingService.test.ts (5)
16-21: LGTM! Mock service includes all new methods.
47-50: Good refactor introducing shared test fixture.The
mockConvertedDatafixture eliminates duplication and makes tests more maintainable.
113-134: LGTM! Test validates createSharingService call for TYPE_FILE.The test properly verifies that both callbacks are passed and the options are correctly structured.
136-160: Excellent test coverage for both update and remove callbacks.These tests properly:
- Extract callbacks from the mock calls
- Invoke them with mock data
- Verify convertItemResponse is called
- Assert setItem and setSharedLink are invoked
163-212: LGTM! Folder tests mirror file tests for consistency.The tests for TYPE_FOLDER properly cover the same scenarios as TYPE_FILE, ensuring both item types are handled correctly.
…Link-deleteSharedLink
What
Before this PR: user cannot create shared link, remove shared link, or change access dropdown
After this PR:
updateSharedLinkandshareAPI call (created and used by existing contentSharingV1) are called and user can update access dropdown, user can create shared link, and user can remove shared link successfully.Testing:
Summary by CodeRabbit
New Features
Bug Fixes
Tests