feat(spaces): добавить изолированные пространства и multi-user
Docker / build (push) Failing after 20s
Docker / build (push) Failing after 20s
Полная изоляция данных по space, Share (ACL) и Assign, switcher и участники в UI. Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
f26b2c8777
commit
e360efb885
47 files changed
+2675
-237
No files matched your search
@@ -12,6 +12,7 @@ import {
|
||||
RefreshCwIcon,
|
||||
FolderKanbanIcon,
|
||||
HistoryIcon,
|
||||
UsersIcon,
|
||||
} from 'lucide-react'
|
||||
|
||||
import {
|
||||
@@ -48,6 +49,7 @@ import { useState, type CSSProperties, type ReactNode } from 'react'
|
||||
import { ModeToggle } from '@/components/mode-toggle'
|
||||
import { SystemMonitorPopover } from '@/components/layout/system-monitor-popover'
|
||||
import { AppsMenu } from '@/components/layout/apps-menu'
|
||||
import { SpaceSwitcher } from '@/components/layout/space-switcher'
|
||||
import { AppSwitcher } from '@/components/app-switcher'
|
||||
import { GlobalSearch, useGlobalSearchHotkey } from '@/components/global-search'
|
||||
import { dashboardStatsQueryOptions } from '@/queries/dashboard'
|
||||
@@ -101,6 +103,7 @@ const NAV_GROUPS: NavGroup[] = [
|
||||
{
|
||||
label: 'Система',
|
||||
items: [
|
||||
{ to: '/spaces', label: 'Пространство', icon: UsersIcon },
|
||||
{ to: '/sync-journal', label: 'Журнал синка', icon: HistoryIcon },
|
||||
{ to: '/audit', label: 'Журнал изменений', icon: HistoryIcon },
|
||||
{ to: '/settings', label: 'Настройки', icon: Settings },
|
||||
@@ -127,6 +130,7 @@ const PARENT_ROUTE: Record<string, string> = {
|
||||
'/renewals': '/dashboard',
|
||||
'/sync-journal': '/settings',
|
||||
'/audit': '/settings',
|
||||
'/spaces': '/settings',
|
||||
}
|
||||
|
||||
/** Shared ops chrome — etalon EvoBGP. @see docs/ui-design-contract.md */
|
||||
@@ -169,6 +173,7 @@ export function AppShell({ children }: { children: ReactNode }) {
|
||||
<Sidebar collapsible="icon">
|
||||
<SidebarHeader>
|
||||
<AppSwitcher />
|
||||
<SpaceSwitcher />
|
||||
</SidebarHeader>
|
||||
<SidebarContent>
|
||||
{navGroups.map((group) => (
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { ChevronsUpDownIcon, PlusIcon } from 'lucide-react'
|
||||
import { useEffect, useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { Button } from '@cfdm/ui/components/button'
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuTrigger,
|
||||
} from '@cfdm/ui/components/dropdown-menu'
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from '@cfdm/ui/components/dialog'
|
||||
import { Input } from '@cfdm/ui/components/input'
|
||||
import { Label } from '@cfdm/ui/components/label'
|
||||
import {
|
||||
SidebarMenu,
|
||||
SidebarMenuButton,
|
||||
SidebarMenuItem,
|
||||
} from '@cfdm/ui/components/sidebar'
|
||||
|
||||
import { api } from '@/lib/api-client'
|
||||
import { getStoredSpaceId, setStoredSpaceId, type SpaceDto } from '@/lib/space'
|
||||
import { spacesKeys, spacesQueryOptions, snapshotKeys } from '@/queries/snapshot'
|
||||
|
||||
export function SpaceSwitcher() {
|
||||
const qc = useQueryClient()
|
||||
const { data: spaces = [] } = useQuery(spacesQueryOptions())
|
||||
const currentId = getStoredSpaceId() ?? spaces[0]?.id
|
||||
const current = spaces.find((s) => s.id === currentId) ?? spaces[0]
|
||||
const [createOpen, setCreateOpen] = useState(false)
|
||||
const [name, setName] = useState('')
|
||||
|
||||
useEffect(() => {
|
||||
if (!getStoredSpaceId() && spaces[0]?.id) {
|
||||
setStoredSpaceId(spaces[0].id)
|
||||
}
|
||||
}, [spaces])
|
||||
|
||||
function selectSpace(space: SpaceDto) {
|
||||
setStoredSpaceId(space.id)
|
||||
void qc.invalidateQueries({ queryKey: snapshotKeys.all })
|
||||
void qc.invalidateQueries({ queryKey: spacesKeys.all })
|
||||
toast.success(`Пространство: ${space.name}`)
|
||||
}
|
||||
|
||||
async function handleCreate() {
|
||||
const n = name.trim()
|
||||
if (!n) return
|
||||
try {
|
||||
const created = await api.createSpace({ name: n })
|
||||
setStoredSpaceId(created.id)
|
||||
setCreateOpen(false)
|
||||
setName('')
|
||||
await qc.invalidateQueries({ queryKey: spacesKeys.all })
|
||||
await qc.invalidateQueries({ queryKey: snapshotKeys.all })
|
||||
toast.success('Пространство создано')
|
||||
} catch (e) {
|
||||
toast.error(e instanceof Error ? e.message : 'Ошибка создания')
|
||||
}
|
||||
}
|
||||
|
||||
if (spaces.length === 0) {
|
||||
return (
|
||||
<div className="px-2 py-1.5 text-xs text-muted-foreground">Пространства…</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<SidebarMenu>
|
||||
<SidebarMenuItem>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger
|
||||
render={<SidebarMenuButton size="lg" className="aria-expanded:bg-muted" />}
|
||||
>
|
||||
<div className="grid flex-1 text-left text-sm leading-tight">
|
||||
<span className="truncate font-medium">{current?.name ?? 'Пространство'}</span>
|
||||
<span className="truncate text-xs text-muted-foreground">
|
||||
{current?.kind === 'main' ? 'Основное' : 'Личное'}
|
||||
{current?.role ? ` · ${current.role}` : ''}
|
||||
</span>
|
||||
</div>
|
||||
<ChevronsUpDownIcon className="ml-auto size-4" />
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent className="min-w-56 rounded-lg" align="start" sideOffset={4}>
|
||||
<DropdownMenuLabel>Пространства</DropdownMenuLabel>
|
||||
{spaces.map((s) => (
|
||||
<DropdownMenuItem
|
||||
key={s.id}
|
||||
onClick={() => selectSpace(s)}
|
||||
className={s.id === current?.id ? 'bg-accent' : undefined}
|
||||
>
|
||||
<span className="truncate">{s.name}</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem onClick={() => setCreateOpen(true)}>
|
||||
<PlusIcon className="size-4" />
|
||||
Создать пространство
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</SidebarMenuItem>
|
||||
</SidebarMenu>
|
||||
|
||||
<Dialog open={createOpen} onOpenChange={setCreateOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>Новое пространство</DialogTitle>
|
||||
</DialogHeader>
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label htmlFor="space-name">Название</Label>
|
||||
<Input
|
||||
id="space-name"
|
||||
value={name}
|
||||
onChange={(e) => setName(e.target.value)}
|
||||
placeholder="Моя команда"
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setCreateOpen(false)}>
|
||||
Отмена
|
||||
</Button>
|
||||
<Button onClick={() => void handleCreate()}>Создать</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useState } from 'react'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import { Button } from '@cfdm/ui/components/button'
|
||||
import { Label } from '@cfdm/ui/components/label'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@cfdm/ui/components/select'
|
||||
import {
|
||||
Sheet,
|
||||
SheetContent,
|
||||
SheetDescription,
|
||||
SheetFooter,
|
||||
SheetHeader,
|
||||
SheetTitle,
|
||||
} from '@cfdm/ui/components/sheet'
|
||||
|
||||
import { api } from '@/lib/api-client'
|
||||
import { getStoredSpaceId } from '@/lib/space'
|
||||
import { spacesQueryOptions, snapshotKeys } from '@/queries/snapshot'
|
||||
import type { Vps } from '@/types/entities'
|
||||
|
||||
type Props = {
|
||||
vps: Vps | null
|
||||
open: boolean
|
||||
onOpenChange: (open: boolean) => void
|
||||
}
|
||||
|
||||
export function VpsAccessSheet({ vps, open, onOpenChange }: Props) {
|
||||
const qc = useQueryClient()
|
||||
const { data: spaces = [] } = useQuery(spacesQueryOptions())
|
||||
const fromSpaceId = getStoredSpaceId() ?? spaces.find((s) => s.kind === 'main')?.id ?? ''
|
||||
const targets = spaces.filter((s) => s.id !== fromSpaceId)
|
||||
const [toSpaceId, setToSpaceId] = useState('')
|
||||
const [permission, setPermission] = useState<'read' | 'write'>('read')
|
||||
|
||||
const shareMutation = useMutation({
|
||||
mutationFn: () =>
|
||||
api.shareVps(fromSpaceId, vps!.id, {
|
||||
toSpaceId,
|
||||
permission,
|
||||
}),
|
||||
onSuccess: async () => {
|
||||
toast.success('Доступ выдан (share)')
|
||||
onOpenChange(false)
|
||||
await qc.invalidateQueries({ queryKey: snapshotKeys.all })
|
||||
},
|
||||
onError: (e: Error) => toast.error(e.message),
|
||||
})
|
||||
|
||||
const assignMutation = useMutation({
|
||||
mutationFn: () => api.assignVps(fromSpaceId, vps!.id, toSpaceId),
|
||||
onSuccess: async () => {
|
||||
toast.success('Сервер перенесён (assign)')
|
||||
onOpenChange(false)
|
||||
await qc.invalidateQueries({ queryKey: snapshotKeys.all })
|
||||
},
|
||||
onError: (e: Error) => toast.error(e.message),
|
||||
})
|
||||
|
||||
return (
|
||||
<Sheet open={open} onOpenChange={onOpenChange}>
|
||||
<SheetContent className="flex flex-col gap-4 sm:max-w-md">
|
||||
<SheetHeader>
|
||||
<SheetTitle>Доступ к серверу</SheetTitle>
|
||||
<SheetDescription>
|
||||
{vps ? `${vps.ip || vps.dns || vps.id}` : ''}
|
||||
{' — share оставляет запись здесь; assign переносит в другое пространство.'}
|
||||
</SheetDescription>
|
||||
</SheetHeader>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label>Целевое пространство</Label>
|
||||
<Select value={toSpaceId} onValueChange={(v) => setToSpaceId(v ?? '')}>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder="Выберите пространство" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{targets.map((s) => (
|
||||
<SelectItem key={s.id} value={s.id}>
|
||||
{s.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<Label>Права (для share)</Label>
|
||||
<Select
|
||||
value={permission}
|
||||
onValueChange={(v) => setPermission((v as 'read' | 'write') ?? 'read')}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="read">read</SelectItem>
|
||||
<SelectItem value="write">write</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
<SheetFooter className="flex-col gap-2 sm:flex-col">
|
||||
<Button
|
||||
disabled={!toSpaceId || !vps || shareMutation.isPending}
|
||||
onClick={() => shareMutation.mutate()}
|
||||
>
|
||||
Share (ACL)
|
||||
</Button>
|
||||
<Button
|
||||
variant="outline"
|
||||
disabled={!toSpaceId || !vps || assignMutation.isPending}
|
||||
onClick={() => {
|
||||
if (
|
||||
!window.confirm(
|
||||
'Перенести сервер? Привязка к аккаунту провайдера будет сброшена.',
|
||||
)
|
||||
) {
|
||||
return
|
||||
}
|
||||
assignMutation.mutate()
|
||||
}}
|
||||
>
|
||||
Assign (перенос)
|
||||
</Button>
|
||||
</SheetFooter>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user