6.5 KiB
6.5 KiB
Agent Guidelines for Data Index Report App
Project Overview
This is a React + TypeScript + Vite application for generating data analysis reports with PDF export functionality. The app includes data visualization components (ECharts), Excel import/export, and PDF generation.
Build, Lint, and Test Commands
Development
npm run dev # Start development server
npm run preview # Preview production build
Build
npm run build # Build for production (runs TypeScript compilation + Vite build)
Linting
npm run lint # Run ESLint on all files
Type Checking
npx tsc --noEmit # Type check without emitting files
Single File Operations
# Lint specific file
npx eslint src/components/ComponentName.tsx
# Type check specific file
npx tsc --noEmit src/components/ComponentName.tsx
Code Style Guidelines
Imports Order
- React and external library imports
- Internal component imports
- Type imports
- Utility/helper imports
- Style/constant imports
Example:
import { useRef, useState } from 'react';
import html2pdf from 'html2pdf.js';
import { Download, Upload } from 'lucide-react';
import { CoverPage } from './components/CoverPage';
import { defaultReportData } from './data/defaultData';
import { parseExcelReportData } from './utils/excelUtils';
import type { ReportData } from './types/data';
TypeScript Configuration
- Strict mode enabled (
"strict": true) - No unused locals/parameters enforced
- Use explicit type annotations for function parameters and return types
- Prefer
interfaceovertypefor object shapes - Use
typeimports for type-only imports
Naming Conventions
- Components: PascalCase (e.g.,
Page02Industry,ChinaMap) - Files: PascalCase for components, camelCase for utilities
- Variables/Functions: camelCase
- Constants: UPPER_SNAKE_CASE for true constants, camelCase for exported constants
- Types/Interfaces: PascalCase with
Iprefix optional (not used in this codebase) - Props Interfaces:
ComponentNamePropspattern
Component Structure
- Import statements
- Interface/type definitions
- Component function with typed props
- Internal helper functions
- JSX return with proper className organization
Example component pattern:
interface ComponentProps {
data: SomeType[];
onAction?: () => void;
}
export const Component = ({ data, onAction }: ComponentProps) => {
// State and hooks
const [state, setState] = useState<StateType>(initialValue);
// Helper functions
const processData = () => {
// Implementation
};
return (
<div className="container-class">
{/* JSX content */}
</div>
);
};
Error Handling
- Use try/catch for async operations
- Provide user feedback for errors (status messages, UI indicators)
- Log errors to console for debugging
- Use TypeScript's strict null checking
Styling (Tailwind CSS)
- Use Tailwind utility classes exclusively
- Organize classes logically: layout → typography → colors → effects
- Use responsive prefixes (sm:, md:, lg:) when needed
- Custom colors defined in
tailwind.config.js - Use
@applysparingly in CSS files only
Example class organization:
<div className="
flex flex-col /* Layout */
p-4 space-y-4 /* Spacing */
bg-white rounded-lg /* Appearance */
shadow-md /* Effects */
hover:shadow-lg /* Interactive */
">
File Organization
src/components/- React componentssrc/types/- TypeScript type definitionssrc/utils/- Utility functionssrc/data/- Default data and constantssrc/constants.ts- Application constantspublic/- Static assets
React Patterns
- Use functional components with hooks
- Prefer explicit prop typing over
any - Use
useStatefor local state - Use
useReffor DOM references - Extract complex logic into custom hooks when reusable
- Use
React.memofor performance optimization when needed
ECharts Integration
- Chart components should accept typed data props
- Use responsive chart configurations
- Include proper error handling for missing data
- Export charts as reusable components
PDF Generation
- Use
html2pdf.jsfor PDF export - Handle width locking during PDF generation
- Provide proper error feedback
- Use
@ts-expect-errorfor library type issues when necessary
Excel Integration
- Use
xlsxlibrary for Excel operations - Provide template generation functions
- Validate imported data structure
- Handle file upload errors gracefully
Development Workflow
Adding New Components
- Create component file in
src/components/ - Define TypeScript interfaces for props
- Implement component with Tailwind styling
- Export component as named export
- Add to appropriate parent component
Adding New Types
- Add to existing interface in
src/types/data.tsor create new file - Use descriptive property names
- Include JSDoc comments for complex types
- Export types for reuse
Adding Utilities
- Create file in
src/utils/ - Write pure functions with typed parameters
- Include error handling
- Export functions as named exports
Testing Changes
- Run
npm run lintto check code style - Run
npx tsc --noEmitfor type checking - Test component in development server
- Verify PDF generation still works
- Test Excel import/export functionality
Common Patterns in Codebase
Data Processing
// Map data aggregation pattern
const aggregatedData = data.reduce((acc, item) => {
const key = item.name;
acc[key] = (acc[key] || 0) + item.value;
return acc;
}, {} as Record<string, number>);
Component Props
// Optional props with defaults
interface Props {
data: DataType[];
title?: string;
className?: string;
}
const Component = ({
data,
title = 'Default Title',
className = ''
}: Props) => {
// Implementation
};
State Management
// Status state pattern
const [status, setStatus] = useState<'idle' | 'loading' | 'success' | 'error'>('idle');
// Data state with default
const [reportData, setReportData] = useState<ReportData>(defaultReportData);
Notes for Agents
- This is a Chinese-language application (UI text in Chinese)
- Focus on data visualization and report generation
- Maintain print-friendly styling for PDF export
- Ensure all interactive elements have
no-printclass when needed - Follow existing patterns for consistency
- Test PDF generation after UI changes
- Verify Excel template compatibility after data structure changes