Skip to content

Commit 66e62c7

Browse files
authored
Merge pull request #106 from ModusCreateOrg/ADE-66
[ADE-66] fixes and improvements to uploading, processing, and viewing a report
2 parents 0395275 + 0a4f2ce commit 66e62c7

File tree

7 files changed

+86
-30
lines changed

7 files changed

+86
-30
lines changed

backend/src/document-processor/controllers/document-processor.controller.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -143,21 +143,31 @@ export class DocumentProcessorController {
143143
throw new BadRequestException(`Report with ID ${reportId} has no associated file`);
144144
}
145145

146-
// Update report status to IN_PROGRESS before starting async processing
147-
report.processingStatus = ProcessingStatus.IN_PROGRESS;
148-
report.updatedAt = new Date().toISOString();
149-
await this.reportsService.updateReport(report);
146+
let message = '';
150147

151-
// Start async processing in background
152-
this.processReportAsync(reportId, userId, report.filePath).catch(error => {
153-
this.logger.error(`Async processing failed for report ${reportId}: ${error.message}`);
154-
});
148+
if (report.processingStatus === ProcessingStatus.IN_PROGRESS) {
149+
message = 'Document processing is already in progress. Please check the report status.';
150+
} else if (report.processingStatus === ProcessingStatus.PROCESSED) {
151+
message = 'Document has already been processed. No further action is needed.';
152+
} else {
153+
message = 'Document processing started. Check the report status to know when it completes.';
154+
155+
// Update report status to IN_PROGRESS before starting async processing
156+
report.processingStatus = ProcessingStatus.IN_PROGRESS;
157+
report.updatedAt = new Date().toISOString();
158+
await this.reportsService.updateReport(report);
159+
160+
// Start async processing in background
161+
this.processReportAsync(reportId, userId, report.filePath).catch(error => {
162+
this.logger.error(`Async processing failed for report ${reportId}: ${error.message}`);
163+
});
164+
}
155165

156166
return {
157167
success: true,
158168
reportId: report.id,
159-
status: ProcessingStatus.IN_PROGRESS,
160-
message: 'Document processing started. Check the report status to know when it completes.',
169+
status: report.processingStatus,
170+
message,
161171
};
162172
} catch (error: unknown) {
163173
this.logger.error(

backend/src/iac/backend-stack.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,18 @@ export class BackendStack extends cdk.Stack {
454454
},
455455
});
456456

457+
const deleteReportIntegration = new apigateway.Integration({
458+
type: apigateway.IntegrationType.HTTP_PROXY,
459+
integrationHttpMethod: 'DELETE',
460+
uri: `${serviceUrl}/api/reports/{id}`,
461+
options: {
462+
...integrationOptions,
463+
requestParameters: {
464+
'integration.request.path.id': 'method.request.path.id',
465+
},
466+
},
467+
});
468+
457469
const patchReportStatusIntegration = new apigateway.Integration({
458470
type: apigateway.IntegrationType.HTTP_PROXY,
459471
integrationHttpMethod: 'PATCH',
@@ -517,6 +529,13 @@ export class BackendStack extends cdk.Stack {
517529
},
518530
});
519531

