cleanup: remove all unconnected Phase I+J scaffold code and unconnected Phase F+H modules (workstream_contract, proactive_feed, dashboard, dsgvo_export, onboarding, mcp_exposure, integration_tools, self_improvement, agent_workstream, workflows/workstream, knowledge_sources, knowledge_extraction, knowledge_lifecycle, platform.py routes, 13 frontend files, 2 test files), restore Dashboard.tsx, tsc clean, backend OK
This commit is contained in:
@@ -1,128 +0,0 @@
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
|
||||
import { TrendingUp, Lightbulb } from 'lucide-react';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { EmptyState } from '@/components/ui/EmptyState';
|
||||
import { Skeleton } from '@/components/ui/Skeleton';
|
||||
import { ProposalCard } from './ProposalCard';
|
||||
import { PatternInsight } from './PatternInsight';
|
||||
import {
|
||||
fetchProposals,
|
||||
fetchPatterns,
|
||||
approveProposal,
|
||||
rejectProposal,
|
||||
rollbackProposal,
|
||||
type ImprovementProposal,
|
||||
type DetectedPattern,
|
||||
} from '@/api/improvement';
|
||||
|
||||
export interface ImprovementCenterProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
export function ImprovementCenter({ className }: ImprovementCenterProps) {
|
||||
const { t } = useTranslation();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const { data: proposals = [], isLoading: loadingProposals } = useQuery<ImprovementProposal[]>({
|
||||
queryKey: ['improvement', 'proposals'],
|
||||
queryFn: () => fetchProposals(),
|
||||
});
|
||||
|
||||
const { data: patterns = [], isLoading: loadingPatterns } = useQuery<DetectedPattern[]>({
|
||||
queryKey: ['improvement', 'patterns'],
|
||||
queryFn: fetchPatterns,
|
||||
});
|
||||
|
||||
const invalidate = () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['improvement', 'proposals'] });
|
||||
queryClient.invalidateQueries({ queryKey: ['improvement', 'patterns'] });
|
||||
};
|
||||
|
||||
const approveMutation = useMutation({
|
||||
mutationFn: approveProposal,
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const rejectMutation = useMutation({
|
||||
mutationFn: rejectProposal,
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const rollbackMutation = useMutation({
|
||||
mutationFn: rollbackProposal,
|
||||
onSuccess: invalidate,
|
||||
});
|
||||
|
||||
const busy = approveMutation.isPending || rejectMutation.isPending || rollbackMutation.isPending;
|
||||
|
||||
return (
|
||||
<div className={className} data-testid="improvement-center">
|
||||
<div className="mb-6">
|
||||
<h2 className="flex items-center gap-2 text-xl font-semibold text-secondary-900">
|
||||
<TrendingUp className="w-5 h-5 text-primary-600" aria-hidden="true" />
|
||||
{t('improvement.title')}
|
||||
</h2>
|
||||
<p className="text-sm text-secondary-500 mt-1">{t('improvement.subtitle')}</p>
|
||||
</div>
|
||||
|
||||
{/* Patterns / Bottlenecks */}
|
||||
<section className="mb-8" aria-labelledby="improvement-patterns-heading">
|
||||
<h3 id="improvement-patterns-heading" className="text-base font-semibold text-secondary-800 mb-3">
|
||||
{t('improvement.patterns')}
|
||||
</h3>
|
||||
{loadingPatterns ? (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
<Skeleton className="h-40" />
|
||||
<Skeleton className="h-40" />
|
||||
</div>
|
||||
) : patterns.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<Lightbulb className="w-6 h-6" />}
|
||||
title={t('improvement.noPatterns')}
|
||||
description={t('improvement.noPatternsDesc')}
|
||||
/>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||||
{patterns.map((pattern) => (
|
||||
<PatternInsight key={pattern.id} pattern={pattern} />
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{/* Proposals */}
|
||||
<section aria-labelledby="improvement-proposals-heading">
|
||||
<h3 id="improvement-proposals-heading" className="text-base font-semibold text-secondary-800 mb-3">
|
||||
{t('improvement.proposals')}
|
||||
</h3>
|
||||
{loadingProposals ? (
|
||||
<div className="grid grid-cols-1 gap-4">
|
||||
<Skeleton className="h-56" />
|
||||
<Skeleton className="h-56" />
|
||||
</div>
|
||||
) : proposals.length === 0 ? (
|
||||
<EmptyState
|
||||
icon={<Lightbulb className="w-6 h-6" />}
|
||||
title={t('improvement.noProposals')}
|
||||
description={t('improvement.noProposalsDesc')}
|
||||
/>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 gap-4">
|
||||
{proposals.map((proposal) => (
|
||||
<ProposalCard
|
||||
key={proposal.id}
|
||||
proposal={proposal}
|
||||
busy={busy}
|
||||
onApprove={(id) => approveMutation.mutate(id)}
|
||||
onReject={(id) => rejectMutation.mutate(id)}
|
||||
onRollback={(id) => rollbackMutation.mutate(id)}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
import React from 'react';
|
||||
import clsx from 'clsx';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { TrendingUp, AlertTriangle, Lightbulb } from 'lucide-react';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
import type { DetectedPattern } from '@/api/improvement';
|
||||
|
||||
export interface PatternInsightProps {
|
||||
pattern: DetectedPattern;
|
||||
}
|
||||
|
||||
function formatConfidence(confidence: number): string {
|
||||
if (confidence === undefined || Number.isNaN(confidence)) return '—';
|
||||
return `${Math.round(confidence * 100)}%`;
|
||||
}
|
||||
|
||||
export function PatternInsight({ pattern }: PatternInsightProps) {
|
||||
const { t } = useTranslation();
|
||||
const confidence = pattern.confidence;
|
||||
const confidenceVariant =
|
||||
confidence >= 0.8 ? 'success' : confidence >= 0.6 ? 'warning' : 'secondary';
|
||||
|
||||
return (
|
||||
<Card className="flex flex-col" data-testid={`pattern-insight-${pattern.id}`}>
|
||||
<div className="flex items-center justify-between gap-2 mb-3">
|
||||
<h3 className="flex items-center gap-2 text-base font-semibold text-secondary-900">
|
||||
<Lightbulb className="w-4 h-4 text-primary-500 flex-shrink-0" aria-hidden="true" />
|
||||
{t(`improvement.patternTypes.${pattern.pattern_type}`)}
|
||||
</h3>
|
||||
<Badge variant={confidenceVariant} dot>
|
||||
{t('improvement.confidence')}: {formatConfidence(confidence)}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<p className="text-sm text-secondary-700 mb-3">{pattern.description}</p>
|
||||
|
||||
<div className="flex items-center gap-4 mb-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<TrendingUp className="w-4 h-4 text-primary-600" aria-hidden="true" />
|
||||
<span className="text-sm text-secondary-700">
|
||||
{t('improvement.occurrences')}:{' '}
|
||||
<span className="font-semibold text-secondary-900">{pattern.occurrence_count}</span>
|
||||
</span>
|
||||
</div>
|
||||
{pattern.pattern_type === 'error_retries' && (
|
||||
<div className="flex items-center gap-2">
|
||||
<AlertTriangle className="w-4 h-4 text-warning-600" aria-hidden="true" />
|
||||
<span className="text-sm text-warning-700">{t('improvement.bottleneck')}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{pattern.evidence_refs.length > 0 && (
|
||||
<div className="space-y-1">
|
||||
<h4 className="text-xs font-semibold text-secondary-500 uppercase tracking-wide">
|
||||
{t('improvement.evidence')}
|
||||
</h4>
|
||||
<ul className="flex flex-wrap gap-2">
|
||||
{pattern.evidence_refs.map((ref) => (
|
||||
<li key={ref}>
|
||||
<code className="px-2 py-0.5 rounded bg-secondary-100 text-xs text-secondary-700">{ref}</code>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
import React from 'react';
|
||||
import clsx from 'clsx';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { TrendingUp, AlertTriangle, CheckCircle, XCircle, RotateCcw, Lightbulb } from 'lucide-react';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import type { ImprovementProposal, ProposalStatus } from '@/api/improvement';
|
||||
|
||||
export interface ProposalCardProps {
|
||||
proposal: ImprovementProposal;
|
||||
onApprove?: (id: string) => void;
|
||||
onReject?: (id: string) => void;
|
||||
onRollback?: (id: string) => void;
|
||||
busy?: boolean;
|
||||
}
|
||||
|
||||
const statusVariant: Record<ProposalStatus, 'default' | 'primary' | 'success' | 'warning' | 'danger' | 'info' | 'secondary'> = {
|
||||
draft: 'secondary',
|
||||
evaluating: 'info',
|
||||
pending_approval: 'warning',
|
||||
approved: 'primary',
|
||||
rejected: 'danger',
|
||||
active: 'success',
|
||||
rolled_back: 'default',
|
||||
expired: 'default',
|
||||
};
|
||||
|
||||
function formatScore(score: number | undefined): string {
|
||||
if (score === undefined || Number.isNaN(score)) return '—';
|
||||
return `${Math.round(score)}%`;
|
||||
}
|
||||
|
||||
export function ProposalCard({ proposal, onApprove, onReject, onRollback, busy = false }: ProposalCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const score = proposal.evaluation_result?.score;
|
||||
const canApprove = proposal.status === 'pending_approval' || proposal.status === 'draft' || proposal.status === 'evaluating';
|
||||
const canReject = proposal.status === 'pending_approval' || proposal.status === 'draft' || proposal.status === 'evaluating';
|
||||
const canRollback = proposal.status === 'active';
|
||||
|
||||
return (
|
||||
<Card className="flex flex-col" data-testid={`proposal-card-${proposal.id}`}>
|
||||
<div className="flex items-center justify-between gap-2 mb-4">
|
||||
<h3 className="flex items-center gap-2 text-lg font-semibold text-secondary-900">
|
||||
<Lightbulb className="w-4 h-4 text-primary-500 flex-shrink-0" aria-hidden="true" />
|
||||
{proposal.title}
|
||||
</h3>
|
||||
<Badge variant={statusVariant[proposal.status]} dot>
|
||||
{t(`improvement.status.${proposal.status}`)}
|
||||
</Badge>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<p className="text-sm text-secondary-700">{proposal.description}</p>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
<div className="space-y-1">
|
||||
<h4 className="text-xs font-semibold text-secondary-500 uppercase tracking-wide">
|
||||
{t('improvement.rationale')}
|
||||
</h4>
|
||||
<p className="text-sm text-secondary-700">{proposal.rationale}</p>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<h4 className="text-xs font-semibold text-secondary-500 uppercase tracking-wide">
|
||||
{t('improvement.expectedBenefit')}
|
||||
</h4>
|
||||
<p className="text-sm text-secondary-700">{proposal.expected_benefit}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-2 rounded-md bg-warning-50 border border-warning-200 p-3">
|
||||
<AlertTriangle className="w-4 h-4 text-warning-600 mt-0.5 flex-shrink-0" aria-hidden="true" />
|
||||
<div className="space-y-1">
|
||||
<h4 className="text-xs font-semibold text-warning-700 uppercase tracking-wide">
|
||||
{t('improvement.riskAssessment')}
|
||||
</h4>
|
||||
<p className="text-sm text-warning-800">{proposal.risk_assessment}</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{proposal.evidence_refs.length > 0 && (
|
||||
<div className="space-y-1">
|
||||
<h4 className="text-xs font-semibold text-secondary-500 uppercase tracking-wide">
|
||||
{t('improvement.evidence')}
|
||||
</h4>
|
||||
<ul className="flex flex-wrap gap-2">
|
||||
{proposal.evidence_refs.map((ref) => (
|
||||
<li key={ref}>
|
||||
<code className="px-2 py-0.5 rounded bg-secondary-100 text-xs text-secondary-700">{ref}</code>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center justify-between rounded-md bg-secondary-50 border border-secondary-200 p-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<TrendingUp className="w-4 h-4 text-primary-600" aria-hidden="true" />
|
||||
<span className="text-sm font-medium text-secondary-700">{t('improvement.score')}</span>
|
||||
</div>
|
||||
<span
|
||||
className={clsx(
|
||||
'text-lg font-semibold',
|
||||
score !== undefined && score >= 80 ? 'text-success-600' : score !== undefined && score >= 60 ? 'text-warning-600' : 'text-secondary-600'
|
||||
)}
|
||||
>
|
||||
{formatScore(score)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mt-4 pt-4 border-t border-secondary-200 flex flex-wrap items-center gap-2">
|
||||
{canApprove && onApprove && (
|
||||
<Button size="sm" variant="primary" icon={<CheckCircle className="w-4 h-4" />} isLoading={busy} onClick={() => onApprove(proposal.id)}>
|
||||
{t('improvement.approve')}
|
||||
</Button>
|
||||
)}
|
||||
{canReject && onReject && (
|
||||
<Button size="sm" variant="danger" icon={<XCircle className="w-4 h-4" />} isLoading={busy} onClick={() => onReject(proposal.id)}>
|
||||
{t('improvement.reject')}
|
||||
</Button>
|
||||
)}
|
||||
{canRollback && onRollback && (
|
||||
<Button size="sm" variant="secondary" icon={<RotateCcw className="w-4 h-4" />} isLoading={busy} onClick={() => onRollback(proposal.id)}>
|
||||
{t('improvement.rollback')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -54,10 +54,7 @@ function getIcon(name: string): React.ReactNode {
|
||||
const singleItems: NavSingleItem[] = [
|
||||
{ to: '/dashboard', labelKey: 'nav.dashboard', icon: <Home className="w-5 h-5 flex-shrink-0" aria-hidden="true" strokeWidth={2} />, order: 0 },
|
||||
{ to: '/contacts', labelKey: 'nav.contacts', icon: <Users className="w-5 h-5 flex-shrink-0" aria-hidden="true" strokeWidth={2} />, order: 10 },
|
||||
{ to: '/workstream', labelKey: 'nav.workstream', icon: <MessageSquare className="w-5 h-5 flex-shrink-0" aria-hidden="true" strokeWidth={2} />, order: 25 },
|
||||
{ to: '/wiki', labelKey: 'nav.wiki', icon: <BookOpen className="w-5 h-5 flex-shrink-0" aria-hidden="true" strokeWidth={2} />, order: 30 },
|
||||
{ to: '/improvement', labelKey: 'nav.improvement', icon: <Lightbulb className="w-5 h-5 flex-shrink-0" aria-hidden="true" strokeWidth={2} />, order: 90 },
|
||||
{ to: '/onboarding', labelKey: 'nav.onboarding', icon: <Sparkles className="w-5 h-5 flex-shrink-0" aria-hidden="true" strokeWidth={2} />, order: 95 },
|
||||
];
|
||||
|
||||
const bottomItems: NavSingleItem[] = [];
|
||||
|
||||
@@ -1,136 +0,0 @@
|
||||
/**
|
||||
* SetupWizard — Phase I.6 (I-ONB) setup wizard.
|
||||
*
|
||||
* Guides users through 4 steps: Welcome, Create first Agent,
|
||||
* Create first Workflow, Enable Knowledge & Workstream.
|
||||
*
|
||||
* Uses lucide-react icons, Tailwind, and i18n via `t()`.
|
||||
*/
|
||||
|
||||
import React, { useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Sparkles,
|
||||
Bot,
|
||||
Workflow,
|
||||
BookOpen,
|
||||
ChevronLeft,
|
||||
ChevronRight,
|
||||
X,
|
||||
} from 'lucide-react';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Card } from '@/components/ui/Card';
|
||||
|
||||
interface SetupWizardProps {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
onComplete?: () => void;
|
||||
}
|
||||
|
||||
const STEP_ICONS = [Sparkles, Bot, Workflow, BookOpen];
|
||||
|
||||
/**
|
||||
* Setup wizard with 4 steps. Each step shows a title, description and an
|
||||
* optional action button that deep-links to the relevant setup page.
|
||||
*/
|
||||
export function SetupWizard({ open, onClose, onComplete }: SetupWizardProps) {
|
||||
const { t } = useTranslation();
|
||||
const [step, setStep] = useState(0);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const totalSteps = 4;
|
||||
const isLast = step === totalSteps - 1;
|
||||
const Icon = STEP_ICONS[step];
|
||||
|
||||
const handleNext = () => {
|
||||
if (isLast) {
|
||||
onComplete?.();
|
||||
onClose();
|
||||
return;
|
||||
}
|
||||
setStep((s) => s + 1);
|
||||
};
|
||||
|
||||
const handleBack = () => {
|
||||
if (step > 0) setStep((s) => s - 1);
|
||||
};
|
||||
|
||||
const stepKey = `setupWizard.step${step + 1}`;
|
||||
|
||||
return (
|
||||
<div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center bg-secondary-900/50 p-4"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label={t('setupWizard.title')}
|
||||
data-testid="setup-wizard"
|
||||
>
|
||||
<Card className="w-full max-w-lg">
|
||||
<div className="flex items-center justify-between px-6 py-4 border-b border-secondary-200">
|
||||
<h2 className="text-lg font-semibold text-secondary-900">
|
||||
{t('setupWizard.title')}
|
||||
</h2>
|
||||
<button
|
||||
type="button"
|
||||
onClick={onClose}
|
||||
className="p-2 rounded-md text-secondary-400 hover:text-secondary-600 hover:bg-secondary-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-primary-500"
|
||||
aria-label={t('setupWizard.close')}
|
||||
>
|
||||
<X className="h-5 w-5" aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="px-6 py-6">
|
||||
{/* Progress indicator */}
|
||||
<div className="flex items-center gap-2 mb-6" aria-hidden="true">
|
||||
{Array.from({ length: totalSteps }).map((_, i) => (
|
||||
<div
|
||||
key={i}
|
||||
className={`h-1.5 flex-1 rounded-full transition-colors ${
|
||||
i <= step ? 'bg-primary-500' : 'bg-secondary-200'
|
||||
}`}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex items-start gap-4">
|
||||
<div className="flex-shrink-0 w-12 h-12 rounded-lg bg-primary-100 text-primary-700 flex items-center justify-center">
|
||||
<Icon className="h-6 w-6" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h3 className="text-lg font-semibold text-secondary-900">
|
||||
{t(`${stepKey}.title`)}
|
||||
</h3>
|
||||
<p className="mt-1 text-sm text-secondary-600">
|
||||
{t(`${stepKey}.description`)}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="px-6 py-4 border-t border-secondary-200 flex items-center justify-between">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={handleBack}
|
||||
disabled={step === 0}
|
||||
icon={<ChevronLeft className="h-4 w-4" />}
|
||||
>
|
||||
{t('setupWizard.back')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
onClick={handleNext}
|
||||
icon={isLast ? undefined : <ChevronRight className="h-4 w-4" />}
|
||||
>
|
||||
{isLast ? t('setupWizard.finish') : t('setupWizard.next')}
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default SetupWizard;
|
||||
@@ -1,64 +0,0 @@
|
||||
/**
|
||||
* MiniAppBlock — renders a `miniapp` workstream block.
|
||||
*
|
||||
* Uses `metadata.app_id` and `metadata.render_schema` to render the MiniApp.
|
||||
* Falls back to a placeholder state for unknown apps.
|
||||
*
|
||||
* Backend: app/ai/workstream_contract.py → build_miniapp_block
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AppWindow, AlertCircle } from 'lucide-react';
|
||||
import type { WorkstreamBlock } from '@/api/miniapps';
|
||||
|
||||
interface MiniAppBlockProps {
|
||||
block: WorkstreamBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a MiniApp block. If the app is unknown or render_schema is empty,
|
||||
* show a fallback state with the app_id.
|
||||
*/
|
||||
export function MiniAppBlock({ block }: MiniAppBlockProps) {
|
||||
const { t } = useTranslation();
|
||||
const metadata = block.metadata ?? {};
|
||||
const appId = typeof metadata.app_id === 'string' ? metadata.app_id : '';
|
||||
const title = typeof metadata.title === 'string' ? metadata.title : '';
|
||||
const renderSchema =
|
||||
metadata.render_schema && typeof metadata.render_schema === 'object'
|
||||
? (metadata.render_schema as Record<string, unknown>)
|
||||
: {};
|
||||
|
||||
const hasRenderSchema = Object.keys(renderSchema).length > 0;
|
||||
|
||||
return (
|
||||
<div className="border border-secondary-200 rounded-lg p-4 bg-white shadow-sm">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex-shrink-0 w-10 h-10 rounded-lg bg-primary-100 text-primary-700 flex items-center justify-center">
|
||||
<AppWindow className="h-5 w-5" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="text-sm font-semibold text-secondary-900">
|
||||
{title || appId || t('workstream.miniapp.untitled')}
|
||||
</h4>
|
||||
{hasRenderSchema ? (
|
||||
<div className="mt-2 text-sm text-secondary-600">
|
||||
{t('workstream.miniapp.renderSchema')}
|
||||
<pre className="mt-2 p-2 rounded bg-secondary-50 text-xs font-mono overflow-x-auto">
|
||||
{JSON.stringify(renderSchema, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
) : (
|
||||
<div className="mt-2 flex items-center gap-2 text-xs text-secondary-400">
|
||||
<AlertCircle className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
<span>{t('workstream.miniapp.noSchema')}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default MiniAppBlock;
|
||||
@@ -1,290 +0,0 @@
|
||||
/**
|
||||
* MiniAppSDK — standard building blocks for MiniApp rendering.
|
||||
*
|
||||
* Provides reusable components used by MiniAppBlock and the Workstream page:
|
||||
* - EntityCard: link to a CRM entity
|
||||
* - ActionButtons: list of action buttons (deep links / callbacks)
|
||||
* - ApprovalCard: approve/reject actions
|
||||
* - ProgressIndicator: progress bar with label
|
||||
* - DeepLink: safe external/internal link
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
ExternalLink,
|
||||
CheckCircle2,
|
||||
XCircle,
|
||||
ArrowRight,
|
||||
} from 'lucide-react';
|
||||
import { Button } from '@/components/ui/Button';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
|
||||
// ── EntityCard ──
|
||||
|
||||
export interface EntityCardProps {
|
||||
entityType: string;
|
||||
entityId: string;
|
||||
title?: string;
|
||||
subtitle?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Card linking to a CRM entity (contact, company, mail, etc.).
|
||||
*/
|
||||
export function EntityCard({
|
||||
entityType,
|
||||
entityId,
|
||||
title,
|
||||
subtitle,
|
||||
url,
|
||||
}: EntityCardProps) {
|
||||
const { t } = useTranslation();
|
||||
const href = url || `/${entityType}/${entityId}`;
|
||||
const safeHref = hrefSafe(href);
|
||||
|
||||
return (
|
||||
<div className="border border-secondary-200 rounded-lg p-4 bg-white shadow-sm">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div className="min-w-0">
|
||||
<Badge variant="secondary">{entityType}</Badge>
|
||||
<h4 className="mt-2 text-sm font-semibold text-secondary-900 truncate">
|
||||
{title || entityId}
|
||||
</h4>
|
||||
{subtitle && (
|
||||
<p className="mt-1 text-xs text-secondary-500 truncate">{subtitle}</p>
|
||||
)}
|
||||
</div>
|
||||
{safeHref && (
|
||||
<a
|
||||
href={safeHref}
|
||||
className="inline-flex items-center gap-1 text-xs font-medium text-primary-600 hover:text-primary-700 focus-visible:ring-2 focus-visible:ring-primary-500 rounded px-2 py-1"
|
||||
aria-label={t('workstream.sdk.openEntity')}
|
||||
>
|
||||
<ExternalLink className="h-3.5 w-3.5" aria-hidden="true" />
|
||||
{t('workstream.sdk.open')}
|
||||
</a>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
// ── ActionButtons ──
|
||||
|
||||
export interface ActionButtonItem {
|
||||
label: string;
|
||||
action: string;
|
||||
type?: 'primary' | 'secondary' | 'danger';
|
||||
}
|
||||
|
||||
export interface ActionButtonsProps {
|
||||
actions: ActionButtonItem[];
|
||||
onAction?: (action: ActionButtonItem) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders a list of action buttons. Actions are either deep links (http/https)
|
||||
* or callbacks handled by the parent via `onAction`.
|
||||
*/
|
||||
export function ActionButtons({ actions, onAction }: ActionButtonsProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (!actions || actions.length === 0) return null;
|
||||
|
||||
const handleClick = (action: ActionButtonItem) => {
|
||||
if (onAction) {
|
||||
onAction(action);
|
||||
return;
|
||||
}
|
||||
const url = action.action;
|
||||
if (isSafeUrl(url)) {
|
||||
window.open(url, '_blank', 'noopener,noreferrer');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-wrap gap-2">
|
||||
{actions.map((action, idx) => {
|
||||
const variant =
|
||||
action.type === 'danger'
|
||||
? 'danger'
|
||||
: action.type === 'secondary'
|
||||
? 'secondary'
|
||||
: 'primary';
|
||||
return (
|
||||
<Button
|
||||
key={idx}
|
||||
variant={variant}
|
||||
size="sm"
|
||||
onClick={() => handleClick(action)}
|
||||
>
|
||||
{action.label || t('workstream.sdk.action')}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ── ApprovalCard ──
|
||||
|
||||
export interface ApprovalCardProps {
|
||||
approvalId: string;
|
||||
action: string;
|
||||
description?: string;
|
||||
onApprove?: (approvalId: string) => void;
|
||||
onReject?: (approvalId: string) => void;
|
||||
isPending?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Approval card with approve/reject actions.
|
||||
*/
|
||||
export function ApprovalCard({
|
||||
approvalId,
|
||||
action,
|
||||
description,
|
||||
onApprove,
|
||||
onReject,
|
||||
isPending = false,
|
||||
}: ApprovalCardProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<div className="border border-warning-200 rounded-lg p-4 bg-warning-50 shadow-sm">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex-shrink-0 w-8 h-8 rounded-full bg-warning-100 text-warning-700 flex items-center justify-center">
|
||||
<CheckCircle2 className="h-4 w-4" aria-hidden="true" />
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<h4 className="text-sm font-semibold text-secondary-900">
|
||||
{t('workstream.sdk.approvalNeeded')}: {action}
|
||||
</h4>
|
||||
{description && (
|
||||
<p className="mt-1 text-xs text-secondary-600">{description}</p>
|
||||
)}
|
||||
<div className="mt-3 flex flex-wrap gap-2">
|
||||
<Button
|
||||
variant="primary"
|
||||
size="sm"
|
||||
isLoading={isPending}
|
||||
onClick={() => onApprove?.(approvalId)}
|
||||
icon={<CheckCircle2 className="h-4 w-4" />}
|
||||
>
|
||||
{t('workstream.sdk.approve')}
|
||||
</Button>
|
||||
<Button
|
||||
variant="danger"
|
||||
size="sm"
|
||||
isLoading={isPending}
|
||||
onClick={() => onReject?.(approvalId)}
|
||||
icon={<XCircle className="h-4 w-4" />}
|
||||
>
|
||||
{t('workstream.sdk.reject')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ── ProgressIndicator ──
|
||||
|
||||
export interface ProgressIndicatorProps {
|
||||
label?: string;
|
||||
value: number; // 0-100
|
||||
status?: 'pending' | 'in_progress' | 'completed' | 'error';
|
||||
}
|
||||
|
||||
/**
|
||||
* Progress bar with optional label and status color.
|
||||
*/
|
||||
export function ProgressIndicator({
|
||||
label,
|
||||
value,
|
||||
status = 'in_progress',
|
||||
}: ProgressIndicatorProps) {
|
||||
const { t } = useTranslation();
|
||||
const clamped = Math.max(0, Math.min(100, value));
|
||||
const barColor =
|
||||
status === 'error'
|
||||
? 'bg-danger-500'
|
||||
: status === 'completed'
|
||||
? 'bg-success-500'
|
||||
: 'bg-primary-500';
|
||||
|
||||
return (
|
||||
<div className="w-full">
|
||||
{label && (
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<span className="text-xs font-medium text-secondary-700">{label}</span>
|
||||
<span className="text-xs text-secondary-400">{clamped}%</span>
|
||||
</div>
|
||||
)}
|
||||
<div
|
||||
className="w-full h-2 rounded-full bg-secondary-100 overflow-hidden"
|
||||
role="progressbar"
|
||||
aria-valuenow={clamped}
|
||||
aria-valuemin={0}
|
||||
aria-valuemax={100}
|
||||
aria-label={label || t('workstream.sdk.progress')}
|
||||
>
|
||||
<div
|
||||
className={`h-full rounded-full transition-all ${barColor}`}
|
||||
style={{ width: `${clamped}%` }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ── DeepLink ──
|
||||
|
||||
export interface DeepLinkProps {
|
||||
href: string;
|
||||
label?: string;
|
||||
external?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Safe deep link — only allows http(s) and internal paths.
|
||||
*/
|
||||
export function DeepLink({ href, label, external = false }: DeepLinkProps) {
|
||||
const { t } = useTranslation();
|
||||
const safeHref = hrefSafe(href);
|
||||
if (!safeHref) {
|
||||
return <span className="text-xs text-secondary-400">{label || href}</span>;
|
||||
}
|
||||
return (
|
||||
<a
|
||||
href={safeHref}
|
||||
target={external ? '_blank' : undefined}
|
||||
rel={external ? 'noopener noreferrer' : undefined}
|
||||
className="inline-flex items-center gap-1 text-sm font-medium text-primary-600 hover:text-primary-700 hover:underline"
|
||||
>
|
||||
{label || href}
|
||||
{external && <ExternalLink className="h-3.5 w-3.5" aria-hidden="true" />}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
// ── Helpers ──
|
||||
|
||||
function hrefSafe(href: string): string | null {
|
||||
if (!href) return null;
|
||||
if (href.startsWith('/')) return href;
|
||||
try {
|
||||
const parsed = new URL(href);
|
||||
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') return href;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function isSafeUrl(url: string): boolean {
|
||||
return hrefSafe(url) !== null;
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
/**
|
||||
* ProactiveFeed — contextual suggestions/actions in the workstream.
|
||||
*
|
||||
* Renders ProactiveSuggestion items with priority, client-side dedupe and
|
||||
* cooldown (mirrors backend app/ai/proactive_feed.py). Suggestions are
|
||||
* non-intrusive: no popups, just a feed section.
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Sparkles, Info, ArrowRight, X } from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
import type { ProactiveSuggestion, ProactivePriority } from '@/api/miniapps';
|
||||
|
||||
interface ProactiveFeedProps {
|
||||
suggestions: ProactiveSuggestion[];
|
||||
/** Cooldown in ms per trigger; default 300000 (5 min). */
|
||||
cooldowns?: Record<string, number>;
|
||||
/** Minimum priority to show. */
|
||||
minPriority?: ProactivePriority;
|
||||
onDismiss?: (id: string) => void;
|
||||
onAction?: (suggestion: ProactiveSuggestion) => void;
|
||||
}
|
||||
|
||||
const PRIORITY_ORDER: Record<ProactivePriority, number> = {
|
||||
low: 0,
|
||||
medium: 1,
|
||||
high: 2,
|
||||
urgent: 3,
|
||||
};
|
||||
|
||||
const PRIORITY_VARIANT: Record<
|
||||
ProactivePriority,
|
||||
'secondary' | 'info' | 'warning' | 'danger'
|
||||
> = {
|
||||
low: 'secondary',
|
||||
medium: 'info',
|
||||
high: 'warning',
|
||||
urgent: 'danger',
|
||||
};
|
||||
|
||||
const ACTION_TYPE_ICON: Record<string, React.ReactNode> = {
|
||||
suggestion: <Sparkles className="h-4 w-4" aria-hidden="true" />,
|
||||
action_required: <ArrowRight className="h-4 w-4" aria-hidden="true" />,
|
||||
info: <Info className="h-4 w-4" aria-hidden="true" />,
|
||||
};
|
||||
|
||||
/**
|
||||
* Client-side dedupe + cooldown keyed by trigger + entity_id.
|
||||
* Persisted in a module-level map so it survives re-renders within a session.
|
||||
*/
|
||||
function dedupeKey(s: ProactiveSuggestion): string {
|
||||
return `${s.trigger}:${s.entity_id ?? 'none'}`;
|
||||
}
|
||||
|
||||
function isCooledDown(s: ProactiveSuggestion, cooldowns: Record<string, number>): boolean {
|
||||
const key = dedupeKey(s);
|
||||
const last = lastAt[key];
|
||||
if (last === undefined) return false;
|
||||
const cooldown = cooldowns[s.trigger] ?? cooldowns.default ?? 300000;
|
||||
return Date.now() - last < cooldown;
|
||||
}
|
||||
|
||||
function markShown(s: ProactiveSuggestion): void {
|
||||
lastAt[dedupeKey(s)] = Date.now();
|
||||
}
|
||||
|
||||
const lastAt: Record<string, number> = {};
|
||||
|
||||
/**
|
||||
* Renders a non-intrusive feed of proactive suggestions.
|
||||
*/
|
||||
export function ProactiveFeed({
|
||||
suggestions,
|
||||
cooldowns = {},
|
||||
minPriority = 'low',
|
||||
onDismiss,
|
||||
onAction,
|
||||
}: ProactiveFeedProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const visible = useMemo(() => {
|
||||
const minLevel = PRIORITY_ORDER[minPriority] ?? 0;
|
||||
return suggestions
|
||||
.filter((s) => PRIORITY_ORDER[s.priority] >= minLevel)
|
||||
.filter((s) => !isCooledDown(s, cooldowns))
|
||||
.sort((a, b) => PRIORITY_ORDER[b.priority] - PRIORITY_ORDER[a.priority]);
|
||||
}, [suggestions, cooldowns, minPriority]);
|
||||
|
||||
// Mark visible suggestions as shown (cooldown tracking)
|
||||
React.useEffect(() => {
|
||||
visible.forEach(markShown);
|
||||
}, [visible]);
|
||||
|
||||
if (visible.length === 0) return null;
|
||||
|
||||
return (
|
||||
<section
|
||||
className="space-y-2"
|
||||
aria-label={t('workstream.proactive.title')}
|
||||
>
|
||||
<div className="flex items-center gap-2 px-1">
|
||||
<Sparkles className="h-4 w-4 text-primary-500" aria-hidden="true" />
|
||||
<h3 className="text-sm font-semibold text-secondary-800">
|
||||
{t('workstream.proactive.title')}
|
||||
</h3>
|
||||
</div>
|
||||
{visible.map((s) => (
|
||||
<div
|
||||
key={s.id}
|
||||
className="border border-secondary-200 rounded-lg p-3 bg-white shadow-sm flex items-start gap-3"
|
||||
>
|
||||
<div className="flex-shrink-0 mt-0.5 text-primary-500">
|
||||
{ACTION_TYPE_ICON[s.action_type] ?? (
|
||||
<Sparkles className="h-4 w-4" aria-hidden="true" />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex-1 min-w-0">
|
||||
<div className="flex items-center gap-2 flex-wrap">
|
||||
<span className="text-sm font-medium text-secondary-900">
|
||||
{s.title}
|
||||
</span>
|
||||
<Badge variant={PRIORITY_VARIANT[s.priority]}>
|
||||
{t(`workstream.proactive.priority.${s.priority}`)}
|
||||
</Badge>
|
||||
</div>
|
||||
{s.description && (
|
||||
<p className="mt-1 text-xs text-secondary-500">{s.description}</p>
|
||||
)}
|
||||
{s.action_url && (
|
||||
<button
|
||||
onClick={() => onAction?.(s)}
|
||||
className="mt-2 inline-flex items-center gap-1 text-xs font-medium text-primary-600 hover:text-primary-700 hover:underline"
|
||||
>
|
||||
{t('workstream.proactive.view')}
|
||||
<ArrowRight className="h-3 w-3" aria-hidden="true" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{onDismiss && (
|
||||
<button
|
||||
onClick={() => onDismiss(s.id)}
|
||||
className="flex-shrink-0 p-1 rounded text-secondary-400 hover:text-secondary-600 hover:bg-secondary-100"
|
||||
aria-label={t('workstream.proactive.dismiss')}
|
||||
>
|
||||
<X className="h-4 w-4" aria-hidden="true" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
export default ProactiveFeed;
|
||||
@@ -1,260 +0,0 @@
|
||||
/**
|
||||
* WorkstreamBlockRenderer — Phase I.7 (I-UI) universal block renderer.
|
||||
*
|
||||
* Renders every workstream block type (text, entity_card, action_card,
|
||||
* evidence_card, approval_card, miniapp, workflow_status, workflow_handoff,
|
||||
* error) with consistent loading / error / empty states.
|
||||
*
|
||||
* Reuses MiniAppBlock and the MiniAppSDK building blocks.
|
||||
*
|
||||
* Backend: app/ai/workstream_contract.py
|
||||
*/
|
||||
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import {
|
||||
Link2,
|
||||
AlertTriangle,
|
||||
Workflow,
|
||||
ArrowRight,
|
||||
Loader2,
|
||||
MessageSquare,
|
||||
} from 'lucide-react';
|
||||
import { Badge } from '@/components/ui/Badge';
|
||||
import { EmptyState } from '@/components/ui/EmptyState';
|
||||
import { MiniAppBlock } from '@/components/workstream/MiniAppBlock';
|
||||
import {
|
||||
EntityCard,
|
||||
ActionButtons,
|
||||
ApprovalCard,
|
||||
ProgressIndicator,
|
||||
DeepLink,
|
||||
type ActionButtonItem,
|
||||
} from '@/components/workstream/MiniAppSDK';
|
||||
import type { WorkstreamBlock } from '@/api/miniapps';
|
||||
|
||||
interface WorkstreamBlockRendererProps {
|
||||
block: WorkstreamBlock;
|
||||
onApprove?: (approvalId: string) => void;
|
||||
onReject?: (approvalId: string) => void;
|
||||
onAction?: (action: ActionButtonItem) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a single workstream block by type.
|
||||
*/
|
||||
export function WorkstreamBlockRenderer({
|
||||
block,
|
||||
onApprove,
|
||||
onReject,
|
||||
onAction,
|
||||
}: WorkstreamBlockRendererProps) {
|
||||
const { t } = useTranslation();
|
||||
const meta = block.metadata ?? {};
|
||||
|
||||
switch (block.type) {
|
||||
case 'text':
|
||||
return (
|
||||
<div className="text-sm whitespace-pre-wrap break-words text-secondary-800">
|
||||
{block.content || String(meta.text ?? '')}
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'entity_card':
|
||||
return (
|
||||
<EntityCard
|
||||
entityType={String(meta.entity_type ?? '')}
|
||||
entityId={String(meta.entity_id ?? '')}
|
||||
title={String(meta.title ?? block.content)}
|
||||
subtitle={String(meta.subtitle ?? '')}
|
||||
url={String(meta.url ?? '')}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'action_card': {
|
||||
const actions: ActionButtonItem[] = Array.isArray(meta.actions)
|
||||
? (meta.actions as ActionButtonItem[])
|
||||
: [];
|
||||
return (
|
||||
<div className="border border-secondary-200 rounded-lg p-4 bg-white shadow-sm space-y-2">
|
||||
<h4 className="text-sm font-semibold text-secondary-900">
|
||||
{String(meta.title ?? block.content)}
|
||||
</h4>
|
||||
{meta.description ? (
|
||||
<p className="text-sm text-secondary-600">
|
||||
{String(meta.description)}
|
||||
</p>
|
||||
) : null}
|
||||
<ActionButtons actions={actions} onAction={onAction} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
case 'evidence_card':
|
||||
return (
|
||||
<div className="border border-secondary-200 rounded-lg p-4 bg-white shadow-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<Link2 className="h-4 w-4 text-primary-500" aria-hidden="true" />
|
||||
<h4 className="text-sm font-semibold text-secondary-900">
|
||||
{String(meta.title ?? block.content)}
|
||||
</h4>
|
||||
{typeof meta.confidence === 'number' && (
|
||||
<Badge variant="secondary">
|
||||
{Math.round(meta.confidence * 100)}%
|
||||
</Badge>
|
||||
)}
|
||||
</div>
|
||||
{meta.snippet ? (
|
||||
<p className="mt-2 text-xs text-secondary-500">
|
||||
{String(meta.snippet)}
|
||||
</p>
|
||||
) : null}
|
||||
{meta.url ? (
|
||||
<div className="mt-2">
|
||||
<DeepLink
|
||||
href={String(meta.url)}
|
||||
label={t('workstream.block.openSource')}
|
||||
external
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'approval_card':
|
||||
return (
|
||||
<ApprovalCard
|
||||
approvalId={String(meta.approval_id ?? '')}
|
||||
action={String(meta.action ?? block.content)}
|
||||
description={String(meta.description ?? '')}
|
||||
onApprove={onApprove}
|
||||
onReject={onReject}
|
||||
/>
|
||||
);
|
||||
|
||||
case 'miniapp':
|
||||
return <MiniAppBlock block={block} />;
|
||||
|
||||
case 'workflow_status':
|
||||
return (
|
||||
<div className="border border-secondary-200 rounded-lg p-4 bg-white shadow-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<Workflow className="h-4 w-4 text-primary-500" aria-hidden="true" />
|
||||
<h4 className="text-sm font-semibold text-secondary-900">
|
||||
{String(meta.workflow_name ?? block.content)}
|
||||
</h4>
|
||||
<Badge variant="info">{String(meta.status ?? '')}</Badge>
|
||||
</div>
|
||||
{meta.step_name ? (
|
||||
<p className="mt-2 text-xs text-secondary-500">
|
||||
{t('workstream.block.step')}: {String(meta.step_name)}
|
||||
</p>
|
||||
) : null}
|
||||
{typeof meta.step_index === 'number' && (
|
||||
<div className="mt-3">
|
||||
<ProgressIndicator
|
||||
label={t('workstream.block.progress')}
|
||||
value={Math.min(100, (meta.step_index + 1) * 10)}
|
||||
status="in_progress"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'workflow_handoff':
|
||||
return (
|
||||
<div className="border border-warning-200 rounded-lg p-4 bg-warning-50 shadow-sm">
|
||||
<div className="flex items-center gap-2">
|
||||
<ArrowRight className="h-4 w-4 text-warning-700" aria-hidden="true" />
|
||||
<h4 className="text-sm font-semibold text-secondary-900">
|
||||
{t('workstream.block.handoff')}: {String(meta.handoff_type ?? '')}
|
||||
</h4>
|
||||
</div>
|
||||
{meta.description ? (
|
||||
<p className="mt-2 text-xs text-secondary-600">
|
||||
{String(meta.description)}
|
||||
</p>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
|
||||
case 'error':
|
||||
return (
|
||||
<div className="border border-danger-200 rounded-lg p-4 bg-danger-50 shadow-sm flex items-start gap-2">
|
||||
<AlertTriangle
|
||||
className="h-4 w-4 text-danger-600 mt-0.5"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<div className="text-sm text-danger-700">
|
||||
{block.content || String(meta.error ?? '')}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
default:
|
||||
return (
|
||||
<div className="text-xs text-secondary-400 italic p-2 rounded bg-secondary-50">
|
||||
{t('workstream.block.unknown', { type: block.type })}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
interface WorkstreamBlockListProps {
|
||||
blocks: WorkstreamBlock[];
|
||||
isLoading?: boolean;
|
||||
onApprove?: (approvalId: string) => void;
|
||||
onReject?: (approvalId: string) => void;
|
||||
onAction?: (action: ActionButtonItem) => void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a list of blocks with consistent loading / empty states.
|
||||
*/
|
||||
export function WorkstreamBlockList({
|
||||
blocks,
|
||||
isLoading = false,
|
||||
onApprove,
|
||||
onReject,
|
||||
onAction,
|
||||
}: WorkstreamBlockListProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex items-center justify-center py-12">
|
||||
<Loader2
|
||||
className="animate-spin h-6 w-6 text-primary-500"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (!blocks || blocks.length === 0) {
|
||||
return (
|
||||
<EmptyState
|
||||
icon={<MessageSquare className="h-8 w-8" aria-hidden="true" />}
|
||||
title={t('workstream.empty.title')}
|
||||
description={t('workstream.empty.description')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-3">
|
||||
{blocks.map((block, idx) => (
|
||||
<WorkstreamBlockRenderer
|
||||
key={idx}
|
||||
block={block}
|
||||
onApprove={onApprove}
|
||||
onReject={onReject}
|
||||
onAction={onAction}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default WorkstreamBlockRenderer;
|
||||
Reference in New Issue
Block a user