Skip to content

fix(cozy-sharing): Refresh link state in share modal#3022

Merged
doubleface merged 1 commit into
masterfrom
feat/refreshLink
Jun 9, 2026
Merged

fix(cozy-sharing): Refresh link state in share modal#3022
doubleface merged 1 commit into
masterfrom
feat/refreshLink

Conversation

@doubleface

@doubleface doubleface commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

https://app.notion.com/p/linagora/5d2f7429646042378356ecb072890d35?v=1c062718bad180d3847f000cd4c97139&p=37462718bad18075bab2e83c56b23d26&pm=s

Summary by CodeRabbit

  • Refactor

    • Updated sharing link handling in sharing dialogs and federated folder modals to use a centralized context source
  • Tests

    • Added tests to verify "Anyone with the link" access message displays correctly when sharing links are available

@coderabbitai

coderabbitai Bot commented Jun 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@doubleface, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 58 minutes and 52 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d1af8313-b38c-4346-aaaf-e2fdd5d6a334

📥 Commits

Reviewing files that changed from the base of the PR and between 6d569c1 and e05c313.

📒 Files selected for processing (6)
  • packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.jsx
  • packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.spec.jsx
  • packages/cozy-sharing/src/components/ShareDialogCozyToCozy.jsx
  • packages/cozy-sharing/src/components/ShareDialogCozyToCozy.spec.jsx
  • packages/cozy-sharing/src/components/ShareDialogOnlyByLink.jsx
  • packages/cozy-sharing/src/components/ShareDialogOnlyByLink.spec.jsx

Walkthrough

Three sharing dialog components are refactored to derive share links from the sharing context hook instead of receiving links as props. FederatedFolderModal conditionally uses async sharingLink for federated documents or direct getSharingLink() calls otherwise. ShareDialogCozyToCozy and ShareDialogOnlyByLink import useSharingContext, compute displayedLink from document IDs, and pass the derived link to child components. Test files are updated to mock the sharing context hook and verify conditional UI rendering based on link availability.

Possibly related PRs

  • linagora/cozy-libs#3009: Modifies FederatedFolderModal to change how share-by-link URLs are generated and passed to WhoHasAccess and ShareByLink components.

Suggested reviewers

  • rezk2ll
  • zatteo
  • JF-Cozy
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: enabling link state refresh across multiple share dialog components by deriving links dynamically via useSharingContext instead of relying on prop passing.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/refreshLink

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.jsx (1)

107-127: ⚡ Quick win

Remove unnecessary state update for non-federated documents.

The else clause (lines 114-116) sets sharingLink state for non-federated documents, but this state is never used—line 190 calls getSharingLink(...) directly instead. This causes unnecessary state updates every time documentPermissions changes, adding complexity without benefit.

♻️ Simplify by removing the unused else clause
 useEffect(() => {
   const fetchSharingLink = async () => {
     if (!existingDocument) return

     if (existingDocument.driveId) {
       const link = await getFederatedShareLink(existingDocument)
       setSharingLink(link)
-    } else {
-      setSharingLink(getSharingLink(existingDocument._id))
     }
   }

   fetchSharingLink()
 }, [
   existingDocument,
   documentPermissions,
   getFederatedShareLink,
-  getSharingLink,
-  getOwner,
-  getSharingById
+  getFederatedShareLink
 ])

Also consider removing getSharingLink, getOwner, and getSharingById from the dependency array since they're not used in the effect body.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.jsx`
around lines 107 - 127, The effect in FederatedFolderModal's useEffect updates
sharingLink for non-federated docs unnecessarily: remove the else branch in
fetchSharingLink so setSharingLink is only called when existingDocument.driveId
is present (keep only the getFederatedShareLink path), and then simplify the
dependency array by removing getSharingLink, getOwner, and getSharingById since
they are not referenced in the effect body; this preserves the existing
getSharingLink usage at render-time (line ~190) and avoids redundant state
updates.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.jsx`:
- Around line 107-127: The effect in FederatedFolderModal's useEffect updates
sharingLink for non-federated docs unnecessarily: remove the else branch in
fetchSharingLink so setSharingLink is only called when existingDocument.driveId
is present (keep only the getFederatedShareLink path), and then simplify the
dependency array by removing getSharingLink, getOwner, and getSharingById since
they are not referenced in the effect body; this preserves the existing
getSharingLink usage at render-time (line ~190) and avoids redundant state
updates.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1b3fe2f8-b296-4c0b-af02-2b6089e588d4

📥 Commits

Reviewing files that changed from the base of the PR and between 64edc58 and 6d569c1.

📒 Files selected for processing (6)
  • packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.jsx
  • packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.spec.jsx
  • packages/cozy-sharing/src/components/ShareDialogCozyToCozy.jsx
  • packages/cozy-sharing/src/components/ShareDialogCozyToCozy.spec.jsx
  • packages/cozy-sharing/src/components/ShareDialogOnlyByLink.jsx
  • packages/cozy-sharing/src/components/ShareDialogOnlyByLink.spec.jsx

const existingRecipients = existingDocument
? getRecipients(existingDocument._id)
: []
const displayedLink = existingDocument?.driveId

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why it's static if the document has a driveId?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. getFederatedShareLink is actually synchronous
So the useState + useEffect wrapper is unnecessary here .
I'll compute the federated link directly in displayedLink, just like getSharingLink
is used for non-federated documents, and remove the effect/state.

@doubleface doubleface requested a review from rezk2ll June 9, 2026 07:48
@doubleface doubleface merged commit dfb6dd3 into master Jun 9, 2026
3 checks passed
@doubleface doubleface deleted the feat/refreshLink branch June 9, 2026 08:57
doubleface added a commit to linagora/twake-drive that referenced this pull request Jun 10, 2026
- Bump `cozy-sharing` from `33.1.1` to `33.2.2`

- [linagora/cozy-libs#2994](linagora/cozy-libs#2994) (`fix(cozy-sharing): Make matching diacritic-insensitive`)
- [linagora/cozy-libs#3021](linagora/cozy-libs#3021) (`feat(cozy-sharing): Show progress icon on done button during share`)
- [linagora/cozy-libs#3022](linagora/cozy-libs#3022) (`fix(cozy-sharing): Refresh link state in share modal`)
- [linagora/cozy-libs#3023](linagora/cozy-libs#3023) (`fix(cozy-sharing): Allow sharing shared drive folder root by email`)
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.

2 participants