diff --git a/frontend/src/pages/RequirementDetailPage.tsx b/frontend/src/pages/RequirementDetailPage.tsx index e945da2..e572949 100644 --- a/frontend/src/pages/RequirementDetailPage.tsx +++ b/frontend/src/pages/RequirementDetailPage.tsx @@ -1,176 +1,63 @@ -import { useState } from 'react' +import { useState, useEffect } from 'react' import { useAuth } from '@/hooks' import { useParams, Link } from 'react-router-dom' - -// Types for requirement details -interface RequirementDetail { - id: string - tag: string - title: string - priority: number - group: string - description: string - authors: string[] - subRequirements: SubRequirement[] - coRequirements: CoRequirement[] - acceptanceCriteria: AcceptanceCriterion[] - sharedComments: Comment[] -} - -interface SubRequirement { - id: string - tag: string - title: string -} - -interface CoRequirement { - id: string - tag: string - title: string -} - -interface AcceptanceCriterion { - id: string - description: string - validated: boolean -} - -interface Comment { - id: string - author: string - date: string - content: string -} +import { requirementService } from '@/services' +import type { Requirement } from '@/services/requirementService' // Tab types type TabType = 'description' | 'sub-requirements' | 'co-requirements' | 'acceptance-criteria' | 'shared-comments' | 'validate' -// Mock data for requirement details -const mockRequirementDetails: Record = { - '1': { - id: '1', - tag: 'GSR#7', - title: 'Controle e monitoramento em right-time', - priority: 0, - group: 'userExperience', - description: '', - authors: ['Ricardo Belo'], - subRequirements: [], - coRequirements: [], - acceptanceCriteria: [], - sharedComments: [], - }, - '2': { - id: '2', - tag: 'GSR#10', - title: 'Interface de software DT-externo bem definida.', - priority: 1, - group: 'Intelligence', - description: 'This requirement defines the need for a well-defined software interface between the Digital Twin and external systems.', - authors: ['Ricardo Belo', 'Maria Silva'], - subRequirements: [ - { id: 'sub1', tag: 'SFR#1', title: 'API Documentation' }, - { id: 'sub2', tag: 'SFR#2', title: 'Authentication Protocol' }, - ], - coRequirements: [ - { id: 'co1', tag: 'GSR#5', title: 'Sincronização de dados em tempo real' }, - ], - acceptanceCriteria: [ - { id: 'ac1', description: 'API endpoints documented with OpenAPI spec', validated: true }, - { id: 'ac2', description: 'Authentication tested with external systems', validated: false }, - ], - sharedComments: [ - { id: 'c1', author: 'Ricardo Belo', date: '2025-11-28', content: 'Initial draft created' }, - ], - }, - '3': { - id: '3', - tag: 'GSR#12', - title: 'Visualizacao', - priority: 1, - group: 'User Experience', - description: 'Visualization requirements for the Digital Twin interface.', - authors: ['Ricardo Belo'], - subRequirements: [], - coRequirements: [], - acceptanceCriteria: [], - sharedComments: [], - }, - '4': { - id: '4', - tag: 'GSR#1', - title: 'Estado corrente atualizado', - priority: 1, - group: 'Data Services', - description: 'The system must maintain an updated current state of all monitored entities.', - authors: ['Ricardo Belo'], - subRequirements: [], - coRequirements: [], - acceptanceCriteria: [], - sharedComments: [], - }, - '5': { - id: '5', - tag: 'GSR#5', - title: 'Sincronização de dados em tempo real', - priority: 2, - group: 'Data Services', - description: 'Real-time data synchronization between physical and digital twin.', - authors: ['Ricardo Belo'], - subRequirements: [], - coRequirements: [], - acceptanceCriteria: [], - sharedComments: [], - }, - '6': { - id: '6', - tag: 'GSR#8', - title: 'Integração com sistemas legados', - priority: 1, - group: 'Integration', - description: 'Integration capabilities with legacy systems.', - authors: ['Ricardo Belo'], - subRequirements: [], - coRequirements: [], - acceptanceCriteria: [], - sharedComments: [], - }, - '7': { - id: '7', - tag: 'GSR#15', - title: 'Dashboard de gestão', - priority: 3, - group: 'Management', - description: 'Management dashboard for system monitoring and control.', - authors: ['Ricardo Belo'], - subRequirements: [], - coRequirements: [], - acceptanceCriteria: [], - sharedComments: [], - }, -} - export default function RequirementDetailPage() { const { user, logout } = useAuth() const { id } = useParams<{ id: string }>() const [activeTab, setActiveTab] = useState('description') - const [priority, setPriority] = useState(0) + const [requirement, setRequirement] = useState(null) + const [loading, setLoading] = useState(true) + const [error, setError] = useState(null) - // Get requirement details from mock data - const requirement = id ? mockRequirementDetails[id] : null + // Fetch requirement data on mount + useEffect(() => { + const fetchRequirement = async () => { + if (!id) { + setError('No requirement ID provided') + setLoading(false) + return + } - // Initialize priority when requirement loads - useState(() => { - if (requirement) { - setPriority(requirement.priority) + try { + setLoading(true) + setError(null) + const data = await requirementService.getRequirement(parseInt(id, 10)) + setRequirement(data) + } catch (err) { + console.error('Failed to fetch requirement:', err) + setError('Failed to load requirement. Please try again.') + } finally { + setLoading(false) + } } - }) - if (!requirement) { + fetchRequirement() + }, [id]) + + if (loading) { return (
-

Requirement not found

+
+

Loading requirement...

+
+
+ ) + } + + if (error || !requirement) { + return ( +
+
+

+ {error || 'Requirement not found'} +

Back to Requirements @@ -188,9 +75,10 @@ export default function RequirementDetailPage() { { id: 'validate', label: 'Validate' }, ] - const handlePriorityChange = (delta: number) => { - setPriority(prev => Math.max(0, prev + delta)) - } + // Get display values from the requirement data + const tagCode = requirement.tag.tag_code + const priorityName = requirement.priority?.priority_name ?? 'None' + const validationStatus = requirement.validation_status || 'Not Validated' const renderTabContent = () => { switch (activeTab) { @@ -198,11 +86,24 @@ export default function RequirementDetailPage() { return (

Description

-

- Author(s): {requirement.authors.join(', ')} +

+ Version: {requirement.version}

+

+ Validation Status: {validationStatus} +

+ {requirement.created_at && ( +

+ Created: {new Date(requirement.created_at).toLocaleDateString()} +

+ )} + {requirement.updated_at && ( +

+ Last Updated: {new Date(requirement.updated_at).toLocaleDateString()} +

+ )}
-

{requirement.description || ''}

+

{requirement.req_desc || 'No description provided.'}