3.5 KiB
3.5 KiB
Question Bank Module Implementation
1. Overview
The Question Bank module (src/modules/questions) is a core component for teachers to manage their examination resources. It implements a comprehensive CRUD interface with advanced filtering and batch operations.
Status: IMPLEMENTED
Date: 2025-12-23
Author: Senior Frontend Engineer
2. Architecture & Tech Stack
2.1 Vertical Slice Architecture
Following the project's architectural guidelines, all question-related logic is encapsulated within src/modules/questions:
components/: UI components (Data Table, Dialogs, Filters)actions.ts: Server Actions for data mutationdata-access.ts: Database query logicschema.ts: Zod schemas for validationtypes.ts: TypeScript interfaces
2.2 Key Technologies
- Data Grid:
@tanstack/react-tablefor high-performance rendering. - State Management:
nuqsfor URL-based state (filters, search). - Forms:
react-hook-form+zod+shadcn/uiform components. - Validation: Strict server-side and client-side validation using Zod schemas.
3. Component Design
3.1 QuestionDataTable (question-data-table.tsx)
- Features: Pagination, Sorting, Row Selection.
- Performance: Uses
React.memocompatible patterns where possible (thoughuseReactTableitself is not memoized). - Responsiveness: Mobile-first design with horizontal scroll for complex columns.
3.2 QuestionColumns (question-columns.tsx)
Custom cell renderers for rich data display:
- Type Badge: Color-coded badges for different question types (Single Choice, Multiple Choice, etc.).
- Difficulty: Visual indicator with color (Green -> Red) and numerical value.
- Actions: Dropdown menu for Edit, Delete, View Details, and Copy ID.
3.3 Create/Edit Dialog (create-question-dialog.tsx)
A unified dialog component for both creating and editing questions.
- Dynamic Fields: Shows/hides "Options" field based on question type.
- Interactive Options: Allows adding/removing/reordering options for choice questions.
- Optimistic UI: Shows loading states during submission.
3.4 Filters (question-filters.tsx)
- URL Sync: All filter states (Search, Type, Difficulty) are synced to URL parameters.
- Debounce: Search input uses debounce to prevent excessive requests.
- Server Filtering: Filtering logic is executed on the server side (currently simulated in
page.tsx, ready for DB integration).
4. Implementation Details
4.1 Data Flow
- Read:
page.tsx(Server Component) fetches data based onsearchParams. - Write: Client components invoke Server Actions (simulated) -> Revalidate Path -> UI Updates.
- Filter: User interaction -> Update URL -> Server Component Re-render -> New Data.
4.2 Type Safety
A shared Question interface ensures consistency across the stack:
export interface Question {
id: string;
content: any; // Rich text structure
type: QuestionType;
difficulty: number;
// ... relations
}
4.3 UI/UX Standards
- Empty States: Custom
EmptyStatecomponent when no data matches. - Loading States: Skeleton screens for table loading.
- Feedback:
Sonnertoasts for success/error notifications. - Confirmation:
AlertDialogfor destructive actions (Delete).
5. Next Steps
- Integrate with real Database (replace Mock Data).
- Implement Rich Text Editor (Slate.js / Tiptap) for question content.
- Add "Batch Import" functionality.
- Implement "Tags" management for Knowledge Points.