532+
reportIdResource.addMethod('DELETE', deleteReportIntegration, {
533+
...methodOptions,
534+
requestParameters: {
535+
'method.request.path.id': true,
536+
},
537+
});
538+
520539
reportStatusResource.addMethod('PATCH', patchReportStatusIntegration, {
521540
...methodOptions,
522541
requestParameters: {

backend/src/reports/reports.controller.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
UnauthorizedException,
1111
Post,
1212
NotFoundException,
13+
Delete,
1314
} from '@nestjs/common';
1415
import {
1516
ApiTags,
@@ -192,6 +193,25 @@ export class ReportsController {
192193
return this.reportsService.saveReport(filePath, userId, originalFilename, fileSize);
193194
}
194195

196+
@ApiOperation({ summary: 'Delete a report' })
197+
@ApiResponse({
198+
status: 200,
199+
description: 'Report deleted successfully',
200+
})
201+
@ApiResponse({
202+
status: 404,
203+
description: 'Report not found',
204+
})
205+
@ApiParam({
206+
name: 'id',
207+
description: 'Report ID',
208+
})
209+
@Delete(':id')
210+
async deleteReport(@Param('id') id: string, @Req() request: RequestWithUser): Promise<void> {
211+
const userId = this.extractUserId(request);
212+
await this.reportsService.deleteReport(id, userId);
213+
}
214+
195215
private extractUserId(request: RequestWithUser): string {
196216
// The user object is attached to the request by our middleware
197217
const user = request.user;

frontend/src/common/utils/i18n/resources/en/common.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
"pages": {
8181
"chat": {
8282
"title": "AI Assistant"
83+
},
84+
"upload": {
85+
"title": "Upload Report"
8386
}
8487
}
8588
}

frontend/src/pages/Reports/ReportDetailPage.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ const ReportDetailPage: React.FC = () => {
8080

8181
// Handle close button
8282
const handleClose = () => {
83-
history.goBack();
83+
history.push('/tabs/home');
8484
};
8585

8686
// Handle action buttons
87-
const handleDiscard = () => {
88-
history.goBack();
87+
const handleDiscard = async () => {
88+
await axios.delete(`${API_URL}/api/reports/${reportId}`, await getAuthConfig());
89+
history.push('/tabs/home');
8990
};
9091

9192
const handleNewUpload = () => {

frontend/src/pages/Reports/components/AiAnalysisTab.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ const AiAnalysisTab: React.FC<AiAnalysisTabProps> = ({
4545
{isLowConfidence && <LowConfidenceNotice />}
4646

4747
{/* Flagged values section */}
48-
<FlaggedValuesSection
49-
flaggedValues={flaggedValues}
50-
isExpanded={flaggedValuesExpanded}
51-
onToggle={toggleFlaggedValues}
52-
/>
48+
{flaggedValues.length > 0 && (
49+
<FlaggedValuesSection
50+
flaggedValues={flaggedValues}
51+
isExpanded={flaggedValuesExpanded}
52+
onToggle={toggleFlaggedValues}
53+
/>
54+
)}
5355

5456
{/* Normal values section */}
5557
<NormalValuesSection

frontend/src/pages/Upload/UploadPage.tsx

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonButton } from '@ionic/react';
1+
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react';
22
import { useTranslation } from 'react-i18next';
3-
import { useState } from 'react';
3+
import { useEffect, useState } from 'react';
44
import { useHistory } from 'react-router-dom';
55
import UploadModal from 'common/components/Upload/UploadModal';
66

@@ -10,7 +10,7 @@ import UploadModal from 'common/components/Upload/UploadModal';
1010
*/
1111
const UploadPage = (): JSX.Element => {
1212
const { t } = useTranslation();
13-
const [isModalOpen, setIsModalOpen] = useState(false);
13+
const [isModalOpen, setIsModalOpen] = useState(true);
1414
const history = useHistory();
1515

1616
const handleUploadComplete = () => {
@@ -21,6 +21,16 @@ const UploadPage = (): JSX.Element => {
2121
history.push('/tabs/home');
2222
};
2323

24+
useEffect(() => {
25+
// Automatically open the upload modal when the component mounts
26+
setIsModalOpen(true);
27+
28+
// Cleanup function to close the modal when the component unmounts
29+
return () => {
30+
setIsModalOpen(false);
31+
};
32+
}, []);
33+
2434
return (
2535
<IonPage>
2636
<IonHeader>
@@ -29,15 +39,6 @@ const UploadPage = (): JSX.Element => {
2939
</IonToolbar>
3040
</IonHeader>
3141
<IonContent>
32-
<div className="ion-padding">
33-
<h1>{t('pages.upload.subtitle')}</h1>
34-
<p>{t('pages.upload.description')}</p>
35-
36-
<IonButton expand="block" className="ion-margin-top" onClick={() => setIsModalOpen(true)}>
37-
{t('upload.selectFile')}
38-
</IonButton>
39-
</div>
40-
4142
<UploadModal
4243
isOpen={isModalOpen}
4344
onClose={() => setIsModalOpen(false)}

0 commit comments

Comments
 (0)