|
| 1 | +import { useState } from 'react'; |
| 2 | +import { useActivities, useActivityDetail } from '../../hooks/useActivities'; |
| 3 | +import { LoadingSpinner } from '../common/LoadingSpinner'; |
| 4 | + |
| 5 | +export function ActivityList() { |
| 6 | + const { data, isLoading, error, refetch } = useActivities(); |
| 7 | + const [selectedActivity, setSelectedActivity] = useState<string | null>(null); |
| 8 | + const [filterTag, setFilterTag] = useState<string>('all'); |
| 9 | + |
| 10 | + // Get unique tags from all activities |
| 11 | + const allTags = data?.activities |
| 12 | + ? [...new Set(data.activities.flatMap(a => a.tags))] |
| 13 | + : []; |
| 14 | + |
| 15 | + // Filter activities by tag |
| 16 | + const filteredActivities = data?.activities.filter( |
| 17 | + a => filterTag === 'all' || a.tags.includes(filterTag) |
| 18 | + ) ?? []; |
| 19 | + |
| 20 | + return ( |
| 21 | + <div className="space-y-6"> |
| 22 | + <div className="flex items-center justify-between"> |
| 23 | + <div> |
| 24 | + <h1 className="text-2xl font-bold text-gray-100">Activities</h1> |
| 25 | + <p className="text-gray-400"> |
| 26 | + {data?.count ?? 0} registered activities |
| 27 | + </p> |
| 28 | + </div> |
| 29 | + <button |
| 30 | + onClick={() => refetch()} |
| 31 | + className="px-4 py-2 border border-dark-border text-gray-300 rounded-lg hover:bg-dark-hover" |
| 32 | + > |
| 33 | + Refresh |
| 34 | + </button> |
| 35 | + </div> |
| 36 | + |
| 37 | + {/* Tag Filter */} |
| 38 | + {allTags.length > 0 && ( |
| 39 | + <div className="flex flex-wrap gap-2"> |
| 40 | + <button |
| 41 | + onClick={() => setFilterTag('all')} |
| 42 | + className={`px-3 py-1 rounded-full text-sm transition-colors ${ |
| 43 | + filterTag === 'all' |
| 44 | + ? 'bg-blue-600 text-white' |
| 45 | + : 'bg-dark-card border border-dark-border text-gray-400 hover:text-gray-200' |
| 46 | + }`} |
| 47 | + > |
| 48 | + All |
| 49 | + </button> |
| 50 | + {allTags.map(tag => ( |
| 51 | + <button |
| 52 | + key={tag} |
| 53 | + onClick={() => setFilterTag(tag)} |
| 54 | + className={`px-3 py-1 rounded-full text-sm transition-colors ${ |
| 55 | + filterTag === tag |
| 56 | + ? 'bg-blue-600 text-white' |
| 57 | + : 'bg-dark-card border border-dark-border text-gray-400 hover:text-gray-200' |
| 58 | + }`} |
| 59 | + > |
| 60 | + {tag} |
| 61 | + </button> |
| 62 | + ))} |
| 63 | + </div> |
| 64 | + )} |
| 65 | + |
| 66 | + {isLoading && ( |
| 67 | + <div className="flex justify-center py-12"> |
| 68 | + <LoadingSpinner /> |
| 69 | + </div> |
| 70 | + )} |
| 71 | + |
| 72 | + {error && ( |
| 73 | + <div className="bg-red-900/30 text-red-400 p-4 rounded-lg border border-red-800"> |
| 74 | + Error loading activities: {error.message} |
| 75 | + </div> |
| 76 | + )} |
| 77 | + |
| 78 | + <div className="grid grid-cols-1 lg:grid-cols-3 gap-6"> |
| 79 | + {/* Activity List */} |
| 80 | + <div className="lg:col-span-2 space-y-3"> |
| 81 | + {filteredActivities.map((activity) => ( |
| 82 | + <button |
| 83 | + key={activity.name} |
| 84 | + onClick={() => setSelectedActivity(activity.name)} |
| 85 | + className={`w-full text-left bg-dark-card rounded-lg border p-4 transition-colors ${ |
| 86 | + selectedActivity === activity.name |
| 87 | + ? 'border-blue-600' |
| 88 | + : 'border-dark-border hover:border-dark-hover' |
| 89 | + }`} |
| 90 | + > |
| 91 | + <div className="flex items-start justify-between"> |
| 92 | + <div className="flex-1 min-w-0"> |
| 93 | + <h3 className="text-gray-100 font-semibold font-mono"> |
| 94 | + {activity.name} |
| 95 | + </h3> |
| 96 | + {activity.description && ( |
| 97 | + <p className="text-gray-400 text-sm mt-1"> |
| 98 | + {activity.description} |
| 99 | + </p> |
| 100 | + )} |
| 101 | + </div> |
| 102 | + {activity.supportsCompensation && ( |
| 103 | + <span className="ml-2 px-2 py-1 bg-orange-900/50 text-orange-400 text-xs rounded-full"> |
| 104 | + Compensatable |
| 105 | + </span> |
| 106 | + )} |
| 107 | + </div> |
| 108 | + {activity.tags.length > 0 && ( |
| 109 | + <div className="flex flex-wrap gap-1 mt-3"> |
| 110 | + {activity.tags.map(tag => ( |
| 111 | + <span |
| 112 | + key={tag} |
| 113 | + className="px-2 py-0.5 bg-dark-hover text-gray-400 text-xs rounded" |
| 114 | + > |
| 115 | + {tag} |
| 116 | + </span> |
| 117 | + ))} |
| 118 | + </div> |
| 119 | + )} |
| 120 | + </button> |
| 121 | + ))} |
| 122 | + |
| 123 | + {data && filteredActivities.length === 0 && ( |
| 124 | + <div className="bg-dark-card rounded-lg border border-dark-border p-12 text-center"> |
| 125 | + <p className="text-gray-500">No activities found with tag "{filterTag}".</p> |
| 126 | + </div> |
| 127 | + )} |
| 128 | + </div> |
| 129 | + |
| 130 | + {/* Activity Detail Panel */} |
| 131 | + <div className="lg:col-span-1"> |
| 132 | + {selectedActivity ? ( |
| 133 | + <ActivityDetailPanel activityName={selectedActivity} /> |
| 134 | + ) : ( |
| 135 | + <div className="bg-dark-card rounded-lg border border-dark-border p-6 text-center"> |
| 136 | + <p className="text-gray-500">Select an activity to view details</p> |
| 137 | + </div> |
| 138 | + )} |
| 139 | + </div> |
| 140 | + </div> |
| 141 | + </div> |
| 142 | + ); |
| 143 | +} |
| 144 | + |
| 145 | +function ActivityDetailPanel({ activityName }: { activityName: string }) { |
| 146 | + const { data, isLoading, error } = useActivityDetail(activityName); |
| 147 | + |
| 148 | + if (isLoading) { |
| 149 | + return ( |
| 150 | + <div className="bg-dark-card rounded-lg border border-dark-border p-6"> |
| 151 | + <LoadingSpinner /> |
| 152 | + </div> |
| 153 | + ); |
| 154 | + } |
| 155 | + |
| 156 | + if (error || !data) { |
| 157 | + return ( |
| 158 | + <div className="bg-dark-card rounded-lg border border-dark-border p-6"> |
| 159 | + <p className="text-red-400">Failed to load activity details</p> |
| 160 | + </div> |
| 161 | + ); |
| 162 | + } |
| 163 | + |
| 164 | + return ( |
| 165 | + <div className="bg-dark-card rounded-lg border border-dark-border p-6 space-y-4 sticky top-6"> |
| 166 | + <h2 className="text-lg font-semibold text-gray-100 font-mono">{data.name}</h2> |
| 167 | + |
| 168 | + {data.description && ( |
| 169 | + <p className="text-gray-400">{data.description}</p> |
| 170 | + )} |
| 171 | + |
| 172 | + <dl className="space-y-3"> |
| 173 | + <div> |
| 174 | + <dt className="text-sm text-gray-500">Supports Compensation</dt> |
| 175 | + <dd className={data.supportsCompensation ? 'text-green-400' : 'text-gray-400'}> |
| 176 | + {data.supportsCompensation ? 'Yes' : 'No'} |
| 177 | + </dd> |
| 178 | + </div> |
| 179 | + |
| 180 | + {data.compensatingActivity && ( |
| 181 | + <div> |
| 182 | + <dt className="text-sm text-gray-500">Compensating Activity</dt> |
| 183 | + <dd className="text-gray-200 font-mono">{data.compensatingActivity}</dd> |
| 184 | + </div> |
| 185 | + )} |
| 186 | + |
| 187 | + {data.inputType && ( |
| 188 | + <div> |
| 189 | + <dt className="text-sm text-gray-500">Input Type</dt> |
| 190 | + <dd className="text-gray-200 font-mono">{data.inputType}</dd> |
| 191 | + </div> |
| 192 | + )} |
| 193 | + |
| 194 | + {data.outputType && ( |
| 195 | + <div> |
| 196 | + <dt className="text-sm text-gray-500">Output Type</dt> |
| 197 | + <dd className="text-gray-200 font-mono">{data.outputType}</dd> |
| 198 | + </div> |
| 199 | + )} |
| 200 | + |
| 201 | + {data.tags.length > 0 && ( |
| 202 | + <div> |
| 203 | + <dt className="text-sm text-gray-500 mb-1">Tags</dt> |
| 204 | + <dd className="flex flex-wrap gap-1"> |
| 205 | + {data.tags.map(tag => ( |
| 206 | + <span |
| 207 | + key={tag} |
| 208 | + className="px-2 py-0.5 bg-dark-hover text-gray-400 text-xs rounded" |
| 209 | + > |
| 210 | + {tag} |
| 211 | + </span> |
| 212 | + ))} |
| 213 | + </dd> |
| 214 | + </div> |
| 215 | + )} |
| 216 | + </dl> |
| 217 | + |
| 218 | + {/* Usage Example */} |
| 219 | + <div className="pt-4 border-t border-dark-border"> |
| 220 | + <h3 className="text-sm text-gray-500 mb-2">Usage in Workflow Definition</h3> |
| 221 | + <pre className="bg-dark-bg rounded-lg p-3 text-sm font-mono text-gray-300 overflow-auto"> |
| 222 | +{`{ |
| 223 | + "Type": "Task", |
| 224 | + "Activity": "${data.name}", |
| 225 | + "Next": "NextState" |
| 226 | +}`} |
| 227 | + </pre> |
| 228 | + </div> |
| 229 | + </div> |
| 230 | + ); |
| 231 | +} |
0 commit comments