Skip to content

feat: add analyze tab for review documents and deals#75

Merged
MSevey merged 4 commits into
mainfrom
matt-ardgbl-915-designated-views-as-app-examples
Dec 11, 2025
Merged

feat: add analyze tab for review documents and deals#75
MSevey merged 4 commits into
mainfrom
matt-ardgbl-915-designated-views-as-app-examples

Conversation

@MSevey

@MSevey MSevey commented Dec 11, 2025

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

New Features

  • Added "Analyze" tab in navigation for document analysis workflows
  • Enabled drag-and-drop document uploads with file validation
  • Added real-time document processing status tracking with progress indicators
  • Implemented extraction results viewer displaying analyzed document data
  • Added "Analyze" action in loan details for direct document analysis access

✏️ Tip: You can customize this high-level summary in your review settings.

@linear

linear Bot commented Dec 11, 2025

Copy link
Copy Markdown
ARDGBL-915 Designated views as App examples

Consider making a collateral checker view to highlight the functionality of uploading a deal or due diligence documents that then can highlight if that collateral seems related to other collateral already in the system.

Potentially create a view as a deal analyzer where someone could upload a draft credit agreement and get feedback on how it compares to other credit agreements in the system.

These views could probably take inspiration from the ingest UI

@coderabbitai

coderabbitai Bot commented Dec 11, 2025

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

Walkthrough

This change introduces a comprehensive document analysis feature for the credit system. New components enable document upload, viewing, and extraction result display with processing status tracking. The AnalyzePage integrates these components with document status polling and deal preview fetching. Navigation, routing, and existing pages (Dashboard, Portfolio, Management) are updated to support the analysis workflow. Type system enhancements add AnalyzeContext to the shared chat context. User ID handling is improved across multiple pages for consistency.

Changes

Cohort / File(s) Summary
Core Analyze Feature
src/credit/pages/AnalyzePage.tsx, src/credit/components/analyze/DocumentUploadSection.tsx, src/credit/components/analyze/DocumentViewer.tsx, src/credit/components/analyze/ExtractionResultsViewer.tsx, src/credit/components/analyze/ProcessingStatus.tsx
New AnalyzePage component with localStorage-backed document queue, status polling, and deal preview fetching. DocumentUploadSection handles drag-and-drop file uploads with validation and progress tracking. DocumentViewer renders document previews (PDF via iframe, others via link). ExtractionResultsViewer displays extraction results with collapsible sections and field validation. ProcessingStatus shows multi-stage pipeline with elapsed time and progress indicators.
Routing & Navigation
src/App.tsx, src/credit/components/layout/Navigation.tsx
Added /credit/analyze route with ProtectedRoute and context providers. Navigation component adds new "Analyze" tab with Sparkles icon to investor, admin, and originator tab sets.
Existing Pages Integration
src/credit/pages/DashboardPage.tsx, src/credit/pages/PortfolioPage.tsx, src/credit/pages/ManagementPage.tsx
Standardized userId derivation from currentUser (user_id or id). Enhanced user loading from localStorage with multiple key checks and error handling. Updated dependency arrays to include currentUser?.user_id. Improved user-scoped document and pending-document fetching.
Management UI Updates
src/credit/components/management/DocumentsTab.tsx, src/credit/components/management/CovenantsTab.tsx, src/credit/components/management/DoublePledgesTab.tsx
DocumentsTab adds extraction review workflow with ExtractionReviewModal, replaces Mark Reviewed with Analyze and Mark Reviewed actions for review-needed documents. CovenantsTab and DoublePledgesTab add company-required alerts; show "Company Required" instead of data when no company is selected.
Loans Integration
src/credit/components/loans/LoanDetailModal.tsx
Added Analyze button navigation to /credit/analyze with mode, dealId, and documentId state when loan has source_document_id. Sparkles icon imported and used for Analyze action.
Shared Types & Context
src/shared/types/chatContext.ts, src/shared/types/index.ts, src/shared/hooks/useCreditAppContext.ts
Added AnalyzeContext interface describing document, extraction results, and deal metadata. Extended ChatContextData with optional analyzeContext property. Added user_id field to User interface. Updated useCreditAppContext to read and expose analyzeContext from localStorage.

Sequence Diagram

