import { useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Loader2, Save } from 'lucide-react'; import { matchPipelines, type PipelineMatchItem } from './matchPipeline'; interface JobRoleCreateDialogProps { open: boolean; onOpenChange: (open: boolean) => void; pipelines: PipelineMatchItem[]; saving: boolean; name: string; code: string; pattern: string; role: string; description: string; onNameChange: (v: string) => void; onCodeChange: (v: string) => void; onPatternChange: (v: string) => void; onRoleChange: (v: string) => void; onDescriptionChange: (v: string) => void; onSubmit: () => void; } // 新建 Job 权限角色弹窗 // Logan.Li export function JobRoleCreateDialog({ open, onOpenChange, pipelines, saving, name, code, pattern, role, description, onNameChange, onCodeChange, onPatternChange, onRoleChange, onDescriptionChange, onSubmit, }: JobRoleCreateDialogProps) { const { t } = useTranslation(); const preview = useMemo(() => matchPipelines(pattern, pipelines), [pattern, pipelines]); const patternHint = useMemo(() => { if (!pattern.trim()) return t('rbac.jobRole.patternHint.empty'); try { // eslint-disable-next-line no-new new RegExp(pattern); return preview.length > 0 ? t('rbac.jobRole.patternHint.matched', { count: preview.length }) : t('rbac.jobRole.patternHint.noMatch'); } catch { return t('rbac.jobRole.patternHint.syntaxError'); } }, [pattern, preview.length, t]); return ( {t('rbac.jobRole.newTitle')} {t('rbac.jobRole.desc')}
onNameChange(e.target.value)} placeholder={t('rbac.jobRole.placeholder.name')} className="h-8 text-sm dg-input" />
onCodeChange(e.target.value)} placeholder={t('rbac.jobRole.placeholder.code')} className="h-8 text-sm font-mono dg-input" />
onPatternChange(e.target.value)} placeholder="^cex-.* 或 ^api-server$" className="h-8 text-sm font-mono dg-input" />

{patternHint}

onDescriptionChange(e.target.value)} placeholder={t('rbac.jobRole.placeholder.description')} className="h-8 text-sm dg-input" />
); }