Show add collaborator box only for spaces

This commit is contained in:
Hakan Shehu
2025-01-23 00:39:42 +01:00
parent 7bc261cbe4
commit 6e661894d2
4 changed files with 15 additions and 18 deletions

View File

@@ -25,7 +25,7 @@ export const ChatHeader = ({ chat, role }: ChatHeaderProps) => {
</div>
<div className="flex items-center gap-2">
<EntryCollaboratorsPopover
entryId={chat.id}
entry={chat}
entries={[chat]}
role={role}
/>

View File

@@ -9,13 +9,13 @@ import {
} from '@/renderer/components/ui/popover';
interface EntryCollaboratorsPopoverProps {
entryId: string;
entry: Entry;
entries: Entry[];
role: EntryRole;
}
export const EntryCollaboratorsPopover = ({
entryId,
entry,
entries,
role,
}: EntryCollaboratorsPopoverProps) => {
@@ -25,7 +25,7 @@ export const EntryCollaboratorsPopover = ({
<UserRoundPlus className="size-5 cursor-pointer text-muted-foreground hover:text-foreground" />
</PopoverTrigger>
<PopoverContent className="mr-2 max-h-128 w-128 overflow-auto">
<EntryCollaborators entryId={entryId} entries={entries} role={role} />
<EntryCollaborators entry={entry} entries={entries} role={role} />
</PopoverContent>
</Popover>
);

View File

@@ -12,33 +12,34 @@ import { Separator } from '@/renderer/components/ui/separator';
import { buildEntryCollaborators } from '@/shared/lib/entries';
interface EntryCollaboratorsProps {
entryId: string;
entry: Entry;
entries: Entry[];
role: EntryRole;
}
export const EntryCollaborators = ({
entryId,
entry,
entries,
role,
}: EntryCollaboratorsProps) => {
const collaborators = buildEntryCollaborators(entries);
const directCollaborators = collaborators.filter(
(collaborator) => collaborator.entryId === entryId
(collaborator) => collaborator.entryId === entry.id
);
const directCollaboratorIds = directCollaborators.map(
(collaborator) => collaborator.collaboratorId
);
const isAdmin = hasEntryRole(role, 'admin');
const ancestors = entries.filter((entry) => entry.id !== entryId);
const canAddCollaborator = isAdmin && entry.type === 'space';
const ancestors = entries.filter((entry) => entry.id !== entry.id);
return (
<div className="flex flex-col gap-2">
{isAdmin && (
{canAddCollaborator && (
<React.Fragment>
<EntryCollaboratorCreate
entryId={entryId}
entryId={entry.id}
existingCollaborators={directCollaboratorIds}
/>
<Separator />
@@ -67,7 +68,7 @@ export const EntryCollaborators = ({
return (
<EntryCollaborator
key={collaborator.collaboratorId}
entryId={entryId}
entryId={entry.id}
collaboratorId={collaborator.collaboratorId}
role={collaborator.role}
canEdit={canEdit}
@@ -85,7 +86,7 @@ export const EntryCollaborators = ({
</div>
{ancestors.map((node) => {
const inheritCollaborators = collaborators.filter(
(collaborator) => collaborator.entryId === entryId
(collaborator) => collaborator.entryId === node.id
);
if (inheritCollaborators.length === 0) {
@@ -105,7 +106,7 @@ export const EntryCollaborators = ({
return (
<EntryCollaborator
key={collaborator.collaboratorId}
entryId={entryId}
entryId={node.id}
collaboratorId={collaborator.collaboratorId}
role={collaborator.role}
canEdit={canEdit}

View File

@@ -102,11 +102,7 @@ export const SpaceSettingsDialog = ({
className="focus-visible:ring-0 focus-visible:ring-offset-0"
value="collaborators"
>
<EntryCollaborators
entryId={space.id}
entries={[space]}
role={role}
/>
<EntryCollaborators entry={space} entries={[space]} role={role} />
</TabsContent>
{canDelete && (
<TabsContent