sequenceDiagram
    participant User
    participant AnalyzePage
    participant DocumentUploadSection
    participant ingestionApi
    participant DocumentViewer
    participant ProcessingStatus
    participant ExtractionResultsViewer

    User->>AnalyzePage: Enter /credit/analyze
    AnalyzePage->>AnalyzePage: Load processing queue from localStorage
    
    rect rgb(200, 220, 255)
    Note over User,AnalyzePage: Document Upload Phase
    User->>DocumentUploadSection: Drag/Select file
    DocumentUploadSection->>DocumentUploadSection: Validate file size
    User->>DocumentUploadSection: Click Upload
    DocumentUploadSection->>ingestionApi: uploadDocument(file, userId, userEmail)
    ingestionApi-->>DocumentUploadSection: documentId, filename
    DocumentUploadSection->>AnalyzePage: onUploadSuccess(documentId, filename)
    AnalyzePage->>AnalyzePage: Add to processing queue, save to localStorage
    end

    rect rgb(220, 255, 220)
    Note over AnalyzePage,ProcessingStatus: Status Polling Phase
    AnalyzePage->>AnalyzePage: Poll document status (dynamic interval)
    AnalyzePage->>ingestionApi: getDocumentStatus(documentId)
    ingestionApi-->>AnalyzePage: status (uploading|processing|ocr|extracting|complete)
    AnalyzePage->>ProcessingStatus: Pass status, filename, progress
    ProcessingStatus-->>AnalyzePage: Render progress UI
    DocumentViewer->>DocumentViewer: Display loading state while processing
    end

    rect rgb(255, 240, 200)
    Note over AnalyzePage,ExtractionResultsViewer: Extraction Results Phase
    AnalyzePage->>AnalyzePage: Document terminal state reached
    AnalyzePage->>ingestionApi: getDealPreview(documentId)
    ingestionApi-->>AnalyzePage: dealPreview (extraction data)
    AnalyzePage->>DocumentViewer: Pass s3Url, filename
    DocumentViewer-->>AnalyzePage: Render document preview
    AnalyzePage->>ExtractionResultsViewer: Pass dealExtraction data
    ExtractionResultsViewer-->>AnalyzePage: Render extraction results with validation
    end

    AnalyzePage->>AnalyzePage: Save analyzeContext to localStorage
    User->>User: Review extraction results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Areas requiring extra attention:

  • AnalyzePage.tsx: Complex state management with localStorage persistence, document queue handling, dual polling loops (status + preview), and lifecycle cleanup logic. Verify proper error boundaries and edge cases around document lifecycle transitions.
  • DocumentsTab.tsx: Significant refactor integrating extraction workflow, ExtractionReviewModal dependency, user context loading, and action branching logic. Review flow correctness for document states (pending_user_review, pending_mapping_confirmation) and proper cleanup of reviewed documents.
  • ProcessingStatus.tsx: Multi-stage pipeline logic with computed stage derivation, elapsed time calculation, and conditional rendering. Verify stage progression logic and error state handling.
  • ExtractionResultsViewer.tsx: Complex nested structure with collapsible sections, field validation (required vs. optional), copy-to-clipboard interactions, and error state rendering. Verify required field detection and UI consistency.
  • User ID handling across pages: userId derivation pattern introduced in DashboardPage, PortfolioPage, and ManagementPage. Verify consistent application and that dependency arrays are complete to avoid missing re-renders.

Poem

🐰 A document dreams of being understood,
Uploaded, scanned, extracted—as it should!
From uploads soaring, progress bars aglow,
Through OCR tunnels, extraction flows—
✨ The Analyze page makes data dance,
hops excitedly what a splendid chance! 📊


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Free

📥 Commits

Reviewing files that changed from the base of the PR and between 3346675 and 6758b54.

📒 Files selected for processing (17)
  • src/App.tsx (2 hunks)
  • src/credit/components/analyze/DocumentUploadSection.tsx (1 hunks)
  • src/credit/components/analyze/DocumentViewer.tsx (1 hunks)
  • src/credit/components/analyze/ExtractionResultsViewer.tsx (1 hunks)
  • src/credit/components/analyze/ProcessingStatus.tsx (1 hunks)
  • src/credit/components/layout/Navigation.tsx (2 hunks)
  • src/credit/components/loans/LoanDetailModal.tsx (5 hunks)
  • src/credit/components/management/CovenantsTab.tsx (1 hunks)
  • src/credit/components/management/DocumentsTab.tsx (6 hunks)
  • src/credit/components/management/DoublePledgesTab.tsx (1 hunks)
  • src/credit/pages/AnalyzePage.tsx (1 hunks)
  • src/credit/pages/DashboardPage.tsx (3 hunks)
  • src/credit/pages/ManagementPage.tsx (3 hunks)
  • src/credit/pages/PortfolioPage.tsx (5 hunks)
  • src/shared/hooks/useCreditAppContext.ts (3 hunks)
  • src/shared/types/chatContext.ts (2 hunks)
  • src/shared/types/index.ts (1 hunks)

Note

🎁 Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Pro by visiting https://app.coderabbit.ai/login.

Comment @coderabbitai help to get the list of available commands and usage tips.

@MSevey MSevey merged commit 8edc0b8 into main Dec 11, 2025
2 of 3 checks passed
@MSevey MSevey deleted the matt-ardgbl-915-designated-views-as-app-examples branch December 11, 2025 20:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant