mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-12-01 13:34:33 +00:00
feat(webui): use project members for asset comment mentions (#315)
* feat(webui): use project members for asset comment mentions * refactor(project): remove legacy unused bots endpoint and props
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
||||
AlertDialogTitle,
|
||||
} from '@/ui/components/ui/alert-dialog'
|
||||
import type { AttachmentInfo, CommentInfo, UserInfo } from '@shumai/dtos'
|
||||
import type { MemberInfo } from '@/ui/stores/members'
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { Download, File, MoreHorizontal, Trash2 } from 'lucide-react'
|
||||
import React from 'react'
|
||||
@@ -36,7 +37,7 @@ interface MessageCardProps {
|
||||
isReply?: boolean
|
||||
hasReplies?: boolean
|
||||
isLastReply?: boolean
|
||||
getUser: (id: string) => UserInfo
|
||||
getUser: (id: string) => MemberInfo | UserInfo
|
||||
onReply: (message: CommentInfo) => void
|
||||
onViewAttachment: (attachment: AttachmentInfo) => void
|
||||
isSelected?: boolean
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
import type { CommentInfo, PostAttachmentRequest, PostAttachmentResponse } from '@shumai/dtos'
|
||||
import { m } from '@/ui/paraglide/messages.js'
|
||||
import type { BotInfo } from '@shumai/dtos'
|
||||
import type { UserInfo } from '@shumai/dtos'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
import type { Annotation } from '@/ui/types'
|
||||
import { useMutation } from '@tanstack/react-query'
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar'
|
||||
import { Skeleton } from '../ui/skeleton'
|
||||
import { useMemberStore } from '@/ui/stores/members'
|
||||
import { useMemberStore, type MemberInfo } from '@/ui/stores/members'
|
||||
import { useTeamContextStore } from '@/ui/stores/team-context'
|
||||
import {
|
||||
ArrowLeft,
|
||||
@@ -51,7 +49,6 @@ interface ChatInputProps {
|
||||
) => void
|
||||
replyingTo?: CommentInfo | null
|
||||
onCancelReply?: () => void
|
||||
bots?: BotInfo[]
|
||||
initialText?: string
|
||||
hideAnnotationControl?: boolean
|
||||
disableMentions?: boolean
|
||||
@@ -74,7 +71,7 @@ const PREDEFINED_COLORS = [
|
||||
'#ffffff', // White
|
||||
]
|
||||
|
||||
type MentionEntity = { type: 'user'; data: UserInfo } | { type: 'bot'; data: BotInfo }
|
||||
type MentionEntity = { type: 'user'; data: MemberInfo }
|
||||
|
||||
export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
(
|
||||
@@ -83,7 +80,6 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
onSendMessage,
|
||||
replyingTo,
|
||||
onCancelReply,
|
||||
bots = [],
|
||||
initialText = '',
|
||||
hideAnnotationControl = false,
|
||||
disableMentions = false,
|
||||
@@ -111,7 +107,12 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
}, [currentTime, frameRate, videoTimeDisplayMode, startTimecode, formatTimestamp])
|
||||
|
||||
const { teamId, ensureTeamIdForProject } = useTeamContextStore()
|
||||
const { members: storeMembers, loading: membersLoading, fetchMembers } = useMemberStore()
|
||||
const {
|
||||
members: storeMembers,
|
||||
loading: membersLoading,
|
||||
fetchMembers,
|
||||
fetchProjectMembers,
|
||||
} = useMemberStore()
|
||||
|
||||
useEffect(() => {
|
||||
if (projectId && !teamId) {
|
||||
@@ -214,16 +215,11 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
}
|
||||
}, [setIsDrawing])
|
||||
|
||||
const filteredAgents = [
|
||||
...storeMembers
|
||||
.filter(
|
||||
(u) => u.type === 'agent' && u.name?.toLowerCase().startsWith(mentionQuery.toLowerCase()),
|
||||
)
|
||||
.map((u) => ({ type: 'user' as const, data: u })),
|
||||
...bots
|
||||
.filter((b) => b.name?.toLowerCase().startsWith(mentionQuery.toLowerCase()))
|
||||
.map((b) => ({ type: 'bot' as const, data: b })),
|
||||
]
|
||||
const filteredAgents = storeMembers
|
||||
.filter(
|
||||
(u) => u.type === 'agent' && u.name?.toLowerCase().startsWith(mentionQuery.toLowerCase()),
|
||||
)
|
||||
.map((u) => ({ type: 'user' as const, data: u }))
|
||||
|
||||
const filteredHumans = storeMembers
|
||||
.filter(
|
||||
@@ -290,7 +286,9 @@ export const ChatInput = React.forwardRef<HTMLDivElement, ChatInputProps>(
|
||||
setMentionQuery(query)
|
||||
setShowMentionList(true)
|
||||
|
||||
if (teamId) {
|
||||
if (projectId) {
|
||||
fetchProjectMembers(projectId, true, true)
|
||||
} else if (teamId) {
|
||||
fetchMembers(teamId, true, true)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { AssetInfo, AttachmentInfo, CommentInfo, FieldValueInfo } from '@shumai/dtos'
|
||||
import { type FieldInfo as MetadataFieldInfo } from '@shumai/dtos'
|
||||
import type { UserInfo } from '@shumai/dtos'
|
||||
import type { MemberInfo } from '@/ui/stores/members'
|
||||
import { client } from '@/ui/api/client'
|
||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/ui/components/ui/tabs'
|
||||
@@ -23,7 +23,7 @@ interface FileViewerRightSidebarProps {
|
||||
projectId: string
|
||||
file: AssetInfo | null
|
||||
onSaveField: (fieldId: string, value: unknown) => void
|
||||
members: UserInfo[]
|
||||
members: MemberInfo[]
|
||||
onCommentSelect?: (comment: CommentInfo) => void
|
||||
hideAnnotationControl?: boolean
|
||||
readOnly?: boolean
|
||||
@@ -78,23 +78,7 @@ export function FileViewerRightSidebar({
|
||||
enabled: !!projectId && !publicFields,
|
||||
})
|
||||
|
||||
const { data: bots } = useQuery({
|
||||
queryKey: ['projects', projectId, 'bots'],
|
||||
queryFn: async () => {
|
||||
const res = await client.api.projects[':projectId'].bots.$get({
|
||||
param: { projectId: projectId },
|
||||
})
|
||||
if (!res.ok) throw new Error('Failed to fetch bots')
|
||||
return await res.json()
|
||||
},
|
||||
enabled: !!projectId && !readOnly,
|
||||
})
|
||||
|
||||
const viewerDef = getViewerForFile(file)
|
||||
const isAiEnabled = !!viewerDef?.commentsConfig?.hasAiBots
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const enabledBots = isAiEnabled ? (bots as any[]) || [] : []
|
||||
|
||||
useEffect(() => {
|
||||
if (publicFields) {
|
||||
@@ -280,20 +264,12 @@ export function FileViewerRightSidebar({
|
||||
}
|
||||
}
|
||||
|
||||
const getUser = (id: string): UserInfo => {
|
||||
const getUser = (id: string): MemberInfo => {
|
||||
const member = members.find((m) => m.id === id)
|
||||
if (member) {
|
||||
return member
|
||||
}
|
||||
|
||||
if (bots) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const bot = (bots as any[]).find((b) => b.id === id)
|
||||
if (bot) {
|
||||
return { id: bot.id, name: bot.name, role: 'bot' }
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
id: 'unknown',
|
||||
name: 'Unknown',
|
||||
@@ -417,7 +393,6 @@ export function FileViewerRightSidebar({
|
||||
onSendMessage={handleSendMessage}
|
||||
replyingTo={replyingTo}
|
||||
onCancelReply={() => setReplyingTo(null)}
|
||||
bots={enabledBots}
|
||||
hideAnnotationControl={hideAnnotationControl}
|
||||
disableMentions={isPublic}
|
||||
currentTime={viewerDef?.commentsConfig?.hasTimestamp ? currentTime : undefined}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from '@/ui/components/ui/alert-dialog'
|
||||
import { Badge } from '@/ui/components/ui/badge'
|
||||
import { Button } from '@/ui/components/ui/button'
|
||||
import { Card, CardContent } from '@/ui/components/ui/card'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from '@/ui/components/ui/dropdown-menu'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/ui/components/ui/select'
|
||||
import { Switch } from '@/ui/components/ui/switch'
|
||||
import { usePermissions } from '@/ui/hooks/use-permissions'
|
||||
@@ -32,16 +32,16 @@ import { m } from '@/ui/paraglide/messages.js'
|
||||
import { AgentInfo, AgentPermission, AgentType, ThinkingLevel } from '@shumai/dtos'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import {
|
||||
Bot,
|
||||
ChevronDown,
|
||||
Cpu,
|
||||
Loader2,
|
||||
MessageSquare,
|
||||
MoreVertical,
|
||||
Plus,
|
||||
Puzzle,
|
||||
Trash2,
|
||||
Zap,
|
||||
Bot,
|
||||
ChevronDown,
|
||||
Cpu,
|
||||
Loader2,
|
||||
MessageSquare,
|
||||
MoreVertical,
|
||||
Plus,
|
||||
Puzzle,
|
||||
Trash2,
|
||||
Zap,
|
||||
} from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
@@ -9,6 +9,5 @@ export const defaultTypeDefinition: FileTypeDefinition = {
|
||||
commentsConfig: {
|
||||
hasTimestamp: false,
|
||||
hasAnnotations: false,
|
||||
hasAiBots: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -11,6 +11,5 @@ export const imageTypeDefinition: FileTypeDefinition = {
|
||||
commentsConfig: {
|
||||
hasTimestamp: false,
|
||||
hasAnnotations: true,
|
||||
hasAiBots: true,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ export const pdfTypeDefinition: FileTypeDefinition = {
|
||||
commentsConfig: {
|
||||
hasTimestamp: true,
|
||||
hasAnnotations: true,
|
||||
hasAiBots: true,
|
||||
formatTimestamp: (second: number) => `P${Math.round(second)}`,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -50,7 +50,6 @@ export interface FileTypeDefinition {
|
||||
commentsConfig?: {
|
||||
hasTimestamp?: boolean
|
||||
hasAnnotations?: boolean
|
||||
hasAiBots?: boolean
|
||||
formatTimestamp?: (second: number) => string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,5 @@ export const videoTypeDefinition: FileTypeDefinition = {
|
||||
commentsConfig: {
|
||||
hasTimestamp: true,
|
||||
hasAnnotations: true,
|
||||
hasAiBots: true,
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user