-
Notifications
You must be signed in to change notification settings - Fork 5
Add container sharing (collaborators) feature #388
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
cmyers-mieweb
wants to merge
9
commits into
main
Choose a base branch
from
cmyers_shareables
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 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e94f0b5
Add container sharing (collaborators) feature
cmyers-mieweb c4d0228
Add hover transition styles to row action buttons
cmyers-mieweb 6ddf911
Add container filters and user list handling
cmyers-mieweb 9470130
Refactor container components; add collaborators support
cmyers-mieweb ed4c275
Enforce ownership filtering for container lists
cmyers-mieweb 83b351e
Centralize container visibility and manage auth
cmyers-mieweb 07caa5c
Capture req.query to avoid Express 5 re-parse
cmyers-mieweb 03bac5a
Disable resource requests for non-owners
cmyers-mieweb 7d2e3f0
Make shared containers read-only for collaborators
cmyers-mieweb 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
165 changes: 165 additions & 0 deletions
165
create-a-container/client/src/pages/containers/CollaboratorsManager.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,165 @@ | ||
| import { useState } from 'react'; | ||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
| import { Badge, Button, Input, useToast } from '@mieweb/ui'; | ||
| import { UserPlus, X } from 'lucide-react'; | ||
| import { ApiError } from '@/lib/api'; | ||
| import { keys, queries } from '@/lib/queries'; | ||
|
|
||
| /** | ||
| * Presentational list of collaborator usernames rendered as removable chips. | ||
| * Shared by the live manager and the create-form's "additional owners" field so | ||
| * both surfaces look identical. | ||
| */ | ||
| export function CollaboratorChips({ | ||
| usernames, | ||
| onRemove, | ||
| disabled, | ||
| emptyText = 'Not shared with anyone yet.', | ||
| }: { | ||
| usernames: string[]; | ||
| onRemove: (username: string) => void; | ||
| disabled?: boolean; | ||
| emptyText?: string; | ||
| }) { | ||
| if (usernames.length === 0) { | ||
| return <p className="text-sm text-muted-foreground">{emptyText}</p>; | ||
| } | ||
| return ( | ||
| <ul className="flex flex-wrap gap-2" aria-label="Shared with"> | ||
| {usernames.map((username) => ( | ||
| <li key={username}> | ||
| <Badge variant="secondary" className="gap-1 pr-1"> | ||
| <span>{username}</span> | ||
| <button | ||
| type="button" | ||
| onClick={() => onRemove(username)} | ||
| disabled={disabled} | ||
| aria-label={`Remove ${username}`} | ||
| className="inline-flex items-center justify-center rounded-full p-0.5 hover:bg-black/10 disabled:opacity-50" | ||
| > | ||
| <X className="size-3" aria-hidden="true" /> | ||
| </button> | ||
| </Badge> | ||
| </li> | ||
| ))} | ||
| </ul> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * An accessible username input + add button. Surfaces a validation/error | ||
| * message (e.g. "user does not exist") inline beneath the field. | ||
| */ | ||
| export function AddCollaboratorField({ | ||
| onAdd, | ||
| pending, | ||
| error, | ||
| label = 'Username', | ||
| }: { | ||
| onAdd: (username: string) => void; | ||
| pending?: boolean; | ||
| error?: string | null; | ||
| label?: string; | ||
| }) { | ||
| const [value, setValue] = useState(''); | ||
|
|
||
| const submit = () => { | ||
| const username = value.trim(); | ||
| if (!username) return; | ||
| onAdd(username); | ||
| setValue(''); | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex items-end gap-2"> | ||
| <div className="flex-1"> | ||
| <Input | ||
| label={label} | ||
| placeholder="Enter a username" | ||
| autoCapitalize="none" | ||
| autoCorrect="off" | ||
| spellCheck={false} | ||
| value={value} | ||
| error={error || undefined} | ||
| hasError={!!error} | ||
| onChange={(e) => setValue(e.target.value)} | ||
| onKeyDown={(e) => { | ||
| // Submit on Enter without bubbling to an enclosing form. | ||
| if (e.key === 'Enter') { | ||
| e.preventDefault(); | ||
| submit(); | ||
| } | ||
| }} | ||
| /> | ||
| </div> | ||
| <Button | ||
| type="button" | ||
| variant="outline" | ||
| leftIcon={<UserPlus className="size-4" />} | ||
| isLoading={pending} | ||
| disabled={!value.trim()} | ||
| onClick={submit} | ||
| > | ||
| Share | ||
| </Button> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Live sharing manager for an existing container: lists current collaborators | ||
| * and lets the owner/admin add or remove them via the API. Used both in the | ||
| * list page's share dialog and the edit form's Sharing section. | ||
| */ | ||
| export function CollaboratorsManager({ | ||
| siteId, | ||
| containerId, | ||
| collaborators, | ||
| }: { | ||
| siteId: string; | ||
| containerId: number; | ||
| collaborators: string[]; | ||
| }) { | ||
| const qc = useQueryClient(); | ||
| const toast = useToast(); | ||
| const [addError, setAddError] = useState<string | null>(null); | ||
|
|
||
| const invalidate = () => { | ||
| qc.invalidateQueries({ queryKey: keys.container(siteId, containerId) }); | ||
| qc.invalidateQueries({ queryKey: keys.containers(siteId) }); | ||
| }; | ||
|
|
||
| const add = useMutation({ | ||
| mutationFn: (username: string) => queries.shareContainer(siteId, containerId, username), | ||
| onSuccess: (_data, username) => { | ||
| setAddError(null); | ||
| toast.success(`Shared with ${username}`); | ||
| invalidate(); | ||
| }, | ||
| onError: (err: ApiError) => setAddError(err.message), | ||
| }); | ||
|
|
||
| const remove = useMutation({ | ||
| mutationFn: (username: string) => queries.unshareContainer(siteId, containerId, username), | ||
| onSuccess: (_data, username) => { | ||
| toast.success(`Stopped sharing with ${username}`); | ||
| invalidate(); | ||
| }, | ||
| onError: (err: ApiError) => toast.error(err.message), | ||
| }); | ||
|
|
||
| return ( | ||
| <div className="flex flex-col gap-4"> | ||
| <CollaboratorChips | ||
| usernames={collaborators} | ||
| onRemove={(u) => remove.mutate(u)} | ||
| disabled={remove.isPending} | ||
| /> | ||
| <AddCollaboratorField | ||
| onAdd={(u) => add.mutate(u)} | ||
| pending={add.isPending} | ||
| error={addError} | ||
| /> | ||
| </div> | ||
| ); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.