|
| 1 | +import React from 'react'; |
| 2 | +import { useNavigate } from 'react-router-dom'; |
| 3 | +import { |
| 4 | + Card, |
| 5 | + CardHeader, |
| 6 | + Text, |
| 7 | + Badge, |
| 8 | + Button |
| 9 | +} from '@fluentui/react-components'; |
| 10 | +import { |
| 11 | + Eye24Regular, |
| 12 | + Calendar24Regular, |
| 13 | + CheckmarkCircle24Regular, |
| 14 | + ErrorCircle24Regular, |
| 15 | + Clock24Regular |
| 16 | +} from '@fluentui/react-icons'; |
| 17 | +import { PlanWithSteps, PlanStatus } from '../models'; |
| 18 | +import { apiService } from '../api/apiService'; |
| 19 | +import '../styles/PlanList.css'; |
| 20 | + |
| 21 | +interface PlanListProps { |
| 22 | + /** Array of plans to display */ |
| 23 | + plans: PlanWithSteps[]; |
| 24 | + /** Optional loading state */ |
| 25 | + loading?: boolean; |
| 26 | + /** Optional empty state message */ |
| 27 | + emptyMessage?: string; |
| 28 | + /** Optional flag to show view button */ |
| 29 | + showViewButton?: boolean; |
| 30 | +} |
| 31 | + |
| 32 | +/** |
| 33 | + * Component to display a list of plans in a grid layout |
| 34 | + */ |
| 35 | +const PlanList: React.FC<PlanListProps> = ({ |
| 36 | + plans, |
| 37 | + loading = false, |
| 38 | + emptyMessage = "No plans found", |
| 39 | + showViewButton = true |
| 40 | +}) => { |
| 41 | + const navigate = useNavigate(); |
| 42 | + |
| 43 | + /** |
| 44 | + * Get badge color based on plan status |
| 45 | + */ |
| 46 | + const getPlanStatusColor = (status: PlanStatus): string => { |
| 47 | + switch (status) { |
| 48 | + case PlanStatus.COMPLETED: |
| 49 | + return 'success'; |
| 50 | + case PlanStatus.IN_PROGRESS: |
| 51 | + return 'brand'; |
| 52 | + case PlanStatus.FAILED: |
| 53 | + return 'danger'; |
| 54 | + default: |
| 55 | + return 'informative'; |
| 56 | + } |
| 57 | + }; |
| 58 | + |
| 59 | + /** |
| 60 | + * Get status icon based on plan status |
| 61 | + */ |
| 62 | + const getPlanStatusIcon = (status: PlanStatus): JSX.Element => { |
| 63 | + switch (status) { |
| 64 | + case PlanStatus.COMPLETED: |
| 65 | + return <CheckmarkCircle24Regular />; |
| 66 | + case PlanStatus.FAILED: |
| 67 | + return <ErrorCircle24Regular />; |
| 68 | + case PlanStatus.IN_PROGRESS: |
| 69 | + return <Clock24Regular />; |
| 70 | + default: |
| 71 | + return <Calendar24Regular />; |
| 72 | + } |
| 73 | + }; |
| 74 | + |
| 75 | + /** |
| 76 | + * Format status text for display |
| 77 | + */ |
| 78 | + const getStatusText = (status: PlanStatus): string => { |
| 79 | + return status.replace('_', ' ').toLowerCase(); |
| 80 | + }; |
| 81 | + |
| 82 | + /** |
| 83 | + * Navigate to plan details page |
| 84 | + */ |
| 85 | + const handleViewPlan = (planId: string) => { |
| 86 | + navigate(`/plan/${planId}`); |
| 87 | + }; |
| 88 | + |
| 89 | + /** |
| 90 | + * Format timestamp to readable date |
| 91 | + */ |
| 92 | + const formatDate = (timestamp: string): string => { |
| 93 | + return new Date(timestamp).toLocaleDateString('en-US', { |
| 94 | + year: 'numeric', |
| 95 | + month: 'short', |
| 96 | + day: 'numeric', |
| 97 | + hour: '2-digit', |
| 98 | + minute: '2-digit' |
| 99 | + }); |
| 100 | + }; |
| 101 | + |
| 102 | + // Show empty state if no plans |
| 103 | + if (!loading && plans.length === 0) { |
| 104 | + return ( |
| 105 | + <div className="plan-list-empty"> |
| 106 | + <Card> |
| 107 | + <div className="empty-content"> |
| 108 | + <Calendar24Regular className="empty-icon" /> |
| 109 | + <Text size={500} weight="semibold"> |
| 110 | + {emptyMessage} |
| 111 | + </Text> |
| 112 | + </div> |
| 113 | + </Card> |
| 114 | + </div> |
| 115 | + ); |
| 116 | + } |
| 117 | + |
| 118 | + return ( |
| 119 | + <div className="plan-list-container"> |
| 120 | + <div className="plan-list-grid"> |
| 121 | + {plans.map((plan) => { |
| 122 | + const completionPercentage = apiService.getPlanCompletionPercentage(plan); |
| 123 | + const stepsAwaitingFeedback = apiService.getStepsAwaitingFeedback(plan); |
| 124 | + |
| 125 | + return ( |
| 126 | + <Card key={plan.id} className="plan-list-card"> |
| 127 | + <CardHeader |
| 128 | + header={ |
| 129 | + <div className="plan-card-header"> |
| 130 | + <Text className="plan-goal" size={500} weight="semibold"> |
| 131 | + {plan.initial_goal} |
| 132 | + </Text> |
| 133 | + <div className="plan-badges"> |
| 134 | + <Badge |
| 135 | + className="status-badge" |
| 136 | + color={getPlanStatusColor(plan.overall_status)} |
| 137 | + appearance="filled" |
| 138 | + icon={getPlanStatusIcon(plan.overall_status)} |
| 139 | + > |
| 140 | + {getStatusText(plan.overall_status)} |
| 141 | + </Badge> |
| 142 | + {stepsAwaitingFeedback.length > 0 && ( |
| 143 | + <Badge |
| 144 | + className="feedback-badge" |
| 145 | + color="warning" |
| 146 | + appearance="filled" |
| 147 | + > |
| 148 | + {stepsAwaitingFeedback.length} awaiting feedback |
| 149 | + </Badge> |
| 150 | + )} |
| 151 | + </div> |
| 152 | + </div> |
| 153 | + } |
| 154 | + /> |
| 155 | + |
| 156 | + <div className="plan-card-content"> |
| 157 | + {plan.summary && ( |
| 158 | + <Text className="plan-summary"> |
| 159 | + {plan.summary} |
| 160 | + </Text> |
| 161 | + )} |
| 162 | + |
| 163 | + <div className="plan-progress"> |
| 164 | + <div className="progress-info"> |
| 165 | + <Text size={300}> |
| 166 | + Progress: {plan.completed} of {plan.total_steps} steps completed |
| 167 | + </Text> |
| 168 | + <Text size={300} weight="semibold"> |
| 169 | + {completionPercentage}% |
| 170 | + </Text> |
| 171 | + </div> |
| 172 | + <div className="progress-bar"> |
| 173 | + <div |
| 174 | + className="progress-fill" |
| 175 | + style={{ width: `${completionPercentage}%` }} |
| 176 | + /> |
| 177 | + </div> |
| 178 | + </div> |
| 179 | + |
| 180 | + <div className="plan-metadata"> |
| 181 | + <Text size={200} className="plan-session"> |
| 182 | + Session: {plan.session_id} |
| 183 | + </Text> |
| 184 | + <Text size={200} className="plan-date"> |
| 185 | + {formatDate(plan.timestamp)} |
| 186 | + </Text> |
| 187 | + </div> |
| 188 | + |
| 189 | + {showViewButton && ( |
| 190 | + <div className="plan-actions"> |
| 191 | + <Button |
| 192 | + appearance="primary" |
| 193 | + icon={<Eye24Regular />} |
| 194 | + onClick={() => handleViewPlan(plan.id)} |
| 195 | + > |
| 196 | + View Details |
| 197 | + </Button> |
| 198 | + </div> |
| 199 | + )} |
| 200 | + </div> |
| 201 | + </Card> |
| 202 | + ); |
| 203 | + })} |
| 204 | + </div> |
| 205 | + </div> |
| 206 | + ); |
| 207 | +}; |
| 208 | + |
| 209 | +export default PlanList; |
0 commit comments