forked from Cognition-Partner-Workshops/otterworks
-
Notifications
You must be signed in to change notification settings - Fork 0
feature: share folders via expiring public links #277
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
Open
devin-ai-integration
wants to merge
2
commits into
main
Choose a base branch
from
devin/1789402355-folder-share-links
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
174 changes: 174 additions & 0 deletions
174
frontend/client-app/src/components/files/folder-share-dialog.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,174 @@ | ||
| import { useState } from "react"; | ||
| import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; | ||
| import { Check, Copy, Link2, X } from "lucide-react"; | ||
| import toast from "react-hot-toast"; | ||
| import { filesApi } from "@/lib/api"; | ||
| import { formatRelativeTime } from "@/lib/utils"; | ||
|
|
||
| interface FolderShareDialogProps { | ||
| folderId: string; | ||
| folderName: string; | ||
| onClose: () => void; | ||
| } | ||
|
|
||
| function formatExpiry(date: string): string { | ||
| const seconds = Math.round((new Date(date).getTime() - Date.now()) / 1000); | ||
| const absolute = Math.abs(seconds); | ||
| const unit = absolute >= 86_400 ? "day" : absolute >= 3_600 ? "hour" : "minute"; | ||
| const divisor = unit === "day" ? 86_400 : unit === "hour" ? 3_600 : 60; | ||
| const value = Math.round(seconds / divisor); | ||
| return new Intl.RelativeTimeFormat(undefined, { numeric: "auto" }).format(value, unit); | ||
| } | ||
|
|
||
| export function FolderShareDialog({ | ||
| folderId, | ||
| folderName, | ||
| onClose, | ||
| }: FolderShareDialogProps) { | ||
| const queryClient = useQueryClient(); | ||
| const [expiresInHours, setExpiresInHours] = useState(24); | ||
| const [copiedId, setCopiedId] = useState<string | null>(null); | ||
|
|
||
| const linksQuery = useQuery({ | ||
| queryKey: ["folder-share-links", folderId], | ||
| queryFn: () => filesApi.listFolderShareLinks(folderId), | ||
| }); | ||
|
|
||
| const createMutation = useMutation({ | ||
| mutationFn: () => filesApi.createFolderShareLink(folderId, expiresInHours), | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: ["folder-share-links", folderId] }); | ||
| toast.success("Link created"); | ||
| }, | ||
| onError: () => toast.error("Failed to create link"), | ||
| }); | ||
|
|
||
| const revokeMutation = useMutation({ | ||
| mutationFn: (linkId: string) => filesApi.revokeFolderShareLink(folderId, linkId), | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: ["folder-share-links", folderId] }); | ||
| toast.success("Link revoked"); | ||
| }, | ||
| onError: () => toast.error("Failed to revoke link"), | ||
| }); | ||
|
|
||
| const copyLink = async (id: string, url: string) => { | ||
| try { | ||
| await navigator.clipboard.writeText(url); | ||
| setCopiedId(id); | ||
| toast.success("Link copied"); | ||
| window.setTimeout(() => setCopiedId(null), 2000); | ||
| } catch { | ||
| toast.error("Failed to copy link"); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="fixed inset-0 z-40 bg-black/40" onClick={onClose} /> | ||
| <div className="fixed inset-0 z-50 flex items-center justify-center p-4"> | ||
| <div | ||
| className="w-full max-w-lg rounded-2xl bg-white shadow-2xl" | ||
| data-testid="folder-share-dialog" | ||
| onClick={(event) => event.stopPropagation()} | ||
| > | ||
| <header className="flex items-center justify-between border-b border-gray-200 px-6 py-4"> | ||
| <div className="flex items-center gap-2"> | ||
| <Link2 size={18} className="text-otter-600" /> | ||
| <h2 className="text-lg font-semibold text-gray-900"> | ||
| Share “{folderName}” | ||
| </h2> | ||
| </div> | ||
| <button | ||
| type="button" | ||
| onClick={onClose} | ||
| className="rounded-lg p-1.5 text-gray-400 transition hover:bg-gray-100 hover:text-gray-600" | ||
| aria-label="Close" | ||
| > | ||
| <X size={18} /> | ||
| </button> | ||
| </header> | ||
|
|
||
| <div className="space-y-5 px-6 py-5"> | ||
| <div className="flex items-end gap-3"> | ||
| <label className="flex-1 text-sm font-medium text-gray-700"> | ||
| Link expires in | ||
| <select | ||
| value={expiresInHours} | ||
| onChange={(event) => setExpiresInHours(Number(event.target.value))} | ||
| className="mt-1 block w-full rounded-lg border border-gray-300 bg-white px-3 py-2 text-sm focus:border-otter-500 focus:outline-none focus:ring-2 focus:ring-otter-500" | ||
| data-testid="share-link-expiry" | ||
| > | ||
| <option value={1}>1 hour</option> | ||
| <option value={24}>24 hours</option> | ||
| <option value={168}>7 days</option> | ||
| <option value={720}>30 days</option> | ||
| </select> | ||
| </label> | ||
| <button | ||
| type="button" | ||
| onClick={() => createMutation.mutate()} | ||
| disabled={createMutation.isPending} | ||
| className="rounded-lg bg-otter-600 px-4 py-2 text-sm font-medium text-white transition hover:bg-otter-700 disabled:cursor-not-allowed disabled:opacity-60" | ||
| data-testid="create-share-link" | ||
| > | ||
| {createMutation.isPending ? "Creating…" : "Create link"} | ||
| </button> | ||
| </div> | ||
|
|
||
| <div> | ||
| <h3 className="mb-2 text-sm font-medium text-gray-700">Active links</h3> | ||
| {linksQuery.isLoading ? ( | ||
| <p className="py-5 text-center text-sm text-gray-500">Loading links…</p> | ||
| ) : linksQuery.isError ? ( | ||
| <p className="py-5 text-center text-sm text-red-600">Unable to load links</p> | ||
| ) : linksQuery.data?.length ? ( | ||
| <div className="space-y-2"> | ||
| {linksQuery.data.map((link) => ( | ||
| <div | ||
| key={link.id} | ||
| className="flex items-center gap-3 rounded-lg border border-gray-200 px-3 py-2.5" | ||
| data-testid="share-link-row" | ||
| > | ||
| <div className="min-w-0 flex-1"> | ||
| <p className="truncate text-sm text-gray-800" title={link.url}> | ||
| {link.url} | ||
| </p> | ||
| <p className="text-xs text-gray-500"> | ||
| Expires {formatExpiry(link.expiresAt)} · Created{" "} | ||
| {formatRelativeTime(link.createdAt)} | ||
| </p> | ||
| </div> | ||
| <button | ||
| type="button" | ||
| onClick={() => copyLink(link.id, link.url)} | ||
| className="rounded-md p-1.5 text-gray-500 transition hover:bg-otter-50 hover:text-otter-600" | ||
| aria-label="Copy share link" | ||
| data-testid="copy-share-link" | ||
| > | ||
| {copiedId === link.id ? <Check size={16} /> : <Copy size={16} />} | ||
| </button> | ||
| <button | ||
| type="button" | ||
| onClick={() => revokeMutation.mutate(link.id)} | ||
| disabled={revokeMutation.isPending} | ||
| className="text-xs font-medium text-red-600 hover:text-red-700 disabled:opacity-50" | ||
| data-testid="revoke-share-link" | ||
| > | ||
| Revoke | ||
| </button> | ||
| </div> | ||
| ))} | ||
| </div> | ||
| ) : ( | ||
| <p className="rounded-lg border border-dashed border-gray-300 py-6 text-center text-sm text-gray-500"> | ||
| No active links | ||
| </p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📝 Info: Bare Axios mapping is internally consistent
The bare client preserves snake_case fields, which
mapSharedFolderViewmaps explicitly. It also avoids the authenticated client's token verification and redirect behavior.Was this helpful? React with 👍 or 👎 to provide feedback.